/*************************************************************************** * * write_hdr * * Writes the specified values into a 1000-byte header block of the * specified file, using the new standard CDC distributed data header format. * * LAST UPDATE: 26 November 1997 * * ARGUMENTS: * * Name Type Description * ---- ---- ----------- * outfile *FILE (Opened) input data file pointer * file_str char[80] Character string with outfile name * instr char[20] Instrument (sensor) * mis_val short Missing value (e.g., -9999) * fields short Number of fields per pixel * pixels short Number of pixels per scanline * hi_fields short Number of high-resolution fields * hi_pixels short Number of high-res pixels per scanline * scale *short Scaling factor (one per field) * offset *short Offset (bias) factor (one per field) * var_desc **char Field variable description (one per field) * * ORIGINAL AUTHORS: * Don Anderson and Wesley Berg, CIRES/CDC, November 1997 * * RETURNS: 0 If successful * < 0 If error * * NOTES: * (1) The passed file descriptor ("outfile") must be for a file which * has already been opened for writing. * (2) Binary write (fwrite) continues up to the 1000th byte of the file * (end of header) * ***************************************************************************/ #include int write_hdr ( FILE *outfile, char file_str[], char satellite[], char sensor[], short mis_val, short satid, short fields, short pixels, short hi_fields, short hi_pixels, float *scale, float *offset, char **units, char **var_desc ) { char buff[5000] ; /* Buffer for filler bytes */ int error_flag ; /* Error flag */ short i ; /* Generic counter */ error_flag = 0 ; fwrite ( file_str, 1, 80, outfile ) ; fwrite ( satellite, 1, 20, outfile ) ; fwrite ( sensor, 1, 20, outfile ) ; fwrite ( &satid, 2, 1, outfile ) ; fwrite ( &fields, 2, 1, outfile ) ; fwrite ( &pixels, 2, 1, outfile ) ; fwrite ( &hi_fields, 2, 1, outfile ) ; fwrite ( &hi_pixels, 2, 1, outfile ) ; fwrite ( &mis_val, 2, 1, outfile ) ; for ( i = 0 ; i < fields + hi_fields ; i++ ) { fwrite ( &scale[i], 4, 1, outfile ) ; fwrite ( &offset[i], 4, 1, outfile ) ; fwrite ( units[i], 1, 40, outfile ) ; fwrite ( var_desc[i], 1, 80, outfile ) ; } if ( ! fwrite ( buff, 1, 5000 - 132 - ((fields+hi_fields)*128), outfile ) ) error_flag = -1 ; return ( error_flag ) ; }