[Thread Prev][Thread Next][Index]

Re: [ferret_users] Question about Reading ASCII Files



Hi Ag,
To just give a few more details to what Peter said -- you would do this in two separate read statements.  The first would give you the number of records to be read and the second would read in the variables (although if it's always just one batch of actual data, Ferret can just read to the end of the file.)

   FILE/SKIP=2/VAR=nn  mydat.dat

  ! We will cancel the dataset to read the next block, so save the value just read:
  LET npts = `nn` 

  ! Now read the variables
  CANCEL DATA mydat.dat
  FILE/FORM=delim/SKIP=4/DELIM="\b"/TYPE="text,date,time,text,numeric"/VAR="fname,ddate,ttime,dlab,val" mydat.dat

Notice I didn't use npts.  If there were several blocks of data you would DEFINE AXIS  and DEFINE  GRID, and use FILE/GRID=  to read a specific number of points from each block.

If you need to create a time axis from the date and time variables, there is a similar example in this FAQ - How can I create a time axis from variables containing year, month, day, etc?
 http://ferret.pmel.noaa.gov/FERRET_17sep07/FAQ/axes_and_data/time_axis_from_variables.html

Although your case here is simpler than what's in the FAQ -- you already have ddate which is in units days from 1-jan-1900, and ttime which is in units of hours and fraction of hours.

Ansley

ag wrote:
Dear Ferret Users:

Am looking for some suggestions on how to read an ASCII file (example below) using Ferret. I would like to be able to skip the first two records and then read the third as an integer (69 in this case), skip the fourth record and  then read the "integer" number of records of input with each record having 5 columns.

The reason I need to do this is sometimes, there are more a few files of the format below concatenated and the number of records of each file is specified always as below in separate blocks.

Thanks in Advance
agdc2005

--------------------File---------------
GISS
Image_Optical_Depth_Land_And_Ocean/MOD04_L2
69
filename        begindatetime   location        mean
MOD04_L2.A2007001.1500.005.2007003093108.hdf    2007-01-01 15:00:00     GISS
MOD04_L2.A2007001.1635.005.2007003093604.hdf    2007-01-01 16:35:00     GISS
MOD04_L2.A2007002.1540.005.2007004182338.hdf    2007-01-02 15:40:00     GISS    0.081
MOD04_L2.A2007003.1625.005.2007005151340.hdf    2007-01-03 16:25:00     GISS    0.027
MOD04_L2.A2007004.1530.005.2007007055054.hdf    2007-01-04 15:30:00     GISS
MOD04_L2.A2007005.1615.005.2007008173325.hdf    2007-01-05 16:15:00     GISS
MOD04_L2.A2007006.1520.005.2007010020024.hdf    2007-01-06 15:20:00     GISS
MOD04_L2.A2007007.1600.005.2007012202039.hdf    2007-01-07 16:00:00     GISS    0.167
MOD04_L2.A2007008.1505.005.2007012223915.hdf    2007-01-08 15:05:00     GISS
MOD04_L2.A2007008.1645.005.2007012225717.hdf    2007-01-08 16:45:00     GISS
MOD04_L2.A2007009.1550.005.2007013005323.hdf    2007-01-09 15:50:00     GISS
MOD04_L2.A2007010.1630.005.2007013053221.hdf    2007-01-10 16:30:00     GISS    0.039
MOD04_L2.A2007011.1535.005.2007014063943.hdf    2007-01-11 15:35:00     GISS    0.113
MOD04_L2.A2007012.1620.005.2007014045513.hdf    2007-01-12 16:20:00     GISS
MOD04_L2.A2007013.1525.005.2007015044928.hdf    2007-01-13 15:25:00     GISS
MOD04_L2.A2007014.1605.005.2007017161152.hdf    2007-01-14 16:05:00     GISS
MOD04_L2.A2007015.1510.005.2007017183912.hdf    2007-01-15 15:10:00     GISS
MOD04_L2.A2007016.1555.005.2007018180305.hdf    2007-01-16 15:55:00     GISS
MOD04_L2.A2007017.1500.005.2007019123555.hdf    2007-01-17 15:00:00     GISS    0.000
MOD04_L2.A2007017.1635.005.2007019125327.hdf    2007-01-17 16:35:00     GISS    0.028
MOD04_L2.A2007018.1540.005.2007020111006.hdf    2007-01-18 15:40:00     GISS    0.126
MOD04_L2.A2007018.1545.005.2007020105940.hdf    2007-01-18 15:45:00     GISS
MOD04_L2.A2007019.1625.005.2007023060629.hdf    2007-01-19 16:25:00     GISS
MOD04_L2.A2007020.1530.005.2007023002013.hdf    2007-01-20 15:30:00     GISS
MOD04_L2.A2007021.1615.005.2007023181352.hdf    2007-01-21 16:15:00     GISS
MOD04_L2.A2007022.1520.005.2007024120208.hdf    2007-01-22 15:20:00     GISS
MOD04_L2.A2007023.1600.005.2007024194356.hdf    2007-01-23 16:00:00     GISS    0.136
MOD04_L2.A2007024.1505.005.2007027011552.hdf    2007-01-24 15:05:00     GISS    0.095
MOD04_L2.A2007024.1645.005.2007027010315.hdf    2007-01-24 16:45:00     GISS    0.086

[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement