Changeset 6791 for trunk/psastro/src/psastroArguments.c
- Timestamp:
- Apr 5, 2006, 12:46:25 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psastro/src/psastroArguments.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastroArguments.c
r5565 r6791 1 1 # include "psastro.h" 2 3 static void usage (void); 4 static void usage_test (void); 5 6 psMetadata *psastroArguments (int *argc, char **argv) { 7 8 unsigned int Nfail; 9 10 // basic pslib options 11 fprintf (stderr, "starting... %s\n", psLibVersion()); 12 psLogSetFormat ("M"); 13 psLogArguments (argc, argv); 14 psTraceArguments (argc, argv); 15 16 if (*argc != 4) usage (); 17 18 // load config information 19 psMetadata *config = psMetadataAlloc (); 20 config = psMetadataConfigParse (config, &Nfail, argv[1], FALSE); 21 return (config); 22 } 2 # include <glob.h> 23 3 24 4 static void usage (void) { 25 fprintf (stderr, "USAGE: psastro (config) (input)(output)\n");5 fprintf (stderr, "USAGE: psastro [-file image(s)] [-list imagelist] (output)\n"); 26 6 exit (2); 27 7 } 28 8 29 p sMetadata *testArguments (int *argc, char **argv) {9 pmConfig *psastroArguments (int *argc, char **argv) { 30 10 31 unsigned int Nfail; 11 int N; 12 13 if (*argc == 1) usage (); 32 14 33 15 // basic pslib options 34 fprintf (stderr, "starting... %s\n", psLibVersion());35 16 psLogSetFormat ("M"); 36 psLogArguments (argc, argv);37 psTraceArguments (argc, argv);38 17 39 if (*argc != 6) usage_test (); 18 // these other options override the PSPHOT recipe options 19 psMetadata *options = psMetadataAlloc (); 40 20 41 // load config information 42 psMetadata *config = psMetadataAlloc (); 43 config = psMetadataConfigParse (config, &Nfail, argv[1], FALSE); 21 // photcode : used in output to supplement header data (argument or recipe?) 22 if ((N = psArgumentGet (*argc, argv, "-photcode"))) { 23 psArgumentRemove (N, argc, argv); 24 psMetadataAddStr (options, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", argv[N]); 25 psArgumentRemove (N, argc, argv); 26 } 27 28 // load config data from default locations 29 pmConfig *config = pmConfigRead(argc, argv); 30 31 // Storage for other command-line arguments 32 config->arguments = psMetadataAlloc (); 33 34 // save these recipe options until we have loaded the options 35 psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "PSASTRO.OPTIONS", PS_DATA_METADATA, "", options); 36 37 // we load all input files onto a psArray, to be parsed later 38 psArray *input = psArrayAlloc (16); 39 input->n = 0; 40 41 // load the list of filenames the supplied file (may be a glob: "file*.fits") 42 if ((N = psArgumentGet (*argc, argv, "-file"))) { 43 glob_t globList; 44 psArgumentRemove (N, argc, argv); 45 globList.gl_offs = 0; 46 glob (argv[N], 0, NULL, &globList); 47 for (int i = 0; i < globList.gl_pathc; i++) { 48 char *filename = psStringCopy (globList.gl_pathv[i]); 49 psArrayAdd (input, 16, filename); 50 } 51 psArgumentRemove (N, argc, argv); 52 } 53 54 // load the list from the supplied text file 55 if ((N = psArgumentGet (*argc, argv, "-list"))) { 56 int nItems; 57 char line[1024]; // XXX limits the list lines to 1024 chars 58 char word[1024]; 59 char *filename; 60 61 psArgumentRemove (N, argc, argv); 62 FILE *f = fopen (argv[N], "r"); 63 if (f == NULL) { 64 psAbort ("psphot", "unable to open specified list file"); 65 } 66 while (fgets (line, 1024, f) != NULL) { 67 nItems = sscanf (line, "%s", word); 68 switch (nItems) { 69 case 0: 70 break; 71 case 1: 72 filename = psStringCopy (word); 73 psArrayAdd (input, 16, filename); 74 break; 75 default: 76 // rigid format, no comments allowed? 77 psAbort ("psphot", "error parsing input list file"); 78 break; 79 } 80 } 81 psArgumentRemove (N, argc, argv); 82 } 83 if (input->n < 1) usage (); 84 85 // input list gets places as an array on the config->arguements list 86 psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "INPUT", PS_DATA_ARRAY, "", input); 87 88 if (*argc != 2) usage (); 89 90 // output positions is fixed 91 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "", argv[2]); 92 93 psTrace(__func__, 1, "Done with psphotArguments...\n"); 44 94 return (config); 45 95 } 46 47 static void usage_test (void) {48 fprintf (stderr, "USAGE: psastro-mktest (config) (cmpfile) (catfile) (rawfile) (reffile)\n");49 exit (2);50 }
Note:
See TracChangeset
for help on using the changeset viewer.
