IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12329


Ignore:
Timestamp:
Mar 8, 2007, 12:08:26 PM (19 years ago)
Author:
Paul Price
Message:

Fixing up API for psLookupTableImport --- should return bool, because it already has a valid table.

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

Legend:

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

    r12287 r12329  
    77*  @author Ross Harman, MHPCC
    88*
    9 *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2007-03-07 02:42:22 $
     9*  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2007-03-08 22:08:26 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
     
    197197    psFree(table->filename);
    198198    psFree(table->format);
     199    psFree(table->index);
    199200}
    200201
     
    419420}
    420421
    421 psLookupTable *p_psLookupTableImport(const char *file,
    422                                      unsigned int lineno,
    423                                      const char *func,
    424                                      psLookupTable *table,
    425                                      psArray *vectors,
    426                                      long indexCol)
    427 {
    428     PS_ASSERT_LOOKUPTABLE_NON_NULL(table, NULL);
    429     PS_ASSERT_ARRAY_NON_NULL(vectors, NULL);
     422bool p_psLookupTableImport(const char *file,
     423                           unsigned int lineno,
     424                           const char *func,
     425                           psLookupTable *table,
     426                           psArray *vectors,
     427                           long indexCol)
     428{
     429    PS_ASSERT_LOOKUPTABLE_NON_NULL(table, false);
     430    PS_ASSERT_ARRAY_NON_NULL(vectors, false);
     431    PS_ASSERT_INT_NONNEGATIVE(indexCol, false);
    430432    if (indexCol >= vectors->n) {
    431433        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Index column, %ld, is larger"
    432434                " than number of columns, %ld.", indexCol, vectors->n);
    433         return NULL;
     435        return false;
    434436    }
    435437
     
    526528    }
    527529
    528     return table;
     530    return true;
    529531}
    530532
     
    533535    PS_ASSERT_LOOKUPTABLE_NON_NULL(table, 0);
    534536
    535     long            numRows  = 0;
    536     psArray*        vectors  = NULL;
    537     psLookupTable*  outTable = NULL;
    538 
    539537    // Read vectors from file specified in table
    540     vectors = psVectorsReadFromFile(table->filename, table->format);
    541 
    542     // Check for valid array after reading from file
    543     if (vectors != NULL) {
    544 
    545         // Import vector into table
    546         outTable = psLookupTableImport(table, vectors, table->indexCol);
    547 
     538    psArray *vectors = psVectorsReadFromFile(table->filename, table->format); // Vectors in file
     539    if (!vectors) {
     540        psError(PS_ERR_UNKNOWN, false, "Unable to read vectors from %s", table->filename);
     541        return 0;
     542    }
     543
     544    // Import vector into table
     545    if (!psLookupTableImport(table, vectors, table->indexCol)) {
     546        psError(PS_ERR_UNKNOWN, false, "Unable to import vectors from %s into lookup table.",
     547                table->filename);
    548548        psFree(vectors);
    549 
    550         // Update the number of rows read if outTable is not NULL
    551         if (outTable != NULL) {
    552             numRows = table->index->n;
    553         }
    554     }
    555 
    556     // Return the number of lines read
    557     return numRows;
     549        return 0;
     550    }
     551    psFree(vectors);                // Drop reference
     552
     553    return table->index->n;
    558554}
    559555
     
    716712    PS_ASSERT_VECTOR_NON_NULL(table->index, NULL);
    717713    PS_ASSERT_ARRAY_NON_NULL(table->values, NULL);
    718 
    719714    long numCols = table->values->n;
     715    if (numCols == 0) {
     716        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "No columns in lookup table from which to interpolate.");
     717        return NULL;
     718    }
     719
    720720    psVector *outVector = psVectorAlloc(numCols, PS_TYPE_F64);
    721721
  • trunk/psLib/src/types/psLookupTable.h

    r12289 r12329  
    66*  @author Ross Harman, MHPCC
    77*
    8 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2007-03-07 02:50:15 $
     8*  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2007-03-08 22:08:26 $
    1010*
    1111*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    130130 */
    131131#ifdef DOXYGEN
    132 psLookupTable *psLookupTableImport(
     132bool psLookupTableImport(
    133133    psLookupTable *table,              ///< Lookup table into which to import
    134134    const psArray *vectors,            ///< Array of vectors
     
    136136);
    137137#else // ifdef DOXYGEN
    138 psLookupTable *p_psLookupTableImport(
     138bool p_psLookupTableImport(
    139139    const char *file,                   ///< File of caller
    140140    unsigned int lineno,                ///< Line number of caller
Note: See TracChangeset for help on using the changeset viewer.