当前位置: 首页>>代码示例>>C++>>正文


C++ NcVar::get方法代码示例

本文整理汇总了C++中NcVar::get方法的典型用法代码示例。如果您正苦于以下问题:C++ NcVar::get方法的具体用法?C++ NcVar::get怎么用?C++ NcVar::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NcVar的用法示例。


在下文中一共展示了NcVar::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getDimEdges

void NetCdfConfigureDialog::getDimEdges(int dimId, unsigned &size, double &firstValue, double &lastValue)
{
    if ((_currentFile->get_var(_currentVar->get_dim(dimId)->name())) != NULL)
    {
        NcVar *tmpVarOfDim = _currentFile->get_var(_currentVar->get_dim(dimId)->name());
        if ((tmpVarOfDim->num_dims()) == 1)
        {
            int sizeOfDim = tmpVarOfDim->get_dim(0)->size();
            size = sizeOfDim;
            double arrayOfDimStart[1] = {0};
            size_t edgeOfArray[1] = {1};
            long edgeOrigin[1] = {0};
            tmpVarOfDim->set_cur(edgeOrigin);
            tmpVarOfDim->get(arrayOfDimStart,edgeOfArray);
            firstValue = arrayOfDimStart[0];
            double arrayOfDimEnd[1] = {0};
            edgeOrigin[0] = sizeOfDim - 1;
            tmpVarOfDim->set_cur(edgeOrigin);
            tmpVarOfDim->get(arrayOfDimEnd,edgeOfArray);
            lastValue = arrayOfDimEnd[0];
        }
    } else {
        size = 0;
        firstValue = 0;
        lastValue = 0;
    }
}
开发者ID:WenjieXu,项目名称:ogs,代码行数:27,代码来源:NetCdfConfigureDialog.cpp

示例2: getLocationsCore

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();
   }
}
开发者ID:WFRT,项目名称:Comps,代码行数:54,代码来源:Netcdf.cpp

示例3: 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];
			}
		}
	}
}
开发者ID:bssrdf,项目名称:tempestremap,代码行数:50,代码来源:GenerateOfflineMap.cpp

示例4: 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());
}
开发者ID:WFRT,项目名称:gridpp,代码行数:50,代码来源:Arome.cpp

示例5: counts

template<class T> static bool load_nc_array(const NcFile& ncf, const string& name, vector<T>& dest, bool required = true, int offset = 0, int count = -1)
{
	NcVar *v = load_nc_variable(ncf, name.c_str(), required);
	if (v)
	{
		vector<long> offsets = list_of(offset).repeat(v->num_dims()-1, 0);
		v->set_cur(&offsets.front());
		vector<long> counts (v->num_dims());
		long* shape = v->edges();
		transform(shape, shape + v->num_dims(), offsets.begin(), counts.begin(), minus<long>());
		delete shape;
		if (count > 0)
		{
			counts[0] = count;
		}
		dest.resize(product(counts));
		bool success = v->get(&dest.front(), &counts.front());
		if (!success)
		{
			dest.resize(0);
			check(!required, string("NetcdfDataset::load_nc_array<") + typeid(T).name() + "> " + name + '\n' + "failed with offset " + str(offsets) + ", counts " + str(counts));
		}
		return success;
	}
	return false;
}
开发者ID:tpajenka,项目名称:RNNLIB,代码行数:26,代码来源:NetcdfDataset.hpp

示例6: getFieldCore

FieldPtr FileArome::getFieldCore(std::string iVariable, int iTime) const {
   // Not cached, retrieve data
   NcVar* var = getVar(iVariable);
   int nLat  = mNLat;
   int nLon  = mNLon;

   int numDims = var->num_dims();

   long* count;
   long totalCount = nLat*nLon;
   if(numDims == 4) {
      // Variable has a surface dimension
      count = new long[4];
      count[0] = 1;
      count[1] = 1;
      count[2] = nLat;
      count[3] = nLon;
      var->set_cur(iTime, 0, 0, 0);
   }
   else if(numDims == 3) {
      count = new long[3];
      count[0] = 1;
      count[1] = nLat;
      count[2] = nLon;
      var->set_cur(iTime, 0, 0);
   }
   else {
      std::stringstream ss;
      ss << "Cannot read variable '" << iVariable << "' from '" << getFilename() << "'";
      Util::error(ss.str());
   }
   float* values = new float[nLat*nLon];
   var->get(values, count);
   float MV = getMissingValue(var);

   float offset = getOffset(var);
   float scale = getScale(var);
   int index = 0;
   FieldPtr field = getEmptyField();
   for(int lat = 0; lat < nLat; lat++) {
      for(int lon = 0; lon < nLon; lon++) {
         float value = values[index];
         assert(index < totalCount);
         if(value == MV) {
            // Field has missing value indicator and the value is missing
            // Save values using our own internal missing value indicator
            value = Util::MV;
         }
         else {
            value = scale*values[index] + offset;
         }
         (*field)(lat,lon,0) = value;
         index++;
      }
   }
   delete[] values;
   delete[] count;
   return field;
}
开发者ID:WFRT,项目名称:gridpp,代码行数:59,代码来源:Arome.cpp

示例7: readScalar

int NetcdfSource::readScalar(double *v, const QString& field)
{
  // TODO error handling
  QByteArray bytes = field.toLatin1();
  NcVar *var = _ncfile->get_var(bytes.constData());  // var is owned by _ncfile
  var->get(v);
  return 1;
}
开发者ID:,项目名称:,代码行数:8,代码来源:

示例8: getLocationsCore

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();
}
开发者ID:WFRT,项目名称:Comps,代码行数:45,代码来源:RdaNetcdf.cpp

示例9: points

std::vector<T> read_vector(NcFile &nc, std::string const &var_name)
{
	// Read points vector
	NcVar *vpoints = nc.get_var(var_name.c_str());
	long npoints = vpoints->get_dim(0)->size();
	std::vector<T> points(npoints);
	vpoints->get(&points[0], npoints);
	return points;
}
开发者ID:seifer08ms,项目名称:icebin,代码行数:9,代码来源:ncutil.hpp

示例10: file

ERMsg C20thReanalysisProject::ReadData( CString filePath, CString varName, CData3Array& data)
{
	//typedef boost::multi_array<int, 2> array_type;


	ERMsg msg;
	
	NcError::set_err( NcError::silent_nonfatal );

  
	//CString filePath = m_path + "cccma_cgcm3_1-20c3m-run1-pr-1961-2000_monthly.nc";//GetFilePath(v, year, m);
	NcFile file(filePath);	//current year file

	if( !file.is_valid() )
	{
		CString err;
		err.FormatMessage(IDS_CMN_UNABLE_OPEN_READ, filePath);
		msg.ajoute(err);
		return msg;
	}

	NcVar* pVarData = file.get_var((LPCTSTR)varName);//is the varaible always at ffirst???
	
	//CString varName = pVarData->name();
	
	size_t sizeTime = pVarData->get_dim(0)->size();
	size_t sizeY = pVarData->get_dim(1)->size();
	size_t sizeX = pVarData->get_dim(2)->size();
	float offset = pVarData->get_att("add_offset")->as_float(0);
	float scaleFactor = pVarData->get_att("scale_factor")->as_float(0);
	
	boost::multi_array<short, 3> tmp(boost::extents[sizeTime][sizeY][sizeX]);

	ENSURE( pVarData->num_dims() == 3);
	
	if( pVarData->get(&(tmp[0][0][0]), sizeTime, sizeY, sizeX) )
	{
		//tmp.extens()
		//data.resize(sizeTime);
		//data.resize(boost::extents[sizeTime][sizeY][sizeX]);
		//apply offset and scale factor
		for(size_t i=0; i<tmp.size(); i++)
			for(size_t j=0; j<tmp[i].size(); j++)
				for(size_t k=0; k<tmp[i][j].size(); k++)
					data[i][j][k] = tmp[i][j][k]*scaleFactor+offset;

		file.close();
	}
	else
	{
		msg.ajoute( "Unable to get NetCDFData");
	}

	return msg;
}
开发者ID:RNCan,项目名称:WeatherBasedSimulationFramework,代码行数:55,代码来源:20thReanalysisProject.cpp

示例11: 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;
}
开发者ID:AlexandreRio,项目名称:climatology_pi,代码行数:53,代码来源:genrelativehumiditydata.cpp

示例12: getRecID

//YUAN: recid - the order (from ZERO) in the .nc file, chtid - the cohort id
int SiteinInputer::getRecID(const int &siteid){
	NcError err(NcError::silent_nonfatal);

	NcFile siteFile(siteinfname.c_str(), NcFile::ReadOnly);
 	NcVar* siteidV = siteFile.get_var("CHTID");

 	int id = -1;
	for (int i=0; i<(int)siteidV->num_vals(); i++){
		siteidV->set_cur(i);
		siteidV->get(&id, 1);
		if(id==siteid) return i;
	}
	return -1;
}
开发者ID:fmyuan,项目名称:ptlndDOSTEM,代码行数:15,代码来源:SiteinInputer.cpp

示例13: main

int main(void)
{
   try
   {
   // This is the array we will read.
   int dataIn[NX][NY]; 

   // Open the file. The ReadOnly parameter tells netCDF we want
   // read-only access to the file.
   NcFile dataFile("simple_xy.nc", NcFile::ReadOnly);

   // You should always check whether a netCDF file open or creation
   // constructor succeeded.
//    if (!dataFile.is_valid())
//    {
//       cout << "Couldn't open file!\n";
//       return NC_ERR;
//    }
  
   // For other method calls, the default behavior of the C++ API is
   // to exit with a message if there is an error.  If that behavior
   // is OK, there is no need to check return values in simple cases
   // like the following.
      
   // Retrieve the variable named "data"
   NcVar *data = dataFile.getVar("data");

   // Read all the values from the "data" variable into memory. 
   data->get(&dataIn[0][0], NX, NY);

   // Check the values. 
   for (int i = 0; i < NX; i++)
      for (int j = 0; j < NY; j++)
	 if (dataIn[i][j] != i * NY + j)
	    return NC_ERR;
    
   // The netCDF file is automatically closed by the NcFile destructor
   cout << "*** SUCCESS reading example file simple_xy.nc!" << endl;

   return 0;
   }catch(NcException e)
   {
      e.what();
      cout<<"FAILURE*************************************"<<endl;
      return 1;
   }
}
开发者ID:mmase,项目名称:wgrib2,代码行数:47,代码来源:simple_xy_rd.cpp

示例14: 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";
   
};
开发者ID:hgenet,项目名称:dostem,代码行数:47,代码来源:Regioner.cpp

示例15: readMatrix

int NetcdfSource::readMatrix(double *v, const QString& field) 
{
  /* For a variable from the netCDF file */
  QByteArray bytes = field.toLatin1();
  NcVar *var = _ncfile->get_var(bytes.constData());  // var is owned by _ncfile
  if (!var) {
    KST_DBG qDebug() << "Queried field " << field << " which can't be read" << endl;
    return -1;
  }

  int xSize = var->get_dim(0)->size();
  int ySize = var->get_dim(1)->size();

  var->get(v, xSize, ySize);

 
  return  xSize * ySize;
}
开发者ID:,项目名称:,代码行数:18,代码来源:


注:本文中的NcVar::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。