Exemple #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);
}
Exemple #2
0
CUnit CUnit::BaseUnit() const
{
	CUnit	Result;
	Result.m_Compiled		= m_Compiled;
	FindBaseUnit( Result.m_Compiled );
	Result.m_Text			= Result.AsString();
	return Result;
}
Exemple #3
0
//----------------------------------------
bool CUnit::operator==(CUnit& u)
{
  return str_icmp(this->AsString().c_str(), u.AsString().c_str());
}
Exemple #4
0
//----------------------------------------
void CPlot::GetInfo()
{

  CUnit unitXRead;
  CUnit unitYRead;

  string unitXStr;
  string unitYStr;

  bool assignYUnit = true;
  bool assignYTitle = true;
  bool assignXUnit = true;
  bool assignXTitle = true;

  CObArray allInternalFiles(false);


  GetAllInternalFiles(allInternalFiles);
  int32_t nrFiles = allInternalFiles.size();

  //int32_t iField = 0;
  int32_t nrFields = m_fields.size();
  CObArray::iterator itField;
  CObArray::iterator itFile;

  CStringArray plotFieldNames;

  for (itField = m_fields.begin() ; itField != m_fields.end() ; itField++)
  {
    CPlotField* field = CPlotField::GetPlotField(*itField);
    string fieldName = (const char *)(field->m_name);

    plotFieldNames.InsertUnique(fieldName);

    if ((field->m_xyProps != NULL) && (m_title.IsEmpty()) )
    {
      m_title = field->m_xyProps->GetTitle();
    }

    for (itFile = field->m_internalFiles.begin() ; itFile != field->m_internalFiles.end() ; itFile++)
    {

      CInternalFiles* yfx = CPlot::GetInternalFiles(*itFile);
      //-----------------------------------
      // Get plot Title --> title of the first file
      //-----------------------------------
      if (m_title.IsEmpty())
      {
        m_title = yfx->GetTitle("").c_str();
      }

      //-----------------------------------
      // Get and control unit of X axis
      //-----------------------------------
      string varXName;
      GetAxisX(yfx, NULL, NULL, &varXName);

      unitXRead = yfx->GetUnit(varXName);


      if (assignXUnit)
      {
        m_unitX = unitXRead;
        unitXStr = m_unitX.AsString();
        m_unitXLabel = "\nUnit:\t" + wxString(m_unitX.GetText().c_str());
        assignXUnit = false;
      }
      else
      {
        string unitXReadStr = unitXRead.AsString();
        if (m_unitX.IsCompatible(unitXRead) == false)
        {
          string msg = CTools::Format("CPlot::CkeckUnits - In group field number %d, X field unit are not in the same way (not compatible)"
                                      "- Expected unit '%s' and found '%s' for axis X - File name is '%s'",
                                       m_groupNumber,
                                       unitXStr.c_str(),
                                       unitXReadStr.c_str(),
                                       yfx->GetName().c_str());
          CException e(msg, BRATHL_INCONSISTENCY_ERROR);
          CTrace::Tracer("%s", e.what());
          throw (e);

        }
        if (unitXStr.compare(unitXReadStr) != 0)
        {
          m_unitXConv = true;
        }
      }
      //-----------------------------------
      // Get title of X axis
      //-----------------------------------
      string titleX;

      if (m_titleX.IsEmpty())
      {
        titleX = yfx->GetTitle(varXName);
        if (titleX.empty())
        {
          titleX = varXName;
        }
      }

      if (assignXTitle)
      {
        m_titleX += titleX.c_str() + m_unitXLabel;
        assignXTitle = false;
      }

      //--------------------------------------------------------
      // Get and control unit of Y axis --> unit of each field
      //---------------------------------------------------------
      unitYRead = yfx->GetUnit(fieldName);

      if ( assignYUnit )
      {
        m_unitY = unitYRead;
        unitYStr = m_unitY.AsString();
        m_unitYLabel = "\nUnit:\t" + wxString(m_unitY.GetText().c_str());
        assignYUnit = false;
      }
      else
      {
        string unitYReadStr = unitYRead.AsString();
        if (m_unitY.IsCompatible(unitYRead) == false)
        {
          string msg = CTools::Format("CXYPlotData::Create - In group field number %d, Y field unit are not in the same way (not compatible)"
                                      "- Expected unit '%s' and found '%s' for axis Y - Field name is '%s' - File name is '%s'",
                                       m_groupNumber,
                                       unitYStr.c_str(),
                                       unitYReadStr.c_str(),
                                       fieldName.c_str(),
                                       yfx->GetName().c_str());
          CException e(msg, BRATHL_INCONSISTENCY_ERROR);
          CTrace::Tracer("%s", e.what());
          throw (e);

        }
        if (unitYStr.compare(unitYReadStr) != 0)
        {
          m_unitYConv = true;
        }
      }

      //-----------------------------------
      // Get title of Y axis (as possible)
      //-----------------------------------

      string titleY;

      if ((nrFields == 1) && (nrFiles <= 1))
      {
        if (m_titleY.IsEmpty())
        {
          titleY = yfx->GetTitle(fieldName);
          if (titleY.empty())
          {
            titleY = fieldName;
          }
        }
      }

      if (assignYTitle)
      {
        m_titleY += titleY.c_str() + m_unitYLabel;
        assignYTitle = false;
      }


    } // end for (itFile = ...

  } //  end for (itField = ...

  //CTrace::GetInstance()->SetTraceLevel(5);
  //plotFieldNames.Dump(*(CTrace::GetInstance()->GetDumpContext()));

  if (plotFieldNames.size() > 0)
  {
    for (itFile = allInternalFiles.begin() ; itFile != allInternalFiles.end() ; itFile++)
    {
      CInternalFiles* yfx = CPlot::GetInternalFiles(*itFile);

      if (yfx == NULL)
      {
        continue;
      }

      CStringArray complement;

      yfx->GetComplementVars(plotFieldNames, complement);

      CStringArray::iterator itStringArray;
      for (itStringArray = complement.begin() ; itStringArray != complement.end(); itStringArray++)
      {
        CNetCDFVarDef* v1Def = yfx->GetNetCDFVarDef(plotFieldNames.at(0));
        CNetCDFVarDef* v2Def = yfx->GetNetCDFVarDef(*itStringArray);

        if ((v1Def == NULL) || (v2Def == NULL))
        {
          continue;
        }


        if (yfx->GetFile()->HaveEqualDimNames(plotFieldNames.at(0), *itStringArray))
        {
          m_nonPlotFieldNames.InsertUnique(*itStringArray);
        }

      }

      //complement.Dump(*(CTrace::GetInstance()->GetDumpContext()));


    }

    //m_nonPlotFieldNames.Dump(*(CTrace::GetInstance()->GetDumpContext()));
  }

/*


  for (iFile = 0 ; iFile < nrFiles ; iFile++)
  {
    CInternalFilesYFX* yfx = GetInternalFilesYFX(allInternalFiles.at(iFile));
    //-----------------------------------
    // Get plot Title --> title of the first file
    //-----------------------------------
    if (m_title.IsEmpty())
    {
      m_title = yfx->GetTitle("").c_str();
    }

    //-----------------------------------
    // Get and control unit of X axis
    //-----------------------------------
    string varXName;
    GetAxisX(yfx, NULL, NULL, &varXName);

    unitXRead = yfx->GetUnit(varXName);



    //--------------------------------------------------------
    // Get and control unit of Y axis --> unit of each field
    //---------------------------------------------------------

    //int32_t iField = 0;
    int32_t nrFields = m_fields.size();
    CObArray::iterator itField;

    for (itField = m_fields.begin() ; itField != m_fields.end() ; itField++)
    {

      if (assignXUnit)
      {
        m_unitX = unitXRead;
        unitXStr = m_unitX.AsString();
        m_unitXLabel = "\nUnit:\t" + wxString(m_unitX.GetText().c_str());
        assignXUnit = false;
      }
      else
      {
        string unitXReadStr = unitXRead.AsString();
        if (m_unitX.IsCompatible(unitXRead) == false)
        {
          string msg = CTools::Format("CPlot::CkeckUnits - In group field number %d, X field unit are not in the same way (not compatible)"
                                      "- Expected unit '%s' and found '%s' for axis X - File name is '%s'",
                                       m_groupNumber,
                                       unitXStr.c_str(),
                                       unitXReadStr.c_str(),
                                       yfx->GetName().c_str());
          CException e(msg, BRATHL_INCONSISTENCY_ERROR);
          CTrace::Tracer(e.what());
          throw (e);

        }
        if (unitXStr.compare(unitXReadStr) != 0)
        {
          m_unitXConv = true;
        }
      }
      //-----------------------------------
      // Get title of X axis
      //-----------------------------------
      string titleX;

      if (m_titleX.IsEmpty())
      {
        titleX = yfx->GetTitle(varXName);
        if (titleX.empty())
        {
          titleX = varXName;
        }
      }

      //if (iFile == 0)
      if (assignXTitle)
      {
        m_titleX += titleX.c_str() + m_unitXLabel;
        assignXTitle = false;
      }


      CPlotField* field = CPlotField::GetPlotField(*itField);
      string fieldName = field->m_name.c_str();

      unitYRead = yfx->GetUnit(fieldName);

      if ( assignYUnit )
      {
        m_unitY = unitYRead;
        unitYStr = m_unitY.AsString();
        m_unitYLabel = "\nUnit:\t" + wxString(m_unitY.GetText().c_str());
        assignYUnit = false;
      }
      else
      {
        string unitYReadStr = unitYRead.AsString();
        if (m_unitY.IsCompatible(unitYRead) == false)
        {
          string msg = CTools::Format("CXYPlotData::Create - In group field number %d, Y field unit are not in the same way (not compatible)"
                                      "- Expected unit '%s' and found '%s' for axis Y - Field name is '%s' - File name is '%s'",
                                       m_groupNumber,
                                       unitYStr.c_str(),
                                       unitYReadStr.c_str(),
                                       fieldName.c_str(),
                                       yfx->GetName().c_str());
          CException e(msg, BRATHL_INCONSISTENCY_ERROR);
          CTrace::Tracer(e.what());
          throw (e);

        }
        if (unitYStr.compare(unitYReadStr) != 0)
        {
          m_unitYConv = true;
        }
      }

      //-----------------------------------
      // Get title of Y axis (as possible)
      //-----------------------------------

      string titleY;

      if ((nrFields == 1) && (nrFiles <= 1))
      {
        if (m_titleY.IsEmpty())
        {
          titleY = yfx->GetTitle(fieldName);
          if (titleY.empty())
          {
            titleY = fieldName;
          }
        }
      }

      if (assignYTitle)
      {
        m_titleY += titleY.c_str() + m_unitYLabel;
        assignYTitle = false;
      }
    }
  }


*/
}