예제 #1
0
//----------------------------------------
void CInternalFilesYFX::CreateData
		(const string		&Name,
		 const string		&Units,
		 const string		&LongName,
                 const string           &Comment /* = ""*/,
      	         double	                ValidMin /* = CTools::m_defaultValueDOUBLE */,
		 double	                ValidMax /* = CTools::m_defaultValueDOUBLE */,
		 nc_type		Type	/*= NC_DOUBLE*/)
{
  if (VarExists(Name))
  {
    throw CFileException(CTools::Format("Try to create data variable '%s' while it already exists",
					                              Name.c_str()),
			                                  GetName(),
			                                  BRATHL_LOGIC_ERROR);
  }

  if (m_file.GetNbDimensions() != 1)
  {
    throw CFileException(CTools::Format("Try to create data variable '%s' while not only one dimension exists",
					                              Name.c_str()),
			                                  GetName(),
			                                  BRATHL_LOGIC_ERROR);
  }

  CUnit unit = CUnit::ToUnit(Units);
  string strUnit = unit.AsString(false, true);

  m_file.AddVar(Name, Type, strUnit, LongName, Comment, 0, -1, -1, -1, ValidMin, ValidMax);
}
예제 #2
0
파일: Unit.cpp 프로젝트: BRAT-DEV/main
//----------------------------------------
void CUnit::InitializeUnitSystem()
{
  CUnit::m_dateRefUdunits = "2001-01-01 00:00:00.0";

  std::string FileName = CTools::FindDataFile(BRATHL_UNITFILE);

  m_initialized = true; // Only get one shot at this - failed or otherwise

  if (FileName.empty())
    {
    std::string errorMsg = CTools::Format("Units system file '%s' not found in '%s' directory."
                                     "Check directory '%s'",
                                      BRATHL_UNITFILE,
                                      CTools::GetInternalDataDir().c_str(),
                                      CTools::GetInternalDataDir().c_str());

      throw CFileException(errorMsg, BRATHL_UNIT_ERROR);
    }

  // didnt throw (yet), so initilaize the units system - this might throw
  CUnit::CheckUdunits(utInit(FileName.c_str()), FileName);
  
  // if the initializationdid not throw, then create the static instance
  // of the cleaner to ensure the unit system is closed properly.

  static CUnitSmartCleaner object;
}
예제 #3
0
void	CLODConvertApp::FileOpen(CString FileName)
{

		EditList[ModelSelected].Name="";
		// Ok... Load the model
		CFile File;
		File.Open(FileName, CFile::modeRead, &CFileException(CFileException::generic, NULL));
		DWORD	FileSize=(DWORD)File.GetLength();
		void *FileBuffer=malloc(FileSize);
		File.Read(FileBuffer, FileSize);
		FileTitle=File.GetFileTitle();
		File.Close();
		TheModelPath=FileName;
		
		while(RenderPhase) Delay(5);
		// Eventually clear the model
		ClearModel(&EditList[ModelSelected]);
		// Linearize the model and assign to selected item
		DeIndexModel(FileBuffer, &EditList[ModelSelected]);
		E_FixModelFeatures(&EditList[ModelSelected]);
		EditList[ModelSelected].Name=FileTitle;
	
		SetupModel();
		AddToRecentFileList(FileName);

}
예제 #4
0
void CInternalFilesZFXY::CreateDim
		(NetCDFVarKind		Kind,
		 const std::string		&XName,
		 const CExpressionValue	&Values,
		 const std::string		&Units,
		 const std::string		&LongName,
                 const std::string           &Comment /* = ""*/,
      	         double	                ValidMin /* = CTools::m_defaultValueDOUBLE */,
		 double	                ValidMax /* = CTools::m_defaultValueDOUBLE */)
{
  if (m_file.GetNbDimensions() >= 2)
    throw CFileException(CTools::Format("Only two dimensions is allowed in %s file type, not %d",
				        GetType().c_str(),
					m_file.GetNbDimensions()),
			 GetName(),
			 BRATHL_LOGIC_ERROR);
  m_file.SetDimension(Kind, XName, Values.GetNbValues(), Values, Units, LongName, Comment, ValidMin, ValidMax);
}
예제 #5
0
void CInternalFilesYFX::CreateDim
		(NetCDFVarKind kind,
		 const string& xName,
		 const CExpressionValue& values,
		 const string& units,
		 const string& longName,
     const string& comment /* = ""*/,
     double	validMin /* = CTools::m_defaultValueDOUBLE */,
		 double	validMax /* = CTools::m_defaultValueDOUBLE */)
{
  if (m_file.GetNbDimensions() != 0)
  {
    throw CFileException(CTools::Format("Only one dimension is allowed in '%s' file type",
				        GetType().c_str()),
			 GetName(),
			 BRATHL_LOGIC_ERROR);
  }

  m_file.SetDimension(kind, xName, values.GetNbValues(), values, units, longName, comment, validMin, validMax);
}
예제 #6
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);
  }
}
예제 #7
0
//----------------------------------------
void CBratProcessExportAscii::GetParameters()
{
  LoadParams(m_commandFileName);
  CheckFileParams();

  CFileParams& params = *m_fileParams;
  CUnit	unit;

// Verify keyword occurences
  uint32_t	nbExpr		= params.CheckCount(kwFIELD,  1, -1);
  uint32_t	nbFormats	= params.CheckCount(kwFIELD_FORMAT, 0, -1);
  uint32_t	nbNames    	= params.CheckCount(kwFIELD_NAME, 0, -1);
  uint32_t	nbOutput	= params.CheckCount(kwOUTPUT, 0);

  params.CheckCount(kwRECORD);
  params.CheckCount(kwFIELD_UNIT, nbExpr);

  if (nbFormats != 0)
  {
    params.CheckCount(kwFIELD_FORMAT, nbExpr);
  }

  if (nbNames != 0)
  {
    params.CheckCount(kwFIELD_NAME, nbExpr);
  }

// Get keyword values

  CTrace *p = CTrace::GetInstance();

  if (nbOutput != 0)
  {
    params.m_mapParam[kwOUTPUT]->GetValue(m_outputFileName);
  }

  if (m_outputFileName != "")
  {
    ofstream	*oFile;
    p->Tracer(1, CBratProcess::PCT_StrFmt, "Output file", m_outputFileName.c_str());
    oFile = new ofstream;
    oFile->open(m_outputFileName.c_str());
    if (oFile->fail())
    {
      throw CFileException("Error creating file", m_outputFileName, BRATHL_IO_ERROR);
    }
    m_outputFile	= oFile;
  }
  else
  {
    p->Tracer(1, CBratProcess::PCT_StrFmt, "Output file", "Standard output");
    m_outputFile	= &cout;
  }

  params.m_mapParam[kwRECORD]->GetValue(m_recordName);
  p->Tracer(1, CBratProcess::PCT_StrFmt, "Data set name", m_recordName.c_str());

  //ExpandArray = false;
  if (params.CheckCount(kwEXPAND_ARRAY, 0, 1) == 1)
  {
    params.m_mapParam[kwEXPAND_ARRAY]->GetValue(m_expandArray);
  }
  p->Tracer(1, CBratProcess::PCT_IntFmt, "Expand array", m_expandArray);

  if (params.CheckCount(kwDATE_AS_PERIOD, 0, 1) == 1)
  {
    params.m_mapParam[kwDATE_AS_PERIOD]->GetValue(m_dateAsPeriod);
  }
  p->Tracer(1, CBratProcess::PCT_IntFmt, "Date as period", m_dateAsPeriod);

  GetSelectParameter(params);

  ResizeArrayDependOnFields(nbExpr);

  uint32_t index;

  for (index = 0; index < nbExpr; index++)
  {
    string* namesTmp = NULL;

    if (nbNames > 0)
    {
      namesTmp = &m_names[index];
    }

    this->GetDefinition(params,
	      kwFIELD,
	      m_fields[index],
	      namesTmp,
	      NULL,
	      &m_units[index],
	      NULL,
	      NULL,
	      &m_formats[index],
	      NULL,
	      "Value/Column",
	      index,
	      nbExpr);
  }

  DeleteFileParams();
}