/* > hrptx.c * (C) 1996 Andrew Brooks arb@sat.dundee.ac.uk * 1.04 arb Thu Feb 18 10:18:01 GMT 1999 - remove need for format parameter. * 1.03 arb Wed Nov 19 15:44:51 GMT 1997 - add support for writing PGM images. * 1.02 arb Tue Jun 24 13:50:50 BST 1997 - added default to switch statement * to keep someone's compiler happy. * 1.01 arb Tue Nov 26 11:38:41 GMT 1996 - added packed Dundee format, check * for correct input format, check for number of lines written. * 1.00 arb Thu Nov 7 12:04:00 GMT 1996 * Usage: hrptx fmt filename * where fmt is "raw", "22k", "24k" or "dundee". * Extracts image data plus TIP and CALIB from an HRPT file. * Writes to filename.ch[1-5] plus ch6 (TIP) and ch7 (CALIB). */ static char SCCSid[] = "@(#)hrptx.c 1.04 (C) 1996 arb HRPT extract"; /* * Notes: * Extracts line-by-line, does not rotate for Northbound passes. */ /* * Configuration: * Define OUTPUT_PGM for 10-bit ASCII PGM output instead of raw binary. * Define strcasecmp if needed by your compiler */ #define OUTPUT_PGM /*#define strcasecmp stricmp*/ #include #include #include typedef enum { HRPT_Bad, HRPT_Raw, HRPT_22k, HRPT_24k, HRPT_Dundee } hrpt_type_t; #define NUM_PIX 2048 #define NUM_CH_IM 5 #define NUM_CH (NUM_CH_IM+2) #define OFFSET_WORD_IM 750 #define OFFSET_WORD_TIP 103 #define OFFSET_WORD_CALIB 0 #define LEN_WORD_TIP (104*5) #define LEN_WORD_CALIB 103 #define TAPE_BLOCK 3700 /* for unpacking Dundee format */ #define SEEK_END 2 char *prog; char *usage = "usage: %s filename\nFormats understood are raw, 22k, 24k or dundee.\nWrites image channels, then TIP then CALIB.\n"; long hrpt_linesize(hrpt_type_t hrpt_type) { switch (hrpt_type) { case HRPT_Raw: return(22180); case HRPT_22k: return(22528); case HRPT_24k: return(24576); case HRPT_Dundee: return(14800); } return(-1); } hrpt_type_t decode_hrpt_type(long filesize) { if ((filesize % hrpt_linesize(HRPT_Raw)) == 0) return(HRPT_Raw); else if ((filesize % hrpt_linesize(HRPT_22k)) == 0) return(HRPT_22k); else if ((filesize % hrpt_linesize(HRPT_24k)) == 0) return(HRPT_24k); else if ((filesize % hrpt_linesize(HRPT_Dundee)) == 0) return(HRPT_Dundee); else return(HRPT_Bad); } int hrpt_unpack_dundee(unsigned char *inbuf, unsigned short *outbuf) { int i, j; unsigned short s[4]; for (i = 3*(TAPE_BLOCK-1), j = 4*(TAPE_BLOCK-1); i >= 0; i -= 3, j -= 4) { s[0] = (unsigned short)inbuf[j]; s[1] = (unsigned short)inbuf[j+1]; s[2] = (unsigned short)inbuf[j+2]; s[3] = (unsigned short)inbuf[j+3]; outbuf[i] = ((s[0] << 2) + (s[1] >> 6)); outbuf[i+1] = ((s[1] << 4) + (s[2] >> 4)) & 0x3FF; outbuf[i+2] = ((s[2] << 6) + (s[3] >> 2)) & 0x3FF; } return(0); } int hrpt_extract_line(FILE *fp[NUM_CH], unsigned short *line) { int ch, x; unsigned short *ptr; unsigned char tipval; ptr = line + OFFSET_WORD_IM; for (x=0; x