Changeset 6819 for branches/rel10_ifa/psModules/src/config/pmConfig.c
- Timestamp:
- Apr 8, 2006, 10:13:03 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.
