/* This program searches the header of the fits file, which is specified on the command line. It then changes the header to the value specified on the command line: ch_head */ #include #include #include char *field; /* Standard length of a FITS field name */ char *value; /* Standard length of the value (I hope)*/ char *new_value; /* what we want instead of the read-in value */ main(int argc, char **argv) { int i; float max, min; FILE *file; if (argc < 3) { /* No file specified ! */ fprintf(stderr, "Usage: fits_head \n"); fprintf(stderr, " field: The field to modify\n"); fprintf(stderr, " value: The new value of the field\n"); fprintf(stderr, " file specs: The fits files to examine\n"); exit(1); } else { field = argv[1]; new_value = argv[2]; } for (i = 0 ; i < argc - 3 ; ++i) { file = fopen(argv[i+3], "rb"); read_header(file); } } read_header(FILE *fp) { static unsigned char fcard[80]; /* basic FITS card, 36 to a block of 2880 bytes */ static unsigned char new_fcard[80]; char *trailer; int end = 0; /* assume the worst! */ int length = 0; while( fread(fcard,1,80,fp) == 80 ) { length = strlen(field); if( strncasecmp(fcard,field,length) == 0 ) { /* fprintf(stderr,"%p\n", fcard+9); */ value = fcard+9; trailer = fcard+30; sprintf(fcard, "%-8s=%21s%50s", field, new_value, trailer); fwrite(fcard,1,80,stdout); } /* else if( strncasecmp(fcard,"END",3) == 0 ) { fwrite(fcard,1,80,stdout); end = 1; break; }*/ else { fwrite(fcard,1,80,stdout); } } return; }