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 "slcimage.hh"
00046 #include "ioroutines.hh"
00047 #include "conversion.hh"
00048 #include "ioroutines.hh"
00049 #include "matrixbk.hh"
00050 #include "exceptions.hh"
00051
00052 #include <cstdio>
00053 #include <strstream>
00054 #include <cstring>
00055 #include <ctime>
00056 char *strptime(const char *s, const char *format, struct tm *tm);
00057
00058
00059
00060
00061
00062
00063
00064 slcimage::slcimage()
00065 {
00066 TRACE_FUNCTION("slcimage() (BK 14-Aug-2000)")
00067 DEBUG.print("initializing slcimage with ERS defaults");
00068
00069 sensor = SLC_ERS;
00070 sar_processor = SARPR_VMP;
00071 approxcentreoriginal.x = 0.;
00072 approxcentreoriginal.y = 0.;
00073 approxcentreoriginal.z = 0.;
00074 wavelength = 0.0565646;
00075 t_azi1 = 0.;
00076 t_range1 = 5.5458330/2.0e3;
00077 prf = 1679.902;
00078 abw = 1378.0;
00079 f_DC_a0 = 0.;
00080 f_DC_a1 = 0.;
00081 f_DC_a2 = 0.;
00082 rsr2x = 18.9624680*2.0e6;
00083 rbw = 15.55e6;
00084 originalwindow.pixlo = 0;
00085 originalwindow.pixhi = 0;
00086 currentwindow.linelo = 0;
00087 currentwindow.linehi = 25000;
00088 currentwindow.pixlo = 0;
00089 currentwindow.pixhi = 5000;
00090 formatflag = 0;
00091 originalwindow.linelo = 1;
00092 originalwindow.pixlo = 1;
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 void slcimage::fillslcimage(const char* file)
00111 {
00112 TRACE_FUNCTION("fillslcimage (BK 14-Aug-2000)")
00113 INFO << "Reading parameters from: " << file;
00114 INFO.print();
00115
00116
00117 ifstream resfile(file, ios::in);
00118 bk_assert(resfile,file,__FILE__,__LINE__);
00119
00120
00121 char dummyline[ONE27];
00122 real8 latitude;
00123 real8 longitude;
00124 char word[ONE27] = " ";
00125 uint check = 0;
00126 int32 linecounter = 0;
00127
00128 DEBUG << setiosflags(ios::fixed)
00129 << setprecision(8)
00130 << setiosflags(ios::showpoint);
00131
00132 while(resfile && linecounter<1000)
00133 {
00134 ++linecounter;
00135 resfile.getline(dummyline,ONE27,'\n');
00136 resfile >> word;
00137
00138 if (!strcmp(word,"Scene_centre_latitude:"))
00139 {
00140 resfile >> latitude;
00141 DEBUG << "[" << linecounter
00142 << "]: string: \"Scene_centre_latitude:\", (derived) value: "
00143 << latitude;
00144 DEBUG.print();
00145 if (abs(latitude) > 90)
00146 WARNING.print("latitude larger than 90 degees?");
00147 check += 1;
00148 }
00149
00150 else if (!strcmp(word,"Scene_centre_longitude:"))
00151 {
00152 resfile >> longitude;
00153 DEBUG << "[" << linecounter
00154 << "]: string: \"Scene_centre_longitude:\", (derived) value: "
00155 << longitude;
00156 DEBUG.print();
00157 if (abs(longitude) > 360)
00158 WARNING.print("longitude larger than 360 degees?");
00159 check += 2;
00160 }
00161
00162 else if (!strcmp(word,"Radar_wavelength"))
00163 {
00164 resfile >> word >> wavelength;
00165 DEBUG << "[" << linecounter
00166 << "]: string: \"Radar_wavelength\", (derived) value: "
00167 << wavelength;
00168 DEBUG.print();
00169 if (wavelength > 0.50)
00170 WARNING.print("wavelength is larger than 50 centimeter?");
00171 if (wavelength < 0.01)
00172 WARNING.print("wavelength is smaller than 1 centimeter?");
00173 check += 4;
00174 }
00175
00176 else if (!strcmp(word,"Range_time_to_first_pixel"))
00177 {
00178 resfile >> word >> word >> t_range1;
00179 t_range1 /= 2000.;
00180 DEBUG << "[" << linecounter
00181 << "]: string: \"Range_time_to_first_pixel\", (derived) value: "
00182 << t_range1;
00183 DEBUG.print();
00184 check += 8;
00185 }
00186
00187 else if (!strcmp(word,"First_pixel_azimuth_time"))
00188 {
00189 struct tm tijdstart;
00190 char c12tijd0[13];
00191 char c12tijd0_tmp[16];
00192 resfile >> word >> utc1 >> c12tijd0_tmp;
00193
00194
00195
00196 strncpy(c12tijd0,c12tijd0_tmp,12);
00197 c12tijd0[12]='\0';
00198
00199 strcat(utc1," ");
00200 strcat(utc1,c12tijd0);
00201
00202
00203 strptime(c12tijd0,"%T",&tijdstart);
00204 char c12frac0[20]="0.";
00205 register int32 i;
00206 for (i=0; i<20; i++)
00207 if (c12tijd0_tmp[i]=='.') break;
00208 int32 j = 2;
00209 while (c12tijd0_tmp[i] != '\0')
00210 {
00211 i++;
00212 c12frac0[j]=c12tijd0_tmp[i];
00213 j++;
00214 }
00215 t_azi1 = tijdstart.tm_sec +
00216 atof(c12frac0) +
00217 60 * tijdstart.tm_min +
00218 3600 * tijdstart.tm_hour;
00219 DEBUG << "[" << linecounter
00220 << "]: string: \"First_pixel_azimuth_time\", (derived) value: "
00221 << t_azi1;
00222 DEBUG.print();
00223 INFO << "sec of day of first azimuth line: " << t_azi1;
00224 INFO.print();
00225 check += 32;
00226 }
00227
00228 else if (!strcmp(word,"Pulse_Repetition_Frequency"))
00229 {
00230 resfile >> word >> word >> prf;
00231 DEBUG << "[" << linecounter
00232 << "]: string: \"Pulse_Repetition_Frequency\", (derived) value: "
00233 << prf;
00234 DEBUG.print();
00235 check += 128;
00236 }
00237
00238 else if (!strcmp(word,"Range_sampling_rate"))
00239 {
00240 resfile >> word >> word >> rsr2x;
00241 rsr2x *= 2000000.;
00242 DEBUG << "[" << linecounter
00243 << "]: string: \"Range_sampling_rate\", (derived) value: "
00244 << rsr2x;
00245 DEBUG.print();
00246 check += 256;
00247 }
00248
00249 else if (!strcmp(word,"Number_of_lines_original:"))
00250 {
00251 resfile >> originalwindow.linehi;
00252 DEBUG << "[" << linecounter
00253 << "]: string: \"Number_of_lines_original:\", (derived) value: "
00254 << originalwindow.linehi;
00255 DEBUG.print();
00256 if (originalwindow.linehi > 100000)
00257 WARNING.print("more than 100000 lines?");
00258 check += 512;
00259 }
00260
00261 else if (!strcmp(word,"Number_of_pixels_original:"))
00262 {
00263 resfile >> originalwindow.pixhi;
00264 DEBUG << "[" << linecounter
00265 << "]: string: \"Number_of_pixels_original:\", (derived) value: "
00266 << originalwindow.pixhi;
00267 DEBUG.print();
00268 if (originalwindow.pixhi > 100000)
00269 WARNING.print("more than 100000 range pixels?");
00270 check += 1024;
00271 }
00272
00273 else if (!strcmp(word,"Total_azimuth_band_width"))
00274 {
00275 resfile >> word >> abw;
00276 DEBUG << "[" << linecounter
00277 << "]: string: \"Total_azimuth_band_width\", (derived) value: "
00278 << abw;
00279 DEBUG.print();
00280 check += 2048;
00281 }
00282 else if (!strcmp(word,"Total_range_band_width"))
00283 {
00284 resfile >> word >> rbw;
00285 rbw *= 1000000.;
00286 DEBUG << "[" << linecounter
00287 << "]: string: \"Total_range_band_width\", (derived) value: "
00288 << rbw;
00289 DEBUG.print();
00290 check += 4096;
00291 }
00292 else if (!strcmp(word,"Xtrack_f_DC_constant"))
00293 {
00294 resfile >> word >> word >> word >> f_DC_a0;
00295 DEBUG << "[" << linecounter
00296 << "]: string: \"Xtrack_f_DC_constant\", (derived) value: "
00297 << f_DC_a0;
00298 DEBUG.print();
00299 check += 8192;
00300 }
00301 else if (!strcmp(word,"Xtrack_f_DC_linear"))
00302 {
00303 resfile >> word >> word >> word >> f_DC_a1;
00304 if (abs(f_DC_a1)<1.0)
00305 {
00306 WARNING << "Strange value for f_DC_a1: " << f_DC_a1
00307 << "; setting f_DC_a1=0 (expected ~1e7)";
00308 WARNING.print();
00309 WARNING.print("other definition of ATLANTIS?");
00310 f_DC_a1 = 0.0;
00311 }
00312 DEBUG << "[" << linecounter
00313 << "]: string: \"Xtrack_f_DC_linear\", (derived) value: "
00314 << f_DC_a1;
00315 DEBUG.print();
00316 check += 16384;
00317 }
00318 else if (!strcmp(word,"Xtrack_f_DC_quadratic"))
00319 {
00320 resfile >> word >> word >> word >> f_DC_a2;
00321 if (abs(f_DC_a2)<1.0)
00322 {
00323 WARNING << "strange value for f_DC_a2: " << f_DC_a2
00324 << "; setting f_DC_a2=0 (expected ~1e12)";
00325 WARNING.print();
00326 WARNING.print("other definition of ATLANTIS?");
00327 f_DC_a2 = 0.0;
00328 }
00329 DEBUG << "[" << linecounter
00330 << "]: string: \"Xtrack_f_DC_quadratic\", (derived) value: "
00331 << f_DC_a2;
00332 DEBUG.print();
00333 check += 32768;
00334 }
00335
00336
00337
00338 else if (!strcmp(word,"SAR_PROCESSOR:"))
00339 {
00340 resfile >> word;
00341 DEBUG << "[" << linecounter
00342 << "]: string: \"SAR_PROCESSOR:\", (derived) value: "
00343 << word;
00344 DEBUG.print();
00345 if (!strcmp(word,"VMP"))
00346 {
00347 DEBUG.print("SAR_PROCESSOR: ESA VMP identified.");
00348 sar_processor = SARPR_VMP;
00349 }
00350 else if (!strcmp(word,"ATLANTIS"))
00351 {
00352 sar_processor = SARPR_ATL;
00353 DEBUG.print("SAR_PROCESSOR: ATLANTIS identified.");
00354 }
00355 else if (!strcmp(word,"TUD"))
00356 {
00357 sar_processor = SARPR_TUD;
00358 DEBUG.print("SAR_PROCESSOR: TUD identified.");
00359 }
00360 else
00361 {
00362 sar_processor = SARPR_VMP;
00363 WARNING.print("SAR_PROCESSOR: not identified, using VMP.");
00364 }
00365 check += 0;
00366 }
00367
00368
00369
00370
00371
00372 else if (!strcmp(word,"Product"))
00373 {
00374 resfile >> word >> word >> word;
00375 DEBUG << "[" << linecounter
00376 << "]: string: \"Product\", (derived) value: "
00377 << word;
00378 DEBUG.print();
00379 check += 65536;
00380
00381
00382
00383 char *pch;
00384 pch = strstr (word,"PRODUCT");
00385 if (pch != NULL)
00386 {
00387 sensor = SLC_ERS;
00388 DEBUG.print("Substring \"PRODUCT\" (radarsat?) found in Product type specifier.");
00389 char next_word[ONE27] = " ";
00390 resfile >> next_word;
00391 char *next_pch;
00392 next_pch = strstr (next_word,"ERS");
00393 if (next_pch != NULL)
00394 {
00395 DEBUG.print("Substring \"PRODUCT ERS\" found in Product type specifier.");
00396 sensor = SLC_ERS;
00397
00398 }
00399 next_pch = strstr (next_word,"RSAT");
00400 if (next_pch != NULL)
00401 {
00402 DEBUG.print("Substring \"PRODUCT RSAT\" found in Product type specifier.");
00403 sensor = SLC_RSAT;
00404 WARNING.print("Assuming Atlantis processor was used/format of SLC.");
00405 WARNING.print("If you don;t want this, change line in res file to:");
00406 WARNING.print("Product type specifier: ERS");
00407 }
00408 }
00409 pch = strstr (word,"RSAT");
00410 if (pch != NULL)
00411 {
00412 DEBUG.print("Substring \"RSAT\" found in Product type specifier.");
00413 sensor = SLC_RSAT;
00414 WARNING.print("Assuming Atlantis processor was used/format of SLC.");
00415 WARNING.print("If you don;t want this, change line in res file to:");
00416 WARNING.print("Product type specifier: ERS");
00417 }
00418 pch = strstr (word,"RADARSAT");
00419 if (pch != NULL)
00420 {
00421 DEBUG.print("Substring \"RADARSAT\" found in Product type specifier.");
00422 sensor = SLC_RSAT;
00423 WARNING.print("Assuming Atlantis processor was used/format of SLC.");
00424 WARNING.print("If you don;t want this, change line in res file to:");
00425 WARNING.print("Product type specifier: ERS");
00426 }
00427 pch = strstr (word,"ES");
00428 if (pch != NULL)
00429 {
00430 DEBUG.print("Substring \"ES\" found in Product type specifier.");
00431 sensor = SLC_ASAR;
00432 }
00433 pch = strstr (word,"ASAR");
00434 if (pch != NULL)
00435 {
00436 DEBUG.print("Substring \"ASAR\" found in Product type specifier.");
00437 sensor = SLC_ASAR;
00438 }
00439 pch = strstr (word,"ENVISAT");
00440 if (pch != NULL)
00441 {
00442 DEBUG.print("Substring \"ENVISAT\" found in Product type specifier.");
00443 sensor = SLC_ASAR;
00444 }
00445 pch = strstr (word,"ERS");
00446 if (pch != NULL)
00447 {
00448 DEBUG.print("Substring \"ERS\" found in Product type specifier.");
00449 sensor = SLC_ERS;
00450 }
00451 pch = strstr (word,"JERS");
00452 if (pch != NULL)
00453 {
00454 DEBUG.print("Substring \"JERS\" found in Product type specifier.");
00455 sensor = SLC_JERS;
00456 }
00457 DEBUG << "Product/sensor: " << sensor;
00458 DEBUG.print();
00459 }
00460
00461
00462 if (check == 1+2+4+8+32+128+256+512+1024+2048+4096+8192+16384+32768+65536)
00463 break;
00464 }
00465
00466 if (check != 1+2+4+8+32+128+256+512+1024+2048+4096+8192+16384+32768+65536)
00467 {
00468 WARNING << "Cannot find parameters in first 1000 lines of file: "
00469 << file
00470 << ". checksum = " << check << ". (see source code)";
00471 WARNING.print();
00472 showdata();
00473 }
00474 resfile.close();
00475
00476
00477 DEBUG << "sensor id: " << sensor;
00478 DEBUG.print();
00479 if (sensor==SLC_ERS)
00480 {
00481 DEBUG.print("ERS 1 or 2 sensor detected.");
00482 if (abs(wavelength-0.0565646) > 0.01)
00483 WARNING.print("wavelength seems to deviates more than 1 cm from ERS2 nominal.");
00484 if (abs(prf - 1680) > 100.0)
00485 WARNING.print("prf deviates more than 100 Hz from ERS2 nominal.");
00486 if (abs(rsr2x - 18.9624680*2.0e6) > 100000.0)
00487 WARNING.print("rsr deviates more than 0.1 MHz from ERS2 nominal.");
00488 if (abs(abw-1378.0) > 100)
00489 WARNING.print("ABW deviates more than 100 Hz from ERS2 nominal?");
00490 if (abs(rbw-15.55e6) > 1000)
00491 WARNING.print("RBW deviates more than 1 kHz from ERS2 nominal?");
00492 }
00493 if (sensor==SLC_ASAR)
00494 {
00495 INFO.print("Yeah, EnviSAT!");
00496 if (abs(wavelength-0.0562356) > 0.01)
00497 WARNING.print("wavelength seems to deviates more than 1 cm from ASAR nominal.");
00498 if (abs(prf-1652.0) > 100.0)
00499 WARNING.print("prf deviates more than 100 Hz from ASAR nominal.");
00500 if (abs(rsr2x - 19.207680*2.0e6) > 100000.0)
00501 WARNING.print("rsr deviates more than 0.1 MHz from ASAR nominal.");
00502 if (abs(abw-1316.0) > 100)
00503 WARNING.print("ABW deviates more than 100 Hz from ASAR nominal?");
00504 if (abs(rbw-16.0e6) > 1000)
00505 WARNING.print("RBW deviates more than 1 kHz from ASAR nominal?");
00506 }
00507 if (sensor==SLC_JERS)
00508 {
00509 WARNING.print("JERS detected: still in testing phase.");
00510 if (abs(wavelength-0.23076920) > 0.01)
00511 WARNING.print("wavelength seems to deviates more than 1 cm from JERS nominal.");
00512 if (abs(prf-1555.0) > 100.0)
00513 WARNING.print("prf deviates more than 100 Hz from JERS nominal.");
00514 if (abs(rsr2x - 17.075998*2.0e6) > 100000.0)
00515 WARNING.print("rsr deviates more than 0.1 MHz from JERS nominal.");
00516 if (abs(abw-1555.0) > 100)
00517 WARNING.print("ABW deviates more than 100 Hz from JERS nominal?");
00518 if (abs(rbw-17.075998*2.0e6) > 1000)
00519 WARNING.print("RBW deviates more than 1 kHz from JERS nominal?");
00520 }
00521 if (sensor==SLC_RSAT)
00522 {
00523 WARNING.print("RSAT detected: this is still in development.");
00524 WARNING.print(" +main difficulty with orbit in earth fixed system; doppler.");
00525 WARNING.print(" +but it seems to work with polyfit(max) for orbit interp.");
00526 }
00527
00528 INFO << setiosflags(ios::fixed)
00529 << setiosflags(ios::showpoint)
00530 << setprecision(3);
00531 INFO << "Range to pixel 1 = "
00532 << pix2range(1.0);
00533
00534 INFO.print();
00535 INFO << "Range to pixel " << originalwindow.pixhi << " = "
00536 << pix2range(originalwindow.pixhi);
00537
00538 INFO.print();
00539
00540
00541
00542
00543 const real8 earlyedgefDC = f_DC_a0;
00544
00545 const real8 extremepix = (abs(f_DC_a2)<1e-9) ? 0.0: f_DC_a1/(-2.0*f_DC_a2);
00546 const real8 extremefDC = f_DC_a0 +
00547 extremepix * f_DC_a1 +
00548 sqr(extremepix) * f_DC_a2;
00549 const real8 faredgefDC = f_DC_a0 +
00550 real8(originalwindow.pixhi-1)/(rsr2x/2.0) * f_DC_a1 +
00551 sqr(real8(originalwindow.pixhi-1)/(rsr2x/2.0)) * f_DC_a2;
00552 DEBUG << setiosflags(ios::scientific)
00553 << setprecision(8)
00554 << setiosflags(ios::showpos);
00555 DEBUG << "fDC(col) = "
00556 << f_DC_a0
00557 << f_DC_a1 << "*(col-1)/"
00558 << rsr2x/2
00559 << f_DC_a2 << "*((col-1)/"
00560 << rsr2x/2 << ")^2" << ends;
00561 DEBUG.print();
00562 DEBUG << "fDC(col) = "
00563 << f_DC_a0
00564 << f_DC_a1/(rsr2x/2) << "*(col-1)"
00565 << f_DC_a2/sqr(rsr2x/2) << "*(col-1)^2" << ends;
00566 DEBUG.print();
00567
00568
00569 INFO << "Doppler centroid frequency: at pixel 1 (early edge): \t\t"
00570 << earlyedgefDC;
00571 INFO.print();
00572 INFO << "Doppler centroid frequency: at pixel "
00573 << originalwindow.pixhi << " (far edge): \t"
00574 << faredgefDC;
00575 INFO.print();
00576 INFO << "Doppler centroid frequency: at pixel " << extremepix*rsr2x/2.;
00577
00578 (extremefDC >= earlyedgefDC) ?
00579 INFO << " (maximum): " : INFO << " (minimum): ";
00580 INFO << "\t"
00581 << extremefDC;
00582 INFO.print();
00583
00584
00585
00586 INFO << "sensor: " << sensor;
00587 INFO.print();
00588
00589
00590 pol2xyz(approxcentreoriginal,
00591 deg2rad(latitude),deg2rad(longitude),0.);
00592
00593 currentwindow.linelo = originalwindow.linelo;
00594 currentwindow.linehi = originalwindow.linehi;
00595 currentwindow.pixlo = originalwindow.pixlo;
00596 currentwindow.pixhi = originalwindow.pixhi;
00597
00598 #ifdef __DEBUG
00599 DEBUG.print("Finished fillslcimage");
00600 DEBUG.print("content of struct:");
00601 showdata();
00602 #endif
00603 DEBUG.reset();
00604 INFO.reset();
00605 }
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625 void slcimage::updateslcimage(
00626 const char *resultfile,
00627 const char *iden)
00628 {
00629 TRACE_FUNCTION("updateslcimage (BK 14-Aug-2000)")
00630 char word[ONE27]=" ";
00631 char dummyline[ONE27];
00632
00633
00634 ifstream resfile(resultfile, ios::in);
00635 bk_assert(resfile,resultfile,__FILE__,__LINE__);
00636
00637 bool foundiden = false;
00638 while(resfile)
00639 {
00640 if (strcmp(word,iden))
00641 {
00642 resfile.getline(dummyline,ONE27,'\n');
00643 resfile >> word;
00644 }
00645 else
00646 {
00647 foundiden = true;
00648 DEBUG << "updateimaginfo: found identifier: \"" << iden
00649 << "\" in file: \"" << resultfile << "\".";
00650 DEBUG.print();
00651 break;
00652 }
00653 }
00654
00655
00656 if (!foundiden)
00657 {
00658 ERROR << "(updateimaginfo). identifier: "
00659 << iden
00660 << " not found in file: " << resultfile;
00661 PRINT_ERROR(ERROR.get_str())
00662 throw(file_error);
00663 }
00664
00665
00666 int32 check = 0;
00667 while(resfile)
00668 {
00669 resfile.getline(dummyline,ONE27,'\n');
00670 resfile >> word;
00671 if (!strcmp(word,"Data_output_file:"))
00672 {
00673 resfile >> file;
00674 DEBUG << "string: \"Data_output_file:\", \t\tvalue: "
00675 << file;
00676 DEBUG.print();
00677 check += 1;
00678 }
00679 else if (!strcmp(word,"Data_output_format:"))
00680 {
00681 resfile >> word;
00682 if (!strcmp(word,"complex_short"))
00683 formatflag = FORMATCI2;
00684 else if (!strcmp(word,"complex_real4"))
00685 formatflag = FORMATCR4;
00686 else
00687 {
00688 PRINT_ERROR("wrong format specifier (impossible?)")
00689 throw(file_error);
00690 }
00691 DEBUG << "string: \"Data_output_format:\", \t\tvalue: "
00692 << formatflag;
00693 DEBUG.print();
00694 check += 1;
00695 }
00696 else if (!strcmp(word,"First_line"))
00697 {
00698 resfile >> word >> word >> currentwindow.linelo;
00699 DEBUG << "string: \"First_line\", \t\tvalue: "
00700 << currentwindow.linelo;
00701 DEBUG.print();
00702 check += 10;
00703 }
00704 else if (!strcmp(word,"Last_line"))
00705 {
00706 resfile >> word >> word >> currentwindow.linehi ;
00707 DEBUG << "string: \"Last_line\", \t\tvalue: "
00708 << currentwindow.linehi;
00709 DEBUG.print();
00710 check += 100;
00711 }
00712 else if (!strcmp(word,"First_pixel"))
00713 {
00714 resfile >> word >> word >> currentwindow.pixlo ;
00715 DEBUG << "string: \"First_pixel\", \t\tvalue: "
00716 << currentwindow.pixlo;
00717 DEBUG.print();
00718 check += 1000;
00719 }
00720 else if (!strcmp(word,"Last_pixel"))
00721 {
00722 resfile >> word >> word >> currentwindow.pixhi ;
00723 DEBUG << "string: \"Last_pixel\", \t\tvalue: "
00724 << currentwindow.pixhi;
00725 DEBUG.print();
00726 check += 10000;
00727 }
00728 if (check == 11112) break;
00729 }
00730
00731 if (check != 11112)
00732 {
00733 char str[EIGHTY];
00734 strcpy(str,"???");
00735 if (check == 11110)
00736 strcpy(str,"Data_output_file:");
00737 else if (check == 11101)
00738 strcpy(str,"First_line");
00739 else if (check == 11011)
00740 strcpy(str,"Last_line");
00741 else if (check == 10111)
00742 strcpy(str,"First_pixel");
00743 else if (check == 01111)
00744 strcpy(str,"Last_pixel");
00745 ERROR << "Missing info: " << str
00746 << " file: " << file
00747 << ". checksum= " << check << ".";
00748 PRINT_ERROR(ERROR.get_str())
00749 throw(some_error);
00750 }
00751
00752
00753 ifstream tmpfile(file, ios::in);
00754 if (tmpfile)
00755 {
00756 tmpfile.seekg(0,ios::end);
00757 uint filesizetrue = tmpfile.tellg();
00758
00759 int32 bytesperelem = 4;
00760 if (formatflag==FORMATCI2) bytesperelem=4;
00761 if (formatflag==FORMATCR4) bytesperelem=8;
00762 if (formatflag==FORMATR4) bytesperelem=4;
00763 if (formatflag==FORMATI2) bytesperelem=2;
00764 if (formatflag==FORMATI2_BIGENDIAN) bytesperelem=2;
00765 if (formatflag==FORMATR8) bytesperelem=8;
00766 if (formatflag==FORMATHGT) bytesperelem=8;
00767 int32 filesizecomp = currentwindow.lines()*currentwindow.pixels()*bytesperelem;
00768 DEBUG << "Checking format/dimensions file=" << file;
00769 DEBUG.print();
00770 if (filesizecomp != filesizetrue)
00771 {
00772 WARNING << "Fileformat or dimensions seem wrong"
00773 << "; bytesperpix=" << bytesperelem
00774 << "; #l=" << currentwindow.lines()
00775 << "; #p=" << currentwindow.pixels()
00776 << "; size=" << filesizetrue
00777 << "; size computed=" << filesizecomp;
00778 WARNING.print();
00779 }
00780 else
00781 {
00782 DEBUG.print("Fileformat and dimensions checked ok.");
00783 }
00784 tmpfile.close();
00785 }
00786 else
00787 {
00788 WARNING << "File: " << file
00789 << " does not seem to exist (may not be a problem).";
00790 WARNING.print();
00791 }
00792
00793
00794
00795 resfile.close();
00796 #ifdef __DEBUG
00797 DEBUG.print("Finished updateslcimage");
00798 DEBUG.print("content of struct:");
00799 showdata();
00800 #endif
00801 }
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814 matrix<complr4> slcimage::readdata(
00815 window win) const
00816 {
00817 TRACE_FUNCTION("readdata (BK 14-Aug-2000)")
00818 matrix<complr4> Result(win.lines(),win.pixels());
00819 switch (formatflag)
00820 {
00821 case FORMATCI2:
00822 {
00823 fileci2tomatcr4(Result,file,currentwindow.lines(),win,currentwindow);
00824 break;
00825 }
00826 case FORMATCR4:
00827 {
00828
00829
00830
00831
00832
00833
00834
00835 readfile(Result,file,currentwindow.lines(),win,currentwindow);
00836 break;
00837 }
00838 default:
00839 PRINT_ERROR("readdata::not correct format on file.")
00840 throw(file_error);
00841 }
00842 return Result;
00843
00844 }
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864 void slcimage::updateslcimageML(
00865 const char *resultfile,
00866 const char *iden)
00867 {
00868 TRACE_FUNCTION("updateslcimageML (Raffaele Nutricato 12-Jan-2004)")
00869 char word[ONE27]=" ";
00870 char dummyline[ONE27];
00871
00872 INFO << "Reading parameters from: " << resultfile;
00873 INFO.print();
00874
00875
00876
00877 ifstream resfile(resultfile, ios::in);
00878 bk_assert(resfile,resultfile,__FILE__,__LINE__);
00879
00880 bool foundiden = false;
00881 while(resfile)
00882 {
00883 if (strcmp(word,iden))
00884 {
00885 resfile.getline(dummyline,ONE27,'\n');
00886 resfile >> word;
00887 }
00888 else
00889 {
00890 foundiden = true;
00891 DEBUG << "updateimaginfo: found identifier: \"" << iden
00892 << "\" in file: \"" << resultfile << "\".";
00893 DEBUG.print();
00894 break;
00895 }
00896 }
00897
00898
00899 if (!foundiden)
00900 {
00901 ERROR << "(updateimaginfo). identifier: "
00902 << iden
00903 << " not found in file: " << resultfile;
00904 PRINT_ERROR(ERROR.get_str())
00905 throw(some_error);
00906 }
00907
00908
00909 int32 numlineschecked = 0;
00910 bool foundfilename = false;
00911 bool foundfileformat = false;
00912 bool foundfirstline = false;
00913 bool foundlastline = false;
00914 bool foundfirstpixel = false;
00915 bool foundlastpixel = false;
00916 bool foundmlL = false;
00917 bool foundmlP = false;
00918
00919 float tmpmultilookL;
00920 float tmpmultilookP;
00921 uint tmplinelo;
00922 uint tmplinehi;
00923 uint tmppixlo;
00924 uint tmppixhi;
00925
00926
00927 while(resfile)
00928 {
00929 numlineschecked++;
00930 resfile.getline(dummyline,ONE27,'\n');
00931 resfile >> word;
00932 if (!strcmp(word,"Data_output_file:"))
00933 {
00934 if (!foundfilename)
00935 {
00936 foundfilename = true;
00937 resfile >> file;
00938 DEBUG << "string: \"Data_output_file:\", \t\tvalue: "
00939 << file;
00940 DEBUG.print();
00941 }
00942 else
00943 WARNING.print("String: \"Data_output_file:\" found again (ignored).");
00944 }
00945 else if (!strcmp(word,"Data_output_format:"))
00946 {
00947 if (!foundfileformat)
00948 {
00949 foundfileformat = true;
00950 resfile >> word;
00951 if (!strcmp(word,"complex_short"))
00952 formatflag = FORMATCI2;
00953 else if (!strcmp(word,"complex_real4"))
00954 formatflag = FORMATCR4;
00955 else
00956 {
00957 PRINT_ERROR("wrong format specifier (impossible?)")
00958 throw(file_error);
00959 }
00960 DEBUG << "string: \"Data_output_format:\", \t\tvalue: "
00961 << formatflag;
00962 DEBUG.print();
00963 }
00964 else
00965 WARNING.print("String: \"Data_output_format:\" found again (ignored).");
00966 }
00967
00968 else if (!strcmp(word,"Multilookfactor_azimuth_direction:"))
00969 {
00970 if (!foundmlL)
00971 {
00972 foundmlL = true;
00973 resfile >> tmpmultilookL;
00974 DEBUG << "String: \"Multilookfactor_azimuth_direction:\", value: "
00975 << tmpmultilookL;
00976 DEBUG.print();
00977 if (tmpmultilookL > 1)
00978 {
00979 PRINT_ERROR("Decimation of slc along azimuth direction not implemented yet.");
00980 throw(file_error);
00981 }
00982 }
00983 else
00984 WARNING.print("String: \"Multilookfactor_azimuth_direction:\" found again (ignored).");
00985 }
00986 else if (!strcmp(word,"Multilookfactor_range_direction:"))
00987 {
00988 if (!foundmlP)
00989 {
00990 foundmlP = true;
00991 resfile >> tmpmultilookP;
00992 DEBUG << "String: \"Multilookfactor_range_direction:\", \tvalue: "
00993 << tmpmultilookP;
00994 DEBUG.print();
00995 if (tmpmultilookP > 1)
00996 {
00997 PRINT_ERROR("Decimation of slc along range direction not implemented yet.");
00998 throw(file_error);
00999 }
01000 }
01001 else
01002 WARNING.print("String: \"Multilookfactor_range_direction:\" found again (ignored).");
01003 }
01004 else if (!strcmp(word,"First_line"))
01005 {
01006 if (!foundfirstline)
01007 {
01008 foundfirstline = true;
01009 resfile >> word >> word >> tmplinelo;
01010 DEBUG << "string: \"First_line\", \t\tvalue: "
01011 << tmplinelo;
01012 DEBUG.print();
01013 }
01014 else
01015 WARNING.print("String: \"First_line:\" found again (ignored).");
01016 }
01017 else if (!strcmp(word,"Last_line"))
01018 {
01019 if (!foundlastline)
01020 {
01021 foundlastline = true;
01022 resfile >> word >> word >> tmplinehi ;
01023 DEBUG << "string: \"Last_line\", \t\tvalue: "
01024 << tmplinehi;
01025 DEBUG.print();
01026 }
01027 else
01028 WARNING.print("String: \"Last_line:\" found again (ignored).");
01029 }
01030 else if (!strcmp(word,"First_pixel"))
01031 {
01032 if (!foundfirstpixel)
01033 {
01034 foundfirstpixel = true;
01035 resfile >> word >> word >> tmppixlo ;
01036 DEBUG << "string: \"First_pixel\", \t\tvalue: "
01037 << tmppixlo;
01038 DEBUG.print();
01039 }
01040 else
01041 WARNING.print("String: \"First_pixel:\" found again (ignored).");
01042 }
01043 else if (!strcmp(word,"Last_pixel"))
01044 {
01045 if (!foundlastpixel)
01046 {
01047 foundlastpixel = true;
01048 resfile >> word >> word >> tmppixhi ;
01049 DEBUG << "string: \"Last_pixel\", \t\tvalue: "
01050 << tmppixhi;
01051 DEBUG.print();
01052 }
01053 else
01054 WARNING.print("String: \"Last_pixel:\" found again (ignored).");
01055 }
01056
01057 if (foundfilename && foundfileformat &&
01058 foundfirstline && foundlastline && foundfirstpixel && foundlastpixel &&
01059 foundmlL && foundmlP) break;
01060 }
01061
01062 if (!(foundfilename && foundfileformat &&
01063 foundfirstline && foundlastline && foundfirstpixel && foundlastpixel &&
01064 foundmlL && foundmlP))
01065 {
01066 char str[EIGHTY];
01067 if (!foundfilename)
01068 strcpy(str,"Data_output_file:");
01069 else if (!foundfileformat)
01070 strcpy(str,"Data_output_format:");
01071 else if (!foundfirstline)
01072 strcpy(str,"First_line");
01073 else if (!foundlastline)
01074 strcpy(str,"Last_line");
01075 else if (!foundfirstpixel)
01076 strcpy(str,"First_pixel");
01077 else if (!foundlastpixel)
01078 strcpy(str,"Last_pixel");
01079 else if (!foundmlL)
01080 strcpy(str,"Multilookfactor_azimuth_direction:");
01081 else if (!foundmlP)
01082 strcpy(str,"Multilookfactor_range_direction:");
01083 ERROR << "Missing info: " << str
01084 << " file: " << file << ".";
01085 PRINT_ERROR(ERROR.get_str())
01086 throw(file_error);
01087 }
01088
01089
01090 int32 osfactL = int32(1./tmpmultilookL+.5);
01091 int32 osfactP = int32(1./tmpmultilookP+.5);
01092 WARNING.print("I assume abw and rbw should also be adapted?");
01093 WARNING.print("Better use the above function, not copy of code???");
01094 WARNING.print("is SARPROCESSOR defined here?");
01095 WARNING.print("Bert Kampes, 20-Apr-2005");
01096 prf *= osfactL;
01097 rsr2x *= osfactP;
01098 currentwindow.linelo = (tmplinelo-1)*osfactL+1;
01099 currentwindow.linehi = tmplinehi*osfactL;
01100 currentwindow.pixlo = (tmppixlo-1)*osfactP+1;
01101 currentwindow.pixhi = tmppixhi*osfactP;
01102 originalwindow.linehi *= osfactL;
01103 originalwindow.pixhi *= osfactP;
01104
01105
01106 INFO << "Updated the following parameters: ";
01107 INFO.print();
01108 INFO << "First_line (w.r.t. original_image): " << currentwindow.linelo;
01109 INFO.print();
01110 INFO << "Last_line (w.r.t. original_image): " << currentwindow.linehi;
01111 INFO.print();
01112 INFO << "First_pixel (w.r.t. original_image): " << currentwindow.pixlo;
01113 INFO.print();
01114 INFO << "Last_pixel (w.r.t. original_image): " << currentwindow.pixhi;
01115 INFO.print();
01116 INFO << "Number_of_lines_original: " << originalwindow.linehi;
01117 INFO.print();
01118 INFO << "Number_of_pixels_original: " << originalwindow.pixhi;
01119 INFO.print();
01120 INFO << "Range_sampling_rate (leaderfile, MHz): " << rsr2x/2.0;
01121 INFO.print();
01122 INFO << "Pulse_Repetition_Frequency (actual, Hz): " << prf;
01123 INFO.print();
01124
01125
01126
01127
01128 ifstream tmpfile(file, ios::in);
01129 if (tmpfile)
01130 {
01131 tmpfile.seekg(0,ios::end);
01132 uint filesizetrue = tmpfile.tellg();
01133
01134 int32 bytesperelem = 4;
01135 if (formatflag==FORMATCI2) bytesperelem=4;
01136 if (formatflag==FORMATCR4) bytesperelem=8;
01137 if (formatflag==FORMATR4) bytesperelem=4;
01138 if (formatflag==FORMATI2) bytesperelem=2;
01139 if (formatflag==FORMATI2_BIGENDIAN) bytesperelem=2;
01140 if (formatflag==FORMATR8) bytesperelem=8;
01141 if (formatflag==FORMATHGT) bytesperelem=8;
01142 int32 filesizecomp = currentwindow.lines()*currentwindow.pixels()*bytesperelem;
01143 DEBUG << "Checking format/dimensions file=" << file;
01144 DEBUG.print();
01145 if (filesizecomp != filesizetrue)
01146 {
01147 WARNING << "Fileformat or dimensions seem wrong"
01148 << "; bytesperpix=" << bytesperelem
01149 << "; #l=" << currentwindow.lines()
01150 << "; #p=" << currentwindow.pixels()
01151 << "; size=" << filesizetrue
01152 << "; size computed=" << filesizecomp;
01153 WARNING.print();
01154 }
01155 else
01156 {
01157 DEBUG.print("Fileformat and dimensions checked ok.");
01158 }
01159 tmpfile.close();
01160 }
01161 else
01162 {
01163 WARNING << "File: " << file
01164 << " does not seem to exist (may not be a problem).";
01165 WARNING.print();
01166 }
01167
01168
01169
01170 resfile.close();
01171 #ifdef __DEBUG
01172 DEBUG.print("Finished updateslcimage");
01173 DEBUG.print("content of struct:");
01174 showdata();
01175 #endif
01176 }
01177
01178
01179