load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRF_contributed.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl" begin ;--ASK FOR USER INPUT------------------------------------ ;-------------------------------------------------------- ;print("==============> Type wrfout file complete path :") ;fname = systemfunc("read ifland; echo $ifland") ; print("Opening file: "+fname+".nc") ;-OPEN WRF FILE & GET GPS COORDS------------------------- ;-------------------------------------------------------- ; f = addfile ("/import/wrkdir1/asemenov/WRF/WRFV3/CFSR_experiment/wrfout_d02_2011-03-15_00:00:00"+".nc", "r") ;f = addfile ("/import/wrkdir1/asemenov/WRF/WRFV3/10_25.03_res_30_10km/wrfout_d02_2011-03-15_00:00:00"+".nc", "r") f = addfile ("/import/wrkdir1/asemenov/WRF/WRFV3/CFSR_experiment/wrfout_d01_2011-03-15_00:00:00"+".nc", "r") wrflat = f->XLAT(0,:,:) wrflon = f->XLONG(0,:,:) ;-GET STATIONS NAMES & GPS COORDS------------------------ ;-------------------------------------------------------- path = "/import/wrkdir1/asemenov/process-model-output/ncdc/station-files/" coor = readAsciiTable(path+"stations-coords.txt", 2, "float", 0) names = readAsciiTable(path+"stations-name-205.txt", 1, "string", 0) ;-CREATE ARRAYS TO HOLD DATE/COORDS/DATA----------------- ;-------------------------------------------------------- col01 = new( (/181/), "float") ; col01 = new( (/43/), "float") col01@_FillValue = -999.00 col02 = col01 col03 = col01 col04 = col01 col05 = col01 col06 = col01 col07 = col01 col08 = col01 col09 = col01 col10 = col01 col11 = col01 col12 = col01 ;-GET THE 61 COMPLETE TIMES------------------------------ ;-------------------------------------------------------- date = chartostring (wrf_user_getvar(f,"Times",-1) ) print(date) yr = stringtofloat (str_get_cols(date,0,3) ) mo = stringtofloat (str_get_cols(date,5,6) ) dy = stringtofloat (str_get_cols(date,8,9) ) hr = stringtofloat (str_get_cols(date,11,12) ) delete(date) ;-SAVE TO ARRAY------------------------------------------ ;-------------------------------------------------------- printVarSummary(col01) printVarSummary(yr) col01 = yr col02= mo col03= dy col04= hr ;-GET VARIABLES FOR ALL TIMES AND ALL DOMAIN------------- ;-------------------------------------------------------- print("Retrieving variables...") tk = wrf_user_getvar(f,"T2",-1) t = tk - 273. delete(tk) print("Temperature ok. Size: "+sizeof(t)) td = wrf_user_getvar(f,"td2",-1) print("Dewpoint ok. Size: "+sizeof(td)) rh = wrf_user_getvar(f,"rh2",-1) print("RH ok. Size: "+sizeof(rh)) u = wrf_user_getvar(f,"U10",-1) v = wrf_user_getvar(f,"V10",-1) spd = (u*u+v*v)^0.5 r2d = 45.0/atan(1.0) dir = atan2(u,v) * r2d + 180 print("Wind ok. Size: "+sizeof(spd)+" and "+sizeof(dir)) delete(u) delete(v) slp = wrf_user_getvar(f,"slp",-1) print("SLP ok. Size: "+sizeof(slp)) ;-LOOP THROUGH 205 STATIONS------------------------------ ;-------------------------------------------------------- do n=0,101-1 print("------ n = "+n+"------") lat = coor(n,0) lon = coor(n,1) col05 = lat col06 = lon sname = names(n,0) print("------ "+sname+"------") ;-GET NEAREST I,J TO STATION LON,LAT--------------------- ;-------------------------------------------------------- ; loc = wrf_user_ll_to_ij(f, lon, lat, True) ; locX = loc(0) ; locY = loc(1) ; print("i for lon "+lon+" is "+loc(0)) ; print("j for lat "+lat+" is "+loc(1)) ;OR............. ;-INTERPOLATE VARIABLE TO DESIRED STATION---------------- ;-------------------------------------------------------- col07 = rcm2points(wrflat,wrflon,t, lat,lon,0) col08 = rcm2points(wrflat,wrflon,td, lat,lon,0) col09 = rcm2points(wrflat,wrflon,rh, lat,lon,0) col10 = rcm2points(wrflat,wrflon,spd, lat,lon,0) col11 = rcm2points(wrflat,wrflon,dir, lat,lon,0) col12 = rcm2points(wrflat,wrflon,slp, lat,lon,0) ;-SAVE AND WRITE VALUES FOR STATION---------------------- ;-------------------------------------------------------- array = (/ col01, col02, col03, col04, col05, col06, col07, col08, col09, col10, col11, col12 /) array_transposed = transpose(array) opt = True opt@fout = "wrfout_d02_2011-03-15_00:00:00_"+sname+".txt" fmtx = "12f12.2" write_matrix(array_transposed, fmtx , opt) end do end