Main Page   Namespace List   Compound List   File List   Compound Members   File Members  

copyOf-ocsReadWriteTools.cc

Go to the documentation of this file.
00001 // $Id: ocsReadWriteTools.cc,v 1.10 2002/04/29 20:33:04 zweck Exp $
00002 
00003 //###################################################################\\
00004 //                                                                   \\
00005 //           Optical Communication Systems Simulator                 \\
00006 //                                                                   \\
00007 //       Copyright (2000):                                           \\
00008 //       Optical Fiber Communications Laboratory (OFCL)              \\
00009 //       Computer Science & Electrical Engineering Department (CSEE) \\ 
00010 //       University of Maryland Baltimore County (UMBC)              \\
00011 //                                                                   \\
00012 //###################################################################\\
00013 
00014 #include "ocsReadWriteTools.hh"
00015 
00016 
00017 extern ofstream LogFile;
00018 
00031 int ReadInt(string ParameterName, string UnitsString,
00032             int LowerBound,int UpperBound,
00033             BoundsFlagEnumerator BoundsFlag, 
00034             InputParameterOptionsEnumerator InputParameterOption,
00035             int DefaultValue,
00036             ifstream * InFile)
00037 {
00038   int ParameterRead = 0;
00039   int ParameterValue = 0;
00040   string NameBuffer;
00041   
00042   // Appends the string ParameterName to the dollar sign to form 
00043   // a string that the begins with a dollar sign.
00044   string ParameterNameDollar = "$"+ParameterName;
00045   
00046   InFile->clear(); // Resets ifstream state to good
00047   
00048   // In order for an input operation to actually do something its
00049   // state must be "good". When the end of file is reached the 
00050   // state is set to "eof" which is not good! (This will have happened
00051   // if the ReadInt function has been previously called.)
00052   // The clear() function resets the state to "good"
00053   
00054   InFile->seekg(0); // Resets the file pointer to the start of the file.
00055   
00056   // Data is sequentially being read from the file. 
00057   // When the end of file has been reached, the implicit call to 
00058   // operator void* in the while structure returns '0' (normally 
00059   // operator void returns true), the file is called by the ifstream
00060   // destructor function.
00061   
00062   while (*InFile >> NameBuffer)
00063     {
00064       if (ParameterNameDollar == NameBuffer) 
00065         {
00066           // If the above condition is true, the value read from the 
00067           // file ater NameBuffer, is of type ParameterValue.
00068           *InFile >> ParameterValue; 
00069           
00070           // FIX: Check that have really read value in correctly!
00071           
00072           ParameterRead = 1;
00073         }  // end if   
00074       
00075     } // end while
00076   
00077   // The obove if block should be executed after every execution of the 
00078   // while statement; in other words, after every Name buffer, there should
00079   // be a ParameterValue. The following block is executed if the Parameter 
00080   // value is missing.
00081   
00082   if(!ParameterRead)
00083     {
00084       // The MissingParameter is being called if ParameterValue is missing.
00085       MissingParameter(ParameterName,InputParameterOption);
00086       
00087       // ParameterValue is being set to a default value
00088       ParameterValue = DefaultValue;
00089     }
00090   
00091   // Write a set of data to the file using the stream-insertion operator <<
00092   // and the LofFile object associated with the file at the beginning of the 
00093   // program. The data maybe retrieved by a program designed to read the file
00094   // Note that the file created is a text file and can be read by any text 
00095   // editor.
00096   LogFile << ParameterName << " = " << ParameterValue << " " 
00097           << UnitsString << endl;
00098   
00099   switch(BoundsFlag)
00100     {
00101     case LOWER_ONLY:
00102       if(ParameterValue < LowerBound)
00103         {
00104           LogFileStars(); //pape explain this call later
00105 
00106           //More data is being written in the LogFile.
00107           LogFile << "             WARNING" << endl 
00108                   << "The integer parameter " 
00109                   << ParameterName << endl 
00110                   << "is not in the required range " 
00111                   << "[" << LowerBound << " , inf)" 
00112                   << endl;
00113           
00114           LogFileStars(); //pape explain this call later
00115         } // end if
00116       break;
00117       
00118     case UPPER_ONLY:
00119       if(ParameterValue > UpperBound)
00120         {
00121           LogFileStars(); //pape explain this call later
00122           
00123           //More data is being written in the LogFile.
00124           LogFile << "             WARNING" << endl 
00125                   << "The integer parameter " 
00126                   << ParameterName << endl 
00127                   << "is not in the required range " 
00128                   << "(-inf , " << UpperBound << "]" 
00129                   << endl;
00130           LogFileStars(); //pape explain this call later
00131         } // end if
00132       
00133       break;
00134       
00135     case LOWER_AND_UPPER:
00136       if(ParameterValue > UpperBound || ParameterValue < LowerBound)
00137         {
00138           LogFileStars();//pape explain this call later
00139           
00140           //More data is being written in the LogFile.
00141           LogFile << "             WARNING" << endl 
00142                   << "The integer parameter " 
00143                   << ParameterName << endl 
00144                   << "is not in the required range " 
00145                   << "[" << LowerBound << " , " <<UpperBound << "]" 
00146                   << endl;
00147           
00148           LogFileStars();//pape explain this call later
00149         } // end if
00150       
00151       break;
00152       
00153       // default case excutes in case of an invalid bound  
00154     case NO_BOUNDS:
00155       break;
00156       
00157 
00158     default: 
00159       cerror("Invalid BoundsFlag Enumerator Choice");
00160       exit(1);
00161           
00162     } // end switch
00163     
00164   return ParameterValue;
00165   
00166   
00167 } // ## end ReadInt
00168 
00169 
00182 long ReadLongInt(string ParameterName, string UnitsString,
00183                  long LowerBound, long UpperBound,
00184                  BoundsFlagEnumerator BoundsFlag, 
00185                  InputParameterOptionsEnumerator InputParameterOption,
00186                  long DefaultValue,
00187                  ifstream * InFile)
00188 {
00189   
00190   int ParameterRead = 0;
00191   long ParameterValue = 0;
00192   string NameBuffer;
00193   
00194   // Appends the string ParameterName to the dollar sign to form 
00195   // a string that the begins with a dollar sign.
00196   string ParameterNameDollar = "$"+ParameterName;
00197   
00198   InFile->clear(); // Resets ifstream state to good
00199   
00200   // In order for an input operation to actually do something its
00201   // state must be "good". When the end of file is reached the 
00202   // state is set to "eof" which is not good! (This will have happened
00203   // if the ReadInt function has been previously called.)
00204   // The clear() function resets the state to "good"
00205 
00206   
00207   InFile->seekg(0); // Resets the file pointer to the start of the file.
00208   
00209   // Data is sequentially being read from the file. 
00210   // When the end of file has been reached, the implicit call to 
00211   // operator void* in the while structure returns '0' (normally 
00212   // operator void returns true), the file is called by the ifstream
00213   // destructor function.
00214   
00215   while (*InFile >> NameBuffer)
00216     {
00217       if (ParameterNameDollar==NameBuffer) 
00218         {
00219           
00220           // If the above condition is true, the value read from the 
00221           // file ater NameBuffer, is of type ParameterValue.
00222           *InFile >> ParameterValue; 
00223           
00224           // FIX: Check that have really read value in correctly!
00225           
00226           ParameterRead = 1;
00227         }  // end if   
00228       
00229     } // end while
00230 
00231   // The obove if block should be executed after every execution of the 
00232   // while statement; in other words, after every Name buffer, there should
00233   // be a ParameterValue. The following block is executed if the Parameter 
00234   // value is missing.
00235   
00236   if(!ParameterRead)
00237     {
00238       // The MissingParameter is being called if ParameterValue is missing.
00239       MissingParameter(ParameterName,InputParameterOption);
00240       
00241       // ParameterValue is being set to a default value
00242       ParameterValue = DefaultValue;
00243     }
00244   
00245   // Write a set of data to the file using the stream-insertion operator <<
00246   // and the LofFile object associated with the file at the beginning of the 
00247   // program. The data maybe retrieved by a program designed to read the file
00248   // Note that the file created is a text file and can be read by any text 
00249   // editor.
00250   LogFile << ParameterName << " = " << ParameterValue << " " 
00251           << UnitsString << endl;
00252 
00253   switch(BoundsFlag)
00254     {
00255     case LOWER_ONLY:
00256       if(ParameterValue < LowerBound)
00257         {
00258           LogFileStars(); //pape explain this call later
00259           
00260           //More data is being written in the LogFile.
00261           LogFile << "             WARNING" << endl 
00262                   << "The integer parameter " 
00263                   << ParameterName << endl 
00264                   << "is not in the required range " 
00265                   << "[" << LowerBound << " , inf)" 
00266                   << endl;
00267           LogFileStars(); //pape explain this call later
00268         } // end if
00269       break;
00270       
00271     case UPPER_ONLY:
00272       if(ParameterValue > UpperBound)
00273         {
00274           LogFileStars(); //pape explain this call later
00275           
00276           //More data is being written in the LogFile.
00277           LogFile << "             WARNING" << endl 
00278                   << "The integer parameter " 
00279                   << ParameterName << endl 
00280                   << "is not in the required range " 
00281                   << "(-inf , " << UpperBound << "]" 
00282                   << endl;
00283 
00284           LogFileStars(); //pape explain this call later
00285         } // end if
00286       break;
00287 
00288     case LOWER_AND_UPPER:
00289       if(ParameterValue > UpperBound || ParameterValue < LowerBound)
00290         {
00291           LogFileStars(); //pape explain this call later
00292           
00293           //More data is being written in the LogFile.
00294           LogFile << "             WARNING" << endl 
00295                   << "The integer parameter " 
00296                   << ParameterName << endl 
00297                   << "is not in the required range " 
00298                   << "[" << LowerBound << " , " <<UpperBound << "]" 
00299                   << endl;
00300           
00301           LogFileStars(); //pape explain this call later
00302         } // end if
00303       
00304       break;
00305       
00306     // default case excutes in case of an invalid bound
00307     case NO_BOUNDS:
00308       break;
00309       
00310       
00311     default: 
00312       cerror("Invalid BoundsFlag Enumerator Choice");
00313       exit(1);
00314       
00315       
00316     } // end switch
00317   
00318   
00319   return ParameterValue;
00320   
00321 } // ### end ReadLongInt
00322 
00323 
00324 
00360 double ReadDouble(string ParameterName, string UnitsString,
00361             double LowerBound, double UpperBound,
00362             BoundsFlagEnumerator BoundsFlag, 
00363             InputParameterOptionsEnumerator InputParameterOption,
00364             double DefaultValue,
00365             ifstream * InFile)
00366 {
00367   
00368   int ParameterRead = 0;
00369   double ParameterValue = 0;
00370   string NameBuffer;
00371   
00372   // Appends the string ParameterName to the dollar sign to form 
00373   // a string that the begins with a dollar sign.
00374   string ParameterNameDollar = "$"+ParameterName;
00375 
00376   InFile->clear(); // Resets ifstream state to good
00377   
00378   // In order for an input operation to actually do something its
00379   // state must be "good". When the end of file is reached the 
00380   // state is set to "eof" which is not good! (This will have happened
00381   // if the ReadInt function has been previously called.)
00382   // The clear() function resets the state to "good"
00383 
00384   InFile->seekg(0); // Resets the file pointer to the start of the file.
00385   
00386   // Data is sequentially being read from the file. 
00387   // When the end of file has been reached, the implicit call to 
00388   // operator void* in the while structure returns '0' (normally 
00389   // operator void returns true), the file is called by the ifstream
00390   // destructor function.
00391   
00392   while (*InFile >> NameBuffer)
00393     {
00394       if (ParameterNameDollar==NameBuffer) 
00395         {
00396           // If the above condition is true, the value read from the 
00397           // file ater NameBuffer, is of type ParameterValue.
00398           *InFile >> ParameterValue; 
00399 
00400          // FIX: Check that have really read value in correctly!
00401 
00402          ParameterRead = 1;
00403      }  // end if   
00404       
00405     } // end while
00406   
00407   // The obove if block should be executed after every execution of the 
00408   // while statement; in other words, after every Name buffer, there should
00409   // be a ParameterValue. The following block is executed if the Parameter 
00410   // value is missing.
00411   
00412   if(!ParameterRead)
00413     {
00414       MissingParameter(ParameterName,InputParameterOption);
00415       ParameterValue =  DefaultValue;
00416     }
00417 
00418   LogFile << ParameterName << " = " << ParameterValue << " " 
00419           << UnitsString << endl;
00420   
00421   switch(BoundsFlag)
00422     {
00423     case LOWER_ONLY:
00424       if(ParameterValue < LowerBound)
00425         {
00426           LogFileStars();
00427           
00428           //More data is being written in the LogFile.
00429           LogFile << "             WARNING" << endl 
00430                   << "The integer parameter " 
00431                   << ParameterName << endl 
00432                   << "is not in the required range " 
00433                   << "[" << LowerBound << " , inf)" 
00434                   << endl;
00435           
00436           LogFileStars();
00437         } // end if
00438            break;
00439 
00440     case UPPER_ONLY:
00441       if(ParameterValue > UpperBound)
00442         {
00443           LogFileStars();
00444           
00445           LogFile << "             WARNING" << endl 
00446                   << "The integer parameter " 
00447                   << ParameterName << endl 
00448                   << "is not in the required range " 
00449                   << "(-inf , " << UpperBound << "]" 
00450                   << endl;
00451           
00452           LogFileStars();
00453         } // end if
00454       break;
00455       
00456     case LOWER_AND_UPPER:
00457       if(ParameterValue > UpperBound || ParameterValue < LowerBound)
00458         {
00459           LogFileStars();
00460           
00461           //More data is being written in the LogFile.
00462           LogFile << "             WARNING" << endl 
00463                   << "The integer parameter " 
00464                   << ParameterName << endl 
00465                   << "is not in the required range " 
00466                   << "[" << LowerBound << " , " <<UpperBound << "]" 
00467                   << endl;
00468           
00469           LogFileStars();
00470         } // end if
00471       break;
00472       
00473     // default case excutes in case of an invalid bound
00474     case NO_BOUNDS:
00475       break;
00476       
00477     default: 
00478              cerror("Invalid BoundsFlag Enumerator Choice");
00479              exit(1);
00480 
00481 
00482     } // end switch
00483 
00484 
00485   return ParameterValue;
00486 
00487 
00488 }  // ## end ReadDouble
00489 
00490 
00491 
00505 string ReadString(string ParameterName, 
00506                   InputParameterOptionsEnumerator InputParameterOption,
00507                   string DefaultValue,
00508                   ifstream * InFile)
00509 {
00510   int ParameterRead = 0;
00511   string ParameterValue ="";
00512   string NameBuffer;
00513   
00514   
00515   string ParameterNameDollar = "$"+ParameterName;
00516 
00517   InFile->clear(); // Resets ifstream state to good
00518   
00519   // In order for an input operation to actually do something its
00520   // state must be "good". When the end of file is reached the 
00521   // state is set to "eof" which is not good! (This will have happened
00522   // if a Read function has been previously called.)
00523   // The clear() function resets the state to "good"
00524 
00525 
00526   InFile->seekg(0); // Resets the file pointer to the start of the file.
00527 
00528   // Data is sequentially being read from the file. 
00529   // When the end of file has been reached, the implicit call to 
00530   // operator void* in the while structure returns '0' (normally 
00531   // operator void returns true), the file is called by the ifstream
00532   // destructor function.
00533   
00534   while (*InFile >> NameBuffer)
00535     {
00536       if (ParameterNameDollar==NameBuffer) 
00537         {
00538           // If the above condition is true, the value read from the 
00539           // file ater NameBuffer, is of type ParameterValue.
00540           *InFile >> ParameterValue; 
00541 
00542          // FIX: Check that have really read value in correctly!
00543 
00544          ParameterRead = 1;
00545      }  // end if
00546    
00547     } // end while
00548 
00549   // The obove if block should be executed after every execution of the 
00550   // while statement; in other words, after every Name buffer, there should
00551   // be a ParameterValue. The following block is executed if the Parameter 
00552   // value is missing.
00553 
00554   if(!ParameterRead)
00555     {
00556       // The MissingParameter is being called if ParameterValue is missing.
00557       MissingParameter(ParameterName,InputParameterOption);
00558       
00559       // ParameterValue is being set to a default value
00560       ParameterValue =  DefaultValue;
00561     }
00562   
00563   // determines whether the file was opened succesfully before attempting
00564   // to write data to the file.
00565   if(LogFile)
00566     LogFile << ParameterName << " = " << ParameterValue << " " << endl;
00567 
00568   // If the "if block" is not executed, the buffer is first flushed; data
00569   // is then written in the file and the buffer gets flushed twice
00570   else
00571     cout << endl 
00572          << ParameterName << " = " << ParameterValue << " " << endl 
00573          << endl;
00574             
00575   return ParameterValue;
00576   
00577 } // ## end ReadString
00578 
00579 // ##############################################################
00580 
00581 
00582 // ### Now follow version of ReadInt and ReadDouble without the 
00583 // ### defult value parameter
00584 
00597 int ReadInt(string ParameterName, string UnitsString,
00598             int LowerBound,int UpperBound,
00599             BoundsFlagEnumerator BoundsFlag, 
00600             InputParameterOptionsEnumerator InputParameterOption,
00601             ifstream * InFile)
00602 {
00603 
00604   int ParameterRead = 0;
00605   int ParameterValue = 0;
00606   string NameBuffer;
00607 
00608   string ParameterNameDollar = "$"+ParameterName;
00609 
00610   InFile->clear(); // Resets ifstream state to good
00611   
00612   // In order for an input operation to actually do something its
00613   // state must be "good". When the end of file is reached the 
00614   // state is set to "eof" which is not good! (This will have happened
00615   // if the ReadInt function has been previously called.)
00616   // The clear() function resets the state to "good"
00617 
00618 
00619   InFile->seekg(0); // Resets the file pointer to the start of the file.
00620 
00621 
00622   while (*InFile >> NameBuffer)
00623     {
00624     if (ParameterNameDollar==NameBuffer) 
00625      {
00626          *InFile >> ParameterValue; 
00627 
00628          // FIX: Check that have really read value in correctly!
00629 
00630          ParameterRead = 1;
00631      }  // end if   
00632       
00633     } // end while
00634 
00635 
00636   if(!ParameterRead)
00637     {
00638       MissingParameter(ParameterName,InputParameterOption);
00639       return 0;
00640     }
00641 
00642   LogFile << ParameterName << " = " << ParameterValue << " " 
00643           << UnitsString << endl;
00644 
00645   switch(BoundsFlag)
00646     {
00647     case LOWER_ONLY:
00648               if(ParameterValue < LowerBound)
00649                 {
00650                   LogFileStars();
00651                   LogFile << "             WARNING" << endl 
00652                           << "The integer parameter " 
00653                           << ParameterName << endl 
00654                           << "is not in the required range " 
00655                           << "[" << LowerBound << " , inf)" 
00656                           << endl;
00657                   LogFileStars();
00658                 } // end if
00659            break;
00660 
00661     case UPPER_ONLY:
00662            if(ParameterValue > UpperBound)
00663                 {
00664                   LogFileStars();
00665                   LogFile << "             WARNING" << endl 
00666                           << "The integer parameter " 
00667                           << ParameterName << endl 
00668                           << "is not in the required range " 
00669                           << "(-inf , " << UpperBound << "]" 
00670                           << endl;
00671                   LogFileStars();
00672                 } // end if
00673            
00674              break;
00675 
00676     case LOWER_AND_UPPER:
00677              if(ParameterValue > UpperBound || ParameterValue < LowerBound)
00678                 {
00679                   LogFileStars();
00680                   LogFile << "             WARNING" << endl 
00681                           << "The integer parameter " 
00682                           << ParameterName << endl 
00683                           << "is not in the required range " 
00684                           << "[" << LowerBound << " , " <<UpperBound << "]" 
00685                           << endl;
00686                   LogFileStars();
00687                 } // end if
00688 
00689             break;
00690 
00691     case NO_BOUNDS:
00692             break;
00693 
00694 
00695     default: 
00696              cerror("Invalid BoundsFlag Enumerator Choice");
00697              exit(1);
00698 
00699 
00700     } // end switch
00701 
00702 
00703   return ParameterValue;
00704 
00705 
00706 } // ## end ReadInt
00707 
00708 
00709 
00710 // #############################################################
00711 
00724 long ReadLongInt(string ParameterName, string UnitsString,
00725             long LowerBound, long UpperBound,
00726             BoundsFlagEnumerator BoundsFlag, 
00727             InputParameterOptionsEnumerator InputParameterOption,
00728             ifstream * InFile)
00729 {
00730 
00731   int ParameterRead = 0;
00732   long ParameterValue = 0;
00733   string NameBuffer;
00734 
00735   string ParameterNameDollar = "$"+ParameterName;
00736 
00737   InFile->clear(); // Resets ifstream state to good
00738   
00739   // In order for an input operation to actually do something its
00740   // state must be "good". When the end of file is reached the 
00741   // state is set to "eof" which is not good! (This will have happened
00742   // if the ReadInt function has been previously called.)
00743   // The clear() function resets the state to "good"
00744 
00745 
00746   InFile->seekg(0); // Resets the file pointer to the start of the file.
00747 
00748 
00749   while (*InFile >> NameBuffer)
00750     {
00751     if (ParameterNameDollar==NameBuffer) 
00752      {
00753          *InFile >> ParameterValue; 
00754 
00755          // FIX: Check that have really read value in correctly!
00756 
00757          ParameterRead = 1;
00758      }  // end if   
00759       
00760     } // end while
00761 
00762 
00763   if(!ParameterRead)
00764     {
00765       MissingParameter(ParameterName,InputParameterOption);
00766       return 0;
00767     }
00768 
00769   LogFile << ParameterName << " = " << ParameterValue << " " 
00770           << UnitsString << endl;
00771 
00772   switch(BoundsFlag)
00773     {
00774     case LOWER_ONLY:
00775               if(ParameterValue < LowerBound)
00776                 {
00777                   LogFileStars();
00778                   LogFile << "             WARNING" << endl 
00779                           << "The integer parameter " 
00780                           << ParameterName << endl 
00781                           << "is not in the required range " 
00782                           << "[" << LowerBound << " , inf)" 
00783                           << endl;
00784                   LogFileStars();
00785                 } // end if
00786            break;
00787 
00788     case UPPER_ONLY:
00789            if(ParameterValue > UpperBound)
00790                 {
00791                   LogFileStars();
00792                   LogFile << "             WARNING" << endl 
00793                           << "The integer parameter " 
00794                           << ParameterName << endl 
00795                           << "is not in the required range " 
00796                           << "(-inf , " << UpperBound << "]" 
00797                           << endl;
00798                   LogFileStars();
00799                 } // end if
00800            
00801              break;
00802 
00803     case LOWER_AND_UPPER:
00804              if(ParameterValue > UpperBound || ParameterValue < LowerBound)
00805                 {
00806                   LogFileStars();
00807                   LogFile << "             WARNING" << endl 
00808                           << "The integer parameter " 
00809                           << ParameterName << endl 
00810                           << "is not in the required range " 
00811                           << "[" << LowerBound << " , " <<UpperBound << "]" 
00812                           << endl;
00813                   LogFileStars();
00814                 } // end if
00815 
00816             break;
00817 
00818     case NO_BOUNDS:
00819             break;
00820 
00821 
00822     default: 
00823              cerror("Invalid BoundsFlag Enumerator Choice");
00824              exit(1);
00825 
00826 
00827     } // end switch
00828 
00829 
00830   return ParameterValue;
00831 
00832 } // ### end ReadLongInt
00833 
00834 // ##############################################################
00835 
00836 
00850 double ReadDouble(string ParameterName, string UnitsString,
00851             double LowerBound, double UpperBound,
00852             BoundsFlagEnumerator BoundsFlag, 
00853             InputParameterOptionsEnumerator InputParameterOption,
00854             ifstream * InFile)
00855 {
00856 
00857   int ParameterRead = 0;
00858   double ParameterValue = 0;
00859   string NameBuffer;
00860 
00861   string ParameterNameDollar = "$"+ParameterName;
00862 
00863   InFile->clear(); // Resets ifstream state to good
00864   
00865   // In order for an input operation to actually do something its
00866   // state must be "good". When the end of file is reached the 
00867   // state is set to "eof" which is not good! (This will have happened
00868   // if the ReadInt function has been previously called.)
00869   // The clear() function resets the state to "good"
00870 
00871 
00872   InFile->seekg(0); // Resets the file pointer to the start of the file.
00873 
00874 
00875   while (*InFile >> NameBuffer)
00876     {
00877     if (ParameterNameDollar==NameBuffer) 
00878      {
00879          *InFile >> ParameterValue; 
00880 
00881          // FIX: Check that have really read value in correctly!
00882 
00883          ParameterRead = 1;
00884      }  // end if   
00885       
00886     } // end while
00887 
00888 
00889   if(!ParameterRead)
00890     {
00891       MissingParameter(ParameterName,InputParameterOption);
00892       return 0;
00893     }
00894 
00895   LogFile << ParameterName << " = " << ParameterValue << " " 
00896           << UnitsString << endl;
00897 
00898   switch(BoundsFlag)
00899     {
00900     case LOWER_ONLY:
00901               if(ParameterValue < LowerBound)
00902                 {
00903                   LogFileStars();
00904                   LogFile << "             WARNING" << endl 
00905                           << "The integer parameter " 
00906                           << ParameterName << endl 
00907                           << "is not in the required range " 
00908                           << "[" << LowerBound << " , inf)" 
00909                           << endl;
00910                   LogFileStars();
00911                 } // end if
00912            break;
00913 
00914     case UPPER_ONLY:
00915 
00916              if(ParameterValue > UpperBound)
00917                 {
00918                   LogFileStars();
00919                   LogFile << "             WARNING" << endl 
00920                           << "The integer parameter " 
00921                           << ParameterName << endl 
00922                           << "is not in the required range " 
00923                           << "(-inf , " << UpperBound << "]" 
00924                           << endl;
00925                   LogFileStars();
00926                 } // end if
00927            
00928              break;
00929 
00930     case LOWER_AND_UPPER:
00931              if(ParameterValue > UpperBound || ParameterValue < LowerBound)
00932                 {
00933                   LogFileStars();
00934                   LogFile << "             WARNING" << endl 
00935                           << "The integer parameter " 
00936                           << ParameterName << endl 
00937                           << "is not in the required range " 
00938                           << "[" << LowerBound << " , " <<UpperBound << "]" 
00939                           << endl;
00940                   LogFileStars();
00941                 } // end if
00942 
00943             break;
00944 
00945     case NO_BOUNDS:
00946             break;
00947 
00948     default: 
00949              cerror("Invalid BoundsFlag Enumerator Choice");
00950              exit(1);
00951 
00952 
00953     } // end switch
00954 
00955 
00956   return ParameterValue;
00957 
00958 
00959 }  // ## end ReadDouble
00960 
00961 // ##############################################################
00962 
00976 string ReadString(string ParameterName, 
00977                   InputParameterOptionsEnumerator InputParameterOption,
00978                   ifstream * InFile)
00979 {
00980   int ParameterRead = 0;
00981   string ParameterValue ="";
00982   string NameBuffer;
00983 
00984   string ParameterNameDollar = "$"+ParameterName;
00985 
00986   InFile->clear(); // Resets ifstream state to good
00987   
00988   // In order for an input operation to actually do something its
00989   // state must be "good". When the end of file is reached the 
00990   // state is set to "eof" which is not good! (This will have happened
00991   // if a Read function has been previously called.)
00992   // The clear() function resets the state to "good"
00993 
00994 
00995   InFile->seekg(0); // Resets the file pointer to the start of the file.
00996 
00997 
00998   while (*InFile >> NameBuffer)
00999     {
01000     if (ParameterNameDollar==NameBuffer) 
01001      {
01002          *InFile >> ParameterValue; 
01003 
01004          // FIX: Check that have really read value in correctly!
01005 
01006          ParameterRead = 1;
01007      }  // end if   
01008       
01009     } // end while
01010 
01011 
01012   if(!ParameterRead)
01013     {
01014       MissingParameter(ParameterName,InputParameterOption);
01015       return " ";
01016     }
01017   else
01018     {
01019       if(LogFile)
01020         LogFile << ParameterName << " = " << ParameterValue << " " << endl;
01021       else
01022         cout << endl 
01023              << ParameterName << " = " << ParameterValue << " " << endl 
01024              << endl;
01025     }
01026 
01027   return ParameterValue;
01028 
01029 } // ## end ReadString
01030 
01031 // ##############################################################
01032 
01039 void MissingParameter(string ParameterName,
01040                       InputParameterOptionsEnumerator InputParameterOption)
01041 {
01042   // determines the action to take based on the nature of the missing 
01043   // parameter.
01044   switch(InputParameterOption)
01045     {
01046       
01047     // No warning message in this case
01048     case OPTIONAL_NO_WARNING:
01049       break;
01050       
01051     // Eventhough the parameter is optional, a warning message is written
01052     // to the file.
01053     case OPTIONAL_WARNING:
01054         if(LogFile)
01055           {
01056             LogFileStars(); //pape explain this line
01057             LogFile << "           WARNING" << endl 
01058                     << ParameterName << " not found!!" << endl;
01059             LogFileStars(); //pape explain this line
01060           }
01061         else
01062           {
01063            cout    << "           WARNING" << endl 
01064                    << ParameterName << " not found!!" << endl;
01065           }
01066         
01067         break;
01068         
01069     // A warning message is being sent to the file and directly outputed
01070     // to the screen via the unbuffered error output stream object "cerr <<"
01071     // because the missing parameter is mandatory 
01072     case MANDATORY:
01073       
01074       // determines whether the file was opened succesfully before attempting
01075       // to write data to the file. If true is returned, a warnig message is
01076       // directly written to the file.
01077       if(LogFile)
01078           {
01079             LogFileStars();
01080             LogFile << "             WARNING" << endl 
01081                     << ParameterName << " not found!!" << endl
01082                     << "             ABORTING NOW" << endl;
01083             LogFileStars();
01084           }
01085       
01086       // The same warning message above is sent to the screen
01087       cerr << "             WARNING" << endl 
01088            << ParameterName << " not found!!" << endl
01089            << "             ABORTING NOW" << endl;
01090       
01091       // The program is exited at this point since the missing parameter 
01092       // is mandatory.
01093       exit(1);
01094       break;
01095       
01096       
01097     default:
01098       cerr << "Switch option error in MissingParameter call for"
01099            <<  ParameterName << endl;
01100       
01101       // The program is exited at this point since the missing parameter 
01102       // is mandatory.
01103       exit(1);
01104       
01105     } // ## end switch
01106   
01107 }// ## end MissingParameter
01108 
01109 
01110 // ###############################################################
01111 
01112 
01126 int ReadInt(string ParameterName, string UnitsString,
01127             int LowerBound,int UpperBound,
01128             BoundsFlagEnumerator BoundsFlag, ifstream * InFile)
01129 {
01130 
01131   int ParameterRead = 0;
01132   int ParameterValue;
01133   string NameBuffer;
01134 
01135   string ParameterNameDollar = "$"+ParameterName;
01136 
01137   InFile->clear(); // Resets ifstream state to good
01138   
01139   // In order for an input operation to actually do something its
01140   // state must be "good". When the end of file is reached the 
01141   // state is set to "eof" which is not good! (This will have happened
01142   // if the ReadInt function has been previously called.)
01143   // The clear() function resets the state to "good"
01144 
01145 
01146   InFile->seekg(0); // Resets the file pointer to the start of the file.
01147 
01148 
01149   while (*InFile >> NameBuffer)
01150     {
01151     if (ParameterNameDollar==NameBuffer) 
01152      {
01153          *InFile >> ParameterValue; 
01154 
01155          // FIX: Check that have really read value in correctly!
01156 
01157          ParameterRead = 1;
01158      }  // end if   
01159       
01160     } // end while
01161 
01162 
01163   if(!ParameterRead)
01164     {
01165        LogFileStars();
01166        LogFile << "             WARNING" << endl 
01167                << ParameterName << " not found!!" << endl
01168                << "             ABORTING NOW" << endl;
01169        LogFileStars();
01170        exit(1);
01171     }
01172   
01173 
01174   LogFile << ParameterName << " = " << ParameterValue << " " 
01175           << UnitsString << endl;
01176 
01177   switch(BoundsFlag)
01178     {
01179     case LOWER_ONLY:
01180               if(ParameterValue < LowerBound)
01181                 {
01182                   LogFileStars();
01183                   LogFile << "             WARNING" << endl 
01184                           << "The integer parameter " 
01185                           << ParameterName << endl 
01186                           << "is not in the required range " 
01187                           << "[" << LowerBound << " , inf)" 
01188                           << endl;
01189                   LogFileStars();
01190                 } // end if
01191            break;
01192 
01193     case UPPER_ONLY:
01194            if(ParameterValue > UpperBound)
01195                 {
01196                   LogFileStars();
01197                   LogFile << "             WARNING" << endl 
01198                           << "The integer parameter " 
01199                           << ParameterName << endl 
01200                           << "is not in the required range " 
01201                           << "(-inf , " << UpperBound << "]" 
01202                           << endl;
01203                   LogFileStars();
01204                 } // end if
01205            
01206              break;
01207 
01208     case LOWER_AND_UPPER:
01209              if(ParameterValue > UpperBound || ParameterValue < LowerBound)
01210                 {
01211                   LogFileStars();
01212                   LogFile << "             WARNING" << endl 
01213                           << "The integer parameter " 
01214                           << ParameterName << endl 
01215                           << "is not in the required range " 
01216                           << "[" << LowerBound << " , " <<UpperBound << "]" 
01217                           << endl;
01218                   LogFileStars();
01219                 } // end if
01220 
01221             break;
01222 
01223     case NO_BOUNDS:
01224             break;
01225 
01226 
01227     default: 
01228              cerror("Invalid BoundsFlag Enumerator Choice");
01229              exit(1);
01230 
01231 
01232     } // end switch
01233 
01234 
01235   return ParameterValue;
01236 
01237 } // ### end ReadInt
01238 
01239 // #########################################################
01240 
01241 
01255 long ReadLongInt(string ParameterName, string UnitsString,
01256             long LowerBound, long UpperBound,
01257             BoundsFlagEnumerator BoundsFlag, ifstream * InFile)
01258 {
01259 
01260   int ParameterRead = 0;
01261   long ParameterValue;
01262   string NameBuffer;
01263 
01264   string ParameterNameDollar = "$"+ParameterName;
01265 
01266   InFile->clear(); // Resets ifstream state to good
01267   
01268   // In order for an input operation to actually do something its
01269   // state must be "good". When the end of file is reached the 
01270   // state is set to "eof" which is not good! (This will have happened
01271   // if the ReadInt function has been previously called.)
01272   // The clear() function resets the state to "good"
01273 
01274 
01275   InFile->seekg(0); // Resets the file pointer to the start of the file.
01276 
01277 
01278   while (*InFile >> NameBuffer)
01279     {
01280     if (ParameterNameDollar==NameBuffer) 
01281      {
01282          *InFile >> ParameterValue; 
01283 
01284          // FIX: Check that have really read value in correctly!
01285 
01286          ParameterRead = 1;
01287      }  // end if   
01288       
01289     } // end while
01290 
01291 
01292   if(!ParameterRead)
01293     {
01294        LogFileStars();
01295        LogFile << "             WARNING" << endl 
01296                << ParameterName << " not found!!" << endl
01297                << "             ABORTING NOW" << endl;
01298        LogFileStars();
01299        exit(1);
01300     }
01301   
01302 
01303   LogFile << ParameterName << " = " << ParameterValue << " " 
01304           << UnitsString << endl;
01305 
01306   switch(BoundsFlag)
01307     {
01308     case LOWER_ONLY:
01309               if(ParameterValue < LowerBound)
01310                 {
01311                   LogFileStars();
01312                   LogFile << "             WARNING" << endl 
01313                           << "The integer parameter " 
01314                           << ParameterName << endl 
01315                           << "is not in the required range " 
01316                           << "[" << LowerBound << " , inf)" 
01317                           << endl;
01318                   LogFileStars();
01319                 } // end if
01320            break;
01321 
01322     case UPPER_ONLY:
01323            if(ParameterValue > UpperBound)
01324                 {
01325                   LogFileStars();
01326                   LogFile << "             WARNING" << endl 
01327                           << "The integer parameter " 
01328                           << ParameterName << endl 
01329                           << "is not in the required range " 
01330                           << "(-inf , " << UpperBound << "]" 
01331                           << endl;
01332                   LogFileStars();
01333                 } // end if
01334            
01335              break;
01336 
01337     case LOWER_AND_UPPER:
01338              if(ParameterValue > UpperBound || ParameterValue < LowerBound)
01339                 {
01340                   LogFileStars();
01341                   LogFile << "             WARNING" << endl 
01342                           << "The integer parameter " 
01343                           << ParameterName << endl 
01344                           << "is not in the required range " 
01345                           << "[" << LowerBound << " , " <<UpperBound << "]" 
01346                           << endl;
01347                   LogFileStars();
01348                 } // end if
01349 
01350             break;
01351 
01352     case NO_BOUNDS:
01353             break;
01354 
01355 
01356     default: 
01357              cerror("Invalid BoundsFlag Enumerator Choice");
01358              exit(1);
01359 
01360 
01361     } // end switch
01362 
01363 
01364   return ParameterValue;
01365 
01366 } // ### end ReadLongInt
01367 
01368 // #########################################################
01369 
01370 
01384 double ReadDouble(string ParameterName, string UnitsString,
01385             double LowerBound, double UpperBound,
01386             BoundsFlagEnumerator BoundsFlag, ifstream * InFile)
01387 {
01388 
01389   int ParameterRead = 0;
01390   double ParameterValue = 0;
01391   string NameBuffer;
01392 
01393   string ParameterNameDollar = "$"+ParameterName;
01394 
01395   InFile->clear(); // Resets ifstream state to good
01396   
01397   // In order for an input operation to actually do something its
01398   // state must be "good". When the end of file is reached the 
01399   // state is set to "eof" which is not good! (This will have happened
01400   // if the ReadInt function has been previously called.)
01401   // The clear() function resets the state to "good"
01402 
01403 
01404   InFile->seekg(0); // Resets the file pointer to the start of the file.
01405 
01406 
01407   while (*InFile >> NameBuffer)
01408     {
01409     if (ParameterNameDollar==NameBuffer) 
01410      {
01411          *InFile >> ParameterValue; 
01412 
01413          // FIX: Check that have really read value in correctly!
01414 
01415          ParameterRead = 1;
01416      }  // end if   
01417       
01418     } // end while
01419 
01420 
01421   if(!ParameterRead)
01422     {
01423        LogFileStars();
01424        LogFile << "             WARNING" << endl 
01425                << ParameterName << " not found!!" << endl;
01426        LogFileStars();
01427       
01428     }
01429   
01430 
01431   LogFile << ParameterName << " = " << ParameterValue << " " 
01432           << UnitsString << endl;
01433 
01434   switch(BoundsFlag)
01435     {
01436     case LOWER_ONLY:
01437               if(ParameterValue < LowerBound)
01438                 {
01439                   LogFileStars();
01440                   LogFile << "             WARNING" << endl 
01441                           << "The integer parameter " 
01442                           << ParameterName << endl 
01443                           << "is not in the required range " 
01444                           << "[" << LowerBound << " , inf)" 
01445                           << endl;
01446                   LogFileStars();
01447                 } // end if
01448            break;
01449 
01450     case UPPER_ONLY:
01451 
01452              if(ParameterValue > UpperBound)
01453                 {
01454                   LogFileStars();
01455                   LogFile << "             WARNING" << endl 
01456                           << "The integer parameter " 
01457                           << ParameterName << endl 
01458                           << "is not in the required range " 
01459                           << "(-inf , " << UpperBound << "]" 
01460                           << endl;
01461                   LogFileStars();
01462                 } // end if
01463            
01464              break;
01465 
01466     case LOWER_AND_UPPER:
01467              if(ParameterValue > UpperBound || ParameterValue < LowerBound)
01468                 {
01469                   LogFileStars();
01470                   LogFile << "             WARNING" << endl 
01471                           << "The integer parameter " 
01472                           << ParameterName << endl 
01473                           << "is not in the required range " 
01474                           << "[" << LowerBound << " , " <<UpperBound << "]" 
01475                           << endl;
01476                   LogFileStars();
01477                 } // end if
01478 
01479             break;
01480 
01481     case NO_BOUNDS:
01482             break;
01483 
01484     default: 
01485              cerror("Invalid BoundsFlag Enumerator Choice");
01486              exit(1);
01487 
01488 
01489     } // end switch
01490 
01491 
01492   return ParameterValue;
01493 
01494 } // ### end ReadDouble
01495 
01496 // #######################################################
01497 
01511 string ReadString(string ParameterName, ifstream * InFile) 
01512 {
01513 
01514   int ParameterRead = 0;
01515   string ParameterValue;
01516   string NameBuffer;
01517 
01518   string ParameterNameDollar = "$"+ParameterName;
01519 
01520   InFile->clear(); // Resets ifstream state to good
01521   
01522   // In order for an input operation to actually do something its
01523   // state must be "good". When the end of file is reached the 
01524   // state is set to "eof" which is not good! (This will have happened
01525   // if a Read function has been previously called.)
01526   // The clear() function resets the state to "good"
01527 
01528 
01529   InFile->seekg(0); // Resets the file pointer to the start of the file.
01530 
01531 
01532   while (*InFile >> NameBuffer)
01533     {
01534     if (ParameterNameDollar==NameBuffer) 
01535      {
01536          *InFile >> ParameterValue; 
01537 
01538          // FIX: Check that have really read value in correctly!
01539 
01540          ParameterRead = 1;
01541      }  // end if   
01542       
01543     } // end while
01544 
01545 
01546   if(!ParameterRead)
01547     {
01548       cerr << "ERROR in ReadString." << endl 
01549            << "Parameter " << ParameterName    
01550            << " not found." << endl << "ABORTING NOW" << endl;
01551 
01552       exit(1);
01553 
01554     }
01555   else
01556     {
01557       if(LogFile)
01558         LogFile << ParameterName << " = " << ParameterValue << " " << endl;
01559       else
01560         cout << endl 
01561              << ParameterName << " = " << ParameterValue << " " << endl 
01562              << endl;
01563     }
01564 
01565   return ParameterValue;
01566 
01567 } // end ReadString();
01568 
01569 
01574 void cerror(char * msg) {cout << msg << endl << flush;}
01575 
01581 void LogFileSeparator()
01582 {
01583 
01584   // The buffer is first flushed twice then a line of pound signs is
01585   // written into the file and at last, the buffer is flushed twice.
01586   LogFile << endl << endl<<
01587           "#########################################" << endl << endl;
01588 }
01589 
01590 
01591 void LogFileStars()
01592 {
01593   LogFile << endl << "**************************************"
01594           <<endl << endl;
01595 }
01596 
01597 
01598 
01599 void LogFileAbortWithErrorMsg(string ErrorMsg)
01600 { 
01601   // Calls the log file seperator to seperate what was last written into 
01602   // the file from the error message that will be written in the file
01603   LogFileSeparator();
01604   
01605   // Writes a set of data in the file and flush the buffer
01606   LogFile << "Error:" << endl << ErrorMsg << endl;
01607 
01608   //## I should include the name of the log file here, if I can
01609   cout << "Error: See *.log for details on the error." << endl;
01610   exit(1);
01611 }
01612 
01613 
01614 string WriteTypeSimulation(typeSimulation TypeSimulation)
01615 {
01616   // checks whether scalar simulation of a vector simulation should be run
01617   switch(TypeSimulation)
01618     {
01619      
01620     case SCALAR:
01621       
01622      return "SCALAR";
01623      break;
01624      
01625     case  VECTOR:
01626       return "VECTOR";
01627       break;
01628       
01629     // Terminates the program after displaying an error message on the
01630     // screen 
01631     default:
01632       cerr << "ERROR: Invalid choice of TypeSimulation" << endl;
01633       cerr << "ABORTING NOW!!" << endl;
01634       
01635       // Note that the error output stream object "cerr <<" is choosen to
01636       // display the error message because it is unbuffered. in other words,
01637       // the error message automatically appears to screen without waiting 
01638       // for the current buffer to be flushed
01639       
01640      exit(1);
01641      
01642    } // end switch 
01643  
01644 } // ## end WriteTypeSimulation

Generated at Mon Jun 9 20:08:10 2003 for OCS by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000