MGHNCREADFILE__DEFINE
Name
Class MGHncReadFile
Purpose
This class encapsulates a netCDF file for READ-ONLY access. It
exposes methods for manipulating dimensions, variables and
attributes.
Category
Scientific Data Formats.
Background
The original reason for having a separate netCDF class for
read-only access (c.f. MGHncFile, which allows read-write access)
was to work around the limit of 32 on the number of open netCDF
files in versions before IDL 6.0. An MGHncReadFile
object does not keep its file open for the lifetime of the
object--instead it calls NCDF_OPEN each time data is required and
NCDF_CLOSE afterwards. This is reasonably efficient for read-only
access, because opening and closing the file is not too
expensive. It would not make sense if the file were to be changed,
because then changes would be flushed to disk on every close.
With the above modification it becomes practical to maintain
sequences of MGHncReadFile objects, as is done by the
MGHncSequence class. After some experience with the latter, I
found it desirable to also add to the MGHncReadFile class the
facility to specify that a subset of records (positions along the
unlimited dimension) were to be read. (For a while I kept track of
this inside MGHncSequence, but the arithmetic was horrendous.)
Some time in the future I may move the "open only when necessary"
functionality into MGHncFile (or into a yet-to-be invented class)
in order to separate it from the "select records" functionality.
Properties
TMP (Init, Get)
Set this property to 1 to make a temporary copy of the netCDF
file. This can be highly advantageous when the original is on a
fast network drive, where opening and closing the file
repeatedly (as MGHncReadFile methods tend to do) is slow and
copying the whole file is reasonably fast.
###########################################################################
Copyright (c) 2000-2012 NIWA:
http://www.niwa.co.nz/
Licensed under the MIT open source license:
http://www.opensource.org/licenses/mit-license.php
###########################################################################
Modification History
Mark Hadfield, 2000-02:
Written, based on MGHncFile.
Mark Hadfield, 2000-05:
Cleaned up code and added the ability to specify a subset of the
records: all operations involving the unlimited dimension can
see only this subset.
Mark Hadfield, 2001-11:
Major overhaul of interface along with MGHncFile and
MGHncSequence. Eliminated the separate class, MGHncReadFileVar,
for variable objects.
Mark Hadfield, 2002-04:
Added a facility I've been considering for a while to the VarGet
method: a zero value in the COUNT vector means get all data and
a negative value in the OFFSET vector specifies an offset
relative to the end of the dataset.
Mark Hadfield, 2004-10:
Found and fixed a long-standing bug in HasAtt method: argument
order should resemble that of NCDF_ATTGET, ie either of
result = onc->HasAtt(var, att)
result = onc->HasAtt(att, /GLOBAL).
Mark Hadfield, 2008-10:
Cleaned up the valid-range code in the _VarGet method. This
was failing to detect missing FLOAT and DOUBLE data. It's still
not right for BYTE data.
Mark Hadfield, 2009-07:
Corrected error in the VarInfo method, discovered by Foldy Lajos:
the value returned by NCDF_VARINQ for a 2-byte integer is 'SHORT',
not 'INT'.
Mark Hadfield, 2010-10:
- Negative values of self.ncid are no longer used to indicate
that the netCDF file is not open (because I am not sure if
NCDF_OPEN can return a negative value). Instead a separate
is_open property is maintained.
- Since NCDF_VARINQ in IDL 8.0 returns 'INT' for a 2-byte integer
(this may be a reversion to its previous behaviour) the code
in the VarInfo method can handle either 'INT' or 'SHORT'.
Mark Hadfield, 2013-02:
- Fixed a bug(possibly version-specific) in processing of variable
scaling attributes like "valid_range": it failed for variables with
no attributes.