[ncl-talk] Sub: Array

Adv advita6 at gmail.com
Fri Oct 30 22:59:51 MDT 2015


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


More information about the ncl-talk mailing list