|
Isis 3.0 Application Source Code Reference |
Home |
00001 /* 00002 NOTICE 00003 00004 The software accompanying this notice (the "Software") is provided to you 00005 free of charge to facilitate your use of the data collected by the Mars 00006 Orbiter Camera (the "MOC Data"). Malin Space Science Systems ("MSSS") 00007 grants to you (either as an individual or entity) a personal, 00008 non-transferable, and non-exclusive right (i) to use and reproduce the 00009 Software solely for the purpose of accessing the MOC Data; (ii) to modify 00010 the source code of the Software as necessary to maintain or adapt the 00011 Software to run on alternate computer platforms; and (iii) to compile, use 00012 and reproduce the modified versions of the Software solely for the purpose 00013 of accessing the MOC Data. In addition, you may distribute the Software, 00014 including any modifications thereof, solely for use with the MOC Data, 00015 provided that (i) you must include this notice with all copies of the 00016 Software to be distributed; (ii) you may not remove or alter any 00017 proprietary notices contained in the Software; (iii) you may not charge any 00018 third party for the Software; and (iv) you will not export the Software 00019 without the appropriate United States and foreign government licenses. 00020 00021 You acknowledge that no title to the intellectual property in the Software 00022 is transferred to you. You further acknowledge that title and full 00023 ownership rights to the Software will remain the exclusive property of MSSS 00024 or its suppliers, and you will not acquire any rights to the Software 00025 except as expressly set forth above. The Software is provided to you AS 00026 IS. MSSS MAKES NO WARRANTY, EXPRESS OR IMPLIED, WITH RESPECT TO THE 00027 SOFTWARE, AND SPECIFICALLY DISCLAIMS THE IMPLIED WARRANTIES OF 00028 NON-INFRINGEMENT OF THIRD PARTY RIGHTS, MERCHANTABILITY AND FITNESS FOR A 00029 PARTICULAR PURPOSE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR 00030 LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO SUCH LIMITATIONS OR 00031 EXCLUSIONS MAY NOT APPLY TO YOU. 00032 00033 Your use or reproduction of the Software constitutes your agreement to the 00034 terms of this Notice. If you do not agree with the terms of this notice, 00035 promptly return or destroy all copies of the Software in your possession. 00036 00037 Copyright (C) 1999 Malin Space Science Systems. All Rights Reserved. 00038 */ 00039 //static char *sccsid = "@(#)header.c 1.2 10/06/99"; 00040 #include <stdio.h> 00041 #include <stdlib.h> 00042 #include <string.h> 00043 #include "image_io.h" 00044 #include <errno.h> 00045 00046 int prefix(const char *s, const char *pre) 00047 { 00048 return strncmp(s, pre, strlen(pre)) == 0; 00049 } 00050 00051 /* write the image header and return the file descriptor to the open file */ 00052 /*int write_header(width, height, infile, outfname)*/ 00053 FILE *write_header(int width, int height, FILE *infile, char *outfname) 00054 { 00055 static int out = -1; 00056 int pos; 00057 FILE *outf; 00058 char line[256]; 00059 int nrec; 00060 int i, pad; 00061 00062 if(out < 0) { 00063 i = remove(outfname); 00064 if(i != -1 || errno == 0 || errno == 2) out = 1; 00065 else { 00066 fprintf(stderr, "can't create %s (%i)\n", outfname, i); 00067 exit(1); 00068 } 00069 /* if((out = creat(outfname, 0666)) < 0) { 00070 fprintf(stderr, "can't create %s\n", outfname); 00071 exit(1); 00072 }*/ 00073 outf = fopen(outfname, "w+"); 00074 } 00075 /* i = lseek(out, 0l, 0);*/ 00076 outf = fopen(outfname, "r+"); 00077 /* outf = fdopen(dup(out), "r+");*/ 00078 00079 nrec = 2048 / width + (2048 % width ? 1 : 0); 00080 00081 /* copy the PDS header with a few modifications */ 00082 pos = ftell(infile); 00083 i = fseek(infile, 0, 0); 00084 while(fgets(line, sizeof(line), infile)) { 00085 i = strlen(line); 00086 if(prefix(line, "RECORD_BYTES")) { 00087 i = fprintf(outf, "RECORD_BYTES = %d\r\n", width); 00088 } 00089 else if(prefix(line, "FILE_RECORDS")) { 00090 i = fprintf(outf, "FILE_RECORDS = %d\r\n", height + nrec); 00091 } 00092 else if(prefix(line, "^IMAGE")) { 00093 i = fprintf(outf, "^IMAGE = %d\r\n", nrec + 1); 00094 } 00095 else if(prefix(line, "LABEL_RECORDS")) { 00096 i = fprintf(outf, "LABEL_RECORDS = %d\r\n", nrec); 00097 } 00098 else if(prefix(line, "DATA_SET_ID")) { 00099 i = fprintf(outf, "DATA_SET_ID = \"MGS-M-MOC-NA/WA-2-DSDP-L0-V1.0\"\r\n"); 00100 } 00101 else if(prefix(line, "ENCODING_TYPE")) { 00102 ; /* skip this in output */ 00103 } 00104 else if(prefix(line, "FILE_NAME")) { 00105 i = fprintf(outf, "FILE_NAME = \"%s\"\r\n", outfname); 00106 } 00107 else if(prefix(line, "LINES")) { 00108 i = fprintf(outf, "LINES = %d\r\n", height); 00109 } 00110 else if(prefix(line, "END\r")) { 00111 i = fputs(line, outf); 00112 break; 00113 } 00114 else { 00115 /* i = fputs(line, outf); */ 00116 i = fprintf(outf, "%s", line); 00117 } 00118 } 00119 pad = nrec * width - (i = ftell(outf)); 00120 if(pad < 0) { 00121 fprintf(stderr, "Error: header too large\n"); 00122 exit(1); 00123 } 00124 00125 for(i = 0; i < pad; i++) fputc(' ', outf); 00126 00127 /* fclose(outf);*/ 00128 i = fseek(outf, nrec * width, 0); 00129 i = fseek(infile, pos, 0); 00130 /* return out;*/ 00131 return outf; 00132 }