11 ofstream f(fileName.c_str(),ios::out);
15 f <<
"# file generated at "<<time.
toString(
"DD/MM/YYYY-HHhMM")<<
"\n";
16 f <<
"# save a steady field \n";
17 f <<
"#N is the number of points\n";
18 f <<
"#values : the values of the array. One value by line\n";
29 throw EMM_Exception(
"EMM_Array::saveToFile("+fileName+
")",
"impossible to open file for saving");
42 const T *vs=&(*this)[0];
60 if (dims.size()!=indics.size())
return false;
67 vector<const T*> arrays(nIndics);
68 typename vector<const T* >::iterator iterA=arrays.begin();
71 typename vector<const EMM_Array<T>*>::const_iterator iterI=indics.begin();
74 typename vector<tUSInt>::const_iterator iterD=dims.begin();
76 while (iterI!=indics.end()) {
78 *iterA=&(*(*iterI))[0];
82 nPacks=(*iterI)->getSize()/(*iterD);
85 if ((*iterI)->getSize()/(*iterD)<nPacks)
return false;
97 for (i=0;i<nPacks;i++) {
100 for (iterA=arrays.begin();iterA!=arrays.end();iterA++) {
101 for (j=0;j<(*iterD);j++) {
117 ifstream f(fileName.c_str(),ios::in);
141 tUInteger nEmptyLines=0,nMaxEmptyLines=10;
143 while (!f.eof() && (numLine<maxLines) && (nEmptyLines<nMaxEmptyLines) ) {
149 tokenizer->setString(line);
152 iComment=tokenizer->getString().find(
"#");
153 if (iComment!=tString::npos) {
156 if (iComment==0)
continue;
159 tokenizer->setString(tokenizer->getString().substr(0,iComment));
166 tokenizer->tokenize();
169 nTokens=tokenizer->getTokensNumber();
175 if ((nPoints==0) && (nTokens>=1)) {
181 if (nPoints>0) loadFromStream(f,1);
194 if (nEmptyLines>=nMaxEmptyLines) {
195 throw EMM_Exception(
"EMM_Array::loadFromFile("+fileName+
")",
" too many empty lines detected "+
200 throw EMM_Exception(
"EMM_Array::loadFromFile("+fileName+
")",
"impossible to open file");
217 for (j=0;j<dim;j++) {
243 if (dims.size()!=arrays.size())
return false;
247 vector<T*> Parrays(nArrays);
248 typename vector<T* >::iterator iterP=Parrays.begin();
251 typename vector<EMM_Array<T>*>::const_iterator iterA=arrays.begin();
254 typename vector<tUSInt>::const_iterator iterD=dims.begin();
259 while (iterA!=arrays.end()) {
261 *iterP=&(*(*iterA))[0];
265 size=(*iterA)->getSize()/(*iterD);
268 if ((*iterA)->getSize()/(*iterD)<size) {
270 "error in reading aim file: the size of arrays to read is not compatible");
287 for (i=0;i<size;i++) {
292 iterP=Parrays.begin();
293 while (iterP!=Parrays.end()) {
297 for (j=0;j<dim;j++) {
const tUIndex & getSize() const
return the size of the array for reading
Definition: CORE_Array.h:1018
static tLLInt parseInt(const tString &str)
return the integer associated to the string
Definition: CORE_Integer.cpp:102
virtual tString toString() const
return the time into a string
Definition: CORE_Time.cpp:344
tBoolean loadFromStream(ifstream &f, const vector< tUSInt > &dims, const vector< EMM_Array< T > * > &arrays) const
load the values to indicators from the stream
Definition: EMM_Array.hpp:235
virtual void println(const tFlag &type, const tString &message)
print the message with an end of line
Definition: CORE_Out.h:342
#define tUInteger
Definition: types.h:91
this class describes a time class
Definition: CORE_Time.h:64
static tLDouble parseReal(const tString &str)
return the real associated to the string
Definition: CORE_Real.h:201
#define tUSInt
Definition: types.h:28
#define tBoolean
Definition: types.h:139
void setSize(const tUIndex &n)
set the size
Definition: CORE_Array.h:292
virtual tString toString() const
return the string associated to the string
Definition: CORE_String.h:223
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:106
tBoolean loadFromFile(const tString &fileName)
load the steady array from file
Definition: EMM_Array.hpp:116
tBoolean saveToStream(ofstream &f) const
save the values of the array into the stream with 1 value per line
Definition: EMM_Array.h:208
tBoolean saveToFile(const tString &fileName) const
save the steady array into file
Definition: EMM_Array.hpp:10
#define tUIndex
Definition: types.h:126
#define tString
Definition: types.h:135
static CORE_Out & out()
get the output
Definition: CORE_Object.h:198
static const tFlag ERROR_MSG
Definition: CORE_Out.h:41
this class describes the exceptions raised for E-MicromM package
Definition: EMM_Exception.h:14
static SP::CORE_String New()
create a class String
Definition: CORE_String.h:96
static tBoolean isDigit(const char &v)
return if the char is a digit
Definition: CORE_String.h:719
This class describes a general array.
Definition: EMM_Array.h:18
static tUInt getMaxUInt()
get the max value for tUInt type
Definition: CORE_Object.h:399