[ncl-talk] sub: array (monthly average ) or climatology ....

Alan Brammer abrammer at albany.edu
Wed Nov 4 11:30:06 MST 2015


Had this folder open so I’ll give you a quick reply. 

There’s a lot of code here and no explanation of why you need help?
Although it sometimes resembles it I believe this list isn’t really intended as a place to just quickly outsource your scripting desires. 

What have you tried?
What specific issue did you run into?
How is anyone on here supposed to know your data layout? 
Have you looked at the numerous climatology examples and previous ncl-talk questions? 
Where did the answers to the above questions fall short and thus what specifically is the problem?

Good luck. As always direct replies to the list.  Hopefully a more specific question lends it self to a more specific answer. 


Alan. 


> On 4 Nov 2015, at 13:23, Adv <advita6 at gmail.com> wrote:
> 
> Hi NCL user,
> 
> I would like to write final average corresponding to each station, monthly average of 42 years to a two dimensionl array.
> Could someone help me to accomplish this? 
> 
> Thank you,
> Adv
> 
> begin
> ;  diri   = "./"
>   fkey   = "minnesota"
> strs=asciiread("minnesota50.csv" , -1, "string")
> n1=(/"197301","197401","197501","197601","197701","197801"             \
> ,"197901","198001","198101","198201","198301","198401"                \
> ,"198501","198601","198701","198801","198901","199001"               \
> ,"199101","199201","199301","199401","199501","199601"                \
> ,"199701","199801","199901","200001","200101","200201","200301"       \
> ,"200401","200501","200601","200701","200801","200901"                \
> ,"201001","201101","201201","201301","201401"/)
> print(n1)
> ns1 = dimsizes(n1)
> print(ns1)
> do j =0, dimsizes(n1)-1
> 
> ;  yyyymm = 197301
>   yyyymm = n1(j)
>   fldstr = "PRCP"                                         ; case sensitive
>   con    = 1.00
> print(yyyymm)
> ;return
> ;***********************************************
> ; match all data lines with specified YYYYYY
> ;***********************************************
> 
> ;  seldata = str_match_ic_regex(strs, tostring(yyyymm))    ; 6.3.0
>   seldata = str_match_ic_regex(strs, tostring(yyyymm))    ; 6.3.0
> ;  print(seldata)
>   print("=====")
> n=(/"THIEF","PARK"/)
> print(n)
> ns = dimsizes(n)
> print(ns)
> tim = new((/ns1,ns/),"float")
> printVarSummary(tim)
> ;tavg = new((/ns1,ns/),"float")
> tavg = new(ns,float)
> print(tavg)
> 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(i)=avg(data)
> end do
> print(tavg)
> ;tim(j,i)=tavg
> end do
> 
> 
> 
> _______________________________________________
> 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