Changeset 3874 in Sophya for trunk/SophyaLib


Ignore:
Timestamp:
Sep 7, 2010, 7:48:49 PM (15 years ago)
Author:
ansari
Message:

Ajout gestion lignes commentaires ds les fichiers input de SLinInterp1D, Reza 07/09/2010

Location:
trunk/SophyaLib/NTools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/NTools/slininterp.cc

    r3869 r3874  
    175175
    176176
    177 /* --Methode-- */
    178 size_t SLinInterp1D::ReadYFromFile(string const& filename, double xmin, double xmax)
     177/*!
     178  \brief Read  Y values from the file \b filename
     179
     180  Read Y values ( one/line) for regularly spaced X's from file \b filename and call
     181  DefinePoints(xmin, xmax, yreg). Return the number of Y values read.
     182  \param filename : input file name
     183  \param xmin,xamx : X range limits
     184  \param clm : comment character, lines starting with \b clm are ignored
     185*/
     186size_t SLinInterp1D::ReadYFromFile(string const& filename, double xmin, double xmax, char clm)
    179187{
    180188  ifstream inputFile;
     
    192200  size_t cnt=0;
    193201  double cola;
     202  string eline;
    194203  while(!inputFile.eof())  {
    195204    inputFile.clear();
     205    if (inputFile.peek() == (int)clm)  {  // skip comment lines
     206      getline(inputFile, eline);
     207      continue;
     208    }
    196209    inputFile >> cola;
    197210    if ( (!inputFile.good()) || inputFile.eof())   break;
     211    inputFile.ignore(1024,'\n');  // make sure we go to the next line
    198212    //cout << cola<< "    "<<colb<<endl;
    199213    ysv.push_back(cola);
     
    206220}
    207221
    208 /* --Methode-- */
    209 size_t SLinInterp1D::ReadXYFromFile(string const& filename, double xmin, double xmax, size_t npt)
     222/*!
     223  \brief Read pairs of  ( X Y ) values from file \b filename
     224
     225  Read pairs of (X Y) values, one pair / line from the specified file and call DefinePoints(xs, ys ...).
     226  One pair of space or tab separated numbers on each line. Return the number of Y values read.
     227  \param filename : input file name
     228  \param xmin,xamx : X range limits. use the X limits from the file if xmax<xmin
     229  \param npt : number of points for regularly spaced interpolation points
     230  \param clm : comment character, lines starting with \b clm are ignored
     231*/
     232size_t SLinInterp1D::ReadXYFromFile(string const& filename, double xmin, double xmax, size_t npt, char clm)
    210233{
    211234  ifstream inputFile;
     
    223246  size_t cnt=0;
    224247  double cola, colb;
     248  string eline;
    225249  while(!inputFile.eof())  { 
    226250    inputFile.clear();
     251    if (inputFile.peek() == (int)clm)  {  // skip comment lines
     252      getline(inputFile, eline);
     253      continue;
     254    }
    227255    inputFile >> cola >> colb;
    228256    if ( (!inputFile.good()) || inputFile.eof())   break;
    229     // cout << " DEBUG - cnt=" << cnt << " x=" << cola << "  y= "<<colb<<endl;
     257    inputFile.ignore(1024,'\n');  // make sure we go to the next line
     258    //    cout << " DEBUG-GCount " << inputFile.gcount() << endl;
     259    //    cout << " DEBUG - cnt=" << cnt << " x=" << cola << "  y= "<<colb<<endl;
    230260    xsv.push_back(cola);
    231261    ysv.push_back(colb);
  • trunk/SophyaLib/NTools/slininterp.h

    r3851 r3874  
    5555  void DefinePoints(vector<double>& xs, vector<double>& ys, double xmin=1., double xmax=-1., size_t npt=0);
    5656
    57   //! Read  Y's  ( one  / line) for regularly spaced X's from file and call DefinePoints(xmin, xmax, yreg)
    58   size_t ReadYFromFile(string const& filename, double xmin, double xmax);
    59   //! Read pairs of X Y ( one pair / line) from file and call DefinePoints(xs, ys ...)
    60   size_t ReadXYFromFile(string const& filename, double xmin=1., double xmax=-1., size_t npt=0);
     57  // Read  Y's (one/line) for regularly spaced X's from file and call DefinePoints(xmin, xmax, yreg)
     58  size_t ReadYFromFile(string const& filename, double xmin, double xmax, char clm='#');
     59  // Read pairs of X Y (one pair/line) from file and call DefinePoints(xs, ys ...)
     60  size_t ReadXYFromFile(string const& filename, double xmin=1., double xmax=-1., size_t npt=0, char clm='#');
    6161 
    6262  vector<double>& GetVX()  { return xs_; }
Note: See TracChangeset for help on using the changeset viewer.