本文整理汇总了C++中NcDim类的典型用法代码示例。如果您正苦于以下问题:C++ NcDim类的具体用法?C++ NcDim怎么用?C++ NcDim使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NcDim类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nc_mdcrd
void COORD::read_netcdf(PRMTOP* Mol, char* filename){
NcFile nc_mdcrd(filename, NcFile::ReadOnly);
if (!nc_mdcrd.is_valid()){
printf("$ Could not open trajectory file %s. Please check.\n", filename);
}
NcDim* FrameDim = nc_mdcrd.get_dim("frame");
int size = FrameDim->size();
printf("# NetCDF Frame dimension: %d\n", size);
NcDim* NDim = nc_mdcrd.get_dim("atom");
const int Ndim = NDim->size();
if (Ndim != Mol->N){
printf("# Mismatch among number of atoms in PRMTOP (%d) and NETCDF (%d) files. Please check.\n", Mol->N, Ndim);
exit(1);
}
else {
printf("# NetCDF number of atoms: %d\n", Ndim);
}
NcVar* nc_Coordinates = nc_mdcrd.get_var("coordinates");
double coords[Ndim][3];
printf("#%12s %12s %12s %12s\n", "Step", "Elec", "VDW", "Total");
for (int frame=1; frame <= size; frame++){
nc_Coordinates->get(&coords[0][0], 1, Ndim, 3);
printf(" %12d ", frame);
Energy->compute_nb2(Mol, coords, this->astart, this->aend, this->bstart, this->bend);
nc_Coordinates->set_cur(frame);
}
}
示例2: dumpvars
void DumpableNcFile::dumpvars( void )
{
int n;
static const char* types[] =
{"","byte","char","short","long","float","double"};
NcVar* vp;
for(n = 0; vp = get_var(n); n++) {
cout << "\t" << types[vp->type()] << " " << vp->name() ;
if (vp->num_dims() > 0) {
cout << "(";
for (int d = 0; d < vp->num_dims(); d++) {
NcDim* dim = vp->get_dim(d);
cout << dim->name();
if (d < vp->num_dims()-1)
cout << ", ";
}
cout << ")";
}
cout << " ;\n";
// now dump each of this variable's attributes
dumpatts(*vp);
}
}
示例3: getLocationFilename
void InputNetcdf::getLocationsCore(std::vector<Location>& iLocations) const {
iLocations.clear();
std::string filename = getLocationFilename();
NcFile ncfile(filename.c_str());
if(ncfile.is_valid()) {
NcDim* ncLocationDim = ncfile.get_dim("Location");
int numLocations = ncLocationDim->size();
NcVar* ncLats = ncfile.get_var("Lat");
NcVar* ncLons = ncfile.get_var("Lon");
NcError q(NcError::silent_nonfatal);
NcVar* ncElevs = ncfile.get_var("Elev");
NcVar* ncIds = ncfile.get_var("Id");
bool hasId = false;
bool hasElev = false;
if(ncIds)
hasId = true;
if(ncElevs)
hasElev = true;
float* lats = new float[numLocations];
float* lons = new float[numLocations];
float* elevs = new float[numLocations];
int* ids = new int[numLocations];
long count[1] = {numLocations};
ncLats->get(lats, count);
ncLons->get(lons, count);
if(hasId)
ncIds->get(ids, count);
if(hasElev)
ncElevs->get(elevs, count);
for(int i = 0; i < numLocations; i++) {
int id = i;
if(hasId)
id = ids[i];
float lat = lats[i];
float lon = lons[i];
float elev = Global::MV;
if(hasElev)
elev = elevs[i];
Location loc(getName(), id, lat, lon);
loc.setElev(elev);
iLocations.push_back(loc);
}
delete[] lats;
delete[] lons;
delete[] elevs;
delete[] ids;
ncfile.close();
}
else {
notifyInvalidSampleFile();
}
}
示例4: main
int main(int argc, char *argv[])
{
NcFile at(atpath, NcFile::ReadOnly);
if(!at.is_valid() || at.num_dims() != 3 || at.num_vars() != 4) {
fprintf(stderr, "failed reading file: %s\n", atpath);
return 1;
}
NcVar* data = at.get_var("rhum");
if(!data->is_valid() || data->num_dims() != 3) {
fprintf(stderr, "rhum has incorrect dimensions");
return 1;
}
NcDim* time = data->get_dim(0);
int timecnt = time->size();
float *rhumd = new float[timecnt*LATS*LONS];
data->get(rhumd, timecnt, LATS, LONS);
float rhumdmon[12][LATS][LONS];
for(int i = 0; i<LATS; i++)
for(int j = 0; j<LONS; j++) {
float rhumdmoncnt[12];
for(int k = 0; k<12; k++) {
rhumdmon[k][i][j] = 0;
rhumdmoncnt[k] = 0;
}
for(int k = 0; k<timecnt; k++) {
double v = rhumd[(k*LATS+i)*LONS+j]*.1 + 3276.5;
if(v >= 0 && v <= 100) {
rhumdmon[k%12][i][j] += v;
rhumdmoncnt[k%12]++;
}
}
for(int k = 0; k<12; k++)
rhumdmon[k][i][j] /= rhumdmoncnt[k];
}
delete [] rhumd;
/* use a single byte instead of 2 to save memory,
resolution of 1/5th of a mm/day resolution */
uint8_t rhumbyte[12][LATS][LONS];
for(int i = 0; i<12; i++)
for(int j = 0; j<LATS; j++)
for(int k = 0; k<LONS; k++)
if(isnan(rhumdmon[i][j][k]) || fabs(rhumdmon[i][j][k]) > 100)
rhumbyte[i][j][k] = 255;
else
rhumbyte[i][j][k] = rhumdmon[i][j][k]*2.0;
fwrite(rhumbyte, sizeof rhumbyte, 1, stdout);
return 0;
}
示例5: get_dim
void DumpableNcFile::dumpdims( void )
{
for (int n=0; n < num_dims(); n++) {
NcDim* dim = get_dim(n);
cout << "\t" << dim->name() << " = " ;
if (dim->is_unlimited())
cout << "UNLIMITED" << " ;\t " << "// " << dim->size() <<
" currently\n";
else
cout << dim->size() << " ;\n";
}
}
示例6: load_nc_dim
static int load_nc_dim(const NcFile& ncf, const string& name, bool required = true)
{
NcDim* d = 0;
try
{
d = ncf.get_dim(name.c_str());
}
catch(char* str)
{
check(!required, string(str) + "\ndimension " + name + " not found in netcdf file");
}
int size = d ? d->size() : 0;
return size;
}
示例7: LoadMetaDataFile
void LoadMetaDataFile(
const std::string & strInputMeta,
DataMatrix3D<int> & dataGLLNodes,
DataMatrix3D<double> & dataGLLJacobian
) {
NcFile ncMeta(strInputMeta.c_str(), NcFile::ReadOnly);
NcDim * dimNp = ncMeta.get_dim("np");
if (dimNp == NULL) {
_EXCEPTIONT("Dimension \"np\" missing from metadata file");
}
NcDim * dimNelem = ncMeta.get_dim("nelem");
if (dimNelem == NULL) {
_EXCEPTIONT("Dimension \"nelem\" missing from metadata file");
}
NcVar * varGLLNodes = ncMeta.get_var("GLLnodes");
if (dimNelem == NULL) {
_EXCEPTIONT("Variable \"GLLnodes\" missing from metadata file");
}
NcVar * varGLLJacobian = ncMeta.get_var("J");
if (dimNelem == NULL) {
_EXCEPTIONT("Variable \"J\" missing from metadata file");
}
int nP = dimNp->size();
int nElem = dimNelem->size();
DataMatrix3D<int> dataGLLNodes_tmp;
DataMatrix3D<double> dataGLLJacobian_tmp;
dataGLLNodes.Initialize(nP, nP, nElem);
dataGLLJacobian.Initialize(nP, nP, nElem);
dataGLLNodes_tmp.Initialize(nP, nP, nElem);
dataGLLJacobian_tmp.Initialize(nP, nP, nElem);
varGLLNodes->get(&(dataGLLNodes_tmp[0][0][0]), nP, nP, nElem);
varGLLJacobian->get(&(dataGLLJacobian_tmp[0][0][0]), nP, nP, nElem);
for (int i = 0; i < nP; i++) {
for (int j = 0; j < nP; j++) {
for (int k = 0; k < nElem; k++) {
dataGLLNodes[i][j][k] = dataGLLNodes_tmp[j][i][k];
dataGLLJacobian[i][j][k] = dataGLLJacobian_tmp[j][i][k];
}
}
}
}
示例8: err
void Regioner::createCohorList4Run(){
// read in a list of cohorts to run
//netcdf error
NcError err(NcError::silent_nonfatal);
//open file and check if valid
string filename = md.runchtfile;
NcFile runFile(filename.c_str(), NcFile::ReadOnly);
if(!runFile.is_valid()){
string msg = filename+" is not valid";
char* msgc = const_cast< char* > ( msg.c_str());
throw Exception(msgc, I_NCFILE_NOT_EXIST);
}
NcDim* chtD = runFile.get_dim("CHTID");
if(!chtD->is_valid()){
string msg="CHT Dimension is not valid in createCohortList4Run";
char* msgc = const_cast<char*> (msg.c_str());
throw Exception(msgc, I_NCDIM_NOT_EXIST);
}
NcVar* chtV = runFile.get_var("CHTID");
if(chtV==NULL){
string msg="Cannot get CHTID in createCohortList4Run ";
char* msgc = const_cast<char*> (msg.c_str());
throw Exception(msgc, I_NCVAR_NOT_EXIST);
}
int numcht = chtD->size();
int chtid = -1;
int chtid0 = -1;
int chtidx = -1;
for (int i=0; i<numcht; i++){
chtV->set_cur(i);
chtV->get(&chtid, 1);
runchtlist.push_back(chtid);
if (i==0) chtid0=chtid;
if (i==numcht-1) chtidx=chtid;
}
cout <<md.casename << ": " <<numcht <<" cohorts to be run @" <<md.runstages<< "\n";
cout <<" from: " <<chtid0<<" to: " <<chtidx <<"\n";
};
示例9: getLocationFilename
void InputRdaNetcdf::getLocationsCore(std::vector<Location>& iLocations) const {
std::string filename = getLocationFilename();
NcFile ncfile(filename.c_str());
assert(ncfile.is_valid());
NcVar* ncLats = ncfile.get_var("latitude");
NcVar* ncLons = ncfile.get_var("longitude");
NcVar* ncElevs = ncfile.get_var("altitude");
NcVar* ncNames = ncfile.get_var("station_id");
NcDim* ncNamesDim = ncfile.get_dim("id_len");
int namesLength = ncNamesDim->size();
NcDim* ncLocationDim = ncfile.get_dim("station");
int numLocations = ncLocationDim->size();
float* lats = new float[numLocations];
float* lons = new float[numLocations];
float* elevs = new float[numLocations];
char* names = new char[numLocations*namesLength];
long count[2] = {numLocations, namesLength};
ncLats->get(lats, count);
ncLons->get(lons, count);
ncElevs->get(elevs, count);
ncNames->get(names, count);
iLocations.resize(numLocations);
for(int i = 0; i < numLocations; i++) {
int id = i;
float lat = lats[i];
float lon = lons[i];
float elev = elevs[i];
Location loc(getName(), id, lat, lon);
loc.setElev(elev);
iLocations[i] = loc;
int nameIndex = i*namesLength;
std::string name = std::string(&names[nameIndex], namesLength);
mLocationNames[name] = i;
}
delete[] lats;
delete[] lons;
delete[] elevs;
delete[] names;
ncfile.close();
}
示例10: err
void SiteinInputer::initSiteinFile(string & dirfile){
siteinfname = dirfile;
NcError err(NcError::silent_nonfatal);
NcFile siteFile(siteinfname.c_str(), NcFile::ReadOnly);
if(!siteFile.is_valid()){
string msg = siteinfname+" is not valid";
char* msgc = const_cast< char* > ( msg.c_str());
throw Exception( msgc, I_NCFILE_NOT_EXIST);
}
NcDim* siteD = siteFile.get_dim("CHTID");
if(!siteD->is_valid()){
throw Exception("SITED Dimension is not Valid in siteinFile", I_NCDIM_NOT_EXIST);
}
}
示例11: NcFile
CCatchmentSetupParams::CCatchmentSetupParams(const std::string & szFilenameForCatchment)
{
if(!boost::filesystem::exists(szFilenameForCatchment))
throw "szFilenameForCatchment doesn't exist";
pCatchmentDescriptionFile = new NcFile(szFilenameForCatchment.c_str());
if (!pCatchmentDescriptionFile->is_valid())
{
throw "Couldn't open file!";
}
NcVar * pReachIDs = pCatchmentDescriptionFile->get_var("rchid");
NcDim* numReaches = pReachIDs->get_dim(0);
const int nNumReaches = numReaches->size();
cout << "numReaches=" << nNumReaches << endl;
//std::vector<int> aReachIDs(nNumReaches, -1);
int anReaches[nNumReaches];
pReachIDs->get(anReaches, nNumReaches); //This is the mapping from rchid to nrch (=idx)
for(int nrch=0;nrch<nNumReaches;nrch++)
{
std::cout << "Reach: " << anReaches[nrch] << std::endl;
aSubcatchments[nrch] = new CSubcatchmentParams(nrch, anReaches[nrch], this);
}
int anDownstreamReaches[nNumReaches];
pCatchmentDescriptionFile->get_var("dsrch_nrch")->get(anDownstreamReaches, nNumReaches);
for(int nrch=0;nrch<nNumReaches;nrch++)
{
if(anDownstreamReaches[nrch]>=0)
{
std::cout << "Catchment " << nrch << " Downstream reach: " << anDownstreamReaches[nrch] << std::endl;
//aSubcatchments[nrch] = new CSubcatchmentParams(nrch, this);
aSubcatchments[nrch]->setDownstreamCatchment(aSubcatchments[anDownstreamReaches[nrch]]);
}
}
std::cout << std::endl;
}
示例12: getSampleFilename
void InputNetcdf::getOffsetsCore(std::vector<float>& iOffsets) const {
iOffsets.clear();
std::string filename = getSampleFilename();
NcFile ncfile(filename.c_str());
if(ncfile.is_valid()) {
NcDim* ncOffsetDim = ncfile.get_dim("Offset");
int numOffsets = ncOffsetDim->size();
NcVar* ncOffsets = ncfile.get_var("Offset");
float* offsets = new float[numOffsets];
//float* elevs = new float[numOffsets];
long count[1] = {numOffsets};
ncOffsets->get(offsets, count);
for(int i = 0; i < numOffsets; i++) {
iOffsets.push_back(offsets[i]);
}
delete[] offsets;
ncfile.close();
}
else {
notifyInvalidSampleFile();
}
}
示例13: FileNetcdf
FileArome::FileArome(std::string iFilename, bool iReadOnly) : FileNetcdf(iFilename, iReadOnly) {
// Set dimensions
NcDim* dTime = getDim("time");
NcDim* dLon = getDim("x");
NcDim* dLat = getDim("y");
mNTime = dTime->size();
mNLat = dLat->size();
mNLon = dLon->size();
mNEns = 1;
mLats = getLatLonVariable("latitude");
mLons = getLatLonVariable("longitude");
if(hasVariableCore("surface_geopotential")) {
FieldPtr elevField = getFieldCore("surface_geopotential", 0);
mElevs.resize(getNumLat());
for(int i = 0; i < getNumLat(); i++) {
mElevs[i].resize(getNumLon());
for(int j = 0; j < getNumLon(); j++) {
float value = (*elevField)(i,j,0) / 9.81;
mElevs[i][j] = value;
}
}
std::cout << "Deriving altitude from geopotential height in " << getFilename() << std::endl;
}
else {
mElevs = getLatLonVariable("altitude");
}
if(hasVar("time")) {
NcVar* vTime = getVar("time");
double* times = new double[mNTime];
vTime->get(times , mNTime);
setTimes(std::vector<double>(times, times+mNTime));
delete[] times;
}
else {
std::vector<double> times;
times.resize(getNumTime(), Util::MV);
setTimes(times);
}
if(hasVar("forecast_reference_time")) {
NcVar* vReferenceTime = getVar("forecast_reference_time");
double referenceTime = getReferenceTime();
vReferenceTime->get(&referenceTime, 1);
setReferenceTime(referenceTime);
}
Util::status( "File '" + iFilename + " 'has dimensions " + getDimenionString());
}
示例14: main
int main()
{
try
{
cout<<"Opening file \"firstFile.cdf\" with NcFile::replace"<<endl;
NcFile ncFile("firstFile.cdf",NcFile::replace);
cout<<left<<setw(55)<<"Testing addGroup(\"groupName\")";
NcGroup groupA(ncFile.addGroup("groupA"));
NcGroup groupA0(ncFile.addGroup("groupA0"));
NcGroup groupB(groupA.addGroup("groupB"));
NcGroup groupC(groupA.addGroup("groupC"));
cout <<" ----------- passed\n";
cout <<left<<setw(55)<<"Testing addDim(\"dimensionName\")";
NcDim dim1 = ncFile.addDim("dim1",11);
NcDim dim2 = ncFile.addDim("dim2");
NcDim dim3 = ncFile.addDim("dim3",13);
NcDim dim4 = groupB.addDim("dim4",14);
NcDim dim5 = groupB.addDim("dim5",15);
NcDim dim6 = groupB.addDim("dim6",16);
NcDim dim7 = groupB.addDim("dim7",17);
cout <<" ----------- passed\n";
cout <<left<<setw(55)<<"Testing NcDim::isUnlimited()";
if( dim1.isUnlimited()) throw NcException("NcException","Error in test 1.1",__FILE__,__LINE__);
if( !dim2.isUnlimited()) throw NcException("NcException","Error in test 1.2",__FILE__,__LINE__);
if( dim3.isUnlimited()) throw NcException("NcException","Error in test 1.3",__FILE__,__LINE__);
if( dim4.isUnlimited()) throw NcException("NcException","Error in test 1.4",__FILE__,__LINE__);
if( dim5.isUnlimited()) throw NcException("NcException","Error in test 1.5",__FILE__,__LINE__);
if( dim6.isUnlimited()) throw NcException("NcException","Error in test 1.6",__FILE__,__LINE__);
if( dim7.isUnlimited()) throw NcException("NcException","Error in test 1.7",__FILE__,__LINE__);
cout <<" ----------- passed\n";
cout <<left<<setw(55)<<"Testing NcDim::isNull()";
if( dim1.isNull()) throw NcException("NcException","Error in test 2.1",__FILE__,__LINE__);
NcDim tmpDim;
if( !tmpDim.isNull()) throw NcException("NcException","Error in test 2.2",__FILE__,__LINE__);
cout <<" ----------- passed\n";
cout <<left<<setw(55)<<"Testing NcDim::getSize()";
if( dim1.getSize() != 11) throw NcException("NcException","Error in test 3.1",__FILE__,__LINE__);
if( dim2.getSize() != 0 ) throw NcException("NcException","Error in test 3.2",__FILE__,__LINE__);
if( dim3.getSize() != 13) throw NcException("NcException","Error in test 3.3",__FILE__,__LINE__);
if( dim4.getSize() != 14) throw NcException("NcException","Error in test 3.4",__FILE__,__LINE__);
if( dim5.getSize() != 15) throw NcException("NcException","Error in test 3.5",__FILE__,__LINE__);
if( dim6.getSize() != 16) throw NcException("NcException","Error in test 3.6",__FILE__,__LINE__);
if( dim7.getSize() != 17) throw NcException("NcException","Error in test 3.7",__FILE__,__LINE__);
cout <<" ----------- passed\n";
cout <<left<<setw(55)<<"Testing NcDim::getParentGroup()";
if( !(dim1.getParentGroup() == ncFile)) throw NcException("NcException","Error in test 4.1",__FILE__,__LINE__);
if( !(dim2.getParentGroup() == ncFile)) throw NcException("NcException","Error in test 4.2",__FILE__,__LINE__);
if( !(dim3.getParentGroup() == ncFile)) throw NcException("NcException","Error in test 4.3",__FILE__,__LINE__);
if( !(dim4.getParentGroup() == groupB)) throw NcException("NcException","Error in test 4.4",__FILE__,__LINE__);
if( !(dim5.getParentGroup() == groupB)) throw NcException("NcException","Error in test 4.5",__FILE__,__LINE__);
if( !(dim6.getParentGroup() == groupB)) throw NcException("NcException","Error in test 4.6",__FILE__,__LINE__);
if( !(dim7.getParentGroup() == groupB)) throw NcException("NcException","Error in test 4.7",__FILE__,__LINE__);
cout <<" ----------- passed\n";
cout <<left<<setw(55)<<"Testing NcDim::getName()";
if( dim1.getName() != "dim1") throw NcException("NcException","Error in test 5.1",__FILE__,__LINE__);
if( dim2.getName() != "dim2") throw NcException("NcException","Error in test 5.2",__FILE__,__LINE__);
if( dim3.getName() != "dim3") throw NcException("NcException","Error in test 5.3",__FILE__,__LINE__);
if( dim4.getName() != "dim4") throw NcException("NcException","Error in test 5.4",__FILE__,__LINE__);
if( dim5.getName() != "dim5") throw NcException("NcException","Error in test 5.5",__FILE__,__LINE__);
if( dim6.getName() != "dim6") throw NcException("NcException","Error in test 5.6",__FILE__,__LINE__);
if( dim7.getName() != "dim7") throw NcException("NcException","Error in test 5.7",__FILE__,__LINE__);
cout <<" ----------- passed\n";
cout <<left<<setw(55)<<"Testing NcGroup::getDimCount([netCDF::Location])";
if( ncFile.getDimCount() != 3) throw NcException("NcException","Error in test 6.1",__FILE__,__LINE__);
if( ncFile.getDimCount(NcGroup::Current) != 3) throw NcException("NcException","Error in test 6.2",__FILE__,__LINE__);
if( ncFile.getDimCount(NcGroup::All) != 7) throw NcException("NcException","Error in test 6.3",__FILE__,__LINE__);
if( ncFile.getDimCount(NcGroup::Parents) != 0) throw NcException("NcException","Error in test 6.4",__FILE__,__LINE__);
if( ncFile.getDimCount(NcGroup::Children) != 4) throw NcException("NcException","Error in test 6.5",__FILE__,__LINE__);
if( ncFile.getDimCount(NcGroup::ParentsAndCurrent) != 3) throw NcException("NcException","Error in test 6.6",__FILE__,__LINE__);
if( ncFile.getDimCount(NcGroup::ChildrenAndCurrent) != 7)throw NcException("NcException","Error in test 6.7",__FILE__,__LINE__);
if( groupA.getDimCount() != 0) throw NcException("NcException","Error in test 6.8",__FILE__,__LINE__);
if( groupA.getDimCount(NcGroup::Current) != 0) throw NcException("NcException","Error in test 6.9",__FILE__,__LINE__);
if( groupA.getDimCount(NcGroup::All) != 7) throw NcException("NcException","Error in test 6.10",__FILE__,__LINE__);
if( groupA.getDimCount(NcGroup::Parents) != 3) throw NcException("NcException","Error in test 6.11",__FILE__,__LINE__);
if( groupA.getDimCount(NcGroup::Children) != 4) throw NcException("NcException","Error in test 6.12",__FILE__,__LINE__);
if( groupA.getDimCount(NcGroup::ParentsAndCurrent) != 3) throw NcException("NcException","Error in test 6.13",__FILE__,__LINE__);
if( groupA.getDimCount(NcGroup::ChildrenAndCurrent) != 4)throw NcException("NcException","Error in test 6.14",__FILE__,__LINE__);
cout <<" ----------- passed\n";
cout <<left<<setw(55)<<"Testing NcGroup::getDims([netCDF::Location])";
{
multimap<string,NcDim> dimMap;
multimap<string,NcDim>::iterator iter;
//.........这里部分代码省略.........
示例15: error
ERMsg C20thReanalysisProject::GetGridInfo(const CString& filePath, int& sizeX, int& sizeY, int& nbBand, CGeoRectWP& rect, float& noData, double& cellSizeX, double& cellSizeY)
{
ERMsg msg;
// CString filePathIn;
//filePathIn.Format("%scccma_cgcm3_1-20c3m-run1-pr-1961-2000_monthly.nc", m_path);
NcError error( NcError::verbose_nonfatal );
NcFile file(filePath);
if( !file.is_valid() )
{
CString err;
err.FormatMessage(IDS_CMN_UNABLE_OPEN_READ, filePath);
msg.ajoute(err);
return msg;
}
int nbDim = file.num_dims();
int nbAtt = file.num_atts();
int nbVar = file.num_vars();
//NcDim* dim0 = file.get_dim(0);
//NcDim* dim1 = file.get_dim(1);
//NcDim* dim2 = file.get_dim(2);
//NcVar* pVarX = file.get_var("xc");
//NcVar* pVarY = file.get_var("yc");
NcDim* pDimX = file.get_dim("lon");
NcDim* pDimY = file.get_dim("lat");
NcDim* pDimTime = file.get_dim("time");
if( pDimX && pDimY && pDimTime)
{
sizeX = pDimX->size();
sizeY = pDimY->size();
nbBand = pDimTime->size();
//double offset = pVarElev->get_att("add_offset")->as_float(0);
//double scaleFactor = pVarElev->get_att("scale_factor")->as_float(0);
typedef vector<float> CDataArray;
CDataArray Y(sizeY);
CDataArray X(sizeX);
NcVar* pVarX = file.get_var("lon");
NcVar* pVarY = file.get_var("lat");
pVarX->get(&(X[0]), sizeX);
pVarY->get(&(Y[0]), sizeY);
CStatistic Xstat;
CStatistic Ystat;
Xstat+=X[0];Xstat+=X[sizeX-1];
Ystat+=Y[0];Ystat+=Y[sizeY-1];
cellSizeX = (Xstat[HIGHEST]-Xstat[LOWEST])/(sizeX-1);
cellSizeY = (Ystat[HIGHEST]-Ystat[LOWEST])/(sizeY-1);
noData=-999;
rect.SetPrj( CProjection( CProjection::GEO ) );
rect.m_xMin = Xstat[LOWEST]-cellSizeX/2-180;
rect.m_yMin = Ystat[LOWEST]-cellSizeY/2;
rect.m_xMax = rect.m_xMin+cellSizeX*sizeX;
rect.m_yMax = rect.m_yMin+cellSizeY*sizeY;
}
else
{
msg.ajoute("Unable to find one of dimention \"lat, lon or time\"");
}
file.close();
return msg;
}