- 积分
- 3464
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-4-18
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2016-12-22 22:59:20
|
显示全部楼层
对于观测的处理过程如下:
文件为每年一个。考虑闰年。
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"
begin
FilePath ="../../data/OBS/prect/daily/3B42_daily_0.25X0.25/"
Files = systemfunc ("/bin/ls " + FilePath)
;print(Files)
FilesIn = addfiles(FilePath + Files, "r")
ListSetType (FilesIn, "cat")
Nfiles =dimsizes(Files)
;print(Nfiles)
Nyear=Nfiles ;the data are store by year
Ninterval =1 ;when your input data is too large,you can set this one bigger to get some piece of the data.
time =FilesIn[0]->time(0)
lat =FilesIn[0]->lat(::Ninterval)
lon =FilesIn[0]->lon(::Ninterval)
Nlat =dimsizes(lat)
Nlon =dimsizes(lon)
Month =(/"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"/)
;Nyear=1 ;you can set Nyear equals 1 to test the first year
Nmonth =12
year=new(Nyear,integer)
prec=new((/Nmonth*Nyear,Nlat,Nlon/), float)
OutTime=new(Nmonth*Nyear, double)
OutTime@units= time@units
OutTime@calendar ="standard" ;this is a must to get the actual time(such as 19991203)
casename="Trmm_3B43"
VarInName=(/"r"/)
VarOutName=(/"prect"/) ;you can quote different varible to batch processing
Nvar=dimsizes(VarInName)
do Ivar=0,Nvar-1
n=0
do Iyear = 0,Nyear-1
time =FilesIn[Iyear]->time(0)
year(Iyear)=ut_calendar(time(0), -1)/100
if (isleapyear(year(Iyear))) then
Monthday =(/0,31,29,31,30,31,30,31,31,30,31,30,31/) ;for leap year ,there are 29 days in February.
print(year(Iyear) + "is leap year")
else
Monthday =(/0,31,28,31,30,31,30,31,31,30,31,30,31/)
print(year(Iyear) + "is not leap year")
end if
do Imon=1,Nmonth
time1=get_cpu_time()
prect = FilesIn[Iyear]->r(sum(Monthday(:Imon-1)) : sum(Monthday(:Imon))-1,::Ninterval,::Ninterval)
;printVarSummary(prect)
;print(dimsizes(prect&time))
YearMonth=ut_calendar(prect&time(0), -1) ;get the year and month ,like 199109
OutFileName =casename +"."+ YearMonth +"."+ VarOutName(Ivar) +".daily.nc"
system("/bin/rm -rf " + OutFileName)
cdf_file = addfile(OutFileName,"c")
cdf_file->$VarOutName(Ivar)$ = prect
prec(n,:,:)=(/dim_avg_n_Wrap(prect, 0)/) ;calculat and store Month Mean
OutTime(n) =prect&time(0) ;store the first day of the month
n=n+1
delete([/prect,YearMonth,cdf_file/])
time2=get_cpu_time()
delt=time2-time1
;print("the time consuming in this loop is : "+ delt +"s")
end do
end do
;============================================================================
;store the Monthly meandatasets
prec!0="time"
prec!1="lat"
prec!2="lon"
prec&time=OutTime
prec&lat=lat
prec&lon=lon
OutFileName2 =casename +"."+ year(0) +"_to_"+ year(Nyear-1) +"."+ VarOutName(Ivar) +".Monthly_Mean.nc"
system("/bin/rm -rf " + OutFileName2)
cdf_file2 = addfile(OutFileName2,"c")
cdf_file2->$VarOutName(Ivar)$ = prec
end do
end
|
|