[ncl-talk] Problems converting hdf to netcdf using NCL

Rick Brownrigg brownrig at ucar.edu
Fri May 22 09:49:19 MDT 2015


Hi Steven,

I'm not expert here on this, but from what I can tell, you've got
curvilinear lat/lon variables that are two dimensional, and so in the
statement:

  dim_sizes = (/nlat, nlon/)

nlat/nlon are themselves 2D, so dim_sizes is a 2x2 (I think).   Your
lat2d/lon2d are defined in more fundamental dimensions in the HDF files --
it looks like perhaps nrows/ncol -- and its those values&names you likely
want to use for filedimdefs().

Make sense?

Hope that helps...
Rick


On Fri, May 22, 2015 at 9:35 AM, BLIUJUS, STEVEN D CTR USAF AFMC
AFLCMC/HBAW-OL <steven.bliujus.3.ctr at us.af.mil> wrote:

> 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) =
> (/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 HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150522/bf1ef415/attachment.html 


More information about the ncl-talk mailing list