NCTool Class Reference

Collects together parallel NetCDF methods used by IceModel and IceModelVec. More...

#include <nc_util.hh>

Inheritance diagram for NCTool:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 NCTool (MPI_Comm c, PetscMPIInt r)
virtual ~NCTool ()
virtual PetscErrorCode open_for_reading (const char filename[])
 Opens a NetCDF file for reading.
virtual PetscErrorCode open_for_writing (const char filename[])
 Opens a file for writing if it exists, creates if it does not.
virtual PetscErrorCode close ()
 Closes a NetCDF file.
virtual PetscErrorCode find_variable (string short_name, string standard_name, int *varid, bool &exists, bool &found_by_standard_name) const
 Finds the variable by its standard_name attribute.
virtual PetscErrorCode find_variable (string short_name, string standard_name, int *varid, bool &exists) const
virtual PetscErrorCode find_variable (string short_name, int *varid, bool &exists) const
virtual PetscErrorCode find_dimension (const char short_name[], int *dimid, bool &exists) const
virtual PetscErrorCode append_time (PetscReal time) const
 Appends time to the t dimension.
virtual PetscErrorCode write_history (const char history[], bool overwrite=false) const
 Writes history to the history global attribute of a NetCDF dataset.
virtual PetscErrorCode get_last_time (double *time) const
 Read the last value of the time variable t from a NetCDF file.
virtual PetscErrorCode get_vertical_dims (double *&z_levels, double *&zb_levels) const
 Read in the variables z and zb from the NetCDF file; do not assume they are equally-spaced.
virtual bool check_dimension (const char dim[], int len) const
 Checks if the dimension dim in a NetCDF file is OK.
virtual PetscErrorCode get_dim_length (const char name[], int *len) const
 Finds the length of a dimension. Returns 0 if failed.
virtual PetscErrorCode get_dim_limits (const char name[], double *min, double *max) const
 Gets dimension limits.
virtual PetscErrorCode put_dimension (int varid, int len, PetscScalar *vals) const
 Put the variable for a dimension in a NetCDF file. Makes no assumption about spacing.
virtual PetscErrorCode put_dimension_regular (int varid, int len, double start, double delta) const
 Put the variable for a dimension in a NetCDF file.
virtual PetscErrorCode inq_unlimdim (int &unlimdimid) const
 Get the dimension ID of an unlimited dimension. Sets unlimdimid to -1 if there isn't one.
virtual PetscErrorCode inq_dimname (int dimid, string &name) const
 Get a name of a dimension by a dimension ID.
virtual PetscErrorCode inq_dimids (int varid, vector< int > &dimids) const
 Gets the list of dimensions a variable depends on.
virtual PetscErrorCode inq_nattrs (int varid, int &N) const
 Get the number of attributes of a variable.
virtual PetscErrorCode inq_att_name (int varid, int n, string &name) const
 Gets the name of the n-th (counting from 0) attribute of a NetCDF variable.
virtual PetscErrorCode inq_att_type (int varid, const char name[], nc_type &typep) const
 Get the attribute type.
virtual PetscErrorCode get_att_text (int varid, const char name[], string &result) const
 Reads a text attribute from a NetCDF file.
virtual PetscErrorCode get_att_double (int varid, const char name[], vector< double > &result) const
 Reads a scalar attribute from a NetCDF file.
virtual PetscErrorCode get_units (int varid, bool &has_units, utUnit &units) const
 Get variable's units information from a NetCDF file.
virtual int get_ncid () const

Protected Attributes

int ncid
MPI_Comm com
PetscMPIInt rank

Detailed Description

Collects together parallel NetCDF methods used by IceModel and IceModelVec.

Definition at line 51 of file nc_util.hh.


Constructor & Destructor Documentation

NCTool ( MPI_Comm  c,
PetscMPIInt  r 
)

Definition at line 39 of file nc_util.cc.

References com, and ncid.

~NCTool (  )  [virtual]

Definition at line 52 of file nc_util.cc.

References com, and ncid.


Member Function Documentation

PetscErrorCode append_time ( PetscReal  time  )  const [virtual]
bool check_dimension ( const char  name[],
int  len 
) const [virtual]

Checks if the dimension dim in a NetCDF file is OK.

A dimension is OK if is exists and its length is equal to len. If len < 0, then dimension length is ignored.

On processor 0 returns true if OK, false otherwise. Always returns true on processors other than 0.

Definition at line 314 of file nc_util.cc.

References ncid, and rank.

Referenced by PISMIO.check_dimensions().

PetscErrorCode close (  )  [virtual]
PetscErrorCode find_dimension ( const char  short_name[],
int *  dimid,
bool &  exists 
) const [virtual]

Definition at line 64 of file nc_util.cc.

References com, ncid, and rank.

Referenced by IceModel.set_grid_defaults(), and NCTimeseries.write().

PetscErrorCode find_variable ( string  short_name,
int *  varid,
bool &  exists 
) const [virtual]

Definition at line 174 of file nc_util.cc.

References find_variable().

PetscErrorCode find_variable ( string  short_name,
string  standard_name,
int *  varid,
bool &  exists 
) const [virtual]

Definition at line 165 of file nc_util.cc.

References find_variable().

PetscErrorCode find_variable ( string  short_name,
string  standard_name,
int *  varidp,
bool &  exists,
bool &  found_by_standard_name 
) const [virtual]

Finds the variable by its standard_name attribute.

Here's how it works:

  1. Check if the current IceModelVec has a standard_name. If it does, go to step 2, otherwise go to step 4.

  2. Find the variable with this standard_name. Bail out if two variables have the same standard_name, otherwise go to step 3.

  3. If no variable was found, go to step 4, otherwise go to step 5.

  4. Find the variable with the right variable name. Go to step 5.

  5. Broadcast the existence flag and the variable ID.

Definition at line 105 of file nc_util.cc.

References check_err(), com, get_att_text(), ncid, and rank.

Referenced by IceModel.bootstrapFromFile(), find_variable(), get_dim_limits(), IceModel.grid_setup(), IceModel.initFromFile(), main(), NCTimeseries.read(), NCConfigVariable.read(), NCSpatialVariable.read(), IceModel.readShelfStreamBCFromFile(), NCSpatialVariable.regrid(), IceModel.set_grid_defaults(), NCTimeseries.write(), NCConfigVariable.write(), and NCSpatialVariable.write().

PetscErrorCode get_att_double ( int  varid,
const char  name[],
vector< double > &  result 
) const [virtual]

Reads a scalar attribute from a NetCDF file.

Definition at line 595 of file nc_util.cc.

References com, ncid, and rank.

Referenced by NCGlobalAttributes.read(), NCConfigVariable.read(), and NCVariable.read_valid_range().

PetscErrorCode get_att_text ( int  varid,
const char  name[],
string &  result 
) const [virtual]

Reads a text attribute from a NetCDF file.

Missimg and empty attributes are treated the same.

Definition at line 550 of file nc_util.cc.

References com, ncid, and rank.

Referenced by find_variable(), get_units(), IceModel.grid_setup(), IceModel.initFromFile(), NCGlobalAttributes.read(), NCConfigVariable.read(), NCVariable.read_valid_range(), NCGlobalAttributes.write_attributes(), and write_history().

PetscErrorCode get_dim_length ( const char  name[],
int *  len 
) const [virtual]
PetscErrorCode get_dim_limits ( const char  name[],
double min,
double max 
) const [virtual]

Gets dimension limits.

Gets dimension limits (i.e. min and max values of the coordinate variable).

Sets min = 0 and max = 0 if the dimension name has length 0.

Set min or max to NULL to omit the corresponding value.

Definition at line 457 of file nc_util.cc.

References check_err(), com, count, fill_missing.data, find_variable(), get_dim_length(), get_units(), vnreport.input, ncid, fill_missing.range, rank, TEMPORARY_STRING_LENGTH, and verbPrintf().

Referenced by PISMIO.get_grid_info(), PISMIO.get_grid_info_2d(), and get_last_time().

PetscErrorCode get_last_time ( double time  )  const [virtual]

Read the last value of the time variable t from a NetCDF file.

Definition at line 179 of file nc_util.cc.

References get_dim_limits().

int get_ncid (  )  const [virtual]
PetscErrorCode get_units ( int  varid,
bool &  has_units,
utUnit &  units 
) const [virtual]

Get variable's units information from a NetCDF file.

Note that this function intentionally ignores the reference date.

Definition at line 636 of file nc_util.cc.

References com, get_att_text(), and n.

Referenced by get_dim_limits(), NCTimeseries.read(), NCSpatialVariable.read(), and NCSpatialVariable.regrid().

PetscErrorCode get_vertical_dims ( double *&  z_levels,
double *&  zb_levels 
) const [virtual]

Read in the variables z and zb from the NetCDF file; do not assume they are equally-spaced.

This function allocates arrays z_levels and zb_levels, and they have to be freed by the caller (using delete[]).

Definition at line 191 of file nc_util.cc.

References check_err(), com, get_dim_length(), ncid, and rank.

Referenced by PISMIO.get_grid(), and IceModel.regrid().

PetscErrorCode inq_att_name ( int  varid,
int  n,
string &  name 
) const [virtual]

Gets the name of the n-th (counting from 0) attribute of a NetCDF variable.

Definition at line 699 of file nc_util.cc.

References check_err(), com, ncid, and rank.

Referenced by NCGlobalAttributes.read(), and NCConfigVariable.read().

PetscErrorCode inq_att_type ( int  varid,
const char  name[],
nc_type &  typep 
) const [virtual]

Get the attribute type.

Definition at line 683 of file nc_util.cc.

References check_err(), com, ncid, and rank.

Referenced by NCGlobalAttributes.read(), and NCConfigVariable.read().

PetscErrorCode inq_dimids ( int  varid,
vector< int > &  dimids 
) const [virtual]

Gets the list of dimensions a variable depends on.

The length of the result (dimids) is the number of dimensions.

Definition at line 716 of file nc_util.cc.

References check_err(), com, ncid, and rank.

Referenced by NCTimeseries.read().

PetscErrorCode inq_dimname ( int  dimid,
string &  name 
) const [virtual]

Get a name of a dimension by a dimension ID.

Definition at line 742 of file nc_util.cc.

References check_err(), com, ncid, and rank.

Referenced by NCTimeseries.read().

PetscErrorCode inq_nattrs ( int  varid,
int &  N 
) const [virtual]

Get the number of attributes of a variable.

Definition at line 671 of file nc_util.cc.

References check_err(), com, ncid, and rank.

Referenced by NCGlobalAttributes.read(), and NCConfigVariable.read().

PetscErrorCode inq_unlimdim ( int &  unlimdimid  )  const [virtual]

Get the dimension ID of an unlimited dimension. Sets unlimdimid to -1 if there isn't one.

Definition at line 756 of file nc_util.cc.

References check_err(), com, ncid, and rank.

PetscErrorCode open_for_reading ( const char  filename[]  )  [virtual]
PetscErrorCode open_for_writing ( const char  filename[]  )  [virtual]

Opens a file for writing if it exists, creates if it does not.

Definition at line 393 of file nc_util.cc.

References check_err(), com, ncid, and rank.

Referenced by IcePSTexModel.prepare_series(), IceExactSSAModel.reportErrors(), IceCompModel.reportErrors(), NCGlobalAttributes.write(), NCTimeseries.write(), and NCConfigVariable.write().

PetscErrorCode put_dimension ( int  varid,
int  len,
PetscScalar *  vals 
) const [virtual]

Put the variable for a dimension in a NetCDF file. Makes no assumption about spacing.

Definition at line 262 of file nc_util.cc.

References check_err(), double, and ncid.

Referenced by PISMIO.create_dimensions().

PetscErrorCode put_dimension_regular ( int  varid,
int  len,
double  start,
double  end 
) const [virtual]

Put the variable for a dimension in a NetCDF file.

Uses starting and ending values and a grid length for regularly-spaced values.

Definition at line 234 of file nc_util.cc.

References check_err(), and ncid.

PetscErrorCode write_history ( const char  history[],
bool  overwrite = false 
) const [virtual]

Writes history to the history global attribute of a NetCDF dataset.

Appends if overwrite == false (default).

Definition at line 280 of file nc_util.cc.

References check_err(), get_att_text(), ncid, and rank.

Referenced by IceModel.write_extras(), IceModel.write_snapshot(), and writePCCStateAtTimes().


Member Data Documentation

MPI_Comm com [protected]
int ncid [protected]
PetscMPIInt rank [protected]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Defines
Generated by  doxygen 1.6.2-20100124