Changeset 9714 for trunk/psLib/src/types
- Timestamp:
- Oct 21, 2006, 2:49:57 PM (20 years ago)
- Location:
- trunk/psLib/src/types
- Files:
-
- 2 edited
-
psLookupTable.c (modified) (23 diffs)
-
psLookupTable.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psLookupTable.c
r9672 r9714 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1.4 0$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-10-2 0 02:36:51$9 * @version $Revision: 1.41 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-10-22 00:49:57 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 69 69 static void lookupTableFree(psLookupTable* table); 70 70 71 /* * Determines if a line is blank (whitespace only) or a commentline. It returns true if so. The input string72 *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. */ 73 73 static bool ignoreLine(char *inString) 74 74 { … … 83 83 84 84 85 /* * Removes leading and trailing whitespace and # characters from a string. The cleaned string is a new null86 *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. */ 87 87 static char *cleanString(char *inString, 88 88 int sLen) … … 95 95 96 96 // Skip over leading # or whitespace 97 while (isspace(*ptrB) || *ptrB=='#') {98 ptrB++;99 }97 // while (isspace(*ptrB) || *ptrB=='#') { 98 // ptrB++; 99 // } 100 100 101 101 // Skip over trailing whitespace, null terminators, and # characters … … 115 115 116 116 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. */ 119 120 static char* getToken(char **inString, 120 121 char *delimiter, … … 138 139 // Move to end of token 139 140 (*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 */ 144 146 return cleanToken; 145 147 } 146 148 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. */ 148 151 static psS32 parseS32(char *inString, 149 152 psParseErrorType *status) … … 164 167 } 165 168 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. */ 167 171 static psS64 parseS64(char *inString, 168 172 psParseErrorType *status) … … 182 186 } 183 187 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. */ 185 190 static psF32 parseF32(char *inString, 186 191 psParseErrorType *status) … … 200 205 } 201 206 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. */ 203 209 static psF64 parseF64(char *inString, 204 210 psParseErrorType *status) … … 218 224 } 219 225 220 /* * Returns single parsed value as a double precision number. The input string must be cleaned and null221 *terminated. */226 /* Returns single parsed value as a double precision number. The input string must be 227 cleaned and null terminated. */ 222 228 static void parseValue(psVector *vec, 223 229 psU64 index, … … 474 480 // Don't increase number of columns 475 481 } else { 476 psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Invalid format specifier"); 482 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 483 "Invalid format specifier"); 477 484 psFree(strValue); 478 485 numCols = 0; … … 500 507 501 508 // 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)) { 503 511 504 512 // Copy pointer to line for parsing … … 515 523 516 524 // 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)) ) { 520 527 // Set column vector 521 528 colVector = outputArray->data[arrayIndex]; … … 523 530 // Set column entries based on format string defining the type 524 531 if(strcmp(strValue,"\%d") == 0 ) { 525 colVector = psVectorRecycle(colVector, numRows, colVector->type.type); 532 colVector = psVectorRecycle(colVector, numRows, 533 colVector->type.type); 526 534 parseValue(colVector,numRows-1,strNum,&parseStatus); 527 535 arrayIndex++; 528 536 } else if (strcmp(strValue,"\%ld") == 0) { 529 colVector = psVectorRecycle(colVector, numRows, colVector->type.type); 537 colVector = psVectorRecycle(colVector, numRows, 538 colVector->type.type); 530 539 parseValue(colVector,numRows-1,strNum,&parseStatus); 531 540 arrayIndex++; 532 541 } else if (strcmp(strValue,"\%f") == 0) { 533 colVector = psVectorRecycle(colVector, numRows, colVector->type.type); 542 colVector = psVectorRecycle(colVector, numRows, 543 colVector->type.type); 534 544 parseValue(colVector,numRows-1,strNum,&parseStatus); 535 545 arrayIndex++; 536 546 } else if (strcmp(strValue,"\%lf") == 0) { 537 colVector = psVectorRecycle(colVector, numRows, colVector->type.type); 547 colVector = psVectorRecycle(colVector, numRows, 548 colVector->type.type); 538 549 parseValue(colVector,numRows-1,strNum,&parseStatus); 539 550 arrayIndex++; … … 544 555 psFree(strNum); 545 556 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 547 559 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."); 549 562 fclose(fp); 550 563 psFree(outputArray); … … 556 569 } 557 570 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 558 581 // Read on the lines in the file - close file pointer 559 582 fclose(fp); … … 562 585 } else { 563 586 // 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"); 565 589 psFree(outputArray); 566 590 return NULL; … … 588 612 // Check for invalid index column 589 613 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"); 591 616 return NULL; 592 617 } 593 618 594 619 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); 597 622 return NULL; 598 623 } … … 647 672 } else { 648 673 // 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 650 676 table->index = vectors->data[indexCol]; 651 677 table->values = (psArray*)vectors; … … 806 832 807 833 // 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); 809 835 810 836 // Find location in table where specified index is between to entries … … 812 838 while(index > convertVal ) { 813 839 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 */ 819 847 CONVERT_VALUE_TO_F64(indexVec, hiIdx, convertVal) 820 848 } … … 833 861 denom -= convertVal; 834 862 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.")); 836 865 return NAN; 837 866 } else { … … 848 877 } 849 878 850 psVector* psLookupTableInterpolateAll( 851 const psLookupTable *table, 852 double index) 879 psVector* psLookupTableInterpolateAll(const psLookupTable *table, 880 double index) 853 881 { 854 882 long numCols = 0; -
trunk/psLib/src/types/psLookupTable.h
r7545 r9714 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1.1 4$ $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 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 80 80 */ 81 81 psLookupTable* psLookupTableAlloc( 82 const char *filename, ///< Name of file to read83 const char *format, ///< scanf-like format string84 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) 85 85 ); 86 86 … … 92 92 */ 93 93 psArray *psVectorsReadFromFile( 94 const char* filename, ///< File to be read95 const char* format ///< scanf-like format string94 const char* filename, ///< File to be read 95 const char* format ///< scanf-like format string 96 96 ); 97 97 … … 115 115 */ 116 116 long psLookupTableRead( 117 psLookupTable *table ///< Table to read117 psLookupTable *table ///< Table to read 118 118 ); 119 119 … … 140 140 psVector* psLookupTableInterpolateAll( 141 141 const psLookupTable *table, ///< Table with data 142 double index ///< Value to be interpolated142 double index ///< Value to be interpolated 143 143 ); 144 144
Note:
See TracChangeset
for help on using the changeset viewer.
