comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » "feature" in NCDF_VARPUT
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
"feature" in NCDF_VARPUT [message #76874] Mon, 11 July 2011 07:24
Fabzou is currently offline  Fabzou
Messages: 76
Registered: November 2010
Member
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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: solving power flows in electricity networks
Next Topic: Writing a lot of data to ASCII file without a loop?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:35:10 PDT 2025

Total time taken to generate the page: 0.00420 seconds