[ncl-talk] Question on Arguments to be passed for a procedure
Francesco Trotta
francesco.trotta4 at unibo.it
Thu Jan 26 03:09:34 MST 2017
Dear Ncl-Team
I'm using NCL - version 6.3.0
I need to write 6 netcdf files for 6 atmospheric variables (u10m,v10m,t2m,q2m,precip,snow) with the same structure.
I would like to define just one procedure for this jobs instead 6 procedure , passing as argument the corrispettive variable.
But to write the variable in the file I need to specify the name of variable (for example fout->snow = (/atmField/), see code below)
Is there a way to pass a name of variable ad argument in order to define just one procedure for all the variable?
thanks
Francesco
procedure write_atm_snow(path_extrapdataAtm,file_extrapdataAtm,glAttDescr, \
nx,ny,nt,lon1d,lat1d,time,tmask,atmField,maskFieldName,atmFieldName)
begin
pathfile_extrapdataAtm = path_extrapdataAtm+"/"+file_extrapdataAtm
system("rm -f "+pathfile_extrapdataAtm)
fout = addfile(pathfile_extrapdataAtm, "c")
;print(fout)
;===================================================================
; Explicitly declare file definition mode. Improve efficiency.
;===================================================================
setfileoption(fout,"DefineMode",True)
;===================================================================
; Defines global attributes associated with the file.
;===================================================================
fAtt = True
fAtt at description = glAttDescr
fAtt at creation_date= systemfunc ("date")
fileattdef(fout, fAtt)
;===================================================================
; Defines dimension names, dimension sizes, unlimited dimensions on the file.
; (Note: to get an UNLIMITED record dimension, we set the dimensionality
; to -1 (or the actual size) and set the dimension name to True.)
;===================================================================
dimNames = (/ "lon", "lat", "time"/)
dimSizes = (/ nx, ny, nt/)
dimUnlim = (/ False, False, True /)
filedimdef(fout,dimNames,dimSizes,dimUnlim)
;===================================================================
; Defines a list of variable names, variable types, and
; variable dimension names for the file.
;===================================================================
filevardef(fout, "lon", typeof(lon1d), "lon")
filevardef(fout, "lat", typeof(lat1d), "lat")
filevardef(fout, "time", typeof(time), "time")
filevardef(fout, maskFieldName,typeof(tmask), (/"lat","lon"/))
filevardef(fout, atmFieldName, typeof(atmField),(/"time","lat","lon"/))
;===================================================================
; Copies attributes from an input variable to the variables on the file.
;====================================================================
filevarattdef(fout, "lon", lon1d)
filevarattdef(fout, "lat", lat1d)
filevarattdef(fout, "time", time)
filevarattdef(fout, maskFieldName,tmask)
filevarattdef(fout, atmFieldName, atmField)
;===================================================================
; Explicitly exit file definition mode. **NOT REQUIRED**
;===================================================================
setfileoption(fout,"DefineMode",False)
;===================================================================
; output only the data values since the dimensionality and such have
; been predefined. The "(/", "/)" syntax tells NCL to only output the
; data values to the predefined locations on the file.
;====================================================================
fout->lat = (/lat1d/)
fout->lon = (/lon1d/)
fout->time = (/time/)
fout->LSM = (/tmask/)
fout->snow = (/atmField/)
end
?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170126/aefec939/attachment.html
More information about the ncl-talk
mailing list