/*
 * Determine if lines from two TextParsers containing *lineSpec are identical.
 * Returns nonzero if *lineSpec line not found in both files.
 */
static int compareLines(
	TextParser &parser1,
	TextParser &parser2,
	const char *lineSpec,			// e.g., "FFT Type" 
	bool &match,					// RETURNED, true if both parsers have the line and they match
	char *lineBufOut)				// RETURNED, one of the lines
{
	char lineBuf[LINE_LENGTH_MAX];

	parser1.setCursor(0);
	parser2.setCursor(0);
	if(!parser1.findLine(lineSpec, lineBuf)) {
		return 1;
	}
	if(!parser2.findLine(lineSpec, lineBufOut)) {
		return 1;
	}
	if(strcmp(lineBuf, lineBufOut)) {
		match = false;
	}
	else {
		match = true;
	}
	return 0;
}
Example #2
0
//------------------------------------------------------------------------------
//void IndentComment(wxStringstream &gen, wxString &comment,
//                   const wxString &prefix)
//------------------------------------------------------------------------------
void BeginScript::IndentComment(wxString &gen, wxString &comment,
                                const wxString &prefix)
{
   TextParser tp;
   
   #if DBGLVL_GEN_STRING
   MessageInterface::ShowMessage
      (wxT("BeginScript::IndentComment() comment='%s', prefix='%s'\n"),
       comment.c_str(), prefix.c_str());
   #endif
   
   StringArray textArray = tp.DecomposeBlock(comment);
   UnsignedInt size = textArray.size();
   
   if (size > 0 && textArray[0] != wxT(""))
   {
      for (UnsignedInt i=0; i<size; i++)
      {
         gen << prefix << textArray[i];
         
         if (textArray[i].find(wxT("\n")) == comment.npos &&
             textArray[i].find(wxT("\r")) == comment.npos)
         {
            gen << wxT("\n");
         }
      }
   }
}
Example #3
0
 void Sprite::LoadFromText(const char *text)
 {
     TextParser parser;
     parser.Parse(text);
     TextParser::NODE *node = NULL;
     if ((node = parser.GetNode("FILETYPE")) && node->values[0] == "SPRITE")
     {
         if ((node = parser.GetNode("RESOURCE")))
         {
             _texture = static_cast<Texture*>(LE_ResourceManager.GetResourceWithRegister(node->values[0].GetCharPtr())->data);
         }
         if ((node = parser.GetNode("FRAMES")))
         {
             for (size_t i = 0; i<node->children.count(); i++)
             {
                 TextParser::NODE *child = node->children[i];
                 if (child)
                 {
                     TextParser::NODE *node_rect = child->FindChild("RECT");
                     if (node_rect)
                     {
                         AddFrame(iRect(node_rect->values[0].ToInt(),
                             node_rect->values[1].ToInt(),
                             node_rect->values[2].ToInt(),
                             node_rect->values[3].ToInt()
                         ));
                     }
                 }
             }
         }
     }
 }
 CNTKTextFormatReaderTestRunner(const string& filename,
     const vector<StreamDescriptor>& streams, unsigned int maxErrors) :
     m_parser(std::make_shared<CorpusDescriptor>(true), wstring(filename.begin(), filename.end()), streams, true)
 {
     m_parser.SetMaxAllowedErrors(maxErrors);
     m_parser.SetTraceLevel(TextParser<ElemType>::TraceLevel::Info);
     m_parser.SetChunkSize(SIZE_MAX);
     m_parser.SetNumRetries(0);
     m_parser.Initialize();
 }
static PyObject* TextParser_remove(PyObject* self, PyObject* args)
{
    PyObject* handle;
    if(!PyArg_ParseTuple(args, "O", &handle))
    {
        return NULL;
    }
    TextParser* tp = static_cast<TextParser*>(PyCObject_AsVoidPtr(handle));

    int         ret = tp->remove();
    return Py_BuildValue("i", ret);
}
static PyObject* TextParser_currentNode(PyObject* self, PyObject* args)
{
    PyObject* handle;
    if(!PyArg_ParseTuple(args, "O", &handle))
    {
        return NULL;
    }
    TextParser* tp = static_cast<TextParser*>(PyCObject_AsVoidPtr(handle));

    std::string value;
    int         ret = tp->currentNode(value);
    return Py_BuildValue("is", ret, value.c_str());
}
static PyObject* TextParser_deleteLeaf(PyObject* self, PyObject* args)
{
    PyObject*   handle;
    const char* label;
    if(!PyArg_ParseTuple(args, "Os", &handle, &label))
    {
        return NULL;
    }
    TextParser* tp = static_cast<TextParser*>(PyCObject_AsVoidPtr(handle));

    int         ret = tp->deleteLeaf(label);
    return Py_BuildValue("i", ret);
}
static PyObject* TextParser_write(PyObject* self, PyObject* args)
{
    const char* filename;
    PyObject*   handle;
    if(!PyArg_ParseTuple(args, "Os", &handle, &filename))
    {
        return NULL;
    }
    TextParser* tp = static_cast<TextParser*>(PyCObject_AsVoidPtr(handle));

    int         ret = tp->write(filename);
    return Py_BuildValue("i", ret);
}
static PyObject* TextParser_updateValue(PyObject* self, PyObject* args)
{
    PyObject*   handle;
    const char* label;
    const char* value;
    if(!PyArg_ParseTuple(args, "Oss", &handle, &label, &value))
    {
        return NULL;
    }
    TextParser* tp = static_cast<TextParser*>(PyCObject_AsVoidPtr(handle));

    int         ret = tp->updateValue(label, value);
    return Py_BuildValue("i", ret);
}
static PyObject* TextParser_getType(PyObject* self, PyObject* args)
{
    PyObject*   handle;
    const char* label;
    if(!PyArg_ParseTuple(args, "Os", &handle, &label))
    {
        return NULL;
    }
    TextParser*         tp = static_cast<TextParser*>(PyCObject_AsVoidPtr(handle));

    int                 ierr;
    TextParserValueType ret = tp->getType(label, &ierr);
    return Py_BuildValue("ii", ierr, ret);
}
static PyObject* TextParser_getValue(PyObject* self, PyObject* args)
{
    PyObject*   handle;
    const char* label;
    if(!PyArg_ParseTuple(args, "Os", &handle, &label))
    {
        return NULL;
    }
    TextParser* tp = static_cast<TextParser*>(PyCObject_AsVoidPtr(handle));

    std::string value;
    int         ret = tp->getValue(label, value);
    return Py_BuildValue("is", ret, value.c_str());
}
// #################################################################
// TextParserでのParse
CDM::E_CDM_ERRORCODE
//cdm_FieldFileNameFormat::Read(TextParser *tp)
cdm_FieldFileNameFormat::Read(cdm_TextParser tpCntl)
{

  //TP
  TextParser *tp = tpCntl.getTPPtr();
  if( !tp )
  {
    return CDM::E_CDM_ERROR_TEXTPARSER;
  }

  vector<string> top_label;  ///< カレントの子ノードのラベル格納
  tp->getNodes(top_label);
  //FieldFileNameFormatタグがある
  int cnt=0;
  for(int i=0; i< top_label.size(); i++)
  {
    if( (strcasecmp(top_label[i].c_str(),"FieldFileNameFormat") == 0 ) ) cnt ++;
  }

  if( cnt<1 ) return CDM::E_CDM_ERROR_UNDEFINED_FIELDFILENAMEFORMAT;

  vector<string> label;  ///< FieldFileNameFormat子ノードのラベル格納

  //FieldFileNameFormatタグへの移動
  tp->changeNode("FieldFileNameFormat");

  //FieldFileNameFormatの子ノードを取得
  tp->getNodes(label,2);

  //FieldFileNameFormatの子ノード数のループ
  for(int i=0; i<label.size(); i++)
  {
    //FieldFileNameFormatElemのインスタンス
    cdm_FieldFileNameFormatElem elem(label[i]);

    //FieldFileNameFormatElemのパース
    if( elem.Read(tp) )
    {
      //FieldFileNameFormatElemをmapに追加
      AddFieldFileNameFormatElem(elem);
    } else {
      return CDM::E_CDM_ERROR;
    }
  }

  return CDM::E_CDM_SUCCESS;
}
Example #13
0
//------------------------------------------------------------------------------
//void IndentChildString(wxStringstream &gen, GmatCommand* cmd, 
//                       wxString &indent, Gmat::WriteMode mode,
//                       const wxString &prefix, const wxString &useName,
//                       bool indentCommentOnly)
//------------------------------------------------------------------------------
void BeginScript::IndentChildString(wxString &gen, GmatCommand* cmd, 
                                    wxString &indent, Gmat::WriteMode mode,
                                    const wxString &prefix,
                                    const wxString &useName,
                                    bool indentCommentOnly)
{
   TextParser tp;
   
   #if DBGLVL_GEN_STRING
   ShowCommand(wxT(""), wxT("BeginScript::IndentChildString() cmd = "), cmd);
   MessageInterface::ShowMessage
      (wxT("BeginScript::IndentChildString() indent='%s', mode=%d, prefix='%s', ")
       wxT("useName='%s', indentCommentOnly=%d\n"), indent.c_str(), mode, prefix.c_str(),
       useName.c_str(), indentCommentOnly);
   #endif
   
   wxString cmdstr;
   if (indentCommentOnly)
      cmdstr = cmd->GetCommentLine();
   else
      cmdstr = cmd->GetGeneratingString(mode, prefix, useName);
   
   StringArray textArray = tp.DecomposeBlock(cmdstr);
   UnsignedInt size = textArray.size();
   
   #if DBGLVL_GEN_STRING
   MessageInterface::ShowMessage(wxT("   There are %d text lines\n"), size);
   #endif
   
   if (size > 0 && textArray[0] != wxT(""))
   {
      for (UnsignedInt i=0; i<size; i++)
      {
         if (indentCommentOnly)
            gen << indent << prefix << textArray[i];
         else
            gen << indent << textArray[i];
         
         if (textArray[i].find(wxT("\n")) == cmdstr.npos &&
             textArray[i].find(wxT("\r")) == cmdstr.npos)
         {
            gen << wxT("\n");
         }
      }
   }
   
   if (indentCommentOnly)
      gen << prefix << cmd->GetTypeName() << wxT(";");
}
static PyObject* TextParser_splitRange(PyObject* self, PyObject* args)
{
    PyObject*   handle;
    const char* value;
    if(!PyArg_ParseTuple(args, "Os", &handle, &value))
    {
        return NULL;
    }
    TextParser* tp = static_cast<TextParser*>(PyCObject_AsVoidPtr(handle));

    double      from;
    double      to;
    double      step;
    int         ret = tp->splitRange(value, &from, &to, &step);

    return Py_BuildValue("iddd", ret, from, to, step);
}
static PyObject* TextParser_getAllLabels(PyObject* self, PyObject* args)
{
    PyObject* handle;
    if(!PyArg_ParseTuple(args, "O", &handle))
    {
        return NULL;
    }
    TextParser*              tp = static_cast<TextParser*>(PyCObject_AsVoidPtr(handle));

    std::vector<std::string> labels;
    int                      ret       = tp->getAllLabels(labels);
    PyObject*                py_labels = PyList_New(labels.size());
    int                      i         = 0;
    for(std::vector<std::string>::iterator it = labels.begin(); it != labels.end(); ++it)
    {
        PyList_SetItem(py_labels, i++, Py_BuildValue("s", (*it).c_str()));
    }
    return Py_BuildValue("iO", ret, py_labels);
}
static PyObject* TextParser_read(PyObject* self, PyObject* args)
{
    // 引数の解析
    const char* filename;
    PyObject*   handle;
    if(!PyArg_ParseTuple(args, "Os", &handle, &filename))
    {
        return NULL;
    }
    TextParser* tp = static_cast<TextParser*>(PyCObject_AsVoidPtr(handle));

    int         ret = tp->read(filename);
    if(ret != 0)
    {
        std::cerr<<"MetaData read failed!! ("<<filename<<")"<<std::endl;
    }

    //戻り値を設定
    return Py_BuildValue("i", ret);
}
static PyObject* TextParser_expandRange(PyObject* self, PyObject* args)
{
    PyObject*   handle;
    const char* value;
    if(!PyArg_ParseTuple(args, "Os", &handle, &value))
    {
        return NULL;
    }
    TextParser*         tp = static_cast<TextParser*>(PyCObject_AsVoidPtr(handle));

    std::vector<double> expanded;
    int                 ret         = tp->expandRange(value, expanded);
    PyObject*           py_expanded = PyList_New(expanded.size());
    int                 i           = 0;
    for(std::vector<double>::iterator it = expanded.begin(); it != expanded.end(); ++it)
    {
        PyList_SetItem(py_expanded, i++, Py_BuildValue("d", *it));
    }
    return Py_BuildValue("iO", ret, py_expanded);
}
static PyObject* TextParser_splitList(PyObject* self, PyObject* args)
{
    PyObject*   handle;
    const char* value;
    if(!PyArg_ParseTuple(args, "Os", &handle, &value))
    {
        return NULL;
    }
    TextParser*         tp = static_cast<TextParser*>(PyCObject_AsVoidPtr(handle));
    std::vector<double> list;
    TextParserSortOrder order = TP_SORT_NONE;
    int                 ret     = tp->splitList(value, list, order);
    PyObject*           py_list = PyList_New(list.size());
    int                 i       = 0;
    for(std::vector<double>::iterator it = list.begin(); it != list.end(); ++it)
    {
        PyList_SetItem(py_list, i++, Py_BuildValue("d", *it));
    }
    return Py_BuildValue("iO", ret, py_list);
}
Example #19
0
// #################################################################
//
void COMB::ReadInit(string input_file)
{

    // ------------------------------------
    FILE* fp = NULL;

    // TPインスタンス生成
    TextParser tpCntl;

    // 入力ファイルをセット
    int ierror = tpCntl.read(input_file);

    // 入力ファイルの読み込み--->パラメータのセット
    ReadInputFile(&tpCntl);

    // TextParserの破棄
    tpCntl.remove();

    return;
}
Example #20
0
// #################################################################
//
void LAYOUT::ReadInit()
{
  
  // ------------------------------------
  FILE* fp = NULL;
  
  // TPインスタンス生成
  TextParser tpCntl;

  
  //入力ファイルをセット
  int ierror = tpCntl.read(fname);
  
  //入力ファイルの読み込み--->パラメータのセット
  ReadInputFile(&tpCntl);
  
  //TextParserの破棄
  tpCntl.remove();
  
  return;
}
/* 
 * Search for line containing lineTitle, return portion of the line following ":".
 * Returns nonzero if no "lineTitle" line found.
 * Line must contain at least 3 tokens - lineTitle, ":", and the string we return. 
 */
static int fineLineWithTitle(TextParser &parser, 
	const char *lineTytle,
	char *str)			// caller allocates, RETURNED
{
	char lineBuf[LINE_LENGTH_MAX];
	parser.setCursor(0);
	if(!parser.findLine(lineTytle, lineBuf)) {
		return 1;
	}
	
	unsigned numTokens;
	const char **tokens;
	numTokens = parser.parseLine(lineBuf, tokens);
	if(numTokens < 3) {
		return 1;
	}
	
	/* copy all tokens after ":" to caller's string */
	str[0] = '\0';
	for(unsigned dex=2; dex<numTokens; dex++) {
		strcat(str, tokens[dex]);
		if(dex < (numTokens - 1)) {
			strcat(str, " ");
		}
	}
	
	/* Convenience: "Accelerate" is too big. */
	if(strstr(str, "Accelerate")) {
		strcpy(str, "vecLib");
	}
	/* so is CLMatrix */
	else if(strstr(str, "CLMatrix")) {
		strcpy(str, "CLM");
	}
	/* ditto MatrixFFT */
	else if(strstr(str, "MatrixFFT")) {
		strcpy(str, "Matrix");
	}
	return 0;
}
Example #22
0
void Description::printPage()
{
    TextPage *page = text->getPage(currentPage);
    if (! page)
        return;
    int len = page->getWidgetsCount();
    for (int i = 0; i < len; i++) {
        Widget *w = page->getWidget(i);
        if (w) {
            widgets.push_back(w);
            area.add(w);
        }
    }
}
Example #23
0
void PathParser::Parse (const TextFragment& input)
{
	TextParser parser (input);
	OptionalType<TextFragment> info;

	parser.ReadText(info, _T(":"));

	if ((info.IsSet()) && (info.Value().Length() == 1))
	{
		m_Drive = *(info.Value().Data());
		parser.Skip(1);
	}

	// Find the last '/ or \ from the back, after the drive
	uint32 index = parser.ReverseFind(_T("\\/"));

	if (index != NUMBER_MAX_UNSIGNED(uint32))
	{
		m_Path = TextFragment(parser, 0, index);
		parser.Skip(index+1);
	}

	// Now we are ate the complete filename
	m_FileName = TextFragment (parser, 0, NUMBER_MAX_UNSIGNED(uint32));

	// Find the extension from the current parser...
	index = parser.ReverseFind(_T("."));

	if (index == NUMBER_MAX_UNSIGNED(uint32))
	{
		// oops there is no extension, BaseFileName == Filename
		m_BaseFileName = m_FileName;
	}
	else
	{
		m_BaseFileName = TextFragment (parser, 0, index);
		m_Extension = TextFragment(parser, index + 1, NUMBER_MAX_UNSIGNED(uint32));
	}
}
Example #24
0
/// TextParser parse.
/// parse() should be called before you start you try to do anything
/// else with the TextParser.
/// \param text Line of text that you want to parse
/// \return true on success, if false is returned, a errorMessage 
/// can is stored in public member variable errorMessage.
bool TextParser::parse(std::string text)
{
	// delete previous m_tokens
	if (m_tokens) 
	{
		delete []m_tokens;
		m_tokens = NULL;
	}

	// create a queue so we can add m_tokens as we go
	queue<MultiVariable> qTokens;

	MultiVariable token; // used to push m_tokens on the queue

	int strLength = (int)text.length();

	const char* s = text.c_str();

	if (text == "")
	{
		m_tokens = NULL;
		m_numTokens = 0;
		m_typeList = "";
		return 1;
	}
	

	// parse the entire
	bool done = false;
	int index = 0;  //index into the string
	while(!done)
	{		

		// if a quote is found
		if (s[index] == '"')
		{			
			// increment the index passed the quote
			index++;

			// remember where we started
			int startIndex = index;
			
			// search for a a corresponding end quote or the end of the string
			while (!(s[index] == '"' || index == strLength))
			 index++; 
			

			// if the end of file was found before and ending quote then
			// return an error
			if (index == strLength)
			{
				errorMessage = "Open quote without ending quote";
				return 0;
			}

			// now there is a string waiting between startIndex and index
			// put it in a string
			token.typeString = text.substr(startIndex,index - startIndex);
			token.type = eDataTypeString;
			
			// push it on the stack
			qTokens.push(token);

			//increment passed ending quote
			index++;
		}
		// if a closing parenthesis was found then there is a problem
		else if (s[index] == ')')
		{
			errorMessage = "Close parenthesis before open parenthesis";
			return 0;
		}

		// if a parenthesis was found
		else if (s[index] == '(')
		{
			// parse till the end parenthesis is found and then 
			// parse the inside of it
			
			index++;
			int startIndex = index;

			
			// search for a breaking character or the end of the string
			while (!(s[index] == ')' || index == strLength))
			 index++; 

			if (index == strLength)
			{
				errorMessage = "Open quote without ending quote";
				return 0;
			}

            // now there is a string waiting between startIndex and index
			// put it in a string
			string sToken = text.substr(startIndex,index - startIndex);

			// parse the inside
			TextParser tp;
			tp.parse(sToken);

			// get the token from the string
			if (!giveTokenFromTextParser(&tp, &token))
			{
				errorMessage = "Could not evaluate (" + sToken + ") to a type";
				return 0;
			}
			
			// push it on the stack
			qTokens.push(token);

			// skip ending parenthesis
			index++;

		}
		// if we found a breaking character just skip it
		else if (s[index] == ' ' || s[index] == ',')
		{
			index++;

		}
		else // a character
		{
			int startIndex = index;
			
			// search for a breaking character or the end of the string
			while (!(s[index] == ' ' || s[index] == ',' || index == strLength))
			 index++; 
			
            // now there is a string waiting between startIndex and index
			// put it in a string
			string sToken = text.substr(startIndex,index - startIndex);

		    // figure out what data type it is
			if (giveInt(&token.typeInt,sToken))
			{
				token.type = eDataTypeInt;
			}
			else if (giveFloat(&token.typeFloat,sToken))
			{
				token.type = eDataTypeFloat;
			}
			else if (giveBool(&token.typeBool,sToken))
			{
				token.type = eDataTypeBool;
			}
			else // take it as a string
			{
				token.type = eDataTypeString;
				token.typeString = sToken;
				
			}
			
			// push it on the stack
			qTokens.push(token);		
		}


		// leave at end of string
		if (index >= strLength) done = true;
	}

	// delete previous token array
	if (m_tokens) 
		delete []m_tokens;

	// get number of m_tokens in queue
	m_numTokens = (int)qTokens.size();
	
	if (m_numTokens <=0)
	{
		m_tokens = NULL;
		m_typeList = "";
		m_numTokens = 0;
	}



	// create a new array to hold m_tokens from the queue
	m_tokens = new MultiVariable[m_numTokens];
	
	// reset the parameter array
	m_typeList = "";

	// loop through all the m_tokens
	for (int a = 0; a < m_numTokens; a++)
	{
		// save the token from the front of the queue
		m_tokens[a] = qTokens.front();

		// pop off the item we just saved
		qTokens.pop();
		
		m_typeList += m_tokens[a].type;


	}

	

	// everything worked return true
	return true;
}
Example #25
0
 TextPage *getPage(unsigned int no) { return text->getPage(no); };
Example #26
0
// #################################################################
//
void DfiInfo::ReadDfiProc(string fname)
{
  TextParser tpCntl;
  string str;
  string label,label_base,label_leaf;
  int ct;
  int nnode=0;
  int iv[3];
  REAL_TYPE v[3];
  
  
  //入力ファイルをセット
  int ierror = tpCntl.read(fname);
  if ( ierror )
  {
    Hostonly_ stamped_printf("\tinput file not found '%s'\n",fname.c_str());
    Exit(0);
  }
  
  
  //Domain
  
  //Global_Origin
  label = "/Domain/GlobalOrigin";
  for (int n=0; n<3; n++) v[n]=0.0;
  if ( !(tpCntl.getInspectedVector(label, v, 3 )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  Global_Origin[0]=v[0];
  Global_Origin[1]=v[1];
  Global_Origin[2]=v[2];
  
  //Global_Region
  label = "/Domain/GlobalRegion";
  for (int n=0; n<3; n++) v[n]=0.0;
  if ( !(tpCntl.getInspectedVector(label, v, 3 )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  Global_Region[0]=v[0];
  Global_Region[1]=v[1];
  Global_Region[2]=v[2];
  
  //Global_Voxel
  label = "/Domain/GlobalVoxel";
  for (int n=0; n<3; n++) iv[n]=0;
  if ( !(tpCntl.getInspectedVector(label, iv, 3 )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  Global_Voxel[0]=iv[0];
  Global_Voxel[1]=iv[1];
  Global_Voxel[2]=iv[2];
  
  //Global_Division
  label = "/Domain/GlobalDivision";
  for (int n=0; n<3; n++) iv[n]=0.0;
  if ( !(tpCntl.getInspectedVector(label, iv, 3 )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  Global_Division[0]=iv[0];
  Global_Division[1]=iv[1];
  Global_Division[2]=iv[2];
  
  
  //MPI
  
  //NumberOfRank
  label = "/MPI/NumberOfRank";
  if ( !(tpCntl.getInspectedValue(label, ct )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  else {
    NumberOfRank = ct;
  }
  
  //NumberOfGroup
  label = "/MPI/NumberOfGroup";
  if ( !(tpCntl.getInspectedValue(label, ct )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  else {
    NumberOfGroup = ct;
  }
  
  
  ////RankID_in_MPIworld
  //label = "/DistributedFileInfo/RankIDinMPIworld";
  //if ( !(tpCntl.getInspectedValue(label, &ct )) ) {
  //  Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
  //  Exit(0);
  //}
  //else {
  //  RankID_in_MPIworld = ct;
  //}
  
  ////GroupID_in_MPIworld
  //label = "/DistributedFileInfo/GroupIDinMPIworld";
  //if ( !(tpCntl.getInspectedValue(label, &ct )) ) {
  //  Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
  //  Exit(0);
  //}
  //else {
  //  GroupID_in_MPIworld = ct;
  //}
  
  
  //Process <--- NodeInfo
  
  nnode=0;
  //label_base = "/DistributedFileInfo/NodeInfo";
  label_base = "/Process";
  if ( tpCntl.chkNode(label_base) )  //nodeがあれば
  {
    nnode = tpCntl.countLabels(label_base);
  }
  NodeInfoSize=nnode;
  Node = new DfiInfo::NodeInfo[nnode];
  
  for (int i=0; i<NodeInfoSize; i++)
  {
    if ( !(tpCntl.getNodeStr(label_base, i+1, str)) )
    {
      printf("\tParsing error : No Elem name\n");
      Exit(0);
    }
    if( strcasecmp(str.substr(0,4).c_str(), "Rank") ) continue;
    label_leaf=label_base+"/"+str;
    
    //RankID
    label = label_leaf + "/ID";
    if ( !(tpCntl.getInspectedValue(label, ct )) )
    {
      Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
      Exit(0);
    }
    else {
      Node[i].RankID= ct;
    }
    
    //HostName
    label = label_leaf + "/HostName";
    if ( !(tpCntl.getInspectedValue(label, str )) )
    {
      Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n", label.c_str());
      Exit(0);
    }
    Node[i].HostName= str;
    
    //VoxelSize
    label = label_leaf + "/VoxelSize";
    for (int n=0; n<3; n++) v[n]=0.0;
    if ( !(tpCntl.getInspectedVector(label, v, 3 )) )
    {
      Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
      Exit(0);
    }
    Node[i].VoxelSize[0]=v[0];
    Node[i].VoxelSize[1]=v[1];
    Node[i].VoxelSize[2]=v[2];
    
    //HeadIndex
    label = label_leaf + "/HeadIndex";
    for (int n=0; n<3; n++) v[n]=0.0;
    if ( !(tpCntl.getInspectedVector(label, v, 3 )) )
    {
      Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
      Exit(0);
    }
    Node[i].HeadIndex[0]=v[0];
    Node[i].HeadIndex[1]=v[1];
    Node[i].HeadIndex[2]=v[2];
    
    //TailIndex
    label = label_leaf + "/TailIndex";
    for (int n=0; n<3; n++) v[n]=0.0;
    if ( !(tpCntl.getInspectedVector(label, v, 3 )) )
    {
      Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
      Exit(0);
    }
    Node[i].TailIndex[0]=v[0];
    Node[i].TailIndex[1]=v[1];
    Node[i].TailIndex[2]=v[2];
    
  }
  
  
  //TextParserの破棄
  tpCntl.remove();
  
}
Example #27
0
// #################################################################
// 
void DfiInfo::ReadDfiFile(string fname)
{
  TextParser tpCntl;
  
  string str;
  string label,label_base,label_leaf;
  int ct;
  REAL_TYPE ct2;
  int nnode=0;
  
  
  //入力ファイルをセット
  int ierror = tpCntl.read(fname);
  if ( ierror )
  {
    Hostonly_ stamped_printf("\tinput file not found '%s'\n",fname.c_str());
    Exit(0);
  }
  
  
  //FileInfo
  
  //Prefix
  //label = "/DistributedFileInfo/Prefix";
  label = "/FileInfo/Prefix";
  if ( !(tpCntl.getInspectedValue(label, str )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  Prefix=str;
  
  //FileFormat
  //label = "/DistributedFileInfo/FileFormat";
  label = "/FileInfo/FileFormat";
  if ( !(tpCntl.getInspectedValue(label, str )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  FileFormat=str;
  
  //GuideCell
  //label = "/DistributedFileInfo/GuideCell";
  label = "/FileInfo/GuideCell";
  if ( !(tpCntl.getInspectedValue(label, ct )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  else {
    GuideCell = ct;
  }
  
  //DataType
  label = "/FileInfo/DataType";
  if ( !(tpCntl.getInspectedValue(label, str )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  DataType=str;
  
  //Endian
  label = "/FileInfo/Endian";
  if ( !(tpCntl.getInspectedValue(label, str )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  Endian=str;
  
  //ArrayShape
  label = "/FileInfo/ArrayShape";
  if ( !(tpCntl.getInspectedValue(label, str )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  ArrayShape=str;
  
  //Component
  label = "/FileInfo/Component";
  if ( !(tpCntl.getInspectedValue(label, ct )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  else {
    Component = ct;
  }
  
  //Unit
  
  //Length
  label = "/Unit/Length";
  if ( !(tpCntl.getInspectedValue(label, str )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  Length=str;
  
  //L0
  label = "/Unit/L0";
  if ( !(tpCntl.getInspectedValue(label, ct2 )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  else {
    L0 = ct2;
  }
  
  //Velocity
  label = "/Unit/Velocity";
  if ( !(tpCntl.getInspectedValue(label, str )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  Velocity=str;
  
  //V0
  label = "/Unit/V0";
  if ( !(tpCntl.getInspectedValue(label, ct2 )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  else {
    V0 = ct2;
  }
  
  //Length
  label = "/Unit/Pressure";
  if ( !(tpCntl.getInspectedValue(label, str )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  Pressure=str;
  
  //P0
  label = "/Unit/P0";
  if ( !(tpCntl.getInspectedValue(label, ct2 )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  else {
    P0 = ct2;
  }
  
  //DiffPrs
  label = "/Unit/DiffPrs";
  if ( !(tpCntl.getInspectedValue(label, ct2 )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  else {
    DiffPrs = ct2;
  }
  
  
  //FilePath
  label = "/FilePath/Process";
  if ( !(tpCntl.getInspectedValue(label, str )) )
  {
    Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
    Exit(0);
  }
  dfi_proc=str;
  
  //read process
  ReadDfiProc(dfi_proc);
  
  
  //TimeSlice
  nnode=0;
  label_base = "/TimeSlice/Slice";
  if ( tpCntl.chkNode(label_base) )  //nodeがあれば
  {
    nnode = tpCntl.countLabels(label_base);
  }
  
  label_base = "/TimeSlice";
  for (int i=0; i<nnode; i++)
  {
    if ( !(tpCntl.getNodeStr(label_base, i+1, str)) )
    {
      printf("\tParsing error : No Elem name\n");
      Exit(0);
    }
    
    if( strcasecmp(str.substr(0,5).c_str(), "Slice") ) continue;
    
    //step
    label=label_base+"/"+str+"/Step";
    if ( !(tpCntl.getInspectedValue(label, ct )) )
    {
      Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
      Exit(0);
    }
    
    //time
    label=label_base+"/"+str+"/Time";
    if ( !(tpCntl.getInspectedValue(label, ct2 )) )
    {
      Hostonly_ stamped_printf("\tParsing error : fail to get '%s'\n",label.c_str());
      Exit(0);
    }
    
    SetSlice(ct,ct2);
  }
  
  //TextParserの破棄
  tpCntl.remove();
  
  //内部変数の計算
  SetValue();
  
  
#if 0
  cout << endl;
  cout << endl;
  //for(int i=0;i<ndfi;i++){
  cout << "" << endl;
  cout << "Prefix = " << this->Prefix << endl;
  //cout << "RankIDinMPIworld = " << this->RankID_in_MPIworld << endl;
  //cout << "GroupIDinMPIworld = " << this->GroupID_in_MPIworld << endl;
  cout << "NumberOfRankIn = " << this->NumberOfRank << endl;
  cout << "NumberOfGroup  = " << this->NumberOfGroup << endl;
  cout << "GlobalOrigin[0] = " << this->Global_Origin[0] << endl;
  cout << "GlobalOrigin[1] = " << this->Global_Origin[1] << endl;
  cout << "GlobalOrigin[2] = " << this->Global_Origin[2] << endl;
  cout << "GlobalRegion[0] = " << this->Global_Region[0] << endl;
  cout << "GlobalRegion[1] = " << this->Global_Region[1] << endl;
  cout << "GlobalRegion[2] = " << this->Global_Region[2] << endl;
  cout << "GlobalVoxel[0] = " << this->Global_Voxel[0] << endl;
  cout << "GlobalVoxel[1] = " << this->Global_Voxel[1] << endl;
  cout << "GlobalVoxel[2] = " << this->Global_Voxel[2] << endl;
  cout << "GlobalDivision[0] = " << this->Global_Division[0] << endl;
  cout << "GlobalDivision[1] = " << this->Global_Division[1] << endl;
  cout << "GlobalDivision[2] = " << this->Global_Division[2] << endl;
  cout << "FileFormat = " << this->FileFormat << endl;
  cout << "GuideCell = " << this->GuideCell << endl;
  cout << "" << endl;
  cout << "NodeInfoSize = " << this->NodeInfoSize << endl;
  for(int j=0; j< this->NodeInfoSize; j++ ) {
    cout << "" << endl;
    cout << "Node[" << j << "].RankID = " << this->Node[j].RankID << endl;
    cout << "Node[" << j << "].HostName = " << this->Node[j].HostName << endl;
    cout << "Node[" << j << "].VoxelSize[0] = " << this->Node[j].VoxelSize[0] << endl;
    cout << "Node[" << j << "].VoxelSize[1] = " << this->Node[j].VoxelSize[1] << endl;
    cout << "Node[" << j << "].VoxelSize[2] = " << this->Node[j].VoxelSize[2] << endl;
    cout << "Node[" << j << "].HeadIndex[0] = " << this->Node[j].HeadIndex[0] << endl;
    cout << "Node[" << j << "].HeadIndex[1] = " << this->Node[j].HeadIndex[1] << endl;
    cout << "Node[" << j << "].HeadIndex[2] = " << this->Node[j].HeadIndex[2] << endl;
    cout << "Node[" << j << "].TailIndex[0] = " << this->Node[j].TailIndex[0] << endl;
    cout << "Node[" << j << "].TailIndex[1] = " << this->Node[j].TailIndex[1] << endl;
    cout << "Node[" << j << "].TailIndex[2] = " << this->Node[j].TailIndex[2] << endl;
    cout << "Node[" << j << "].IJK = " << this->Node[j].IJK << endl;
    cout << "Node[" << j << "].IJK_JK = " << this->Node[j].IJK_JK << endl;
    cout << "Node[" << j << "].IJK_K = " << this->Node[j].IJK_K << endl;
  }
  cout << "" << endl;
  //cout << "step.size() = " << this->step.size() << endl;
  //for(int j=0; j< this->step.size(); j++ ) {
  //  cout << "step[" << j << "] = " << this->step[j] << endl;
  //}
  cout << "Sc.size() = " << this->Sc.size() << endl;
  for(int j=0; j< this->Sc.size(); j++ ) {
    cout << "step[" << j << "] = " << this->Sc[j]->step << endl;
    cout << "time[" << j << "] = " << this->Sc[j]->time << endl;
  }
  cout << "" << endl;
  cout << "index_y.size() = " << this->index_y.size() << endl;
  for(int j=0; j< this->index_y.size(); j++ ) {
    cout << "index_y[" << j << "] = " << this->index_y[j] << endl;
  }
  cout << "" << endl;
  cout << "index_z.size() = " << this->index_z.size() << endl;
  for(int j=0; j< this->index_z.size(); j++ ) {
    cout << "index_z[" << j << "] = " << this->index_z[j] << endl;
  }
  //}
  cout << endl;
  cout << endl;
  
  //Exit(0);
  
#endif
  
}
 // Retrieves a chunk of data.
 void LoadChunk()
 {
     m_chunk = m_parser.GetChunk(0);
 }
Example #29
0
void SceneManager::LoadFromText(const char *text)
{
    TextParser parser;
    parser.Parse(text);
    TextParser::NODE *node = NULL;
    if ((node = parser.GetNode("FILETYPE")) && node->values[0] == "SCENE")
    {
        TextParser::NODE *node_data = parser.GetNode("DATA");
        if (node_data)
        {
            // Models
            TextParser::NODE *node_models = node_data->FindChild("MODELS");
            if (node_models)
            {
                for(size_t i=0;i<node_models->children.size();i++)
                {
                    TextParser::NODE *child = node_models->children[i];
                    TextParser::NODE *node_filename = NULL;
                    if ( child->name == "MODEL" && 
                        (node_filename = child->FindChild("FILENAME")))
                    {   // MODEL
                        Model *model = new Model(node_filename->values[0].GetCharPtr());
                        TextParser::NODE *node_position = child->FindChild("POSITION");
                        if (node_position) model->SetPosition(node_position->ToFVector3());
                        TextParser::NODE *node_scale = child->FindChild("SCALE");
                        if (node_scale) model->SetScale(node_scale->ToFVector3());
                        TextParser::NODE *node_rotation = child->FindChild("ROTATION");
                        if (node_rotation) model->SetRotation(node_rotation->ToFVector3());
                        mModels.push_back(model);
                    }
                }
            }

            // Lights
            TextParser::NODE *node_lights = node_data->FindChild("LIGHTS");
            if (node_lights)
            {
                for(size_t i=0;i<node_lights->children.size();i++)
                {
                    Light *light = NULL;
                    TextParser::NODE *child = node_lights->children[i];
                    TextParser::NODE *node_type = child->FindChild("TYPE");
                    if (node_type->values[0] == "Point")
                    {
                        light = new PointLight();
                    }
                    else if (node_type->values[0] == "Directional")
                    {
                        light = new DirectionalLight();
                    }
                    else if (node_type->values[0] == "Ambient")
                    {
                        light = new AmbientLight();
                    }
                    if (!light) continue;
                    TextParser::NODE *node_color = child->FindChild("COLOR");
                    if (node_color)
                    {
                        light->SetColor(node_color->ToFVector3());
                    }
                    TextParser::NODE *node_intensity = child->FindChild("INTENSITY");
                    if (node_intensity)
                    {
                        light->SetIntensity(node_intensity->values[0].ToFloat());
                    }
                    TextParser::NODE *node_pos = child->FindChild("POSITION");
                    if (node_pos && light->GetType() == Light::TYPE_POINT)
                    {
                        ((PointLight*)light)->SetPosition(node_pos->ToFVector3());
                    }
                    TextParser::NODE *node_scl = child->FindChild("SCALE");
                    if (node_scl && light->GetType() == Light::TYPE_POINT)
                    {
                        ((PointLight*)light)->SetScale(node_scl->ToFVector3());
                    }
                    switch(light->GetType())
                    {
                    case Light::TYPE_POINT:
                        {
                            TextParser::NODE *node_range = child->FindChild("RANGE");
                            if (node_range)
                            {
                                ((PointLight*)light)->SetRange(node_range->values[0].ToFloat());
                            }
                            TextParser::NODE *node_exp = child->FindChild("EXPONENT");
                            if (node_exp)
                            {
                                ((PointLight*)light)->SetExponent(node_exp->values[0].ToFloat());
                            }
                        } break;
                    }
                    AddLight(light);
                }
            }
        }
    }
}