Changeset 31011 for trunk/ippToPsps/src/Config.c
- Timestamp:
- Mar 22, 2011, 4:11:23 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/src/Config.c (modified) (46 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/src/Config.c
r30147 r31011 1 /** @file ippToPspsConfig.c1 /** @file Config.c 2 2 * 3 3 * @ingroup ippToPsps … … 7 7 */ 8 8 9 #include " ippToPspsConfig.h"9 #include "Config.h" 10 10 #include <ctype.h> 11 11 #include <libxml/parser.h> 12 12 #include <libxml/tree.h> 13 13 14 // Gets PS type from string 14 #include "Fits.h" 15 16 /** 17 Gets PS type from string 18 */ 15 19 static int ippToPsps_GetDataType(char *typename) { 16 20 … … 28 32 } 29 33 30 // finds a column within this table 31 static IppToPspsConfig_Column* ippToPspsConfig_findColumn(IppToPspsConfig_Table* table, const char* name) { 32 33 IppToPspsConfig_Column* column = NULL; 34 /** 35 Finds a column within this table 36 */ 37 static Column* findColumn(Table* table, const char* name) { 38 39 Column* column = NULL; 34 40 35 41 for (uint32_t i=0; i<table->numOfColumns; i++) { … … 46 52 } 47 53 48 // finds a table from the array of tables 49 static IppToPspsConfig_Table* ippToPspsConfig_findTable(IppToPspsConfig* this, const char* name) { 50 51 IppToPspsConfig_Table* table = NULL; 54 /** 55 Finds a table from the array of tables 56 */ 57 static Table* findTable(Config* this, const char* name) { 58 59 Table* table = NULL; 52 60 53 61 for (uint32_t i=0; i<this->numOfTables; i++) { … … 64 72 } 65 73 66 // gets an attribute value from XML node 67 static bool ippToPspsConfig_getAttribute(xmlNode* node, const char* attName, char* _value) { 74 /** 75 Gets an attribute value from XML node 76 */ 77 static bool getAttribute(xmlNode* node, const char* attName, char* _value) { 68 78 69 79 xmlChar* value = xmlGetProp(node, (const xmlChar*)attName); … … 75 85 } 76 86 77 // creates a FITS binary table and populates it with defaults based on definition in schema XML 78 static bool ippToPspsConfig_createTable(IppToPspsConfig_Table* table, fitsfile* fitsOut, const long nRows) { 87 /** 88 Creates a FITS binary table and populates it with defaults based on definition in schema XML 89 */ 90 static bool createTable(Table* table, Fits* fitsOut, const long nRows) { 79 91 80 92 if (!table) return false; … … 98 110 switch (table->columns[i].pspsType) { 99 111 100 case TBYTE: 101 sprintf(colTypes[i],"1B"); 102 break; 103 case TSHORT: 104 sprintf(colTypes[i],"1I"); 105 break; 106 case TLONG: 107 sprintf(colTypes[i],"1J"); // TODO 108 break; 109 case TLONGLONG: 110 sprintf(colTypes[i],"1K"); 111 break; 112 case TFLOAT: 113 sprintf(colTypes[i],"1E"); 114 break; 115 case TDOUBLE: 116 sprintf(colTypes[i],"1D"); 117 break; 118 case TSTRING: 119 sprintf(colTypes[i],"32A"); // TODO width? 120 break; 112 case TBYTE: sprintf(colTypes[i],"1B"); 113 break; 114 case TSHORT: sprintf(colTypes[i],"1I"); 115 break; 116 case TLONG: sprintf(colTypes[i],"1J"); // TODO 117 break; 118 case TLONGLONG: sprintf(colTypes[i],"1K"); 119 break; 120 case TFLOAT: sprintf(colTypes[i],"1E"); 121 break; 122 case TDOUBLE: sprintf(colTypes[i],"1D"); 123 break; 124 case TSTRING: sprintf(colTypes[i],"32A"); // TODO width? 125 break; 121 126 122 127 default: 123 break;128 break; 124 129 } 125 130 … … 127 132 } 128 133 129 int status = 0; 130 if (fits_create_tbl(fitsOut, BINARY_TBL, nRows, nCols, colNames, colTypes, NULL, table->name, &status)) { 131 132 fits_report_error(stderr, status); 133 psError(PS_ERR_IO,"Unable to create table: %s", table->name); 134 } 134 fitsOut->createBinaryTable(fitsOut, nRows, nCols, colNames, colTypes, table->name); 135 135 136 136 for (i=0;i<nCols;i++) free(colTypes[i]); … … 166 166 case TBYTE: 167 167 for(j=0;j<nRows;j++) int8col[j] = (int8_t)tempLong; 168 fits _write_col(fitsOut, TBYTE, col, 1, 1, nRows, int8col, &status);168 fitsOut->writeColumn(fitsOut, TBYTE, col, 1, 1, nRows, int8col); 169 169 break; 170 170 case TSHORT: 171 171 for(j=0;j<nRows;j++) int16col[j] = (int16_t)tempLong; 172 fits _write_col(fitsOut, TSHORT, col, 1, 1, nRows, int16col, &status);172 fitsOut->writeColumn(fitsOut, TSHORT, col, 1, 1, nRows, int16col); 173 173 break; 174 174 case TLONG: 175 175 for(j=0;j<nRows;j++) longcol[j] = (long)tempLong; 176 fits _write_col(fitsOut, TLONG, col, 1, 1, nRows, longcol, &status);176 fitsOut->writeColumn(fitsOut, TLONG, col, 1, 1, nRows, longcol); 177 177 break; 178 178 179 179 case TLONGLONG: 180 180 for(j=0;j<nRows;j++) longcol[j] = tempLong; 181 fits _write_col(fitsOut, TLONGLONG, col, 1, 1, nRows, longcol, &status);181 fitsOut->writeColumn(fitsOut, TLONGLONG, col, 1, 1, nRows, longcol); 182 182 break; 183 183 184 184 case TFLOAT: 185 185 for(j=0;j<nRows;j++) floatcol[j] = (float)tempDouble; 186 fits _write_col(fitsOut, TFLOAT, col, 1, 1, nRows, floatcol, &status);186 fitsOut->writeColumn(fitsOut, TFLOAT, col, 1, 1, nRows, floatcol); 187 187 break; 188 188 189 189 case TDOUBLE: 190 190 for(j=0;j<nRows;j++) doublecol[j] = tempDouble; 191 fits _write_col(fitsOut, TDOUBLE, col, 1, 1, nRows, doublecol, &status);191 fitsOut->writeColumn(fitsOut, TDOUBLE, col, 1, 1, nRows, doublecol); 192 192 break; 193 193 194 194 case TSTRING: 195 195 for(j=0;j<nRows;j++) strcpy(strcol[j], tempStr); 196 fits _write_col(fitsOut, TSTRING, col, 1, 1, nRows, strcol, &status);196 fitsOut->writeColumn(fitsOut, TSTRING, col, 1, 1, nRows, strcol); 197 197 break; 198 198 … … 214 214 } 215 215 216 // count number of children with the provided name 217 static int ippToPspsConfig_countChildren(xmlNode* rootNode, const char* name) { 216 /* 217 Counts number of children with the provided name 218 */ 219 static int countChildren(xmlNode* rootNode, const char* name) { 218 220 219 221 int count = 0; … … 228 230 } 229 231 230 // searches through this table and finds attribute value for a provided key 231 static bool ippToPspsConfig_getRowAttribute(IppToPspsConfig* this, xmlNode* tableNode, 232 /** 233 Searches through this table and finds attribute value for a provided key 234 */ 235 static bool getRowAttribute(Config* this, xmlNode* tableNode, 232 236 const char* keyName, const char* keyValue, 233 237 const char* attName, char* attValue) { … … 243 247 244 248 if (strcmp((const char*)node->name, "row")==0) { 245 //psLogMsg("ippToPsps", PS_LOG_INFO, " Looking for key '%s'", keyName );246 247 if (! ippToPspsConfig_getAttribute(node, keyName, buffer)) continue;248 //psLogMsg("ippToPsps", PS_LOG_INFO, "Found key '%s' value '%s'", keyName, buffer );249 //psLogMsg("ippToPsps", PS_LOG_INFO, " Looking for key '%s'", keyName ); 250 251 if (!getAttribute(node, keyName, buffer)) continue; 252 //psLogMsg("ippToPsps", PS_LOG_INFO, "Found key '%s' value '%s'", keyName, buffer ); 249 253 250 254 if (strcmp(buffer, keyValue) != 0) continue; 251 ippToPspsConfig_getAttribute(node, attName, attValue);255 getAttribute(node, attName, attValue); 252 256 //printf("FOUND %s %s %s %s \n", keyName, buffer, attName, attValue ); 253 257 return true; … … 261 265 } 262 266 263 // opens an XML file and returns the document 264 static xmlDoc* ippToPspsConfig_openXmlFile(const char* path) { 267 /* 268 opens an XML file and returns the document 269 */ 270 static xmlDoc* openXmlFile(const char* path) { 265 271 266 272 xmlDoc* doc = xmlReadFile(path, NULL, 0); … … 269 275 } 270 276 271 // closes an XML file 272 static bool ippToPspsConfig_closeXmlFile(xmlDoc* doc) { 277 /* 278 closes an XML file 279 */ 280 static bool closeXmlFile(xmlDoc* doc) { 273 281 274 282 xmlFreeDoc(doc); … … 278 286 } 279 287 280 // gets filter ID for this filter name from 'init' data 281 static bool ippToPspsConfig_getInitValue( 282 IppToPspsConfig* this, 288 /** 289 Gets a value from the 'init' data 290 */ 291 static bool getInitValue( 292 Config* this, 283 293 const char* tableName, 284 294 const char* keyName, const char* keyValue, … … 290 300 psStringAppend(&path, "%s/../init/data.xml", this->configsPath); // TODO nasty 291 301 292 xmlDoc* doc = ippToPspsConfig_openXmlFile(path);302 xmlDoc* doc = openXmlFile(path); 293 303 294 304 if (doc == NULL) { … … 313 323 314 324 if (strcmp((const char*)node->name, "table")!=0) continue; 315 if (! ippToPspsConfig_getAttribute(node, "name", tempStr)) continue;325 if (!getAttribute(node, "name", tempStr)) continue; 316 326 if (strcmp(tempStr, tableName)!=0) continue; 317 327 318 ret = ippToPspsConfig_getRowAttribute(this, node, keyName, keyValue, attName, attValue);328 ret = getRowAttribute(this, node, keyName, keyValue, attName, attValue); 319 329 break; 320 330 } … … 322 332 } 323 333 324 ippToPspsConfig_closeXmlFile(doc);334 closeXmlFile(doc); 325 335 326 336 return ret; 327 337 } 328 338 329 // gets survey ID from survey name 330 bool ippToPspsConfig_getSurveyId(IppToPspsConfig* this, const char* surveyType, int8_t* surveyId) { 339 /* 340 Gets survey ID from survey name 341 */ 342 static bool getSurveyId(Config* this, const char* surveyType, int8_t* surveyId) { 331 343 332 344 char buffer[10]; 333 if (! ippToPspsConfig_getInitValue(this, "Survey", "name", surveyType, "surveyID", buffer)) {345 if (!getInitValue(this, "Survey", "name", surveyType, "surveyID", buffer)) { 334 346 335 347 *surveyId = -1; … … 341 353 } 342 354 343 // gets filter ID from filter type 344 bool ippToPspsConfig_getFilterId(IppToPspsConfig* this, const char* filterType, int8_t* filterId) { 355 /* 356 Gets filter ID from filter type 357 */ 358 static bool getFilterId(Config* this, const char* filterType, int8_t* filterId) { 345 359 346 360 char tmp[2]; … … 348 362 tmp[1] = '\0'; 349 363 char buffer[10]; 350 if (! ippToPspsConfig_getInitValue(this, "Filter", "filterType", tmp, "filterID", buffer)) {364 if (!getInitValue(this, "Filter", "filterType", tmp, "filterID", buffer)) { 351 365 352 366 *filterId = -1; … … 358 372 } 359 373 360 // populate the provided table with data from XML 361 static bool ippToPspsConfig_populateTable(IppToPspsConfig_Table* table, xmlNode* rootElement, fitsfile *fitsOut) { 374 /** 375 Populates the provided table with data from XML 376 */ 377 static bool populateTable(Table* table, xmlNode* rootElement, Fits *fitsOut) { 362 378 363 379 char tempStr[100]; … … 370 386 371 387 if (strcmp((const char*)node->name, "table")!=0) continue; 372 if (! ippToPspsConfig_getAttribute(node, "name", tempStr)) continue;388 if (!getAttribute(node, "name", tempStr)) continue; 373 389 if (strcmp(tempStr, table->name)==0) {tableNode = node; break;} 374 390 } … … 382 398 383 399 // now count the number of rows 384 int nRows = ippToPspsConfig_countChildren(tableNode, "row");400 int nRows = countChildren(tableNode, "row"); 385 401 if (nRows < 1) return false; 386 if (! ippToPspsConfig_createTable(table, fitsOut, nRows)) return false;402 if (!createTable(table, fitsOut, nRows)) return false; 387 403 388 404 int rows=0; … … 411 427 col = i+1; 412 428 413 if (! ippToPspsConfig_getAttribute(node, table->columns[i].pspsName, tempStr)) continue;429 if (!getAttribute(node, table->columns[i].pspsName, tempStr)) continue; 414 430 415 431 strncpy(strcol[0], tempStr, 32); … … 420 436 case TBYTE: 421 437 bytecol[0] = atoi(tempStr); 422 fits _write_col(fitsOut, table->columns[i].pspsType, col, rows, 1, 1, bytecol, &status);438 fitsOut->writeColumn(fitsOut, table->columns[i].pspsType, col, rows, 1, 1, bytecol); 423 439 break; 424 440 case TSHORT: 425 441 shortcol[0] = atoi(tempStr); 426 fits _write_col(fitsOut, table->columns[i].pspsType, col, rows, 1, 1, shortcol, &status);442 fitsOut->writeColumn(fitsOut, table->columns[i].pspsType, col, rows, 1, 1, shortcol); 427 443 break; 428 444 case TLONG: 429 445 case TLONGLONG: 430 446 longcol[0] = atol(tempStr); 431 fits _write_col(fitsOut, table->columns[i].pspsType, col, rows, 1, 1, longcol, &status);447 fitsOut->writeColumn(fitsOut, table->columns[i].pspsType, col, rows, 1, 1, longcol); 432 448 break; 433 449 case TFLOAT: 434 450 floatcol[0] = atof(tempStr); 435 fits _write_col(fitsOut, table->columns[i].pspsType, col, rows, 1, 1, floatcol, &status);451 fitsOut->writeColumn(fitsOut, table->columns[i].pspsType, col, rows, 1, 1, floatcol); 436 452 break; 437 453 case TDOUBLE: 438 454 doublecol[0] = atof(tempStr); 439 fits _write_col(fitsOut, table->columns[i].pspsType, col, rows, 1, 1, doublecol, &status);455 fitsOut->writeColumn(fitsOut, table->columns[i].pspsType, col, rows, 1, 1, doublecol); 440 456 break; 441 457 case TSTRING: 442 fits _write_col(fitsOut, table->columns[i].pspsType, col, rows, 1, 1, strcol, &status);458 fitsOut->writeColumn(fitsOut, table->columns[i].pspsType, col, rows, 1, 1, strcol); 443 459 break; 444 460 … … 460 476 } 461 477 462 // loads a table description from XML 463 static bool ippToPspsConfig_loadTableDescription(IppToPspsConfig_Table* table, xmlNode* tableNode) { 478 /** 479 Loads a table description from XML 480 */ 481 static bool loadTableDescription(Table* table, xmlNode* tableNode) { 464 482 465 483 bool ret = true; 466 484 char tableName[100]; 467 ippToPspsConfig_getAttribute(tableNode, "name", tableName);485 getAttribute(tableNode, "name", tableName); 468 486 strcpy(table->name, tableName); 469 487 470 488 // count how many columns we have coming in and allocate memory for them 471 table->numOfColumns = ippToPspsConfig_countChildren(tableNode, "column");472 table->columns = calloc(table->numOfColumns, sizeof( IppToPspsConfig_Column));489 table->numOfColumns = countChildren(tableNode, "column"); 490 table->columns = calloc(table->numOfColumns, sizeof(Column)); 473 491 // psLogMsg("ippToPsps", PS_LOG_INFO, " Found '%d' columns", table->numOfColumns); 474 492 … … 484 502 485 503 // column name 486 ippToPspsConfig_getAttribute(node, "name", buffer);504 getAttribute(node, "name", buffer); 487 505 sprintf(table->columns[columnNum].pspsName, buffer); 488 506 489 507 // column type 490 ippToPspsConfig_getAttribute(node, "type", buffer);508 getAttribute(node, "type", buffer); 491 509 table->columns[columnNum].pspsType = ippToPsps_GetDataType(buffer); 492 510 493 511 // default value 494 ippToPspsConfig_getAttribute(node, "default", buffer);512 getAttribute(node, "default", buffer); 495 513 sprintf(table->columns[columnNum].defaultValue, buffer); 496 514 497 515 // comment 498 ippToPspsConfig_getAttribute(node, "comment", buffer);516 getAttribute(node, "comment", buffer); 499 517 sprintf(table->columns[columnNum].comment, buffer); 500 518 … … 523 541 } 524 542 525 // read table shapes from XML file 526 bool ippToPspsConfig_loadTableDescriptions(IppToPspsConfig* this) { 543 /** 544 Reads table shapes from XML file 545 */ 546 static bool loadTableDescriptions(Config* this) { 527 547 528 548 bool ret = true; … … 531 551 psStringAppend(&path, "%s/tables.xml", this->configsPath); 532 552 533 xmlDoc* doc = ippToPspsConfig_openXmlFile(path);553 xmlDoc* doc = openXmlFile(path); 534 554 535 555 if (doc == NULL) { … … 549 569 550 570 // count how many tables we have coming in and allocate memory for them 551 this->numOfTables = ippToPspsConfig_countChildren(rootElement, "table");552 this->tables = calloc(this->numOfTables, sizeof( IppToPspsConfig_Table));571 this->numOfTables = countChildren(rootElement, "table"); 572 this->tables = calloc(this->numOfTables, sizeof(Table)); 553 573 // psLogMsg("ippToPsps", PS_LOG_INFO, " Found '%d' tables", this->numOfTables); 554 574 555 575 xmlNode* node = NULL; 556 IppToPspsConfig_Table* table = NULL;576 Table* table = NULL; 557 577 558 578 int tableNum = 0; … … 565 585 table = this->tables+tableNum; 566 586 567 if (! ippToPspsConfig_loadTableDescription(table, node)) ret = false;587 if (!loadTableDescription(table, node)) ret = false; 568 588 else tableNum++; 569 589 } … … 574 594 psError(PS_ERR_IO, false, "Mismatch between number of tables expected (%d) and those found (%d)", this->numOfTables, tableNum); 575 595 576 ippToPspsConfig_closeXmlFile(doc);596 closeXmlFile(doc); 577 597 578 598 return ret; 579 599 } 580 600 581 // loads mappings from XML for a particular table 582 static bool ippToPspsConfig_loadTableMappings(IppToPspsConfig* this, xmlNode* tableNode) { 601 /** 602 Loads mappings from XML for a particular table 603 */ 604 static bool loadTableMappings(Config* this, xmlNode* tableNode) { 583 605 584 606 bool ret = false; … … 587 609 588 610 char tableName[100]; 589 ippToPspsConfig_getAttribute(tableNode, "name", tableName);590 591 IppToPspsConfig_Table* table = ippToPspsConfig_findTable(this, tableName);592 IppToPspsConfig_Column* column = NULL;611 getAttribute(tableNode, "name", tableName); 612 613 Table* table = findTable(this, tableName); 614 Column* column = NULL; 593 615 if (!table) return false; 594 616 … … 603 625 604 626 // column type 605 ippToPspsConfig_getAttribute(node, "pspsName", buffer);606 column = ippToPspsConfig_findColumn(table, buffer);627 getAttribute(node, "pspsName", buffer); 628 column = findColumn(table, buffer); 607 629 608 630 if (!column) continue; 609 631 610 632 // IPP name 611 ippToPspsConfig_getAttribute(node, "ippName", buffer);633 getAttribute(node, "ippName", buffer); 612 634 strcpy(column->ippName, buffer); 613 635 614 636 // IPP type 615 ippToPspsConfig_getAttribute(node, "ippType", buffer);637 getAttribute(node, "ippType", buffer); 616 638 column->ippType = ippToPsps_GetDataType(buffer); 617 639 … … 626 648 } 627 649 628 // reads table mappings from XML file 629 static bool ippToPspsConfig_loadMappings(IppToPspsConfig* this) { 650 /** 651 Reads table mappings from XML file 652 */ 653 static bool loadMappings(Config* this) { 630 654 631 655 bool ret = true; … … 634 658 psStringAppend(&path, "%s/map.xml", this->configsPath); 635 659 636 xmlDoc* doc = ippToPspsConfig_openXmlFile(path);660 xmlDoc* doc = openXmlFile(path); 637 661 638 662 if (doc == NULL) { … … 657 681 if (strcmp((const char*)node->name, "table")==0) { 658 682 659 if (! ippToPspsConfig_loadTableMappings(this, node)) ret = false;683 if (!loadTableMappings(this, node)) ret = false; 660 684 } 661 685 } 662 686 } 663 687 664 ippToPspsConfig_closeXmlFile(doc);688 closeXmlFile(doc); 665 689 666 690 return ret; 667 691 } 668 692 669 // populate the provided table with data from XML 670 bool ippToPspsConfig_populateFromFile(IppToPspsConfig* this, fitsfile *fitsOut) { 693 /** 694 Populate the provided table with data from XML 695 */ 696 static bool populateFromFile(Config* this, Fits *fitsOut) { 671 697 672 698 bool ret = true; … … 674 700 psStringAppend(&path, "%s/data.xml", this->configsPath); 675 701 676 xmlDoc* doc = ippToPspsConfig_openXmlFile(path);702 xmlDoc* doc = openXmlFile(path); 677 703 678 704 if (doc == NULL) { … … 690 716 691 717 for (uint32_t i=0; i<this->numOfTables; i++) { 692 if (! ippToPspsConfig_populateTable(this->tables+i, rootElement, fitsOut)) {718 if (!populateTable(this->tables+i, rootElement, fitsOut)) { 693 719 ret = false; 694 720 } 695 721 } 696 722 697 ippToPspsConfig_closeXmlFile(doc);723 closeXmlFile(doc); 698 724 699 725 return ret; 700 726 } 701 727 702 // gets the contents of a FITS column vector 703 bool ippToPspsConfig_getColumnVector( 704 int col, 705 long row, 706 int type, 707 int repeat, 708 float* vector, 709 fitsfile *fitsIn) { 710 711 int status = 0; 712 int anynull = 0; 713 714 fits_read_col(fitsIn, type, col, row, 1, repeat, NULL, vector, &anynull, &status); 715 716 if (status) { 717 psError(PS_ERR_IO, false, "Failed to read vector column %d row %ld", col, row); 718 return false; 719 } 720 721 int i; 722 for(i=0; i<repeat; i++) printf("JJJ %f\n", vector[i]); 723 724 return true; 725 } 726 727 // gets metadata about a column 728 bool ippToPspsConfig_getFitsColumnMeta( 729 char* name, 730 int* colNum, 731 int* type, 732 long* repeat, 733 fitsfile *fitsIn) { 734 735 int status = 0; 736 fits_get_colnum(fitsIn, CASESEN, name, colNum, &status); 737 if (status) { 738 psError(PS_ERR_IO, false, "Unable to read col '%s'", name); 739 return false; 740 } 741 742 status = 0; 743 fits_get_eqcoltype(fitsIn, *colNum, type, repeat, NULL, &status); 744 if (status) { 745 psError(PS_ERR_IO, false, "Unable to read type info for '%s'", name); 746 return false; 747 } 748 749 return true; 750 } 751 752 // populate with data from another FITS table into this one 753 static bool ippToPspsConfig_populateTableFromFits( 754 IppToPspsConfig_Table* table, 755 fitsfile *fitsIn, 756 fitsfile *fitsOut, 728 /** 729 Populate with data from another FITS table into this one 730 */ 731 static bool populateTableFromFits( 732 Table* table, 733 Fits *fitsIn, 734 Fits *fitsOut, 757 735 const long nRows, 758 736 const bool fromHeader) { … … 770 748 strcol[i] = (char*)calloc(50,sizeof(char)); // TODO 20? size issue 771 749 772 int8_t int8null = -99;773 int16_t int16null = -999;774 long longnull = -999;775 float floatnull = -999.0;776 double doublenull = -999.0;777 778 int anynull = 0;779 int readStatus = 0;780 int writeStatus = 0;781 782 750 // first loop round all columns and get IPP col numbers for provided column names TODO only do once, first time in 783 751 if(!fromHeader) { … … 787 755 if (strlen(table->columns[i].ippName) < 1) continue; 788 756 789 int dummy; 790 791 if (!ippToPspsConfig_getFitsColumnMeta( 792 table->columns[i].ippName, 793 &table->columns[i].ippColNum, 794 // &table->columns[i].ippType, TODO getting wrong type for some reason 795 &dummy, 796 &table->columns[i].ippRepeat, 797 fitsIn)) {return false;} 757 int dummy; // TODO getting wrong type for some reason 758 if (!fitsIn->getColumnMeta(fitsIn, table->columns[i].ippName, &table->columns[i].ippColNum, &dummy, &table->columns[i].ippRepeat)) return false; 798 759 } 799 760 } … … 802 763 for (uint32_t i=0; i<table->numOfColumns; i++) { 803 764 804 readStatus = 0;805 writeStatus = 0;806 807 765 if (!table->columns[i].usingDefault) { 808 766 … … 813 771 case TBYTE: 814 772 if (fromHeader) { 815 fits_read_key(fitsIn, TBYTE, table->columns[i].ippName, &int8col[0], NULL, &readStatus); 816 if (!isfinite(int8col[0])) int8col[0] = int8null; 773 fitsIn->getHeaderKeyValue(fitsIn, TBYTE, table->columns[i].ippName, &int8col[0]); 817 774 } 818 else fits _read_col(fitsIn, TBYTE, table->columns[i].ippColNum, 1, 1, nRows, &int8null, int8col, &anynull, &readStatus);819 fits _write_col(fitsOut, TBYTE, col, 1, 1, nRows, int8col, &writeStatus);775 else fitsIn->readColumn(fitsIn, TBYTE, table->columns[i].ippColNum, 1, 1, nRows, int8col); 776 fitsOut->writeColumn(fitsOut, TBYTE, col, 1, 1, nRows, int8col); 820 777 break; 821 778 case TSHORT: 822 779 if (fromHeader) { 823 fits_read_key(fitsIn, TSHORT, table->columns[i].ippName, &int16col[0], NULL, &readStatus); 824 if (!isfinite(int16col[0])) int16col[0] = int16null; 780 fitsIn->getHeaderKeyValue(fitsIn, TSHORT, table->columns[i].ippName, &int16col[0]); 825 781 } 826 else fits _read_col(fitsIn, TSHORT, table->columns[i].ippColNum, 1, 1, nRows, &int16null, int16col, &anynull, &readStatus);827 fits _write_col(fitsOut, TSHORT, col, 1, 1, nRows, int16col, &writeStatus);782 else fitsIn->readColumn(fitsIn, TSHORT, table->columns[i].ippColNum, 1, 1, nRows, int16col); 783 fitsOut->writeColumn(fitsOut, TSHORT, col, 1, 1, nRows, int16col); 828 784 break; 829 785 case TLONG: 830 786 if (fromHeader) { 831 fits_read_key(fitsIn, TLONG, table->columns[i].ippName, &longcol[0], NULL, &readStatus); 832 if (!isfinite(longcol[0])) longcol[0] = longnull; 787 fitsIn->getHeaderKeyValue(fitsIn, TLONG, table->columns[i].ippName, &longcol[0]); 833 788 } 834 else fits _read_col(fitsIn, TLONG, table->columns[i].ippColNum, 1, 1, nRows, &longnull, longcol, &anynull, &readStatus);835 fits _write_col(fitsOut, TLONG, col, 1, 1, nRows, longcol, &writeStatus);789 else fitsIn->readColumn(fitsIn, TLONG, table->columns[i].ippColNum, 1, 1, nRows, longcol); 790 fitsOut->writeColumn(fitsOut, TLONG, col, 1, 1, nRows, longcol); 836 791 break; 837 792 case TLONGLONG: 838 793 if (fromHeader) { 839 fits_read_key(fitsIn, TLONGLONG, table->columns[i].ippName, &longcol[0], NULL, &readStatus); 840 if (!isfinite(longcol[0])) longcol[0] = longnull; 794 fitsIn->getHeaderKeyValue(fitsIn, TLONGLONG, table->columns[i].ippName, &longcol[0]); 841 795 } 842 else fits _read_col(fitsIn, TLONGLONG, table->columns[i].ippColNum, 1, 1, nRows, &longnull, longcol, &anynull, &readStatus);843 fits _write_col(fitsOut, TLONGLONG, col, 1, 1, nRows, longcol, &writeStatus);796 else fitsIn->readColumn(fitsIn, TLONGLONG, table->columns[i].ippColNum, 1, 1, nRows, longcol); 797 fitsOut->writeColumn(fitsOut, TLONGLONG, col, 1, 1, nRows, longcol); 844 798 break; 845 799 case TFLOAT: 846 800 if (fromHeader) { 847 fits_read_key(fitsIn, TFLOAT, table->columns[i].ippName,&floatcol[0], NULL, &readStatus); 848 if (!isfinite(floatcol[0])) floatcol[0] = floatnull; 801 fitsIn->getHeaderKeyValue(fitsIn, TFLOAT, table->columns[i].ippName,&floatcol[0]); 849 802 } 850 else fits _read_col(fitsIn, TFLOAT, table->columns[i].ippColNum, 1, 1, nRows, &floatnull, floatcol, &anynull, &readStatus);851 fits _write_col(fitsOut, TFLOAT, col, 1, 1, nRows, floatcol, &writeStatus);803 else fitsIn->readColumn(fitsIn, TFLOAT, table->columns[i].ippColNum, 1, 1, nRows, floatcol); 804 fitsOut->writeColumn(fitsOut, TFLOAT, col, 1, 1, nRows, floatcol); 852 805 break; 853 806 case TDOUBLE: 854 807 if (fromHeader) { 855 fits_read_key(fitsIn, TDOUBLE, table->columns[i].ippName, &doublecol[0], NULL, &readStatus); 856 if (!isfinite(doublecol[0])) doublecol[0] = doublenull; 808 fitsIn->getHeaderKeyValue(fitsIn, TDOUBLE, table->columns[i].ippName, &doublecol[0]); 857 809 } 858 else fits _read_col(fitsIn, TDOUBLE, table->columns[i].ippColNum, 1, 1, nRows, &doublenull, doublecol, &anynull, &readStatus);859 fits _write_col(fitsOut, TDOUBLE, col, 1, 1, nRows, doublecol, &writeStatus);810 else fitsIn->readColumn(fitsIn, TDOUBLE, table->columns[i].ippColNum, 1, 1, nRows, doublecol); 811 fitsOut->writeColumn(fitsOut, TDOUBLE, col, 1, 1, nRows, doublecol); 860 812 break; 861 813 case TSTRING: 862 if (fromHeader) fits _read_key(fitsIn, TSTRING, table->columns[i].ippName, strcol[0], NULL, &readStatus);863 else fits _read_col(fitsIn, TSTRING, table->columns[i].ippColNum, 1, 1, nRows, " ", strcol, &anynull, &readStatus);864 fits _write_col(fitsOut, TSTRING, col, 1, 1, nRows, strcol, &writeStatus);814 if (fromHeader) fitsIn->getHeaderKeyValue(fitsIn, TSTRING, table->columns[i].ippName, strcol[0]); 815 else fitsIn->readColumn(fitsIn, TSTRING, table->columns[i].ippColNum, 1, 1, nRows, strcol); 816 fitsOut->writeColumn(fitsOut, TSTRING, col, 1, 1, nRows, strcol); 865 817 break; 866 818 … … 870 822 break; 871 823 } 872 873 // TODO need these errors, but strange error handling runs out of memory874 //if (readStatus) {875 // psError(PS_ERR_IO, false, "Unable to read col num '%d' col name '%s', type %d",876 // table->columns[i].ippColNum, table->columns[i].ippName, table->columns[i].ippType);877 // fits_report_error(stderr, readStatus);878 //}879 //if (writeStatus) {880 // psError(PS_ERR_IO, false, "Unable to write col '%s'", table->columns[i].pspsName );881 // fits_report_error(stderr, writeStatus);882 //}883 824 } 884 825 } … … 895 836 } 896 837 897 // creates and populates a table 898 bool ippToPspsConfig_writeTable( 899 IppToPspsConfig* this, 900 fitsfile* fitsIn, 901 fitsfile* fitsOut, 838 /** 839 Creates and populates a table 840 */ 841 static bool createAndPopulateTable( 842 Config* this, 843 Fits* fitsIn, 844 Fits* fitsOut, 902 845 const long nRows, 903 846 const char* tableName, 904 const bool fromHeader) { 905 906 907 IppToPspsConfig_Table* table = ippToPspsConfig_findTable(this, tableName); 847 const int fromHeader) { 848 849 Table* table = findTable(this, tableName); 908 850 if (!table) return false; 909 851 910 if(!ippToPspsConfig_createTable(table, fitsOut, nRows)) return false; 911 return ippToPspsConfig_populateTableFromFits(table, fitsIn, fitsOut, nRows, fromHeader); 912 } 913 914 // Destructor. 915 void ippToPspsConfig_Destructor(IppToPspsConfig* this) { 852 if(!createTable(table, fitsOut, nRows)) return false; 853 return populateTableFromFits(table, fitsIn, fitsOut, nRows, fromHeader); 854 } 855 856 /** 857 Destructor. 858 */ 859 static void destroy(Config* this) { 916 860 917 861 if (this != NULL ) { … … 927 871 } 928 872 929 / / Constructor. Loads IPP -> PSPS mappings from a csv930 IppToPspsConfig* ippToPspsConfig_Constructor(const char* path) { 931 932 IppToPspsConfig* this = NULL; 933 934 this = malloc(sizeof(IppToPspsConfig));873 /** 874 Constructor. Loads IPP -> PSPS mappings from an XML file 875 */ 876 Config* new_Config(const char* path) { 877 878 Config* this = (Config*)calloc(1, sizeof(Config)); 935 879 936 880 this->configsPath = NULL; 937 881 psStringAppend(&this->configsPath, path); 938 882 883 // method pointers 884 this->getFilterId = getFilterId; 885 this->getSurveyId = getSurveyId; 886 this->createAndPopulateTable = createAndPopulateTable; 887 this->populateFromFile = populateFromFile; 888 this->destroy = destroy; 889 939 890 // load tables descriptions from XML 940 if ( ippToPspsConfig_loadTableDescriptions(this)) {891 if (loadTableDescriptions(this)) { 941 892 942 893 // load any mappings we may have from XML 943 ippToPspsConfig_loadMappings(this);894 loadMappings(this); 944 895 } 945 896
Note:
See TracChangeset
for help on using the changeset viewer.
