Changeset 10858
- Timestamp:
- Dec 29, 2006, 4:35:23 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/misc/src/fields.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/misc/src/fields.c
r7080 r10858 1 1 # include <ohana.h> 2 2 # include <gfitsio.h> 3 # include <sys/types.h> 4 # include <regex.h> 5 6 int print_fields (char *filename, char *extname, Header *header, int argc, char **argv); 3 7 4 8 int main (int argc, char **argv) { 5 9 6 10 int i; 11 FILE *f; 7 12 Header header; 8 char filename[1000], buffer[1000];9 int N, Extend, Nextend, status, GotFile, GotField;13 char filename[1000], *Extname, extname[80]; 14 int N, Nbytes, Extnum, Nextend, status, GotFile, GotField, GotExtension; 10 15 11 Extend = FALSE; 16 regex_t preg; 17 18 Extnum = FALSE; 12 19 if ((N = get_argument (argc, argv, "-x"))) { 13 Ext end= TRUE;20 Extnum = TRUE; 14 21 remove_argument (N, &argc, argv); 15 22 Nextend = atoi (argv[N]); 16 23 remove_argument (N, &argc, argv); 24 } 25 26 Extname = NULL; 27 if ((N = get_argument (argc, argv, "-n"))) { 28 remove_argument (N, &argc, argv); 29 Extname = strcreate (argv[N]); 30 remove_argument (N, &argc, argv); 31 regcomp (&preg, Extname, REG_EXTENDED); 17 32 } 18 33 … … 21 36 22 37 while (fscanf (stdin, "%s", filename) != EOF) { 23 if (Extend) { 24 status = gfits_read_Xheader (filename, &header, Nextend); 25 } else { 26 status = gfits_read_header (filename, &header); 27 } 28 if (!status) { 29 GotFile = FALSE; 38 if (!Extnum && !Extname) { 39 GotFile &= gfits_read_header (filename, &header); 40 GotField &= print_fields (filename, NULL, &header, argc, argv); 30 41 continue; 31 42 } 32 33 fprintf (stdout, "%s ", filename); 34 for (i = 1; i < argc; i++) { 35 bzero (buffer, 1000); 36 status = gfits_scan (&header, argv[i], "%s", 1, buffer); 37 if (!status) { 38 GotField = FALSE; 43 if (Extnum) { 44 GotFile &= gfits_read_Xheader (filename, &header, Nextend); 45 GotField &= print_fields (filename, NULL, &header, argc, argv); 46 continue; 47 } 48 49 if (Extname) { 50 /* keep reading headers, only parse fields for matching headers */ 51 Nextend = 0; 52 GotExtension = FALSE; 53 f = fopen (filename, "r"); 54 if (f == NULL) { 55 GotFile = FALSE; 56 continue; 39 57 } 40 stripwhite (buffer); 41 fprintf (stdout, "%s ", buffer); 58 while (gfits_fread_header (f, &header)) { 59 /* extract the EXTNAME for this component (set to PHU for 0th component) */ 60 status = gfits_scan (&header, "EXTNAME", "%s", 1, extname); 61 if (!status) { 62 if (Nextend == 0) { 63 strcpy (extname, "PHU"); 64 } else { 65 strcpy (extname, "UNKNOWN"); 66 } 67 } 68 if (!regexec (&preg, extname, 0, NULL, 0)) { 69 GotField &= print_fields (filename, extname, &header, argc, argv); 70 GotExtension = TRUE; 71 } 72 73 Nbytes = gfits_matrix_size (&header); 74 fseek (f, Nbytes, SEEK_CUR); 75 Nextend ++; 76 77 GotFile = gfits_read_Xheader (filename, &header, Nextend); 78 continue; 79 } 80 fclose (f); 81 if (Nextend == 0) { 82 GotFile = FALSE; 83 } 42 84 } 43 fprintf (stdout, "\n");85 } 44 86 45 gfits_free_header (&header); 46 } 87 regfree (&preg); 47 88 48 89 if (!GotFile) exit (1); 49 90 if (!GotField) exit (2); 91 if (!GotExtension) exit (3); 50 92 exit (0); 51 93 } 94 95 int print_fields (char *filename, char *extname, Header *header, int argc, char **argv) { 96 97 int i, status, GotField; 98 char buffer[1000]; 99 100 GotField = TRUE; 101 102 if (extname) { 103 fprintf (stdout, "%s[%s] ", filename, extname); 104 } else { 105 fprintf (stdout, "%s ", filename); 106 } 107 for (i = 1; i < argc; i++) { 108 bzero (buffer, 1000); 109 GotField &= gfits_scan (header, argv[i], "%s", 1, buffer); 110 stripwhite (buffer); 111 fprintf (stdout, "%s ", buffer); 112 } 113 fprintf (stdout, "\n"); 114 gfits_free_header (header); 115 return (GotField); 116 }
Note:
See TracChangeset
for help on using the changeset viewer.
