[Thread Prev][Thread Next][Index]

Re: [ferret_users] Reading variables from an ascii file



Hi Ansley,
Thanks a lot, it works fine! Now, some data are over land and they are NaN values indeed. According to "Setting a missing value" at Ferret FAQ having an ocean mask with earth's surface may help to get only data over ocean, Where could I find an ocean mask with earth's surface at 0.2 minute resolution?
Cheers
Arturo
 
----- Original Message -----
Sent: Tuesday, February 16, 2010 1:29 PM
Subject: 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


[Thread Prev][Thread Next][Index]

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

Privacy Policy | Disclaimer | Accessibility Statement