[Thread Prev][Thread Next][Index]

Re: [ferret_users] Reading an ascii file: longitute latitute variable

Hi Angela,
It looks as if your data is on a regularly spaced grid, so the longitude and latitude points listed are not single axes but instead represent the whole grid.  There are a couple ways to handle this.

If you are doing just this one problem, and if the grid is regularly spaced, then a quick and easy way to define the right grid is to just look at your file and see what the axis definitions should be, and define the axes without specifically reading the coordinates into Ferret. This would go something like this:
yes? define axis/x=-53:120:0.5/units=degrees xaxis
yes? define axis/y=68.5:88.5:0.5/units=degrees yaxis

(or whatever the true ranges and delta-values are in the file)

yes? ! Define the grid and read, skipping the first two values in each input record.
yes? define grid/x=xaxis/y=yaxis xygrid
yes? file/var="dummy1,dummy2,dry"/grid=xygrid  myfile.txt
If you want a more general script, or if the spacing of the grid is not even, then you'll need to first use the data in the file to define the axes and then define a grid to read the data field. (Try LIST or PLOT commands with these different variables to see what we're doing here.)
yes? file/var="xpoints,ypoints"  myfile.txt

yes? ! The first N points of the variable xpoints will define the x axis. 
yes? ! Let's find where xpoints starts to repeat itself.
yes? ! Where does the first derivative cross zero?

yes? let xdif = xpoints[i=@ddf]

yes? let xcross = xdif[i=@evnt:0]
yes? let npts = `xcross[i=@loc:1]`  ! the first place xcross crosses 0.

yes? ! Now use the first npts of the data from the file to define the axis
yes? define axis/x/units=degrees xaxis = xpoints[i=1:`npts`]

yes? ! the values for the y axis should be the first value of ypoints,
yes? ! then one point every `npts` after that
yes? let total = `ypoints,return=isize`  ! total points read from the file
yes? define axis/y/units=degrees yaxis=ypoints[i=1:`total`:`npts`]

yes? ! Now define the grid and read the variable
yes? cancel data myfile.txt

yes? define grid/x=xaxis/y=yaxis xygrid
yes? file/var="dummy1,dummy2,dry"/grid=xygrid  myfile.txt
I'll put this into an FAQ - seems like something people must run into all the time.

AV Gallego-Sala wrote:
Dear Ferret Users,

I am new to Ferret and would be very grateful if somebody could help me
with a "simple" problem. I am using FERRET v5.70 (alpha) on a Mac OS X
10.5.6 and I don't seem to be able to read a simple ascii file of the
following kind:

  -53.500000       68.500000      0.99750608
  -53.000000       68.500000      0.99756086
  -52.500000       68.500000      0.99761266
  -52.000000       68.500000      0.99761307
  -51.500000       68.500000      0.99767214
  -51.000000       68.500000      0.99771249
  -50.500000       68.500000       0.0000000

where the first column is the longitude, the second is the latitude and
the last is the variable (dryness index).

I tried:

FILE/VAR=xpoints,ypoints,dry filename
DEFINE AXIS/from_data/X/name=xaxis/UNITS=degrees xpoints
 **ERROR: improper grid or axis definition: data for DEFINE
AXIS/FROM_VARIABLE is not monotonic

I then thought perhaps the longitude needs to be sorted monotonically, so
I changed the file so that the longitude increased all the time, this
worked for the x axis, but still got the same error for the y axis (which
of course is not monotonic now):

FILE/VAR=xpoints,ypoints,dry filename
yes? DEFINE AXIS/from_data/X/name=xaxis/UNITS=degrees xpoints
 *** NOTE: Axis has repeated values -- micro-adjusting ...
yes? DEFINE AXIS/from_data/Y/name=yaxis/UNITS=degrees ypoints
 **ERROR: improper grid or axis definition: data for DEFINE
AXIS/FROM_VARIABLE is not monotonic

Anybody has any suggestions? I will so very, very grateful!


[Thread Prev][Thread Next][Index]

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

Privacy Policy | Disclaimer | Accessibility Statement