[Thread Prev][Thread Next][Index]

Re: [ferret_users] Reading variables from an ascii file



Hi Arturo-
It might be helpful for your C program to add the longitude and latitude values in each line so it's easier to see what you're doing, but that's not strictly necessary. So, the second and third columns would be lat and lon - but read on and see if you think this is necessary -

19600101000000 18.05000 271.94998  7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26.  ...
19600101010000 18.05000 271.94998  7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26.
...
19601231230000 18.05000 271.94998  7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26. 
19600101000000 18.05000 272.1500   7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26. 
19600101010000 18.05000 272.1500   7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26. 
...
19601231230000 18.05000 272.1500   7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26. 

 

Is time listed as each hour of the year?  If so you should be able to read the data in a way similar to the ASCII reading Examples 6 and 7 (see "ASCII data, reading, examples" in the Users Guide Index).  Time is varying fastest, then Longitude, then Latitude, correct?

So, first just learning how to read one variable.  I'll just make up some example longitude and latitude axes; you'll adjust these to match your data. They don't have to be regularly spaced, but we are assuming they're on a grid.

There are several ways to define coordinate axes - see the documentation.
DEFINE AXIS/X=271.95:279.0:0.2/UNITS=degrees_lon xaxis 
DEFINE AXIS/Y=18.05:19.0:0.05/UNITS=degrees_lat  yaxis
DEFINE AXIS/T="1-jan-1960:00:00":"31-Dec-1960:23:00":1/UNITS=hours taxis
DEFINE GRID/X=xaxis/Y=yaxis/T=taxis xytgrid

FILE/var="tvar,v1"/grid=xytgrid/order=txy file.dat

I'm assuming the data looks like this - without the lon and lat variables I talked about at the start of this message.
 19600101000000   7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26.  0.67  4.74  3.68  3.34  3.09 271.  21.  0.58  5.73  5.59  5.38  5.22 236.  19.
 19600101010000   7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26.  0.67  4.74  3.68  3.34  3.09 271.  21.  0.58  5.73  5.59  5.38  5.22 236.  19.
...
 19601231230000   7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26.  0.67  4.74  3.68  3.34  3.09 271.  21.  0.58  5.73  5.59  5.38  5.22 236.  19.



If you do put the lon and lat data into the file, then you'd read it with FILE/var="tvar,xvar,yvar,v1"/...

This will read the time variable into "tvar" which you can just ignore, because it contains information that's already captured in the definition of the time axis. Then the variable whose value as listed in your examples as 7.2 will be v1.  Try this, and look at your variable in Ferret (do some commands like SHADE at a particular time, or plot a time series at a single XY location and see if it looks correct.)

Now you can read more variables.  A detail here is that Ferret will only read 20 variables from an ASCII file.  I count 26 in your example.  So if you try
yes? file/var="tvar,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20,v21,v22,v23,v24,v25,v26"/grid=xytgrid file.dat

you'll get an error message.  To get around that  you might do this - probably naming your variables with meaningful names -
yes? file/var="tvar,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15"/grid=xytgrid file.dat
yes? save/clobber/file=my_data.nc v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19

yes? cancel data file.dat
yes? file/var="v20,v21,v22,v23,v24,v25,v26"/grid=xytgrid/format=(99x,F6.2,...) file.dat
yes? save/append/file=my_data.nc 20,v21,v22,v23,v24,v25,v26
where the FORMAT statement would specify the Fortran format for the remaining variables to be read in.

Hope this gets you started! 

Ansley

Arturo Avila Rosas wrote:
Hiya Ansley,
This is a sample of what I want to read:
 
TIME SERIES OF INTEGRATED PARAMETERS AT EstGME-50-01         LAT. =   18.05000 LONG. =  271.94998
 |----- DATE ----|-------- WIND ----------
 |--------------- WAVES -----------------
 |--------------- WINDSEA ---------------
 |--------------- SWELL ----------------|
                  U10  DIR.  US   CD  TAUW
    HS    TP    TM   TM1   TM2  DIR. SPR.
    HS    TP    TM   TM1   TM2  DIR. SPR.
    HS    TP    TM   TM1   TM2  DIR. SPR.
  YYYYMMDDHHMMSS [M/S][DEG][M/S][1000] [%]
   [M]   [S]   [S]   [S]   [S] [DEG][DEG]
   [M]   [S]   [S]   [S]   [S] [DEG][DEG]
   [M]   [S]   [S]   [S]   [S] [DEG][DEG]
1960 01 01 00 00 00 
1960 01 01 01 00 00
yyyy mm dd hh mm ss

 
 19600101000000   7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26.  0.67  4.74  3.68  3.34  3.09 271.  21.  0.58  5.73  5.59  5.38  5.22 236.  19.
 19600101010000   7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26.  0.67  4.74  3.68  3.34  3.09 271.  21.  0.58  5.73  5.59  5.38  5.22 236.  19.
...
 19601231230000   7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26.  0.67  4.74  3.68  3.34  3.09 271.  21.  0.58  5.73  5.59  5.38  5.22 236.  19.
 
TIME SERIES OF INTEGRATED PARAMETERS AT EstGME-51-01         LAT. =   18.05000 LONG. =  272.1500
 |----- DATE ----|-------- WIND ----------
 |--------------- WAVES -----------------
 |--------------- WINDSEA ---------------
 |--------------- SWELL ----------------|
                  U10  DIR.  US   CD  TAUW
    HS    TP    TM   TM1   TM2  DIR. SPR.
    HS    TP    TM   TM1   TM2  DIR. SPR.
    HS    TP    TM   TM1   TM2  DIR. SPR.
  YYYYMMDDHHMMSS [M/S][DEG][M/S][1000] [%]
   [M]   [S]   [S]   [S]   [S] [DEG][DEG]
   [M]   [S]   [S]   [S]   [S] [DEG][DEG]
   [M]   [S]   [S]   [S]   [S] [DEG][DEG]
 
 19600101000000   7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26.  0.67  4.74  3.68  3.34  3.09 271.  21.  0.58  5.73  5.59  5.38  5.22 236.  19.
 19600101010000   7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26.  0.67  4.74  3.68  3.34  3.09 271.  21.  0.58  5.73  5.59  5.38  5.22 236.  19.
...
 19601231230000   7.2 278. 0.26 1.34 0.72  0.88  5.73  4.50  3.99  3.64 255.  26.  0.67  4.74  3.68  3.34  3.09 271.  21.  0.58  5.73  5.59  5.38  5.22 236.  19.
 
I made a C program to get rid off the headers and the date data so I've got an ascii file with only the valuable data
Thanks a bunch
Arturo
 
 
----- Original Message -----
Sent: Friday, February 12, 2010 1:30 PM
Subject: Re: [ferret_users] Reading variables from an ascii file

Hi Arturo,
We can help you better if you write back and show a sample of what the data look like.  What is in each block of data?

Ansley

Arturo Avila Rosas wrote:
Dear ferreters,
How do I read an ascii file wich contains anual data from a grid of stations located in the gulf?
Blocks of columns of variables are listed hourly from the first to the last day of the year. This
is done for each station so as to complete with all the stations.
Cheers
Arturo

[Thread Prev][Thread Next][Index]

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

Privacy Policy | Disclaimer | Accessibility Statement