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


C++ NcDim::size方法代码示例

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


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

示例1: read_netcdf

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);
	}
}
开发者ID:alessandronascimento,项目名称:amberenergy,代码行数:33,代码来源:COORD.cpp

示例2: dumpdims

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";
    }
}
开发者ID:akiyoshi,项目名称:wrf-fire,代码行数:13,代码来源:nctst.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: 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

示例6: 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

示例7: 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

示例8: 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;
}
开发者ID:tpajenka,项目名称:RNNLIB,代码行数:14,代码来源:NetcdfDataset.hpp

示例9: 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

示例10: 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;
	
}
开发者ID:JustineSurGithub,项目名称:tom-cv,代码行数:43,代码来源:catchment_setup_params.cpp

示例11: getOffsetsCore

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

示例12: getMembersCore

void InputNetcdf::getMembersCore(std::vector<Member>& iMembers) const {
   iMembers.clear();
   std::string filename = getSampleFilename();
   NcFile ncfile(filename.c_str());
   if(ncfile.is_valid()) {
      NcDim* ncMemberDim = ncfile.get_dim("Member");
      int numMembers   = ncMemberDim->size();
      NcVar* ncRes = ncfile.get_var("Resolution");
      float* res = new float[numMembers];

      long count[1] = {numMembers};
      ncRes->get(res, count);
      for(int i = 0; i < numMembers; i++) {
         Member member(getName(), res[i], "", i);
         iMembers.push_back(member);
      }
      delete[] res;
      ncfile.close();
   }
   else {
      notifyInvalidSampleFile();
   }
}
开发者ID:WFRT,项目名称:Comps,代码行数:23,代码来源:Netcdf.cpp

示例13: 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;
}
开发者ID:RNCan,项目名称:WeatherBasedSimulationFramework,代码行数:80,代码来源:20thReanalysisProject.cpp

示例14: loadNetCdfFile

bool EpidemicDataSet::loadNetCdfFile(const char * filename)
{
#if USE_NETCDF // TODO: should handle this differently
    // change netcdf library error behavior
    NcError err(NcError::verbose_nonfatal);

    // open the netcdf file
    NcFile ncFile(filename, NcFile::ReadOnly);

    if(!ncFile.is_valid())
    {
        put_flog(LOG_FATAL, "invalid file %s", filename);
        return false;
    }

    // get dimensions
    NcDim * timeDim = ncFile.get_dim("time");
    NcDim * nodesDim = ncFile.get_dim("nodes");
    NcDim * stratificationsDim = ncFile.get_dim("stratifications");

    if(timeDim == NULL || nodesDim == NULL || stratificationsDim == NULL)
    {
        put_flog(LOG_FATAL, "could not find a required dimension");
        return false;
    }

    numTimes_ = timeDim->size();

    // make sure we have the expected number of nodes
    if(nodesDim->size() != numNodes_)
    {
        put_flog(LOG_FATAL, "got %i nodes, expected %i", nodesDim->size(), numNodes_);
        return false;
    }

    put_flog(LOG_DEBUG, "file contains %i timesteps, %i nodes", numTimes_, numNodes_);

    // make sure number of stratifications matches our expectation...
    int numExpectedStratifications = 1;

    for(unsigned int i=0; i<NUM_STRATIFICATION_DIMENSIONS; i++)
    {
        numExpectedStratifications *= stratifications_[i].size();
    }

    if(stratificationsDim->size() != numExpectedStratifications)
    {
        put_flog(LOG_FATAL, "got %i stratifications, expected %i", stratificationsDim->size(), numExpectedStratifications);
        return false;
    }

    // get all float variables with dimensions (time, nodes, stratifications)
    for(int i=0; i<ncFile.num_vars(); i++)
    {
        NcVar * ncVar = ncFile.get_var(i);

        if(ncVar->num_dims() == 3 && ncVar->type() == ncFloat && strcmp(ncVar->get_dim(0)->name(), "time") == 0 && strcmp(ncVar->get_dim(1)->name(), "nodes") == 0 && strcmp(ncVar->get_dim(2)->name(), "stratifications") == 0)
        {
            put_flog(LOG_INFO, "found variable: %s", ncVar->name());

            // full shape
            blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> shape;
            shape(0) = numTimes_;
            shape(1) = numNodes_;

            for(int j=0; j<NUM_STRATIFICATION_DIMENSIONS; j++)
            {
                shape(2 + j) = stratifications_[j].size();
            }

            blitz::Array<float, 2+NUM_STRATIFICATION_DIMENSIONS> var((float *)ncVar->values()->base(), shape, blitz::duplicateData);

            variables_[std::string(ncVar->name())].reference(var);
        }
    }
#endif
    return true;
}
开发者ID:gregjohnson,项目名称:PanFluExercise,代码行数:78,代码来源:EpidemicDataSet.cpp

示例15: main

int main(int argc, char ** argv){
  NcError error(NcError::verbose_nonfatal);

  try{
    std::string inFile;
    std::string outFile;
    std::string varName;
    std::string inList;
//    bool calcStdDev;

    BeginCommandLine()
      CommandLineString(inFile, "in", "");
      CommandLineString(inList, "inlist","");
      CommandLineString(varName, "var", "");
      CommandLineString(outFile, "out", "");
  //    CommandLineBool(calcStdDev, "std");
      ParseCommandLine(argc, argv);
    EndCommandLine(argv)
    AnnounceBanner();
  

    if ((inFile != "") && (inList != "")){
      _EXCEPTIONT("Can only open one file (--in) or list (--inlist).");
    }

    //file list vector
    std::vector<std::string> vecFiles;
    if (inFile != ""){
      vecFiles.push_back(inFile);
    }
    if (inList != ""){
      GetInputFileList(inList,vecFiles);
    }

    //open up first file
    NcFile readin(vecFiles[0].c_str());
    if (!readin.is_valid()){
      _EXCEPTION1("Unable to open file %s for reading",\
        vecFiles[0].c_str());
    }
    int tLen,latLen,lonLen;

    NcDim * time = readin.get_dim("time");
    tLen = time->size();
    NcVar * timeVar = readin.get_var("time");

    NcDim * lat = readin.get_dim("lat");
    latLen = lat->size();
    NcVar * latVar = readin.get_var("lat");

    NcDim * lon = readin.get_dim("lon");
    lonLen = lon->size();
    NcVar * lonVar = readin.get_var("lon");

    //read input variable
    NcVar * inVar = readin.get_var(varName.c_str());
    //Create output matrix
    DataMatrix<double> outMat(latLen,lonLen);
    densCalc(inVar,outMat);
    //Option for calculating the yearly standard deviation 
 /*   if (calcStdDev){
      for (int a=0; a<latLen; a++){
        for (int b=0; b<lonLen; b++){
          storeMat[0][a][b] = outMat[a][b];
        }
      }
    }
*/
    //If multiple files, add these values to the output
    if (vecFiles.size()>1){
      DataMatrix<double> addMat(latLen,lonLen);
      std::cout<<"There are "<<vecFiles.size()<<" files."<<std::endl;
      for (int v=1; v<vecFiles.size(); v++){
        NcFile addread(vecFiles[v].c_str());
        NcVar * inVar = addread.get_var(varName.c_str());
        densCalc(inVar,addMat);
        for (int a=0; a<latLen; a++){
          for (int b=0; b<lonLen; b++){
            outMat[a][b]+=addMat[a][b];
          }
        }
/*        if (calcStdDev){
          for (int a=0; a<latLen; a++){
            for (int b=0; b<lonLen; b++){
              storeMat[v][a][b] = addMat[a][b];
            }
          }
        }*/
        addread.close(); 
      }
      //Divide output by number of files
      double div = 1./((double) vecFiles.size());
      for (int a=0; a<latLen; a++){
        for (int b=0; b<lonLen; b++){
          outMat[a][b]*=div;
        }
      }
    }
 
    NcFile readout(outFile.c_str(),NcFile::Replace, NULL,0,NcFile::Offset64Bits);
//.........这里部分代码省略.........
开发者ID:ClimateGlobalChange,项目名称:tempestextremes,代码行数:101,代码来源:DensityCalculations.cpp


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