28 ifstream fileHst(fileName.c_str(),ios::in);
69 tBoolean isFirstHCyclesNumberRead=
false;
80 fileHst.getline(line,len);
83 tokenizer->setString(line);
84 tokenizer->tokenize(
": , \t");
85 nTokens=tokenizer->getTokensCount();
88 if (nTokens==0)
continue;
91 token=tokenizer->nextToken();
94 if (token.find(
"#")==0)
continue;
98 if ( (nTokens==4) && (n==0) ) {
132 if ((dim==0) || (n==0)) {
133 cout <<
"error in reading the hysteresis file: M type can not be read or no data found \n";
145 token=tokenizer->nextToken();
150 tokenizer->nextToken();
151 tokenizer->nextToken();
160 if (nTokens/dim>nMaxHCycles)
throw EMM_Exception(
"emicrom/hysteresis",
161 "EMMH_HysteresisFile::load()",
165 while (nTokens>=dim) {
168 for (k=0;k<dim;k++) {
169 token=tokenizer->nextToken();
178 nHCycles=nTokens/dim;
184 if (!isFirstHCyclesNumberRead){
188 isCurrentDataFound=
true;
192 isFirstHCyclesNumberRead=
true;
193 }
else if ( (!isCurrentDataFound) && (nHCycles<iHCycle+1) ) {
196 isCurrentDataFound=
true;;
198 }
else if ((!isCurrentDataFound) && (nHCycles>iHCycle+1)) {
203 isCurrentDataFound=
true;
212 cout <<
"error in reading the hysteresis file:not enough data to read Hext \n";
223 }
while ( (succeeds) &&
224 ((n==0) || ( (n>0) && (i<n)) ) &&
225 ((Hext!=
null) || !isCurrentDataFound) &&
226 (!fileHst.eof()) && (numLine<
MAX_LINES) );
231 cout <<
"error in opening the file "<<fileName<<
"\n";
236 if (!isCurrentDataFound) {
240 if (iHCycle%2==0) iData=0;
271 nMaxHCycles=(M.
getSize()/(n*dim));
277 ofstream fileHst(fileName.c_str(),ios::out);
279 fileHst <<
"# hysteresis file modified by e-microm"<<endl;
280 fileHst << comment <<endl;
281 fileHst <<
"# N: number of data per half cycle"<<endl;
282 fileHst <<
"# D : dimension of the field per data"<<endl;
283 fileHst <<
"# nHCycles : number of half cycles"<<endl;
284 fileHst <<
"# S : steps number for saving equilibrium magnetism"<<endl;
285 fileHst<< n<<
"\t"<<dim<<
"\t"<<nMaxHCycles<<
"\t"<<s<<endl;
286 fileHst <<
"# Hext : M^0_x M^0_y M^0_z M^1_x M^1_y M^1_z ..."<<endl;
288 const tReal *Hi=&Hext[0];
290 const T *Mci,*Mi=&M[0];
294 fileHst<<(*Hi)<<
"\t";
301 for (c=0;c<iHCycle;c++) {
302 for (d=0;d<dim;d++) {
303 fileHst<<(*Mci)<<
"\t";
313 for (d=0;d<dim;d++) {
314 fileHst<<(*Mci)<<
"\t";
320 for (d=0;d<dim;d++) {
321 fileHst<<(*Mci)<<
"\t";
335 cout <<
"impossible to open the hysteresis file "<<fileName<<
"\n";
345 const tUSInt& flowSize)
const {
348 tString outFileName=inFileName+
"~";
365 "EMMH_HysteresisFile::append(...)",
371 ifstream iFileHst(inFileName.c_str(),ios::in);
374 ofstream oFileHst(outFileName.c_str(),ios::out);
379 tUIndex index,index1,index0=i0;
380 for (c=1;c<=c0;c++) {
381 index0+=((c%2==1)?(2*(n-1-i0)+1):(2*i0+1));
383 index1=index0+flowSize;
385 if (iFileHst && oFileHst) {
413 iFileHst.getline(line,len);
416 tokenizer->setString(line);
417 tokenizer->tokenize(
": , \t");
418 nTokens=tokenizer->getTokensCount();
421 if (nTokens==0)
continue;
424 token=tokenizer->nextToken();
427 if (token.find(
"#")==0) {
428 oFileHst<<line<<
"\n";
434 if ( (nTokens==4) && (!hasDataBeenRead) ) {
443 c=c0+(i0+flowSize)/n;
444 if (c>nMaxHCycles) nMaxHCycles=c;
449 oFileHst<< n<<
"\t"<<dim<<
"\t"<<nMaxHCycles<<
"\t"<<flowSize<<endl;
450 hasDataBeenRead=
true;
457 tokenizer->nextToken();
458 tokenizer->nextToken();
462 nHCycles=nTokens/dim;
473 for (c=1;c<nHCycles;c++) {
474 index+=((c%2==1)?(2*(n-1-i)+1):(2*i+1));
481 else index+=((c%2==1)?(2*(n-1-i)+1):(2*i+1));
485 while ((index>=index0) && (index<index1)) {
486 Mi=&M[dim*(index-index0)];
487 for (k=0;k<dim;k++) {
488 oFileHst<<(*Mi)<<
"\t";
494 index+=((c%2==1)?(2*(n-1-i)+1):(2*i+1));
510 }
while ( ((n==0) || ( (n>0) && (i<n)) )
520 cout <<
"impossible to open the hysteresis file "<<inFileName<<
" for reading and "<<outFileName<<
" for writing \n";
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
static tBoolean mv(const tString &src, const tString &dest)
move file
Definition: CORE_IO.cpp:430
#define tUInteger
Definition: types.h:91
static void parse(const tString &str, tUChar &c)
parse unsigned char c in str
Definition: CORE_String.h:504
tBoolean load(EMM_RealArray &H, EMM_RealArray &M, tUSInt &D, tUInteger &i, tUInteger &c, tUSInt &s) const
load the file and fill the H values and the M values
Definition: EMMH_HysteresisFile.cpp:153
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
tBoolean append(const EMM_RealArray &M, const tUSInt &D, const EMM_RealArray &data, const tUSInt &dataDim, const tUSInt &n) const
append the data to the hysteresis file & relaxation return code
Definition: EMMH_HysteresisFile.cpp:120
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:106
#define null
Definition: types.h:144
static const tUIndex MAX_LINES
Definition: EMMH_HysteresisFile.h:45
#define tUIndex
Definition: types.h:126
This class describes a real array.
Definition: EMM_RealArray.h:16
#define tString
Definition: types.h:135
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
tBoolean save(const EMM_RealArray &Hext, const vector< tString > &dataNames, const tUInteger &nMaxHCycles, const tUSInt &flowSize) const
save all the external field for all hysteresis files:
Definition: EMMH_HysteresisFile.cpp:6
This class describes a general array.
Definition: EMM_Array.h:18
#define tReal
Definition: types.h:118