Re: How to write a ASCII file using NCL

From: IMRAN NADEEM <qphoton_at_nyahnyahspammersnyahnyah>
Date: Mon, 2 Mar 2009 13:11:52 +0100

Hi Amjad,

Task: Read grads binary file and write a time series of a variable at
particular grid box.

First step you need information about the binary file. You can get this
information from grads CTL file. A CTL file of one of RegCM3 output files
looks like:

pdef 70 60 lcc 47.00 10.50 35.00 30.00 30.00 60.00 10.50
90000. 90000.
xdef 321 linear -53.75 0.4054
ydef 138 linear 17.02 0.4054
zdef 23 levels 1008.43 998.80 984.35....................
tdef 124 linear 6z01dec1999 6hr
vars 13

clwp 23 0 cloud liquid water path (3D var)
qrs 23 0 solar heating rate (3D var)
qrl 23 0 longwave cooling rate (3D var)
frsa 0 99 surface absorbed solar flux (3D var)
frla 0 99 longwave cooling of surface (2D var)
clrst 0 99 clearsky total column abs solar flux
clrss 0 99 clearsky surface absorbed solar flux
clrlt 0 99 clearsky net upward LW flux at TOA
clrls 0 99 clearsky LW cooling at surface (W/m2
solin 0 99 instantaneous incident solar (W/m2)
sabtp 0 99 total column absorbed solar flux W/m
firtp 0 99 net upward LW flux at TOA (W/m2)
endvars

Here mlon = 70 Number of grid points in east-west direction
        nlat = 60 Number of grid points in north-south direction
        ntim = 124 Number of timesteps
        nvar = 13 Total number of variables
        n3d = 3 No. of 3D variables
        n2d = 10 No. of 2D variables

 Variables are written in binary files in the order given in CTL file.

The order in which these variables are written in Binary file is described
here:

http://www.iges.org/grads/gadoc/aboutgriddeddata.html

The attached script read a simple grads binary file whose CTL file is also
attached. I will send you binary in separate email.
The file contains time series of daily mean temperature for year 1986. The
scripts reads the file and write NetCDF output.
It also writes time series of temperature values at particular grid box in
ASCII file. Time and Temperature are written in two
separate ASCII files as 1D time series. You can join them with linux paste
command:

                                paste Time.txt Temp.txt > Temperature.txt

By adding suitable loops and following the order of data written, you can
read and write more complicated files.

Regards
Nadeem

On Fri, Feb 20, 2009 at 7:13 AM, Muhammad Amjad <callamjad_at_gmail.com> wrote:

> Dear All,
>
> I want to write the following grads script in NCL for 3 hourly output
> of WRF model. Can any body help! It will be more encouraging if I that
> script can write time step with that magnitude of wind.
>
> ____________________________________________________________
> 'reinit'
> 'open file.ctl'
> 'set lat 25.0'
> 'set lon 60.0'
>
> res = write('wind.txt',''wind speed'')
>
> t=1
> tmax=660
> while (t<=tmax)
> 'set t 't
>
> 'define d1 = mag(u10,v10)'
>
> 'd d1' ; rec1 = sublin(result,1) ; value1 = subwrd(rec1,4)
>
> res = write('wind.txt',''value1'')
>
> t = t+1
>
> endwhile
> ________________________________________________________________________
>
>
> Regards,
> Amjad.
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Received on Mon Mar 02 2009 - 05:11:52 MST

This archive was generated by hypermail 2.2.0 : Mon Mar 02 2009 - 16:45:42 MST