Re: Writing ascii file

From: Debasish <debasish_at_nyahnyahspammersnyahnyah>
Date: Mon Aug 30 2010 - 11:19:46 MDT

Dear Soumik,

Please check the example 4 in the webpage

http://www.ncl.ucar.edu/Document/Functions/Built-in/asciiwrite.shtml

GoodLuck

Debasish

On 2010-08-30, at 13:03, sbasu@iarc.uaf.edu wrote:

> Hello,
>
> I want to write a 256*128 dataset in asii file. I want my format to be:
> lon,lat,slp_mon
> where lon and lat to be the actual longitude and latitude values from the
> netcdf file that I am using.
> Here is my code that I am trying to use:
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>
> begin
>
> ;***********************************************
> ;read in netcdf data
> ;***********************************************
>
> in = addfile("./ctrl.cam2.h0.1997-11-01-00000.nc","r")
> slp = in->PSL(123:246,:,:)
> lat = in ->lat
> lon = in->lon
> slp=slp/100 ;convert Pa to hPa
>
> printVarSummary(lon)
> ;***********************************************
> ;Calculate monthly mean
> ;***********************************************
>
> slp_mon = dim_avg( slp(lat|:, lon|:, time|:) ) ;to reorder the array so
> that time is the rightmost dimension
>
> printVarSummary(slp_mon)
> printVarSummary(lat)
> printVarSummary(lon)
>
> ;************************************************
> ;Write the monthly mean to ascii file
> ;************************************************
> slp_1d = new ((/32768/) , "float")
> lon_1d = new ((/32768/) , "float")
> lat_1d = new ((/32768/) , "float")
>
> data = new ( (/ 3, 32768 /) , "float")
>
> data (0,:) = slp_1d
> data (1,:) = lon_1d
> data (2,:) = lat_1d
>
> index =0
> do j =1,255
> do i =1,127
> slp_1d(index)= slp_mon(i,j)
> lon_1d(index) = j
> lat_1d(index) = i
> end do
> end do
>
> fmtx = "f3.4,6x,f3.4,6x,f4.5"
>
> write_matrix(data,fmtx, False)
>
>
> ;************************************************
> ;Check
> ;************************************************
> print("OK")
>
> end
>
>
> Thanks,
> --
> *************************************
> Soumik Basu
> Graduate Student, Research Assistant
> International Arctic Research Center
> University of Alaska Fairbanks
> Fairbanks,Alaska,USA
> **************************************
>
>
> -----------------------------------------
> This email was sent using SquirrelMail.
> "Webmail for nuts!"
> http://squirrelmail.org/
>
> _______________________________________________
> 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 Aug 30 11:21:21 2010

This archive was generated by hypermail 2.1.8 : Thu Sep 09 2010 - 05:56:39 MDT