[Thread Prev][Thread Next][Index]

Re: reading multiple datasets from a single ascii file

Hi Steve again,
A conversation here brought up some more ideas which I
thought I'd pass along.  You could use the shift operator
in doing the kind of thing I showed in the last message, to have
the indices start at 1.

Another idea which I like, as it makes the Ferret code simpler,
is to use unix soft links to give the data several file names, and
then read these as different data sets using the SET DATA/GRID
qualifier to get just the amount in each set.

The file twosets.dat has these lines:

1 2 3
4 5 6
7 8 9
1 2 3
4 5 6
7 8 9
10 11 12

> ln - s twosets.dat headers.dat
> ln -s twosets.dat set1.dat
> ln -s twosets.dat set2.dat

> ferret
! Read the whole file to get the headers; the size of each data
! set.  Find the lines where v2 is missing. These are the header lines.

yes? file/var=v1,v2,v3/form=delim/type=numeric/delim=" " headers.dat
yes? list  v1,v2,v3
yes? let headers = if missing(v2,-999) eq -999 then v1
yes? list headers

! Compress the header values.  Include the dataset name, as we
! will be coming back to use this list again.

yes? let headers = compressi( if missing(v2[d=headers.dat],-999) eq -999 then v1[d=headers.dat])
yes? list headers

! Define an axis and grid for the first set.

yes? def axis/x=1:`headers[i=1]`:1 xax1
yes? def grid/x=xax1 grid1

! Skip the first header line, read the data

yes? let nskip1 = 1

yes? file/skip=`nskip1`/grid=grid1/var="v1_1,v1_2,v1_3" set1.dat
yes? list v1_1,v1_2,v1_3

! Define an axis and grid for the second set.

yes? def axis/x=1:`headers[i=2]`:1 xax2
yes? def grid/x=xax2 grid2

! Skip the first header line, plus the first set and the second header line

yes? let nskip2 = nskip1 + headers[i=1] + 1
yes? file/skip=`nskip2`/grid=grid2/var="v2_1,v2_2,v2_3" set2.dat
yes? list v2_1,v2_2,v2_3

yes? show data

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement