- Timestamp:
- Apr 19, 2013, 4:45:57 PM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130419
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130419
-
branches/eam_branches/ipp-20130419/psModules
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20130307/psModules (added) merged: 35321,35341,35343,35348,35350,35375-35376,35379,35381,35413
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20130419/psModules/src/camera/pmFPAfileDefine.c
r34085 r35421 446 446 } 447 447 448 // given a filename, convert to UNIX namespace and read the PHU 449 psMetadata *readPHUfromFilename (char *filename, pmConfig *config) { 450 451 // Need to generate an FPA 452 psString realName = pmConfigConvertFilename(filename, config, false, false); 453 if (!realName) { 454 psError(psErrorCodeLast(), false, "Failed to convert file name %s", filename); 455 return NULL; 456 } 457 458 // load the header of the first image 459 // EXTWORD (fits->extword) is not relevant to the PHU 460 psFits *fits = psFitsOpen(realName, "r"); // FITS file 461 if (!fits) { 462 psError(psErrorCodeLast(), false, "Failed to open file %s", realName); 463 psFree(realName); 464 return NULL; 465 } 466 467 psMetadata *phu = psFitsReadHeader (NULL, fits); // Primary header 468 if (!phu) { 469 psError(psErrorCodeLast(), false, "Failed to read file header %s", realName); 470 psFree(realName); 471 return NULL; 472 } 473 474 if (!psFitsClose(fits)) { 475 psError(psErrorCodeLast(), false, "Failed to close file %s", realName); 476 psFree(realName); 477 psFree(phu); 478 return NULL; 479 } 480 481 return phu; 482 } 483 484 // this this function wants to return: 485 // pmFPA, PHU, fileLevel, outConfig 486 // camera, cameraName, formatName 487 typedef struct { 488 pmFPA *fpa; 489 psMetadata *phu; 490 psMetadata *format; 491 pmFPALevel fileLevel; 492 psString cameraName; 493 psString formatName; 494 } pmFPAfromFilenameOutput; 495 496 // for the given filename, read PHU and determine camera format; build an FPA for the file 497 bool pmFPAfromFilename (pmFPAfromFilenameOutput *output, pmConfig **outConfig, pmConfig *sysConfig, char *filename){ 498 499 // Need to generate an FPA 500 psMetadata *phu = readPHUfromFilename (filename, sysConfig); 501 if (!phu) { 502 psError(psErrorCodeLast(), false, "Failed to read PHU for %s", filename); 503 return false; 504 } 505 506 // if we expect the loaded FPA to differ in configuration from the current system configuration 507 // generate an output config for this FPA 508 pmConfig *config = NULL; 509 if (outConfig) { 510 config = pmConfigAlloc(); 511 config->user = psMemIncrRefCounter(sysConfig->user); 512 config->system = psMemIncrRefCounter(sysConfig->system); 513 514 psFree (config->files); 515 config->files = psMemIncrRefCounter(sysConfig->files); 516 psFree (config->arguments); 517 config->arguments = psMemIncrRefCounter(sysConfig->arguments); 518 519 *outConfig = config; 520 } else { 521 config = sysConfig; 522 } 523 524 // values which are returned to calling function 525 psString formatName = NULL; // Name of camera format 526 psString cameraName = NULL; // Name of camera 527 psMetadata *camera = NULL; // Camera configuration 528 529 // Determine the current format from the header; determine camera if not specified already. 530 psMetadata *format = pmConfigCameraFormatFromHeader(&camera, &cameraName, &formatName, config, phu, true); 531 if (!format) { 532 psError(psErrorCodeLast(), false, "Failed to determine camera format for %s", filename); 533 psFree(camera); 534 psFree(formatName); 535 psFree(phu); 536 return false; 537 } 538 539 pmFPALevel fileLevel = pmFPAPHULevel(format); 540 if (fileLevel == PM_FPA_LEVEL_NONE) { 541 psError(PM_ERR_CONFIG, true, "Unable to determine file level for %s", filename); 542 psFree(camera); 543 psFree(formatName); 544 psFree(phu); 545 return false; 546 } 547 548 // build the template fpa, set up the basic view 549 // we supply the metaCamera name (if NULL, baseCamera name is used) 550 pmFPA *fpa = pmFPAConstruct(camera, cameraName); 551 psFree(camera); 552 553 if (!fpa) { 554 psError(psErrorCodeLast(), false, "Failed to construct FPA from %s", filename); 555 psFree(formatName); 556 psFree(format); 557 psFree(phu); 558 return NULL; 559 } 560 561 output->fpa = fpa; 562 output->phu = phu; 563 output->format = format; 564 output->fileLevel = fileLevel; 565 output->cameraName = cameraName; 566 output->formatName = formatName; 567 568 return true; 569 570 } 448 571 449 572 /// Define a file from an array of filenames 450 static pmFPAfile *fpaFileDefineFromArray(pmConfig *config, // Configuration 573 static pmFPAfile *fpaFileDefineFromArray(pmConfig **outConfig, // output configuration 574 pmConfig *sysConfig, // global configuration 451 575 pmFPAfile *bind, // File to bind to, or NULL 452 576 const char *name, // Name of file … … 454 578 ) 455 579 { 456 PS_ASSERT_PTR_NON_NULL( config, NULL);580 PS_ASSERT_PTR_NON_NULL(sysConfig, NULL); 457 581 PS_ASSERT_STRING_NON_EMPTY(name, NULL); 458 582 … … 463 587 pmFPALevel fileLevel = PM_FPA_LEVEL_NONE; // Level for files 464 588 psMetadata *phu = NULL; // Primary header 589 465 590 if (bind) { 466 591 // Use the FPA we're binding to … … 468 593 fileLevel = bind->fileLevel; 469 594 } else { 470 // Need to generate an FPA 471 psString realName = pmConfigConvertFilename(filenames->data[0], config, false, false); 472 if (!realName) { 473 psError(psErrorCodeLast(), false, "Failed to convert file name %s", (char *)filenames->data[0]); 474 return NULL; 475 } 476 477 // load the header of the first image 478 // EXTWORD (fits->extword) is not relevant to the PHU 479 psFits *fits = psFitsOpen(realName, "r"); // FITS file 480 if (!fits) { 481 psError(psErrorCodeLast(), false, "Failed to open file %s", realName); 482 psFree(realName); 483 return NULL; 484 } 485 phu = psFitsReadHeader (NULL, fits); // Primary header 486 if (!phu) { 487 psError(psErrorCodeLast(), false, "Failed to read file header %s", realName); 488 psFree(realName); 489 return NULL; 490 } 491 if (!psFitsClose(fits)) { 492 psError(psErrorCodeLast(), false, "Failed to close file %s", realName); 493 psFree(realName); 494 return NULL; 495 } 496 497 // Determine the current format from the header; determine camera if not specified already. 498 psMetadata *camera = NULL; // Camera configuration 499 format = pmConfigCameraFormatFromHeader(&camera, &cameraName, &formatName, config, phu, true); 500 if (!format) { 501 psError(psErrorCodeLast(), false, "Failed to determine camera format for %s", realName); 502 psFree(camera); 503 psFree(formatName); 504 psFree(realName); 505 psFree(phu); 506 return NULL; 507 } 508 509 fileLevel = pmFPAPHULevel(format); 510 if (fileLevel == PM_FPA_LEVEL_NONE) { 511 psError(PM_ERR_CONFIG, true, "Unable to determine file level for %s", realName); 512 psFree(camera); 513 psFree(formatName); 514 psFree(realName); 515 psFree(phu); 516 return NULL; 517 } 518 519 // build the template fpa, set up the basic view 520 // XXX do we want this to be the baseCamera name or the metaCamera name? 521 fpa = pmFPAConstruct(camera, cameraName); 522 psFree(camera); 523 if (!fpa) { 524 psError(psErrorCodeLast(), false, "Failed to construct FPA from %s", realName); 525 psFree(formatName); 526 psFree(realName); 527 psFree(format); 528 psFree(phu); 529 return NULL; 530 } 531 psFree(realName); 532 } 595 pmFPAfromFilenameOutput output; 596 if (!pmFPAfromFilename (&output, outConfig, sysConfig, filenames->data[0])) { 597 return NULL; 598 } 599 fpa = output.fpa; 600 phu = output.phu; 601 format = output.format; 602 fileLevel = output.fileLevel; 603 cameraName = output.cameraName; 604 formatName = output.formatName; 605 } 606 607 pmConfig *config = outConfig ? *outConfig : sysConfig; 533 608 534 609 // load the given filerule (from config->camera) and bind it to the fpa … … 561 636 // Check that the file corresponds to the same camera and format 562 637 if (!phu) { 563 psString realName = pmConfigConvertFilename(filenames->data[i], config, false, false);564 if (! realName) {565 psError(psErrorCodeLast(), false, "Failed to convert file name %s", (char*)filenames->data[i]);638 phu = readPHUfromFilename (filenames->data[i], config); 639 if (!phu) { 640 psError(psErrorCodeLast(), false, "Failed to read PHU for %s", (char *)filenames->data[i]); 566 641 return NULL; 567 642 } 568 psFits *fits = psFitsOpen(realName, "r"); // FITS file569 if (!fits) {570 psError(psErrorCodeLast(), false, "Failed to open file %s", realName);571 psFree(realName);572 return NULL;573 }574 phu = psFitsReadHeader(NULL, fits);575 if (!psFitsClose(fits)) {576 psError(psErrorCodeLast(), false, "Failed to close file %s", realName);577 psFree(realName);578 return NULL;579 }580 if (!phu) {581 psError(psErrorCodeLast(), false, "Failed to read file header %s", realName);582 psFree(realName);583 return NULL;584 }585 psFree(realName);586 643 } 587 644 … … 651 708 } 652 709 653 654 pmFPAfile *pmFPAfileDefineFromArgs(bool *success, pmConfig *config, 655 const char *filename, const char *argname) 710 // find the file associated with the argname & generate a pmFPAfile for it based on the filerule 711 pmFPAfile *pmFPAfileDefineFromArgs(bool *success, pmConfig *config, const char *filename, const char *argname) 656 712 { 657 713 PS_ASSERT_PTR_NON_NULL(config, NULL); … … 676 732 } 677 733 678 pmFPAfile *file = fpaFileDefineFromArray( config, NULL, filename, filenames); // File of interest734 pmFPAfile *file = fpaFileDefineFromArray(NULL, config, NULL, filename, filenames); // File of interest 679 735 680 736 if (success) { … … 685 741 } 686 742 687 pmFPAfile *pmFPAfileBindFromArgs(bool *success, pmFPAfile *input, pmConfig *config, 688 const char *filename, const char *argname)743 // find the file associated with the argname & bind it to the given pmFPAfile for it based on the filerule 744 pmFPAfile *pmFPAfileBindFromArgs(bool *success, pmFPAfile *input, pmConfig *config, const char *filename, const char *argname) 689 745 { 690 746 PS_ASSERT_PTR_NON_NULL(input, NULL); … … 710 766 } 711 767 712 pmFPAfile *file = fpaFileDefineFromArray( config, input, filename, filenames); // File of interest768 pmFPAfile *file = fpaFileDefineFromArray(NULL, config, input, filename, filenames); // File of interest 713 769 714 770 if (success) { … … 719 775 } 720 776 721 pmFPAfile *pmFPAfileDefineSingleFromArgs(bool *success, pmConfig *config, const char *filename, 722 const char *argname, int entry)777 // find the specific file associated with the argname & generate a pmFPAfile for it based on the filerule 778 pmFPAfile *pmFPAfileDefineSingleFromArgs(bool *success, pmConfig *config, const char *filename, const char *argname, int entry) 723 779 { 724 780 PS_ASSERT_PTR_NON_NULL(config, NULL); … … 746 802 psArray *single = psArrayAlloc(1); // Array of single filename of interest 747 803 single->data[0] = psMemIncrRefCounter(filenames->data[entry]); 748 pmFPAfile *file = fpaFileDefineFromArray( config, NULL, filename, single); // File of interest804 pmFPAfile *file = fpaFileDefineFromArray(NULL, config, NULL, filename, single); // File of interest 749 805 psFree(single); 750 806 … … 756 812 } 757 813 814 // find the file in the config list & generate a pmFPAfile for it based on the filerule 758 815 pmFPAfile *pmFPAfileDefineFromRun(bool *success, pmFPAfile *bind, pmConfig *config, const char *filename) 759 816 { … … 769 826 } 770 827 771 pmFPAfile *file = fpaFileDefineFromArray( config, bind, filename, filenames); // File of interest828 pmFPAfile *file = fpaFileDefineFromArray(NULL, config, bind, filename, filenames); // File of interest 772 829 psFree(filenames); 773 830 … … 779 836 } 780 837 838 // find the files in the config list & generate an array of pmFPAfiles for them based on the filerule 781 839 psArray *pmFPAfileDefineMultipleFromRun(bool *success, psArray *bind, pmConfig *config, const char *filename) 782 840 { … … 808 866 dummy->data[0] = files->data[i]; 809 867 pmFPAfile *bindFile = bind ? bind->data[i] : NULL; // File to which to bind 810 files->data[i] = psMemIncrRefCounter(fpaFileDefineFromArray( config, bindFile, filename, dummy));868 files->data[i] = psMemIncrRefCounter(fpaFileDefineFromArray(NULL, config, bindFile, filename, dummy)); 811 869 if (!files->data[i]) { 812 870 psError(psErrorCodeLast(), false, "Unable to define file %s %d", filename, i); … … 823 881 824 882 return files; 883 } 884 885 // find the file associated with the argname & generate a pmFPAfile for it based on the filerule 886 pmFPAfile *pmFPAfileDefineNewConfig(bool *success, pmConfig **outConfig, pmConfig *sysConfig, const char *filename, const char *argname) 887 { 888 PS_ASSERT_PTR_NON_NULL(outConfig, NULL); 889 PS_ASSERT_PTR_NON_NULL(sysConfig, NULL); 890 PS_ASSERT_STRING_NON_EMPTY(filename, NULL); 891 PS_ASSERT_STRING_NON_EMPTY(argname, NULL); 892 893 // Search the argument data for the named fileset (argname) 894 bool status; // Status of MD lookup 895 psArray *filenames = psMetadataLookupPtr(&status, sysConfig->arguments, argname); // Filenames for file 896 if (!status) { 897 if (success) { 898 *success = true; 899 } 900 return NULL; 901 } 902 if (filenames->n == 0) { 903 psError(PM_ERR_CONFIG, true, "No files in array in %s in arguments", argname); 904 if (success) { 905 *success = false; 906 } 907 return NULL; 908 } 909 910 pmFPAfile *file = fpaFileDefineFromArray(outConfig, sysConfig, NULL, filename, filenames); // File of interest 911 912 if (success) { 913 *success = file ? true : false; 914 } 915 916 return file; 825 917 } 826 918
Note:
See TracChangeset
for help on using the changeset viewer.
