[ncl-talk] NCL Help

Dennis Shea shea at ucar.edu
Mon Nov 23 10:45:07 MST 2015


You must be very careful about variable types. They *must* match the
format specification.
I do not know why you used a 'do' loop. Each iteration over-wrote the
previous iteration

Time = 201411050800    ; this is a 'long' integer

===

sta     = (/"Mum", "RNC", "CNB"/)
Temp = (/30, 20, 25/)                       ; integers
RH     = (/80, 900, 95/)
WS     = (/2, 3, 4/)
WD    = (/80, 150, 95/)
Time = 201411050800l                  ; this is a 'long' int

; Temp, RH, WS, WD are all integers; use    %i

        fil_I = "foo_I.txt"
        system("/bin/rm -f "+fil_I)                       ; remove any
pre-existing file

        write_table(fil_I, "w", [/Time/], "%li")      ; note 'li'
=> long integer
        write_table(fil_I, "a", [/"Station","Temp","RH","WS","WD"/],
"%s %s %s %s %s ")
        write_table(fil_I, "a", [/sta,Temp,RH,WS,WD/],"%s %i %i %i %i")

; change to float; use := syntax to overwrite previous integer type;
%f to write

Temp := (/30, 20, 25/)*1.0
RH     := (/80, 900, 95/)*1.0
WS    := (/2, 3, 4/)*1.0
WD    := (/80, 150, 95/)*1.0

        fil_F = "foo_F.txt"
        system("/bin/rm -f "+fil_F)   ; remove any pre-existing file
        write_table(fil_F, "w", [/Time/], "%li")
        write_table(fil_F, "a", [/"Station","Temp","RH","WS","WD"/],
"%s %s %s %s %s ")
        write_table(fil_F, "a", [/sta,Temp,RH,WS,WD/],"%s %f %f %f %f")

On Mon, Nov 23, 2015 at 4:58 AM, Arun Kumar Dwivedi
<dwivedi.arunkumar at gmail.com> wrote:
> Hello,
> I  need some help in my ncl script. I want to write some cities name and
> their corresponding data in one text file but it is getting replaced every
> time. how to do it in correct manner? My script is as follows
>
>
> 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"
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> begin
>
>
> sta = (/"Mum", "RNC", "CNB"/)
> Temp = (/30, 20, 25/)
> RH = (/80, 900, 95/)
> WS = (/2, 3, 4/)
> WD = (/80, 150, 95/)
> Time = 201411050800
>
>     do k = 0,2,1
>
>     write_table("ex.txt", "w", [/Time/], "%i")
>     write_table("ex.txt", "a", [/"Station","Temp","RH","WS","WD"/], "%s %s
> %s %s %s ")
>     write_table("ex.txt", "a", [/sta(k),Temp(k),RH(k),WS(k),WD(k)/],"%s %f
> %f %f %f")
>
>   end do
>
>
> end
>
> Thanks & Regards
> Arun Kumar Dwivedi,
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>


More information about the ncl-talk mailing list