/*************************************************************************** * * write_hdr * * Writes the specified values into a 5000-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 output data file pointer * hdr *struct std_hdr Pointer to std_hdr structure * * 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 5000th byte of the file * (end of header) * ***************************************************************************/ #include #include "common_structures" int write_hdr ( FILE *outfile, struct std_hdr hdr ) { char buff[5000] ; /* Buffer for filler bytes */ int error_flag ; /* Error flag */ short i ; /* Generic counter */ error_flag = 0 ; fwrite ( hdr.filename, 1, 80, outfile ) ; fwrite ( hdr.satellite, 1, 20, outfile ) ; fwrite ( hdr.sensor, 1, 20, outfile ) ; fwrite ( &hdr.satid, 2, 1, outfile ) ; fwrite ( &hdr.fields, 2, 1, outfile ) ; fwrite ( &hdr.pixperscan, 2, 1, outfile ) ; fwrite ( &hdr.hifields, 2, 1, outfile ) ; fwrite ( &hdr.hipixperscan, 2, 1, outfile ) ; fwrite ( &hdr.missing_val, 2, 1, outfile ) ; for ( i = 0 ; i < hdr.fields + hdr.hifields ; i++ ) { fwrite ( &hdr.scale[i], 4, 1, outfile ) ; fwrite ( &hdr.offset[i], 4, 1, outfile ) ; fwrite ( &hdr.units[i], 1, 40, outfile ) ; fwrite ( &hdr.description[i], 1, 80, outfile ) ; } if (!fwrite (buff,1,5000-132-((hdr.fields+hdr.hifields)*128),outfile)) error_flag = -1 ; return ( error_flag ) ; }