tfpar.cpp

00001 /*************************************************************************************
00002  * MechSys - A C++ library to simulate (Continuum) Mechanical Systems                *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>       *
00004  * Copyright (C) 2005 Raul Dario Durand Farfan  <raul.durand at gmail.com>           *
00005  *                                                                                   *
00006  * This file is part of MechSys.                                                     *
00007  *                                                                                   *
00008  * MechSys is free software; you can redistribute it and/or modify it under the      *
00009  * terms of the GNU General Public License as published by the Free Software         *
00010  * Foundation; either version 2 of the License, or (at your option) any later        *
00011  * version.                                                                          *
00012  *                                                                                   *
00013  * MechSys is distributed in the hope that it will be useful, but WITHOUT ANY        *
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   *
00015  * PARTICULAR PURPOSE. See the GNU General Public License for more details.          *
00016  *                                                                                   *
00017  * You should have received a copy of the GNU General Public License along with      *
00018  * MechSys; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, *
00019  * Fifth Floor, Boston, MA 02110-1301, USA                                           *
00020  *************************************************************************************/
00021 
00022 #include <iostream>
00023 #include <string>
00024 
00025 #include "util/exception.h"
00026 #include "util/fileparser.h"
00027 
00028 using std::cout;
00029 using std::endl;
00030 
00031 int main(int argc, char **argv) try
00032 {
00033     // Open file
00034     FileParser FP(String("tfpar.ini"));
00035 
00036     // Number of elements
00037     int n_elements;
00038     FP.ReadNextValue(n_elements);
00039 
00040     // Allocate elements
00041     typedef Array<Array<double> > IniData;
00042     typedef Array<IniData>      Element;
00043     Element Elements; Elements.resize(n_elements);
00044 
00045     // Read elements
00046     for (int i=0; i<n_elements; ++i) 
00047     {
00048         // Read current line
00049         FP.JumpCommentsOrBlanks();
00050         std::string str_line = FP.GetCurrentLine(); FP.Advance();
00051 
00052         // Parse values
00053         LineParser LP(str_line);
00054 
00055         int            element_num;
00056         int            some_value;
00057         LP.StructuredLine(element_num, some_value, Elements[i]);
00058 
00059         // Output
00060         cout << element_num << "  " << some_value << "  ";
00061         for (size_t j=0; j<Elements[i].size(); j++)
00062         {
00063             cout << "{ ";
00064             for (size_t k=0; k<Elements[i][j].size(); k++)
00065             {
00066                 cout << Elements[i][j][k] << " ";
00067             }
00068             cout << "}  ";
00069         }
00070         cout << endl;
00071     }
00072 
00073     return 0;
00074 }
00075 catch (Exception * e)
00076 {
00077     e->Cout();
00078     if (e->IsFatal()) exit(1);
00079     delete e;
00080 }

Generated on Wed Jan 24 15:56:27 2007 for MechSys by  doxygen 1.4.7