[ncl-talk] Error when creating netCDF file with new variables
Sébastien Marinier
marinier.sebastien at gmail.com
Thu Jan 5 13:31:47 MST 2017
Dear NCL users,
I've been using NCL for post-processing some WRF output files: the script
"crops" the domain and interpolates some variables at some pressure levels.
When I run my script, I get this error:
fatal:Dimension sizes of left hand side do not match right hand side
fatal:["Execute.c":8575]:Execute: Error occurred at or near line 140 in
file test_crop_3d.ncl
fatal:Dimension sizes of left hand side do not match right hand side
fatal:["Execute.c":8575]:Execute: Error occurred at or near line 141 in
file test_crop_3d.ncl
fatal:Dimension sizes of left hand side do not match right hand side
fatal:["Execute.c":8575]:Execute: Error occurred at or near line 142 in
file test_crop_3d.ncl
fatal:Dimension sizes of left hand side do not match right hand side
fatal:["Execute.c":8575]:Execute: Error occurred at or near line 143 in
file test_crop_3d.ncl
I looked at this kind of error in the archives, but didn't find any
solution. Lines 140 to 143 are the following lines:
fout->U250 = (/u250/)
fout->U500 = (/u500/)
fout->V250 = (/v250/)
fout->V500 = (/v500/)
Here's the full script:
;------------------------------------------------------------
;Getting coordinates and indices to crop the domain
;------------------------------------------------------------
fname_coords = "./wrfout_constants.nc"
f_coords = addfile(fname_coords,"r")
lon = f_coords->XLONG(0,:,:)
lat = f_coords->XLAT(0,:,:)
latN = 60.0
latS = 40.0
lonW = -140.0
lonE = -85.0
hpa = 0.01
ij = region_ind(lat,lon,latS,latN,lonW,lonE)
iStrt = ij(0)
iLast = ij(1)
jStrt = ij(2)
jLast = ij(3)
new_lat = lat(iStrt:iLast,jStrt:jLast)
new_lon = lon(iStrt:iLast,jStrt:jLast)
;------------------------------------------------------------
;Opening files
;------------------------------------------------------------
f = addfile("wrf3d_d01_2013-06-01_00:00:00","r")
;-------------------------------------------------------------
;Create new netCDF file
;-------------------------------------------------------------
dims = dimsizes(new_lat)
ny = dims(0)
nx = dims(1)
i=0
time = f->Times(i,:)
tk = f->TK(i,:,iStrt:iLast,jStrt:jLast)
p = f->P(i,:,iStrt:iLast,jStrt:jLast)
z_tmp = f->Z(i,:,iStrt:iLast,jStrt:jLast)
qvapor = f->QVAPOR(i,:,iStrt:iLast,jStrt:jLast)
u_tmp = f->U(i,:,iStrt:iLast,jStrt:jLast)
v_tmp = f->V(i,:,iStrt:iLast,jStrt:jLast)
;Unstagger some variables
z = wrf_user_unstagger(z_tmp,z_tmp at stagger)
;u = wrf_user_unstagger(u_tmp,u_tmp at stagger)
;v = wrf_user_unstagger(v_tmp,v_tmp at stagger)
u = u_tmp
v = v_tmp
;Compute RH
rh = wrf_rh(qvapor,p,tk)
;Interpolation at pressure levels
;250 mb
u250 = wrf_user_intrp3d(u,p*hpa,"h",250,0.,False)
v250 = wrf_user_intrp3d(v,p*hpa,"h",250,0.,False)
z250 = wrf_user_intrp3d(z,p*hpa,"h",250,0.,False)
t250 = wrf_user_intrp3d(tk,p*hpa,"h",250,0.,False)
rh250 = wrf_user_intrp3d(rh,p*hpa,"h",250,0.,False)
;500 mb
u500 = wrf_user_intrp3d(u,p*hpa,"h",500,0.,False)
v500 = wrf_user_intrp3d(v,p*hpa,"h",500,0.,False)
z500 = wrf_user_intrp3d(z,p*hpa,"h",500,0.,False)
t500 = wrf_user_intrp3d(tk,p*hpa,"h",500,0.,False)
rh500 = wrf_user_intrp3d(rh,p*hpa,"h",500,0.,False)
;sfc
psfc = p(0,:,:)
slp = wrf_slp(z,tk,p,qvapor)
rh0 = rh(0,:,:)
;Output Files
diro = "./"
filo = "wrf_lvls_"+time+".nc"
system("/bin/rm -f "+diro+filo) ; remove if exists
fout = addfile(diro+filo,"c") ; open output file
setfileoption(fout,"DefineMode",True)
;Global attributes
fAtt = True
fAtt at title = "Cropped and interpolated (sfc, 500 mb and 250 mb) data files
from Liu et al. (2016) simulations"
fAtt at Conventions = "None"
fAtt at creation_date = systemfunc("date")
fileattdef(fout,fAtt)
;Dimensions of coordinates
dimNames =
(/"Time","south_north","west_east","south_north_stag","west_east_stag","DateStrLen"/)
dimSizes = (/-1,ny,nx,ny+1,nx+1,19/)
dimUnlim = (/True,False,False,False,False,False/)
filedimdef(fout,dimNames,dimSizes,dimUnlim)
;... of variables
filevardef(fout,"Times",typeof(time),getvardims(time))
filevardef(fout,"XLAT",typeof(new_lat),getvardims(new_lat))
filevardef(fout,"XLONG",typeof(new_lon),getvardims(new_lon))
filevardef(fout,"U250",typeof(u250),getvardims(u250))
filevardef(fout,"U500",typeof(u500),getvardims(u500))
filevardef(fout,"V250",typeof(v250),getvardims(v250))
filevardef(fout,"V500",typeof(v500),getvardims(v500))
filevardef(fout,"Z250",typeof(z250),getvardims(z250))
filevardef(fout,"Z500",typeof(z500),getvardims(z500))
filevardef(fout,"T250",typeof(t250),getvardims(t250))
filevardef(fout,"T500",typeof(t500),getvardims(t500))
filevardef(fout,"RH250",typeof(rh250),getvardims(rh250))
filevardef(fout,"RH500",typeof(rh500),getvardims(rh500))
filevardef(fout,"RH0",typeof(rh0),getvardims(rh0))
filevardef(fout,"PSFC",typeof(psfc),getvardims(psfc))
filevardef(fout,"SLP",typeof(slp),getvardims(slp))
;Copy attributes
;filevarattdef(fout,"Times",time)
filevarattdef(fout,"XLAT",new_lat)
filevarattdef(fout,"XLONG",new_lon)
filevarattdef(fout,"U250",u250)
filevarattdef(fout,"U500",u500)
filevarattdef(fout,"V250",v250)
filevarattdef(fout,"V500",v500)
filevarattdef(fout,"Z250",z250)
filevarattdef(fout,"Z500",z500)
filevarattdef(fout,"T250",t250)
filevarattdef(fout,"T500",t500)
filevarattdef(fout,"RH250",rh250)
filevarattdef(fout,"RH500",rh500)
filevarattdef(fout,"RH0",rh0)
filevarattdef(fout,"PSFC",psfc)
filevarattdef(fout,"SLP",slp)
setfileoption(fout,"DefineMode",False)
;Output variables
fout->Times = (/time/)
fout->XLAT = (/new_lat/)
fout->XLONG = (/new_lon/)
fout->U250 = (/u250/)
fout->U500 = (/u500/)
fout->V250 = (/v250/)
fout->V500 = (/v500/)
fout->Z250 = (/z250/)
fout->Z500 = (/z500/)
fout->T250 = (/t250/)
fout->T500 = (/t500/)
fout->RH250 = (/rh250/)
fout->RH500 = (/rh500/)
fout->RH0 = (/rh0/)
fout->PSFC = (/psfc/)
fout->SLP = (/slp/)
-------------------------------------------------------------------------------------------------------
I think there is a problem with the staggered coordinates, but I can't put
the finger on it...
Thanks for the help,
Sebastien.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170105/24520449/attachment.html
More information about the ncl-talk
mailing list