On Jul 10, 7:36 am, Josh <joshuamonta...@gmail.com> wrote:
> Hi,
>
> I'm trying to read in data from a file that has the following format:
>
> 231359152 09/25/2003 18:38:35.816 20.013574 25.668425
> 626.779 14.396667
>
> I'm having no problems getting the fourth, fifth, and sixth columns of
> data into double arrays with a statement like this:
>
> readf, lun, recNum, date, time, lat, lon, elev, geoid
>
> and a for loop. But I would like to get the second column in an
> array, too. My intuition says it should be a string because of the
> nasty /'s in it (ultimately, I'd like these dates to be the
> independant axis values).
>
> I tried declaring the variable date as a string beforehand (date = '
> '), but then that slurps the entire line (all columns) into that
> variable. If I don't declare it as a string and try to put it into a
> string array (strArr), it becomes 9.00000.
>
> I'm reading the documentation for explicitly formatted input, but am
> having trouble figuring out how to apply it here.
>
> As always, all suggestions are greatly appreciated!
> -Josh
I usually use structures for my needs. You could just declare them as
integers and read with a format specifier for these leaving out the
slashes.
Assuming data is like above and with the 'nX' denoting the number of
spaces I have between your data (in my file - may be different for
you.), you can use:
;type declaration
IDL> recnum=0L & day=0 & month=0 & yyyy=0
IDL> hh=0 & mm=0 & ss=0 & dec_sec=0
IDL> lat=0. & lon=0. & elev=0. & geoid=0.
;read data from lun=2
IDL>readf,2,recnum,day,month,yyyy,hh,mm,ss,dec_sec,$
lat,lon,elev,geoid,$
format='(i9,1x,2(i2,1x),i4,1x,3(i2,1x),i3,2(2x,f9.6),$
1x,f7.3,1x,f9.6)'
IDL>print,recnum,day,month,yyyy,hh,mm,ss,dec_sec,lat,lon,$
elev,geoid
231359152 9 25 2003 18 38 35
816 20.0136 25.6684 626.779 14.3967
--
I suggest using structures. I found them very helpful. And if you have
header information that you need to make use of, for your calculations
(I do), then open the file, read in those required header info first,
and then define structure for the (homogeneous) data part like above,
and then use "replicate" to populate.
--
Hth,
/rk
|