00001 #include <stdio.h>
00002 #include "sadie.h"
00003 #include "mosaic.h"
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 void MOSAIC_INDEX2DISK(
00016 MOSAIC_INDEX *in,
00017 unsigned char *name
00018 )
00019
00020 {
00021 int i;
00022 static char array[2] = { 0x00, 0x01 };
00023 char msg[SLEN];
00024 int nlin, npix, height_max, hstart, hend;
00025 short nframe;
00026 int value;
00027 FILE *fp=NULL;
00028
00029
00030
00031
00032
00033 if (!CHECKIMG_MOSAIC_INDEX(in)) {
00034 MESSAGE('E'," Can't identify image.");
00035 goto the_end;
00036 }
00037
00038 if (NAMES) {
00039 MESSAGE('I',"");
00040 MESSAGE('I',"MOSAIC_INDEX2DISK");
00041 MESSAGE('I',"");
00042 sprintf(msg," Output disk file: %s",name);
00043 MESSAGE('I',msg);
00044 MESSAGE('I'," ...............");
00045 }
00046
00047
00048
00049
00050 height_max = in->height_max;
00051 npix = in->npix;
00052 nlin = in->nlin;
00053 nframe = in->nframe;
00054 hstart = in->hstart;
00055 hend = in->hend;
00056 if (*(short *)array != 1) {
00057
00058
00059
00060 height_max = SWAP((unsigned char *)&height_max);
00061 npix = SWAP((unsigned char *)&npix);
00062 nlin = SWAP((unsigned char *)&nlin);
00063 nframe = SWAP((unsigned char *)&nframe);
00064 hstart = SWAP((unsigned char *)&hstart);
00065 hend = SWAP((unsigned char *)&hend);
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 if (!(fp=fopen(name,"w"))) {
00075 sprintf(msg," Can't open file %s.",name);
00076 MESSAGE('E',msg);
00077 goto the_end;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087 if (fwrite(&height_max,sizeof(height_max),1,fp) != 1) {
00088 sprintf(msg," Can't write number of lines in the uncompressed mosaic to file %s.",name);
00089 MESSAGE('E',msg);
00090 goto the_end;
00091 }
00092
00093
00094 if (fwrite(&nlin,sizeof(nlin),1,fp) != 1) {
00095 sprintf(msg," Can't write number of lines in the compressed mosaic to file %s.",name);
00096 MESSAGE('E',msg);
00097 goto the_end;
00098 }
00099
00100
00101 if (fwrite(&npix,sizeof(npix),1,fp) != 1) {
00102 sprintf(msg," Can't write number of pixels/line to file %s.",name);
00103 MESSAGE('E',msg);
00104 goto the_end;
00105 }
00106
00107
00108 if (fwrite(&nframe,sizeof(nframe),1,fp) != 1) {
00109 sprintf(msg," Can't write number of frames to file %s.",name);
00110 MESSAGE('E',msg);
00111 goto the_end;
00112 }
00113
00114
00115 if (fwrite(&hstart,sizeof(hstart),1,fp) != 1) {
00116 sprintf(msg," Can't write X-coord of left extreme point to file %s.",name);
00117 MESSAGE('E',msg);
00118 goto the_end;
00119 }
00120
00121
00122 if (fwrite(&hend,sizeof(hend),1,fp) != 1) {
00123 sprintf(msg," Can't write X-coord of right extreme point to file %s.",name);
00124 MESSAGE('E',msg);
00125 goto the_end;
00126 }
00127
00128
00129 if (*(short *)array != 1) {
00130 for (i=0; i<in->npix; i++) {
00131 value = in->voffset[i];
00132 value = SWAP((unsigned char *)&value);
00133 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00134 sprintf(msg," Can't write data to file %s.",name);
00135 MESSAGE('E',msg);
00136 goto the_end;
00137 }
00138 }
00139 for (i=0; i<in->npix; i++) {
00140 value = in->vheight[i];
00141 value = SWAP((unsigned char *)&value);
00142 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00143 sprintf(msg," Can't write data to file %s.",name);
00144 MESSAGE('E',msg);
00145 goto the_end;
00146 }
00147 }
00148 for (i=0; i<in->npix; i++) {
00149 value = in->vstart[i];
00150 value = SWAP((unsigned char *)&value);
00151 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00152 sprintf(msg," Can't write data to file %s.",name);
00153 MESSAGE('E',msg);
00154 goto the_end;
00155 }
00156 }
00157 for (i=0; i<in->npix; i++) {
00158 value = in->vend[i];
00159 value = SWAP((unsigned char *)&value);
00160 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00161 sprintf(msg," Can't write data to file %s.",name);
00162 MESSAGE('E',msg);
00163 goto the_end;
00164 }
00165 }
00166 for (i=0; i<in->nframe; i++) {
00167 value = in->frame[i].startx;
00168 value = SWAP((unsigned char *)&value);
00169 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00170 sprintf(msg," Can't write data to file %s.",name);
00171 MESSAGE('E',msg);
00172 goto the_end;
00173 }
00174
00175 value = in->frame[i].endx;
00176 value = SWAP((unsigned char *)&value);
00177 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00178 sprintf(msg," Can't write data to file %s.",name);
00179 MESSAGE('E',msg);
00180 goto the_end;
00181 }
00182
00183 value = in->frame[i].starty;
00184 value = SWAP((unsigned char *)&value);
00185 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00186 sprintf(msg," Can't write data to file %s.",name);
00187 MESSAGE('E',msg);
00188 goto the_end;
00189 }
00190
00191 value = in->frame[i].endy;
00192 value = SWAP((unsigned char *)&value);
00193 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00194 sprintf(msg," Can't write data to file %s.",name);
00195 MESSAGE('E',msg);
00196 goto the_end;
00197 }
00198 }
00199 for(i = 0; i < 2; i++) {
00200 value = in->roi->top[i];
00201 value = SWAP((unsigned char *)&value);
00202 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00203 sprintf(msg," Can't write data to file %s.",name);
00204 MESSAGE('E',msg);
00205 goto the_end;
00206 }
00207 value = in->roi->bottom[i];
00208 value = SWAP((unsigned char *)&value);
00209 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00210 sprintf(msg," Can't write data to file %s.",name);
00211 MESSAGE('E',msg);
00212 goto the_end;
00213 }
00214 value = in->roi->left[i];
00215 value = SWAP((unsigned char *)&value);
00216 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00217 sprintf(msg," Can't write data to file %s.",name);
00218 MESSAGE('E',msg);
00219 goto the_end;
00220 }
00221 value = in->roi->right[i];
00222 value = SWAP((unsigned char *)&value);
00223 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00224 sprintf(msg," Can't write data to file %s.",name);
00225 MESSAGE('E',msg);
00226 goto the_end;
00227 }
00228 }
00229 } else {
00230 for (i=0; i<in->npix; i++) {
00231 value = in->voffset[i];
00232 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00233 sprintf(msg," Can't write data to file %s.",name);
00234 MESSAGE('E',msg);
00235 goto the_end;
00236 }
00237 }
00238 for (i=0; i<in->npix; i++) {
00239 value = in->vheight[i];
00240 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00241 sprintf(msg," Can't write data to file %s.",name);
00242 MESSAGE('E',msg);
00243 goto the_end;
00244 }
00245 }
00246 for (i=0; i<in->npix; i++) {
00247 value = in->vstart[i];
00248 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00249 sprintf(msg," Can't write data to file %s.",name);
00250 MESSAGE('E',msg);
00251 goto the_end;
00252 }
00253 }
00254 for (i=0; i<in->npix; i++) {
00255 value = in->vend[i];
00256 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00257 sprintf(msg," Can't write data to file %s.",name);
00258 MESSAGE('E',msg);
00259 goto the_end;
00260 }
00261 }
00262 for (i=0; i<in->nframe; i++) {
00263 value = in->frame[i].startx;
00264 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00265 sprintf(msg," Can't write data to file %s.",name);
00266 MESSAGE('E',msg);
00267 goto the_end;
00268 }
00269
00270 value = in->frame[i].endx;
00271 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00272 sprintf(msg," Can't write data to file %s.",name);
00273 MESSAGE('E',msg);
00274 goto the_end;
00275 }
00276
00277 value = in->frame[i].starty;
00278 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00279 sprintf(msg," Can't write data to file %s.",name);
00280 MESSAGE('E',msg);
00281 goto the_end;
00282 }
00283
00284 value = in->frame[i].endy;
00285 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00286 sprintf(msg," Can't write data to file %s.",name);
00287 MESSAGE('E',msg);
00288 goto the_end;
00289 }
00290 }
00291
00292 for(i = 0; i < 2; i++) {
00293
00294 value = in->roi->top[i];
00295 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00296 sprintf(msg," Can't write data to file %s.",name);
00297 MESSAGE('E',msg);
00298 goto the_end;
00299 }
00300
00301 value = in->roi->bottom[i];
00302 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00303 sprintf(msg," Can't write data to file %s.",name);
00304 MESSAGE('E',msg);
00305 goto the_end;
00306 }
00307
00308 value = in->roi->left[i];
00309 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00310 sprintf(msg," Can't write data to file %s.",name);
00311 MESSAGE('E',msg);
00312 goto the_end;
00313 }
00314
00315 value = in->roi->right[i];
00316 if (fwrite(&value,sizeof(value),1,fp) != 1) {
00317 sprintf(msg," Can't write data to file %s.",name);
00318 MESSAGE('E',msg);
00319 goto the_end;
00320 }
00321 }
00322 }
00323
00324
00325
00326 the_end:
00327
00328 if (fp) {
00329 if (fclose(fp)) {
00330 sprintf(msg," Can't close file %s.",name);
00331 MESSAGE('W',msg);
00332 }
00333 }
00334
00335 if (TIMES) TIMING(T_EXIT);
00336
00337 }