This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Matt,
> Date: Thu, 28 Sep 2000 11:22:53 -0700
> From: "Matt D'Ortenzio" <address@hidden>
> To: address@hidden
> Subject: Testing for exisiting dimensions
The above message contained the following:
> I ran into a problem while trying to test whether certain dimension names
> exist in one of my datasets. I wrote the following, where "dummy" is not
> a name of a dimension in the set:
>
> $dimIdentifier = NetCDF::dimid($ncID, "dummy");
> if ($dimIdentifier == -1)
> {
> print "Dimension doesn't exist..\n\n";
> }
>
> I was hoping that the "dimid" function would simply set the $dimIdentifier
> variable to -1 and execution would continue, however right after the
> "dimid" function is called, the program stops and the following netCDF
> error message is printed:
>
> ncdimid: ncid 3: Invalid dimension id or name
>
> How can you cleanly catch this error? Thanks for the help.
Your program halts because the default error-handling action of the
netCDF library is to abort on error. To override, call the following
first:
NetCDF::ncopts(NetCDF::VERBOSE);
This will cause the netCDF library to print a message to standard error
and then continue.
> -Matt
> *************************************************************
> Matt D'Ortenzio
> NASA Ames Research Center
> MS 269-1
> Moffett Field, CA 94035
> Phone: (650)604-1715
> Email: address@hidden
> *************************************************************
Regards,
Steve Emmerson <http://www.unidata.ucar.edu>