本文整理汇总了C++中NcFile::close方法的典型用法代码示例。如果您正苦于以下问题:C++ NcFile::close方法的具体用法?C++ NcFile::close怎么用?C++ NcFile::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NcFile
的用法示例。
在下文中一共展示了NcFile::close方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: netcdf_mpas_read_xyzvertex
void netcdf_mpas_read_xyzvertex ( string filename, int nvertices,
double xvertex[], double yvertex[], double zvertex[] )
//****************************************************************************80
//
// Purpose:
//
// NETCDF_MPAS_READ_CELLS gets the cell center coordinates.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 01 January 2011
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
// The NETCDF User's Guide,
// Unidata Program Center, March 2009.
//
// Parameters:
//
// Input, string NC_FILENAME, the name of the NETCDF file to examine.
//
// Input, int NVERTICES, the number of vertices.
//
// Output, double XVERTEX[NVERTICES], YVERTEXL[NVERTICES],
// ZVERTEX[NVERTICES], the coordinates of the nodes.
//
{
NcVar *var_id;
//
// Open the file.
//
NcFile ncid ( filename.c_str ( ), NcFile::ReadOnly );
//
// Get the variable values.
//
var_id = ncid.get_var ( "xVertex" );
(*var_id).get ( &xvertex[0], nvertices );
var_id = ncid.get_var ( "yVertex" );
(*var_id).get ( &yvertex[0], nvertices );
var_id = ncid.get_var ( "zVertex" );
(*var_id).get ( &zvertex[0], nvertices );
//
// Close the file.
//
ncid.close ( );
return;
}
示例2: netcdf_mpas_read_xyzcell
void netcdf_mpas_read_xyzcell ( string filename, int ncells, double xcell[],
double ycell[], double zcell[] )
//****************************************************************************80
//
// Purpose:
//
// NETCDF_MPAS_READ_XYZCELL reads xCell, yCell, zCell.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 29 December 2010
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
// The NETCDF User's Guide,
// Unidata Program Center, March 2009.
//
// Parameters:
//
// Input, string NC_FILENAME, the name of the NETCDF file to examine.
//
// Input, int NCELLS, the number of nodes.
//
// Output, double XCELL[NCELLS], YCELL[NCELLS], ZCELL[NCELLS], the
// coordinates of the nodes.
//
{
NcVar *var_id;
//
// Open the file.
//
NcFile ncid ( filename.c_str ( ), NcFile::ReadOnly );
//
// Get the variable values.
//
var_id = ncid.get_var ( "xCell" );
(*var_id).get ( &xcell[0], ncells );
var_id = ncid.get_var ( "yCell" );
(*var_id).get ( &ycell[0], ncells );
var_id = ncid.get_var ( "zCell" );
(*var_id).get ( &zcell[0], ncells );
//
// Close the file.
//
ncid.close ( );
return;
}
示例3: netcdf_mpas_read_verticesoncell
void netcdf_mpas_read_verticesoncell ( string filename, int maxedges,
int ncells, int verticesoncell[] )
//****************************************************************************80
//
// Purpose:
//
// NETCDF_MPAS_READ_VERTICESONCELLS gets verticesOnCells.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 01 January 2011
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
// The NETCDF User's Guide,
// Unidata Program Center, March 2009.
//
// Parameters:
//
// Input, string NC_FILENAME, the name of the NETCDF file to examine.
//
// Input, int MAXEDGES, the maximum number of edges for a cell.
//
// Input, int NCELLS, the number of cells.
//
// Output, int VERTICESONCELLS[MAXEDGES*NCELLS];
//
{
NcVar *var_id;
//
// Open the file.
//
NcFile ncid ( filename.c_str ( ), NcFile::ReadOnly );
//
// Get the variable values.
//
var_id = ncid.get_var ( "verticesOnCell" );
(*var_id).get ( &verticesoncell[0], ncells, maxedges );
//
// Close the file.
//
ncid.close ( );
return;
}
示例4: netcdf_mpas_read_maxedges
int netcdf_mpas_read_maxedges ( string filename )
//****************************************************************************80
//
// Purpose:
//
// NETCDF_MPAS_READ_MAXEDGES gets MAXEDGES.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 01 January 2011
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
// The NETCDF User's Guide,
// Unidata Program Center, March 2009.
//
// Parameters:
//
// Input, string NC_FILENAME, the name of the NETCDF file to examine.
//
// Output, int NETCDF_MPAS_READ_MAXEDGES, the value of MAXEDGES.
//
{
int maxedges;
long int maxedges_size;
NcDim *maxedges_id;
//
// Open the file.
//
NcFile ncid ( filename.c_str ( ), NcFile::ReadOnly );
//
// Get MAXEDGES, which is a NETCDF dimension.
//
maxedges_id = ncid.get_dim ( "maxEdges" );
maxedges_size = (*maxedges_id).size ( );
//
// Close the file.
//
ncid.close ( );
maxedges = ( int ) maxedges_size;
return maxedges;
}
示例5: netcdf_mpas_read_nvertices
int netcdf_mpas_read_nvertices ( string filename )
//****************************************************************************80
//
// Purpose:
//
// NETCDF_MPAS_READ_NVERTICES gets the number of vertices.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 30 December 2010
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
// The NETCDF User's Guide,
// Unidata Program Center, March 2009.
//
// Parameters:
//
// Input, string NC_FILENAME, the name of the NETCDF file to examine.
//
// Output, int NETCDF_MPAS_READ_NVERTICES, the value of NVERTICES.
//
{
int nvertices;
long int nvertices_size;
NcDim *nvertices_id;
//
// Open the file.
//
NcFile ncid ( filename.c_str ( ), NcFile::ReadOnly );
//
// Get NCELLS, which is a NETCDF dimension.
//
nvertices_id = ncid.get_dim ( "nVertices" );
nvertices_size = (*nvertices_id).size ( );
//
// Close the file.
//
ncid.close ( );
nvertices = ( int ) nvertices_size;
return nvertices;
}
示例6: isValid
bool FileArome::isValid(std::string iFilename) {
bool status = false;
NcFile file = NcFile(iFilename.c_str(), NcFile::ReadOnly);
if(file.is_valid()) {
status = hasDim(file, "time") && hasDim(file, "x") && hasDim(file, "y") &&
!hasDim(file, "ensemble_member") &&
hasVar(file, "latitude") && hasVar(file, "longitude");
}
file.close();
return status;
}
示例7: netcdf_mpas_read_cellsonvertex
void netcdf_mpas_read_cellsonvertex ( string filename, int nvertices,
int cellsonvertex[] )
//****************************************************************************80
//
// Purpose:
//
// NETCDF_MPAS_READ_CELLSONVERTEX gets the cellsOnVertex information.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 30 December 2010
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
// The NETCDF User's Guide,
// Unidata Program Center, March 2009.
//
// Parameters:
//
// Input, string NC_FILENAME, the name of the NETCDF file to examine.
//
// Input, int NEDGES, the number of edges.
//
// Output, int CELLSONVERTEX[3*NVERTICES];
//
{
NcVar *var_id;
//
// Open the file.
//
NcFile ncid ( filename.c_str ( ), NcFile::ReadOnly );
//
// Get the variable values.
//
var_id = ncid.get_var ( "cellsOnVertex" );
(*var_id).get ( &cellsonvertex[0], nvertices, 3 );
//
// Close the file.
//
ncid.close ( );
return;
}
示例8: createSoilClimate
void CCohortdriver::createSoilClimate(BgcData *bd, EnvData *ed, Vegetation_Env *ve,
string& datadir){
string file = datadir+ "calirestart.nc";
NcFile* resFile = new NcFile(file.c_str(), NcFile::Replace);
NcDim * chtD = resFile->add_dim("CHTID", 1);
NcDim * monD = resFile->add_dim("MON", 12);
NcDim * layD = resFile->add_dim("LAYER", MAX_SOI_LAY);
NcVar* drgV = resFile->add_var("DRG",ncInt, chtD);
NcVar* vegV = resFile->add_var("VEG",ncInt, chtD);
NcVar* numslV = resFile->add_var("NUMSL",ncInt, chtD);
NcVar* rsoilcV = resFile->add_var("RSOILC", ncDouble, layD);
NcVar* nsoilcV = resFile->add_var("NSOILC", ncDouble, layD);
NcVar* dzV = resFile->add_var("DZ", ncDouble, layD);
NcVar* typeV = resFile->add_var("TYPE", ncDouble, layD);
NcVar* poroV = resFile->add_var("PORO", ncDouble, layD);
NcVar* rootfracV = resFile->add_var("ROOTFRAC", ncDouble, layD);
NcVar* taV = resFile->add_var("TA",ncDouble, monD);
NcVar* growV = resFile->add_var("GROW",ncDouble, monD);
NcVar* co2V = resFile->add_var("CO2",ncDouble, monD);
NcVar* petV = resFile->add_var("PET",ncDouble, monD);
NcVar* eetV = resFile->add_var("EET",ncDouble, monD);
NcVar* parV = resFile->add_var("PAR",ncDouble, monD);
NcVar* envlaiV = resFile->add_var("ENVLAI",ncFloat, monD);
NcVar* tsV = resFile->add_var("TS", ncDouble, monD, layD);
NcVar* ch4V = resFile->add_var("CH4",ncDouble, monD, layD);
NcVar* liqV = resFile->add_var("LIQ",ncDouble, monD, layD);
NcVar* vwcV = resFile->add_var("VSM",ncDouble, monD, layD);
NcVar* swsV = resFile->add_var("SWS",ncDouble, monD, layD);
NcVar* iceV = resFile->add_var("ICE",ncDouble, monD, layD);
NcVar* yreetV = resFile->add_var("YREET",ncDouble, chtD);
NcVar* yrpetV = resFile->add_var("YRPET",ncDouble, chtD);
NcVar* yrco2V = resFile->add_var("YRCO2",ncDouble, chtD);
NcVar* prveetmxV = resFile->add_var("PRVEETMX",ncDouble, chtD);
NcVar* prvpetmxV = resFile->add_var("PRVPETMX",ncDouble, chtD);
numslV->put(&ed->m_soid.actual_num_soil, 1);
drgV->put(&ed->cd->drgtype, 1);
vegV->put(&ed->cd->vegtype, 1);
poroV->put(&ed->m_sois.por[0], MAX_SOI_LAY);
typeV->put(&ed->m_sois.type[0], MAX_SOI_LAY);
dzV->put(&ed->m_sois.dz[0], MAX_SOI_LAY);
rsoilcV->put(&bd->m_sois.reac[0], MAX_SOI_LAY);
nsoilcV->put(&bd->m_sois.nonc[0], MAX_SOI_LAY);
rootfracV->put(&ed->m_sois.rootfrac[0], MAX_SOI_LAY);
tsV->put(&ed->eq_ts[0][0], 12, MAX_SOI_LAY);
ch4V->put(&ed->eq_ch4[0][0], 12, MAX_SOI_LAY);
liqV->put(&ed->eq_liq[0][0], 12, MAX_SOI_LAY);
iceV->put(&ed->eq_ice[0][0], 12, MAX_SOI_LAY);
vwcV->put(&ed->eq_vwc[0][0], 12, MAX_SOI_LAY);
swsV->put(&ed->eq_sws[0][0], 12, MAX_SOI_LAY);
taV->put(&ed->eq_ta[0], 12);
petV->put(&ed->eq_pet[0], 12);
eetV->put(&ed->eq_eet[0], 12);
co2V->put(&ed->eq_co2[0], 12);
parV->put(&ed->eq_par[0], 12);
growV->put(&ed->eq_grow[0], 12);
envlaiV->put(&ve->envlaiall[0], 12);
yreetV->put(&ed->eq_y_eet, 1);
yrpetV->put(&ed->eq_y_pet, 1);
yrco2V->put(&ed->eq_y_co2, 1);
prveetmxV->put(&ed->eq_prveetmx);
prvpetmxV->put(&ed->eq_prvpetmx);
resFile->close();
delete resFile; //Yuan: if not, memory leaking may occur
// exit(0);
};
示例9: netcdf_mpas_report
//.........这里部分代码省略.........
// Return information about the NETCDF file.
//
num_dims = ncid.num_dims ( );
num_vars = ncid.num_vars ( );
num_atts = ncid.num_atts ( );
unlimdimid = ncid.rec_dim ( );
cout << "\n";
cout << "PRIMARY PARAMETERS:\n";
cout << "\n";
cout << " The number of dimensions NUM_DIMS = " << num_dims << "\n";
cout << " The number of variables NUM_VARS = " << num_vars << "\n";
cout << " The number of global attributes NUM_ATTS = " << num_atts << "\n";
cout << " The unlimited dimension (if any) UNLIMDIMID = \"" << (*unlimdimid).name ( ) << "\"\n";
//
// Retrieve global attributes.
// First, we must evaluate the constant "NC_GLOBAL".
//
// nc_global = netcdf.getConstant ( 'NC_GLOBAL' );
cout << "\n";
cout << "GLOBAL ATTRIBUTES:\n";
cout << " Att --------Name-------- Type Len\n";
cout << "\n";
for ( i = 0; i < num_atts; i++ )
{
att = ncid.get_att ( i );
name = (*att).name ( );
type = (*att).type ( );
len = (*att).num_vals ( );
cout << " " << setw(2) << i
<< " \"" << setw(18) << name << "\""
<< " " << setw(4) << type
<< " " << setw(4) << len << "\n";
}
//
// Determine names and extents of dimensions.
// Since each NAME is a char array, we make a cell array to hold them.
//
cout << "\n";
cout << "DIMENSIONS:\n";
cout << " Dim --------Name-------- Extent\n";
cout << "\n";
for ( i = 0; i < num_dims; i++ )
{
dim = ncid.get_dim ( i );
name = (*dim).name ( );
len = (*dim).size ( );
cout << " " << setw(2) << i
<< " \"" << setw(18) << name << "\""
<< " " << setw(6) << len << "\n";
}
//
// Get variable names, types, dimensions, number of attributes.
//
cout << "\n";
cout << "VARIABLES:\n";
cout << " Var --------Name-------- Type Natts Ndims Dims\n";
cout << "\n";
for ( i = 0; i < num_vars; i++ )
{
var = ncid.get_var ( i );
name = (*var).name ( );
type = (*var).type ( );
num_dims = (*var).num_dims ( );
num_atts = (*var).num_atts ( );
cout << " " << setw(2) << i
<< " \"" << setw(18) << name << "\""
<< " " << setw(4) << type
<< " " << setw(4) << num_atts
<< " " << setw(4) << num_dims
<< " ";
for ( j = 0; j < num_dims; j++ )
{
dim = (*var).get_dim ( j );
if ( j == 0 )
{
cout << "[";
}
cout << (*dim).name ( );
if ( j < num_dims - 1 )
{
cout <<",";
}
else
{
cout << "]";
}
}
cout << "\n";
}
//
// Close the file.
//
ncid.close ( );
return;
}
示例10: NetCDFProduct
//.........这里部分代码省略.........
// Build up output NetCDF file name and open it
sprintf( NcName, "%s_%4d%02d%02d_%02d%02d.nc", channel,
tmtime->tm_year + 1900, tmtime->tm_mon + 1, tmtime->tm_mday,
tmtime->tm_hour, tmtime->tm_min );
NcFile ncf ( NcName , NcFile::Replace );
if (! ncf.is_valid()) return false;
// Fill arrays on creation
ncf.set_fill(NcFile::Fill);
// Add Global Attributes
if (! ncf.add_att("Satellite", MSG_spacecraft_name(spc).c_str()))
return false;
sprintf(reftime, "%04d-%02d-%02d %02d:%02d:00 UTC",
tmtime->tm_year + 1900, tmtime->tm_mon + 1, tmtime->tm_mday,
tmtime->tm_hour, tmtime->tm_min);
if (! ncf.add_att("Antenna", "Fixed") ) return false;
if (! ncf.add_att("Receiver", "HIMET") ) return false;
if (! ncf.add_att("Time", reftime) ) return false;
if (! ncf.add_att("Area_Name", "SpaceView" ) ) return false;
sprintf(projname, "GEOS(%3.1f)", sublon);
if (! ncf.add_att("Projection", projname) ) return false;
if (! ncf.add_att("Columns", AreaNpix ) ) return false;
if (! ncf.add_att("Lines", AreaNlin ) ) return false;
if (! ncf.add_att("SampleX", 1.0 ) ) return false;
if (! ncf.add_att("SampleY", 1.0 ) ) return false;
if (! ncf.add_att("AreaStartPix", AreaPixStart ) ) return false;
if (! ncf.add_att("AreaStartLin", AreaLinStart ) ) return false;
if (! ncf.add_att("Column_Scale_Factor", cfac) ) return false;
if (! ncf.add_att("Line_Scale_Factor", lfac) ) return false;
if (! ncf.add_att("Column_Offset", coff) ) return false;
if (! ncf.add_att("Line_Offset", loff) ) return false;
if (! ncf.add_att("Orbit_Radius", sh) ) return false;
if (! ncf.add_att("Longitude", sublon) ) return false;
if (! ncf.add_att("NortPolar", 1) ) return false;
if (! ncf.add_att("NorthSouth", 1) ) return false;
if (! ncf.add_att("title", TITLE) ) return false;
if (! ncf.add_att("Institution", INSTITUTION) ) return false;
if (! ncf.add_att("Type", TYPE) ) return false;
if (! ncf.add_att("Version", HIMET_VERSION) ) return false;
if (! ncf.add_att("Conventions", "COARDS") ) return false;
if (! ncf.add_att("history", "Created from raw data") ) return false;
// Dimensions
wd = AreaNpix;
hg = AreaNlin;
bpp = header[0].image_structure->number_of_bits_per_pixel;
ncal = (int) pow(2.0, bpp);
tdim = ncf.add_dim("time");
if (!tdim->is_valid()) return false;
ldim = ncf.add_dim("line", hg);
if (!ldim->is_valid()) return false;
cdim = ncf.add_dim("column", wd);
if (!cdim->is_valid()) return false;
caldim = ncf.add_dim("calibration", ncal);
if (!caldim->is_valid()) return false;
// Get calibration values
cal = PRO_data->prologue->radiometric_proc.get_calibration((int) chn, bpp);
// Add Calibration values
NcVar *cvar = ncf.add_var("calibration", ncFloat, caldim);
if (!cvar->is_valid()) return false;
cvar->add_att("long_name", "Calibration coefficients");
cvar->add_att("variable", channel);
if (chn > 3 && chn < 12)
cvar->add_att("units", "K");
else
cvar->add_att("units", "mW m^-2 sr^-1 (cm^-1)^-1");
if (!cvar->put(cal, ncal)) return false;
tvar = ncf.add_var("time", ncDouble, tdim);
if (!tvar->is_valid()) return false;
tvar->add_att("long_name", "Time");
tvar->add_att("units", "seconds since 2000-01-01 00:00:00 UTC");
double atime;
time_t ttime;
extern long timezone;
ttime = mktime(tmtime);
atime = ttime - 946684800 - timezone;
if (!tvar->put(&atime, 1)) return false;
ivar = ncf.add_var(channel, ncShort, tdim, ldim, cdim);
if (!ivar->is_valid()) return false;
if (!ivar->add_att("add_offset", 0.0)) return false;
if (!ivar->add_att("scale_factor", 1.0)) return false;
if (!ivar->add_att("chnum", chn)) return false;
// Write output values
if (!ivar->put((const short int *) pixels, 1, hg, wd)) return false;
// Close NetCDF output
(void) ncf.close( );
delete [ ] pixels;
delete [ ] cal;
return( true );
}
示例11: size_read
//.........这里部分代码省略.........
// Output, int *HEXAHEDRONS, the number of hexahedrons (may be 0).
//
{
NcDim *dim_dimension;
NcDim *dim_edges;
NcDim *dim_eight;
NcDim *dim_four;
NcDim *dim_hexahedrons;
NcToken dim_name;
int dim_num;
NcDim *dim_quadrilaterals;
NcDim *dim_tetrahedrons;
NcDim *dim_three;
NcDim *dim_triangles;
NcDim *dim_two;
NcDim *dim_vertices;
NcDim *dim_pointer;
int i;
//
// Initialize everything to nothing.
//
*dim = 0;
*vertices = 0;
*edges = 0;
*triangles = 0;
*quadrilaterals = 0;
*tetrahedrons = 0;
*hexahedrons = 0;
//
// Open the file in "read only" mode.
//
NcFile dataFile ( filename.c_str ( ), NcFile::ReadOnly );
if ( !dataFile.is_valid ( ) )
{
cout << "\n";
cout << "SIZE_READ: Fatal error!\n";
cout << " Could not open file.\n";
exit ( 1 );
}
//
// Get the dimension information.
//
// I would much prefer to write "0" as the size of certain dimensions, but I am not
// allowed to, so I simply omit them from the file.
//
// Therefore, when I open the file and try to determine dimensions, some dimensions
// are "missing", which I would have presumed I could discover painlessly by asking
// for pointers to them, and getting NULLs back. But that doesn't seem to work either.
//
// So my bonehead backup is simply to read all the dimensions by index, retrieve
// their names, and see what I find.
//
dim_num = dataFile.num_dims ( );
for ( i = 0; i < dim_num; i++ )
{
dim_pointer = dataFile.get_dim ( i );
dim_name = dim_pointer->name ( );
if ( !strcmp ( dim_name, "Dimension" ) )
{
*dim = dim_pointer->size ( );
}
else if ( !strcmp ( dim_name, "Vertices" ) )
{
*vertices = dim_pointer->size ( );
}
else if ( !strcmp ( dim_name, "Edges" ) )
{
*edges = dim_pointer->size ( );
}
else if ( !strcmp ( dim_name, "Triangles" ) )
{
*triangles = dim_pointer->size ( );
}
else if ( !strcmp ( dim_name, "Quadrilaterals" ) )
{
*quadrilaterals = dim_pointer->size ( );
}
else if ( !strcmp ( dim_name, "Tetrahedrons" ) )
{
*tetrahedrons = dim_pointer->size ( );
}
else if ( !strcmp ( dim_name, "Hexahedrons" ) )
{
*hexahedrons = dim_pointer->size ( );
}
else
{
cout << " Ignoring information about dimension \"" << dim_name << "\".\n";
}
}
//
// Close the file.
//
dataFile.close ( );
return;
}
示例12: data_read
//.........这里部分代码省略.........
// Output, int QUADRILATERAL_VERTEX[4*QUADRILATERALS], the vertices that
// form each quadrilateral.
//
// Output, int QUADRILATERAL_LABEL[QUADRILATERALS], a label for
// each quadrilateral.
//
// Output, int TETRAHEDRON_VERTEX[4*TETRAHEDRONS], the vertices that
// form each tetrahedron.
//
// Output, int TETRAHEDRON_LABEL[TETRAHEDRONS], a label for
// each tetrahedron.
//
// Output, int HEXAHEDRON_VERTEX[8*HEXAHEDRONS], the vertices that form
// each hexahedron.
//
// Output, int HEXAHEDRON_LABEL[HEXAHEDRONS], a label for each hexahedron.
//
{
//
// Open the file in "read only" mode.
//
NcFile dataFile ( filename.c_str ( ), NcFile::ReadOnly );
if ( !dataFile.is_valid ( ) )
{
cout << "\n";
cout << "DATA_READ: Fatal error!\n";
cout << " Could not open file.\n";
exit ( 1 );
}
//
// Vertices.
//
NcVar *var_vertex_coordinate = dataFile.get_var ( "Vertex_Coordinate" );
var_vertex_coordinate->get ( &vertex_coordinate[0], dim, vertices );
NcVar *var_vertex_label = dataFile.get_var ( "Vertex_Label" );
var_vertex_label->get ( &vertex_label[0], vertices );
//
// Edges.
//
if ( 0 < edges )
{
NcVar *var_edge_vertex = dataFile.get_var ( "Edge_Vertex" );
var_edge_vertex->get ( &edge_vertex[0], 2, edges );
NcVar *var_edge_label = dataFile.get_var ( "Edge_Label" );
var_edge_label->get ( &edge_label[0], edges );
}
//
// Triangles.
//
if ( 0 < triangles )
{
NcVar *var_triangle_vertex = dataFile.get_var ( "Triangle_Vertex" );
var_triangle_vertex->get ( &triangle_vertex[0], 3, triangles );
NcVar *var_triangle_label = dataFile.get_var ( "Triangle_Label" );
var_triangle_label->get ( &triangle_label[0], triangles );
}
//
// Quadrilaterals.
//
if ( 0 < quadrilaterals )
{
NcVar *var_quadrilateral_vertex = dataFile.get_var ( "Quadrilateral_Vertex" );
var_quadrilateral_vertex->get ( &quadrilateral_vertex[0], 4, quadrilaterals );
NcVar *var_quadrilateral_label = dataFile.get_var ( "Quadrilateral_Label" );
var_quadrilateral_label->get ( &quadrilateral_label[0], quadrilaterals );
}
//
// Tetrahedrons.
//
if ( 0 < tetrahedrons )
{
NcVar *var_tetrahedron_vertex = dataFile.get_var ( "Tetrahedron_Vertex" );
var_tetrahedron_vertex->get ( &tetrahedron_vertex[0], 4, tetrahedrons );
NcVar *var_tetrahedron_label = dataFile.get_var ( "Tetrahedron_Label" );
var_tetrahedron_label->get ( &tetrahedron_label[0], tetrahedrons );
}
//
// Hexahedrons.
//
if ( 0 < hexahedrons )
{
NcVar *var_hexahedron_vertex = dataFile.get_var ( "Hexahedron_Vertex" );
var_hexahedron_vertex->get ( &hexahedron_vertex[0], 8, hexahedrons );
NcVar *var_hexahedron_label = dataFile.get_var ( "Hexahedron_Label" );
var_hexahedron_label->get ( &hexahedron_label[0], hexahedrons );
}
//
// Close the file.
//
dataFile.close ( );
return;
}
示例13: ice_write
//.........这里部分代码省略.........
{
dim_edges = dataFile.add_dim ( "Edges", edges );
}
if ( 0 < triangles )
{
dim_triangles = dataFile.add_dim ( "Triangles", triangles );
}
if ( 0 < quadrilaterals )
{
dim_quadrilaterals = dataFile.add_dim ( "Quadrilaterals", quadrilaterals );
}
if ( 0 < tetrahedrons )
{
dim_tetrahedrons = dataFile.add_dim ( "Tetrahedrons", tetrahedrons );
}
if ( 0 < hexahedrons )
{
dim_hexahedrons = dataFile.add_dim ( "Hexahedrons", hexahedrons );
}
dim_two = dataFile.add_dim ( "Two", 2 );
dim_three = dataFile.add_dim ( "Three", 3 );
dim_four = dataFile.add_dim ( "Four", 4 );
dim_eight = dataFile.add_dim ( "Eight", 8 );
//
// Define variables.
//
var_vertex_coordinate = dataFile.add_var ( "Vertex_Coordinate", ncDouble, dim_three, dim_vertices );
var_vertex_label = dataFile.add_var ( "Vertex_Label", ncInt, dim_vertices );
if ( 0 < edges )
{
var_edge_vertex = dataFile.add_var ( "Edge_Vertex", ncInt, dim_two, dim_edges );
var_edge_label = dataFile.add_var ( "Edge_Label", ncInt, dim_edges );
}
if ( 0 < triangles )
{
var_triangle_vertex = dataFile.add_var ( "Triangle_Vertex", ncInt, dim_three, dim_triangles );
var_triangle_label = dataFile.add_var ( "Triangle_Label", ncInt, dim_triangles );
}
if ( 0 < quadrilaterals )
{
var_quadrilateral_vertex = dataFile.add_var ( "Quadrilateral_Vertex", ncInt, dim_four, dim_quadrilaterals );
var_quadrilateral_label = dataFile.add_var ( "Quadrilateral_Label", ncInt, dim_quadrilaterals );
}
if ( 0 < tetrahedrons )
{
var_tetrahedron_vertex = dataFile.add_var ( "Tetrahedron_Vertex", ncInt, dim_four, dim_tetrahedrons );
var_tetrahedron_label = dataFile.add_var ( "Tetrahedron_Label", ncInt, dim_tetrahedrons );
}
if ( 0 < hexahedrons )
{
var_hexahedron_vertex = dataFile.add_var ( "Hexahedron_Vertex", ncInt, dim_eight, dim_hexahedrons );
var_hexahedron_label = dataFile.add_var ( "Hexahedron_Label", ncInt, dim_hexahedrons );
}
//
// Write the data.
//
var_vertex_coordinate->put ( &vertex_coordinate[0], 3, vertices );
var_vertex_label->put ( &vertex_label[0], vertices );
if ( 0 < edges )
{
var_edge_vertex->put ( &edge_vertex[0], 2, edges );
var_edge_label->put ( &edge_label[0], edges );
}
if ( 0 < triangles )
{
var_triangle_vertex->put ( &triangle_vertex[0], 3, triangles );
var_triangle_label->put ( &triangle_label[0], triangles );
}
if ( 0 < quadrilaterals )
{
var_quadrilateral_vertex->put ( &quadrilateral_vertex[0], 4, quadrilaterals );
var_quadrilateral_label->put ( &quadrilateral_label[0], quadrilaterals );
}
if ( 0 < tetrahedrons )
{
var_tetrahedron_vertex->put ( &tetrahedron_vertex[0], 4, tetrahedrons );
var_tetrahedron_label->put ( &tetrahedron_label[0], tetrahedrons );
}
if ( 0 < hexahedrons )
{
var_hexahedron_vertex->put ( &hexahedron_vertex[0], 8, hexahedrons );
var_hexahedron_label->put ( &hexahedron_label[0], hexahedrons );
}
//
// Close the file.
//
dataFile.close ( );
return;
}