Hi all,
Thank you for your replies.
The differences in the documentation seems to confirm that using NF90_GLOBAL as
"varid" is not possible for nf90_inquire_variable().
I will use the solution proposed by Nick Papior and will also explore NCDF
further.
Best Regards,
Jim
-----Original Message-----
From: Wei-keng Liao [mailto:wkliao@xxxxxxxxxxxxxxxxxxxxx]
Sent: 14 July 2015 20:48
To: Dave Allured - NOAA Affiliate
Cc: Jim Enright; netcdfgroup@xxxxxxxxxxxxxxxx
Subject: Re: [netcdfgroup] Question about using nf90_inquire_variable
If NC_GLOBAL can be used in the varid argument of some netCDF APIs, should it
be considered as invalid in some other APIs? I wish the document can be more
specific.
I am fine with making NC_GLOBAL illegal in nf90_inquire_variable and returning
an error makes more sense than allowing it.
Wei-keng
On Jul 14, 2015, at 2:04 PM, Dave Allured - NOAA Affiliate wrote:
> Wei-keng and Jim,
>
> This is not a bug, IMO. Compare the documentation for these two functions:
>
> nf90_inquire_attribute(ncid, varid, name ...
> varid
> Variable ID of the attribute's variable, or NF90_GLOBAL for a global
> attribute.
>
> nf90_inquire_variable(ncid, varid, name ...
> varid
> Variable ID.
>
> A variable ID of NF90_GLOBAL is explicitly allowed with
> nf90_inquire_attribute, but not with nf90_inquire_variable. The intended
> functions for discovering global attributes are nf90_inquire and
> nf90_inquire_attribute. With a bit of study, the F90 documentation on this
> topic seems rather clear to me.
>
> Attempting to use nf90_inquire_variable for global attributes is a
> mis-application of that function. Furthermore, that function is probably
> returning the appropriate error code in this case, as documented: "The
> variable ID is invalid for the specified netCDF dataset."
>
> Nick Paplor's suggested fix looks good to me.
>
> --Dave
>
>
> On Tue, Jul 14, 2015 at 12:16 PM, Wei-keng Liao
> <wkliao@xxxxxxxxxxxxxxxxxxxxx> wrote:
> > These latter two functions accept NF90_GLOBAL as "varid" but an error is
> > thrown when this is used for varid in nf90_inquire_variable().
>
> This may be a bug.
> The netCDF Fortran 90 document did not say using NF90_GLOBAL in the varid
> argument is illegal.
> As nf90_inquire_variable() calls nc_inq_var() internally, the netCDF-C
> 4.3.3.1 document for nc_inq_var() also did not say using NC_GLOBAL is illegal.
>
> Although nf90_inquire() can get you the desired result as pointed out
> by Nick Papior, but you may still want to report this possible bug to
> the Unidata netCDF Support <support-netcdf@xxxxxxxxxxxxxxxx>
>
> Wei-keng
>
> On Jul 14, 2015, at 11:13 AM, <Jim.Enright@xxxxxxxxxxxxxx>
> <Jim.Enright@xxxxxxxxxxxxxx> wrote:
>
> > Hi,
> >
> > I'm wondering if it is possible to use the nf90_inquire_variable() function
> > to find information about global attributes in a similar way to
> > nf90_inquire_attribute()?
> > For example, should it be possible to set varid to be NF90_GLOBAL to find
> > the number of global attributes? i.e.:
> > call check(nf90_inquire_variable(ncid, NF90_GLOBAL, nAtts =
> > numAttr))
> >
> > The reason for this query is because we have a code block (snippet shown
> > below) which prints some header information by looping over an array of
> > variables.
> > It first calls nf90_inquire_variable to get the number of attributes and
> > then uses this to get more details about the attributes by calling
> > nf90_inq_attname() and nf90_inquire_attribute().
> > These latter two functions accept NF90_GLOBAL as "varid" but an error is
> > thrown when this is used for varid in nf90_inquire_variable().
> > Is this the expected behaviour of nf90_inquire_variable? If so, can you
> > recommend the best alternative way to get the number of global attributes -
> > nf90_inquire() perhaps?
> >
> > do idxVar = varBegin, numVars
> >
> > varName = varInfoArray%varInfoArr(idxVar)%varName
> >
> > if( varName .eq. 'UNDEFINED' ) then
> > varid = nf90_global
> > else
> > varid = varInfoArray%varInfoArr(idxVar)%varId
> > end if
> >
> > call check( nf90_inquire_variable( ncid, varid, nAtts = numAttr ) ...
> > ... do idxAttr = 1, numAttr
> >
> > ! Get the names & details of the attributes call check(
> > nf90_inq_attname( ncid, varid, idxAttr, attrName ))
> >
> > call check( nf90_inquire_attribute( ncid, varid, attrName,
> > netCDFType, numAttrValues )) end do ... end do
> >
> > Best regards,
> > Jim
______________________________________________________________________
Fujitsu Laboratories of Europe Limited
Hayes Park Central, Hayes End Road, Hayes, Middlesex, UB4 8FE
Registered No. 4153469
This e-mail and any attachments are for the sole use of addressee(s) and
may contain information which is privileged and confidential. Unauthorised
use or copying for disclosure is strictly prohibited. The fact that this
e-mail has been scanned by Trendmicro Interscan does not guarantee that
it has not been intercepted or amended nor that it is virus-free.