[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A (too?) simple question about importing data




q4668057@bonsai.fernuni-hagen.de (Michael Spranger) writes:
> Hi,
> another beginner's question, this time about reading data:
> I want to read data from ASCII files into a structure. The data look
> as follows:
> 
> YYYY MM DD HH II SSSSS PPPPPP LLLLLLL KKK RRR 
> 0330 00 00 00 00 00000  50.60   03.40 000 0.0 USGS_EU_Catalogue
> 
> the structure, type, and length of variables are always the same, only
> the the order might change and some data might be missing. The last
> row (without header) contains comments only.

It's a beginner's *and* advanced user's question.  My suggestion is to
try TRANSREAD available from my web page.  It attempts to make it easy
to read lots of data from a file.  [ To get the formatting right I
suggest using the /DEBUG option. ]

I made a file called test.dat with the following lines:

YYYY MM DD HH II SSSSS PPPPPP LLLLLLL KKK RRR 
0330 00 00 00 00 00000  50.60   03.40 000 0.0 USGS_EU_Catalogue
0340 00 00 00 00 00000 124.56   03.40 000 0.0 Test line 1
0350 00 00 00 00 00000 789.01   03.40 000 0.0 Test line 2

And then executed the following commands:

IDL> yyyy = 0L & mm = 0L & dd = 0L & hh = 0L & ii = 0L & sssss = 0L 
IDL> pppppp = 0D & lllllll = 0D & kkk = 0L & rrr = 0D & ccc = ''
IDL> transread, unit, yyyy, mm, dd, hh, ii, sssss, pppppp, lllllll, kkk, $
     rrr, ccc, format='(I5,I3,I3,I3,I3,I6,D7,D8,I4,D4,A0)', file='test.dat'
IDL> print, yyyy
         330         340         350

The first two lines establish the types of each variable -- I used the
column headers you provided.  The third line is the actual invocation
of TRANSREAD.  The format keyword is vital, and may take some
experimentation.  Note that lines that don't match the format are
skipped automatically, you can define comment characters, and you can
specify start/stop "cues" to enable/disable parsing.

Craig
http://cow.physics.wisc.edu/~craigm/idl/idl.html

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------