Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

psLookupTable.h

Go to the documentation of this file.
00001 /** @file  psLookupTable.h
00002 *
00003 *  @brief This file defines the structure and functions for table lookups.
00004 *
00005 *  @ingroup dataIO
00006 *
00007 *  @author Ross Harman, MHPCC
00008 *
00009 *  @version $Revision: 1.14 $ $Name: rel12 $
00010 *  @date $Date: 2006/06/13 23:54:57 $
00011 *
00012 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
00013 */
00014 
00015 #ifndef PS_LOOKUPTABLE_H
00016 #define PS_LOOKUPTABLE_H
00017 
00018 #include "psType.h"
00019 #include "psVector.h"
00020 #include "psArray.h"
00021 #include "psLogMsg.h"
00022 
00023 
00024 /** Lookup table structure
00025  *
00026  *  Holds table data read from external data files.
00027  *
00028  */
00029 typedef struct
00030 {
00031     const char *filename;              ///< Name of file with table
00032     const char *format;                ///< scanf-like format string for file
00033     long indexCol;                     ///< Column of the index vector (starting at zero)
00034     psVector *index;                   ///< Vector of independent index values
00035     psArray *values;                   ///< Array of dependent table values corresponding to index values
00036     const double validFrom;            ///< Lower bound for rable read
00037     const double validTo;              ///< Upper bound for table read
00038 }
00039 psLookupTable;
00040 
00041 
00042 /** Lookup table lookup status and error conditions
00043  *
00044  *  Success, failure, and status conditions for table lookups.
00045  */
00046 typedef enum {
00047     PS_LOOKUP_SUCCESS             = 0x0000,        ///< Table lookup succeeded
00048     PS_LOOKUP_PAST_TOP            = 0x0101,        ///< Lookup off top of table
00049     PS_LOOKUP_PAST_BOTTOM         = 0x0102,        ///< Lookup off bottom of table
00050     PS_LOOKUP_ERROR               = 0x0104         ///< Any other type of lookup error
00051 } psLookupStatusType;
00052 
00053 /** Lookup table parse status and error conditions
00054  *
00055  *  Success, failure, and status conditions for table parsing.
00056  */
00057 typedef enum {
00058     PS_PARSE_SUCCESS              = 0x0000,        ///< Table lookup succeeded
00059     PS_PARSE_ERROR_TYPE           = 0x0101,        ///< Error parsing type
00060     PS_PARSE_ERROR_VALUE          = 0x0102,        ///< Error parsing numerical value
00061     PS_PARSE_ERROR_GENERAL        = 0x0104         ///< Any other type of lookup error
00062 }psParseErrorType;
00063 
00064 /** Checks the type of a particular pointer.
00065  *
00066  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00067  *
00068  *  @return bool:       True if the pointer matches a psLookupTable structure, false otherwise.
00069  */
00070 bool psMemCheckLookupTable(
00071     psPtr ptr                          ///< the pointer whose type to check
00072 );
00073 
00074 
00075 /** Allocator for psLookupTable struct
00076  *
00077  *  Allocates a new psLookupTable struct.
00078  *
00079  *  @return psLookupTable*     New psLookupTable struct.
00080  */
00081 psLookupTable* psLookupTableAlloc(
00082     const char *filename,           ///< Name of file to read
00083     const char *format,             ///< scanf-like format string
00084     long indexCol                    ///< Column of the index vector (starting at zero)
00085 );
00086 
00087 /** Read vectors from file
00088  *
00089  *  Read numeric vectors from ASCII text file
00090  *
00091  *  @return psArray*  New array of psVectors corresponding to the columns of the table
00092  */
00093 psArray *psVectorsReadFromFile(
00094     const char* filename,            ///< File to be read
00095     const char* format               ///< scanf-like format string
00096 );
00097 
00098 /** Import arrays of vectors into a table
00099  *
00100  *  Import array of vectors read from text file into a table structure
00101  *
00102  *  @return psLookupTable*  Lookup table structure with array vector data
00103  */
00104 psLookupTable *psLookupTableImport(
00105     psLookupTable *table,              ///< Lookup table into which to import
00106     const psArray *vectors,            ///< Array of vectors
00107     long indexCol                      ///< Index of the index vector in the array of vectors
00108 );
00109 
00110 /** Read lookup table
00111  *
00112  *  Reads a lookup table and fills corresponding psLookupTable struct.
00113  *
00114  *  @return long:     Number of valid lines read
00115  */
00116 long psLookupTableRead(
00117     psLookupTable *table            ///< Table to read
00118 );
00119 
00120 /** Lookup and interpolate value from table.
00121  *
00122  *  Interpolates value from table. Sets status bit for success or one of several possible failure
00123  *  conditions.
00124  *
00125  *  @return double     Interpolation value at index
00126  */
00127 double psLookupTableInterpolate(
00128     const psLookupTable *table,        ///< Table with data
00129     double index,                      ///< Value to be interpolated
00130     long column                        ///< Column in table to be interpolated
00131 );
00132 
00133 /** Lookup and interpolate all values from table.
00134  *
00135  *  Interpolates all values from table. Sets status bit for success or one of several possible failure
00136  *  conditions.
00137  *
00138  *  @return psVector*     Interpolation values calculated at index
00139  */
00140 psVector* psLookupTableInterpolateAll(
00141     const psLookupTable *table,         ///< Table with data
00142     double index                       ///< Value to be interpolated
00143 );
00144 
00145 #endif // #ifndef PS_LOOKUPTABLE_H

Generated on Mon Jul 3 14:13:44 2006 for Pan-STARRS Foundation Library by  doxygen 1.4.4