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