Changeset 6819
- Timestamp:
- Apr 8, 2006, 10:13:03 AM (20 years ago)
- Location:
- branches/rel10_ifa/psModules/src
- Files:
-
- 4 edited
-
astrom/pmFPAfile.c (modified) (9 diffs)
-
astrom/pmFPAfile.h (modified) (4 diffs)
-
config/pmConfig.c (modified) (5 diffs)
-
config/pmConfig.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c
r6755 r6819 67 67 } 68 68 69 pmFPAfile *pmFPAfileDefine (psMetadata *files, psMetadata * format, pmFPA *fpa, char *name)69 pmFPAfile *pmFPAfileDefine (psMetadata *files, psMetadata *camera, pmFPA *fpa, char *name) 70 70 { 71 71 … … 74 74 char *type; 75 75 76 // select the FILERULES from the camera format77 psMetadata *filerules = psMetadataLookupPtr (&status, format, "FILERULES");76 // select the FILERULES from the camera config 77 psMetadata *filerules = psMetadataLookupPtr (&status, camera, "FILERULES"); 78 78 if (filerules == NULL) { 79 psErrorStackPrint(stderr, "Can't find FILERULES in the FORMATconfiguration!\n");79 psErrorStackPrint(stderr, "Can't find FILERULES in the CAMERA configuration!\n"); 80 80 return NULL; 81 81 } 82 82 83 83 // select the name from the FILERULES 84 // check for indirectname (type == STR, name is aliased name)84 // check for alias name (type == STR, name is aliased name) 85 85 char *realname = psMetadataLookupStr (&status, filerules, name); 86 86 if (realname == NULL) … … 179 179 } 180 180 181 file->fpa = psMemIncrRefCounter(fpa); 181 if (fpa != NULL) { 182 file->fpa = psMemIncrRefCounter(fpa); 183 } 182 184 183 185 psMetadataAddPtr (files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file); … … 190 192 } 191 193 194 /* 192 195 pmFPAfile *pmFPAfileConstruct (psMetadata *files, psMetadata *format, psMetadata *camera, char *name) 193 196 { … … 197 200 return file; 198 201 } 202 */ 199 203 200 204 // open file (if not already opened) … … 228 232 229 233 // indirect filenames 230 if (!strcasecmp (file->filename, "@F PAIO")) {234 if (!strcasecmp (file->filename, "@FILES")) { 231 235 psFree (file->filename); 232 236 extra = pmFPAfileNameFromRule (file->filextra, file, view); … … 252 256 case PM_FPA_FILE_IMAGE: 253 257 case PM_FPA_FILE_CMF: 258 psTrace ("pmFPAfile", 5, "opening %s (type: %d)\n", file->filename, file->type); 254 259 file->fits = psFitsOpen (file->filename, mode); 255 psTrace ("pmFPAfile", 5, "opening %s (type: %d)\n", file->filename, file->type); 260 if (file->fits == NULL) 261 psAbort (__func__, "error opening file %s\n", file->filename); 256 262 file->state = PM_FPA_STATE_OPEN; 257 263 break; … … 410 416 psFree (iter); 411 417 return true; 412 }413 414 // select the rule from the camera configuration, perform substitutions as needed415 char *pmFPAfileNameFromRule (char *rule, pmFPAfile *file, const pmFPAview *view)416 {417 418 char *newName = NULL; // destination for resulting name419 420 newName = psStringCopy (rule);421 422 if (strstr (newName, "{CHIP.NAME}") != NULL) {423 pmChip *chip = pmFPAviewThisChip (view, file->fpa);424 if (chip != NULL) {425 char *name = psMetadataLookupStr (NULL, chip->concepts, "CHIP.NAME");426 if (name != NULL) {427 newName = psStringSubstitute (newName, name, "{CHIP.NAME}");428 }429 }430 }431 if (strstr (newName, "{CELL.NAME}") != NULL) {432 pmCell *cell = pmFPAviewThisCell (view, file->fpa);433 if (cell != NULL) {434 char *name = psMetadataLookupStr (NULL, cell->concepts, "CELL.NAME");435 if (name != NULL) {436 newName = psStringSubstitute (newName, name, "{CELL.NAME}");437 }438 }439 }440 if (strstr (newName, "{EXTNAME}") != NULL) {441 pmHDU *hdu = pmFPAviewThisHDU (view, file->fpa);442 if (hdu->extname != NULL) {443 newName = psStringSubstitute (newName, hdu->extname, "{EXTNAME}");444 }445 }446 if (strstr (newName, "{OUTPUT}") != NULL) {447 char *name = psMetadataLookupStr (NULL, file->names, "OUTPUT");448 if (name != NULL) {449 newName = psStringSubstitute (newName, name, "{OUTPUT}");450 }451 }452 return newName;453 418 } 454 419 … … 606 571 # endif 607 572 } 573 574 // look for the given name on the argument list. 575 // returns the file (a view to the one saved on config->files) 576 pmFPAfile *pmFPAfileFromArgs (bool *found, pmConfig *config, char *filename, char *argname) 577 { 578 bool status; 579 pmFPA *fpa = NULL; 580 psFits *fits = NULL; 581 pmFPAfile *file = NULL; 582 psMetadata *phu = NULL; 583 psMetadata *format = NULL; 584 585 if (*found) 586 return NULL; 587 588 // we search the argument data for the named fileset (argname) 589 psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname); 590 if (!status) 591 return NULL; 592 if (infiles->n < 1) 593 return NULL; 594 595 // determine the current format from the header 596 // if no camera has been specified, use the first image as a template for the rest. 597 fits = psFitsOpen (infiles->data[0], "r"); 598 phu = psFitsReadHeader (NULL, fits); 599 format = pmConfigCameraFormatFromHeader (config, phu); 600 psFitsClose (fits); 601 602 // build the template fpa, set up the basic view 603 fpa = pmFPAConstruct (config->camera); 604 605 // load the given filerule (from config->camera) and associate it with the fpa 606 // the output file is just a view to the file on config->files 607 file = pmFPAfileDefine (config->files, config->camera, fpa, filename); 608 if (!file) { 609 psErrorStackPrint(stderr, "file %s not defined\n", filename); 610 psFree (fpa); 611 psFree (format); 612 return NULL; 613 } 614 615 // this file is (by virtue of being supplied in the argument list) coming from the fileset 616 psFree (file->filerule); 617 psFree (file->filextra); 618 619 // adjust the rules to identify these files in the file->names data 620 file->filerule = psStringCopy ("@FILES"); 621 // XXX this rule does not work in general 622 file->filextra = psStringCopy ("{CHIP.NAME}.{CELL.NAME}"); 623 624 // examine the list of input files and validate their cameras 625 for (int i = 0; i < infiles->n; i++) { 626 if (i > 0) { 627 fits = psFitsOpen (infiles->data[i], "r"); 628 phu = psFitsReadHeader (NULL, fits); 629 pmConfigValidateCameraFormat (format, phu); 630 psFitsClose (fits); 631 } 632 633 // set the view to the corresponding entry for this phu 634 pmFPAview *view = pmFPAAddSource (fpa, phu, format); 635 636 // XXX is this the correct psMD to save the filename? 637 char *name = pmFPAfileNameFromRule (file->filextra, file, view); 638 psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]); 639 640 psFree (view); 641 psFree (name); 642 psFree (phu); 643 } 644 psFree (fpa); 645 psFree (format); 646 *found = true; 647 648 return file; 649 } 650 651 // look for the given name on the argument list. 652 pmFPAfile *pmFPAfileFromConf (bool *found, pmConfig *config, char *filename, pmFPA *input) 653 { 654 psFits *fits = NULL; 655 pmFPAfile *file = NULL; 656 psMetadata *phu = NULL; 657 psMetadata *format = NULL; 658 psArray *infiles = NULL; 659 660 if (*found) 661 return NULL; 662 663 // a camera config is needed (as source of file rule) 664 if (config->camera == NULL) { 665 psErrorStackPrint (stderr, "camera is not defined\n"); 666 return NULL; 667 } 668 669 // expect @DETDB in the config filerule 670 file = pmFPAfileDefine (config->files, config->camera, NULL, filename); 671 if (!file) { 672 psErrorStackPrint(stderr, "file %s not defined\n", filename); 673 return NULL; 674 } 675 676 // image names come from the file->name list? 677 if (!strcasecmp (file->filerule, "@FILES")) 678 psAbort ("pmFPAfileFromConfig", "programming error"); 679 680 // image needs to come from the detrend database 681 if (!strcasecmp (file->filerule, "@DETDB")) { 682 // char *extra = pmFPAfileNameFromRule (file->filextra, file, view); 683 // psArray *infiles = pmDetrendSelect (extra, input); 684 psAbort ("pmFPAfileFromConfig", "@DETDB not yet defined"); 685 } else { 686 infiles = psArrayAlloc(1); 687 infiles->n = 1; 688 infiles->data[0] = psStringCopy (file->filerule); 689 } 690 if (infiles == NULL) 691 return NULL; 692 if (infiles->n < 1) { 693 psFree (infiles); 694 return NULL; 695 } 696 697 // determine the current format from the header 698 // if no camera has been specified, use the first image as a template for the rest. 699 fits = psFitsOpen (infiles->data[0], "r"); 700 phu = psFitsReadHeader (NULL, fits); 701 format = pmConfigCameraFormatFromHeader (config, phu); 702 psFitsClose (fits); 703 704 // build the template fpa, set up the basic view 705 file->fpa = pmFPAConstruct (config->camera); 706 707 // this file is (by virtue of being supplied in the argument list) coming from the fileset 708 psFree (file->filerule); 709 psFree (file->filextra); 710 711 // adjust the rules to identify these files in the file->names data 712 file->filerule = psStringCopy ("@FILES"); 713 // XXX this rule does not work in general 714 file->filextra = psStringCopy ("{CHIP.NAME}.{CELL.NAME}"); 715 716 // examine the list of input files and validate their cameras 717 for (int i = 0; i < infiles->n; i++) { 718 if (i > 0) { 719 fits = psFitsOpen (infiles->data[i], "r"); 720 phu = psFitsReadHeader (NULL, fits); 721 pmConfigValidateCameraFormat (format, phu); 722 psFitsClose (fits); 723 } 724 725 // set the view to the corresponding entry for this phu 726 pmFPAview *view = pmFPAAddSource (file->fpa, phu, format); 727 728 // XXX is this the correct psMD to save the filename? 729 char *name = pmFPAfileNameFromRule (file->filextra, file, view); 730 psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]); 731 732 psFree (view); 733 psFree (name); 734 psFree (phu); 735 } 736 psFree (format); 737 psFree (infiles); 738 *found = true; 739 return file; 740 } 741 742 bool pmFPAfileAddFileNames (psMetadata *files, char *name, char *value, int mode) 743 { 744 745 // add the output names to the output-type files 746 psMetadataItem *item = NULL; 747 psMetadataIterator *iter = psMetadataIteratorAlloc (files, PS_LIST_HEAD, NULL); 748 while ((item = psMetadataGetAndIncrement (iter)) != NULL) { 749 pmFPAfile *file = item->data.V; 750 751 if (file->mode == mode) { 752 psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", value); 753 } 754 } 755 psFree (iter); 756 return true; 757 } 758 759 // select the rule from the camera configuration, perform substitutions as needed 760 char *pmFPAfileNameFromRule (char *rule, pmFPAfile *file, const pmFPAview *view) 761 { 762 763 char *newName = NULL; // destination for resulting name 764 765 newName = psStringCopy (rule); 766 767 if (strstr (newName, "{CHIP.NAME}") != NULL) { 768 pmChip *chip = pmFPAviewThisChip (view, file->fpa); 769 if (chip != NULL) { 770 char *name = psMetadataLookupStr (NULL, chip->concepts, "CHIP.NAME"); 771 if (name != NULL) { 772 newName = psStringSubstitute (newName, name, "{CHIP.NAME}"); 773 } 774 } 775 } 776 if (strstr (newName, "{CELL.NAME}") != NULL) { 777 pmCell *cell = pmFPAviewThisCell (view, file->fpa); 778 if (cell != NULL) { 779 char *name = psMetadataLookupStr (NULL, cell->concepts, "CELL.NAME"); 780 if (name != NULL) { 781 newName = psStringSubstitute (newName, name, "{CELL.NAME}"); 782 } 783 } 784 } 785 if (strstr (newName, "{EXTNAME}") != NULL) { 786 pmHDU *hdu = pmFPAviewThisHDU (view, file->fpa); 787 if (hdu->extname != NULL) { 788 newName = psStringSubstitute (newName, hdu->extname, "{EXTNAME}"); 789 } 790 } 791 if (strstr (newName, "{OUTPUT}") != NULL) { 792 char *name = psMetadataLookupStr (NULL, file->names, "OUTPUT"); 793 if (name != NULL) { 794 newName = psStringSubstitute (newName, name, "{OUTPUT}"); 795 } 796 } 797 return newName; 798 } 799 -
branches/rel10_ifa/psModules/src/astrom/pmFPAfile.h
r6726 r6819 7 7 * @author EAM, IfA 8 8 * 9 * @version $Revision: 1.1.2. 8$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-0 3-29 20:55:42$9 * @version $Revision: 1.1.2.9 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-04-08 20:13:03 $ 11 11 * 12 12 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii … … 17 17 18 18 #include "pslib.h" 19 #include "pmConfig.h" 19 20 #include "pmFPA.h" 20 21 #include "pmFPAview.h" … … 72 73 pmFPAfile; 73 74 75 // allocate an empty pmFPAfile structure 74 76 pmFPAfile *pmFPAfileAlloc (); 77 78 // load the pmFPAfile information from the camera configuration data 75 79 pmFPAfile *pmFPAfileDefine (psMetadata *files, psMetadata *camera, pmFPA *fpa, char *name); 80 81 // load the pmFPAfile information from the camera configuration data, constructing the needed fpa structure 82 // XXX deprecate this function? 83 pmFPAfile *pmFPAfileConstruct (psMetadata *files, psMetadata *format, psMetadata *camera, char *name); 84 85 // open the real file corresponding to the given pmFPAfile appropriate to the current view 76 86 bool pmFPAfileOpen (pmFPAfile *file, const pmFPAview *view); 87 88 // read from the real file corresponding to the given pmFPAfile for the current view 77 89 bool pmFPAfileRead (pmFPAfile *file, const pmFPAview *view); 90 91 // write to the real file corresponding to the given pmFPAfile for the current view 78 92 bool pmFPAfileWrite (pmFPAfile *file, const pmFPAview *view); 93 94 // close the real file corresponding to the given pmFPAfile appropriate to the current view 79 95 bool pmFPAfileClose (pmFPAfile *file, const pmFPAview *view); 80 96 81 bool pmFPAfileReadChecks (psMetadata *files, const pmFPAview *view); 97 // examine all pmFPAfiles listed in the files and perform the needed I/O operations (open,read,write,close) 82 98 bool pmFPAfileIOChecks (psMetadata *files, const pmFPAview *view, pmFPAfilePlace place); 83 99 100 // return an image corresponding to the current readout, from the specified file. if the pmFPAfile does not 101 // exist, construct the image using the given size and type (save it in a pmFPAfile??) 84 102 psImage *pmFPAfileReadoutImage (psMetadata *files, const pmFPAview *view, char *name, int Nx, int Ny, int type); 85 103 … … 90 108 bool pmFPAviewWriteFitsImage (const pmFPAview *view, pmFPAfile *file); 91 109 110 // look for the given argname on the argument list. find the give filename from the file rules 111 pmFPAfile *pmFPAfileFromArgs (bool *found, pmConfig *config, char *filename, char *argname); 112 113 // look for the given argname on the argument list. find the give filename from the file rules 114 pmFPAfile *pmFPAfileFromConf (bool *found, pmConfig *config, char *filename, pmFPA *input); 115 116 // add the specified filename info (value) to the files of the given mode using the given reference name 117 bool pmFPAfileAddFileNames (psMetadata *files, char *name, char *value, int mode); 118 92 119 // convert the rule to a name based on the current view 93 120 char *pmFPAfileNameFromRule (char *rule, pmFPAfile *file, const pmFPAview *view); 94 121 95 pmFPAfile *pmFPAfileConstruct (psMetadata *files, psMetadata *format, psMetadata *camera, char *name);96 97 122 # endif -
branches/rel10_ifa/psModules/src/config/pmConfig.c
r6773 r6819 3 3 * @author PAP, IfA 4 4 * 5 * @version $Revision: 1.7.4. 9$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-04-0 4 22:14:58$5 * @version $Revision: 1.7.4.10 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-04-08 20:13:03 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 15 15 #include <sys/types.h> 16 16 #include <sys/stat.h> 17 #include <glob.h> 17 18 #include "pslib.h" 18 19 #include "pmConfig.h" … … 40 41 // Initialise 41 42 config->site = NULL; 42 config->files = NULL;43 43 config->camera = NULL; 44 44 config->recipes = NULL; … … 46 46 config->database = NULL; 47 47 48 // the file structure is used to carry pmFPAfiles 49 config->files = psMetadataAlloc (); 48 50 return config; 49 51 } … … 656 658 return true; 657 659 } 660 661 // given the 'file' and 'list' words, find the arguments associated with these words 662 // and interpret them as lists of files. return an array of the resulting filenames. 663 psArray *pmConfigFileSets (int *argc, char **argv, char *file, char *list) 664 { 665 666 int Narg; 667 668 // we load all input files onto a psArray, to be parsed later 669 psArray *input = psArrayAlloc (16); 670 input->n = 0; 671 672 // load the list of filenames the supplied file (may be a glob: "file*.fits") 673 if ((Narg = psArgumentGet (*argc, argv, file))) { 674 glob_t globList; 675 psArgumentRemove (Narg, argc, argv); 676 globList.gl_offs = 0; 677 glob (argv[Narg], 0, NULL, &globList); 678 for (int i = 0; i < globList.gl_pathc; i++) { 679 char *filename = psStringCopy (globList.gl_pathv[i]); 680 psArrayAdd (input, 16, filename); 681 psFree (filename); 682 } 683 psArgumentRemove (Narg, argc, argv); 684 } 685 686 // load the list from the supplied text file 687 if ((Narg = psArgumentGet (*argc, argv, list))) { 688 int nItems; 689 char line[1024]; // XXX limits the list lines to 1024 chars 690 char word[1024]; 691 char *filename; 692 693 psArgumentRemove (Narg, argc, argv); 694 FILE *f = fopen (argv[Narg], "r"); 695 if (f == NULL) { 696 psAbort ("psphot", "unable to open specified list file"); 697 } 698 while (fgets (line, 1024, f) != NULL) { 699 nItems = sscanf (line, "%s", word); 700 switch (nItems) { 701 case 0: 702 break; 703 case 1: 704 filename = psStringCopy (word); 705 psArrayAdd (input, 16, filename); 706 psFree (filename); 707 break; 708 default: 709 // rigid format, no comments allowed? 710 psAbort ("pmConfig", "error parsing input list file"); 711 break; 712 } 713 } 714 psArgumentRemove (Narg, argc, argv); 715 } 716 717 return input; 718 } 719 720 bool pmConfigFileSetsMD (psMetadata *metadata, int *argc, char **argv, char *name, char *file, char *list) 721 { 722 723 psArray *files = pmConfigFileSets (argc, argv, file, list); 724 if (files->n == 0) { 725 psFree (files); 726 return false; 727 } 728 729 psMetadataAddPtr (metadata, PS_LIST_TAIL, name, PS_DATA_ARRAY, "", files); 730 psFree (files); 731 return true; 732 } -
branches/rel10_ifa/psModules/src/config/pmConfig.h
r6773 r6819 3 3 * @author PAP, IfA 4 4 * 5 * @version $Revision: 1.3.4. 6$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-04-0 4 22:14:58$5 * @version $Revision: 1.3.4.7 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-04-08 20:13:03 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 23 23 psMetadata *arguments; // Command-line arguments 24 24 psMetadata *files; // pmFPAfiles used for analysis 25 // psMetadata *format; // camera format for primary image 25 26 psDB *database; // Database handle 26 27 } … … 112 113 113 114 115 psArray *pmConfigFileSets (int *argc, char **argv, char *file, char *list); 116 bool pmConfigFileSetsMD (psMetadata *metadata, int *argc, char **argv, char *name, char *file, char *list); 117 118 114 119 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
