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.
Tony,
> To: <address@hidden>
> From: "Tony Simmers" <address@hidden>
> Subject: Is utopen open?
> Organization: MetService
The above message contained the following:
> Is there a way to tell if the udunits library has already been initialised?
Not really.  It would be pretty simple, however, to add a utisopen()
function to the API.  Just add the following
    /*
     *  Indicate if the units(3) package has been initialized.
     *
     *  This function returns:
     *      0               if the units(3) package has not been initialized.
     *     !0               if the units(3) package has been initialized.
     */
        int
    utIsInit()
    {
        return initialized;
    }
    /*
     * FORTRAN interface to the above function.
     */
    FCALLSCFUN0(INT,utIsInit,UTISOPEN,utisopen)
to the file "lib/utlib.c" -- say, after the utOpen() function. Then,
rebuild and reinstall the package. From a Fortran-77 program, you would
then write
    if (utisopen()) begin
        ...
    else
        ...
    end
or something similar (my Fortran's pretty rusty).
> In a unit converting subroutine I would like to be able to check whether the
> unit definitions etc have been opened, and if not, open them.  At the moment
> a message like
> udunits(3): Already initialized from file ..." is printed out, since the
> utopen routine returns a zero status even though it is concerned enough to
> print a message.
> 
> Alternatively, how much overhead is involved in opening then closing udunits
> many times?
The database would have to be parsed every time.  I'd add the utisopen()
function, instead.
Regards,
Steve Emmerson   <http://www.unidata.ucar.edu>