Re: write_matrix

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri Oct 21 2011 - 15:47:27 MDT

I think you just have "p" transposed. Try treating it as a K x I (4 x 12) variable and not 12 x 4.

Or, you can use "sprintf" instead, to create a big list of strings, and then write to this to a file using asciiread.

Here's a sample:

nvals = 100
PBL = random_uniform(-5.,5.,nvals)
TEMP2 = random_uniform(0.,300.,nvals)
WSPD10 = random_uniform(0.,70,nvals)
WDIR0 = random_uniform(0,360.,nvals)

fmtx = "%14.6f"

title = " PBL(m) TEMP2(K) WSPD10(m/s) WDIR10(DEGREES)"
vals = sprintf(fmtx,PBL) + " " + sprintf(fmtx,TEMP2) + " " + \
        sprintf(fmtx,WSPD10) + " " + sprintf(fmtx,WDIR0)

strs = new(nvals+1,string)
strs(0) = title
strs(1:) = vals
asciiwrite("test.txt",strs)

--Mary

On Oct 21, 2011, at 2:55 AM, cnl88 wrote:

> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "/usr/local/ncl/lib/ncarg/nclscripts/wrf/WRF_contributed.ncl"
> load "/usr/local/ncl/lib/ncarg/nclscripts/csm/contributed.ncl"
> ;************************************************
> begin
> big = asciiread("./nlcheng3-4chuance2.txt",(/6336,4/),"integer")
> line = 6336
> yy = new((/line/),integer)
> hh = new((/line/),integer)
> nn = new((/line/),integer)
> mm = new((/line/),integer)
> do x =0,11
> yy(x) = big(x,0)
> hh(x) = big(x,1)
> nn(x)= big(x,2)
> mm(x) = big(x,3)
>
> fn = "/home/nlcheng/huatu111111111/cmaq/chou/ln/METCRO2D_"+yy(x)+".nc"
> a = addfile(fn,"r")
> fon = "nlcheng-result.txt"
> t=hh(x)
> m=mm(x)
> n=nn(x)
> PBL = a->PBL(t,0,m,n)
> TEMP2= a->TEMP2(t,0,m,n)
>
> WSPD10 = a->WSPD10(t,0,m,n)
> WDIR10=a->WDIR10(t,0,m,n)
>
> I = 12 ; number of elements per variable
> K = 4 ; number of variables (1D arrays)
>
> p = new ( (/I,K/), typeof(PBL) )
> p(x,0) = PBL
> p(x,1) = TEMP2
> p(x,2) = WSPD10
> p(x,3) = WDIR10
> fmtx = "4f12.6"
> opt = True
>
> opt@title = "PBL(m) ,TEMP2(K), WSPD10(m/s) ,WDIR10(DEGREES)"
>
> write_matrix (p,fmtx, opt )
>
> end do
> end

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Oct 21 15:47:38 2011

This archive was generated by hypermail 2.1.8 : Mon Oct 24 2011 - 09:29:35 MDT