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

Generated on Wed Sep 14 10:42:48 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.2