Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

real_interp.h

Go to the documentation of this file.
00001 // SuperMix version 1.0  C++ source file
00002 //
00003 // Copyright (c) 1999 California Institute of Technology.
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms for noncommercial
00007 // purposes are permitted provided that the above copyright notice and
00008 // this paragraph are duplicated in all such forms and that any
00009 // documentation and other materials related to such distribution and
00010 // use acknowledge that the software was developed by California
00011 // Institute of Technology. Redistribution and/or use in source or
00012 // binary forms is not permitted for any commercial purpose. Use of
00013 // this software does not include a permitted use of the Institute's
00014 // name or trademark for any purpose.
00015 //
00016 // DISCLAIMER:
00017 // THIS SOFTWARE AND/OR RELATED MATERIALS ARE PROVIDED "AS-IS" WITHOUT
00018 // WARRANTY OF ANY KIND INCLUDING ANY WARRANTIES OF PERFORMANCE OR
00019 // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE OR PURPOSE (AS SET
00020 // FORTH IN UCC 23212-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
00021 // LICENSED PRODUCT, HOWEVER USED.  IN NO EVENT SHALL CALTECH/JPL BE
00022 // LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING BUT NOT LIMITED TO
00023 // INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING ECONOMIC
00024 // DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF
00025 // WHETHER CALTECH/JPL SHALL BE ADVISED, HAVE REASON TO KNOW, OR IN
00026 // FACT SHALL KNOW OF THE POSSIBILITY.  THE USER BEARS ALL RISK
00027 // RELATING TO QUALITY AND PERFORMANCE OF THE SOFTWARE AND/OR RELATED
00028 // MATERIALS.
00029 //
00030 // ********************************************************************
00031 // real_interp.h
00032 //
00033 // The real_interp class is an abstract real parameter which gets its value
00034 // by interpolating into a table. The table may be supplied at
00035 // construction, from either an external file, a datafile object or a
00036 // real_matrix object. The independent variable used as an index for the
00037 // interpolation comes from an abstract real parameter, which may be
00038 // supplied at construction.
00039 //
00040 // Since real_interp is an interpolator<double>, the member functions of
00041 // that class are available for real_interp, such as spline() (the default)
00042 // and linear(), etc.
00043 //
00044 // J. Zmuidzinas  November 3, 1997
00045 //
00046 // 10/1/99:  More enhancements
00047 // 7/6/99:   Now derived from interpolator<double>; using real_matrix;
00048 //           added new constructor and table().
00049 // 4/20/99:  Modified to use interpolator<double>
00050 // 2/12/98:  Added constructor from real_table
00051 //
00052 // ********************************************************************
00053 
00054 #ifndef REAL_INTERP_H
00055 #define REAL_INTERP_H
00056 
00057 #include "parameter/abstract_real_parameter.h"
00058 #include "interpolate.h"
00059 #include "datafile.h"
00060 
00061 class real_interp : public abstract_real_parameter, public interpolator<double>
00062 {
00063 public:
00064 
00065   // The option enumeration definitions for use in the constructors:
00066 
00067   typedef enum { STD, PHASE } phase_type;      // y (dependent variable) data type flag.
00068 
00069   // STD   : The default. Don't do anything special with the y values.
00070   //
00071   // PHASE : Interpret the y values as phase data IN RADIANS, which may wrap
00072   //         around discontinuously after every 2 Pi of phase difference.
00073   //         Correctly interpolates across such phase discontinuities using get().
00074 
00075 
00076   // ----------------------------------------------
00077   // Constructing the real_interp object:
00078 
00079   // In each of the following constructors, the argument xp refers to a real
00080   // parameter sort of object which will be used to determine the x values used during
00081   // interpolations when the real_interp object is asked for its value
00082   // (see get(), below).
00083 
00084   // Also note that the (x,y) data supplied at construction need not be sorted, but all
00085   // x values must be unique.
00086 
00087 
00088   // ----------------------------------------------
00089   // Constructing, but supplying no data (add data using file() or table()):
00090 
00091   explicit
00092   real_interp(const abstract_real_parameter &xp,  // The independent (x) variable object
00093               phase_type ptype = STD              // Will the y data be phase data?
00094               ) ;
00095 
00096   // xp refers to a real parameter sort of object which will be used to determine the x
00097   // value used to perform an interpolation when the real_interp object is asked for its
00098   // value (see get(), below).
00099 
00100   explicit
00101   real_interp(phase_type ptype = STD) ;           // Pick parameter and get data later... 
00102 
00103 
00104   // ----------------------------------------------
00105   // Constructing, taking data directly from a file or stream:
00106 
00107   real_interp(
00108               const abstract_real_parameter &xp, // The independent (x) variable object
00109               const char * const name,           // The name of the file to open
00110               double x_unit = 1.0,               // Units for the x value
00111               double y_unit = 1.0,               // Units for the y value
00112               int ycol = 1,                      // Which complex number on line to use 
00113               bool ignore_ws = true,             // Should all blank lines be ignored?
00114               phase_type ptype = STD             // Is the y data phase data?
00115               );
00116 
00117   // The above version opens and reads from the named file. Using the functionality of
00118   // data_parser in io.h, it always skips initial blank lines and comments in the
00119   // file. If ignore_ws is set to false, then any further blank or comment lines
00120   // once data starts being read terminates the input. Otherwise the default is to
00121   // read the entire file. ycol tells which number entry should be read in
00122   // each line; don't count the 1st column, which contains the x value (a double).
00123   // x and y values are scaled (multiplied) by x_unit and y_unit, respectively.
00124 
00125   // The following constructor is like the above, except it reads from a supplied input
00126   // stream. It starts from the current stream location and then skips any initial
00127   // blank or comment lines: 
00128 
00129   real_interp(
00130               const abstract_real_parameter &xp, // The independent (x) variable object
00131               istream & s,                       // The input stream
00132               double x_unit = 1.0,               // Units for the x value
00133               double y_unit = 1.0,               // Units for the y value
00134               int ycol = 1,                      // Which complex number on line to use 
00135               bool ignore_ws = true,             // Should all blank lines be ignored?
00136               phase_type ptype = STD             // Is the y data phase data?
00137               );
00138 
00139 
00140   // ----------------------------------------------
00141   // Constructing with data taken from existing data table variables: 
00142 
00143   // Constructing from a real_matrix object:
00144 
00145   real_interp(const real_matrix &rt,              // The real_matrix with the data points 
00146               int xrow, int yrow,                 // Row references into the real_matrix 
00147               const abstract_real_parameter &xp,  // The independent (x) variable object 
00148               phase_type ptype = STD              // Is the y data phase data?
00149               ) ;
00150 
00151   // The x and y row numbers, xrow and yrow, refer to LEFT INDEX values in the 
00152   // real_matrix. They correspond to the FIRST INDEX in a real_matrix::read(i,j) function
00153   // call.
00154 
00155 
00156   // Constructing from a datafile object:
00157 
00158   real_interp(const datafile &df,                 // The datafile with the data points
00159               int xcol, int ycol,                 // Column references into the datafile
00160               const abstract_real_parameter &xp,  // The independent (x) variable object
00161               phase_type ptype = STD              // Is the y data phase data?
00162               ) ;
00163 
00164   // The x and y column numbers, xcol and ycol, refer to the actual columns in the
00165   // ASCII file on the disk from which the datafile was constructed. They correspond
00166   // to the FIRST INDEX in a datafile::read(i,j) function call. The data table is read
00167   // only once, at construction, so it may refer to a temporary object. For example:
00168   //
00169   //   real_interp R(datafile("my_data"),1,2,device::f);
00170   //
00171   // reads the data from "my_data" into a temporary datafile object, uses it to build
00172   // the interpolation tables within R, and then discards the datafile object. The first
00173   // column in the file "my_data" supplies the x (independent) values, the second column
00174   // the y (dependent) values. The parameter device::f will be the independent variable.
00175 
00176 
00177   // ----------------------------------------------
00178   // Supplying the data or x parameter following construction:
00179 
00180   // parameter():
00181 
00182   real_interp & parameter(const abstract_real_parameter &xp)
00183     { xparam = &xp ; return *this ; }
00184 
00185 
00186   // file():
00187 
00188   real_interp & file(
00189               const char * const name,  // The name of the file to open
00190               double x_unit = 1.0,      // Units for the x value
00191               double y_unit = 1.0,      // Units for the y value
00192               int ycol = 1,             // Which y value on line to use 
00193               bool ignore_ws = true,    // Should all blank lines be ignored?
00194               phase_type ptype = STD    // Is the y data phase data?
00195               );
00196 
00197   real_interp & file(
00198               istream & s,              // The input stream
00199               double x_unit = 1.0,      // Units for the x value
00200               double y_unit = 1.0,      // Units for the y value
00201               int ycol = 1,             // Which y value on line to use 
00202               bool ignore_ws = true,    // Should all blank lines be ignored?
00203               phase_type ptype = STD    // Is the y data phase data?
00204               );
00205 
00206 
00207   // table():
00208   
00209   real_interp & table(
00210               const real_matrix &rt,              // The real_matrix with the data points 
00211               int xrow, int yrow,                 // Row references into the real_matrix 
00212               phase_type ptype = STD              // Is the y data phase data?
00213               )
00214     {  phase = ptype ; construct(rt, xrow, yrow) ; return *this ; }
00215 
00216   real_interp & table(
00217               const datafile &df,                 // The datafile with the data points
00218               int xcol, int ycol,                 // Column references into the datafile
00219               phase_type ptype = STD              // Is the y data phase data?
00220               )
00221     {  phase = ptype ; construct(*(df.table()), xcol, ycol) ; return *this ; }
00222 
00223 
00224   // ----------------------------------------------
00225   // Return an interpolated value:
00226 
00227   double get() const ;  // Returns a y(x) value obtained by interpolation, using the current
00228                         // value of the abstract_real_parameter supplied during construction
00229                         // as the independent (x) value into the interpolator.
00230 
00231   // get() implements the abstract interface declaration in the abstract_real_parameter
00232   // base class from which real_interp is derived.
00233 
00234 
00235 private:
00236   const abstract_real_parameter *xparam ;  // this parameter gives the x value
00237   phase_type phase ;
00238   double phase_adjust(double phase) const; // bring phase into -Pi, Pi range
00239   void construct(const real_matrix &rt, int xrow, int yrow) ;
00240 
00241 };
00242 
00243 #endif /* REAL_INTERP_H */
00244 
00245 
00246 
00247 
00248 
00249 
00250 
00251 
00252 
00253 

Please direct comments and corrections to supermix@submm.caltech.edu
Go to the supermix home page
Generated by doxygen1.2.7