Dear IDLers,
Some of you may find this post pretty useless, sorry if this is the case.
I found a bug in a procedure I wrote a long time ago and I was horrified
because it passed trough all my tests.
Luckily, despite the bug in the code, the routine still did what I
expected: the NCDF_VARPUT command accepts an OFFSET vector of more
elements then the number of dimensions of the variable, and seems to
ignore the first indices in this case. Here is an example to explain
what I mean:
PRO feature_ncdf
nt = 2 ; Times
nx = 150
ny = 150
tid = NCDF_CREATE('test.nc', /CLOBBER) ; NCDF outfile
NCDF_CONTROL, tid, /FILL
;Define dimensions
dimTimeid = NCDF_DIMDEF(tid, 'time', nt)
dimXid = NCDF_DIMDEF(tid, 'x', nx)
dimYid = NCDF_DIMDEF(tid, 'y', ny)
; Define variables
vid = NCDF_VarDef(tid, 'myvar', [dimxid, dimyid, dimTimeid], /LONG)
NCDF_CONTROL, tid, /ENDEF ; Switch to normal Fill mode
; Fill the variable with zeros
var0 = LONARR(nx, ny, nt)
NCDF_VARPUT, tid, vid, var0
; check if they are all zeros
NCDF_VARGET, tid, vid, vartotest
if total(abs(vartotest)) ne 0 then print, 'error'
var1 = LONARR(nx, ny) + 1
; Offset vector of more elements than the variable ndims
NCDF_VARPUT, tid, vid, var1, OFFSET=[0,0,0,1]
; check if despite the wrong command, the ones are
; filled at the right place
NCDF_VARGET, tid, vid, vartotest2
if total(abs(vartotest2[*,*,0])) eq 0 then print, 'As expected'
if min(vartotest2[*,*,1]) eq 1 and max(vartotest2[*,*,1]) eq 1 then $
print, 'Ah, it worked. How strange.'
NCDF_CLOSE, tid
END
I am confused since there is no documentation about this behavior. Is
this longer offset vector allowed so that one can put variables of any
dimension at the right place in time without having to make too many
"if" statements?
Fab
|