IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9714 for trunk/psLib/src/types


Ignore:
Timestamp:
Oct 21, 2006, 2:49:57 PM (20 years ago)
Author:
drobbin
Message:

Finished testing of psLookupTable. 100% coverage reported. Added tables for tests. Removed unnecessary table. Removed unreachable spot from psLookupTableInterpolate. Minor formatting in psLookupTable.h.

Location:
trunk/psLib/src/types
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psLookupTable.c

    r9672 r9714  
    77*  @author Ross Harman, MHPCC
    88*
    9 *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-10-20 02:36:51 $
     9*  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-10-22 00:49:57 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
     
    6969static void lookupTableFree(psLookupTable* table);
    7070
    71 /** Determines if a line is blank (whitespace only) or a commentline. It returns true if so. The input string
    72  * must be null terminated. */
     71/* Determines if a line is blank (whitespace only) or a commentline. It returns true if so.
     72   The input string must be null terminated. */
    7373static bool ignoreLine(char *inString)
    7474{
     
    8383
    8484
    85 /** Removes leading and trailing whitespace and # characters from a string. The cleaned string is a new null
    86  * terminated copy of the original input string. */
     85/* Removes leading and trailing whitespace and # characters from a string. The
     86   cleaned string is a new null terminated copy of the original input string. */
    8787static char *cleanString(char *inString,
    8888                         int sLen)
     
    9595
    9696    // Skip over leading # or whitespace
    97     while (isspace(*ptrB) || *ptrB=='#') {
    98         ptrB++;
    99     }
     97    //    while (isspace(*ptrB) || *ptrB=='#') {
     98    //        ptrB++;
     99    //    }
    100100
    101101    // Skip over trailing whitespace, null terminators, and # characters
     
    115115
    116116
    117 /** Returns cleaned token based on delimiter, but not including delimiter. Also changes the pointer location
    118  * the beginning of the string. Tokens are newly allocated null terminated strings. */
     117/* Returns cleaned token based on delimiter, but not including delimiter. Also changes
     118   the pointer location the beginning of the string. Tokens are newly allocated null
     119    terminated strings. */
    119120static char* getToken(char **inString,
    120121                      char *delimiter,
     
    138139        // Move to end of token
    139140        (*inString) += sLen;
    140     } else if(**inString!='\0' && sLen==0) {
    141         *status = PS_PARSE_ERROR_GENERAL;
    142     }
    143 
     141    }
     142    /*    else if(**inString!='\0' && sLen==0) {
     143            *status = PS_PARSE_ERROR_GENERAL;
     144        }
     145    */
    144146    return cleanToken;
    145147}
    146148
    147 /** Returns single parsed value as a psS32. The input string must be cleaned and null terminated. */
     149/* Returns single parsed value as a psS32. The input string must be cleaned and
     150   null terminated. */
    148151static psS32 parseS32(char *inString,
    149152                      psParseErrorType *status)
     
    164167}
    165168
    166 /** Returns single parsed value as a psS64. The input string must be cleaned and null terminated. */
     169/* Returns single parsed value as a psS64. The input string must be cleaned and
     170   null terminated. */
    167171static psS64 parseS64(char *inString,
    168172                      psParseErrorType *status)
     
    182186}
    183187
    184 /** Returns single parsed value as a psF32. The input string must be cleaned and null terminated. */
     188/* Returns single parsed value as a psF32. The input string must be cleaned and
     189   null terminated. */
    185190static psF32 parseF32(char *inString,
    186191                      psParseErrorType *status)
     
    200205}
    201206
    202 /** Returns single parsed value as a psF64. The input string must be cleaned and null terminated. */
     207/* Returns single parsed value as a psF64. The input string must be cleaned and
     208   null terminated. */
    203209static psF64 parseF64(char *inString,
    204210                      psParseErrorType *status)
     
    218224}
    219225
    220 /** Returns single parsed value as a double precision number. The input string must be cleaned and null
    221  * terminated. */
     226/* Returns single parsed value as a double precision number. The input string must be
     227   cleaned and null terminated. */
    222228static void parseValue(psVector *vec,
    223229                       psU64 index,
     
    474480            // Don't increase number of columns
    475481        } else {
    476             psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Invalid format specifier");
     482            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     483                    "Invalid format specifier");
    477484            psFree(strValue);
    478485            numCols = 0;
     
    500507
    501508            // Loop through file to get numRows, numCols, and column data types
    502             while((fgets(line, MAX_STRING_LENGTH, fp) != NULL) && (parseStatus == PS_PARSE_SUCCESS)) {
     509            while((fgets(line, MAX_STRING_LENGTH, fp) != NULL) &&
     510                    (parseStatus == PS_PARSE_SUCCESS))   {
    503511
    504512                // Copy pointer to line for parsing
     
    515523
    516524                    // Loop through format and line strings to get values in text table file
    517                     while((strValue=getToken((char**)&tempFormat," \t",&parseStatus)) &&
    518                             (strNum=getToken((char**)&linePtr," \t",&parseStatus)) ) {
    519 
     525                    while((strValue=getToken((char**)&tempFormat," \t",&parseStatus))
     526                            && (strNum=getToken((char**)&linePtr," \t",&parseStatus)) ) {
    520527                        // Set column vector
    521528                        colVector = outputArray->data[arrayIndex];
     
    523530                        // Set column entries based on format string defining the type
    524531                        if(strcmp(strValue,"\%d") == 0 ) {
    525                             colVector = psVectorRecycle(colVector, numRows, colVector->type.type);
     532                            colVector = psVectorRecycle(colVector, numRows,
     533                                                        colVector->type.type);
    526534                            parseValue(colVector,numRows-1,strNum,&parseStatus);
    527535                            arrayIndex++;
    528536                        } else if (strcmp(strValue,"\%ld") == 0) {
    529                             colVector = psVectorRecycle(colVector, numRows, colVector->type.type);
     537                            colVector = psVectorRecycle(colVector, numRows,
     538                                                        colVector->type.type);
    530539                            parseValue(colVector,numRows-1,strNum,&parseStatus);
    531540                            arrayIndex++;
    532541                        } else if (strcmp(strValue,"\%f") == 0) {
    533                             colVector = psVectorRecycle(colVector, numRows, colVector->type.type);
     542                            colVector = psVectorRecycle(colVector, numRows,
     543                                                        colVector->type.type);
    534544                            parseValue(colVector,numRows-1,strNum,&parseStatus);
    535545                            arrayIndex++;
    536546                        } else if (strcmp(strValue,"\%lf") == 0) {
    537                             colVector = psVectorRecycle(colVector, numRows, colVector->type.type);
     547                            colVector = psVectorRecycle(colVector, numRows,
     548                                                        colVector->type.type);
    538549                            parseValue(colVector,numRows-1,strNum,&parseStatus);
    539550                            arrayIndex++;
     
    544555                        psFree(strNum);
    545556
    546                         // If the file line was not parsed successful report error and return NULL
     557                        // If the file line was not parsed successful report
     558                        // error and return NULL
    547559                        if(parseStatus != PS_PARSE_SUCCESS) {
    548                             psError(PS_ERR_UNKNOWN,true,"Parsing text file failed.");
     560                            psError(PS_ERR_UNKNOWN, true,
     561                                    "Parsing text file failed.");
    549562                            fclose(fp);
    550563                            psFree(outputArray);
     
    556569            }
    557570
     571            //Return NULL for an empty table
     572            if (numRows == 0) {
     573                psError(PS_ERR_UNKNOWN, true,
     574                        "Parsing text file failed - input table is empty.");
     575                fclose(fp);
     576                psFree(outputArray);
     577                psFree(line);
     578                return NULL;
     579            }
     580
    558581            // Read on the lines in the file - close file pointer
    559582            fclose(fp);
     
    562585    } else {
    563586        // Format string parse error detected
    564         psError(PS_ERR_UNKNOWN,true,"Format string was not parsed sucessfully");
     587        psError(PS_ERR_UNKNOWN, true,
     588                "Format string was not parsed sucessfully");
    565589        psFree(outputArray);
    566590        return NULL;
     
    588612    // Check for invalid index column
    589613    if(indexCol < 0 ) {
    590         psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Index column cannot be less than zero");
     614        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     615                "Index column cannot be less than zero");
    591616        return NULL;
    592617    }
    593618
    594619    if (indexCol >= vectors->n) {
    595         psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Index column, %ld, is larger than number of columns, %ld.",
    596                 indexCol, vectors->n);
     620        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Index column, %ld, is larger"
     621                " than number of columns, %ld.", indexCol, vectors->n);
    597622        return NULL;
    598623    }
     
    647672    } else {
    648673        // Index vector is already sorted
    649         // Assign array vector specified by indexCol to table index vector and increment memory ref
     674        // Assign array vector specified by indexCol to table index vector
     675        // and increment memory ref
    650676        table->index = vectors->data[indexCol];
    651677        table->values = (psArray*)vectors;
     
    806832
    807833    // Verify the index is within the bounds of the table
    808     CHECK_LOWER_UPPER_BOUND(table,index,column)
     834    CHECK_LOWER_UPPER_BOUND(table,index,column);
    809835
    810836    // Find location in table where specified index is between to entries
     
    812838    while(index > convertVal ) {
    813839        hiIdx++;
    814         if(hiIdx >= numRows) {
    815             psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    816                     _("High index too big, %" PRIu64 "."), hiIdx);
    817             return NAN;
    818         }
     840        /*  XXX:  following is unreachable.
     841                if(hiIdx >= numRows) {
     842                    psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     843                            _("High index too big, %" PRIu64 "."), hiIdx);
     844                    return NAN;
     845                }
     846        */
    819847        CONVERT_VALUE_TO_F64(indexVec, hiIdx, convertVal)
    820848    }
     
    833861    denom -= convertVal;
    834862    if(fabs(denom) < FLT_EPSILON) {
    835         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Divide by zero error during interpolation."));
     863        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     864                _("Divide by zero error during interpolation."));
    836865        return NAN;
    837866    } else {
     
    848877}
    849878
    850 psVector* psLookupTableInterpolateAll(
    851     const psLookupTable *table,
    852     double index)
     879psVector* psLookupTableInterpolateAll(const psLookupTable *table,
     880                                      double index)
    853881{
    854882    long numCols = 0;
  • trunk/psLib/src/types/psLookupTable.h

    r7545 r9714  
    77*  @author Ross Harman, MHPCC
    88*
    9 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-06-13 23:54:57 $
     9*  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-10-22 00:49:57 $
    1111*
    1212*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    8080 */
    8181psLookupTable* psLookupTableAlloc(
    82     const char *filename,           ///< Name of file to read
    83     const char *format,             ///< scanf-like format string
    84     long indexCol                    ///< Column of the index vector (starting at zero)
     82    const char *filename,              ///< Name of file to read
     83    const char *format,                ///< scanf-like format string
     84    long indexCol                      ///< Column of the index vector (starting at zero)
    8585);
    8686
     
    9292 */
    9393psArray *psVectorsReadFromFile(
    94     const char* filename,            ///< File to be read
    95     const char* format               ///< scanf-like format string
     94    const char* filename,              ///< File to be read
     95    const char* format                 ///< scanf-like format string
    9696);
    9797
     
    115115 */
    116116long psLookupTableRead(
    117     psLookupTable *table            ///< Table to read
     117    psLookupTable *table               ///< Table to read
    118118);
    119119
     
    140140psVector* psLookupTableInterpolateAll(
    141141    const psLookupTable *table,         ///< Table with data
    142     double index                       ///< Value to be interpolated
     142    double index                        ///< Value to be interpolated
    143143);
    144144
Note: See TracChangeset for help on using the changeset viewer.