[Thread Prev][Thread Next][Index]

Re: [ferret_users] ASCII DATA



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
> 

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement