Collects together parallel NetCDF methods used by IceModel and IceModelVec. More...
#include <nc_util.hh>

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 |
Collects together parallel NetCDF methods used by IceModel and IceModelVec.
Definition at line 51 of file nc_util.hh.
| NCTool | ( | MPI_Comm | c, | |
| PetscMPIInt | r | |||
| ) |
Definition at line 39 of file nc_util.cc.
| ~NCTool | ( | ) | [virtual] |
Definition at line 52 of file nc_util.cc.
| PetscErrorCode append_time | ( | PetscReal | time | ) | const [virtual] |
Appends time to the t dimension.
Definition at line 340 of file nc_util.cc.
References check_err(), ncid, and rank.
Referenced by IceModel.dumpToFile(), IceUnitModel.test_IceModelVec2T(), IceUnitModel.test_IceModelVec2V(), IceModel.write_extras(), IceModel.write_snapshot(), and writePCCStateAtTimes().
| 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.
Referenced by PISMIO.check_dimensions().
| PetscErrorCode close | ( | ) | [virtual] |
Closes a NetCDF file.
Definition at line 383 of file nc_util.cc.
References check_err(), ncid, and rank.
Referenced by IceModel.bootstrapFromFile(), IceModel.dumpToFile(), PISMComponent.find_pism_input(), DiagnosticTimeseries.flush(), PISMIO.get_grid(), IceModel.grid_setup(), PSForceThickness.init(), IceModelVec2T.init(), IceModel.init_timeseries(), IceModel.initFromFile(), main(), IcePSTexModel.prepare_series(), NCGlobalAttributes.read(), NCTimeseries.read(), NCConfigVariable.read(), NCSpatialVariable.read(), IceROSSModel.readObservedVels(), IceModel.readShelfStreamBCFromFile(), NCSpatialVariable.regrid(), IceModel.regrid(), IceExactSSAModel.reportErrors(), IceCompModel.reportErrors(), IceModel.set_grid_defaults(), IceUnitModel.test_IceModelVec2T(), IceUnitModel.test_IceModelVec2V(), NCGlobalAttributes.write(), NCTimeseries.write(), NCConfigVariable.write(), NCSpatialVariable.write(), IceModel.write_extras(), IceModel.write_snapshot(), and writePCCStateAtTimes().
| 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:
Check if the current IceModelVec has a standard_name. If it does, go to step 2, otherwise go to step 4.
Find the variable with this standard_name. Bail out if two variables have the same standard_name, otherwise go to step 3.
If no variable was found, go to step 4, otherwise go to step 5.
Find the variable with the right variable name. Go to step 5.
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] |
Finds the length of a dimension. Returns 0 if failed.
Definition at line 431 of file nc_util.cc.
References check_err(), com, ncid, and rank.
Referenced by PISMComponent.find_pism_input(), DiagnosticTimeseries.flush(), get_dim_limits(), PISMIO.get_grid_info(), PISMIO.get_grid_info_2d(), get_vertical_dims(), IceModel.initFromFile(), main(), PISMIO.put_var(), NCTimeseries.read(), IceExactSSAModel.reportErrors(), and IceCompModel.reportErrors().
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] |
Definition at line 60 of file nc_util.cc.
References ncid.
Referenced by NCTimeseries.read(), NCTimeseries.write(), NCConfigVariable.write(), NCSpatialVariable.write(), NCGlobalAttributes.write_attributes(), NCConfigVariable.write_attributes(), and NCVariable.write_attributes().
| 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().
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] |
Opens a NetCDF file for reading.
Stops if a file does not exist or could not be opened.
Definition at line 361 of file nc_util.cc.
References com, ncid, and rank.
Referenced by IceModel.bootstrapFromFile(), PISMComponent.find_pism_input(), DiagnosticTimeseries.flush(), PISMIO.get_grid(), IceModel.grid_setup(), PSForceThickness.init(), IceModelVec2T.init(), IceModel.initFromFile(), main(), NCGlobalAttributes.read(), NCTimeseries.read(), NCConfigVariable.read(), NCSpatialVariable.read(), IceROSSModel.readObservedVels(), IceModel.readShelfStreamBCFromFile(), NCSpatialVariable.regrid(), IceModel.regrid(), and IceModel.set_grid_defaults().
| 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().
MPI_Comm com [protected] |
Definition at line 90 of file nc_util.hh.
Referenced by find_dimension(), find_variable(), get_att_double(), get_att_text(), get_dim_length(), get_dim_limits(), get_units(), PISMIO.get_var(), get_vertical_dims(), inq_att_name(), inq_att_type(), inq_dimids(), inq_dimname(), inq_nattrs(), inq_unlimdim(), NCTool(), open_for_reading(), PISMIO.open_for_writing(), open_for_writing(), PISMIO.put_var(), PISMIO.regrid_var(), and ~NCTool().
int ncid [protected] |
Definition at line 89 of file nc_util.hh.
Referenced by append_time(), check_dimension(), close(), PISMIO.compute_start_and_count(), PISMIO.create_dimensions(), find_dimension(), find_variable(), get_att_double(), get_att_text(), get_dim_length(), get_dim_limits(), get_ncid(), PISMIO.get_var(), get_vertical_dims(), inq_att_name(), inq_att_type(), inq_dimids(), inq_dimname(), inq_nattrs(), inq_unlimdim(), NCTool(), open_for_reading(), PISMIO.open_for_writing(), open_for_writing(), put_dimension(), put_dimension_regular(), PISMIO.put_var(), PISMIO.regrid_var(), write_history(), and ~NCTool().
PetscMPIInt rank [protected] |
Definition at line 91 of file nc_util.hh.
Referenced by append_time(), check_dimension(), close(), PISMIO.compute_start_and_count(), PISMIO.create_dimensions(), find_dimension(), find_variable(), get_att_double(), get_att_text(), get_dim_length(), get_dim_limits(), PISMIO.get_var(), get_vertical_dims(), inq_att_name(), inq_att_type(), inq_dimids(), inq_dimname(), inq_nattrs(), inq_unlimdim(), open_for_reading(), PISMIO.open_for_writing(), open_for_writing(), PISMIO.put_var(), PISMIO.regrid_var(), and write_history().
1.6.2-20100124