[ncl-talk] NCL Help

Dennis Shea shea at ucar.edu
Tue Nov 24 07:27:13 MST 2015


Please respond to ncl-talk only.  We are way too busy to handle direct
emails. Please read the documentation on all the functions used.

==
k     = 5
sta   = new(k, "string")
Temp := new((/k,3/), "float") ;k for no of stations and 3 for 3 days values
RH   := new((/k,3/), "float")
WS   := new((/k,3/), "float")
WD   := new((/k,3/), "float")
Time  = 201411050800l

sta   = (/ "A", "B", "C", "D", "E" /)     ; fill with values
Temp  = random_uniform(5,  15, (/k,3/))
RH    = random_uniform(50, 95, (/k,3/))
WS    = random_uniform( 0, 15, (/k,3/))
WD    = random_uniform( 0,360, (/k,3/))

delim = conform_dims( k, "|", -1)         ; make a one-dimensional vector
print(delim)

        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(:,0),RH(:,0),WS(:,0),WD(:,0),delim, \

Temp(:,1),RH(:,1),WS(:,1),WD(:,1),delim, \

Temp(:,2),RH(:,2),WS(:,2),WD(:,2)    /], \
                                                  "%s %f %f %f %f %s
%f %f %f %f %s %f %f %f %f")


On Mon, Nov 23, 2015 at 9:33 PM, Arun Kumar Dwivedi
<dwivedi.arunkumar at gmail.com> wrote:
> Hello
> Thanks for the help
> It my mistake to not illustrate the problem correctly.
> Actually the number of stations are not fixed they are supplied from an
> external file and all the parameters will be written for three days side by
> side (separate by a vertical line ). This may be looks likes follow--
>
> k represents the number of stations
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> sta     = new(k, "string")
> Temp := ((/k,3/), "float") ;k for no of stations and 3 for 3 days values
> RH := ((/k,3/), "float")
> WS := ((/k,3/), "float")
> WD := ((/k,3/), "float")
> Time = 201411050800l
>
>         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,"|", Temp,RH,WS,WD,"|",
> Temp,RH,WS,WD,/],"%s %f %f %f %f %s %f %f %f %f %s %f %f %f %f")
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> where red, green and blue colors represent 1st,2nd and 3rd days value
> respectively.
>
>
>  How to write my values in this manner because no. of stations are not fixed
> and I have to write one station values below another one line by line
>
> On Mon, Nov 23, 2015 at 11:15 PM, Dennis Shea <shea at ucar.edu> wrote:
>>
>> 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
>> >
>
>
>
>
> Thanks & Regards
> Arun Kumar Dwivedi,
>


More information about the ncl-talk mailing list