Esempio n. 1
0
void Programme::addVariable(Variable& var) {
	if(hasVar(variables, var.getNom())) {
		throw "La variable \""+var.getNom()+"\" a déjà été instanciée dans le programme \""+nom+"\".";
	}
	else if(hasVar(arguments, var.getNom())) {
		throw "La variable \""+var.getNom()+"\" a déjà été instanciée dans le programme \""+nom+"\" en tant qu'argument.";
	}
	else {
		variables.push_back(var);
	}
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
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());
}
Esempio n. 4
0
void Programme::addArgument(Variable& var) {
	if(hasVar(arguments, var.getNom())) {
		throw "L'argument \""+var.getNom()+"\" existe déjà dans le programme \""+nom+"\".";
	}
	else {
		arguments.push_back(var);
	}
}
void bi::ParticleMCMCNetCDFBuffer::map(const long P, const long T) {
  std::string name;
  int id, i;
  VarType type;
  Var* var;
  Dim* dim;

  /* dimensions */
  BI_ERROR_MSG(hasDim("nr"), "File must have nr dimension");
  nrDim = mapDim("nr", T);
  for (i = 0; i < m.getNumDims(); ++i) {
    dim = m.getDim(i);
    BI_ERROR_MSG(hasDim(dim->getName().c_str()), "File must have " <<
        dim->getName() << " dimension");
    nDims.push_back(mapDim(dim->getName().c_str(), dim->getSize()));
  }
  BI_ERROR_MSG(hasDim("np"), "File must have np dimension");
  npDim = mapDim("np", P);

  /* time variable */
  tVar = ncFile->get_var("time");
  BI_ERROR_MSG(tVar != NULL && tVar->is_valid(),
      "File does not contain variable time");
  BI_ERROR_MSG(tVar->num_dims() == 1, "Variable time has " << tVar->num_dims() <<
      " dimensions, should have 1");
  BI_ERROR_MSG(tVar->get_dim(0) == nrDim, "Dimension 0 of variable time should be nr");

  /* other variables */
  for (i = 0; i < NUM_VAR_TYPES; ++i) {
    type = static_cast<VarType>(i);
    if (type == D_VAR || type == R_VAR || type == P_VAR) {
      vars[type].resize(m.getNumVars(type), NULL);
      for (id = 0; id < m.getNumVars(type); ++id) {
        var = m.getVar(type, id);
        if (hasVar(var->getOutputName().c_str())) {
          vars[type][id] = mapVar(m.getVar(type, id));
        }
      }
    }
  }

  llVar = ncFile->get_var("loglikelihood");
  BI_ERROR_MSG(llVar != NULL && llVar->is_valid(),
      "File does not contain variable loglikelihood");
  BI_ERROR_MSG(llVar->num_dims() == 1, "Variable loglikelihood has " <<
      llVar->num_dims() << " dimensions, should have 1");
  BI_ERROR_MSG(llVar->get_dim(0) == npDim,
      "Dimension 0 of variable loglikelihood should be np");

  lpVar = ncFile->get_var("logprior");
  BI_ERROR_MSG(lpVar != NULL && lpVar->is_valid(),
      "File does not contain variable logprior");
  BI_ERROR_MSG(lpVar->num_dims() == 1, "Variable logprior has " <<
      lpVar->num_dims() << " dimensions, should have 1");
  BI_ERROR_MSG(lpVar->get_dim(0) == npDim,
      "Dimension 0 of variable logprior should be np");

}
Esempio n. 6
0
void FileNetcdf::writeReferenceTime() {
   if(!hasVar("forecast_reference_time")) {
      int id;
      int status = ncredef(mFile);
      handleNetcdfError(status, "could not put into define mode");
      status = nc_def_var(mFile, "forecast_reference_time", NC_DOUBLE, 0, NULL, &id);

      handleNetcdfError(status, "writing reference time");

      status = ncendef(mFile);
      handleNetcdfError(status, "could not put into data mode");
   }
   int vTime = getVar("forecast_reference_time");
   double referenceTime = getReferenceTime();
   if(!Util::isValid(referenceTime))
      referenceTime = NC_FILL_DOUBLE;
   int status = nc_put_var_double(mFile, vTime, &referenceTime);
   handleNetcdfError(status, "could not write reference time");
   setAttribute(vTime, "standard_name", "forecast_reference_time");
   setAttribute(vTime, "units", "seconds since 1970-01-01 00:00:00 +00:00");
}
Esempio n. 7
0
void FileNetcdf::writeTimes() {
   std::vector<double> times = getTimes();
   if(times.size() != getNumTime()) {
      std::stringstream ss;
      ss << "The times specified for NetCDF file '" << getFilename() << "' has " << times.size()
         << " elements, but the time dimension is " << getNumTime() << ". Putting missing values.";
      Util::warning(ss.str());
      times = std::vector<double>(getNumTime(), Util::MV);
   }

   // Convert missing
   for(int i = 0; i < times.size(); i++) {
      if(!Util::isValid(times[i]))
         times[i] = NC_FILL_FLOAT;
   }
   if(!hasVar("time")) {
      int dTime  = getDim("time");
      int id;
      int status = ncredef(mFile);
      handleNetcdfError(status, "could not put into define mode");
      status = nc_def_var(mFile, "time", NC_DOUBLE, 1, &dTime, &id);

      handleNetcdfError(status, "creating time variable");

      status = ncendef(mFile);
      handleNetcdfError(status, "could not put into data mode");
   }
   int vTime = getVar("time");
   double timesArr[getNumTime()];
   for(int t = 0; t < getNumTime(); t++) {
      timesArr[t] = times[t];
   }
   int status = nc_put_var_double(mFile, vTime, timesArr);
   handleNetcdfError(status, "could not write times");
   setAttribute(vTime, "long_name", "time");
   setAttribute(vTime, "standard_name", "time");
   setAttribute(vTime, "units", "seconds since 1970-01-01 00:00:00 +00:00");
}
Esempio n. 8
0
bool MemoryArray::insertVar(const RegisterId reg, const Type type)
{
	assertM(type != Type::pred, "Can't put a predicate to memory, reg id:" << reg);

	if(hasVar(reg)){
		assertM(type == _declared.find(reg)->second, "Tried to insert different" <<
				" types for same identifier, id:" << reg << ", new type:" <<
				ir::PTXOperand::toString(type) << ", old type: "
				<< ir::PTXOperand::toString(_declared.find(reg)->second));
		return false;
	}

	_minVarSize = std::min(_minVarSize, ir::PTXOperand::bytes(type));
	_maxVarSize = std::max(_maxVarSize, ir::PTXOperand::bytes(type));
	_isBin |= (type >= Type::b8);
	if(!_isBin){
		_hasFloat |= ir::PTXOperand::isFloat(type);
		_hasInt |= ir::PTXOperand::isInt(type);
		_hasUnsigned |= (!ir::PTXOperand::isSigned(type));
		_isBin = (_hasFloat & _hasInt);
	}
	return true;
}
Esempio n. 9
0
bool FileNetcdf::hasVar(std::string iVar) const {
   return hasVar(mFile, iVar);
}
Esempio n. 10
0
bool Programme::hasVariable(std::string var) const {
	return hasVar(variables, var) || hasArgument(var);
}
Esempio n. 11
0
bool Programme::hasArgument(std::string arg) const {
	return hasVar(arguments, arg);
}