[ncl-talk] Sub: Array

Mary Haley haley at ucar.edu
Sun Nov 1 22:08:31 MST 2015


Adv,

Please do not post the same question to ncl-talk twice. Usually somebody
will try to answer as soon as they can, but we all have very busy jobs and
can't always answer within a day. We also don't usually check ncl-talk
emails on the weekend.

What you are asking for, if I understand correctly, is to simply make
"tavg" a 1D array of the number of stations you have.

Right outside your "do" loop, add the two lines:

ns = dimsizes(n)
tavg = new(ns,float)

Then, in the do loop where you calculate "tavg", simply change it to
tavg(i):

do i =0,ns-1
   ...
​  ​
tavg
​(i)​
=avg(data)
end do


On Fri, Oct 30, 2015 at 10:59 PM, Adv <advita6 at gmail.com> wrote:

> Hi NCL user,
>
> I would like to write final average corresponding to two different
> stations to single array.
> Could someone help me to accomplish this?
>
> Thank you,
> Adv
>
>  fkey   = "minnesota"
> strs=asciiread("minnesota50.csv" , -1, "string")
> ;***********************************************
> ; user specified YYYYMM and VARIABLE
> ;***********************************************
>   yyyymm = 197301
>   fldstr = "PRCP"                                         ; case sensitive
>   con    = 1.00
>   dat=new((/1/),float)
> ;***********************************************
> ; match all data lines with specified YYYYYY
> ;***********************************************
>
>   seldata = str_match_ic_regex(strs, tostring(yyyymm))    ; 6.3.0
> ;  seldata = str_match_ic_regex(strs, 1973)    ; 6.3.0
> ;  print(seldata)
>   print("=====")
> n=(/"THIEF","PARK"/)
> print(n)
>
> do i =0, dimsizes(n)-1
> strkey = n(i)
> print(strkey)
> ;strkey= "THIEF"
> ;print(strkey)
> ;return
> ; find all lines (rows) which contain the key string
>
>   seldata1 = str_match_ic_regex(seldata, strkey)     ; 6.3.0  onward
> print(seldata1)
> print(dimsizes(seldata1))
> ;***********************************************
> ; write selected data to ascii file
> ;***********************************************
>
>   seldir  = "./"
>   selfil  = fkey+"."+yyyymm+".csv"
>   system("/bin/rm -f "+seldir+selfil)
>   asciiwrite(seldir+selfil, seldata1)   ; all data for selected yyyymm
> ;***********************************************
> ; Which field matches
> ;***********************************************
> FIELDS = (/"STATION","STATION_NAME","ELEVATION","LATITUDE","LONGITUDE"    \
>           ,"DATE","MDPR","MDSF","DAPR","DASF","PRCP","SNWD","SNOW"        \
>           ,"TMAX","TMIN","TOBS"
> /)
>
>
>   nfield = ind(FIELDS.eq.fldstr) + 1      ; field to be extracted
>   print("fldstr="+fldstr+" corresponds to field number "+nfield)
>   print("=====")
> ;***********************************************
> ; extract the values
> ;***********************************************
>
>   sdat   = str_get_field(seldata1 , 2, ",")
> ;*********Monthly average********************************
>   data   = tofloat( str_get_field(seldata1 , nfield, ",") )*con
>   data at _FillValue = -9999*con
>   print(sdat+" : "+data)
>  print("=====")
> ;print(data)
> ;return
> tavg=avg(data)
> end do
> print(tavg)
> return
>
>
> _______________________________________________
> 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/20151101/a11fc372/attachment.html 


More information about the ncl-talk mailing list