[Thread Prev][Thread Next][Index]
Re: [ferret_users] ASCII DATA
Hi Jaison & William
Thanks for your detailed solutions for my problem. I read the data
sucessfully by the method described by William.
I am reading lat/lon information form file because I want to plot data with 3 arguments shade
command.Like,
shade pre,lon,lat.
With Regards
Ashley
On 12/12/06, William S. Kessler <William.S.Kessler@noaa.gov> wrote:
Hi Ashley -
Is there a reason why you need to read the lon,lat values in the
file? It sounds as if you already know the axis information (since
you are defining a grid based on some knowledge of the structure).
What is the point of having lon and lat on a lat/lon/time grid?
But if you do want to keep this information, one way is to do 2
separate reads. It requires knowing the format of the data records
(or a careful read of Chapter 2, section
5.2 of the manual on
"delimited reads"), or see the last block below for a kluge.
! first read lon,lat
define axis/x=8.0833E:22.917E/npo=90 xaxis
define axis/y=48.083:53.917/npo=36 yaxis
define grid/x=xaxis/y=yaxis mygridxy
file/var="lat,lon"/g=mygridxy/ord=xy mydatafile.dat ! note: need
those quotes around the variable list!
! save the lon,lat variables for later use
save/file=saved_lon_lat.cdf lon,lat
! now read the data pre, knowing the fortran format of the file
! if you decided that you don't really need lon,lat, then just start
here
define axis/t=15-SEP-1988:14-AUG-1989:`365.2425/12`/units=days/T0=15-
SEP-1988 taxis
define grid/x=xaxis/y=yaxis/t=taxis mygridxyt
file/format=(12x,12f9.1)/var=pre/g= mygridxyt/col=12/ord=xyt
mydatafile.dat
! I have "guessed" at the format, note the use of "12x" to skip 12
spaces at the beginning of each record
! if you don't know the format, or if it is free format, then you can
still do this as in step 1 above,
! using an extra write/read to force a format
file/
var="lat,lon,pre1,pre2,pre3,pre4,pre5,pre6,pre7,pre8,pre9,pre10,pre11,pr
e12"/g=mygridxy/ord=xy mydatafile.dat
! write it out to a dummy file
list/nohead/format=(12f9.1)/file=dummy.dat
pre1,pre2,pre3,pre4,pre5,pre6,pre7,pre8,pre9,pre10,pre11,pre12
! now read it back in, on the grid you want
file/format=(12f9.1)/var=pre/g= mygridxyt/col=12/ord=xyt dummy.dat
I think that will work!
Billy K
On Dec 11, 2006, at 2:41 PM, Jaison Kurian wrote:
> Hi Ashley,
>
Your ascii file is not in a format which can be properly
> opened in Ferret. Columns 3-14 contains data on an XYT grid, which
> should be readed along the line/row using /COLUMNS qualifier. But the
> presence of lon and lat in the first 2 columns makes this jobs diffi-
> cult. Ferret can skip lines/rows easily, but not columns. There are
> many Linux "text" commands which can modify the original ASCII data
> to a format which can be opened in Ferret.
>
> Here is an example using "awk" utility in Linux/Unix (you can
> also try commands like column, cut, sed, colrm etc). Modify this
> example according to your ASCII data and give a try. Please let me
> know if you have any problems with this method.
>
> Regards,
>
> Jaison
>
> Example for reading ASCII data after removing first 2-columns
> -------------------------------------------------------------
> Suppose you have an ascii file with 3-lon, 2-lat & 12-time points,
> arranged as Lon, lat, data(t=1:12) ..like this
>
>
1 1
1 2 3 4 5 6 7 8 9 10 11 18
>
2 1
0 8 9 7 6 5 4 2 3 19 10 13
>
3 1
5 3 2 4 9 3 2 6 2 16 14 12
>
1 2
1 2 3 4 5 6 7 8 9 10 11 18
>
2 2
0 8 9 7 6 5 4 2 3 19 10 14
>
3 2
5 3 2 4 9 3 2 6 2 16 14 12
>
> in a file latlon_prec.dat. Then try as follows
>
> !-----------------jnl file starts
> here---------------------------------
> ! If you precisely know the lat lon points to define the grid, then
> you
> ! don't need the first two columns of the ASCII data. Also ferret
> ! will not skip "columns". Remove first two columns using awk
> command
> ! as follows, save the resulting data to an intermediate file
>
> spawn rm -f prec.dat ! remove if this intermediate file exists
> spawn awk '{$1=$2=""; print}' latlon_prec.dat > prec.dat
>
> ! define input grid
>
> define axis/x=1:3:1 xax
> define axis/y=1:2:1 yax
> define axis/t=1:12:1 tax
> define grid/x=xax/y=yax/t=tax gfile
>
> ! read in data from the intermediate file
> ! give the proper ORDER in which data is arranged--> along a line/
> row
> ! time varies fastest (since we are reading with COLUMNS qualifier)
> ! so T should come first....choose X and Y as required...
>
> FILE/grid=gfile/ORDER=TXY/COLUMNS=12/var=prec
prec.dat
>
> list/i=3/j=2 prec ! check if data has been properly read
>
> set var/bad=-999.99/title="My variable"/units="my_units" prec
>
> ! do your calculations here
>
> ! save the data if you need to access it easily in future..
>
> ! sp rm -f savedata.nc
> ! save/file=savedata/APPEND prec
> ! save/file=savedata/APPEND other, variables, here
>
> ! remove the intermediate file
>
> sp rm -f prec.dat
> !---------------------------------------------------------------------
> ---
>
> On Mon, 4 Dec 2006, Ashley Watson wrote:
>
>> Hi everyone,
>>
>> I'm trying to read an ASCII data file with 3 variables. The file
>> looks like:
>>
>> lon lat Pre(t=1) Pre(t=2) ............Pre(t=12)
>> .....................................................................
>> ...............
>> .....................................................................
>> ...............
>> .....................................................................
>> ..............
>>
>> So there are 14 columns in datafile. The first two variables are
>> lat, lon
>> and the third one is variable with 12 timesteps.
>> I tried to read this data with commnds:
>>
>> define axis/x=8.0833E:22.917E/npo=90 xaxis
>> define axis/y=48.083:53.917/npo=36 yaxis
>> define
>> axis/t=15-SEP-1988:14-AUG-1989:`365.2425/12`/units=days/T0=15-
>> SEP-1988 taxis
>> define grid/x=xaxis/y=yaxis/t=taxis mygrid
>> file/var=lat,lon,pre/grid=mygrid/col=14/order=xyt mydatafile.dat
>>
>>
>> It does'nt work. show data command shows:
>>
I J K
L
>> lon
1:90 1:36 ...
1:12
>>
lat
1:90 1:36 ...
1:12
>> pre
1:90 1:36 ...
1:12
>>
>> The problem is L should be 1 for lat, lat variables. Whats wrong. Any
>> suggestion
>>
>> Ashley
>>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
William S. Kessler
NOAA / Pacific Marine Environmental Laboratory
7600 Sand Point Way NE
Seattle WA 98115 USA
william.s.kessler@noaa.gov
Tel: 206-526-6221
Fax: 206-526-6744
Home page: http://www.pmel.noaa.gov/people/kessler/
[Thread Prev][Thread Next][Index]
Dept of Commerce /
NOAA /
OAR /
PMEL /
TMAP
Contact Us | Privacy Policy | Disclaimer | Accessibility Statement