本文整理汇总了C++中NcFile::add_dim方法的典型用法代码示例。如果您正苦于以下问题:C++ NcFile::add_dim方法的具体用法?C++ NcFile::add_dim怎么用?C++ NcFile::add_dim使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NcFile
的用法示例。
在下文中一共展示了NcFile::add_dim方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createDataSet
NCDataSet* NCDataSetBuilder::createDataSet() {
returned = true;
if (RepastProcess::instance()->rank() == 0) {
NcFile* ncfile = new NcFile(dataSet->file_.c_str(), NcFile::Replace, NULL, 0, NcFile::Offset64Bits);
NcDim* runDim = ncfile->add_dim("run", 1);
NcDim* tickDim = ncfile->add_dim("tick");
ncfile->add_var("tick", ncDouble, tickDim);
for (size_t i = 0; i < dataSet->dataSources.size(); i++) {
NCDataSource* ds = dataSet->dataSources[i];
ncfile->add_var(ds->name().c_str(), ds->ncType(), tickDim, runDim);
}
dataSet->ncfile = ncfile;
}
return dataSet;
}
示例2: bind
boost::function<void ()> Grid_LonLat::netcdf_define(NcFile &nc, std::string const &vname) const
{
auto parent = Grid::netcdf_define(nc, vname);
NcDim *lonbDim = nc.add_dim((vname + ".lon_boundaries.length").c_str(),
this->lonb.size());
NcVar *lonb_var = nc.add_var((vname + ".lon_boundaries").c_str(),
ncDouble, lonbDim);
NcDim *latbDim = nc.add_dim((vname + ".lat_boundaries.length").c_str(),
this->latb.size());
NcVar *latb_var = nc.add_var((vname + ".lat_boundaries").c_str(),
ncDouble, latbDim);
NcVar *info_var = nc.get_var((vname + ".info").c_str());
info_var->add_att("north_pole_cap", north_pole ? 1 : 0);
info_var->add_att("south_pole_cap", south_pole ? 1 : 0);
info_var->add_att("points_in_side", points_in_side);
info_var->add_att("nlon", nlon());
info_var->add_att("nlat", nlat());
return boost::bind(&Grid_LonLat_netcdf_write, parent, &nc, this, vname);
}
示例3: bind
boost::function<void()> zd11_c::netcdf_define(NcFile &nc, std::string const &vname)
{
auto oneDim = giss::get_or_add_dim(nc, "one", 1);
auto infoVar = nc.add_var((vname + ".info").c_str(), ncDouble, oneDim);
infoVar->add_att("m", this->m);
infoVar->add_att("n", this->n);
auto neDim = nc.add_dim((vname + ".ne").c_str(), this->ne);
nc.add_var((vname + ".row").c_str(), ncInt, neDim);
nc.add_var((vname + ".col").c_str(), ncInt, neDim);
nc.add_var((vname + ".val").c_str(), ncDouble, neDim);
return boost::bind(&netcdf_write, this, &nc, vname);
}
示例4: exception
boost::function<void ()> netcdf_define(
NcFile &nc,
std::string const &vname,
blitz::Array<T,rank> const &val,
std::vector<NcDim *> const &ddims = {})
{
// Type-check for unit strides
int stride = 1;
for (int i=rank-1; i>=0; --i) {
if (val.stride(i) != stride) {
fprintf(stderr, "Unexpected stride of %d (should be %d) in dimension %d (extent=%d) of %s (rank=%d)\n", val.stride(i), stride, i, val.extent(i), vname.c_str(), rank);
fprintf(stderr, "Are you trying to write a Fortran-style array? Use f_to_c() in blitz.hpp first\n");
throw std::exception();
}
//printf("(stride=%d) *= (val.extent[%d]=%d)\n", stride, i, val.extent(i));
stride *= val.extent(i);
}
// Create the required dimensions
NcDim const *dims[rank];
for (int i=0; i<rank; ++i) {
if (i >= ddims.size()) {
char dim_name[200];
sprintf(dim_name, "%s.dim%d", vname.c_str(), i);
dims[i] = nc.add_dim(dim_name, val.extent(i));
} else {
dims[i] = ddims[i];
}
assert(dims[i] != NULL);
}
// Create the variable
NcVar *nc_var = nc.add_var(vname.c_str(), get_nc_type<T>(), rank, dims);
assert(nc_var != NULL);
// Write it out (later)
return boost::bind(&netcdf_write_blitz<T,rank>, nc_var, val);
}
示例5: 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);
};
示例6: CopyNcVar
void CopyNcVar(
NcFile & ncIn,
NcFile & ncOut,
const std::string & strVarName,
bool fCopyAttributes,
bool fCopyData
) {
if (!ncIn.is_valid()) {
_EXCEPTIONT("Invalid input file specified");
}
if (!ncOut.is_valid()) {
_EXCEPTIONT("Invalid output file specified");
}
NcVar * var = ncIn.get_var(strVarName.c_str());
if (var == NULL) {
_EXCEPTION1("NetCDF file does not contain variable \"%s\"",
strVarName.c_str());
}
NcVar * varOut;
std::vector<NcDim *> dimOut;
dimOut.resize(var->num_dims());
std::vector<long> counts;
counts.resize(var->num_dims());
long nDataSize = 1;
for (int d = 0; d < var->num_dims(); d++) {
NcDim * dimA = var->get_dim(d);
dimOut[d] = ncOut.get_dim(dimA->name());
if (dimOut[d] == NULL) {
if (dimA->is_unlimited()) {
dimOut[d] = ncOut.add_dim(dimA->name());
} else {
dimOut[d] = ncOut.add_dim(dimA->name(), dimA->size());
}
if (dimOut[d] == NULL) {
_EXCEPTION2("Failed to add dimension \"%s\" (%i) to file",
dimA->name(), dimA->size());
}
}
if (dimOut[d]->size() != dimA->size()) {
if (dimA->is_unlimited() && !dimOut[d]->is_unlimited()) {
_EXCEPTION2("Mismatch between input file dimension \"%s\" and "
"output file dimension (UNLIMITED / %i)",
dimA->name(), dimOut[d]->size());
} else if (!dimA->is_unlimited() && dimOut[d]->is_unlimited()) {
_EXCEPTION2("Mismatch between input file dimension \"%s\" and "
"output file dimension (%i / UNLIMITED)",
dimA->name(), dimA->size());
} else if (!dimA->is_unlimited() && !dimOut[d]->is_unlimited()) {
_EXCEPTION3("Mismatch between input file dimension \"%s\" and "
"output file dimension (%i / %i)",
dimA->name(), dimA->size(), dimOut[d]->size());
}
}
counts[d] = dimA->size();
nDataSize *= counts[d];
}
// ncByte / ncChar type
if ((var->type() == ncByte) || (var->type() == ncChar)) {
DataVector<char> data;
data.Initialize(nDataSize);
varOut =
ncOut.add_var(
var->name(), var->type(),
dimOut.size(), (const NcDim**)&(dimOut[0]));
if (varOut == NULL) {
_EXCEPTION1("Cannot create variable \"%s\"", var->name());
}
var->get(&(data[0]), &(counts[0]));
varOut->put(&(data[0]), &(counts[0]));
}
// ncShort type
if (var->type() == ncShort) {
DataVector<short> data;
data.Initialize(nDataSize);
varOut =
ncOut.add_var(
var->name(), var->type(),
dimOut.size(), (const NcDim**)&(dimOut[0]));
if (varOut == NULL) {
_EXCEPTION1("Cannot create variable \"%s\"", var->name());
}
if (fCopyData) {
var->get(&(data[0]), &(counts[0]));
//.........这里部分代码省略.........
示例7: 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 );
}
示例8: ice_write
//.........这里部分代码省略.........
NcDim *dim_quadrilaterals;
NcDim *dim_tetrahedrons;
NcDim *dim_three;
NcDim *dim_triangles;
NcDim *dim_two;
NcDim *dim_vertices;
NcVar *var_edge_vertex;
NcVar *var_edge_label;
NcVar *var_hexahedron_vertex;
NcVar *var_hexahedron_label;
NcVar *var_quadrilateral_vertex;
NcVar *var_quadrilateral_label;
NcVar *var_tetrahedron_vertex;
NcVar *var_tetrahedron_label;
NcVar *var_triangle_vertex;
NcVar *var_triangle_label;
NcVar *var_vertex_coordinate;
NcVar *var_vertex_label;
//
// Create the file.
//
NcFile dataFile ( filename.c_str ( ), NcFile::Replace );
if ( !dataFile.is_valid ( ) )
{
cout << "\n";
cout << "ICE_WRITE - Fatal error!\n";
cout << " Could not open the file.\n";
exit ( 1 );
}
//
// Dimension information.
//
dim_dimension = dataFile.add_dim ( "Dimension", dim );
dim_vertices = dataFile.add_dim ( "Vertices", vertices );
if ( 0 < edges )
{
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 );
//