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

Adv advita6 at gmail.com
Wed Nov 4 11:23:58 MST 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151104/fd3c6376/attachment.html 


More information about the ncl-talk mailing list