[ncl-talk] Problems converting hdf to netcdf using NCL
BLIUJUS, STEVEN D CTR USAF AFMC AFLCMC/HBAW-OL
steven.bliujus.3.ctr at us.af.mil
Fri May 22 09:59:30 MDT 2015
I wanted to provide an example of what is in the hdf file. See attached.
Steve
-----Original Message-----
From: ncl-talk-bounces at ucar.edu [mailto:ncl-talk-bounces at ucar.edu] On Behalf Of BLIUJUS, STEVEN D CTR USAF AFMC AFLCMC/HBAW-OL
Sent: Friday, May 22, 2015 10:36 AM
To: ncl-talk at ucar.edu
Subject: [ncl-talk] Problems converting hdf to netcdf using NCL
I am taking several hdf files (200-400) and trying to generate one NetCDF file. I am able to plot it on a grid, but when I try to write to a NetCDF file, I get the following error:
fatal:Number of dimensions in parameter (2) of (filedimdef) is (2), (1) dimensions were expected
fatal:["Execute.c":8128]:Execute: Error occurred at or near line 82 in file File.ncl
The data I am creating is AOD with two dimensions (lat/lon). I am uncertain as to why it is expecting one dimension. Below is my script. FYI, the original files had to be manipulated in order to make AOD have the lat/lon dimensions. Any help would be greatly appreciated.
load "/home/bliujuss/ncl/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "/home/bliujuss/ncl/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
load "/home/bliujuss/ncl/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "/home/bliujuss/ncl/lib/ncarg/nclscripts/csm/shea_util.ncl"
begin
diri = "/home/bliujuss/Verification_data/Test/"
fili = systemfunc("ls "+diri+"*.hdf")
a = addfiles(fili,"r")
;ListSetType(a,"cat")
var1=a[:]->Optical_Depth_Land_And_Ocean(:,:)
Optical_Depth_Land_And_Ocean = short2flt(var1)
var2=a[:]->Longitude(:,:)
Longitude=var2
var3 = a[:]->Latitude(:,:)
Latitude=var3
dims = dimsizes(Optical_Depth_Land_And_Ocean)
nrows = dims(0) ;203
npixels = dims(1) ;135
lat2d = new((/nrows,npixels/),float)
lon2d = new((/nrows,npixels/),float)
do i=0,npixels-1
lat2d(:,i) = Latitude(:,i)
end do
do i=0,nrows-1
lon2d(i,:) = Longitude(i,:)
end do
Optical_Depth_Land_And_Ocean at lat2d = lat2d(::5,::5) Optical_Depth_Land_And_Ocean at lon2d = lon2d(::5,::5)
wks = gsn_open_wks("x11","plot_aod")
gsn_define_colormap(wks,"NCV_banded")
setvalues NhlGetWorkspaceObjectId()
"wsMaximumSize": 300000000
end setvalues
res = True ; plot mods desired
res at cnLinesOn = False ; turn off contour lines
res at cnFillOn = True ; color plot desired
res at cnLineLabelsOn = False ; turn off contour lines
res at gsnAddCyclic = False ; non-global data
res at gsnSpreadColors = True ; use full range of colormap
;res at cnFillMode = "RasterFill" ; turn on raster mode
res at lbLabelAutoStride = True ; nice spacing of lables
res at gsnMaximize = True ; blow up plot as much as poss
;print(min(lat2d))
;print(max(lat2d))
;print(min(lon2d))
;print(max(lon2d))
plot = gsn_csm_contour_map_ce(wks,Optical_Depth_Land_And_Ocean(::5,::5),res)
print(max(Optical_Depth_Land_And_Ocean(::5,::5)))
nlat = dimsizes(lat2d(::5,::5))
nlon = dimsizes(lon2d(::5,::5))
diro = "/home/bliujuss/Plots/"
filo = "example.nc"
system("rm -f" + diro + filo)
fout = addfile (diro + filo, "c")
setfileoption(fout,"DefineMode",True)
dim_names = (/"lat", "lon"/)
dim_sizes = (/nlat, nlon/)
dimUnlim = (/False, False/)
filedimdef(fout,dim_names,dim_sizes,dimUnlim)
filevardef(fout, "lat", typeof(lat2d(::5,::5)),getvardims(lat2d(::5,::5)))
filevardef(fout, "lon", typeof(lon2d(::5,::5)),getvardims(lon2d(::5,::5)))
filevardef(fout, "AOT", typeof(Optical_Depth_Land_And_Ocean(::5,::5)),getvardims(Optical_Depth_Land_And_Ocean(::5,::5)))
filevarattdef(fout,"AOT", Optical_Depth_Land_And_Ocean(::5,::5))
filevarattdef(fout,"lat", lat2d(::5,::5)) filevarattdef(fout,"lon", lon2d(::5,::5))
setfileoption(fout,"DefineMode",False)
fout->Optical_Depth_Land_And_Ocean(::5,::5) =
fout->(/Optical_Depth_Land_And_Ocean(::5,::5)/)
fout->lat2d(::5,::5) = (/lat2d(::5,::5)/)
fout->lon2d(::5,::5) = (/lon2d(::5,::5)/)
end
Steven Bliujus
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dump.MOD04_L2.A2014306.2330.006.2015077230656.pscs_000500937810.txt
Url: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150522/309a004a/attachment.txt
More information about the ncl-talk
mailing list