Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

processor.cc

Go to the documentation of this file.
00001 /*
00002  @file   processor.cc Doris InSAR processor.
00003  @brief  main routine calling all modules.
00004 */
00005 /*
00006  * Copyright (c) 1999-2003 Bert Kampes
00007  * Copyright (c) 1999-2003 Delft University of Technology, The Netherlands
00008  *
00009  * This file is part of Doris, the Delft o-o radar interferometric software.
00010  *
00011  * Doris program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * Doris is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  *
00025  * Publications that contain results produced by the Doris software should
00026  * contain an acknowledgment. (For example: The interferometric processing
00027  * was performed using the freely available Doris software package developed
00028  * by the Delft Institute for Earth-Oriented Space Research (DEOS), Delft
00029  * University of Technology, or include a reference to: Bert Kampes and
00030  * Stefania Usai. \"Doris: The Delft Object-oriented Radar Interferometric
00031  * software.\" In: proceedings 2nd ITC ORS symposium, August 1999. (cdrom)).
00032  *
00033  */
00034 
00035 /****************************************************************
00036  * $Source: /users/kampes/DEVELOP/DORIS/doris/src/RCS/processor.cc,v $  *
00037  * $Revision: 3.43 $                                            *
00038  * $Date: 2005/04/22 11:30:15 $                                 *
00039  * $Author: kampes $                                            *
00040  *                                                              *
00041  * - main()                                                     *
00042  * - initmessages()                                             *
00043  * - handleinput()                                              *
00044  * - usage()                                                    *
00045  * - copyright()                                                *
00046  * - quote()                                                    *
00047  * - preview(...)                                               *
00048  ****************************************************************/
00049 
00050 
00051 // ====== Include files used here =========================================
00052 #include "matrixbk.hh"                  // my matrix class
00053 #include "orbitbk.hh"                   // my orbit class (includes matrix class)
00054 #include "slcimage.hh"                  // my slc image class
00055 #include "productinfo.hh"               // my 'products' class
00056 #include "constants.hh"                 // global,general structs/typedefs/constants
00057 #include "utilities.hh"                 // interpolation etc.
00058 #include "ioroutines.hh"                // errormessages, readinput, ...
00059 #include "step1routines.hh"             // routines slc2dsk, readfiles, .
00060 #include "coregistration.hh"            // routines for coarse coreg
00061 #include "referencephase.hh"            // flatearth, radarcode dem
00062 #include "products.hh"                  // routines for interferogram/coherence
00063 #include "geocode.hh"                   // routines for s2h, DEM generation etc.
00064 #include "unwrap.hh"                    // routines for unwrapping
00065 #include "filtering.hh"                 // routines for filtering
00066 #include "conversion.hh"                // deg2rad
00067 #include "exceptions.hh"                // error message class (throw these)
00068 
00069 #include "bk_baseline.hh"               // my baseline class for modeling bperp etc.
00070 
00071 #include <iostream>                     // cout, ...
00072 #include <fstream>                      // files, ...
00073 #include <ctime>                        // time
00074 #include <cstdlib>                      // system, atoi
00075 #include <cctype>                       // isspace
00076 #include <algorithm>                    // min max
00077 #include <cstring>                      // strcat according to g++ (?)
00078 #include <csignal>                      // function signal()
00079 
00080 
00081 
00082 
00083 // ====== Global variables, declared extern in constants.h ======
00084 // === Declared extern in constants.h, set in main to be able to use them ===
00085 // === in readinput.cc they are set via the input file ======================
00086 bk_messages TRACE;
00087 bk_messages DEBUG;
00088 bk_messages INFO;
00089 bk_messages PROGRESS;
00090 bk_messages WARNING;
00091 bk_messages ERROR;
00092 bk_messages matDEBUG;
00093 bk_messages matERROR;
00094 
00095 // ______ used in matrix_bk.cc to keep track of total allocated ______
00096 #ifdef __DEBUGMAT2      // use index checking, alloc
00097 uint totalallocated=0;  // [B] matrixdebuging
00098 #endif
00099 
00100 
00101 
00102 // ====== Prototypes functions in this file ======
00103 void initmessages();
00104 void usage(char *programname);
00105 void handleinput(int argc, char* argv[], input_gen &for_inputfilename);
00106 void quote();
00107 void copyright();
00108 void preview(int32 previewflag, int32 width, int32 informat, char *infile, char *outfile, char *opts);
00109 
00110 
00111 
00112 
00113 
00114 /****************************************************************
00115  @brief  main main program
00116  @param  argc argument count
00117  @param  argv value of arguments
00118  *    main                                                      *
00119  * A big switch to select the modules the user requests.        *
00120  * Handles some general information such as size of             *
00121  * current file as well.                                        *
00122  *    Bert Kampes, 11-Dec-1998                                  *
00123  ****************************************************************/
00124 int main(
00125         int argc,
00126         char* argv[])
00127   {
00128   // ___ catch math errors ___
00129   CatchSignals(handle_signal);// handle SIGFPE etc.
00130   // try should work nowadys compilers
00131   try{
00132   // ====== Set defaults for message class so we can use it here ======
00133   initmessages();
00134 
00135   // ====== ident string for `what doris` ======
00136   char ident[] = "@(#)Doris InSAR software, $Revision: 3.43 $, $Author: kampes $";
00137   cerr << endl;
00138   INFO.print(ident);
00139 
00140   // ====== Structs for storing input ======
00141   input_gen             input_general;          // general inputparameters
00142                                                 // misuse logfile for input file name
00143   input_ell             input_ellips;           // ellipsoid pm.
00144   input_pr_orbits       input_porbits;          // inputparam. readfiles slave
00145   input_readfiles       input_m_readfiles;      // inputparam. readfiles master
00146   input_crop            input_m_crop;           // inputparam. crop master
00147   input_oversample      input_m_oversample;     // by Raffaele Nutricato
00148 
00149   input_readfiles       input_s_readfiles;      // inputparam. readfiles slave
00150   input_crop            input_s_crop;           // inputparam. crop slave
00151   input_oversample      input_s_oversample;     // by Raffaele Nutricato
00152   input_filtazi         input_ms_filtazi;       // inputparam. azimuth filtering
00153   input_resample        input_s_resample;       // inputparam. resample
00154 
00155   input_coarsecorr      input_i_coarsecorr;     // inputparam. coarse correlation
00156   input_fine            input_i_fine;           // inputparam. fine correlation
00157   input_coregpm         input_i_coregpm;        // inputparam. coreg pm comp.
00158   input_filtrange       input_ms_filtrange;     // inputparam. range filtering
00159   input_interfero       input_i_interfero;      // inputparam. interfero.
00160   input_coherence       input_i_coherence;      // inputparam. coherence
00161   input_comprefpha      input_i_comprefpha;     // inputparam. flat earth corr.
00162   input_subtrrefpha     input_i_subtrrefpha;    // inputparam. subtr earth corr.
00163   input_comprefdem      input_i_comprefdem;     // inputparam. ref. dem
00164   input_subtrrefdem     input_i_subtrrefdem;    // inputparam. subtr ref. dem
00165   input_filtphase       input_i_filtphase;      // inputparam. phase filter
00166   input_dinsar          input_i_dinsar; // inputparam. 3pass diff. insar
00167   input_unwrap          input_i_unwrap;         // inputparam. unwrapping
00168   input_slant2h         input_i_slant2h;        // inputparam. slant2height
00169   input_geocode         input_i_geocode;        // inputparam. geocode
00170 
00171 
00172 // ______ Info on images/products ______
00173   slcimage              master;                 // info on master image
00174   slcimage              slave;                  // info on slave image
00175   productinfo           interferogram;          // interferogram
00176   productinfo           unwrappedinterf;        // interferogram unwrapped
00177   //productinfo         differentialinterf;     // diff. interferogram
00178   productinfo           radarcodedrefdem;       // reference DEM
00179   productinfo           coherence;              // coherence image
00180   productinfo           heightinradarsystem;    // s2h, in radarcoord.
00181 
00182 
00183 // ______ Orbital data (interpolation) ______
00184   orbit masterorbit;                            // class orbit
00185   orbit slaveorbit;                             // class orbit
00186 
00187 
00188 // ______ Matrices for storing polynomial coefficients ______
00189   matrix<real8> coeff_cpmL;                     // coregistration parameters
00190   matrix<real8> coeff_cpmP;                     // coregistration parameters
00191   matrix<real8> coeff_flat;                     // flatearth correction
00192 
00193 
00194 
00195 // ====== Initialize options ("inputoptionsfile"), files etc ======
00196   handleinput(argc,argv,input_general);         // handle input
00197   printcpu(1);                                  // initialize timers
00198   readinput(input_general,                      // fill input structs
00199             input_ellips,
00200             input_porbits,
00201             input_m_readfiles,
00202             input_m_crop,
00203             input_m_oversample, // added by ____RaffaeleNutricato
00204             input_s_readfiles,
00205             input_s_crop,
00206             input_s_oversample, // added by ____RaffaeleNutricato
00207             input_ms_filtazi,
00208             input_i_coarsecorr,
00209             input_i_fine,
00210             input_i_coregpm,
00211             input_s_resample,
00212             input_ms_filtrange,
00213             input_i_interfero,
00214             input_i_coherence,
00215             input_i_comprefpha,
00216             input_i_subtrrefpha,
00217             input_i_comprefdem,
00218             input_i_subtrrefdem,
00219             input_i_filtphase,
00220             input_i_dinsar,
00221             input_i_unwrap,
00222             input_i_slant2h,
00223             input_i_geocode);
00224   // ___ Perform some initial tests of platform after SCREEN is set ___
00225   inittest();                                   // initial tests
00226   // ___ transfer general input to orbit ___
00227   masterorbit.set_interp_method(input_general.orb_interp);// transfer input
00228   slaveorbit.set_interp_method(input_general.orb_interp);// transfer input
00229   // ___ trace function after readinput (screen level known) ___
00230   TRACE_FUNCTION("main");
00231 
00232 
00233 
00234 // ====== Write initial info if appropriate ======
00235   initwrite(input_general.logfile, LOGID);              // general info logfile(=1)
00236   bool processmaster = doinitwrite(input_general, MASTERID);
00237   bool processlave   = doinitwrite(input_general, SLAVEID);
00238   bool processinterf = doinitwrite(input_general, INTERFID);
00239   if (processmaster)
00240     initwrite(input_general.m_resfile, MASTERID);       // general info master result=2
00241   if (processlave)
00242     initwrite(input_general.s_resfile, SLAVEID);        // general info slave result=3
00243   if (processinterf)
00244     initwrite(input_general.i_resfile, INTERFID);       // general info interf_out=4
00245   updatefile("scratchreadinput",input_general.logfile); // copy input2log (readinput)
00246 
00247 
00248 
00249 // ====== Check requested processing and fill alreadyprocessed ======
00250   int16 alreadyprocessed[NUMPROCESSES];
00251   checkprocessing(input_general,alreadyprocessed);      // initialize alreadyprocessed
00252 
00253   DEBUG.print("Time spent for initialization:");
00254   printcpu(); 
00255   PROGRESS.print("Finished initialization");
00256 
00257 
00258 
00259 
00260 // *********************************************************
00261 // **** start master                                    ****
00262 // *********************************************************
00263 
00264 // ====== PROCESS INFOFILES CDROM: MASTER ======
00265   if (input_general.process[pr_m_readfiles])
00266     {
00267     PROGRESS.print("Start M_READFILES.");
00268     alreadyprocessed[pr_m_readfiles]=1;                         // update alreadypr.
00269     if (input_general.interactive)
00270       {
00271       cerr << "\nProcessing readfiles for master.";
00272       getanswer();
00273       }
00274 
00275     // ______ Select method for READFILES______
00276     switch (input_m_readfiles.sensor_id)
00277       {
00278       // ______ JERS also ceos? (falls through to ers) ______
00279       case SLC_JERS:
00280         INFO.print("JERS: Under development: is JERS really CEOS like ERS?");
00281       // ______ RSAT also CEOS? (falls through to ERS, account in reader) ______
00282       case SLC_RSAT:
00283         WARNING.print("RSAT: for orbit highest polyfit recommended.");
00284         WARNING.print("RSAT: Under development: CEOS reader seems to work.");
00285       // ______ ERS-1/2 ______
00286       case SLC_ERS:
00287         // ______ Get checks slave volumefile ______
00288         char c16checkvol1[17];
00289         char c16checkvol2[17];
00290         char c16checkvol3[17];  // check id of volume file
00291         if (alreadyprocessed[pr_s_readfiles])
00292           {
00293           readres(c16checkvol1,sizeof(c16checkvol1),
00294             input_general.s_resfile,"Volume_ID:");
00295           readres(c16checkvol2,sizeof(c16checkvol2),
00296             input_general.s_resfile,"Volume_identifier:");
00297           readres(c16checkvol3,sizeof(c16checkvol3),
00298             input_general.s_resfile,"Volume_set_identifier:");
00299           }
00300         // ______ Extract info ______
00301         readvolume(input_m_readfiles,
00302           c16checkvol1, c16checkvol2, c16checkvol3);
00303         // ___ written in readvolume ___
00304         updatefile("scratchresvol",input_general.m_resfile);
00305         // ___ written in readvolume ___
00306         updatefile("scratchlogvol",input_general.logfile);
00307         // ______Get check with master volumefile______
00308         char c8checkleadat[9];  // check vol met lea en dat
00309         readres(c8checkleadat,sizeof(c8checkleadat),
00310           input_general.m_resfile,"(Check)Number",5);
00311         // ______ Extract info ______
00312         // read info
00313         readleader(input_m_readfiles, atoi(c8checkleadat)-1);
00314         // made in readleader
00315         updatefile("scratchreslea",input_general.m_resfile);
00316         // made in readleader
00317         updatefile("scratchloglea",input_general.logfile);
00318         // ______ DONT PROCESS NULLFILE ______
00319         //    readnull(input_m_readfiles);
00320         //    updatefile("scratchresnull",input_general.m_resfile);
00321         //    updatefile("scratchlognull",input_general.logfile);
00322         //
00323         // read data file info
00324         readdat(input_m_readfiles, atoi(c8checkleadat)-1);
00325         // update resfile
00326         updatefile("scratchresdat",input_general.m_resfile);
00327         // update logfile
00328         updatefile("scratchlogdat",input_general.logfile);
00329         break;
00330       // ______ ENVISAT ASAR ______
00331       case SLC_ASAR:
00332         INFO.reset();// make sure nothing in buffer
00333         INFO << "envisat_dump_header2doris.csh "
00334              << input_m_readfiles.datfile
00335              << " > scratchres_envisat" << endl << ends;
00336         char cmd[512];// command string
00337         strcpy(cmd, INFO.get_str());
00338         INFO.print("With following command the envisat header was read.");
00339         INFO.print(cmd);
00340         PROGRESS.print("Making system call to envisat_dump_header2doris.csh");
00341         PROGRESS.print("(also requires envisat_dump_header program)");
00342         system(cmd);// this does the work
00343         INFO.reset();
00344         PROGRESS.print("Finished system call to envisat_dump_header2doris.csh");
00345         // ___ update resfile ___
00346         updatefile("scratchres_envisat",input_general.m_resfile);
00347         // ___ update logfile ___
00348         updatefile("envisat_dump_header.log",input_general.logfile);
00349         break;
00350       default:
00351         PRINT_ERROR("impossible error for checked input.")
00352         throw(input_error);// exit
00353       }
00354     PROGRESS.print("Finished M_READFILES.");
00355     DEBUG.print("Time spent for reading files master:");
00356     printcpu(); 
00357     }
00358 
00359 // ______Fill slcimage struct______
00360   if (existed(input_general.m_resfile))
00361     {
00362     master.fillslcimage(input_general.m_resfile);
00363     interferogram.win = master.currentwindow;
00364     }
00365 
00366   // ______ Account for timing errors ______
00367   DEBUG.print("Correction for master image timing errors if specified");
00368   DEBUG << "rg_timing_error: " << input_m_readfiles.rg_timing_error;
00369   DEBUG.print();
00370   DEBUG << "az_timing_error: " << input_m_readfiles.az_timing_error;
00371   DEBUG.print();
00372   master.add_rg_t_error(input_m_readfiles.rg_timing_error);
00373   master.add_az_t_error(input_m_readfiles.az_timing_error);
00374 
00375 
00376 // ====== GET PRECISE ORBITS (GETORB): MASTER ======
00377 // BK 15-Dec-2003 (moved before crop since required if dbow_geo
00378   if (input_general.process[pr_m_porbits])
00379     {
00380     PROGRESS.print("Start M_PORBITS.");
00381     alreadyprocessed[pr_m_porbits]=1;   // update alreadypr.
00382     if (input_general.interactive)
00383       {
00384       cerr << "\nProcessing get precise orbits for master.";
00385       getanswer();
00386       }
00387     // ______ Getorb does the real work ______
00388     getorb(master,input_porbits,MASTERID);
00389     convertgetorbout(MASTERID);
00390     // ______ result of conv.getorb master ______
00391     updatefile("scratchdatapoints",input_general.m_resfile);
00392     // ______ remove data section by leader ______
00393     removedatleader(input_general.m_resfile);
00394     PROGRESS.print("Finished M_PORBITS.");
00395     DEBUG.print("Time spent for obtaining precise orbits master:");
00396     printcpu(); 
00397     }
00398 // ______ Get coefficients for orbit interpolation if data in file ______
00399   //(alreadyprocessed[pr_m_readfiles] && isspace(input_porbits.m_orbdir[0])))
00400   if (alreadyprocessed[pr_m_porbits]    ||
00401       alreadyprocessed[pr_m_readfiles])
00402     masterorbit.initialize(input_general.m_resfile);
00403 
00404   // ______ Dump interpolated orbit if requested ______
00405   // ______ also possible to dump orbit of readfiles with card M_ORB_DUMP ___
00406   // ___ this returns if no orbit available ___
00407   masterorbit.dumporbit(input_porbits,MASTERID);
00408 
00409 
00410 
00411 // ====== PROCESS DATAFILE CDROM: MASTER ======
00412   if (input_general.process[pr_m_crop])
00413     {
00414     PROGRESS.print("Start M_CROP.");
00415     alreadyprocessed[pr_m_crop]=1;      // update alreadypr.
00416     if (input_general.interactive)
00417       {
00418       cerr << "\nProcessing crop for master.";
00419       getanswer();
00420       }
00421 
00422     // ______ Assume orbits loaded, use GEO card if present ______
00423     if (input_m_crop.dbow_geo.pixhi != 0)
00424       {
00425       PROGRESS.print("Computing crop based on center lat/lon/height/width.");
00426       real8 centerline, centerpix;
00427       real8 centerphi    = deg2rad(input_m_crop.dbow_geo.linelo/1e6-360.0);
00428       real8 centerlambda = deg2rad(input_m_crop.dbow_geo.linehi/1e6-360.0);
00429       //real8 centerheight = 0.0;
00430       real8 centerheight = input_general.terrain_height;
00431       DEBUG.print("Using height of HEIGHT card");
00432       DEBUG << "CROP: center lat/lon/hei: " 
00433             << centerphi << " " << centerlambda << " " << centerheight;
00434       DEBUG.print();
00435       cn centerpos;// compute phi/lambda/h-->x,y,z
00436       ell2xyz(input_ellips,centerpos,centerphi,centerlambda,centerheight);
00437       DEBUG << "Converted M_DBOW_GEO phi,lambda --> x,y,z: "
00438             << centerphi << ", " << centerlambda << ", " << " --> "
00439             << centerpos.x << " " << centerpos.y << " " << centerpos.z;
00440       DEBUG.print();
00441       DEBUG << "Center master SLC: x,y,z: "
00442             << master.approxcentreoriginal.x << " " 
00443             << master.approxcentreoriginal.y << " "
00444             << master.approxcentreoriginal.z;
00445       DEBUG.print();
00446       if (abs(master.approxcentreoriginal.x-centerpos.x)>50000.0)// 50km
00447         WARNING.print("M_DBOW_GEO: coordinates seem to be outside SLC area? (X)");
00448       if (abs(master.approxcentreoriginal.y-centerpos.y)>50000.0)// 50km
00449         WARNING.print("M_DBOW_GEO: coordinates seem to be outside SLC area? (Y)");
00450       if (abs(master.approxcentreoriginal.z-centerpos.z)>50000.0)// 50km
00451         WARNING.print("M_DBOW_GEO: coordinates seem to be outside SLC area? (Z)");
00452       int32 n_iter = xyz2lp(centerline, centerpix,
00453         master, masterorbit, centerpos,
00454         10, 1e-3);// MAXITERATIONS, CONVERGENCE_TIME
00455       // old way: cannot check with center coordinates:
00456       //int32 n_iter = ell2lp(centerline, centerpix, input_ellips, 
00457       //  master, masterorbit, centerphi, centerlambda, centerheight,
00458       //  10, 1e-3);// MAXITERATIONS, CONVERGENCE_TIME
00459       DEBUG << "CROP: center line/pix: " << centerline << " " << centerpix;
00460       DEBUG.print();
00461       int32 l0 = int32(centerline+0.5) - input_m_crop.dbow_geo.pixlo/2;
00462       int32 lN = l0 + input_m_crop.dbow_geo.pixlo - 1;
00463       int32 p0 = int32(centerpix+0.5)  - input_m_crop.dbow_geo.pixhi/2;
00464       int32 pN = p0 + input_m_crop.dbow_geo.pixhi - 1;
00465       //DEBUG.print("there is still a problem here possibly");
00466       //DEBUG.print("but we have to change this anyway to account for H");
00467       //if (l0 < 0) l0 = 0;// since int with uint compared..
00468       //if (lN < 0) pN = 999999;// since int with uint compared..
00469       //if (p0 < 0) pN = 0;// since int with uint compared..
00470       //if (pN < 0) pN = 999999;// since int with uint compared..
00471       //if (l0 > lN) l0 = 0;// since int with uint compared..
00472       //if (p0 > pN) p0 = 0;// since int with uint compared..
00473       //if (lN < l0) lN = 999999;// since int with uint compared..
00474       //if (pN < p0) pN = 999999;// since int with uint compared..
00475       if (l0 < int32(master.currentwindow.linelo)) l0 = master.currentwindow.linelo;
00476       if (lN > int32(master.currentwindow.linehi)) lN = master.currentwindow.linehi;
00477       if (p0 < int32(master.currentwindow.pixlo))  p0 = master.currentwindow.pixlo;
00478       if (pN > int32(master.currentwindow.pixhi))  pN = master.currentwindow.pixhi;
00479       INFO << "DBOW from GEO: " << l0 << " " << lN << " " << p0 << " " << pN;
00480       INFO.print();
00481       // ___ Simply fill dbow with it and it will be done correctly! ___
00482       input_m_crop.dbow.linelo = uint(l0);
00483       input_m_crop.dbow.linehi = uint(lN);
00484       input_m_crop.dbow.pixlo  = uint(p0);
00485       input_m_crop.dbow.pixhi  = uint(pN);
00486       }
00487 
00488     // ______ For each sensor, of course the formats differ... ______
00489     // ______ make sure radarsat_dump_data is called for ATLANTIS ______
00490     switch (master.sensor)
00491       {
00492       // ______ JERS also CEOS? (falls through to ers) ______
00493       case SLC_JERS:
00494         WARNING.print("JERS: Under development: is JERS really CEOS like ERS?");
00495       // ______ ERS-1/2 ______
00496       case SLC_ERS:
00497         switch (master.sar_processor)
00498           {
00499           case SARPR_VMP:
00500             // --- default, ESA SLCs ---
00501             // ______Get check with volumefile______
00502             char c8checkleadat[9];      // check vol met lea en dat
00503             readres(c8checkleadat,sizeof(c8checkleadat),
00504               input_general.m_resfile,"(Check)Number",5);
00505             writeslc(input_general,input_m_crop, atoi(c8checkleadat)-1);
00506             updatefile("scratchres2raw",input_general.m_resfile);       // update resfile
00507             break;
00508           case SARPR_ATL:
00509             // --- self processed from RAW ---
00510             radarsat_dump_data(input_general,input_m_crop);//
00511             updatefile("scratchres2raw",input_general.m_resfile);       // update resfile
00512             WARNING.print("ATLANTIS data cropping not fully checked yet.");
00513             break;
00514           case SARPR_TUD:
00515             //break;
00516           default: 
00517             PRINT_ERROR("unrecognized sar_processor.")
00518             throw(input_error);// exit
00519           }
00520         break;
00521       // ______ ENVISAT ASAR ______
00522       case SLC_ASAR:
00523         PROGRESS.print("System call to get ASAR SLC data (requires envisat_dump_data program)");
00524         // ______ Data window must be set correctly ______
00525         if (input_m_crop.dbow.linelo == 0 || input_m_crop.dbow.linehi == 0 ||
00526             input_m_crop.dbow.pixlo == 0  || input_m_crop.dbow.pixhi == 0)
00527           {
00528           input_m_crop.dbow = master.currentwindow;// needs to be set correctly after readfiles
00529           }
00530         envisat_dump_data(input_m_crop);
00531         PROGRESS.print("Finished system call to envisat_dump_data");
00532         updatefile("scratchres2raw",input_general.m_resfile);   // update resfile
00533         break;
00534       // ______ RADARSAT (detected by Product specifier) ______
00535       case SLC_RSAT:
00536         radarsat_dump_data(input_general,input_m_crop);//
00537         updatefile("scratchres2raw",input_general.m_resfile);   // update resfile
00538         WARNING.print("RSAT (Atlantis) not fully checked yet.");
00539         break;
00540       default:
00541         PRINT_ERROR("impossible error (sensor not ERS JERS RSAT nor ASAR).")
00542         throw(input_error);// exit
00543       }
00544     PROGRESS.print("Finished M_CROP.");
00545     DEBUG.print("Time spent for writing raw format master:");
00546     printcpu(); 
00547     }
00548 
00549 // ______ Update info on image ______
00550   if (alreadyprocessed[pr_m_crop])
00551     {
00552     INFO.print("master: latest known processing stage: crop");
00553     char   SECTIONID[ONE27];
00554     strcpy(SECTIONID,"*_Start_");
00555     strcat(SECTIONID,processcontrol[pr_m_crop]);
00556     master.updateslcimage(input_general.m_resfile,SECTIONID);
00557     }
00558 
00559 // ______ Generate magnitude preview of master SLC if requested ______
00560   if (input_general.process[pr_m_crop])
00561     {
00562     PROGRESS.print("calling preview for cropped master");
00563     if (master.sensor!=SLC_RSAT)
00564       preview(input_general.preview,
00565             master.currentwindow.pixels(), master.formatflag,
00566             master.file, "master_mag.ras", 
00567             "-e 0.5 -s 1.0 -q mag -o sunraster -b -c gray -M 2/10");
00568     else//multilooking depends on beam
00569       preview(input_general.preview,
00570             master.currentwindow.pixels(), master.formatflag,
00571             master.file, "master_mag.ras", 
00572             "-e 0.5 -s 1.0 -q mag -o sunraster -b -c gray -M 5/6");
00573     }
00574 
00575 
00576 
00577 //____ RaffaeleNutricato START MODIFICATION SECTION 5 ______
00578 // ====== OVERSAMPLE SLC: MASTER ======
00579 // For the moment only along the range direction
00580   if (input_general.process[pr_m_oversample])
00581     {
00582     PROGRESS.print("Start M_OVS.");
00583     alreadyprocessed[pr_m_oversample]=1;  // update alreadypr.
00584     if (input_general.interactive)
00585       {
00586       cerr << "\nProcessing oversample for master.";
00587       getanswer();
00588       }
00589     // ______Master and Slave oversampling ratioes should be identical______
00590     if (alreadyprocessed[pr_s_oversample])
00591       { 
00592       char checkmultilook [20];
00593       int32 checkOsrRange;
00594       readres(checkmultilook,sizeof(checkmultilook),
00595               input_general.s_resfile,"Multilookfactor_range_direction:");
00596       checkOsrRange = int32(1.0/atof(checkmultilook)+.5);
00597       if (input_m_oversample.OsrRange != checkOsrRange)
00598         WARNING.print("Master and Slave range oversampling factors should be identical!!!");
00599       }
00600     if (alreadyprocessed[pr_s_oversample])
00601       { 
00602       char checkmultilook[20];
00603       int32 checkOsrAzimuth;
00604       readres(checkmultilook,sizeof(checkmultilook),
00605               input_general.s_resfile,"Multilookfactor_azimuth_direction:");
00606       checkOsrAzimuth = int32(1.0/atof(checkmultilook)+.5);
00607       if (input_m_oversample.OsrAzimuth != checkOsrAzimuth)
00608         WARNING.print("Master and Slave azimuth oversampling factors should be identical!!!");
00609       }
00610 
00611     // ______Performs the master range oversampling______
00612     // I hope the same process can be done for all of the sensors!!! 
00613     OversampleSLC(input_general,master,input_m_oversample,MASTERID);
00614     updatefile("scratchoversample",input_general.m_resfile);    // update resfile
00615 
00616     PROGRESS.print("Finished M_OVS.");
00617     DEBUG.print("Time spent for oversampling master:");
00618     printcpu(); 
00619     }
00620 
00621   // ______ Update info on image ______
00622   if (alreadyprocessed[pr_m_oversample])
00623     {
00624     INFO.print("master: latest known processing stage: oversample");
00625     char   SECTIONID[ONE27];
00626     strcpy(SECTIONID,"*_Start_");
00627     strcat(SECTIONID,processcontrol[pr_m_oversample]);
00628     master.updateslcimageML(input_general.m_resfile,SECTIONID);
00629     interferogram.win = master.currentwindow;
00630     }
00631 
00632   // ______ Generate magnitude preview of master SLC if requested ______
00633   // -M 2/10 make no sense after oversampling!!
00634   if (input_general.process[pr_m_oversample])
00635     {
00636     PROGRESS.print("calling preview for oversampled master");
00637     preview(input_general.preview,
00638             master.currentwindow.pixels(), master.formatflag,
00639             master.file, "master_ovs_mag.ras", 
00640             "-e 0.5 -s 1.0 -q mag -o sunraster -b -c gray -M 2/2");
00641     }
00642 
00643 
00644 
00645 
00646 // *********************************************************
00647 // **** start slave                                     ****
00648 // *********************************************************
00649 
00650 // ====== PROCESS INFOFILE CDROM: SLAVE ======
00651   if (input_general.process[pr_s_readfiles])
00652     {
00653     PROGRESS.print("Start S_READFILES.");
00654     // ___ update alreadyprocessed for this step ___
00655     alreadyprocessed[pr_s_readfiles]=1;
00656     if (input_general.interactive)
00657       {
00658       cerr << "\nProcessing readfiles for slave.";
00659       getanswer();
00660       }
00661 
00662     // ______ Select method for SLAVE READFILES______
00663     switch (input_s_readfiles.sensor_id)
00664       {
00665       // ______ JERS also CEOS? (falls through to ers) ______
00666       case SLC_JERS:
00667         INFO.print("JERS: Under development: is JERS really CEOS like ERS?");
00668       // ______ RSAT also CEOS? (falls through to ERS, account in reader) ______
00669       case SLC_RSAT:
00670         WARNING.print("RSAT: Under development: CEOS reader seems to work.");
00671       // ______ ERS-1/2 ______
00672       case SLC_ERS:
00673         // ______ Get checks with master volumefile ______
00674         char c16checkvol1[17];
00675         char c16checkvol2[17];
00676         char c16checkvol3[17];  // check id of volume file
00677         if (alreadyprocessed[pr_m_readfiles])
00678           {
00679           readres(c16checkvol1,sizeof(c16checkvol1),
00680             input_general.m_resfile,"Volume_ID:");
00681           readres(c16checkvol2,sizeof(c16checkvol2),
00682             input_general.m_resfile,"Volume_identifier:");
00683           readres(c16checkvol3,sizeof(c16checkvol3),
00684             input_general.m_resfile,"Volume_set_identifier:");
00685           }
00686 
00687         // ______ Extract info ______
00688         readvolume(input_s_readfiles, c16checkvol1, c16checkvol2, c16checkvol3);
00689         // created in readvolume
00690         updatefile("scratchresvol",input_general.s_resfile);
00691         // created in readvolume
00692         updatefile("scratchlogvol",input_general.logfile);
00693 
00694         // ______ Get check with slave volumefile ______
00695         char c8checkleadat[9];  // check vol met lea en dat
00696         readres(c8checkleadat,sizeof(c8checkleadat),
00697           input_general.s_resfile,"(Check)Number",5);
00698 
00699         // ______ Extract info ______
00700         readleader(input_s_readfiles, atoi(c8checkleadat)-1);
00701         // made in readleader
00702         updatefile("scratchreslea",input_general.s_resfile);
00703         // made in readleader
00704         updatefile("scratchloglea",input_general.logfile);
00705 
00706         //  // DONT PROCESS NULLFILE
00707         //readnull(input_s_readfiles);
00708         //updatefile("scratchresnull",input_general.s_resfile);
00709         //updatefile("scratchlognull",input_general.logfile);
00710         // ___ read data file info ___
00711         readdat(input_s_readfiles, atoi(c8checkleadat)-1);
00712         // update resfile
00713         updatefile("scratchresdat",input_general.s_resfile);
00714         // update logfile
00715         updatefile("scratchlogdat",input_general.logfile);
00716         break; // (this break was missing in v3.4, thanks Raffaele Nutricato)
00717       // ______ ENVISAT ASAR ______
00718       case SLC_ASAR:
00719         //WARNING.print("Under development, requires envisat_dump_header");
00720         INFO.reset();// make sure nothing in buffer
00721         INFO << "envisat_dump_header2doris.csh "
00722              << input_s_readfiles.datfile
00723              << " > scratchres_envisat" << endl << ends;
00724         char cmd[512];// command string
00725         strcpy(cmd, INFO.get_str());
00726         INFO.print("With following command the envisat header was read.");
00727         INFO.print(cmd);
00728         PROGRESS.print("Making system call to envisat_dump_header2doris.csh");
00729         PROGRESS.print("(also requires envisat_dump_header program)");
00730         system(cmd);// this does the work
00731         INFO.reset();
00732         PROGRESS.print("Finished system call to envisat_dump_header2doris.csh");
00733         // update resfile
00734         updatefile("scratchres_envisat",input_general.s_resfile);
00735         // update logfile
00736         updatefile("envisat_dump_header.log",input_general.logfile);
00737         break;
00738       default:
00739         PRINT_ERROR("impossible error (sensor not ERS nor ASAR).")
00740         throw(input_error);// exit
00741       }
00742 
00743     PROGRESS.print("Finished S_READFILES.");
00744     DEBUG.print("Time spent for reading files slave:");
00745     printcpu(); 
00746     }
00747 
00748 // ______ Fill slcimage struct ______
00749   if (existed(input_general.s_resfile))
00750     slave.fillslcimage(input_general.s_resfile);
00751 
00752   // ______ Check sensor correspondent ______
00753   if (alreadyprocessed[pr_m_readfiles] && alreadyprocessed[pr_s_readfiles])
00754     if (master.sensor != slave.sensor)
00755       WARNING.print("master.sensor not same as slave.sensor (ERS-ERS, ASAR-ASAR only)");
00756 
00757 
00758   // ______ Account for timing errors ______
00759   DEBUG.print("Correction for slave image timing errors if specified");
00760   DEBUG << "rg_timing_error: " << input_s_readfiles.rg_timing_error;
00761   DEBUG.print();
00762   DEBUG << "az_timing_error: " << input_s_readfiles.az_timing_error;
00763   DEBUG.print();
00764   slave.add_rg_t_error(input_s_readfiles.rg_timing_error);
00765   slave.add_az_t_error(input_s_readfiles.az_timing_error);
00766 
00767 
00768 
00769 // BK 15-Dec-2003 (moved before crop since required if dbow_geo
00770 // ====== GET PRECISE ORBITS (GETORB): SLAVE ======
00771   if (input_general.process[pr_s_porbits])
00772     {
00773     PROGRESS.print("Start S_PORBITS.");
00774     alreadyprocessed[pr_s_porbits]=1;                           // update alreadypr.
00775     if (input_general.interactive)
00776       {
00777       cerr << "\nProcessing get precise orbits for slave.";
00778       getanswer();
00779       }
00780     // ______getorb does the real work______
00781     //getorb(slave,input_porbits.s_orbdir);
00782     getorb(slave,input_porbits,SLAVEID);
00783     convertgetorbout(SLAVEID);
00784     updatefile("scratchdatapoints",input_general.s_resfile);    // result of conv.getorb slave
00785     removedatleader(input_general.s_resfile);                   // remove data section by leader
00786     PROGRESS.print("Finished S_PORBITS.");
00787     DEBUG.print("Time spent for obtaining precise orbits slave:");
00788     printcpu(); 
00789     }
00790   // ______ Get coefficients for orbit interpolation if data in file ______
00791   //   (alreadyprocessed[pr_s_readfiles] && isspace(input_porbits.s_orbdir[0])))
00792   if (alreadyprocessed[pr_s_porbits]   ||
00793       alreadyprocessed[pr_s_readfiles])
00794     slaveorbit.initialize(input_general.s_resfile);
00795 
00796   // ______ Dump interpolated orbit if requested ______
00797   //if (alreadyprocessed[pr_s_porbits])
00798   // ___ compbaseline return if no orbit available ___
00799   // ______ also possible to dump orbit of readfiles with card M_ORB_DUMP ___
00800   slaveorbit.dumporbit(input_porbits,SLAVEID);
00801 
00802 
00803   // --- initialize BASELINE class if orbits available ---
00804   // Bert Kampes, 04-Apr-2005
00805   BASELINE baseline;
00806   baseline.model_parameters(master,slave,masterorbit,slaveorbit,input_ellips);
00807 
00808 
00809   // ______ Stdout baseline parametrizations as INFO ______
00810   //if (alreadyprocessed[pr_m_porbits] && alreadyprocessed[pr_s_porbits])
00811   // ___ compbaseline return if no orbit available ___
00812   //compbaseline(input_general, master, slave, masterorbit, slaveorbit);
00813   for (register int32 i=0; i<input_general.dumpbaselineL; ++i) // azimuthlines
00814     {
00815     const real8 line = (input_general.dumpbaselineL==1) ?
00816       master.currentwindow.linelo +   master.currentwindow.lines()/2.0 :
00817       master.currentwindow.linelo + i*master.currentwindow.lines()/
00818         (input_general.dumpbaselineL-1.0);
00819     for (register int32 j=0; j<input_general.dumpbaselineP; ++j) // rangepixels
00820       {
00821       const real8 pixel = (input_general.dumpbaselineP==1) ?
00822         master.currentwindow.pixlo +   master.currentwindow.pixels()/2.0 :
00823         master.currentwindow.pixlo + j*master.currentwindow.pixels()/
00824           (input_general.dumpbaselineP-1.0);
00825       for (register int32 height=0; height<1001; height=height+1000)// height
00826         baseline.dump(line,pixel,height);// eval parameters on grid
00827       }
00828     }
00829 
00830 
00831   // ====== Get tiepoint coordinates etc., this returns if nothing to do ======
00832   PROGRESS.print("Computating integration constant based on tiepoint");
00833   tiepoint(input_general, master, slave, masterorbit, slaveorbit, input_ellips);
00834 
00835 
00836 
00837 // ====== PROCESS DATAFILE CDROM: SLAVE ======
00838   if (input_general.process[pr_s_crop])
00839     {
00840     PROGRESS.print("Start S_CROP.");
00841     // ___ update alreadypr. ___
00842     alreadyprocessed[pr_s_crop]=1;
00843     if (input_general.interactive)
00844       {
00845       cerr << "\nProcessing crop for slave.";
00846       getanswer();
00847       }
00848 
00849     // ______ Assume orbits loaded, use GEO card if present ______
00850     if (input_s_crop.dbow_geo.pixhi != 0)
00851       {
00852       PROGRESS.print("Computing crop based on center lat/lon/height/width.");
00853       real8 centerline, centerpix;
00854       real8 centerphi    = deg2rad(input_s_crop.dbow_geo.linelo/1e6-360.0);
00855       real8 centerlambda = deg2rad(input_s_crop.dbow_geo.linehi/1e6-360.0);
00856       real8 centerheight = input_general.terrain_height;
00857       DEBUG.print("Using height of HEIGHT card");
00858       DEBUG << "CROP: center lat/lon/hei: " 
00859             << centerphi << " " << centerlambda << " " << centerheight;
00860       DEBUG.print();
00861       cn centerpos;// compute phi/lambda/h-->x,y,z
00862       ell2xyz(input_ellips,centerpos,centerphi,centerlambda,centerheight);
00863       DEBUG << "convert S_DBOW_GEO phi,lambda --> x,y,z: "
00864             << centerphi << ", " << centerlambda << ", " << " --> "
00865             << centerpos.x << " " << centerpos.y << " " << centerpos.z;
00866       DEBUG.print();
00867       DEBUG << "Center slave SLC: x,y,z: "
00868             << slave.approxcentreoriginal.x << " " 
00869             << slave.approxcentreoriginal.y << " "
00870             << slave.approxcentreoriginal.z;
00871       DEBUG.print();
00872       if (abs(slave.approxcentreoriginal.x-centerpos.x)>50000.0)// 50km
00873         WARNING.print("S_DBOW_GEO: coordinates seem to be outside SLC area? (X)");
00874       if (abs(slave.approxcentreoriginal.y-centerpos.y)>50000.0)// 50km
00875         WARNING.print("S_DBOW_GEO: coordinates seem to be outside SLC area? (Y)");
00876       if (abs(slave.approxcentreoriginal.z-centerpos.z)>50000.0)// 50km
00877         WARNING.print("S_DBOW_GEO: coordinates seem to be outside SLC area? (Z)");
00878       int32 n_iter = xyz2lp(centerline, centerpix,
00879         slave, slaveorbit, centerpos,
00880         10, 1e-3);// MAXITERATIONS, CONVERGENCE_TIME
00881       //old way: not possible to check x,y,z, indiviually
00882       //int32 n_iter = ell2lp(centerline, centerpix, input_ellips, 
00883       //  slave, slaveorbit, centerphi, centerlambda, 0.0);// height
00884       DEBUG << "CROP: center line/pix: " << centerline << " " << centerpix;
00885       DEBUG.print();
00886       int32 l0 = int32(centerline+0.5) - input_s_crop.dbow_geo.pixlo/2;
00887       int32 lN = l0 + input_s_crop.dbow_geo.pixlo - 1;
00888       int32 p0 = int32(centerpix+0.5)  - input_s_crop.dbow_geo.pixhi/2;
00889       int32 pN = p0 + input_s_crop.dbow_geo.pixhi - 1;
00890       if (l0 < int32(slave.currentwindow.linelo)) l0 = slave.currentwindow.linelo;
00891       if (lN > int32(slave.currentwindow.linehi)) lN = slave.currentwindow.linehi;
00892       if (p0 < int32(slave.currentwindow.pixlo))  p0 = slave.currentwindow.pixlo;
00893       if (pN > int32(slave.currentwindow.pixhi))  pN = slave.currentwindow.pixhi;
00894       INFO << "DBOW from GEO: " << l0 << " " << lN << " " << p0 << " " << pN;
00895       INFO.print();
00896       // ___ Simply fill dbow with it and it will be done correctly! ___
00897       input_s_crop.dbow.linelo = uint(l0);
00898       input_s_crop.dbow.linehi = uint(lN);
00899       input_s_crop.dbow.pixlo  = uint(p0);
00900       input_s_crop.dbow.pixhi  = uint(pN);
00901       }
00902 
00903     // ______ For each sensor, of course the formats differ... ______
00904     switch (slave.sensor)
00905       {
00906       // ______ JERS also CEOS? (falls through to ers) ______
00907       case SLC_JERS:
00908         WARNING.print("JERS: Under development: is JERS really CEOS like ERS?");
00909       // ______ ERS-1/2 ______
00910       case SLC_ERS:
00911         switch (slave.sar_processor)
00912           {
00913           case SARPR_VMP:
00914             // --- default, ESA SLCs ---
00915             // ______ Get check with volumefile ______
00916             char c8checkleadat[9];      // check vol met lea en dat
00917             readres(c8checkleadat,sizeof(c8checkleadat),
00918               input_general.s_resfile,"(Check)Number",5);
00919             writeslc(input_general,input_s_crop, atoi(c8checkleadat)-1);
00920             updatefile("scratchres2raw",input_general.s_resfile);       // update resfile
00921             break;
00922           case SARPR_ATL:
00923             // --- self processed from RAW using Atlantis ---
00924             radarsat_dump_data(input_general,input_s_crop);//
00925             updatefile("scratchres2raw",input_general.s_resfile);       // update resfile
00926             WARNING.print("ATLANTIS data cropping not fully checked yet.");
00927             break;
00928           case SARPR_TUD:
00929             //break;
00930           default: 
00931             PRINT_ERROR("unrecognized sar_processor.")
00932             throw(input_error);// exit
00933           }
00934         break;
00935       // ______ ENVISAT ASAR ______
00936       case SLC_ASAR:
00937         PROGRESS.print("System call to get ASAR SLC data (requires envisat_dump_data program)");
00938         // ______ Data window must be set correctly ______
00939         if (input_s_crop.dbow.linelo == 0 || input_s_crop.dbow.linehi == 0 ||
00940             input_s_crop.dbow.pixlo == 0  || input_s_crop.dbow.pixhi == 0)
00941           input_s_crop.dbow = slave.currentwindow;
00942         envisat_dump_data(input_s_crop);
00943         PROGRESS.print("Finished system call to envisat_dump_data");
00944         updatefile("scratchres2raw",input_general.s_resfile);   // update resfile
00945         break;
00946       // ______ RADARSAT ______
00947       case SLC_RSAT:
00948         radarsat_dump_data(input_general,input_s_crop);//
00949         updatefile("scratchres2raw",input_general.s_resfile);   // update resfile
00950         WARNING.print("RSAT (Atlantis) not fully checked yet.");
00951         break;
00952       default:
00953         PRINT_ERROR("impossible error (sensor not (J)ERS or ASAR).")
00954         throw(input_error);// exit
00955       }
00956     PROGRESS.print("Finished S_CROP.");
00957     DEBUG.print("Time spent for writing raw format slave:");
00958     printcpu(); 
00959     }
00960 
00961   // ______ Update info on image ______
00962   if (alreadyprocessed[pr_s_crop])
00963     {
00964     INFO.print("slave: latest known processing stage: crop");
00965     char   SECTIONID[ONE27];
00966     strcpy(SECTIONID,"*_Start_");
00967     strcat(SECTIONID,processcontrol[pr_s_crop]);
00968     //updateslcimage(slave,input_general.s_resfile,SECTIONID);
00969     slave.updateslcimage(input_general.s_resfile,SECTIONID);
00970     }
00971 
00972   // ______ Check wavelength ______
00973   if (alreadyprocessed[pr_m_crop] && alreadyprocessed[pr_s_crop])
00974     {
00975     if (abs(master.wavelength-slave.wavelength) > EPS)
00976       WARNING.print("wavelength master not equal to wavelength slave.");
00977     }
00978 
00979 
00980   // ______ Generate magnitude preview if requested ______
00981   if (input_general.process[pr_s_crop])
00982     {
00983     PROGRESS.print("calling preview for cropped slave");
00984     if (master.sensor!=SLC_RSAT)
00985       preview(input_general.preview,
00986               slave.currentwindow.pixels(), slave.formatflag,
00987               slave.file, "slave_mag.ras", 
00988               "-e 0.5 -s 1.0 -q mag -o sunraster -b -c gray -M 2/10");
00989     else// multilooking depends on beam
00990       preview(input_general.preview,
00991               slave.currentwindow.pixels(), slave.formatflag,
00992               slave.file, "slave_mag.ras", 
00993               "-e 0.5 -s 1.0 -q mag -o sunraster -b -c gray -M 5/6");
00994     }
00995 
00996 
00997 
00998 //____RaffaeleNutricato START MODIFICATION SECTION 6
00999 // ====== OVERSAMPLE SLC: SLAVE ======
01000 // For the moment only along the range direction
01001   if (input_general.process[pr_s_oversample])
01002     {
01003     PROGRESS.print("Start S_OVS.");
01004     alreadyprocessed[pr_s_oversample]=1;  // update alreadypr.
01005     if (input_general.interactive)
01006       {
01007       cerr << "\nProcessing oversample for slave.";
01008       getanswer();
01009       }
01010     // ______Master and Slave oversampling ratioes should be identical______
01011     if (alreadyprocessed[pr_m_oversample])
01012       { 
01013       char checkmultilook[20];
01014       int32 checkOsrRange;
01015       readres(checkmultilook,sizeof(checkmultilook),
01016               input_general.m_resfile,"Multilookfactor_range_direction:");
01017       checkOsrRange = int32(1.0/atof(checkmultilook)+.5);
01018       if (input_s_oversample.OsrRange != checkOsrRange)
01019         WARNING.print("Master and Slave range oversampling factors should be identical!!!");
01020       }
01021     if (alreadyprocessed[pr_m_oversample])
01022       { 
01023       char checkmultilook[20];
01024       int32 checkOsrAzimuth;
01025       readres(checkmultilook,sizeof(checkmultilook),
01026               input_general.m_resfile,"Multilookfactor_azimuth_direction:");
01027       checkOsrAzimuth = int32(1.0/atof(checkmultilook)+.5);
01028       if (input_s_oversample.OsrAzimuth != checkOsrAzimuth)
01029         WARNING.print("Master and Slave azimuth oversampling factors should be identical!!!");
01030       }
01031 
01032 
01033     // ______Performs the slave range oversampling______
01034     // I hope the same process can be done for all of the sensors!!! 
01035     OversampleSLC(input_general,slave,input_s_oversample,SLAVEID);
01036     updatefile("scratchoversample",input_general.s_resfile);    // update resfile
01037 
01038     PROGRESS.print("Finished S_OVS.");
01039     DEBUG.print("Time spent for oversampling slave:");
01040     printcpu(); 
01041     }
01042 
01043   // ______ Update info on image ______
01044   if (alreadyprocessed[pr_s_oversample])
01045     {
01046     INFO.print("slave: latest known processing stage: oversample");
01047     char   SECTIONID[ONE27];
01048     strcpy(SECTIONID,"*_Start_");
01049     strcat(SECTIONID,processcontrol[pr_s_oversample]);
01050     slave.updateslcimageML(input_general.s_resfile,SECTIONID);
01051     }
01052 
01053   // ______ Generate magnitude preview of slave SLC if requested ______
01054   // -M 2/10 make no sense after oversampling!!
01055   if (input_general.process[pr_s_oversample])
01056     {
01057     PROGRESS.print("calling preview for oversampled slave");
01058     preview(input_general.preview,
01059             slave.currentwindow.pixels(), slave.formatflag,
01060             slave.file, "slave_ovs_mag.ras", 
01061             "-e 0.5 -s 1.0 -q mag -o sunraster -b -c gray -M 2/2");
01062     }
01063 //____RaffaeleNutricato END MODIFICATION SECTION 6
01064 
01065 
01066 
01067 
01068 // *********************************************************
01069 // **** start interferogram                             ****
01070 // *********************************************************
01071 
01072 // ====== COARSE CO-REGISTRATION BASED ON ORBITS ======
01073   if (input_general.process[pr_i_coarse])
01074     {
01075     PROGRESS.print("Start COARSE_ORB.");
01076     alreadyprocessed[pr_i_coarse]=1;                            // update alreadypr.
01077     if (input_general.interactive)
01078       {
01079       cerr << "\nProcessing coarse co-registration based on orbits.";
01080       getanswer();
01081       }
01082     coarseporbit(input_ellips, master, slave, masterorbit, slaveorbit, baseline);
01083 
01084     // ______ Update log files ______
01085     updatefile("scratchlogcoarse",input_general.logfile);       // 
01086     updatefile("scratchrescoarse",input_general.i_resfile);     // 
01087     PROGRESS.print("Finished COARSE_ORB.");
01088     DEBUG.print("Time spent for coarse coregistration with orbits:");
01089     printcpu(); 
01090     }
01091 
01092 // ______ Read estimates to interferogram info struct ______
01093   if (alreadyprocessed[pr_i_coarse])
01094     {
01095     INFO.print("latest known processing stage: coarse (orbits)");
01096     char c6initoffL[7]; // initial offset lines 
01097     char c6initoffP[7]; // initial offset pixels 
01098     readres(c6initoffL,sizeof(c6initoffL),input_general.i_resfile,
01099             "Coarse_orbits_translation_lines:", 0);
01100     readres(c6initoffP,sizeof(c6initoffP),input_general.i_resfile,
01101             "Coarse_orbits_translation_pixels:", 0);
01102     slave.coarseoffsetL  = atoi(c6initoffL);            // used as initial value
01103     slave.coarseoffsetP  = atoi(c6initoffP);            // used as initial value
01104     master.coarseoffsetL = -slave.coarseoffsetL;        // (never used)
01105     master.coarseoffsetP = -slave.coarseoffsetP;        // azifilt
01106 
01107     // ______ Corners of current slave in master coordinate system ______
01108     const int32 sL0 = slave.currentwindow.linelo - slave.coarseoffsetL;
01109     const int32 sLN = slave.currentwindow.linehi - slave.coarseoffsetL;
01110     const int32 sP0 = slave.currentwindow.pixlo  - slave.coarseoffsetP;
01111     const int32 sPN = slave.currentwindow.pixhi  - slave.coarseoffsetP;
01112     interferogram.win.linelo = max(sL0,int32(master.currentwindow.linelo));
01113     interferogram.win.linehi = min(sLN,int32(master.currentwindow.linehi));
01114     interferogram.win.pixlo  = max(sP0,int32(master.currentwindow.pixlo));
01115     interferogram.win.pixhi  = min(sPN,int32(master.currentwindow.pixhi));
01116     }
01117 
01118 
01119 
01120 // ====== COARSE CO-REGISTRATION BASED ON CORRELATION ======
01121   if (input_general.process[pr_i_coarse2])
01122     {
01123     PROGRESS.print("Start COARSE_CORR.");
01124     alreadyprocessed[pr_i_coarse2]=1;                           // update alreadypr.
01125     if (input_general.interactive)
01126       {
01127       cerr << "\nProcessing coarse co-registration with correlation.";
01128       getanswer();
01129       }
01130 
01131     // ______ If requested: use estimated offsets from orbits as initial ______
01132     if (input_i_coarsecorr.initoffsetL == NaN && 
01133         input_i_coarsecorr.initoffsetL == NaN)  // flag for using answer of coarse1
01134       {
01135       input_i_coarsecorr.initoffsetL = slave.coarseoffsetL;
01136       input_i_coarsecorr.initoffsetP = slave.coarseoffsetP;
01137       }
01138 
01139     // ______Select method______
01140     switch (input_i_coarsecorr.method)
01141       {
01142       case cc_magfft:
01143         coarsecorrelfft(input_i_coarsecorr, master, slave);     // infoimage
01144         break;
01145       case cc_magspace:
01146         coarsecorrel(input_i_coarsecorr, master, slave);                // infoimage
01147         break;
01148       default:
01149         PRINT_ERROR("impossible error for checked input.")
01150         throw(input_error);// exit
01151       }
01152 
01153     // ______ Update log files ______
01154     updatefile("scratchlogcoarse2",input_general.logfile);      // 
01155     updatefile("scratchrescoarse2",input_general.i_resfile);    // 
01156     PROGRESS.print("Finished COARSE_CORR.");
01157     DEBUG.print("Time spent for coarse coregistration with correlation:");
01158     printcpu(); 
01159     }
01160 
01161 // ______ Read estimates to interferogram info struct ______
01162   if (alreadyprocessed[pr_i_coarse2])
01163     {
01164     INFO.print("latest known processing stage: coarse (corr)");
01165     char c6initoffL[7]; // initial offset lines 
01166     char c6initoffP[7]; // initial offset pixels 
01167     readres(c6initoffL,sizeof(c6initoffL),input_general.i_resfile,
01168             "Coarse_correlation_translation_lines:", 0);
01169     readres(c6initoffP,sizeof(c6initoffP),input_general.i_resfile,
01170             "Coarse_correlation_translation_pixels:", 0);
01171     slave.coarseoffsetL  = atoi(c6initoffL);            // used as initial value
01172     slave.coarseoffsetP  = atoi(c6initoffP);            // used as initial value
01173     master.coarseoffsetL = -slave.coarseoffsetL;        // (never used)
01174     master.coarseoffsetP = -slave.coarseoffsetP;        // azifilt
01175 
01176     // ______ corners of current slave in master coordinate system ______
01177     const int32 sL0 = slave.currentwindow.linelo - slave.coarseoffsetL;
01178     const int32 sLN = slave.currentwindow.linehi - slave.coarseoffsetL;
01179     const int32 sP0 = slave.currentwindow.pixlo  - slave.coarseoffsetP;
01180     const int32 sPN = slave.currentwindow.pixhi  - slave.coarseoffsetP;
01181 
01182     // fill these as well to be sure ? (BK)
01183     interferogram.win.linelo = max(sL0,int32(master.currentwindow.linelo));
01184     interferogram.win.linehi = min(sLN,int32(master.currentwindow.linehi));
01185     interferogram.win.pixlo  = max(sP0,int32(master.currentwindow.pixlo));
01186     interferogram.win.pixhi  = min(sPN,int32(master.currentwindow.pixhi));
01187     }
01188 
01189 
01190 
01191 // ====== FILTER AZIMUTH: MASTER (and SLAVE directly after) ======
01192 // ______ Do this step here, use coarse corr for fDC polynomial ______
01193   if (input_general.process[pr_m_filtazi])
01194     {
01195     PROGRESS.print("Start FILTAZI (master).");
01196     alreadyprocessed[pr_m_filtazi]=1;                           // update alreadypr.
01197     if (input_general.interactive)
01198       {
01199       cerr << "\nProcessing filtering azimuth direction for master.";
01200       getanswer();
01201       }
01202     // only master ...
01203     // output file name of master
01204     strcpy(input_ms_filtazi.foname,input_ms_filtazi.fomaster);
01205     azimuthfilter(input_general,input_ms_filtazi,master,slave);
01206     updatefile("scratchresfiltazi",input_general.m_resfile);    // update resfile
01207     updatefile("scratchlogfiltazi",input_general.logfile);      // update logfile
01208     PROGRESS.print("Finished FILTAZI for master.");
01209     DEBUG.print("Time spent for azimuth filtering master:");
01210     printcpu(); 
01211     }
01212 // ______ Update info of master, current filename, format, etc. ______
01213   if (alreadyprocessed[pr_m_filtazi])
01214     {
01215     INFO.print("master: latest known processing stage: azimuth filtered");
01216     char   SECTIONID[ONE27];
01217     strcpy(SECTIONID,"*_Start_");
01218     strcat(SECTIONID,processcontrol[pr_m_filtazi]);
01219     master.updateslcimage(input_general.m_resfile,SECTIONID);
01220     }
01221 
01222 
01223 // ====== FILTER AZIMUTH: SLAVE ======
01224   if (input_general.process[pr_s_filtazi])
01225     {
01226     PROGRESS.print("Start FILTAZI (slave).");
01227     alreadyprocessed[pr_s_filtazi]=1;                           // update alreadypr.
01228     if (input_general.interactive)
01229       {
01230       cerr << "\nProcessing filtering azimuth direction for slave.";
01231       getanswer();
01232       }
01233     // only slave ...
01234     strcpy(input_ms_filtazi.foname,input_ms_filtazi.foslave);
01235     azimuthfilter(input_general,input_ms_filtazi,slave,master);
01236     updatefile("scratchresfiltazi",input_general.s_resfile);    // update resfile
01237     updatefile("scratchlogfiltazi",input_general.logfile);      // update logfile
01238     PROGRESS.print("Finished FILTAZI slave.");
01239     DEBUG.print("Time spent for azimuth filtering slave:");
01240     printcpu(); 
01241     }
01242 
01243 // ______ Update info of slave, filename current image, format, etc. ______
01244   if (alreadyprocessed[pr_s_filtazi])
01245     {
01246     INFO.print("slave: latest known processing stage: azimuth filtered");
01247     char   SECTIONID[ONE27];
01248     strcpy(SECTIONID,"*_Start_");
01249     strcat(SECTIONID,processcontrol[pr_s_filtazi]);
01250     slave.updateslcimage(input_general.s_resfile,SECTIONID);
01251     }
01252 
01253 
01254 
01255 // ====== FILTER RANGE: MASTER&SLAVE porbits ======
01256 // ______ Only one step for master and slave, after coarse coreg. ______
01257 // ______ Method based on orbits only. (For adaptive method see after resampling) ______
01258 // ______ Update of struct should only occur for method porbits, ______
01259 // ______ so first find that out (BK 26-mar-01) ______
01260   if (input_general.process[pr_m_filtrange] &&
01261       input_ms_filtrange.method==rf_porbits)
01262     {
01263     PROGRESS.print("Start FILTRANGE (porbits).");
01264     alreadyprocessed[pr_m_filtrange]=1;         // update alreadypr.
01265     alreadyprocessed[pr_s_filtrange]=1;         // update alreadypr.
01266     if (input_general.interactive)
01267       {
01268       cerr << "\nRange filtering based on orbits master and slave.";
01269       getanswer();
01270       }
01271 
01272     // ______ Filter routine ______
01273     rangefiltporbits(input_general,input_ms_filtrange,input_ellips,
01274                      master,slave,masterorbit,slaveorbit);
01275 
01276     // ______ Update log files ______
01277     updatefile("scratchlogfiltrange",input_general.logfile);
01278     updatefile("scratchresMfiltrange",input_general.m_resfile);
01279     updatefile("scratchresSfiltrange",input_general.s_resfile);
01280 
01281     PROGRESS.print("Finished FILTRANGE.");
01282     DEBUG.print("Time spent for range filtering:");
01283     printcpu(); 
01284     }
01285  
01286 // ______ Update info of master, size interferogram ______
01287 // ______ Only update if method is porbits ______
01288   if (alreadyprocessed[pr_m_filtrange])
01289     {
01290     char c10rfmethod[11];       // method
01291     readres(c10rfmethod,sizeof(c10rfmethod),input_general.m_resfile,
01292             "Method_rangefilt:", 0);
01293     if (!strcmp(c10rfmethod,"porbits"))
01294       {
01295       INFO.print("master: latest known processing stage: filtrange (orbits)");
01296       char   SECTIONID[ONE27];
01297       strcpy(SECTIONID,"*_Start_");
01298       strcat(SECTIONID,processcontrol[pr_m_filtrange]);
01299       master.updateslcimage(input_general.m_resfile,SECTIONID);
01300       // ______ cut out overlay master slave exact ______
01301       interferogram.win = master.currentwindow;
01302       }
01303     }
01304 
01305 // ______ Update info of slave, size interferogram ______
01306   if (alreadyprocessed[pr_s_filtrange])         // same time as _m_
01307     {
01308     char c10rfmethod[11];       // method
01309     readres(c10rfmethod,sizeof(c10rfmethod),input_general.s_resfile,
01310             "Method_rangefilt:", 0);
01311     if (!strcmp(c10rfmethod,"porbits"))
01312       {
01313       INFO.print("slave: latest known processing stage: filtrange (orbits)");
01314       char   SECTIONID[ONE27];
01315       strcpy(SECTIONID,"*_Start_");
01316       strcat(SECTIONID,processcontrol[pr_s_filtrange]);
01317       slave.updateslcimage(input_general.s_resfile,SECTIONID);
01318       }
01319     }
01320 
01321 
01322 
01323 
01324 // ====== FINE CO-REGISTRATION ======
01325   if (input_general.process[pr_i_fine])
01326     {
01327     PROGRESS.print("Start FINE.");
01328     alreadyprocessed[pr_i_fine]=1;                              // update alreadypr.
01329     if (input_general.interactive)
01330       {
01331       cerr << "\nProcessing fine co-registration.";
01332       getanswer();
01333       }
01334 
01335     // ______ If requested: Read result coarse from file ______
01336     if (input_i_fine.initoffsetL == NaN &&              // flag for using
01337         input_i_fine.initoffsetL == NaN)                //  asnwer of coarse2
01338       {
01339       input_i_fine.initoffsetL = slave.coarseoffsetL;
01340       input_i_fine.initoffsetP = slave.coarseoffsetP;
01341       }
01342 
01343     // ______ Select method ______
01344     if (input_i_fine.method == fc_magfft  ||
01345         input_i_fine.method == fc_magspace  )
01346       finecoreg(input_i_fine, master, slave);      // selects other methods within
01347     else if (input_i_fine.method == fc_oversample) // still 2b implemented in place
01348       //finecoreg2(input_i_fine, master, slave)
01349       ;
01350     else
01351       {
01352       PRINT_ERROR("Method FC not implemented.")
01353       throw(input_error);// exit
01354       }
01355 
01356     // ______ Update log files ______
01357     updatefile("scratchlogfine",input_general.logfile);
01358     updatefile("scratchresfine",input_general.i_resfile);
01359     PROGRESS.print("Finished FINE.");
01360     DEBUG.print("Time spent for fine coregistration:");
01361     printcpu(); 
01362 
01363     // ______ Plot if requested, use gmt script: plotoffsets ______
01364     INFO.reset();// make sure nothing in buffer
01365     INFO << "plotoffsets " << input_general.i_resfile << " "
01366          << master.currentwindow.linelo  << " " 
01367          << master.currentwindow.linehi  << " "
01368          << master.currentwindow.pixlo   << " "
01369          << master.currentwindow.pixhi   << " "
01370          << input_i_fine.plotthreshold   << " ";
01371     // ______ optional 7th argument for background ______
01372     if (input_i_fine.plotmagbg) INFO << master.file;
01373     INFO << "&" << endl << ends;
01374     char cmd[512];// command string
01375     strcpy(cmd, INFO.get_str());
01376     INFO.print("With following command the estimated offset vectors can be plotted.");
01377     INFO.print(cmd);
01378     // ______ Actual make the call if requested ______
01379     if (input_i_fine.plotoffsets) system(cmd);
01380     }
01381 
01382 // _______ Fill oversampling factor for coregpm routine ______
01383   uint osfactor = 8;                                    // oversamplingsfactor
01384   if (alreadyprocessed[pr_i_fine])
01385     {
01386     INFO.print("latest known processing stage: fine");
01387     char c4osfactor[4];
01388     readres(c4osfactor,sizeof(c4osfactor),input_general.i_resfile,
01389                 "Oversampling", 1);
01390     osfactor = uint(atoi(c4osfactor));
01391     }
01392 
01393 
01394 
01395 // ====== COMPUTATION CO-REGISTRATION PARAMETERS ======
01396   if (input_general.process[pr_i_coregpm])
01397     {
01398     PROGRESS.print("Start COREGPM.");
01399     alreadyprocessed[pr_i_coregpm]=1;                           // update alreadypr.
01400     if (input_general.interactive)
01401       {
01402       cerr << "\nProcessing computation of co-registration parameters.";
01403       getanswer();
01404       }
01405 
01406     coregpm(master.originalwindow, 
01407             input_general.i_resfile, input_i_coregpm, osfactor);
01408 
01409     // ______ Update log files ______
01410     updatefile("scratchlogcpm",input_general.logfile);
01411     updatefile("scratchrescpm",input_general.i_resfile);
01412 
01413     PROGRESS.print("Finished COREGPM.");
01414     DEBUG.print("Time spent for computation of coregistration parameters:");
01415     printcpu(); 
01416 
01417     // ______ Plot if requested, use gmt script: plotcpm ______
01418     INFO.reset();// make sure nothing in buffer
01419     INFO << "plotcpm CPM_Data "
01420          << master.currentwindow.linelo  << " "
01421          << master.currentwindow.linehi  << " "
01422          << master.currentwindow.pixlo   << " "
01423          << master.currentwindow.pixhi   << " ";
01424     // ______ optional 6th argument for background ______
01425     if (input_i_coregpm.plotmagbg) INFO << master.file;
01426     // not ok? BK 27-Jun-00: omem << "&" << ends;
01427     INFO << "&" << endl << ends;
01428     char cmd[512];// command string
01429     strcpy(cmd, INFO.get_str());
01430     INFO.print("Next command will plot solution:");
01431     INFO.print(cmd);
01432     // ______ Actual make the call if requested ______
01433     if (input_i_coregpm.plot) system(cmd);
01434     }
01435 
01436   // ______ Fill matrix coefficients, interferogram info struct ______
01437   // ______ Approximate overlap in master system in interf. window ______
01438   if (alreadyprocessed[pr_i_coregpm])
01439     {
01440     INFO.print("latest known processing stage: coregpm");
01441     char c10offL[11];
01442     readres(c10offL,sizeof(c10offL),input_general.i_resfile,"Degree_cpm:");
01443     int32 degreecpm = atoi(c10offL);
01444     coeff_cpmL = readcoeff(input_general.i_resfile,
01445                  "Estimated_coefficientsL:",Ncoeffs(degreecpm));
01446     coeff_cpmP = readcoeff(input_general.i_resfile,
01447                  "Estimated_coefficientsP:",Ncoeffs(degreecpm));
01448     // bk 1 sep 2000, req. for resample...
01449     //interferogram.win = getoverlap(master,slave,coeff_cpmL,coeff_cpmP);
01450     }
01451 
01452 
01453 
01454 // ====== RESAMPLING OF SLAVE IMAGE ======
01455   if (input_general.process[pr_s_resample])
01456     {
01457     PROGRESS.print("Start RESAMPLE.");
01458     alreadyprocessed[pr_s_resample]=1;                          // update alreadypr.
01459     if (input_general.interactive)
01460       {
01461       cerr << "\nProcessing resampling of slave image. (might take some time.)";
01462       getanswer();
01463       }
01464     // ______ (interf.win contains approx. offset) ______
01465     resample(input_general,input_s_resample,
01466              master,slave,coeff_cpmL,coeff_cpmP);
01467 
01468     // ______ Update log files ______
01469     updatefile("scratchlogresample",input_general.logfile);
01470     updatefile("scratchresresample",input_general.s_resfile);
01471 
01472     PROGRESS.print("Finished RESAMPLE.");
01473     DEBUG.print("Time spent for resampling of slave image:");
01474     printcpu(); 
01475     }
01476 
01477   // ______ Update info of slave, size interferogram ______
01478   if (alreadyprocessed[pr_s_resample])
01479     {
01480     INFO.print("slave: latest known processing stage: resample");
01481     char   SECTIONID[ONE27];
01482     strcpy(SECTIONID,"*_Start_");
01483     strcat(SECTIONID,processcontrol[pr_s_resample]);
01484     slave.updateslcimage(input_general.s_resfile,SECTIONID);
01485     // (this is in master coord. system, as it should be) (BK 26-1-00)
01486     // in some routines this might be used, should be changed
01487     // wins are in same system
01488     interferogram.win = 
01489       getoverlap(master.currentwindow,slave.currentwindow);
01490     }
01491   // ___ generate a preview of amplitude if requested ______
01492   if (input_general.process[pr_s_resample])
01493     {
01494     PROGRESS.print("calling preview for resampled slave");
01495     if (master.sensor!=SLC_RSAT)
01496       preview(input_general.preview,
01497               slave.currentwindow.pixels(), slave.formatflag,
01498               slave.file, "slave_rs_mag.ras", 
01499               "-e 0.5 -s 1.0 -q mag -o sunraster -b -c gray -M 2/10");
01500     else//multilooking depends on beam
01501       preview(input_general.preview,
01502               slave.currentwindow.pixels(), slave.formatflag,
01503               slave.file, "slave_rs_mag.ras", 
01504               "-e 0.5 -s 1.0 -q mag -o sunraster -b -c gray -M 5/6");
01505     }
01506 
01507 
01508 
01509 
01510 // ====== FILTER RANGE: MASTER&SLAVE adaptive ======
01511 // ______ Only one step for master and slave, after resampling. ______
01512 // ______ Method adaptive only, for method based on orbits see after coarse. ______
01513   if (input_general.process[pr_m_filtrange] &&
01514       input_ms_filtrange.method==rf_adaptive)
01515     {
01516     PROGRESS.print("Start FILTRANGE (adaptive).");
01517     alreadyprocessed[pr_m_filtrange]=1;         // update alreadypr.
01518     alreadyprocessed[pr_s_filtrange]=1;         // update alreadypr.
01519     if (input_general.interactive)
01520       {
01521       cerr << "\nAdaptive range filtering master and slave.";
01522       getanswer();
01523       }
01524 
01525     // ______ Filter routine ______
01526     rangefilter(input_general,master,slave,interferogram,input_ms_filtrange);
01527 
01528     // ______ Update log files ______
01529     updatefile("scratchlogfiltrange",input_general.logfile);
01530     updatefile("scratchresMfiltrange",input_general.m_resfile);
01531     updatefile("scratchresSfiltrange",input_general.s_resfile);
01532 
01533     PROGRESS.print("Finished FILTRANGE.");
01534     DEBUG.print("Time spent for range filtering:");
01535     printcpu(); 
01536     }
01537  
01538 // ______ Update info of slave, size interferogram ______
01539   if (alreadyprocessed[pr_m_filtrange])
01540     {
01541     char c10rfmethod[11];       // method
01542     readres(c10rfmethod,sizeof(c10rfmethod),input_general.m_resfile,
01543             "Method_rangefilt:", 0);
01544     if (!strcmp(c10rfmethod,"adaptive"))
01545       {
01546       INFO.print("master: latest known processing stage: adaptive range filtered");
01547       char   SECTIONID[ONE27];
01548       strcpy(SECTIONID,"*_Start_");
01549       strcat(SECTIONID,processcontrol[pr_m_filtrange]);
01550       master.updateslcimage(input_general.m_resfile,SECTIONID);
01551       // ______ cut out overlay master slave exact ______
01552       interferogram.win = master.currentwindow;
01553       }
01554     }
01555 
01556 // ______ Update info of slave, size interferogram ______
01557   if (alreadyprocessed[pr_s_filtrange])         // same time as _m_
01558     {
01559     char c10rfmethod[11];       // method
01560     readres(c10rfmethod,sizeof(c10rfmethod),input_general.s_resfile,
01561             "Method_rangefilt:", 0);
01562     if (!strcmp(c10rfmethod,"adaptive"))
01563       {
01564       INFO.print("slave: latest known processing stage: adaptive range filtered");
01565       char   SECTIONID[ONE27];
01566       strcpy(SECTIONID,"*_Start_");
01567       strcat(SECTIONID,processcontrol[pr_s_filtrange]);
01568       slave.updateslcimage(input_general.s_resfile,SECTIONID);
01569       // ______ cut out overlay master slave exact, coord in master system ______
01570       if (slave.currentwindow.linelo != master.currentwindow.linelo ||
01571           slave.currentwindow.linehi != master.currentwindow.linehi ||
01572           slave.currentwindow.pixlo  != master.currentwindow.pixlo  ||
01573           slave.currentwindow.pixhi  != master.currentwindow.pixhi    )
01574         {
01575         WARNING.print("master/slave should overlap exactly after adaptive range filtering?");
01576         master.showdata();
01577         slave.showdata();
01578         }
01579       }
01580     }
01581 
01582 
01583 
01584 
01585 
01586 
01587 // ______ Fill matrix coefficients flatearth ______
01588 // ______ because might be requested to b subtracted ______
01589   if (alreadyprocessed[pr_i_comprefpha])
01590     {
01591     INFO.print("latest known processing stage: comprefpha");
01592     char c10offL[11];
01593     readres(c10offL,sizeof(c10offL),input_general.i_resfile,"Degree_flat:");
01594     int32 degreeflat = atoi(c10offL);
01595     coeff_flat = readcoeff(input_general.i_resfile,
01596                 "Estimated_coefficients_flatearth:",Ncoeffs(degreeflat));
01597     }
01598 
01599 
01600 // ====== COMPUTATION OF (COMPLEX) INTERFEROGRAM ======
01601   if (input_general.process[pr_i_interfero])
01602     {
01603     PROGRESS.print("Start INTERFERO.");
01604     alreadyprocessed[pr_i_interfero]=1;                         // update alreadypr.
01605     if (input_general.interactive)
01606       {
01607       cerr << "\nProcessing computation of interferogram.";
01608       getanswer();
01609       }
01610     // ______ Select method ______
01611     // ______ slave.currentwin is in master system (after resample) and is ______
01612     // ______ smaller than master.currentwin ______
01613     if (input_i_interfero.method==int_oldmethod)
01614       compinterfero(master,slave,
01615       input_general,input_i_interfero,coeff_flat);
01616     else if (input_i_interfero.method==int_oversample)
01617       {
01618       PRINT_ERROR("NOT IMPLEMENTED IN THIS VERSION.")
01619       throw(input_error);// exit
01620       }
01621     else
01622       {
01623       PRINT_ERROR("unknown method interfero.")
01624       throw(input_error);// exit
01625       }
01626 
01627     // ______ Update log files ______
01628     updatefile("scratchloginterfero",input_general.logfile);
01629     updatefile("scratchresinterfero",input_general.i_resfile);
01630  
01631     PROGRESS.print("Finished INTERFERO.");
01632     DEBUG.print("Time spent for computation of interferogram:");
01633     printcpu(); 
01634     }
01635 
01636 // ______ Fill input struct for filenames ______
01637   if (alreadyprocessed[pr_i_interfero])                 // update productinfo
01638     {
01639     INFO.print("latest known processing stage: interfero");
01640     char   SECTIONID[ONE27];
01641     strcpy(SECTIONID,"*_Start_");
01642     strcat(SECTIONID,processcontrol[pr_i_interfero]);
01643     interferogram.fillproductinfo(input_general.i_resfile,SECTIONID);
01644     }
01645 
01646 // ______ Generate preview if requested ______
01647   if (input_general.process[pr_i_interfero])
01648     {
01649     // ___ floor is not required, we do int division (BK, april 2003) ___
01650     // int32(floor(interferogram.win.pixels()/interferogram.multilookP)),
01651     PROGRESS.print("calling preview for complex interferogram");
01652     preview(input_general.preview,
01653             int32((interferogram.win.pixels()/interferogram.multilookP)),
01654             interferogram.formatflag, interferogram.file,
01655             "interferogram_mag.ras", "-e 0.3 -s 1.0 -q mag -o sunraster -b -c gray -M 2/2");
01656     preview(input_general.preview, 
01657             int32((interferogram.win.pixels()/interferogram.multilookP)),
01658             interferogram.formatflag, interferogram.file,
01659             "interferogram_pha.ras", "-q phase -o sunraster -b -c jet -M 2/2");
01660     preview(input_general.preview, 
01661             int32((interferogram.win.pixels()/interferogram.multilookP)),
01662             interferogram.formatflag, interferogram.file,
01663             "interferogram_mix.ras", "-e 0.3 -s 1.2 -q mixed -o sunraster -b -c hsv -M 2/2");
01664     }
01665 
01666 
01667 
01668 // ====== COMPUTATION OF REFERENCE PHASE (FLATEARTH) ======
01669   if (input_general.process[pr_i_comprefpha])
01670     {
01671     PROGRESS.print("Start COMPREFPHA.");
01672     alreadyprocessed[pr_i_comprefpha]=1;                // update alreadypr.
01673     if (input_general.interactive)
01674       {
01675       cerr << "\nProcessing computation of reference interferogram.";
01676       getanswer();
01677       }
01678 
01679     if (input_i_comprefpha.method == fe_porbits)
01680       flatearth(input_i_comprefpha, input_ellips, master, slave, interferogram,
01681                 masterorbit, slaveorbit);
01682 
01683     else if (input_i_comprefpha.method == fe_method2)
01684       {
01685       PRINT_ERROR("NOT IMPLEMENTED IN THIS VERSION.")
01686       throw(input_error);// exit
01687       }
01688 
01689     // ______ Update log files ______
01690     updatefile("scratchlogflat",input_general.logfile);
01691     updatefile("scratchresflat",input_general.i_resfile);
01692 
01693     PROGRESS.print("Finished COMPREFPHA.");
01694     DEBUG.print("Time spent for computation of reference interferogram 'flat earth':");
01695     printcpu(); 
01696     }
01697 
01698 // ______Fill matrix coefficients flatearth______
01699   if (alreadyprocessed[pr_i_comprefpha])
01700     {
01701     INFO.print("latest known processing stage: comprefpha");
01702     char c10offL[11];
01703     readres(c10offL,sizeof(c10offL),input_general.i_resfile,"Degree_flat:");
01704     int32 degreeflat = atoi(c10offL);
01705 
01706     coeff_flat = readcoeff(input_general.i_resfile,
01707                 "Estimated_coefficients_flatearth:",Ncoeffs(degreeflat));
01708     }
01709 
01710 
01711 
01712 // ====== SUBTRACT REFERENCE PHASE (FLATEARTH) ======
01713   if (input_general.process[pr_i_subtrrefpha])
01714     {
01715     PROGRESS.print("Start SUBTRREFPHA.");
01716     alreadyprocessed[pr_i_subtrrefpha]=1;                       // update alreadypr.
01717     if (input_general.interactive)
01718       {
01719       cerr << "\nProcessing subtraction of reference phase from interferogram.\n";
01720       getanswer();
01721       }
01722 
01723     // ______ Select appropriate module ______
01724     switch (input_i_subtrrefpha.method)
01725       {
01726       case srp_polynomial:
01727         subtrrefpha(master,interferogram,
01728                     input_general,input_i_subtrrefpha,
01729                     coeff_flat);
01730         break;
01731       case srp_exact:
01732         subtrrefpha(input_ellips, master, slave, interferogram,
01733                     input_general, input_i_subtrrefpha,
01734                     masterorbit, slaveorbit);
01735         break;
01736       default:
01737         PRINT_ERROR("PANIC: not possible, bert.")
01738         throw(unhandled_case_error);// exit
01739       }
01740 
01741     // ______ Update log files ______
01742     updatefile("scratchlogsubtrrefpha",input_general.logfile);
01743     updatefile("scratchressubtrrefpha",input_general.i_resfile);
01744  
01745     PROGRESS.print("Finished SUBTRREFPHA.");
01746     DEBUG.print("Time spent for subtraction of reference phase:");
01747     printcpu(); 
01748     }
01749 
01750 // ______ Fill input struct for filenames ______
01751   if (alreadyprocessed[pr_i_subtrrefpha])               // update productinfo
01752     {
01753     INFO.print("latest known processing stage: subtrrefpha");
01754     char   SECTIONID[ONE27];
01755     strcpy(SECTIONID,"*_Start_");
01756     strcat(SECTIONID,processcontrol[pr_i_subtrrefpha]);
01757     interferogram.fillproductinfo(input_general.i_resfile,SECTIONID);
01758     }
01759 
01760 // ______ Generate preview if requested ______
01761   if (input_general.process[pr_i_subtrrefpha])
01762     {
01763     PROGRESS.print("calling preview for refpha corrected image");
01764     // ____ if refphase dumped, tmp change filename ___
01765     //if (!strcmp(interferogram.file,"NO_OUTPUT_ONLY_DUMPING_REF_PHA")
01766     if (input_i_subtrrefpha.dumponlyrefpha==true)
01767       strcpy(interferogram.file,input_i_subtrrefpha.forefpha);
01768     preview(input_general.preview, 
01769             int32((interferogram.win.pixels()/interferogram.multilookP)),
01770             interferogram.formatflag, interferogram.file,
01771             "interferogram_srp_mag.ras", "-e 0.3 -s 1.0 -q mag -o sunraster -b -c gray -M 2/2");
01772     preview(input_general.preview, 
01773             int32((interferogram.win.pixels()/interferogram.multilookP)),
01774             interferogram.formatflag, interferogram.file,
01775             "interferogram_srp_pha.ras", "-q phase -o sunraster -b -c jet -M 2/2");
01776     preview(input_general.preview, 
01777             int32((interferogram.win.pixels()/interferogram.multilookP)),
01778             interferogram.formatflag, interferogram.file,
01779             "interferogram_srp_mix.ras", "-e 0.3 -s 1.2 -q mixed -o sunraster -b -c cool -M 2/2");
01780     if (input_i_subtrrefpha.dumponlyrefpha==true)
01781       {INFO.print("exiting, only dumped refpha"); exit(1);}
01782     }
01783 
01784 
01785 
01786 // ====== COMPUTATION OF COHERENCE IMAGE ======
01787 // (use complex interferogram in future!)
01788   if (input_general.process[pr_i_coherence])
01789     {
01790     PROGRESS.print("Start COHERENCE.");
01791     alreadyprocessed[pr_i_coherence]=1;                         // update alreadypr.
01792     if (input_general.interactive)
01793       {
01794       cerr << "\nProcessing computation of coherence.";
01795       getanswer();
01796       }
01797 
01798     // ______ Select method ______
01799     switch (input_i_coherence.method)
01800       {
01801       case coh_oldmethod:
01802           // use flatearth, compute interferogram again
01803           // compcoherence(master,slave,interferogram,
01804           compcoherence(master, slave,
01805                         input_general, input_i_coherence, coeff_flat);
01806         break;
01807       case coh_newmethod:
01808           // use computed complex interferogram (minus ref.pha)
01809           PRINT_ERROR("NOT IMPLEMENTED IN THIS VERSION.")
01810           throw(unhandled_case_error);// exit
01811         break;
01812       default:
01813         PRINT_ERROR("unknown method coherence.")
01814         throw(unhandled_case_error);// exit
01815       }
01816 
01817     // ______ Update log files ______
01818     updatefile("scratchlogcoherence",input_general.logfile);
01819     updatefile("scratchrescoherence",input_general.i_resfile);
01820  
01821     PROGRESS.print("Finished COHERENCE.");
01822     DEBUG.print("Time spent for computation of coherence:");
01823     printcpu(); 
01824     }
01825 
01826 // ______ Fill input struct for filenames ______
01827   if (alreadyprocessed[pr_i_coherence])                         // update slcimage
01828     {
01829     INFO.print("latest known processing stage: coherence");
01830     char   SECTIONID[ONE27];
01831     strcpy(SECTIONID,"*_Start_");
01832     strcat(SECTIONID,processcontrol[pr_i_coherence]);
01833     coherence.fillproductinfo(input_general.i_resfile,SECTIONID);
01834     }
01835   // ___ generate preview if requested and just processed ___
01836   if (input_general.process[pr_i_coherence])
01837     {
01838     // ______ See if we can trick cpxfiddle in believing this is cpx ______
01839     // ______ Should also work for real4 ______ // BK 16-Jun-2003 ______
01840     PROGRESS.print("calling preview for coherence");
01841     preview(input_general.preview, 
01842             int32((coherence.win.pixels()/coherence.multilookP)),
01843             coherence.formatflag, coherence.file,
01844             "coherence.ras", 
01845             "-q normal -o sunraster -b -c gray -M 2/2");
01846     }
01847 
01848 
01849 
01850 // ====== COMPUTE REFERENCE PHASE (DEM) ======
01851   if (input_general.process[pr_i_comprefdem])
01852     {
01853     PROGRESS.print("Start COMPREFDEM.");
01854     alreadyprocessed[pr_i_comprefdem]=1;                        // update alreadypr.
01855     if (input_general.interactive)
01856       {
01857       cerr << "\nProcessing computation of reference phase from DEM.\n";
01858       getanswer();
01859       }
01860     // if (input_i_comprefdem.method == gtopo30)
01861       radarcodedem(input_general, input_ellips, input_i_comprefdem,
01862                 master, slave, interferogram,
01863                 masterorbit, slaveorbit);
01864 
01865     // ______ Update log files ______
01866     updatefile("scratchlogcomprefdem",input_general.logfile);
01867     updatefile("scratchrescomprefdem",input_general.i_resfile);
01868  
01869     //WARNING("Not tested properly yet.");
01870     PROGRESS.print("Finished COMPREFDEM.");
01871     DEBUG.print("Time spent for computation of reference DEM:");
01872     printcpu(); 
01873     }
01874 
01875 // ______ Fill input struct for ______
01876   if (alreadyprocessed[pr_i_comprefdem])                        // update slcimage
01877     {
01878     INFO.print("latest known processing stage: comprefdem");
01879     char   SECTIONID[ONE27];
01880     strcpy(SECTIONID,"*_Start_");
01881     strcat(SECTIONID,processcontrol[pr_i_comprefdem]);
01882     radarcodedrefdem.fillproductinfo(input_general.i_resfile,SECTIONID);
01883     }
01884   // ___ generate preview if requested and just processed ___
01885   if (input_general.process[pr_i_comprefdem])
01886     {
01887     // ______ See if we can trick cpxfiddle in believing this is cpx ______
01888     // ______ Should also work for real4 ______ // BK 16-Jun-2003 ______
01889     PROGRESS.print("calling preview for comprefdem (phase)");
01890     preview(input_general.preview, 
01891             int32((radarcodedrefdem.win.pixels()/radarcodedrefdem.multilookP)),
01892             radarcodedrefdem.formatflag, radarcodedrefdem.file,
01893             "comprefdem_phase.ras", 
01894             "-q normal -o sunraster -b -c jet -M 2/2");
01895     if (specified(input_i_comprefdem.forefdemhei))
01896       {
01897       PROGRESS.print("calling preview for comprefdem (height)");
01898       preview(input_general.preview, 
01899               int32((radarcodedrefdem.win.pixels()/radarcodedrefdem.multilookP)),
01900               FORMATR4, input_i_comprefdem.forefdemhei,
01901               "comprefdem_height.ras", 
01902               "-q normal -o sunraster -b -c jet -M 2/2");
01903       }
01904     }
01905 
01906 
01907 
01908 // ====== SUBTRACT REFERENCE PHASE (DEM) ======
01909   if (input_general.process[pr_i_subtrrefdem])
01910     {
01911     PROGRESS.print("Start SUBTRREFDEM.");
01912     alreadyprocessed[pr_i_subtrrefdem]=1;                       // update alreadypr.
01913     if (input_general.interactive)
01914       {
01915       cerr << "\nProcessing subtraction of reference DEM from interferogram.\n";
01916       getanswer();
01917       }
01918     subtrrefdem(interferogram,radarcodedrefdem,input_general,input_i_subtrrefdem);
01919 
01920     // ______ Update log files ______
01921     updatefile("scratchlogsubtrrefdem",input_general.logfile);
01922     updatefile("scratchressubtrrefdem",input_general.i_resfile);
01923  
01924     PROGRESS.print("Finished SUBTRREFDEM.");
01925     DEBUG.print("Time spent for subtraction of reference DEM:");
01926     printcpu(); 
01927     }
01928 
01929 // ______ Fill input struct for filenames ______
01930   if (alreadyprocessed[pr_i_subtrrefdem])                       // update slcimage
01931     {
01932     INFO.print("latest known processing stage: subtrrefdem");
01933     //WARNING("check this ..., nothing changed except filenaem?");
01934     char   SECTIONID[ONE27];
01935     strcpy(SECTIONID,"*_Start_");
01936     strcat(SECTIONID,processcontrol[pr_i_subtrrefdem]);
01937     interferogram.fillproductinfo(input_general.i_resfile,SECTIONID);
01938     }
01939 
01940 // ______ Generate preview if requested ______
01941   if (input_general.process[pr_i_subtrrefdem])
01942     {
01943     PROGRESS.print("calling preview for refdem corrected interferogram");
01944     preview(input_general.preview, 
01945             int32((interferogram.win.pixels()/interferogram.multilookP)),
01946             interferogram.formatflag, interferogram.file,
01947             "interferogram_srd_mag.ras", "-e 0.3 -s 1.0 -q mag -o sunraster -b -c gray -M 2/2");
01948     preview(input_general.preview, 
01949             int32((interferogram.win.pixels()/interferogram.multilookP)),
01950             interferogram.formatflag, interferogram.file,
01951             "interferogram_srd_pha.ras", "-q phase -o sunraster -b -c jet -M 2/2");
01952     preview(input_general.preview, 
01953             int32((interferogram.win.pixels()/interferogram.multilookP)),
01954             interferogram.formatflag, interferogram.file,
01955             "interferogram_srd_mix.ras", "-e 0.3 -s 1.2 -q mixed -o sunraster -b -c hot -M 2/2");
01956     }
01957 
01958 
01959 // ====== PHASE FILTERING ======
01960   if (input_general.process[pr_i_filtphase])
01961     {
01962     PROGRESS.print("Start FILTPHASE.");
01963     alreadyprocessed[pr_i_filtphase]=1;                         // update alreadypr.
01964     if (input_general.interactive)
01965       {
01966       cerr << "\nProcessing phase filtering.";
01967       getanswer();
01968       }
01969 
01970     switch (input_i_filtphase.method)
01971       {
01972       case fp_goldstein:
01973         phasefilter(input_general,interferogram,input_i_filtphase);
01974         break;
01975       case fp_spatialconv:
01976         spatialphasefilt(input_general,interferogram,input_i_filtphase);
01977         break;
01978       case fp_spectral:
01979         phasefilterspectral(input_general,interferogram,input_i_filtphase);
01980         break;
01981       default:
01982         PRINT_ERROR("PANIC: not possible.")
01983         throw(unhandled_case_error);// exit
01984       }
01985 
01986 // ______ Update log files ______
01987     updatefile("scratchlogfiltphase",input_general.logfile);
01988     updatefile("scratchresfiltphase",input_general.i_resfile);
01989 
01990     PROGRESS.print("Finished FILTPHASE.");
01991     DEBUG.print("Time spent for phase filtering:");
01992     printcpu(); 
01993     }
01994 
01995 // ______ Fill info struct for filenames ______
01996   if (alreadyprocessed[pr_i_filtphase]) // update productinfo
01997     {
01998     INFO.print("latest known processing stage: filtphase");
01999     char   SECTIONID[ONE27];
02000     strcpy(SECTIONID,"*_Start_");
02001     strcat(SECTIONID,processcontrol[pr_i_filtphase]);
02002     interferogram.fillproductinfo(input_general.i_resfile,SECTIONID);
02003     }
02004 
02005 // ______ Generate preview if requested ______
02006   if (input_general.process[pr_i_filtphase])
02007     {
02008     PROGRESS.print("calling preview for phase filtered corrected interferogram");
02009     preview(input_general.preview, 
02010             int32((interferogram.win.pixels()/interferogram.multilookP)),
02011             interferogram.formatflag, interferogram.file,
02012             "interferogram_filt_mag.ras", "-e 0.3 -s 1.0 -q mag -o sunraster -b -c gray -M 2/2");
02013     preview(input_general.preview, 
02014             int32((interferogram.win.pixels()/interferogram.multilookP)),
02015             interferogram.formatflag, interferogram.file,
02016             "interferogram_filt_pha.ras", "-q phase -o sunraster -b -c jet -M 2/2");
02017     preview(input_general.preview, 
02018             int32((interferogram.win.pixels()/interferogram.multilookP)),
02019             interferogram.formatflag, interferogram.file,
02020             "interferogram_filt_mix.ras", "-e 0.3 -s 1.2 -q mixed -o sunraster -b -c hsv -M 2/2");
02021     }
02022 
02023 
02024 
02025 // ====== DIFFERENTIAL 3 PASS, DEFO PROCESSING ======
02026   if (input_general.process[pr_i_dinsar])
02027     {
02028     PROGRESS.print("Start DINSAR.");
02029     alreadyprocessed[pr_i_dinsar]=1;                            // update alreadypr.
02030     if (input_general.interactive)
02031       {
02032       cerr << "\nProcessing differential interferometry.";
02033       getanswer();
02034       }
02035     dinsar(input_general,input_i_dinsar,input_ellips,
02036             master,masterorbit,
02037             slave,slaveorbit,interferogram);                    // (defopair)
02038 
02039     // ______ Update log files ______
02040     updatefile("scratchlogdinsar",input_general.logfile);
02041     updatefile("scratchresdinsar",input_general.i_resfile);
02042  
02043     PROGRESS.print("Finished DINSAR.");
02044     DEBUG.print("Time spent for 3 pass differential interferometry:");
02045     printcpu(); 
02046     }
02047 
02048   // ______ Fill info struct for filenames ______
02049   // ______ use interferogram because you want to unwrap it? ______
02050   if (alreadyprocessed[pr_i_dinsar])                            // update productinfo
02051     {
02052     INFO.print("latest known processing stage: dinsar");
02053     char   SECTIONID[ONE27];
02054     strcpy(SECTIONID,"*_Start_");
02055     strcat(SECTIONID,processcontrol[pr_i_dinsar]);
02056     interferogram.fillproductinfo(input_general.i_resfile,SECTIONID);
02057     }
02058 
02059 // ______ Generate preview if requested ______
02060   if (input_general.process[pr_i_dinsar])
02061     {
02062     PROGRESS.print("calling preview for differential interferogram");
02063     preview(input_general.preview, 
02064             int32((interferogram.win.pixels()/interferogram.multilookP)),
02065             interferogram.formatflag, interferogram.file,
02066             "interferogram_dinsar_mag.ras", "-e 0.3 -s 1.0 -q mag -o sunraster -b -c gray -M 2/2");
02067     preview(input_general.preview, 
02068             int32((interferogram.win.pixels()/interferogram.multilookP)),
02069             interferogram.formatflag, interferogram.file,
02070             "interferogram_dinsar_pha.ras", "-q phase -o sunraster -b -c jet -M 2/2");
02071     preview(input_general.preview, 
02072             int32((interferogram.win.pixels()/interferogram.multilookP)),
02073             interferogram.formatflag, interferogram.file,
02074             "interferogram_dinsar_mix.ras", "-e 0.3 -s 1.2 -q mixed -o sunraster -b -c jet -M 2/2");
02075     }
02076 
02077 
02078 
02079 
02080 // ====== UNWRAPPING INTERFEROGRAM ======
02081   unwrappedinterf = interferogram;
02082   if (input_general.process[pr_i_unwrap])
02083     {
02084     PROGRESS.print("Start UNWRAP.");
02085     alreadyprocessed[pr_i_unwrap]=1;                            // update alreadypr.
02086     if (input_general.interactive)
02087       {
02088       cerr << "\nProcessing unwrapping of interferogram.";
02089       getanswer();
02090       }
02091 
02092     switch (input_i_unwrap.method)
02093       {
02094       // ___ Branch cut ___
02095       case uw_method1:
02096         unwraptreeframon(
02097                 input_general, 
02098                 input_i_unwrap,
02099                 interferogram);
02100         break;
02101 
02102       // ___ Statistic minimal cost flow ___
02103       case uw_method2:
02104         snaphu_unwrap(
02105                 input_general, 
02106                 input_i_unwrap,
02107                 interferogram,
02108                 master, slave,
02109                 masterorbit, slaveorbit,
02110                 input_ellips);
02111         if (specified(input_i_unwrap.snaphu_log))
02112           updatefile(input_i_unwrap.snaphu_log,input_general.logfile);
02113         break;
02114 
02115       // ___ Minimal cost flow algorithm ___
02116       case uw_method3:
02117         PRINT_ERROR("NOT IMPLEMENTED IN THIS VERSION.")
02118         throw(unhandled_case_error);// exit
02119         break;
02120 
02121       default:
02122         PRINT_ERROR("PANIC: NOT POSSIBLE.")
02123         throw(unhandled_case_error);// exit
02124       }
02125 
02126 //    // ______ Apply bias to unwrapped interferogram, based on tiepoint ______
02127 //    // ______ This simply loads the created unwrapped ifg; ______
02128 //    // ______ computes the tiepoint, and saves it to the same file. ______
02129 //    if (abs(input_i_unwrap.tiepoint.x) < 0.001 &&
02130 //        abs(input_i_unwrap.tiepoint.y) < 0.001 &&
02131 //        abs(input_i_unwrap.tiepoint.z) < 0.001)
02132 //      {
02133 //      PROGRESS.print("Computating integration constant based on tiepoint");
02134 //      add_bias_unwrap(
02135 //              input_general, 
02136 //              input_i_unwrap,
02137 //              interferogram,
02138 //              master, slave,
02139 //              masterorbit, slaveorbit,
02140 //              input_ellips);
02141 //++++ also add in unwrap.h
02142 //      }
02143 
02144     // ______ Update log files ______
02145     updatefile("scratchlogunwrap",input_general.logfile);
02146     updatefile("scratchresunwrap",input_general.i_resfile);
02147 
02148     PROGRESS.print("Finished UNWRAP.");
02149     DEBUG.print("Time spent for unwrapping:");
02150     printcpu(); 
02151     }
02152 
02153   // ______ Fill info struct for filenames ______
02154   // ______ 2b sure, initialize unwrappedinterf with interferogram ______
02155   unwrappedinterf = interferogram;
02156   if (alreadyprocessed[pr_i_unwrap])                            // update productinfo
02157     {
02158     INFO.print("latest known processing stage: unwrap");
02159     char   SECTIONID[ONE27];
02160     strcpy(SECTIONID,"*_Start_");
02161     strcat(SECTIONID,processcontrol[pr_i_unwrap]);
02162     unwrappedinterf.fillproductinfo(input_general.i_resfile,SECTIONID);
02163     }
02164   // ___ generate preview if requested and just now computed____
02165   if (input_general.process[pr_i_unwrap])
02166     {
02167     // ______ Generate preview if requested and oformat was hgt?______
02168     // ______ See if we can trick cpxfiddle in believing this is cpx ______
02169     // ______ Should also work for real4 ______
02170     // BK 13-Apr-2003
02171     PROGRESS.print("calling preview for unwrapped interferogram");
02172     preview(input_general.preview, 
02173             int32((unwrappedinterf.win.pixels()/unwrappedinterf.multilookP)),
02174             unwrappedinterf.formatflag, unwrappedinterf.file,
02175             "unwrapped_interferogram.ras", 
02176             "-q normal -o sunraster -b -c jet -M 2/2");// -V
02177     }
02178 
02179 
02180 // ====== SLANT TO HEIGHT CONVERSION ======
02181   if (input_general.process[pr_i_slant2h])
02182     {
02183     PROGRESS.print("Start SLANT2H.");
02184     alreadyprocessed[pr_i_slant2h]=1;                           // update alreadypr.
02185     if (input_general.interactive)
02186       {
02187       cerr << "\nProcessing slant to height conversion.";
02188       getanswer();
02189       }
02190     if (!strcmp(input_i_slant2h.fohei,unwrappedinterf.file))
02191       {
02192       PRINT_ERROR("slant2h: same filename input/output")
02193       throw(input_error);// exit
02194       }
02195 
02196     switch (input_i_slant2h.method)
02197       {
02198       case s2h_schwabisch:
02199         slant2hschwabisch(
02200             input_general, input_i_slant2h, input_ellips,
02201             master, slave, unwrappedinterf,
02202             masterorbit, slaveorbit);
02203         break;
02204 
02205       case s2h_rodriguez:
02206         slant2hrodriguez(
02207             input_general, input_i_slant2h, input_ellips,
02208             master, slave, unwrappedinterf,
02209             coeff_flat,
02210             masterorbit, slaveorbit, 
02211             baseline);
02212         break;
02213 
02214       case s2h_ambiguity:
02215         slant2hambiguity(
02216             input_general, input_i_slant2h, input_ellips,
02217             master, slave, unwrappedinterf,
02218             masterorbit, slaveorbit,
02219             baseline);
02220         // ______ This method includes geocoding, but probably contains trend ______
02221         alreadyprocessed[pr_i_geocoding]=1;                     // update alreadypr.
02222         break;
02223 
02224       default:
02225         PRINT_ERROR("slant2h: unknown method.")
02226         throw(unhandled_case_error);// exit
02227       }
02228 
02229     // ______ Update log files ______
02230     updatefile("scratchlogslant2h",input_general.logfile);
02231     updatefile("scratchresslant2h",input_general.i_resfile);
02232 
02233     PROGRESS.print("Finished SLANT2H.");
02234     DEBUG.print("Time spent for slant 2 height:");
02235     printcpu(); 
02236     }
02237 
02238   // ______ Fill info struct for filenames ______
02239   if (alreadyprocessed[pr_i_slant2h])                   // update productinfo
02240     {
02241     INFO.print("latest known processing stage: slant2h");
02242     char   SECTIONID[ONE27];
02243     strcpy(SECTIONID,"*_Start_");
02244     strcat(SECTIONID,processcontrol[pr_i_slant2h]);
02245     heightinradarsystem.fillproductinfo(input_general.i_resfile,SECTIONID);
02246     }
02247   // ___ generate preview if requested and just processed ___
02248   if (input_general.process[pr_i_slant2h])
02249     {
02250     // ______ Generate preview if requested and oformat was hgt?______
02251     // ______ See if we can trick cpxfiddle in believing this is cpx ______
02252     // ______ Should also work for real4 ______
02253     // ______ note that there is not point in preview of these heights? _____
02254     // BK 13-Apr-2003
02255     PROGRESS.print("calling preview for slant to height");
02256     preview(input_general.preview, 
02257             int32((heightinradarsystem.win.pixels()/heightinradarsystem.multilookP)),
02258             heightinradarsystem.formatflag, heightinradarsystem.file,
02259             "height_in_radarcoordinates.ras", 
02260             "-q normal -o sunraster -b -c jet -M 2/2");// -V
02261     }
02262 
02263 
02264 
02265 // ====== GEOCODING ======
02266   if (input_general.process[pr_i_geocoding])
02267     {
02268     PROGRESS.print("Start GEOCODE.");
02269     alreadyprocessed[pr_i_geocoding]=1;                 // update alreadypr.
02270     if (input_general.interactive)
02271       {
02272       cerr << "\nProcessing geocoding.";
02273       getanswer();
02274       }
02275     geocode(
02276         input_general, input_i_geocode, input_ellips, master,
02277         heightinradarsystem, masterorbit);
02278 
02279     // ______ Update log files ______
02280     updatefile("scratchloggeocode",input_general.logfile);
02281     updatefile("scratchresgeocode",input_general.i_resfile);
02282     PROGRESS.print("Finished GEOCODE.");
02283     DEBUG.print("Time spent for geocoding:");
02284     printcpu(); 
02285     }
02286   // ______ No need fillproductinfo after last one ______
02287 //  // ______ but do it for consistentness/preview card one day _____
02288 //  // ______ Fill info struct for filenames ______
02289   if (alreadyprocessed[pr_i_geocoding])                 // update productinfo
02290     {
02291     INFO.print("latest known processing stage: geocoding");
02292     }
02293 
02294 
02295 
02296   // ====== TIDY UP ======
02297   // ______ Update process control flags in resultfiles ______
02298   if (processmaster)
02299     updateprocesscontrol(input_general.m_resfile,MASTERID);
02300   if (processlave)
02301     updateprocesscontrol(input_general.s_resfile,SLAVEID);
02302   if (processinterf)
02303     updateprocesscontrol(input_general.i_resfile,INTERFID);
02304 
02305   DEBUG.print("Time spent for tidying up:");
02306   printcpu(); 
02307 
02308   cout << "\n\nProcessing results are in parameter file";
02309   if ((processmaster && processlave)   ||
02310       (processmaster && processinterf) ||
02311       (processlave   && processinterf))
02312     cout << "s:\n";
02313   else
02314     cout << ":\n";
02315   if (processmaster)
02316     cout << "   " << input_general.m_resfile << endl;
02317   if (processlave)
02318     cout << "   " << input_general.s_resfile << endl;
02319   if (processinterf)
02320     cout << "   " << input_general.i_resfile << endl;
02321   quote();
02322   WARNING.summary();
02323 
02324   }// --- end of try block; now catch thrown exceptions -------------
02325   catch(USAGE_ERROR& usage_error)// catch errors of EXCEPTION class
02326     {
02327     exit(-1);// normal exit; 
02328     }
02329   catch(EXCEPTION& error)// catch errors of EXCEPTION class
02330     {
02331     cerr << "Caught error of EXCEPTION class!" << endl;
02332     cerr << "It is: " << (const char*)error << endl;
02333     printcpu();
02334     WARNING.summary();
02335     exit(1);
02336     }
02337   catch(const char* error_string)// catch handled errors
02338     {
02339     cerr << "Caught error!" << endl;
02340     cerr << "It is: " << error_string << endl;
02341     printcpu();
02342     WARNING.summary();
02343     exit(2);
02344     }
02345   catch(...) // catches other errors
02346     {
02347     cerr << "Caught an unhandled error!" << endl;
02348     printcpu();
02349     WARNING.summary();
02350     exit(3);
02351     }
02352 
02353   cout << "\n\nNormal termination.\nThank you for using Doris.\n\n";
02354   return int32(0);
02355   } // END main
02356 
02357 
02358 
02359 /****************************************************************
02360  @brief  initmessages initializes logging messages
02361  @param  none no arguments
02362  * initmessages                                                 *
02363  * set defaults for global messages objects                     *
02364  * #%// BK 12-Apr-2003                                          *
02365  ****************************************************************/
02366 void initmessages()
02367   {
02368   TRACE.setidentifyer("TRACE");
02369   TRACE.dostderr(0);
02370   TRACE.doprint(0);
02371   TRACE.bellrings(0);
02372   DEBUG.setidentifyer("DEBUG");
02373   DEBUG.dostderr(0);
02374   DEBUG.doprint(0);
02375   DEBUG.bellrings(0);
02376   INFO.setidentifyer("INFO");
02377   INFO.dostderr(0);
02378   INFO.doprint(1);
02379   INFO.bellrings(0);
02380   PROGRESS.setidentifyer("PROGRESS");
02381   PROGRESS.dostderr(1);
02382   PROGRESS.doprint(1);
02383   PROGRESS.bellrings(1);
02384   WARNING.setidentifyer("WARNING");
02385   WARNING.dostderr(1);
02386   WARNING.doprint(1);
02387   WARNING.bellrings(2);
02388   ERROR.setidentifyer("ERROR");
02389   ERROR.dostderr(1);
02390   ERROR.doprint(1);
02391   ERROR.bellrings(3);
02392   ERROR.doexit(0);
02393   matDEBUG.setidentifyer("mtxDEBUG");
02394   matDEBUG.dostderr(0);
02395   matDEBUG.doprint(1);// default print, define prevents too much
02396   matERROR.setidentifyer("mtxERROR");
02397   matERROR.dostderr(1);
02398   matERROR.doprint(1);
02399   matERROR.bellrings(10);// should not occur anyway
02400   matERROR.doexit(1);
02401   } // END initmessages
02402 
02403 
02404 
02405 /****************************************************************
02406  @brief  handleinput parses input
02407  @param  argc original command line input to program
02408  @param  argv original command line input to program
02409  @param  input_gen general input struct
02410  * handleinput                                                  *
02411  * returns inputfilename as input_gen.logfile                   *
02412  * BK 01-Dec-1999                                               *
02413  ****************************************************************/
02414 void handleinput(int argc, char* argv[], input_gen &input_general)
02415   {
02416   TRACE_FUNCTION("handleinput");     
02417   // ====== Handle command line arguments ======
02418   switch (argc)
02419     {
02420     case 3:                                     // help search term
02421       ; // do nothing, assume argv[1] is -h ... 
02422       //--- fall through --- //
02423     case 2:                                     // optionsfilename, -h, or -ver
02424       if (!strcmp(argv[1],"-ver") || !strcmp(argv[1],"-v") ||
02425           !strcmp(argv[1],"-VER") || !strcmp(argv[1],"-V")) // version number asked
02426         {
02427         cerr <<   "Software name:    " << SWNAME
02428              << "\nSoftware version: " << SWVERSION << endl;
02429         exit(0);
02430         }
02431       // ______ Help wanted ______
02432       else if (!strcmp(argv[1],"-h") || !strcmp(argv[1],"-H") ||
02433                !strcmp(argv[1],"-help") || !strcmp(argv[1],"-HELP"))
02434         {
02435         // g++ makes: helpdoris (null) if empty argv[2] 
02436         if (argc==2) 
02437           {
02438           INFO.print("Making system call:");
02439           INFO.print("helpdoris");
02440           system("helpdoris"); 
02441           }
02442         else
02443           {
02444           INFO << "helpdoris " << argv[2] << ends;      // search pattern
02445           char cmd[512];// command string
02446           strcpy(cmd, INFO.get_str());
02447           INFO.print("Making system call:");
02448           INFO.print(cmd);
02449           system(cmd);
02450           }
02451         exit(0);
02452         }
02453       // ______ Copyright notice ______
02454       else if (!strcmp(argv[1],"-c") || !strcmp(argv[1],"-C"))
02455         {
02456         copyright();
02457         }
02458       // ______ Random quote ______
02459       else if (!strcmp(argv[1],"-q") || !strcmp(argv[1],"-Q"))
02460         {
02461         quote();
02462         exit(0);
02463         }
02464       // ______ Assume input file ______
02465       else
02466         strcpy(input_general.logfile,argv[1]);          // store in logfile.
02467       break; // --- stop falling, no more options --- //
02468     // default no name for inputfile
02469     //case 1:                                           // no arguments
02470     //  strcpy(input_general.logfile,"inputoptionsfile");       // default name
02471     //  break;
02472     default:
02473       usage(argv[0]);
02474     } // switch handle arguments
02475 
02476   // ______ Check command line arguments ______
02477   if (existed(input_general.logfile)==true)
02478     {
02479     INFO << "input file: \"" << input_general.logfile << "\"";
02480     INFO.print();
02481     }
02482   else
02483     {
02484     ERROR << argv[0] << " input file: \"" << input_general.logfile
02485          << "\" not found.";
02486     ERROR.print();
02487     throw(input_error);// check if exception is caught in try block
02488     //usage(argv[0]);
02489     }
02490   } // END handleinput
02491 
02492 
02493 
02494 /****************************************************************
02495  @brief  usage echos synopsis
02496  @param  programname name of this program
02497  * usage                                                        *
02498  * BK 01-Dec-1999                                               *
02499  ****************************************************************/
02500 void usage(char *programname)
02501   {
02502   TRACE_FUNCTION("usage");
02503   cerr << "\n\t ***     **     **   *    **"
02504        << "\n\t *  *   *  *   *     *   *"
02505        << "\n\t *  *   *  *   *     *    *"
02506        << "\n\t *  *   *  *   *     *     *"
02507        << "\n\t ***     **    *     *   **\n\n\n";
02508   cerr << "\n  Program: \"" << programname << "\" " << SWVERSION
02509        << "\n\tInterferometric processor for SAR SLC data.\n"
02510        << "\n\t(c) Delft University of Technolgy, the Netherlands."
02511        << "\n\t    Created by: Bert Kampes.\n\n"
02512        << "  SYNOPSIS:\n\t" << programname
02513        << " infile | -h [searchterm] | -v | -c | -q\n\n"
02514        << "\t  infile:       input file for " << programname << endl
02515        //<< "\n\t\t\t(default: \"inputoptionsfile\")\n"
02516        << "\t  -h [term]:    call \"helpdoris\" (script with searchable help)\n"
02517        << "\t  -c:           return copyright notice.\n"
02518        << "\t  -q:           return random quote (not so random).\n"
02519        << "\t  -v:           return version number.\n\n\n";
02520   throw(usage_error);// normal exit
02521   } // END usage
02522 
02523 
02524 
02525 /****************************************************************
02526  @brief  quote like fortune program
02527  * quote                                                        *
02528  * I copied some quotes from the internet etc.                  *
02529  * sorry not to have a source for them.                         *
02530  * BK 15-Nov-2000                                               *
02531  ****************************************************************/
02532 void quote()
02533   {
02534   TRACE_FUNCTION("quote");
02535   // ______ Initialize quotes (send me new ones) ______
02536   const int32 largestquote = ONE27; 
02537   const char QUOTES[][largestquote] = {
02538     "tip: Check out \"http://enterprise.geo.tudelft.nl/doris/\"",
02539     "tip: Check out \"http://enterprise.geo.tudelft.nl/dig/\"",
02540     "tip: See the online manual at \"http://enterprise.geo.tudelft.nl/doris/\"",
02541     "tip: Type: \"helpdoris\" for a synopsis of all input cards.",
02542     "tip: The \"run\" script can be used to generate template input files.",
02543     "tip: Get ASAR/ERS[12] precise orbits via \"http://www.deos.tudelft.nl/ers/precorbs/\"",
02544     "tip: For RADARSAT, use polyfit orbit interpolation, not approximation.",
02545     "tip: cpxfiddle is a nifty little utility.",
02546     "tip: dateconv is a nifty little utility.",
02547     "GMT is a great package.",
02548     "The only thing we have to fear is fear itself.",
02549     "2b || !2b = 1",
02550     "Sent me better quotes. Quick.", // 10
02551     "The whole is more than the sum of its parts.",
02552     "To Thales the primary question was not what do we know,\n\tbut how do we know it.",
02553     "For the things of this world cannot be made known without\n\ta knowledge of mathematics.",
02554     "Life is a school of probability.",
02555     "\"Obvious\" is the most dangerous word in mathematics.",
02556     "An expert is a man who has made all the mistakes, which can be made,\n\tin a very narrow field.",
02557     "Structures are the weapons of the mathematician.",
02558     "A witty statesman said, you might prove anything by figures.",
02559     "Men pass away, but their deeds abide.",
02560     "It is a good thing for an uneducated man to read books of quotations.", // 20
02561     "Mathematics is written for mathematicians.",
02562     "Revolutions never occur in mathematics.",
02563     "It is easier to square the circle than to get round a mathematician.",
02564     "Cognito ergo sum. \"I think, therefore I am.\"",
02565     "It is not enough to have a good mind. The main thing is to use it well.",
02566     "From a drop of water a logician could predict an Atlantic or a Niagara.",
02567     "I don't believe in mathematics.",
02568     "Imagination is more important than knowledge.",
02569     "A Mathematician is a machine for turning coffee into theorems.",
02570     "Whenever you can, count.", // 30
02571     "Mathematics is a language.",
02572     "One should always generalize.",
02573     "Statistics: the mathematical theory of ignorance.",
02574     "When we ask advice, we are usually looking for an accomplice.",
02575     "What we know is not much. What we do not know is immense.",
02576     "Medicine makes people ill, mathematics make them sad and theology makes them sinful.",
02577     "A great truth is a truth whose opposite is also a great truth.",
02578     "I feign no hypotheses.",
02579     "It is not certain that everything is uncertain.",
02580     "Though this be madness, yet there is method in it.", // 40
02581     "I have no faith in political arithmetic.",
02582     "Fourier is a mathematical poem.",
02583     "We think in generalities, but we live in details.",
02584     "I think that God in creating man somewhat overestimated his ability.",
02585     "Add little to little and there will be a big pile.",
02586     "Computers in the future may weigh no more than 1.5 tons. (1949)",
02587     "There is no reason anyone would want a computer in their home. (1977)",
02588     "Heavier-than-air flying machines are impossible. (1895)",
02589     "Everything that can be invented has been invented. (1899)",
02590     "640K ought to be enough for anybody. (1981)", // 50
02591     "Pentiums melt in your PC, not in your hand.",
02592     "Always remember you're unique, just like everyone else.",
02593     "Ever notice how fast Windows runs? Neither did I.",
02594     "Double your drive space - delete Windows!",
02595     "Circular definition: see Definition, circular.",
02596     "43.3% of statistics are meaningless.",
02597     "Very funny, Scotty. Now beam down my clothes.",
02598     "I've got a problem. I say everything twice",
02599     "Don't insult the alligator till after you cross the river.",
02600     "Black holes are where God divided by zero.", // 60
02601     "% make fire\n\tMake: Don't know how to make fire. Stop.",
02602     "% why not?\n\tNo match.",
02603     "% gotta light?\n\tNo match.",
02604     "% !1984\n\t 1984: Event not found. # (on some systems)",
02605     "% How's my lovemaking?\n\t Unmatched '.",
02606     "% \"How would you rate his incompetence?\n\tUnmatched \".",
02607     "% [Where is Jimmy Hoffa?\n\tMissing ].",
02608     "% [Where is my brain?\n\tMissing ].",
02609     "% ^How did the sex change^ operation go?\n\tModifier failed.",
02610     "% ar x \"my love life\"\n\tar: my love life does not exist", // 70
02611     "This time it will surely run.",
02612     "Bug? That's not a bug, that's a feature.",
02613     "It's redundant! It's redundant!",
02614     "cpxfiddle is a great program.",
02615     "The shortest path between two truths in the real domain\n\tpasses through the complex domain.",
02616     "You have a tendency to feel you are superior to most computers.",
02617     "The first 90% of a project takes 90% of the time.",
02618     "The last 10% of a project takes 90% of the time.",
02619     "Any given program, when running, is obsolete.",
02620     "Any given program costs more and takes longer.",
02621     "If a program is useful, it will have to be changed.", // 80
02622     "If a program is useless, it will have to be documented.",
02623     "Any given program will expand to fill all available memory.",
02624     "The value of a program is porportional to the weight of its output.",
02625     "Program complexity grows until it exceeds the capability\n\tof the programmer who must maintain it.",
02626     "Make it possible for programmers to write programs in English\n\tand you will find that programmers cannot write in English.",
02627     "On a helmet mounted mirror used by US cyclists:\n\t\"REMEMBER, OBJECTS IN THE MIRROR ARE ACTUALLY BEHIND YOU.\"",
02628     "On a New Zealand insect spray\n\t\"THIS PRODUCT NOT TESTED ON ANIMALS.\"",
02629     "In some countries, on the bottom of Coke bottles:\n\t\"OPEN OTHER END.\"",
02630     "On a Sears hairdryer:\n\t\"DO NOT USE WHILE SLEEPING.\"",
02631     "On a bar of Dial soap:\n\t\"DIRECTIONS - USE LIKE REGULAR SOAP.\"", // 90
02632     "On a Korean kitchen knife:\n\t\"WARNING KEEP OUT OF CHILDREN.\"",
02633     "On an American Airlines packet of nuts:\n\t\"INSTRUCTIONS - OPEN PACKET, EAT NUTS.\"",
02634     "On a child's superman costume:\n\t\"WEARING OF THIS GARMENT DOES NOT ENABLE YOU TO FLY.\"",
02635     "Looking at wrapped interferograms is like running in circles.",
02636     "Conversation equals conservation (proposition with thesis Ramon Hanssen).",
02637     "Unlikely children's book title:\n\t\"Curios George and the High-Voltage Fence\".",
02638     "Unlikely children's book title:\n\t\"Controlling the Playground: Respect through Fear\".",
02639     "Unlikely children's book title:\n\t\"Mr Fork and Ms Electrical Outlet Become Friends\".",
02640     "Unlikely children's book title:\n\t\"Strangers Have the Best Candy\".",
02641     "Unlikely children's book title:\n\t\"Daddy Drinks Because You Cry\".", // 100
02642     "Stanley looked quite bored and somewhat detached, but then penguins often do.",
02643     "Trouble with Windows? Reboot. Trouble with Unix? Be root.",
02644     "The good thing about standards is that there are so many to choose from.",
02645     "You can always count on Americans to do the right thing,\n\tafter they have exhausted all the alternatives.",
02646     "Where there is matter, there is geometry.",
02647     "The simplest schoolboy is now familiar with facts for which Archimedes\n\twould have sacrificed his life.",
02648     "Get the fastest fourier transform in the west at http://www.fftw.org/",
02649     "See http://www.gnu.org/ for compiler updates, etc.",
02650     "You can only find truth with logic if you have already found truth without it.",
02651     "Everything should be made as simple as possible, but not simpler.", // 110
02652     "Seek simplicity, and distrust it.",
02653     "Descartes commanded the future from his study more\n\tthan Napoleon from the throne.",
02654     "Say what you know, do what you must, come what may.",
02655     "To the devil with those who published before us.",
02656     "The words figure and fictitious both derive from\n\tthe same Latin root, fingere. Beware!",
02657     "The best material model of a cat is another, or preferably the same, cat.",
02658     "He who loves practice without theory is like the sailor who boards ship\n\twithout a rudder and compass.",
02659     "Nature uses as little as possible of anything.",
02660     "Mathematics is not yet ready for such problems.",
02661     "You can only find truth with logic if you have already found truth without it.", // 120
02662     "Natural selection is a mechanism for generating an exceedingly high\n\tdegree of improbability.",
02663     "Similar figures exist only in pure geometry.",
02664     "Writing briefly takes far more time than writing at length.",
02665     "Like the crest of a peacock so is mathematics at the head of all knowledge.",
02666     "The real danger is not that computers will begin to think like men,\n\tbut that men will begin to think like computers.",
02667     "Why did the blond stare at the orange juice?\n\tit said concentrate.",
02668     "Hofstadter's Law: It always takes longer than you expect,\neven when you take into account Hofstadter's Law.",
02669     "It can be of no practical use to know that Pi is irrational, but if we\n\tcan know, it surely would be intolerable not to know.",
02670     "Life is a complex, it has real and imaginary parts.",
02671     "Beauty can be perceived but not explained.", // 130
02672     "Programming is like sex: one mistake and you have to\n\tsupport it for the rest of your life. [Michael Sinz]",
02673     "I wish you were here and I was there [me].",
02674     "In mathematics you dont understand things, you just get used to them [Neumann].",
02675     "A man is incomplete until he is married. After that, he is finished [Zsa Zsa Gabor].",
02676     "Unlikely children's book title:\n\t\"The Kids' Guide to Hitchhiking\".", // 138
02677     "Unlikely children's book title:\n\t\"Whining, Kicking and Crying to Get Your Way\".",
02678     "Unlikely children's book title:\n\t\"Dads New Wife Robert\".",
02679     "Unlikely children's book title:\n\t\"The Little Sissy Who Snitched\".",
02680     ""};
02681 
02682   // ______ Get random seed and print quote +endl ______
02683   const int32 NUMQUOTES = 141; 
02684   const int32 seed      = time(NULL);
02685   const int32 quotenumber = seed%NUMQUOTES;
02686   cerr << "\n  ..." << QUOTES[quotenumber] << "\n\n";
02687   } // END quote
02688 
02689 
02690 
02691 /****************************************************************
02692  @brief  copyright echos copyriht info
02693  * copyright                                                    *
02694  * BK 15-Nov-2000                                               *
02695  ****************************************************************/
02696 void copyright()
02697   {
02698   TRACE_FUNCTION("copyright");
02699   cerr << "\n\t ***     **     **   *    **"
02700        << "\n\t *  *   *  *   *     *   *"
02701        << "\n\t *  *   *  *   *     *    *"
02702        << "\n\t *  *   *  *   *     *     *"
02703        << "\n\t ***     **    *     *   **\n"
02704        << "\n"
02705        << "\n"
02706        << "COPYRIGHT NOTICE:\n"
02707        << "-----------------\n"
02708        << " Doris program is free software; you can redistribute it and/or modify\n"
02709        << "it under the terms of the GNU General Public License as published by\n"
02710        << "the Free Software Foundation; either version 2 of the License, or\n"
02711        << "(at your option) any later version.\n"
02712        << "\n"
02713        << "Doris is distributed in the hope that it will be useful,\n"
02714        << "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
02715        << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
02716        << "GNU General Public License for more details.\n"
02717        << "\n"
02718        << "You should have received a copy of the GNU General Public License\n"
02719        << "along with this program; if not, write to the Free Software\n"
02720        << "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n"
02721        << "--- (END COPYRIGHT NOTICE) ---\n"
02722        << "\n"
02723        << "Publications that contain results produced by the Doris software should \n"
02724        << "contain an acknowledgment. (For example: The interferometric processing \n"
02725        << "was performed using the freely available Doris software package developed \n"
02726        << "by the Delft Institute for Earth-Oriented Space Research (DEOS), Delft \n"
02727        << "University of Technology, or include a reference to: Bert Kampes and \n"
02728        << "Stefania Usai. \"Doris: The Delft Object-oriented Radar Interferometric \n"
02729        << "software.\" In: proceedings 2nd ITC ORS symposium, August 1999. (cdrom)).\n"
02730        << "\n[Written by Bert Kampes, (c)1998-2003].\n\n";
02731 /*
02732        << "COPYRIGHT NOTICE:\n"
02733        << "Doris is a scientific-purpose software and cannot be commercialized, nor \n"
02734        << "can parts or products of it be commercialized. Parties interested in using \n"
02735        << "Doris or its products for any commercial purposes are requested to contact \n"
02736        << "Prof. Dr. Roland Klees of DEOS (r.klees@citg.tudelft.nl)\n"
02737        << "\n"
02738        << "Our version of the software is the only official one. Please do not \n"
02739        << "distribute the Doris software to third parties, instead refer to the Doris \n"
02740        << "home page. This in order to guarantee uniformity in the distribution of \n"
02741        << "updates and information.\n"
02742        << "\n"
02743        << "Delft University of Technology is not responsible for any damage caused by \n"
02744        << "errors in the software or the documentation.\n"
02745        << "\n"
02746        << "Users are very welcome to extend the capabilities of the Doris software by \n"
02747        << "implementing new algorithms or improving the existing ones. It is intended \n"
02748        << "that if new software is developed based on Doris, that this also is made \n"
02749        << "available for free to the other users (through us).\n"
02750        << "\n"
02751        << "We would appreciate if any addition or modification of the software would \n"
02752        << "be announced first to us, so that it can be included in the official \n"
02753        << "(next) version of the software.\n"
02754        << "\n"
02755        << "Publications that contain results produced by the Doris software should \n"
02756        << "contain an acknowledgment. (For example: The interferometric processing \n"
02757        << "was performed using the freely available Doris software package developed \n"
02758        << "by the Delft Institute for Earth-Oriented Space Research (DEOS), Delft \n"
02759        << "University of Technology, or include a reference to: Bert Kampes and \n"
02760        << "Stefania Usai. \"Doris: The Delft Object-oriented Radar Interferometric \n"
02761        << "software.\" In: proceedings ITC 2nd ORS symposium, August 1999. (cdrom)).\n"
02762        << "\n[Written by Bert Kampes, (c)1998-2003].\n\n";
02763 */
02764   exit(0);
02765   } // END copyright
02766 
02767 
02768 
02769 
02770 /****************************************************************
02771  @brief  preview generates cpxfiddle scripts for quicklooks
02772  @param  previewflag etc.
02773  * preview                                                      *
02774  * create scritps to generate sunraster files.                  *
02775  * previewflag set by PREVIEW card:                             *
02776  * i.e.: 0: OFF; 1:ON (generate sh script); 2:xv (call shscript)*
02777  * BK 07-Feb-2002                                               *
02778  ****************************************************************/
02779 void preview(
02780         int32 previewflag,
02781         int32 width,
02782         int32 formatflag,
02783         char *infile,
02784         char *outfile,
02785         char *opts)
02786   {
02787   TRACE_FUNCTION("preview (BK 07-Feb-2002)");
02788   DEBUG << "previewflag: " << previewflag;
02789   DEBUG.print();
02790   if (previewflag==0)
02791     {
02792     DEBUG.print("NO preview requested.");
02793     return;
02794     }
02795   char scriptname[127];
02796   //strcpy(scriptname,outfile);
02797   strcpy(scriptname,"./");// prevent error if "." is not in path (unix/linux/cygwin slash)
02798   strcat(scriptname,outfile);
02799   strcat(scriptname,".sh");
02800   INFO.reset();// be sure to get rid of old chars before system call
02801   if (previewflag<3)
02802     {
02803     PROGRESS.print("Start PREVIEW generation.");
02804     // ______ find out format of inputfile ______
02805     switch (formatflag)
02806       {
02807       case FORMATCR4:
02808         {
02809         INFO << "cpxfiddle -w " << width << " " << opts;
02810         INFO << " -f cr4 -l1 -p1 -P" << width;// -L?
02811         break;
02812         }
02813       case FORMATCI2:
02814         {
02815         INFO << "cpxfiddle -w " << width << " " << opts;
02816         INFO << " -f ci2 -l1 -p1 -P" << width;// -L?
02817         break;
02818         }
02819       // ___ trick cpxfiddle, make it think this complex ___
02820       // ___ width is in complex pixels, but hgt is band interleaved ___
02821       // ___ read second band (phase) as part of complex file___
02822       // ___ -q normal must be set to trick cpxfiddle ___
02823       case FORMATHGT:
02824         {
02825         PROGRESS.print(
02826           "Trying to trick cpxfiddle for HGT format (should work)");
02827         int32 start_band_2 = int32(floor(width/2.0)+2.0);// (start at 1)
02828         DEBUG << "start of second band for cpxfiddle: " << start_band_2;
02829         DEBUG.print();
02830         INFO << "cpxfiddle -w " << width << " " << opts;
02831         INFO << " -f cr4 -l1 -p" << start_band_2 << " -P" << width;
02832         break;
02833         }
02834       // ___ trick cpxfiddle, make it think this complex ___
02835       // ___ this may not always work (in case of odd width)___
02836       // ___ -q normal must be set to trick cpxfiddle ___
02837       case FORMATR4:
02838         {
02839         // [added real4 option to cpxfiddle BK 13-Apr-2003]
02840         PROGRESS.print(
02841           "Trying to trick cpxfiddle for REAL4 format (should work)");
02842         INFO << "cpxfiddle -w " << width << " " << opts;
02843         INFO << " -f r4 -l1 -p1 -P" << width;
02844         break;
02845         }
02846       default:
02847         PRINT_ERROR("PREVIEW generation: Unknown formatflag.")
02848         throw(unhandled_case_error);// exit
02849       }
02850     INFO << " " << infile << " > " << outfile << ends;
02851     INFO.print("With following command the SUNraster image can be generated again.");
02852     INFO.print(INFO.get_str());// buffer should not be touched by previous print
02853     // ______ Create the script ______ //
02854     ofstream scriptfile;
02855     scriptfile.open(scriptname, ios::out);
02856     bk_assert(scriptfile,scriptname,__FILE__,__LINE__);
02857     scriptfile << "#!/bin/sh\n"
02858                << "# Doris software generated script to generate preview.\n"
02859                << "# Program cpxfiddle is used to create a SUNraster file\n"
02860                << "# from a complex input file.  (For unwrapped interferograms\n"
02861                << "# we try to fool cpxfiddle.)\n"
02862                << "# Send comments to: Bert Kampes, b.m.kampes@lr.tudelft.nl\n"
02863                << "# to run, type at prompt: " << scriptname << endl
02864                << INFO.get_str() << endl;
02865     if (previewflag==2)
02866       {
02867       scriptfile << "xv " << outfile << endl;
02868       }
02869     scriptfile << "# EOF\n";
02870     scriptfile.close();
02871     // ______ Make file executable via system call to chmod ______ //
02872     //omem << "chmod +x " << scriptname << endl << ends;
02873     //system(MESSAGE);
02874     DEBUG << "chmod +x " << scriptname << endl << ends;
02875     DEBUG.print();// rewinds buffer (for next call)
02876     system(DEBUG.get_str());
02877     // ______ Actual make the call ______ //
02878     //omem << "sh " << scriptname << "&" << endl << ends;
02879     //omem.seekp(0);
02880     //omem << scriptname << "&" << endl << ends;
02881     //system(MESSAGE);
02882     INFO.reset();// make sure buffer is empty before system call
02883     INFO << scriptname << "&" << endl << ends;
02884     system(INFO.get_str());
02885     INFO.print();// resets buffer (for next call)
02886     PROGRESS << "SUNraster file created of: " << infile 
02887            << " (see also file: " << scriptname << ")";
02888     PROGRESS.print();
02889     }
02890   else
02891     {
02892     PRINT_ERROR("PREVIEW generation: Unknown option.")
02893     throw(unhandled_case_error);// exit
02894     }
02895   } // END preview
02896 
02897 

Generated on Fri Apr 22 15:57:57 2005 for Doris by doxygen 1.3.6