#include <iostream>#include <string>#include <netcdf.h>#include <nco_fl.hh>#include <nco_utl.hh>Include dependency graph for nco_hgh.hh:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Classes | |
| struct | var_mtd_sct |
Functions | |
| int | nco_var_dfn (const int &nc_id, var_mtd_sct *var_mtd, const int &var_mtd_nbr, const int &dmn_nbr_max=10) |
|
||||||||||||||||||||
|
Definition at line 32 of file nco_hgh.cc. References NC_EINDEFINE, NC_NOERR, nco_def_var(), nco_enddef(), nco_inq_dim(), nco_put_att(), and nco_redef(). 00036 { 00037 /* Purpose: Process metadata structure, defining variables and attributes 00038 On entry, file is assumed to be open, and may be in define mode or in data mode 00039 On exit, file is placed in data mode 00040 Variable metadata is stored in single metadata input structure 00041 Routine only handles variable and attribute definition, not variable writing 00042 nc_id is modified as variables are defined 00043 var_mtd is modified as variable ID is returned after each definition 00044 fxm: It would be nice not to have to pass var_mtd_nbr from calling routine, 00045 but would presumably require a map container to accomplish 00046 */ 00047 00048 int rcd(0); // Return success code 00049 // Local 00050 register long idx; // [idx] Counting index 00051 const std::string sbr_nm("nco_var_dfn"); // [sng] Name of subroutine 00052 const unsigned short int dbg_lvl(0); // [sng] Debugging level 00053 if(dbg_lvl >= 5) std::cerr << "DEBUG: Entering " << sbr_nm << "()..." << std::endl; 00054 if(dbg_lvl >= 5) std::cerr << "DEBUG:"+sbr_nm+"() reports var_mtd_nbr = " << var_mtd_nbr << std::endl; 00055 00056 // Allow file to already be in define mode 00057 rcd=nco_redef(nc_id,NC_EINDEFINE); // [fnc] Put open netCDF dataset into define mode 00058 00059 int dmn_idx; // [idx] Counting index for dmn 00060 for(idx=0;idx<var_mtd_nbr;idx++){ 00061 // Set dmn_nbr_max to, e.g., 1, to limit output file size at expense of losing all 2-D variables 00062 if(var_mtd[idx].dmn_nbr <= dmn_nbr_max){ 00063 00064 // Sanity check before output 00065 if(dbg_lvl >= 5){ 00066 std::string dmn_nm; 00067 size_t dmn_sz; 00068 for(dmn_idx=0;dmn_idx<var_mtd[idx].dmn_nbr;dmn_idx++){ 00069 rcd=nco_inq_dim(nc_id,dmn_idx,dmn_nm,dmn_sz); 00070 std::cout << "Dimension " << dmn_nm << " is " << ((rcd != NC_NOERR) ? "valid" : "invalid" ) << " and has size " << dmn_sz << std::endl; 00071 } // end loop over dmn 00072 } // endif dbg 00073 00074 rcd=nco_def_var // [fnc] Define variable 00075 (nc_id, // I [enm] netCDF file for output 00076 var_mtd[idx].nm, // I [sng] Variable name 00077 var_mtd[idx].type, // I [enm] netCDF type 00078 var_mtd[idx].dmn_nbr, // I [nbr] Number of dimensions 00079 var_mtd[idx].dmn_id, // I [dmn] Dimension list 00080 var_mtd[idx].var_id); // O [var] Variable ID 00081 00082 rcd=nco_put_att // [fnc] Create attribute 00083 (nc_id, // I [enm] netCDF file for output 00084 var_mtd[idx].var_id, // [id] Variable ID 00085 var_mtd[idx].att_1_nm, // [sng] Attribute name 00086 var_mtd[idx].att_1_val); // [sng] Attribute value 00087 00088 rcd=nco_put_att // [fnc] Create attribute 00089 (nc_id, // I [enm] netCDF file for output 00090 var_mtd[idx].var_id, // [id] Variable ID 00091 var_mtd[idx].att_2_nm, // [sng] Attribute name 00092 var_mtd[idx].att_2_val); // [sng] Attribute value 00093 } // endif 00094 } // end loop over var 00095 00096 // Be in data mode on exit so values may be written 00097 rcd=nco_enddef(nc_id); // [fnc] Leave define mode 00098 00099 if(dbg_lvl >= 5) std::cerr << "DEBUG: Exiting " << sbr_nm << "()..." << std::endl; 00100 return rcd; // [enm] Return success code 00101 } // end nco_var_dfn()
|
1.4.4