Changeset 17634
- Timestamp:
- May 12, 2008, 11:41:55 AM (18 years ago)
- Location:
- trunk/psModules/src/camera
- Files:
-
- 2 edited
-
pmFPAfileDefine.c (modified) (39 diffs)
-
pmFPAfileDefine.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAfileDefine.c
r17489 r17634 87 87 } 88 88 89 pmFPAfile *file = pmFPAfileAlloc ();89 pmFPAfile *file = pmFPAfileAlloc(); 90 90 91 91 // save the name of this pmFPAfile 92 file->name = psStringCopy (name);92 file->name = psStringCopy(name); 93 93 94 94 file->filerule = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "FILENAME.RULE")); 95 95 96 type = psMetadataLookupStr (&status, data, "FILE.TYPE");96 type = psMetadataLookupStr(&status, data, "FILE.TYPE"); 97 97 file->type = pmFPAfileTypeFromString(type); 98 98 if (file->type == PM_FPA_FILE_NONE) { 99 99 psError(PS_ERR_IO, true, "FILE.TYPE is not defined for %s\n", name); 100 psFree(file); 100 101 return NULL; 101 102 } … … 107 108 if (file->dataLevel == PM_FPA_LEVEL_NONE) { 108 109 psError(PS_ERR_IO, true, "DATA.LEVEL is not set for %s\n", name); 110 psFree(file); 109 111 return NULL; 110 112 } … … 125 127 // XXX ppFocus wants to override the selection with the new selection 126 128 // XXX require programs like ppFocus to remove existing files by hand 127 if (!psMetadataAddPtr (config->files, PS_LIST_TAIL, name,128 PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", file)) {129 psError (PS_ERR_IO, false, "could not add %s to config files", name);130 return NULL; 131 } 132 psFree (file);133 return (file);129 if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, name, 130 PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", file)) { 131 psError(PS_ERR_IO, false, "could not add %s to config files", name); 132 return NULL; 133 } 134 psFree(file); 135 return file; 134 136 } 135 137 … … 242 244 if (fitsType && strcasecmp(fitsType, "NONE") != 0) { 243 245 244 // load the FITSTYPE scheme for this file245 psMetadata *scheme = pmConfigFitsType(config, camera, fitsType); // File rule246 // load the FITSTYPE scheme for this file 247 psMetadata *scheme = pmConfigFitsType(config, camera, fitsType); // File rule 246 248 if (!scheme) { 247 // XXX change to a config error?249 // XXX change to a config error? 248 250 psWarning("Unable to find %s in FITS in camera configuration --- will use defaults.", fitsType); 249 251 goto FITS_OPTIONS_DONE; … … 375 377 // place the resulting file in the config system 376 378 psMetadataAddPtr (config->files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file); 377 psFree (file);// we free this copy of file, but 'files' still has a copy378 return (file);// the returned value is a view into the version on 'files'379 psFree(file); // we free this copy of file, but 'files' still has a copy 380 return file; // the returned value is a view into the version on 'files' 379 381 } 380 382 … … 429 431 430 432 // use success to identify valid exit conditions (as opposed to 'argument not supplied') 431 if (success) *success = false; 433 if (success) { 434 *success = false; 435 } 432 436 433 437 // we search the argument data for the named fileset (argname) 434 438 psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname); 435 439 if (!status) { 436 if (success) *success = true; 440 if (success) { 441 *success = true; 442 } 437 443 return NULL; 438 444 } … … 467 473 // determine the current format from the header 468 474 // determine camera if not specified already 469 format = pmConfigCameraFormatFromHeader (config, phu, true);475 format = pmConfigCameraFormatFromHeader(config, phu, true); 470 476 if (!format) { 471 477 psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", realName); … … 476 482 477 483 // build the template fpa, set up the basic view 478 fpa = pmFPAConstruct (config->camera);484 fpa = pmFPAConstruct(config->camera); 479 485 if (!fpa) { 480 486 psError(PS_ERR_IO, false, "Failed to construct FPA from %s", realName); … … 486 492 // load the given filerule (from config->camera) and bind it to the fpa 487 493 // the returned file is just a view to the entry on config->files 488 file = pmFPAfileDefineInput (config, fpa, filename);494 file = pmFPAfileDefineInput(config, fpa, filename); 489 495 if (!file) { 490 496 psError(PS_ERR_IO, false, "file %s not defined\n", filename); … … 500 506 // adjust the rules to identify these files in the file->names data 501 507 psFree (file->filerule); 502 file->filerule = psStringCopy ("@FILES");503 file->filesrc = psStringCopy ("{CHIP.NAME}.{CELL.NAME}");508 file->filerule = psStringCopy("@FILES"); 509 file->filesrc = psStringCopy("{CHIP.NAME}.{CELL.NAME}"); 504 510 505 511 file->fileLevel = pmFPAPHULevel(format); … … 509 515 psFree(fpa); 510 516 psFree(format); 511 psFree(file);512 517 return NULL; 513 518 } … … 528 533 if (!fits) { 529 534 psError(PS_ERR_IO, false, "Failed to open file %s\n", realName); 530 psFree (realName);535 psFree(realName); 531 536 return NULL; 532 537 } … … 534 539 if (!phu) { 535 540 psError(PS_ERR_IO, false, "Failed to read file header %s", realName); 536 psFree (realName);537 psFitsClose (fits);541 psFree(realName); 542 psFitsClose(fits); 538 543 return NULL; 539 544 } 540 545 bool valid = false; 541 546 if (!pmConfigValidateCameraFormat (&valid, format, phu)) { 542 psError (PS_ERR_UNKNOWN, false, "Error in config scripts\n");543 psFree (realName);544 psFitsClose (fits);547 psError(PS_ERR_UNKNOWN, false, "Error in config scripts\n"); 548 psFree(realName); 549 psFitsClose(fits); 545 550 return NULL; 546 551 } 547 552 if (!valid) { 548 553 psError(PS_ERR_IO, false, "file %s is not from the required camera", realName); 549 psFree (realName);550 psFitsClose (fits);554 psFree(realName); 555 psFitsClose(fits); 551 556 return NULL; 552 557 } 553 558 psFree(realName); 554 psFitsClose (fits);559 psFitsClose(fits); 555 560 } 556 561 … … 560 565 psError(PS_ERR_IO, false, "Unable to determine source for %s", file->name); 561 566 psFree(phu); 562 psFree (fpa);563 psFree (format);567 psFree(fpa); 568 psFree(format); 564 569 return NULL; 565 570 } 566 571 567 572 // associate the filename with the FPA element 568 char *name = pmFPAfileNameFromRule (file->filesrc, file, view);573 char *name = pmFPAfileNameFromRule(file->filesrc, file, view); 569 574 570 575 // save the name association in the pmFPAfile structure 571 psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]); 572 573 psFree (view); 574 psFree (name); 575 psFree (phu); 576 } 577 psFree (fpa); 578 if (success) *success = true; 576 psMetadataAddStr(file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]); 577 578 psFree(view); 579 psFree(name); 580 psFree(phu); 581 } 582 psFree(fpa); 583 if (success) { 584 *success = true; 585 } 579 586 580 587 return file; … … 600 607 601 608 // use success to identify valid exit conditions (as opposed to 'argument not supplied') 602 if (success) *success = false; 609 if (success) { 610 *success = false; 611 } 603 612 604 613 // we search the argument data for the named fileset (argname) … … 606 615 if (!status) { 607 616 // this is not an error: this just means no matching argument was supplied 608 if (success) *success = true; 617 if (success) { 618 *success = true; 619 } 609 620 return NULL; 610 621 } … … 647 658 if (!fits) { 648 659 psError(PS_ERR_IO, false, "Failed to open file %s\n", realName); 649 psFree (realName);660 psFree(realName); 650 661 return NULL; 651 662 } … … 653 664 if (!phu) { 654 665 psError(PS_ERR_IO, false, "Failed to read file header %s", realName); 655 psFree (realName);656 psFitsClose (fits);666 psFree(realName); 667 psFitsClose(fits); 657 668 return NULL; 658 669 } … … 665 676 psFree(realName); 666 677 psFitsClose(fits); 667 psFree(file);668 678 return NULL; 669 679 } … … 673 683 psError(PS_ERR_UNKNOWN, false, "Error in config scripts\n"); 674 684 psFree(realName); 675 psFree(file);676 685 psFitsClose(fits); 677 686 return NULL; … … 681 690 realName); 682 691 psFree(realName); 683 psFree(file);684 692 psFitsClose(fits); 685 693 return NULL; … … 704 712 psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]); 705 713 706 psFree (view);707 psFree (name);708 psFree (phu);714 psFree(view); 715 psFree(name); 716 psFree(phu); 709 717 } 710 718 psFree(file->format); … … 712 720 file->formatName = psStringCopy(config->formatName); 713 721 714 if (success) *success = true; 722 if (success) { 723 *success = true; 724 } 715 725 return file; 716 726 } … … 736 746 psMetadata *format = NULL; 737 747 738 if (success) *success = false; 748 if (success) { 749 *success = false; 750 } 739 751 740 752 // we search the argument data for the named fileset (argname) … … 742 754 if (!status) { 743 755 psTrace("psModules.camera", 5, "Failed to find %s in argument list", argname); 744 if (success) *success = true; 756 if (success) { 757 *success = true; 758 } 745 759 return NULL; 746 760 } 747 761 if (infiles->n <= entry) { 748 psError(PS_ERR_IO, false, "only %ld files in %s in argument, entry %d requested\n", infiles->n, argname, entry); 762 psError(PS_ERR_IO, false, "only %ld files in %s in argument, entry %d requested\n", 763 infiles->n, argname, entry); 749 764 return NULL; 750 765 } … … 802 817 psFree(phu); 803 818 psFree(fpa); 804 psFree(file);805 819 psFree(format); 806 820 return NULL; … … 813 827 psFree(phu); 814 828 psFree(fpa); 815 psFree(file);816 829 psFree(format); 817 830 return NULL; … … 830 843 psFree(format); 831 844 832 if (success) *success = true; 845 if (success) { 846 *success = true; 847 } 833 848 return file; 834 849 } … … 841 856 PS_ASSERT_STRING_NON_EMPTY(filename, NULL); 842 857 843 if (success) *success = false; 858 if (success) { 859 *success = false; 860 } 844 861 845 862 // a camera config is needed (as source of file rule) … … 858 875 // load the given filerule (from config->camera) and bind it to the fpa 859 876 // the returned file is just a view to the entry on config->files 860 pmFPAfile *file = pmFPAfileDefineInput (config, fpa, filename);877 pmFPAfile *file = pmFPAfileDefineInput(config, fpa, filename); 861 878 psFree (fpa); 862 879 if (!file) { … … 866 883 867 884 // image names may not come from file->names 868 if (!strcasecmp (file->filerule, "@FILES")) {885 if (!strcasecmp(file->filerule, "@FILES")) { 869 886 psError(PS_ERR_IO, true, "supplied filerule uses illegal value @FILES"); 870 887 // XXX remove the file from config->files 871 psFree(file);872 888 return NULL; 873 889 } 874 890 875 891 // image names may come from the detrend database 876 if (!strcasecmp (file->filerule, "@DETDB")) {892 if (!strcasecmp(file->filerule, "@DETDB")) { 877 893 psTrace ("pmFPAfile", 5, "requiring use of detrend database source\n"); 878 894 // don't free the file here: it is left on config->files 879 895 // to be used optionally by pmFPAfileDefineFromDetDB (or others) 880 if (success) *success = true; 896 if (success) { 897 *success = true; 898 } 881 899 return NULL; 882 900 } … … 884 902 // Prepend the global path to the file rule 885 903 // this function is implicitly an INPUT operation: do not create the file 886 psString tmpName = pmConfigConvertFilename (file->filerule, config, false);904 psString tmpName = pmConfigConvertFilename(file->filerule, config, false); 887 905 psFree (file->filerule); 888 906 file->filerule = tmpName; 889 907 890 if (success) *success = true; 908 if (success) { 909 *success = true; 910 } 891 911 892 912 return file; … … 911 931 pmFPAfile *file = NULL; 912 932 913 if (success) *success = false; 933 if (success) { 934 *success = false; 935 } 914 936 915 937 // a camera config is needed (as source of file rule) … … 937 959 if (!file) { 938 960 psError(PS_ERR_IO, false, "file %s not defined\n", filename); 939 psFree (fpa);961 psFree(fpa); 940 962 return NULL; 941 963 } … … 1054 1076 psFree (options); 1055 1077 1056 if (success) *success = true; 1078 if (success) { 1079 *success = true; 1080 } 1057 1081 return file; 1058 1082 } … … 1202 1226 if (!pmConceptsCopyFPA(file->fpa, src, true, false)) { 1203 1227 psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from source to new FPA"); 1204 psFree(file);1205 1228 return NULL; 1206 1229 } … … 1254 1277 if (!pmConceptsCopyFPA(file->fpa, src, false, false)) { 1255 1278 psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from source to new FPA"); 1256 psFree(file);1257 1279 return NULL; 1258 1280 } … … 1294 1316 bool status = false; 1295 1317 1296 pmFPAfile *file = psMetadataLookupPtr (&status, files, name);1318 pmFPAfile *file = psMetadataLookupPtr(&status, files, name); 1297 1319 if (!status) { 1298 1320 psTrace("psModules.camera", 6, "Internal File %s not in file list", name); … … 1309 1331 1310 1332 psTrace("psModules.camera", 6, "dropping Internal FPA File %s", name); 1311 psMetadataRemoveKey (files, name);1333 psMetadataRemoveKey(files, name); 1312 1334 return true; 1313 1335 } -
trunk/psModules/src/camera/pmFPAfileDefine.h
r15931 r17634 4 4 * @author EAM, IfA 5 5 * 6 * @version $Revision: 1.1 6$ $Name: not supported by cvs2svn $7 * @date $Date: 200 7-12-27 02:08:19$6 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2008-05-12 21:41:55 $ 8 8 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii 9 9 */ … … 39 39 40 40 /// Define the FPA file using the provided camera and format names. 41 /// 42 /// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only 43 /// reference count is held by the config->files metadata. 41 44 pmFPAfile *pmFPAfileDefineOutputForFormat(const pmConfig *config, // Configuration 42 45 pmFPA *fpa, // Optional FPA to bind … … 78 81 79 82 /// Same as pmFPAfileDefineFromFPA, except it uses an FPA file instead of an FPA 83 /// 84 /// The new pmFPAfile is inserted into the config->files metadata, freed and returned; so that the user does 85 /// not have to (and should not!) free the result. 80 86 pmFPAfile *pmFPAfileDefineFromFile(const pmConfig *config, // Configuration 81 87 pmFPAfile *src, // Source file for this file … … 122 128 // create a file with the given name, assign it type "INTERNAL", and supply it with an image 123 129 // of the requested dimensions. (image only, mask and weight are ignored) 124 pmReadout *pmFPAfileDefineInternal (psMetadata *files, const char *name, int Nx, int Ny, int type); 130 /// 131 /// The new pmFPAfile is inserted into the config->files metadata, freed and returned; so that the user does 132 /// not have to (and should not!) free the result. 133 pmReadout *pmFPAfileDefineInternal(psMetadata *files, const char *name, int Nx, int Ny, int type); 125 134 126 135 // delete the INTERNAL file of the given name (if it exists) 127 bool pmFPAfileDropInternal (psMetadata *files, const char *name);136 bool pmFPAfileDropInternal(psMetadata *files, const char *name); 128 137 129 138 // look for the given argname on the argument list. find the give filename from the file rules … … 131 140 // Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only 132 141 // reference count is held by the config->files metadata. 133 pmFPAfile *pmFPAfileDefineSingleFromArgs (bool *found, pmConfig *config, const char *filename,134 const char *argname, int entry);142 pmFPAfile *pmFPAfileDefineSingleFromArgs(bool *found, pmConfig *config, const char *filename, 143 const char *argname, int entry); 135 144 136 145 // Select or construct the requested readout. If the named entry does not exist, generate it based … … 139 148 // pmFPAfile is being used internally. 140 149 pmReadout *pmFPAGenerateReadout(const pmConfig *config, // configuration information 141 const pmFPAview *view, // select background for this entry142 const char *name, // name of internal/external file143 const pmFPA *fpa, // use this fpa to generate144 const psImageBinning *binning);150 const pmFPAview *view, // select background for this entry 151 const char *name, // name of internal/external file 152 const pmFPA *fpa, // use this fpa to generate 153 const psImageBinning *binning); 145 154 146 155 /// @}
Note:
See TracChangeset
for help on using the changeset viewer.
