[ncl-talk] NCL code problem

Alan Brammer abrammer at albany.edu
Tue Jun 14 07:29:46 MDT 2016


Simple examples are always better. 
e.g.

alist = [/ 189., 25., 76., 34./]
write_table("list.txt", "a", alist, "%5.5f”)

;;
;;more list.txt
;189.00000


This also makes it easier for you to test the problem. 

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

> format
> The format for of each (first) element of the list.   

you need a format string for each column of your list (your list is only one row long but you still need a format for each column). 

e.g.

write_table("list.txt", "a", alist, "%5.5f %5.5f %5.5f %5.5f “)

dynamically you could get clever about it and do the below:

fmt = new( ListCount(alist), "string")
fmt = "%5.5f “  		 ;; only works if every column has the same format.
write_table("list.txt", "a", alist,   str_concat(fmt)   )  ;; turn array of formats into long string. 





Good luck. 

Alan





##############################
Alan Brammer,
Post-Doc Researcher

Department of Atmospheric and Environmental Sciences,
University at Albany, State University of New York, Albany, NY, 12222
abrammer at albany.edu
##############################


> On 14 Jun 2016, at 01:52, snow <snowflake_822 at yahoo.com> wrote:
> 
> 
>  
> To whom it may concern,
> 
> I have written a simple NCL code to extract and take the average of my data and write the table of my data. but in the write part the output is only one data instead of 4.
> 
> I wrote this email. to find any kind of help.
> 
> I appreciate your time and kindness.
> 
> Best regards,
> 
> Snow Sho
> 
> 
> this is the code:
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>> begin
>> ;----------------------------------------------------------------------
>> ; WRF data translate NetCDF file to  ascii file  
>> ;----------------------------------------------------------------------
>> 
>>     infile=("wrfout_d03_2007-07-24_00_00_00")
>>     fn=dimsizes(infile)
>>     fin=addfile(infile,"r")
>>     R=fin->RAINNC(0,:,:)
>>      a=(/189,193,191,192,192,193,192,188,198,196,192,187,197,194,190,187,197,196,195,195,196/)
>>      b=(/285,286,287,288,289,290,291,292,293,294,295,296,296,297,298,299,298,299,300,301,302/)
>>      c=(/180,174,172,181,179,173,184,175,185,174,184,173,183,193,182,191,179,189,178,188,176/)
>>      d=(/264,266,267,267,268,269,270,270,271,271,272,273,273,273,274,273,275,274,276,275,277/)
>>      e=(/202,205,206,206,198,197,206,205,204,202,200,200,200,200,210,209,205,202,212,208,204,203/)
>>      f=(/270,271,272,273,274,276,277,278,279,280,281,282,283,284,284,284,285,286,287,288,289,290/)
>>      g=(/208,208,209,210,211,210,207,205,215,212,213,215,216,207,209,210,211,214,215,209,211,215,214/)
>>      h=(/263,264,265,266,267,267,268,269,269,270,271,273,274,276,277,278,279,279,280,282,283,284,287/)
>>         R1=new((/21/),"float")        
>>         R2=new((/21/),"float")
>>         R3=new((/22/),"float")
>>         R4=new((/23/),"float")
>> 
>>         do k=0,20
>>         R1(k)=R(a(k),b(k))
>>         end do
>>      ;  print(R1)
>>         do k=0,20
>>         R2(k)=R(c(k),d(k))
>>         end do
>>         do k=0,21
>>         R3(k)=R(e(k),f(k))
>>         end do
>>         do k=0,22
>>         R4(k)=R(g(k),h(k))
>>         end do
>>         R5=avg(R1(:))
>>         R6=avg(R2(:))
>>         R7=avg(R3(:))
>>         R8=avg(R4(:))
>> 
>>         ca=new((/1/),"float")
>>         ca=(/R5/)
>>         cb=new((/1/),"float")
>>         cb=(/R6/)
>>         cc=new((/1/),"float")
>>         cc=(/R7/)
>>         cd=new((/1/),"float")
>>         cd=(/R8/)
>> 
>> ;   alist=[/R5,R6,R7,R8/]
>>    alist=[/ca,cb,cc,cd/]
>>   write_table("list.txt", "a", alist, "%5.5f")
>>   end
> 
> 
> 
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160614/b45db7e6/attachment.html 


More information about the ncl-talk mailing list