00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "constants.hh"
00045 #include "productinfo.hh"
00046 #include "ioroutines.hh"
00047 #include "exceptions.hh"
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 void productinfo::fillproductinfo(
00081 const char* resultfile,
00082 const char* iden)
00083 {
00084 TRACE_FUNCTION("fillproductinfo (BK 01-Sep-2000)")
00085 char word[ONE27]=" ";
00086 char dummyline[ONE27];
00087
00088
00089
00090 ifstream resfile(resultfile, ios::in);
00091 bk_assert(resfile,resultfile,__FILE__,__LINE__);
00092
00093 bool foundiden = false;
00094 while(resfile)
00095 {
00096 if (strcmp(word,iden))
00097 {
00098 resfile.getline(dummyline,ONE27,'\n');
00099 resfile >> word;
00100 }
00101 else
00102 {
00103 foundiden = true;
00104 break;
00105 }
00106 }
00107
00108
00109 if (!foundiden)
00110 {
00111 ERROR << "(fillproductinfo). identifier: \"" << iden
00112 << "\" not found in file: " << resultfile;
00113 PRINT_ERROR(ERROR.get_str())
00114 throw(file_error);
00115 }
00116
00117
00118 int32 numlineschecked = 0;
00119 bool foundfilename = false;
00120 bool foundfileformat = false;
00121 bool foundfirstline = false;
00122 bool foundlastline = false;
00123 bool foundfirstpixel = false;
00124 bool foundlastpixel = false;
00125 bool foundmlL = false;
00126 bool foundmlP = false;
00127
00128 while(resfile)
00129 {
00130 numlineschecked++;
00131 resfile.getline(dummyline,ONE27,'\n');
00132 resfile >> word;
00133
00134 if (!strcmp(word,"Data_output_file:"))
00135 {
00136 if (!foundfilename)
00137 {
00138 foundfilename = true;
00139 resfile >> file;
00140 DEBUG << "String: \"Data_output_file:\", \t\t\tvalue: " << file;
00141 DEBUG.print();
00142 }
00143 else
00144 WARNING.print("String: \"Data_output_file:\" found again (ignored).");
00145 }
00146 else if (!strcmp(word,"Data_output_format:"))
00147 {
00148 if (!foundfileformat)
00149 {
00150 foundfileformat = true;
00151 resfile >> word;
00152 if (!strcmp(word,"complex_short"))
00153 formatflag = FORMATCI2;
00154 else if (!strcmp(word,"complex_real4"))
00155 formatflag = FORMATCR4;
00156 else if (!strcmp(word,"real4"))
00157 formatflag = FORMATR4;
00158 else if (!strcmp(word,"hgt"))
00159 formatflag = FORMATHGT;
00160 else
00161 {
00162 PRINT_ERROR("wrong format specifier (impossible?)")
00163 throw(unhandled_case_error);
00164 }
00165 DEBUG << "String: \"Data_output_format:\", \t\tvalue: " << formatflag;
00166 DEBUG.print();
00167 }
00168 else
00169 WARNING.print("String: \"Data_output_format:\" found again (ignored).");
00170 }
00171
00172 else if (!strcmp(word,"Multilookfactor_azimuth_direction:"))
00173 {
00174 if (!foundmlL)
00175 {
00176 foundmlL = true;
00177 resfile >> multilookL;
00178 DEBUG << "String: \"Multilookfactor_azimuth_direction:\", value: "
00179 << multilookL;
00180 DEBUG.print();
00181 }
00182 else
00183 WARNING.print("String: \"Multilookfactor_azimuth_direction:\" found again (ignored).");
00184 }
00185 else if (!strcmp(word,"Multilookfactor_range_direction:"))
00186 {
00187 if (!foundmlP)
00188 {
00189 foundmlP = true;
00190 resfile >> multilookP;
00191 DEBUG << "String: \"Multilookfactor_range_direction:\", \tvalue: "
00192 << multilookP;
00193 DEBUG.print();
00194 }
00195 else
00196 WARNING.print("String: \"Multilookfactor_range_direction:\" found again (ignored).");
00197 }
00198
00199 else if (!strcmp(word,"First_line"))
00200 {
00201 if (!foundfirstline)
00202 {
00203 foundfirstline = true;
00204 resfile >> word >> word >> win.linelo ;
00205 DEBUG << "String: \"First_line:\", \t\t\tvalue: " << win.linelo;
00206 DEBUG.print();
00207 }
00208 else
00209 WARNING.print("String: \"First_line:\" found again (ignored).");
00210 }
00211
00212 else if (!strcmp(word,"Last_line"))
00213 {
00214 if (!foundlastline)
00215 {
00216 foundlastline = true;
00217 resfile >> word >> word >> win.linehi ;
00218 DEBUG << "String: \"Last_line:\", \t\t\tvalue: " << win.linehi;
00219 DEBUG.print();
00220 }
00221 else
00222 WARNING.print("String: \"Last_line:\" found again (ignored).");
00223 }
00224
00225 else if (!strcmp(word,"First_pixel"))
00226 {
00227 if (!foundfirstpixel)
00228 {
00229 foundfirstpixel = true;
00230 resfile >> word >> word >> win.pixlo ;
00231 DEBUG << "String: \"First_pixel:\", \t\t\tvalue: " << win.pixlo;
00232 DEBUG.print();
00233 }
00234 else
00235 WARNING.print("String: \"First_pixel:\" found again (ignored).");
00236 }
00237
00238 else if (!strcmp(word,"Last_pixel"))
00239 {
00240 if (!foundlastpixel)
00241 {
00242 foundlastpixel = true;
00243 resfile >> word >> word >> win.pixhi ;
00244 DEBUG << "String: \"Last_pixel:\", \t\t\tvalue: " << win.pixhi;
00245 DEBUG.print();
00246 }
00247 else
00248 WARNING.print("String: \"Last_pixel:\" found again (ignored).");
00249 }
00250
00251
00252 if (foundfilename && foundfileformat &&
00253 foundfirstline && foundlastline && foundfirstpixel && foundlastpixel &&
00254 foundmlL && foundmlP) break;
00255
00256
00257
00258 if (numlineschecked == 15) break;
00259 }
00260
00261
00262
00263
00264
00265 ifstream tmpfile(file, ios::in);
00266 if (tmpfile)
00267 {
00268 tmpfile.seekg(0,ios::end);
00269 uint filesizetrue = tmpfile.tellg();
00270 int32 bytesperelem = 4;
00271 if (formatflag==FORMATCI2) bytesperelem=4;
00272 if (formatflag==FORMATCR4) bytesperelem=8;
00273 if (formatflag==FORMATR4) bytesperelem=4;
00274 if (formatflag==FORMATI2) bytesperelem=2;
00275 if (formatflag==FORMATI2_BIGENDIAN) bytesperelem=2;
00276 if (formatflag==FORMATR8) bytesperelem=8;
00277 if (formatflag==FORMATHGT) bytesperelem=8;
00278 int32 filesizecomp = int32(win.lines()/multilookL) *
00279 int32(win.pixels()/multilookP) *
00280 bytesperelem;
00281 DEBUG << "Checking format/dimensions file=" << file;
00282 DEBUG.print();
00283 if (filesizecomp != filesizetrue)
00284 {
00285 WARNING << "Fileformat or dimensions seem wrong"
00286 << "; bytesperpix=" << bytesperelem
00287 << "; #l=" << win.lines()
00288 << "; #p=" << win.pixels()
00289 << "; size=" << filesizetrue
00290 << "B; size computed=" << filesizecomp << "B";
00291 WARNING.print();
00292 }
00293 else
00294 {
00295 DEBUG.print("Fileformat and dimensions ok.");
00296 }
00297 tmpfile.close();
00298 }
00299 else
00300 {
00301 WARNING << "File: " << file
00302 << " does not seem to exist (may not be a problem).";
00303 WARNING.print();
00304 }
00305
00306
00307
00308
00309 resfile.close();
00310
00311 #ifdef __DEBUG
00312 DEBUG.print("finished fillproductinfo");
00313 DEBUG.print("content of struct:");
00314 showdata();
00315 #endif
00316 }
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 matrix<real4> productinfo::readphase(
00333 window cutout) const
00334 {
00335 TRACE_FUNCTION("productinfo::readphase (BK 22-Sep-2000)")
00336
00337 const int32 linesondisk = int32(win.lines()/multilookL);
00338 const int32 pixelsondisk = int32(win.pixels()/multilookP);
00339
00340 #ifdef __DEBUGMAT2
00341 if (cutout.linelo < 1)
00342 {
00343 PRINT_ERROR("readphase: cutout window larger than what's on disk!")
00344 throw(input_error);
00345 }
00346 if (cutout.linehi>linesondisk)
00347 {
00348 PRINT_ERROR("readphase: cutout window larger than what's on disk!")
00349 throw(input_error);
00350 }
00351 if (cutout.pixlo < 1)
00352 {
00353 PRINT_ERROR("readphase: cutout window larger than what's on disk!")
00354 throw(input_error);
00355 }
00356 if (cutout.pixhi>pixelsondisk)
00357 {
00358 PRINT_ERROR("readphase: cutout window larger than what's on disk!")
00359 throw(input_error);
00360 }
00361 #endif
00362
00363
00364
00365
00366
00367
00368
00369 ifstream ifile;
00370 openfstream(ifile,file);
00371 bk_assert(ifile,file,__FILE__,__LINE__);
00372
00373 matrix<real4> Result(cutout.lines(),cutout.pixels());
00374
00375
00376 switch (formatflag)
00377 {
00378 case FORMATR4:
00379 {
00380
00381 DEBUG.print("reading real4 from file");
00382 matrix<real4> LINE(1,cutout.pixels());
00383 for (int32 line=cutout.linelo; line<=cutout.linehi; ++line)
00384 {
00385 int32 start = (cutout.pixlo-1 + pixelsondisk*(line-1))
00386 * sizeof(real4);
00387 ifile.seekg(start,ios::beg);
00388 ifile >> LINE;
00389 Result.setrow(line-cutout.linelo,LINE);
00390
00391
00392 }
00393 break;
00394 }
00395
00396 case FORMATCR4:
00397 {
00398 DEBUG.print("reading complex real4 from file (get phase)");
00399 const window dummyoffset(1,99999,1,99999);
00400 matrix<complr4> TMP(cutout.lines(),cutout.pixels());
00401 readfile(TMP,file,linesondisk,cutout,dummyoffset);
00402 Result = angle(TMP);
00403 break;
00404 }
00405
00406
00407 case FORMATHGT:
00408 {
00409 DEBUG.print("reading hgt (band interleaved) from file (get phase)");
00410
00411 matrix<real4> LINE(1,win.pixels()*2);
00412 for (int32 line=cutout.linelo; line<=cutout.linehi; ++line)
00413 {
00414 const int32 start = (line-1) * pixelsondisk * 2 * sizeof(real4);
00415 ifile.seekg(start,ios::beg);
00416 ifile >> LINE;
00417 for (int32 pix=cutout.pixlo; pix<=cutout.pixhi; ++pix)
00418 {
00419
00420 if (LINE(0,pix-1) == 0.)
00421 Result(line-cutout.linelo,pix-cutout.pixlo) = NaN;
00422 else
00423 Result(line-cutout.linelo,pix-cutout.pixlo) = LINE(0,pix-1+pixelsondisk);
00424 }
00425 }
00426 break;
00427 }
00428
00429 default:
00430 PRINT_ERROR("readphase::not correct format on file.")
00431 throw(unhandled_case_error);
00432 }
00433
00434 ifile.close();
00435 return Result;
00436 }
00437
00438