Example #1
0
//----------------------------------------
double CUnit::ConvertToUnit(const double	fromValue, double defaultValue /* = CTools::m_defaultValueDOUBLE */)
{
  double out = defaultValue;

  if (isDefaultValue(fromValue))
  {
    if (!isDefaultValue(defaultValue))
    {
      out = ConvertToUnit(defaultValue);
    }
    return out;
    
  }
  
  CUnit	unit	= this->BaseUnit();
  unit.SetConversionTo(*this);
  out	= unit.Convert(fromValue);

  return out;
}
Example #2
0
// If WantedUnit is "", the returned value is in base (SI) unit.
void CExternalFilesAvisoGrid::GetValue
		(const string		&name,
		 double         	&value,
		 const string		&wantedUnit)
{
  uint32_t	start[3];
  uint32_t	count[3]	= {1, 1, 1};

  MustBeOpened();

  if (m_latIndex == AT_BEGINNING)
  {
    throw CFileException(CTools::Format("PROGRAM ERROR: Try to access file ('%s' field) while file is already rewinded (NextRecord must be called)",
				        name.c_str()),
		   GetName(),
		   BRATHL_LOGIC_ERROR);
  }

  if (CurrentMeasure() >= m_nbMeasures)
  {
    throw CFileException(CTools::Format("PROGRAM ERROR: Try to access file ('%s' field) while all measurements have been read",
				        name.c_str()),
			 GetName(),
			 BRATHL_LOGIC_ERROR);
  }

  start[0]	= m_lonIndex;
  start[1]	= m_latIndex;
  start[2]	= m_depthIndex;

// Find field def.
  CFieldNetCdf* var = GetFieldNetCdf(name);
      
  int32_t netCdfId = var->GetNetCdfId();


  if (netCdfId < 0)
  {
    int32_t	index;
    switch (netCdfId)
    {
      //---------------------------
      case INTERNAL_LAT_ID:
      //---------------------------
	      index	= m_latIndex;
    	  break;
      //---------------------------
      case INTERNAL_LON_ID:
      //---------------------------
        index	= m_lonIndex;
        break;
      //---------------------------
      case INTERNAL_DEPTH_ID:
      //---------------------------
	      index	= m_depthIndex;
	      break;
      //---------------------------
      default:
      //---------------------------
	      throw CException(CTools::Format("PROGRAM ERROR: Unknown pseudo netcdf id %d",
					      netCdfId),
  		       BRATHL_LOGIC_ERROR);
    }

    value	= var->GetValues()[index];
    
    CUnit	unit	= var->GetUnit();
    
    if ((wantedUnit != "") && (wantedUnit != CUnit::m_UNIT_SI))
    {
      unit.SetConversionTo(wantedUnit);
    }
    value	= unit.Convert(value);
  }
  else
  {
    int	nbDims	= m_file.GetVarNbDims(netCdfId);
    
    if (nbDims != 2) 
    {
      nbDims = 3;
    }

    m_file.ReadVar(name, nbDims, start, count, &value, wantedUnit);
  }
}