src/GamIO/Gascii.cc
// ----------------------------------------------------------------------------
//                    I/O To Obtain Doubles From An ASCII File
// ----------------------------------------------------------------------------
I/O To Obtain Doubles From An ASCII File
I / O To Obtain Doubles From An ASCII File
double* GetDoubles(const string& filename, int& N)
  {
  int nlines = LineCount(filename);     
  double *Dvect = NULL;                 
  Dvect = new double[nlines];           
  ifstream inp;                         
  inp.open(filename.c_str());           
  int line=0;
  string input;                         
  string datas;                         
  while(Greadline(inp, input))          
    {
    datas = cutDouble(input);           
    Dvect[line] = atof(datas.c_str());  
    line++;                             
    }
  N = nlines;
  return Dvect;
  }
double * GetDoubles ( const string & filename , int & N ) { int nlines = LineCount ( filename ) ; double * Dvect = NULL ; Dvect = new double [ nlines ] ; ifstream inp ; inp . open ( filename . c_str ( ) ) ; int line = 0 ; string input ; string datas ; while ( Greadline ( inp , input ) ) { datas = cutDouble ( input ) ; Dvect [ line ] = atof ( datas . c_str ( ) ) ; line ++ ; } N = nlines ; return Dvect ; }
I/O To Obtain Doubles From An ASCII File
I / O To Obtain Doubles From An ASCII File
// Input        filename: ASCII input file name // Return       Dvect   : A double vector is filled with values //                        found in the file "filename" // Note                 : Assumes file contains 1 value per line // Line count // Double vector, 1 value per line // Allocate double vector space // Input stream  lines = 0;                            // Reset line count // Reopen the file // String for a whole line // String for read data // Loop file, read lines // Store the value in vector // Convert from string to float // Increment line count