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

Home » Public Forums » archive » NetCDF and empty variables
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
NetCDF and empty variables [message #66142] Fri, 17 April 2009 06:18 Go to next message
renaud.dussurget is currently offline  renaud.dussurget
Messages: 8
Registered: April 2008
Junior Member
Hi,
I've been trying reading a NC file with David Fanning's (very handy!)
NCDF_DATA object, and it failed reading a file while parsing it.
After trying to understand where it was crashing, I've realised that
this variable was empty (though it is supposed to have 3 dimensions)
and that IDL NCDF_VARGET function was not able to deal with this
problem...

An example :

IDL>ncid = NCDF_OPEN('myFile.nc')
IDL>varId = NCDF_VARID(ncid,'HISTORY_INSTITUTION')
IDL>out=NCDF_VARINQ(ncid, VarId)
IDL>help, out, /str
** Structure <a9c098>, 5 tags, length=56, data length=52, refs=1:
NAME STRING 'HISTORY_INSTITUTION'
DATATYPE STRING 'CHAR'
NDIMS LONG 3
NATTS LONG 3
DIM LONG Array[3]

IDL>print, out.dim
6 8 12

IDL>NCDF_VARGET, ncid, varId, data, COUNT=cnt
% Array dimensions must be greater than 0.

I have found a simple way to deal with this, however I don't really
like it...
IDL>cmd = 'NCDF_VarGet, ncid, varId, data
IDL>res= EXECUTE(cmd)
% Array dimensions must be greater than 0.

And then in the code, write something like this
IF (res EQ 0) THEN data = -1

Does anyone has a better solution???

Thanks
Bye
Re: NetCDF and empty variables [message #66189 is a reply to message #66142] Wed, 22 April 2009 17:29 Go to previous message
Mark[1] is currently offline  Mark[1]
Messages: 66
Registered: February 2008
Member
On Apr 22, 4:03 pm, David Fanning <n...@dfanning.com> wrote:
> Yeah, so what does that mean that it has an unlimited
> dimension. Why would someone do that? :-)

Say you have an ocean model with a rectangular grid. For your output
netCDF files you would probably have fixed dimensions (x, y and z) for
the three spatial dimensions of the model and you would have an
unlimited dimension (t) correspond to simulated time. Your model grid
variables would depend on the fixed dimensions in various combinations
and you would write this info at the beginning of the model run. Your
model state variables (temperature, salinity, velocity components)
would depend on x, y, z AND t, and you would write snapshots of these
as the model runs, stepping along the t dimension each time. By making
the t dimension unlimited you don't have to know how many snapshots
you're going to write in advance. If the model hasn't written any
snapshots yet--perhaps it crashed before it could--then the size of
the time dimension is 0.
Re: NetCDF and empty variables [message #66192 is a reply to message #66142] Wed, 22 April 2009 08:29 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> OK, I understand that I can't read any variable that has
> this unlimited dimension set to zero. So, how do I determine
> ahead of time (that is, before I read the variable) whether
> that variable is using this dimension?

Never mind, I figured out that NCDF_VARINQ can return me
the IDs of all of the dimensions of the variable. If
I have a dimension with a length of zero, I save its ID
and later compare it to the dimension IDs returned
from the function listed above. If there is a match,
I don't read the variable and do something else.

The nCDF_Browser has been updated appropriately:

http://www.dfanning.com/ncdf_browser.zip

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: NetCDF and empty variables [message #66195 is a reply to message #66142] Wed, 22 April 2009 07:30 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mark writes:

> That said, there's nothing weird about this file except that it has an
> unlimited dimension (N_HISTORY) with size zero. And that's not really
> very weird at all.

OK, I understand that I can't read any variable that has
this unlimited dimension set to zero. So, how do I determine
ahead of time (that is, before I read the variable) whether
that variable is using this dimension?

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: NetCDF and empty variables [message #66201 is a reply to message #66142] Tue, 21 April 2009 21:03 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mark writes:

> That said, there's nothing weird about this file except that it has an
> unlimited dimension (N_HISTORY) with size zero. And that's not really
> very weird at all.
>
> The ncdump utility shows this:
>
> $ ncdump -v HISTORY_PARAMETER 69003_prof.nc
> netcdf \69003_prof {
> dimensions:
> DATE_TIME =3D 14 ;
> STRING256 =3D 256 ;
> STRING64 =3D 64 ;
> STRING32 =3D 32 ;
> STRING16 =3D 16 ;
> STRING8 =3D 8 ;
> STRING4 =3D 4 ;
> STRING2 =3D 2 ;
> N_PROF =3D 16 ;
> N_PARAM =3D 2 ;
> N_LEVELS =3D 94 ;
> N_CALIB =3D 1 ;
> N_HISTORY =3D UNLIMITED ; // (0 currently)
> variables:
> ...etc
>
> and so does IDL
>
> IDL> id =3D ncdf_open('C:\Temp\69003_prof.nc')
> IDL> inq =3D ncdf_inquire(id)
> IDL> ncdf_diminq, id, inq.recdim, name, size
> IDL> print, name, size
> N_HISTORY 0
> IDL> ncdf_close, id

Yeah, so what does that mean that it has an unlimited
dimension. Why would someone do that? :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: NetCDF and empty variables [message #66202 is a reply to message #66142] Tue, 21 April 2009 20:48 Go to previous message
Mark[1] is currently offline  Mark[1]
Messages: 66
Registered: February 2008
Member
On Apr 22, 6:38 am, David Fanning <n...@dfanning.com> wrote:
> renaud.dussur...@gmail.com writes:
>> I've posted the a link to the original file on the other post:
>
>> ftp://ftp.ifremer.fr/ifremer/argo/dac/coriolis/69003/69003_p rof.nc
>
> Pretty weird. NONE of the HISTORY_* variables were
> populated in this file. I've modified my nCDF_Browser
> routine to handle this strange state of affairs.
> Download this new file:
>
>   http://www.dfanning.com/programs/ncdf_data__define.pro
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Coyote's Guide to IDL Programming (www.dfanning.com)
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

First, please accept apologies for starting a new thread (I don't know
how that happened) and for not reading the other thread thoroughly
enough to see that the file had already been posted.

That said, there's nothing weird about this file except that it has an
unlimited dimension (N_HISTORY) with size zero. And that's not really
very weird at all.

The ncdump utility shows this:

$ ncdump -v HISTORY_PARAMETER 69003_prof.nc
netcdf \69003_prof {
dimensions:
DATE_TIME = 14 ;
STRING256 = 256 ;
STRING64 = 64 ;
STRING32 = 32 ;
STRING16 = 16 ;
STRING8 = 8 ;
STRING4 = 4 ;
STRING2 = 2 ;
N_PROF = 16 ;
N_PARAM = 2 ;
N_LEVELS = 94 ;
N_CALIB = 1 ;
N_HISTORY = UNLIMITED ; // (0 currently)
variables:
...etc

and so does IDL

IDL> id = ncdf_open('C:\Temp\69003_prof.nc')
IDL> inq = ncdf_inquire(id)
IDL> ncdf_diminq, id, inq.recdim, name, size
IDL> print, name, size
N_HISTORY 0
IDL> ncdf_close, id

And this is what I said in the first post of the current thread.
Re: NetCDF and empty variables [message #66205 is a reply to message #66142] Tue, 21 April 2009 11:38 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
renaud.dussurget@gmail.com writes:

> I've posted the a link to the original file on the other post:
>
> ftp://ftp.ifremer.fr/ifremer/argo/dac/coriolis/69003/69003_p rof.nc

Pretty weird. NONE of the HISTORY_* variables were
populated in this file. I've modified my nCDF_Browser
routine to handle this strange state of affairs.
Download this new file:

http://www.dfanning.com/programs/ncdf_data__define.pro

Cheers,

David
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: NetCDF and empty variables [message #66208 is a reply to message #66142] Tue, 21 April 2009 08:49 Go to previous message
renaud.dussurget is currently offline  renaud.dussurget
Messages: 8
Registered: April 2008
Junior Member
On 21 avr, 02:11, Mark <mark.h...@gmail.com> wrote:
> On Apr 21, 12:18 am, renaud.dussur...@gmail.com wrote:
>
>> NCDF_INQUIRE and NCDF_DIMINQ just give what the
>> properties of the variable should be, and not what
>> it really is in the file (i.e. no
>> data)
>
> To misquote a very wise man who wasn't talking about NetCDF files,
> what is is, what isn't isn't, there is no should.
>
> Perhaps you could put a copy of the file on an FTP server, so we could
> look at it. Or if it's small, maybe you could convert it to CDL (text)
> format and post that on the group.

I've posted the a link to the original file on the other post:

ftp://ftp.ifremer.fr/ifremer/argo/dac/coriolis/69003/69003_p rof.nc

Renaud
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: VISualize 2009 summary
Next Topic: image correlation

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

Current Time: Wed Oct 08 15:55:34 PDT 2025

Total time taken to generate the page: 0.00726 seconds