写完程序抬头散步,发个程序代码
简书的文章真是看起来赏心悦目,我也要写一写。
今天把今天编写的NCL脚本贴一下,以后会用到的。
【将grib数据通过ncl输出成netcdf文件】
关键字:ncl,grib2,netcdf,fnl,gdas0p25
begin
;***********************************************
; get variable names from grib file
;***********************************************
; --$ ls gdas1.fnl0p25.2019070*.f00.grib2 >grib2filelist.txt
filename = asciiread("./grib2filelist.txt",-1,"string")
nfiles = dimsizes(filename)
do fidex = 0, nfiles-1
;print(filename(fidex))
grib_in = addfile("./"+filename(fidex),"r")
names = getfilevarnames(grib_in); extract all variable names
;print(names) ;查看所有变量
names2=(/"TMP_P0_L100_GLL0","UGRD_P0_L100_GLL0","VGRD_P0_L100_GLL0","HGT_P0_L100_GLL0","RH_P0_L100_GLL0"/)
;***********************************************
; create output netcdf file
;***********************************************
filename_pre=str_get_cols(filename(fidex),0,27)
system("rm "+filename_pre +".nc") ; remove any pre-existing file
ncdf_out = addfile(filename_pre +".nc" ,"c") ; create output netCDF file
;***********************************************
; loop through variables and output each to netcdf
;***********************************************
do i = 0, dimsizes(names2)-1
ncdf_out->$names2(i)$ = grib_in->$names2(i)$
end do
end do
end