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