load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/popRemap.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/cd_string.ncl" begin plot_lat=69 plot_lon=24 plot_name="FINNMARK" plot_filename = "/home/uio/huit/postproc/plot_sel.txt" clim_output = "/usit/abel/u1/jennybj/inputdata/atm/1x1_"+plot_name+"/" clim_input = "/work/databases/geo/cesm/inputdata/atm/datm7/atm_forcing.datm7.cruncep_qianFill.0.5d.V4.c130305" system("mkdir -p "+ clim_output) cruCreat=True varCOMB=False varMOD=False timCOMB=False varTIMEsub=False mon = ispan(0,11,1) mon@units = "month" month =cd_string(mon,"%N") print(month) if (cruCreat) then do year=1901,2010,1 ; do m=1,11,1 m=0 frsds=addfile(clim_input+"/Solar6Hrly/clmforc.cruncep.V4.c2011.0.5d.Solr."+year+"-"+month(m)+".nc","r") fprec=addfile(clim_input+"/Precip6Hrly/clmforc.cruncep.V4.c2011.0.5d.Prec."+year+"-"+month(m)+".nc","r") ftphw=addfile(clim_input+"/TPHWL6Hrly/clmforc.cruncep.V4.c2011.0.5d.TPQWL."+year+"-"+month(m)+".nc","r") rsds=frsds->FSDS(:,:,:) prec=fprec->PRECTmms(:,:,:) psrf=ftphw->PSRF(:,:,:) tbot=ftphw->TBOT(:,:,:) wind=ftphw->WIND(:,:,:) qbot=ftphw->QBOT(:,:,:) lon=frsds->LONGXY(0,:) lat=frsds->LATIXY(:,0) time=frsds->time(:) edgew =frsds->EDGEW edgee =frsds->EDGEE edges =frsds->EDGES edgen =frsds->EDGEN longxy =frsds->LONGXY latxy =frsds->LATIXY loni=ind_nearest_coord(plot_lon, lon, 0) latj=ind_nearest_coord(plot_lat, lat, 0) print(loni) print(latj) ;### system("rm -f "+clim_output+"clm1pt_"+plot_name+"_"+year+"-"+month(m)+".nc") ; remove if exists fclim = addfile(clim_output+"clm1pt_"+plot_name+"_"+year+"-"+month(m)+".nc","c") ntim = dimsizes(time) ; get dimension sizes nlat = 1 nlon = 1 nscalar = 1 setfileoption(fclim,"DefineMode",True) fAtt = True ; assign file attributes fAtt@case_title = "CRUNCEP: norway " fAtt@conventions = "CF-1.0" fAtt@title = "CLM single point datm input data" fAtt@history = "Original data from CRUNCEP data" fAtt@creation_date = systemfunc ("date") fileattdef( fclim, fAtt ) ; copy file attributes dimNames = (/"scalar","lon","lat","time"/) dimSizes = (/ nscalar, nlon, nlat, -1 /) dimUnlim = (/ False, False, False, True/) filedimdef(fclim,dimNames,dimSizes,dimUnlim) filevardef(fclim, "EDGEW" ,typeof(edgew),getvardims(edgew)) filevardef(fclim, "EDGEE" ,typeof(edgee),getvardims(edgee)) filevardef(fclim, "EDGES" ,typeof(edges),getvardims(edges)) filevardef(fclim, "EDGEN" ,typeof(edgen),getvardims(edgen)) filevardef(fclim, "LONGXY" ,typeof(longxy) ,getvardims(longxy)) filevardef(fclim, "LATIXY" ,typeof(latxy) ,getvardims(latxy)) filevardef(fclim, "FSDS",typeof(rsds),getvardims(rsds)) filevardef(fclim, "PRECTmms",typeof(prec),getvardims(prec)) filevardef(fclim, "TBOT",typeof(tbot),getvardims(tbot)) filevardef(fclim, "WIND",typeof(wind),getvardims(wind)) filevardef(fclim, "PSRF",typeof(psrf),getvardims(psrf)) filevardef(fclim, "SHUM",typeof(qbot),getvardims(qbot)) filevardef(fclim, "time",typeof(time),getvardims(time)) filevarattdef(fclim,"EDGEW",edgew) filevarattdef(fclim,"EDGEE",edgee) filevarattdef(fclim,"EDGES",edges) filevarattdef(fclim,"EDGEN",edgen) filevarattdef(fclim,"LONGXY",longxy) filevarattdef(fclim,"LATIXY",latxy) filevarattdef(fclim,"FSDS",rsds) filevarattdef(fclim,"PRECTmms",prec) filevarattdef(fclim,"TBOT",tbot) filevarattdef(fclim,"WIND",wind) filevarattdef(fclim,"PSRF",psrf) filevarattdef(fclim,"SHUM",qbot) filevarattdef(fclim,"time",time) setfileoption(fclim,"DefineMode",False) print(time) fclim->time = (/time/) ; "(/", "/)" syntax tells NCL to only output the data values to the predefined locations on the file. print(fclim->time) xfloor=plot_lon-0.01 xceil =plot_lon+0.01 yfloor=plot_lat-0.01 yceil =plot_lat+0.01 print(yceil) print(xceil) fclim->EDGEW = (/xfloor/) fclim->EDGEE = (/xceil/) fclim->EDGES = (/yfloor/) fclim->EDGEN = (/yceil/) printVarSummary(plot_lon) fclim->LONGXY = (/plot_lon/) fclim->LATIXY = (/plot_lat/) fclim->FSDS = (/rsds(:,latj,loni)/) fclim->PRECTmms = (/prec(:,latj,loni)/) ; !!!! time variable can be modified in the attributes of the variable is also copied. make sure to use (/ /) to only copy data. fclim->TBOT = (/tbot(:,latj,loni)/) fclim->WIND = (/wind(:,latj,loni)/) fclim->PSRF = (/psrf(:,latj,loni)/) fclim->SHUM = (/qbot(:,latj,loni)/) print(fclim->time) delete(rsds) delete(time) delete(prec) delete(tbot) delete(qbot) delete(wind) delete(psrf) ; end do end do end if if (varCOMB) then do year=1901,2010,1 system("cp "+clim_output+"clm1pt_"+plot_name+"_FSDS_"+year+"01010130-"+year+"12312230.nc "+clim_output+"clm1pt_"+plot_name+"_"+year+".nc") system("ncks -h -A "+clim_output+"clm1pt_"+plot_name+"_PRECTmms_"+year+"01010130-"+year+"12312230.nc "+clim_output+"clm1pt_"+plot_name+"_"+year+".nc") system("ncks -h -A "+clim_output+"clm1pt_"+plot_name+"_TBOT_"+year+"01010130-"+year+"12312230.nc "+clim_output+"clm1pt_"+plot_name+"_"+year+".nc") system("ncks -h -A "+clim_output+"clm1pt_"+plot_name+"_WIND_"+year+"01010130-"+year+"12312230.nc "+clim_output+"clm1pt_"+plot_name+"_"+year+".nc") system("ncks -h -A "+clim_output+"clm1pt_"+plot_name+"_PSHUM_"+year+"01010130-"+year+"12312230.nc "+clim_output+"clm1pt_"+plot_name+"_"+year+".nc") end do end if if (varMOD) then do year=1981,2010,1 system("ncrename -v LATXY,LATIXY "+clim_output+"clm1pt_"+plot_info(0,1)+"_"+year+".nc") end do end if if (varTIMEsub) then do year=1981,2010,1 system("ncrcat -O -d time,0,2919,2 "+clim_output+"clm1pt_"+plot_info(0,1)+"_"+year+".nc "+clim_output+"clm1pt_"+plot_info(0,1)+"_"+year+".nc") end do end if ;if (varSHUMMOD) then ; do year=1981,2010,1 ; ncrcat -O clm1pt_322_1982-*.nc clm1pt_322_1983.nc ; ncks -v PSRF clm1pt_322_1981-01.nc test.nc ; system("ncrename -v LATXY,LATIXY "+clim_output+"clm1pt_"+plot_info(0,1)+"_"+year+".nc") ; end do ;end if if (timCOMB) then do m=0,20,1 system("ncrcat -O "+clim_output+"clm1pt_"+plot_name+"_*.nc "+clim_output+"clm1pt_"+plot_name+"_1981-2010.nc") end do end if end