Changeset 30717
- Timestamp:
- Feb 21, 2011, 9:01:25 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110213/Ohana/src/tools/src/fhead.c
r27491 r30717 1 1 # include <ohana.h> 2 2 # include <gfitsio.h> 3 # include <regex.h> 3 4 4 5 int main (int argc, char **argv) { 5 6 6 int N, Ext end, Nextend, status;7 int N, Extnum, Nextend, status; 7 8 int i, j; 8 9 off_t nbytes; 9 10 Header head; 10 char *p; 11 char *p, *CCDKeyword, *Extname, extname[80]; 12 FILE *f; 13 off_t Nbytes; 14 regex_t preg; 11 15 12 Extend = FALSE; 16 CCDKeyword = NULL; 17 if ((N = get_argument (argc, argv, "-keyword"))) { 18 remove_argument (N, &argc, argv); 19 CCDKeyword = strcreate (argv[N]); 20 remove_argument (N, &argc, argv); 21 } 22 if (CCDKeyword == NULL) { 23 CCDKeyword = strcreate ("EXTNAME"); 24 } 25 26 Extnum = FALSE; 13 27 Nextend = 0; 14 28 if ((N = get_argument (argc, argv, "-x"))) { 15 Ext end= TRUE;29 Extnum = TRUE; 16 30 remove_argument (N, &argc, argv); 17 31 Nextend = atoi (argv[N]); 18 32 remove_argument (N, &argc, argv); 33 } 34 35 Extname = NULL; 36 if ((N = get_argument (argc, argv, "-n"))) { 37 remove_argument (N, &argc, argv); 38 Extname = strcreate (argv[N]); 39 remove_argument (N, &argc, argv); 40 regcomp (&preg, Extname, REG_EXTENDED); 19 41 } 20 42 … … 23 45 fprintf (stdout, "------> %s <------\n", argv[i]); 24 46 25 if (Extend) { 26 status = gfits_read_Xheader (argv[i], &head, Nextend); 27 } else { 28 status = gfits_read_header (argv[i], &head); 29 } 30 31 if (!status) continue; 32 33 for (j = 79; j < head.datasize; j+= 80) { 34 head.buffer[j] = 10; 47 status = FALSE; 48 if (!Extnum && !Extname) { 49 if (!gfits_read_header (argv[i], &head)) { 50 continue; 51 } 52 } 53 if (Extnum) { 54 if (!gfits_read_Xheader (argv[i], &head, Nextend)) { 55 continue; 56 } 57 } 58 if (Extname) { 59 /* keep reading headers until we reach the one we want */ 60 Nextend = 0; 61 f = fopen (argv[i], "r"); 62 if (f == NULL) continue; 63 while (gfits_fread_header (f, &head)) { 64 /* extract the EXTNAME (or other CCDKeyword) for this component (set to PHU for 0th component) */ 65 if (!gfits_scan (&head, CCDKeyword, "%s", 1, extname)) { 66 if (Nextend == 0) { 67 strcpy (extname, "PHU"); 68 } else { 69 strcpy (extname, "UNKNOWN"); 70 } 71 } 72 if (!regexec (&preg, extname, 0, NULL, 0)) { 73 goto done; 74 } 75 76 Nbytes = gfits_data_size (&head); 77 fseeko (f, Nbytes, SEEK_CUR); 78 Nextend ++; 79 } 80 // failed to find the desired header 81 continue; 35 82 } 36 83 37 p = gfits_header_field (&head, "END", 1);38 nbytes = p - head.buffer;39 fwrite (head.buffer, nbytes, 1, stdout);40 gfits_free_header (&head);84 done: 85 for (j = 79; j < head.datasize; j+= 80) { 86 head.buffer[j] = 10; 87 } 41 88 89 p = gfits_header_field (&head, "END", 1); 90 nbytes = p - head.buffer; 91 fwrite (head.buffer, nbytes, 1, stdout); 92 gfits_free_header (&head); 93 94 } 95 exit (0); 42 96 } 43 exit (0);44 }
Note:
See TracChangeset
for help on using the changeset viewer.
