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

complex_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 // complex_interp.h
00032 //
00033 // The complex_interp class is an abstract complex parameter which gets its
00034 // value by interpolating into a table. The table may be supplied at
00035 // construction, from either an external file, a complex_matrix, a datafile
00036 // object or a real_matrix object. The independent variable used as an index
00037 // for the interpolation comes from an abstract real parameter, which may be
00038 // supplied at construction.
00039 //
00040 // Since complex_interp is an interpolator<complex>, the member functions of
00041 // that class are available, such as spline() (the default), linear(), etc.
00042 //
00043 // J. Zmuidzinas  November 3, 1997
00044 //
00045 // 10/1/99:  More enhancements
00046 // 7/6/99:   Huge modifications to interface and implementation
00047 // 2/12/98:  Added constructor from a real_table (JZ)
00048 //
00049 // ********************************************************************
00050 
00051 #ifndef COMPLEX_INTERP_H
00052 #define COMPLEX_INTERP_H 1
00053 
00054 class istream;
00055 
00056 #include "parameter/abstract_complex_parameter.h"
00057 #include "parameter/abstract_real_parameter.h"
00058 #include "interpolate.h"
00059 #include "datafile.h"
00060 
00061 class complex_interp : public abstract_complex_parameter, public interpolator<complex>
00062 {
00063 public:
00064 
00065   // ----------------------------------------------
00066   // Constructing the complex_interp object:
00067 
00068   // In each of the following constructors, the argument xp refers to a real
00069   // parameter sort of object which will be used to determine the x values used during
00070   // interpolations when the complex_interp object is asked for its value
00071   // (see get(), below).
00072 
00073   // Also note that the (x,y) data supplied need not be sorted, but all
00074   // x values must be unique.
00075 
00076 
00077   // ----------------------------------------------
00078   // Constructing, but supplying no data (add data using file() or table()):
00079 
00080   explicit
00081   complex_interp(
00082               const abstract_real_parameter &xp   // The independent (x) variable object
00083               ) ;
00084 
00085   // xp refers to a real parameter sort of object which will be used to determine the x
00086   // value used to perform an interpolation when the complex_interp object is asked for
00087   // its value (see get(), below).
00088 
00089   complex_interp() ;                              // Pick parameter and get data later... 
00090 
00091 
00092   // ----------------------------------------------
00093   // Constructing, taking data directly from a file or stream:
00094 
00095   complex_interp(
00096               const abstract_real_parameter &xp, // The independent (x) variable object
00097               const char * const name,           // The name of the file to open
00098               double x_unit = 1.0,               // Units for the x value
00099               double y_unit = 1.0,               // Units for the y value
00100               int ycol = 1,                      // Which complex number on line to use 
00101               bool ignore_ws = true              // Should all blank lines be ignored?
00102               );
00103 
00104   // The above version opens and reads from the named file. Using the functionality
00105   // of data_parser in io.h, it always skips initial blank lines and comments in the
00106   // file. If ignore_ws is set to false, then any further blank or comment lines
00107   // once data starts being read terminates the input. Otherwise the default is to
00108   // read the entire file. ycol tells which complex number entry should be read in
00109   // each line; don't count the 1st column, which contains the x value (a double).
00110   // The format for interpreting complex number data is given by Complex::in_mode();
00111   // see SIScmplx.h for details. x and y values are scaled (multiplied) by x_unit
00112   // and y_unit, respectively.
00113 
00114   // The following constructor is like the above, except it reads from a supplied input
00115   // stream. It starts from the current stream location and then skips any initial
00116   // blank or comment lines: 
00117 
00118   complex_interp(
00119               const abstract_real_parameter &xp, // The independent (x) variable object
00120               istream & s,                       // The input stream
00121               double x_unit = 1.0,               // Units for the x value
00122               double y_unit = 1.0,               // Units for the y value
00123               int ycol = 1,                      // Which complex number on line to use 
00124               bool ignore_ws = true              // Should all blank lines be ignored?
00125               );
00126 
00127 
00128   // ----------------------------------------------
00129   // Constructing with data taken from existing data table variables: 
00130 
00131   // Constructing from a complex_matrix object:
00132 
00133   complex_interp(
00134               const complex_matrix &ct,           // The matrix with the data points
00135               int xrow,                           // Row index for the x data
00136               int yrow,                           // Row index for the y data
00137               const abstract_real_parameter &xp   // The independent (x) variable object
00138               ) ;
00139 
00140   // The x and y row numbers, xrow and yrow, refer to LEFT INDEX values in the 
00141   // complex_matrix. They correspond to the FIRST INDEX in a complex_matrix::read(i,j)
00142   // function call. Only the real part of the values in xrow will be used.
00143 
00144   // The following option enumeration definitions for use in the remaining constructors:
00145   typedef enum {CARTESIAN=0, POLAR=1, DB=2} data_mode ; // for constructing from real data
00146 
00147   // CARTESIAN  : The default. Complex data is stored in the input real_matrix or
00148   //              datafile as (real, imaginary). 
00149   //
00150   // POLAR      : Complex data is stored in the input real_matrix or datafile as
00151   //              (magnitude, phase), with the phase in RADIANS.
00152   //
00153   // DB         : Complex data is stored as (magnitude,phase),
00154   //              with the magnitude in DECIBELS and the phase in DEGREES.
00155 
00156   complex_interp(
00157               const real_matrix &rt,              // The real_matrix with the data points
00158               int xrow, int yrow1, int yrow2,     // Row references into the real_matrix
00159               const abstract_real_parameter &xp,  // The independent (x) variable object
00160               data_mode dmode = CARTESIAN         // the form of (yrow1,yrow2) data
00161               ) ;
00162 
00163   // The x and y row numbers: xrow, yrow1, and yrow2, refer to LEFT INDEX values in the 
00164   // real_matrix. They correspond to the FIRST INDEX in a real_matrix::read(i,j) function
00165   // call.
00166 
00167 
00168   // Constructing from a datafile object:
00169 
00170   complex_interp(
00171               const datafile &df,                 // The datafile with the data points
00172               int xcol, int ycol1, int ycol2,     // Column references into the datafile
00173               const abstract_real_parameter &xp,  // The independent (x) variable object
00174               data_mode dmode = CARTESIAN         // the form of (ycol1,ycol2) data
00175               ) ;
00176 
00177   // The x and y column numbers: xcol, ycol1, and ycol2, refer to the actual columns in
00178   // the ASCII file on the disk from which the datafile was constructed. They correspond
00179   // to the FIRST INDEX in a datafile::read(i,j) function call. The data table is read
00180   // only once, at construction, so it may refer to a temporary object. For example:
00181   //
00182   //   complex_interp C(datafile("my_data"),1,2,3,device::f,complex_interp::POLAR);
00183   //
00184   // reads the data from "my_data" into a temporary datafile object, uses it to build
00185   // the interpolation tables within C, and then discards the datafile object. The first
00186   // column in the file "my_data" supplies the x (independent) values, the second and
00187   // third columns the y (dependent) values; in this example the complex y values are
00188   // interpreted as magnitude and phase (in radians). The parameter device::f will be
00189   // the independent variable.
00190 
00191 
00192   // ----------------------------------------------
00193   // Supplying the data or x parameter following construction:
00194 
00195   // parameter():
00196 
00197   complex_interp & parameter(const abstract_real_parameter &xp)
00198     { xparam = &xp ; return *this ; }
00199 
00200 
00201   // file():
00202 
00203   complex_interp & file(
00204               const char * const name,  // The name of the file to open
00205               double x_unit = 1.0,      // Units for the x value
00206               double y_unit = 1.0,      // Units for the y value
00207               int ycol = 1,             // Which complex number on line to use 
00208               bool ignore_ws = true     // Should all blank lines be ignored?
00209               );
00210 
00211   complex_interp & file(
00212               istream & s,              // The input stream
00213               double x_unit = 1.0,      // Units for the x value
00214               double y_unit = 1.0,      // Units for the y value
00215               int ycol = 1,             // Which complex number on line to use 
00216               bool ignore_ws = true     // Should all blank lines be ignored?
00217               );
00218 
00219 
00220   // touchstone():
00221 
00222   // Read in the data from a Touchstone-formatted 1-port data file and set the
00223   // x parameter to device::f (global frequency). Interprets the Touchstone
00224   // specification line to interpret the data format. In the event a specification
00225   // line is not present (specification lines begin with '#'), uses the default
00226   // format which would have a specification line of:
00227   //   "# GHZ S MA R 50"
00228   // (GHz frequency scale, S parameter in Magnitude-Degree, 50 Ohm normalization)
00229   complex_interp & touchstone(
00230               const char * const name,  // The name of the file to open
00231               char conversion = 'S'     // use 'Z' to convert data to impedance, 'Y'
00232                                         // for admittance. Default 'S' converts to
00233                                         // a reflection coefficient into a normalizing
00234                                         // impedance of device::Z0 at time of call
00235               );
00236 
00237 
00238   // table():
00239   
00240   complex_interp & table(
00241               const datafile &df,                 // The datafile with the data points
00242               int xcol, int ycol1, int ycol2,     // Column references into the datafile
00243               data_mode dmode = CARTESIAN         // the form of (ycol1,ycol2) data
00244               )
00245     {  construct(*(df.table()), xcol, ycol1, ycol2, dmode) ; return *this ; }
00246   
00247   complex_interp & table(
00248               const real_matrix &rt,              // The real_matrix with the data points 
00249               int xrow, int yrow1, int yrow2,     // Row references into the real_matrix 
00250               data_mode dmode = CARTESIAN         // the form of (ycol1,ycol2) data
00251               )
00252     {  construct(rt, xrow, yrow1, yrow2, dmode) ; return *this ; }
00253 
00254   complex_interp & table(
00255               const complex_matrix &ct,           // The matrix with the data points
00256               int xrow,                           // Row index for the x data
00257               int yrow
00258               )
00259     {  construct(ct, xrow, yrow) ; return *this ; }
00260 
00261 
00262   // ----------------------------------------------
00263   // Return an interpolated value:
00264 
00265   Complex get() const ; // Returns a y(x) value obtained by interpolation, using the current
00266                         // value of the abstract_real_parameter supplied during construction
00267                         // as the independent (x) value into the interpolator.
00268 
00269   // get() implements the abstract interface declaration in the abstract_real_parameter
00270   // base class from which real_interp is derived.
00271 
00272 private:
00273   const abstract_real_parameter *xparam ;  // parameter gives the x value
00274   void construct(const real_matrix &rt, int xcol, int ycol1, int ycol2, data_mode d) ;
00275   void construct(const complex_matrix &ct, int xcol, int ycol) ;
00276 
00277 };
00278 
00279 #endif /* COMPLEX_INTERP_H */

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