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

ioroutines.cc

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999-2003 Bert Kampes
00003  * Copyright (c) 1999-2003 Delft University of Technology, The Netherlands
00004  *
00005  * This file is part of Doris, the Delft o-o radar interferometric software.
00006  *
00007  * Doris program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * Doris is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * Publications that contain results produced by the Doris software should
00022  * contain an acknowledgment. (For example: The interferometric processing
00023  * was performed using the freely available Doris software package developed
00024  * by the Delft Institute for Earth-Oriented Space Research (DEOS), Delft
00025  * University of Technology, or include a reference to: Bert Kampes and
00026  * Stefania Usai. \"Doris: The Delft Object-oriented Radar Interferometric
00027  * software.\" In: proceedings 2nd ITC ORS symposium, August 1999. (cdrom)).
00028  *
00029  */
00030 /****************************************************************
00031  * $Source: /users/kampes/DEVELOP/DORIS/doris/src/RCS/ioroutines.cc,v $
00032  * $Revision: 3.20 $
00033  * $Date: 2005/04/11 13:47:45 $
00034  * $Author: kampes $
00035  *
00036  * implementation of io routines.
00037  ****************************************************************/
00038 
00039 
00040 #include "constants.hh"         // global constants
00041 #include "ioroutines.hh"        // header of this file
00042 #include "conversion.hh"        // pol2xyz, deg2rad, ...
00043 #include "refsystems.hh"        // for axis ellipsoid
00044 #include "utilities.hh"         // ispower2
00045 #include "slcimage.hh"          // my slc image class
00046 #include "productinfo.hh"       // my 'products' class
00047 #include "exceptions.hh"                 // my exceptions class
00048 
00049 
00050 
00051 #include <fstream>              // for file streams
00052 #include <strstream>            // for memory stream
00053 #include <cstring>              // for strcmp etc.
00054 #include <iomanip>              // for setprecision etc.
00055 #include <cstdlib>              // exit
00056 #include <cctype>               // isspace()
00057 #include <cstdarg>              // for ellipses in functions
00058 #include <algorithm>            // generic max
00059 #include <cstdio>               // some compilers, remove function
00060 #include <ctime>                // some compilers, clock functions
00061 char *strptime(const char *s, const char  *format,  struct tm *tm);
00062 
00063 
00064 
00065 
00066 /****************************************************************
00067  *    printcpu                                                  *
00068  *                                                              *
00069  * Prints cpu and wallclock to screen as DEBUG                  *
00070  * Printcpu(true) should be called at start main.               *
00071  *                                                              *
00072  * input:                                                       *
00073  *  - bool init: first time true, default false                 *
00074  * output:                                                      *
00075  *  - screen: cpu and wallclock time                            *
00076  *                                                              *
00077  *    Bert Kampes, 11-Dec-1998                                  *
00078  ****************************************************************/ 
00079 void printcpu(
00080         bool init)
00081   {
00082   TRACE_FUNCTION("printcpu (BK 11-Dec-1998)")
00083   time_t nseconds = time(NULL);
00084   char *tijd = ctime(&nseconds);                      // includes newline
00085   INFO << "Current time: " << tijd;
00086   INFO.print();
00087 
00088   //static int32 cput_last   = clock();
00089   //static real4 cput_total  = 0.;
00090   //int32        cput_process = clock() - cput_last;
00091   //static int32 wct_total   = 0;               // wallclock, init at first call
00092   //static int32 wct_last    = time(NULL);      // wallclock, init at first call
00093   //int32        wct_process = time(NULL) - wct_last;
00094 
00095   static clock_t cput_last    = clock();// init only first call
00096   clock_t        cput_process = clock() - cput_last;
00097   static real4   cput_total   = 0.0;// init only first call
00098 
00099   static time_t wct_last    = time(NULL);       // wallclock, init at first call
00100   time_t        wct_process = time(NULL) - wct_last;
00101   static int32  wct_total   = 0;                // wallclock, init at first call
00102 
00103   if (init)                                     // return if only initialization
00104     return;
00105 
00106   cput_total += (real4(cput_process))/real4(CLOCKS_PER_SEC);
00107   cput_last   = clock();
00108   //wct_total  += wct_process;
00109   wct_total  += int32(wct_process);
00110   wct_last    = time(NULL);
00111 
00112   const int32 cputmin = int32(floor(cput_total/60));
00113   const real4 cputsec = cput_total - cputmin*60;
00114   DEBUG << " cputime used for process: \t"
00115        <<  setw(6) << real4(cput_process)/real4(CLOCKS_PER_SEC)
00116        << " sec (total: " 
00117        << setw(4) << cputmin << " min "
00118        << setw(3) << cputsec << " sec)\n"
00119        << "\t   wallclock: \t\t\t" 
00120        << setw(6) << wct_process
00121        << " sec (total: " 
00122        << setw(4) << wct_total/60 << " min "
00123        << setw(3) << wct_total%60 << " sec)";
00124   DEBUG.print();
00125   cerr << "total cpu: \t"
00126        << setw(4) << cputmin << " min "
00127        << setw(3) << cputsec << " sec\n";
00128   } // END printcpu
00129 
00130 
00131 
00132 /****************************************************************
00133  *    inittest                                                  *
00134  *                                                              *
00135  * Some initial tests and info for portability.                 *
00136  *                                                              *
00137  * input:                                                       *
00138  *  - void                                                      *
00139  * output:                                                      *
00140  *  - void, exits if trouble                                    *
00141  *                                                              *
00142  *    Bert Kampes, 11-Dec-1998                                  *
00143  ****************************************************************/
00144 void inittest()
00145   {
00146   TRACE_FUNCTION("inittest (BK 11-Dec-1998)")
00147   // ______ Some info ______
00148   #ifdef __DEBUG
00149     DEBUG.print("\"__DEBUG\"                 defined (extra verbose)");
00150   #else
00151     DEBUG.print("\"__DEBUG\"                 not defined (extra verbose)");
00152   #endif
00153   #ifdef __DEBUGMAT1
00154     DEBUG.print("\"__DEBUGMAT1\"             defined (range checking matrix class)");
00155   #else
00156     DEBUG.print("\"__DEBUGMAT1\"             not defined (range checking matrix class)");
00157   #endif
00158   #ifdef __DEBUGMAT2
00159     DEBUG.print("\"__DEBUGMAT2\"             defined (verbose matrix class)");
00160   #else
00161     DEBUG.print("\"__DEBUGMAT2\"             not defined (verbose matrix class)");
00162   #endif
00163   #ifdef __USE_FFTW_LIBRARY__
00164     DEBUG.print("\"__USE_FFTW_LIBRARY__\"    defined (using fftw routines)");
00165   #else
00166     DEBUG.print("\"__USE_FFTW_LIBRARY__\"    not defined (not using fftw routines)");
00167   #endif
00168   #ifdef __USE_VECLIB_LIBRARY__
00169     DEBUG.print("\"__USE_VECLIB_LIBRARY__\"  defined (using library routines)");
00170   #else
00171     DEBUG.print("\"__USE_VECLIB_LIBRARY__\"  not defined (using internal routines)");
00172   #endif
00173   #ifdef __USE_LAPACK_LIBRARY__
00174     DEBUG.print("\"__USE_LAPACK_LIBRARY__\"  defined (using library routines)");
00175   #else
00176     DEBUG.print("\"__USE_LAPACK_LIBRARY__\"  not defined (using internal routines)");
00177   #endif
00178   #ifdef __GplusplusCOMPILER__
00179     DEBUG.print("\"__GplusplusCOMPILER__\"   defined (GNU c++ compiler)");
00180     WARNING.print("NOT USED ANYMORE. since v3.8");
00181   #else
00182     DEBUG.print("\"__GplusplusCOMPILER__\"   not defined (no GNU c++ compiler)");
00183   #endif
00184   #ifdef __GNUC__
00185     DEBUG << "\"__GNUC__\":               " << __GNUC__;
00186     DEBUG.print();
00187   #endif
00188   #ifdef __GNUC_MINOR__
00189     DEBUG << "\"__GNUC_MINOR__\":         " << __GNUC_MINOR__;
00190     DEBUG.print();
00191   #endif
00192   // ___ Testing endianness ___
00193   DEBUG.print("Testing endianness.");
00194   int i;
00195   int littleendian=0;// thus big assumed
00196   char test[64]={0};
00197   for (i=0;i<32;i++) test[i]=0;
00198   test[0]=0x01;
00199   if (0x0001==*(int *)(&test[0])) littleendian=1;
00200   #ifdef __X86PROCESSOR__
00201     DEBUG.print("\"__X86PROCESSOR__\"        defined (little Endian machine)");
00202     if (littleendian == 1) 
00203       INFO.print("Little Endian machine defined and this is correct.");
00204     else
00205       WARNING.print("Little Endian machine defined and this is NOT correct.");
00206   #else
00207     DEBUG.print("\"__X86PROCESSOR__\"        not defined (big Endian machine)");
00208     if (littleendian == 0) 
00209       INFO.print("Big Endian machine defined and this is correct.");
00210     else
00211       WARNING.print("Big Endian machine defined and this is NOT correct.");
00212   #endif
00213 
00214   #ifdef __NO_STRPTIME
00215     DEBUG.print("\"__NO_STRPTIME\"           defined (using internal routine)");
00216   #else
00217     DEBUG.print("\"__NO_STRPTIME\"           not defined (using library routine)");
00218   #endif
00219   // ___ Testing strptime function ___
00220   DEBUG.print("Testing strptime function.");
00221   struct tm tm_ref;
00222   char utc_ref[100] = "05-JAN-1985 01:02:03.000";
00223   strptime(utc_ref,"%d-%b-%Y %T",&tm_ref);
00224   int status = 0;
00225   if (tm_ref.tm_mday != 5)  status=1;
00226   if (tm_ref.tm_mon  != 0)  status=1;
00227   if (tm_ref.tm_year != 85) status=1;
00228   if (tm_ref.tm_hour != 1)  status=1;
00229   if (tm_ref.tm_min  != 2)  status=1;
00230   if (tm_ref.tm_sec  != 3)  status=1;
00231   if (status == 0) 
00232     INFO.print("strptime function works fine.");
00233   else
00234     WARNING.print("strptime function seems NOT TO BE OK.");
00235 
00236 
00237   // ______ Some info ______
00238   if (sizeof(int16) != 2) 
00239     {
00240     PRINT_ERROR("code: 900: sizeof int16(short) != 2: see typedefs in constants.h")
00241     throw(some_error);
00242     }
00243   if (sizeof(int32) != 4) 
00244     {
00245     PRINT_ERROR("code: 900: sizeof int32(int) != 4: see typedefs in constants.h")
00246     throw(some_error);
00247     }
00248   if (sizeof(uint) != 4) 
00249     {
00250     PRINT_ERROR("code: 900: sizeof uint(unsigned int) != 4: see typedefs in constants.h")
00251     throw(some_error);
00252     }
00253   if (sizeof(real8) != 8) 
00254     {
00255     PRINT_ERROR("code: 900: sizeof real8(double) != 8: see typedefs in constants.h")
00256     throw(some_error);
00257     }
00258   if (sizeof(real4) != 4) 
00259     {
00260     PRINT_ERROR("code: 900: sizeof real4(float) != 4: see typedefs in constants.h")
00261     throw(some_error);
00262     }
00263   if (sizeof(compli16) != 4) 
00264     {
00265     PRINT_ERROR("code: 900: sizeof compli16(complex short) != 4: see typedefs in constants.h")
00266     throw(some_error);
00267     }
00268   if (sizeof(compli32) != 8) 
00269     {
00270     PRINT_ERROR("code: 900: sizeof compli32(complex int) != 8: see typedefs in constants.h")
00271     throw(some_error);
00272     }
00273   if (sizeof(complr4) != 8) 
00274     {
00275     PRINT_ERROR("code: 900: sizeof complr4(complex float) != 8: see typedefs in constants.h")
00276     throw(some_error);
00277     }
00278   if (sizeof(complr8) != 16) 
00279     {
00280     PRINT_ERROR("code: 900: sizeof complr16(complex double) != 16: see typedefs in constants.h")
00281     throw(some_error);
00282     }
00283   if (int32(7.5) != 7) 
00284     {
00285     PRINT_ERROR("code: 900: it is assumed that int(7.5)==7")
00286     throw(some_error);
00287     }
00288   if (complr4(1.1) != complr4(1.1,0))
00289     {
00290     PRINT_ERROR("code: ???: it is assumed that complr4(7.5) == 7.5 + 0.0i")
00291     throw(some_error);
00292     }
00293   DEBUG.print("test somewhere also memory,diskspace.");
00294 
00295   // ___ Testing cn ___
00296   DEBUG.print("Testing coordinate class:");
00297   cn P; P.test();
00298   // ___ Testing window ___
00299   DEBUG.print("Testing window class:");
00300   window W; W.test();
00301   // ___ Testing ellips ___
00302   DEBUG.print("Testing ellips class:");
00303   input_ell E; E.test();
00304   } // END inittest
00305 
00306 
00307 /****************************************************************
00308  *    doinitwrite                                               *
00309  *                                                              *
00310  * Decides to call initwrite or not necessary because           *
00311  *  no call for image (slave or master).                        *
00312  * if something will be processed then true                     *
00313  * input:                                                       *
00314  *  - input processes                                           *
00315  *  - imageid: =2 master, =3 slave                              *
00316  * output:                                                      *
00317  *  - bool true or false                                        *
00318  * future: THIS ROUTINE SHOULD BE UPDATED AS WE GO ALONG        *
00319  *                                                              *
00320  *    Bert Kampes, 15-Dec-1998                                  *
00321  ****************************************************************/
00322 bool doinitwrite(
00323         input_gen &generalinput,
00324         int16 imageid)
00325   {
00326   TRACE_FUNCTION("doinitwrite (BK 15-Dec-1998)")
00327   // ______Check input and decide (normally true)______
00328   if (imageid == MASTERID)
00329     {
00330     if (!(generalinput.process[pr_m_readfiles] ||
00331           generalinput.process[pr_m_crop]      ||
00332 //____RaffaeleNutricato START MODIFICATION SECTION 1
00333           generalinput.process[pr_m_oversample] || 
00334 //____RaffaeleNutricato END MODIFICATION SECTION 1
00335           generalinput.process[pr_m_porbits]   ||
00336           generalinput.process[pr_m_filtazi]   ||
00337           generalinput.process[pr_m_filtrange] ||
00338           generalinput.process[pr_m_EXTRA]        ))
00339       return false;
00340     }
00341   else if (imageid == SLAVEID)
00342     {
00343     if (!(generalinput.process[pr_s_readfiles] ||
00344           generalinput.process[pr_s_crop]      ||
00345 //____RaffaeleNutricato START MODIFICATION SECTION 2
00346           generalinput.process[pr_s_oversample] || 
00347 //____RaffaeleNutricato END MODIFICATION SECTION 2
00348           generalinput.process[pr_s_porbits]   ||
00349           generalinput.process[pr_s_resample]  ||
00350           generalinput.process[pr_s_filtazi]   ||
00351           generalinput.process[pr_s_filtrange] ||
00352           generalinput.process[pr_s_EXTRA]        ))
00353       return false;
00354     }
00355   else if (imageid == INTERFID)
00356     {
00357     if (!(generalinput.process[pr_i_coarse]      ||
00358           generalinput.process[pr_i_coarse2]     ||
00359           generalinput.process[pr_i_fine]        ||
00360           generalinput.process[pr_i_coregpm]     ||
00361           generalinput.process[pr_i_comprefpha]  ||
00362           generalinput.process[pr_i_subtrrefpha] ||
00363           generalinput.process[pr_i_comprefdem]  ||
00364           generalinput.process[pr_i_subtrrefdem] ||
00365           generalinput.process[pr_i_interfero]   ||
00366           generalinput.process[pr_i_coherence]   ||
00367           generalinput.process[pr_i_filtphase]   ||
00368           generalinput.process[pr_i_unwrap]      ||
00369           generalinput.process[pr_i_slant2h]     ||
00370           generalinput.process[pr_i_geocoding]   ||
00371           generalinput.process[pr_i_dinsar]      ||
00372           generalinput.process[pr_i_EXTRA2]        ))
00373       return false;
00374     }
00375   else
00376     {
00377     PRINT_ERROR("code 901: wrong input.")
00378     throw(some_error);
00379     }
00380   return true;
00381   }  // END doinitwrite
00382 
00383 
00384 /****************************************************************
00385  *    initwrite                                                 *
00386  *                                                              *
00387  * Writes some general info to logfile and resultfile           *
00388  *                                                              *
00389  * input:                                                       *
00390  *  - file: name of file                                        *
00391  *  - fileid:                                                   *
00392  *      1:logfile, 2:masterres, 3:slaveres, 4:interferogram     *
00393  * output:                                                      *
00394  *  - void, file is updated                                     *
00395  *                                                              *
00396  *    Bert Kampes, 11-Dec-1998                                  *
00397  ****************************************************************/
00398 void initwrite(
00399         const char* file,
00400         int16 fileid)
00401   {
00402   TRACE_FUNCTION("initwrite (BK 11-Dec-1998)")
00403   #ifndef SWNAME
00404   DEBUG.print("SWNAME NOT DEFINED.");
00405   #endif
00406   #ifndef SWVERSION
00407   DEBUG.print("SWVERSION NOT DEFINED.");
00408   #endif
00409 
00410 
00411 // ______Initialize time______
00412 // #ifdef __GplusplusCOMPILER__
00413 // g++ 2.7.2.2 wants int, though long is exactly same
00414 // use __GNUC__ = 2, __GNUC_MINOR__ = 7, __GNUG__ = 2
00415 // can be seen with g++ -v dummy.c
00416 //#if __GNUC_MINOR__ == 7
00417 //  int32 nseconds = time(NULL);
00418 //#else // at least version 2.95.2 and HP aCC
00419 //  long nseconds = time(NULL);
00420 //#endif
00421   time_t nseconds = time(NULL);
00422   char *tijd = ctime(&nseconds);                      // includes newline
00423 
00424 // ______Write logfile if not exists______
00425   bool ofilenew = true;
00426   if (existed(file)) ofilenew = false;
00427 
00428   ofstream ofile;
00429   ofile.open(file, ios::out | ios::app);
00430   bk_assert(ofile,file,__FILE__,__LINE__);
00431 
00432 
00433   DEBUG.print("Writing (updating) of file (initwrite).");
00434   if (ofilenew)
00435     {
00436     ofile
00437           << "=====================================================";
00438     switch (fileid)
00439       {
00440       case LOGID:
00441         ofile << "\n LOGFILE:                  " << file;
00442         break;
00443       case MASTERID:
00444         ofile << "\n MASTER RESULTFILE:        " << file;
00445         break;
00446       case SLAVEID:
00447         ofile << "\n SLAVE RESULTFILE:         " << file;
00448         break;
00449       case INTERFID:
00450         ofile << "\n INTERFEROGRAM RESULTFILE: " << file;
00451         break;
00452       default:
00453         PRINT_ERROR("panic: code 901:initwrite, internal fileid not ok!")
00454         throw(unhandled_case_error);
00455       }
00456     ofile << "\n\nCreated by:"
00457           << "\nInSAR Processor:        " << SWNAME
00458           << "\nVersion:                " << SWVERSION
00459     #if defined (__DEBUG) || defined (__DEBUGMAT1) || defined (__DEBUGMAT2)
00460           << " (debug)"
00461     #else
00462           << " (optimal)"
00463     #endif
00464     #ifdef __USE_FFTW_LIBRARY__
00465           << "\nFFTW library:           " << "used"
00466     #else
00467           << "\nFFTW library:           " << "not used"
00468     #endif
00469     #ifdef __USE_VECLIB_LIBRARY__
00470           << "\nVECLIB library:         " << "used"
00471     #else
00472           << "\nVECLIB library:         " << "not used"
00473     #endif
00474     #ifdef __USE_LAPACK_LIBRARY__
00475           << "\nLAPACK library:         " << "used"
00476     #else
00477           << "\nLAPACK library:         " << "not used"
00478     #endif
00479           << "\nCompiled at:            " << __DATE__ << " " << __TIME__;
00480     #ifdef __GNUC__
00481       ofile << "\nBy GNU gcc:             " << __GNUC__;
00482       #ifdef __GNUC_MINOR__
00483         ofile << "." << __GNUC_MINOR__;
00484         #ifdef __GNUG__
00485           ofile << "." << __GNUG__;
00486         #endif
00487       #endif
00488     #endif
00489     ofile << "\nFile creation at:       " << tijd
00490           << "\n --------------------------------------------------"
00491           << "\n| Delft institute of Earth-oriented Space research |"
00492           << "\n|        Delft University of Technology            |"
00493           << "\n|       http://www.geo.tudelft.nl/doris/           |"
00494           << "\n|                                                  |"
00495           << "\n| Author: Bert Kampes                              |"
00496           << "\n --------------------------------------------------\n\n";
00497 
00498 // ======Write process control in result file======
00499     switch (fileid)
00500       {
00501 
00502 // ______These may not be changed without changing check process control______
00503       case MASTERID:
00504         ofile << "\nStart_process_control\n"
00505               << processcontrol[pr_m_readfiles] <<   " \t\t0\n"
00506               << processcontrol[pr_m_porbits]   <<     " \t0\n"
00507               << processcontrol[pr_m_crop]      << " \t\t\t0\n"
00508 //____RaffaeleNutricato START MODIFICATION SECTION 3
00509               << processcontrol[pr_m_oversample] <<   " \t\t0\n" 
00510 //____RaffaeleNutricato END MODIFICATION SECTION 3
00511               << processcontrol[pr_m_filtazi]   <<   " \t\t0\n"
00512               << processcontrol[pr_m_filtrange] <<   " \t\t0\n"
00513               << processcontrol[pr_m_EXTRA]     <<   " \t\t0\n"
00514               << "End_process_control\n";
00515         break;
00516 
00517 // ______These may not be changed without changing check process control______
00518       case SLAVEID:
00519         ofile << "\nStart_process_control\n"
00520               << processcontrol[pr_s_readfiles] <<   " \t\t0\n"
00521               << processcontrol[pr_s_porbits]   <<     " \t0\n"
00522               << processcontrol[pr_s_crop]      << " \t\t\t0\n"
00523 //____RaffaeleNutricato START MODIFICATION SECTION 4
00524               << processcontrol[pr_s_oversample] <<   " \t\t0\n" 
00525 //____RaffaeleNutricato END MODIFICATION SECTION 4
00526               << processcontrol[pr_s_resample]  <<   " \t\t0\n"
00527               << processcontrol[pr_s_filtazi]   <<   " \t\t0\n"
00528               << processcontrol[pr_s_filtrange] <<   " \t\t0\n"
00529               << processcontrol[pr_s_EXTRA]     <<   " \t\t0\n"
00530               << "End_process_control\n";
00531         break;
00532 
00533 // ______These may not be changed without changing check process control______
00534       case INTERFID:
00535         ofile << "\nStart_process_control\n"
00536               << processcontrol[pr_i_coarse]      <<   " \t\t0\n"
00537               << processcontrol[pr_i_coarse2]     <<   " \t\t0\n"
00538               << processcontrol[pr_i_fine]        <<   " \t\t0\n"
00539               << processcontrol[pr_i_coregpm]     <<   " \t\t0\n"
00540               << processcontrol[pr_i_interfero]   <<   " \t\t0\n"
00541               << processcontrol[pr_i_coherence]   <<     " \t0\n"
00542               << processcontrol[pr_i_comprefpha]  <<   " \t\t0\n"
00543               << processcontrol[pr_i_subtrrefpha] <<   " \t\t0\n"
00544               << processcontrol[pr_i_comprefdem]  <<   " \t\t0\n"
00545               << processcontrol[pr_i_subtrrefdem] <<   " \t\t0\n"
00546               << processcontrol[pr_i_filtphase]   <<   " \t\t0\n"
00547               << processcontrol[pr_i_unwrap]      <<   " \t\t0\n"
00548               << processcontrol[pr_i_slant2h]     <<   " \t\t0\n"
00549               << processcontrol[pr_i_geocoding]   <<   " \t\t0\n"
00550               << processcontrol[pr_i_dinsar]      <<   " \t\t\t0\n"
00551               << processcontrol[pr_i_EXTRA2]      <<   " \t\t0\n"
00552               << "End_process_control\n";
00553         break;
00554 
00555       default:
00556         ; //do nothing
00557       } // switch fileid
00558     }
00559 
00560   else                                                          // file already existed
00561     {
00562     ofile << endl << endl
00563           << "   *====================================================================*\n"
00564           << "   |                                                                    |\n"
00565           << "       Following part is appended at: " << tijd // \n included in tijd...
00566           << "   |                                                                    |\n"
00567           << "   *--------------------------------------------------------------------*\n\n";
00568     } //if else file existence
00569 
00570 // ______Tidy up______
00571   ofile.close();
00572   } // END initwrite
00573 
00574 
00575 /****************************************************************
00576  *    updatefile                                                *
00577  *                                                              *
00578  * A scratchfile is appended to a logfile.                      *
00579  * The scratchfile is deleted after copying.                    *
00580  *                                                              *
00581  * input:                                                       *
00582  *  - scratchfile                                               *
00583  *  - logfile                                                   *
00584  * output:                                                      *
00585  *  - void, updated logfile, scratchfile is deleted             *
00586  *                                                              *
00587  *    Bert Kampes, 11-Dec-1998                                  *
00588  * changed to 4*127 after problem.
00589  #%// BK 07-Mar-2001
00590  ****************************************************************/
00591 void updatefile(
00592         const char* sfile,
00593         const char* lfile)
00594   {
00595   TRACE_FUNCTION("updatefile (BK 11-Dec-1998)")
00596 
00597   char                  dummyline[4*ONE27];
00598   //ifstream scratchfile(sfile, ios::in | ios::nocreate);
00599   ifstream scratchfile(sfile, ios::in);
00600   bk_assert(scratchfile,sfile,__FILE__,__LINE__);
00601 
00602   ofstream logfile(lfile, ios::out | ios::app);
00603   bk_assert(logfile,lfile,__FILE__,__LINE__);
00604 
00605 // ______Start writing______
00606   scratchfile.getline(dummyline,4*ONE27,'\n');            // to prevent twice last line
00607   while (scratchfile)
00608     {
00609     logfile << dummyline << endl;
00610     scratchfile.getline(dummyline,4*ONE27,'\n');
00611     }
00612 
00613   // ______ Add current time ______
00614   time_t nseconds = time(NULL);
00615   char *tijd = ctime(&nseconds);                      // includes newline
00616   logfile << "\n   Current time: " << tijd; // \n included in tijd...
00617 
00618 // ______Tidy up______
00619   logfile.close();
00620   scratchfile.close();
00621   if (remove(sfile))                                    // remove file
00622     WARNING.print("Could not remove file.");
00623 
00624   DEBUG << "File: " << lfile
00625        << " has been updated by file: " << sfile << " (removed.)";
00626   DEBUG.print();
00627   } // END updatefile
00628 
00629 
00630 /****************************************************************
00631  *    getanswer                                                 *
00632  *                                                              *
00633  * Waits for user to press a key.                               *
00634  * (Mainly) used in interactive mode.                           *
00635  * should not wait for enter but getch() doesnt work !!         *
00636  * (dos only?)
00637  *                                                              *
00638  * future: no enter required                                    *
00639  *                                                              *
00640  *    Bert Kampes, 11-Dec-1998                                  *
00641  ****************************************************************/
00642 void getanswer(
00643         )
00644   {
00645   TRACE_FUNCTION("getanswer (BK 11-Dec-1998)")
00646   char dummychar;
00647   cerr << "\n Press <ENTER> to continue."; 
00648   cin.unsetf(ios::skipws);      // ignore ws (just enter)
00649   cin >> dummychar;
00650   cerr << " continuing...\n"; 
00651   } // END getanswer
00652 
00653 
00654 /****************************************************************
00655  *    readres                                                   *
00656  *                                                              *
00657  * Pattern is searched in file (1st word),                      *
00658  * next (skipwords) words are ignored (default=0)               *
00659  * the following word is returned as returnword,                *
00660  *  sizeofrw includes '\0'                                      *
00661  *                                                              *
00662  * eg: in main c8[9] as readres(c8,sizeof(c8),file,pat)         *
00663  *                                                              *
00664  * input:                                                       *
00665  *  - pointer to returnword                                     *
00666  *  - size of returnword (including '\0')                       *
00667  *  - file name to search                                       *
00668  *  - pattern to search for                                     *
00669  *  - number of words to skip before desired returnword (0=def  *
00670  * output:                                                      *
00671  *  - true if found, returnword is filled                       *
00672  *                                                              *
00673  * future: should include identifier as well                    *
00674  * better?: file.readsome(pattern)                              *
00675  *                                                              *
00676  *    Bert Kampes, 11-Dec-1998                                  *
00677  ****************************************************************/
00678 bool readres(
00679         char* returnword,
00680         const int16 sizeofrw, 
00681         const char* file,
00682         const char* pattern,
00683         const int16 skipwords)      //=0 default
00684   {
00685   TRACE_FUNCTION("readres (BK 11-Dec-1998)")
00686   char                  dummyline[ONE27];
00687   char                  word[EIGHTY];
00688   bool                  foundword = false;
00689 
00690   //ifstream infile(file, ios::in | ios::nocreate);
00691   ifstream infile(file, ios::in);
00692   bk_assert(infile,file,__FILE__,__LINE__);
00693 
00694 
00695   // ======Search infile======
00696   returnword[0] = '\0';                        // garanty word is empty
00697   char ch       = '\t';
00698   while (infile)
00699     {
00700     infile >> word;
00701     if (strcmp(pattern,word))                  // no pattern match.
00702       {
00703       infile.getline(dummyline,ONE27,'\n');    // goto next line.
00704       }
00705     else                                       // pattern match.
00706       {
00707       for (register int32 i=0; i<skipwords; i++)
00708         infile >> word;                        // goto correct position: word
00709       int32 tin;
00710       while (isspace(tin=ch))                  // goto correct position: trailing blanks
00711         {
00712         infile.get(ch);
00713         if (ch == '\n')                        // no argument after key
00714           {
00715           WARNING.print("Found identifier, but not so desired word!, exiting routine...");
00716           break;
00717           }
00718         }
00719 
00720       // ______ Actual read word ______
00721       foundword = true;
00722       //infile.putback(ch);
00723       //infile.read(returnword,sizeofrw-1);    // read desired word including blanks
00724       //returnword[sizeofrw]='\0'; ?
00725       // ______ Test bert ______
00726       for (int ii=0; ii<sizeofrw; ++ii)
00727         {
00728         if (ch == '\n')                        // no argument after key
00729           {
00730           returnword[ii] = '\0';
00731           break;
00732           }
00733         else
00734           {
00735           returnword[ii] = ch;
00736           }
00737         infile.get(ch);
00738         }
00739       //returnword[sizeofrw-1]='\0';
00740       break;                                   // file
00741       }                                        // else
00742     }                                          // file
00743 
00744   // ______ Give some info ______
00745   if (foundword)
00746     {
00747     DEBUG << "read: \"" << returnword << "\" as word " << skipwords << " after \""
00748          << pattern << "\"";
00749     DEBUG.print();
00750     }
00751   else
00752     {
00753     ERROR << "readres: could not find pattern: \"" << pattern
00754          << "\" in file: " << file;
00755     PRINT_ERROR(ERROR.get_str());
00756     throw(file_error);
00757     }
00758 
00759   infile.close();
00760   return foundword;
00761   } // END readres
00762 
00763 
00764 /****************************************************************
00765  *    updateprocesscontrol                                      *
00766  *                                                              *
00767  * Update the process controls flags at begin result file       *
00768  *                                                              *
00769  * input:                                                       *
00770  *  - file: name of file                                        *
00771  * output:                                                      *
00772  *  - void, file is updated                                     *
00773  *                                                              *
00774  *    Bert Kampes, 14-Dec-1998                                  *
00775  ****************************************************************/
00776 void updateprocesscontrol(
00777         const char* file,
00778         int16 fileid)
00779   {
00780   TRACE_FUNCTION("updateprocesscontrol (BK 14-Dec-1998)")
00781 //____RaffaeleNutricato START MODIFICATION SECTION 5
00782 //  int16                 checkprocess[NUMPROCESSES]; // already processed?
00783   int16                 checkprocess[NUMPROCESSES+1]; // Raffaele Nutricato, Hopefully this fixes bug!
00784 //____RaffaeleNutricato END MODIFICATION SECTION 5
00785 
00786   char                  dummyline[ONE27];
00787   //bool                processed = false;      // process control in resultfile
00788   //bool                processerror = false;   // to avoid error in middle of copying
00789 
00790   // ______Check existense, input______
00791   if (!existed(file))
00792     return;
00793 
00794 // ======Update process controls======
00795   ofstream tmpfile("scratchcopy", ios::out | ios::trunc);          // temporary copy
00796   bk_assert(tmpfile,"updateprocesscontrol: scratchcopy",__FILE__,__LINE__);
00797   //ifstream resfile(file, ios::in | ios::nocreate);
00798   ifstream resfile(file, ios::in);
00799   bk_assert(resfile,file,__FILE__,__LINE__);
00800 
00801 // ______copy resfile to tmpfile and fill checkprocess______
00802   for (register int32 i=0;i<NUMPROCESSES;i++)
00803     checkprocess[i]=0;
00804   resfile.getline(dummyline,ONE27,'\n');                // to prevent twice last line
00805   while(resfile)
00806     {
00807     tmpfile << dummyline << endl;                       // copy line
00808     fillcheckprocess(dummyline,checkprocess,fileid);      // check line to fill ...
00809     resfile.getline(dummyline,ONE27,'\n');              // get next line
00810     }
00811   resfile.close();
00812   tmpfile.close();
00813 
00814 
00815 // ______Update process_controls______
00816   //ifstream tmpfile2("scratchcopy", ios::in | ios::nocreate);  // temporary copy
00817   ifstream tmpfile2("scratchcopy", ios::in);    // temporary copy
00818   bk_assert(tmpfile2,"updateprocesscontrols: scratchcopy",__FILE__,__LINE__);
00819   ofstream resfile2(file, ios::out | ios::trunc);                  // do replace ! 
00820   bk_assert(resfile2,file,__FILE__,__LINE__);
00821 
00822 
00823 // ______Copy back, up to process control______
00824   while (strcmp(dummyline,"Start_process_control"))
00825     {
00826     tmpfile2.getline(dummyline,ONE27,'\n');
00827     resfile2 << dummyline << endl;
00828     }
00829 
00830 // ______Update process controls______
00831   char word[EIGHTY]=" ";
00832   for (;;)                                      // forever
00833     {
00834     tmpfile2 >> word;
00835     resfile2 << word;
00836     tmpfile2.getline(dummyline,ONE27,'\n');     // go to next line
00837     if (!strcmp(word,"End_process_control")) 
00838       {
00839       resfile2 << endl;
00840       break;
00841       }
00842 
00843     switch (fileid)
00844       {
00845     case MASTERID:
00846       if      (!strcmp(word,processcontrol[pr_m_readfiles]))
00847         (checkprocess[pr_m_readfiles]) ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00848       else if (!strcmp(word,processcontrol[pr_m_porbits]))
00849         (checkprocess[pr_m_porbits])   ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00850       else if (!strcmp(word,processcontrol[pr_m_crop]))
00851         (checkprocess[pr_m_crop])   ? resfile2 << "\t\t\t1\n" : resfile2 << "\t\t\t0\n";
00852 //____RaffaeleNutricato START MODIFICATION SECTION 6
00853       else if (!strcmp(word,processcontrol[pr_m_oversample]))
00854         (checkprocess[pr_m_oversample])   ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n"; 
00855 //____RaffaeleNutricato END MODIFICATION SECTION 6
00856       else if (!strcmp(word,processcontrol[pr_m_filtazi]))
00857         (checkprocess[pr_m_filtazi])   ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00858       else if (!strcmp(word,processcontrol[pr_m_filtrange]))
00859         (checkprocess[pr_m_filtrange])  ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00860       else if (!strcmp(word,processcontrol[pr_m_EXTRA]))
00861         (checkprocess[pr_m_EXTRA])  ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00862       else 
00863         {
00864         ERROR << "PANIC: forgotten to update routine? " << word
00865              << " not recognized in master resultfile.";
00866         PRINT_ERROR(ERROR.get_str())
00867         throw(unhandled_case_error);
00868         }
00869       break; // switch
00870 
00871     case SLAVEID:
00872       if      (!strcmp(word,processcontrol[pr_s_readfiles]))
00873         (checkprocess[pr_s_readfiles]) ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00874       else if (!strcmp(word,processcontrol[pr_s_porbits]))
00875         (checkprocess[pr_s_porbits])   ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00876       else if (!strcmp(word,processcontrol[pr_s_crop]))
00877         (checkprocess[pr_s_crop])   ? resfile2 << "\t\t\t1\n" : resfile2 << "\t\t\t0\n";
00878 //____RaffaeleNutricato START MODIFICATION SECTION 7
00879       else if (!strcmp(word,processcontrol[pr_s_oversample]))
00880         (checkprocess[pr_s_oversample])   ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00881 //____RaffaeleNutricato END MODIFICATION SECTION 7
00882       else if (!strcmp(word,processcontrol[pr_s_resample]))
00883         (checkprocess[pr_s_resample])  ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00884       else if (!strcmp(word,processcontrol[pr_s_filtazi]))
00885         (checkprocess[pr_s_filtazi])   ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00886       else if (!strcmp(word,processcontrol[pr_s_filtrange]))
00887         (checkprocess[pr_s_filtrange])  ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00888       else if (!strcmp(word,processcontrol[pr_s_EXTRA]))
00889         (checkprocess[pr_s_EXTRA])  ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00890       else 
00891         {
00892         ERROR << "PANIC: forgotten to update routine? " << word
00893              << " not recognized in slave resultfile.";
00894         PRINT_ERROR(ERROR.get_str())
00895         throw(unhandled_case_error);
00896         }
00897       break; // switch
00898 
00899     case INTERFID:
00900       if      (!strcmp(word,processcontrol[pr_i_coarse]))
00901         (checkprocess[pr_i_coarse])    ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00902       else if (!strcmp(word,processcontrol[pr_i_coarse2]))
00903         (checkprocess[pr_i_coarse2])   ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00904       else if (!strcmp(word,processcontrol[pr_i_fine]))
00905         (checkprocess[pr_i_fine])      ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00906       else if (!strcmp(word,processcontrol[pr_i_coregpm]))
00907         (checkprocess[pr_i_coregpm])   ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00908       else if (!strcmp(word,processcontrol[pr_i_interfero]))
00909         (checkprocess[pr_i_interfero]) ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00910       else if (!strcmp(word,processcontrol[pr_i_coherence]))
00911         (checkprocess[pr_i_coherence]) ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00912       else if (!strcmp(word,processcontrol[pr_i_comprefpha]))
00913         (checkprocess[pr_i_comprefpha]) ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00914       else if (!strcmp(word,processcontrol[pr_i_subtrrefpha]))
00915         (checkprocess[pr_i_subtrrefpha]) ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00916       else if (!strcmp(word,processcontrol[pr_i_comprefdem]))
00917         (checkprocess[pr_i_comprefdem]) ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00918       else if (!strcmp(word,processcontrol[pr_i_subtrrefdem]))
00919         (checkprocess[pr_i_subtrrefdem]) ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00920       else if (!strcmp(word,processcontrol[pr_i_filtphase]))
00921         (checkprocess[pr_i_filtphase]) ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00922       else if (!strcmp(word,processcontrol[pr_i_unwrap]))
00923         (checkprocess[pr_i_unwrap])    ? resfile2 << "\t\t\t1\n" : resfile2 << "\t\t\t0\n";
00924       else if (!strcmp(word,processcontrol[pr_i_slant2h]))
00925         (checkprocess[pr_i_slant2h])   ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00926       else if (!strcmp(word,processcontrol[pr_i_geocoding]))
00927         (checkprocess[pr_i_geocoding]) ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00928       else if (!strcmp(word,processcontrol[pr_i_dinsar]))
00929         (checkprocess[pr_i_dinsar]) ? resfile2 << "\t\t\t1\n" : resfile2 << "\t\t\t0\n";
00930       else if (!strcmp(word,processcontrol[pr_i_EXTRA2]))
00931         (checkprocess[pr_i_EXTRA2]) ? resfile2 << "\t\t1\n" : resfile2 << "\t\t0\n";
00932       else 
00933         {
00934         ERROR << "PANIC: forgotten to update routine? " << word
00935              << " not recognized in interferogram resultfile.";
00936         PRINT_ERROR(ERROR.get_str())
00937         throw(unhandled_case_error);
00938         }
00939       break; // switch
00940 
00941     default:
00942       PRINT_ERROR("PANIC, impossible wrong.")
00943       throw(unhandled_case_error);
00944       } // switch
00945     } // forever
00946 
00947 
00948 // ======Copy rest of file======
00949   tmpfile2.getline(dummyline,ONE27,'\n');       // get line
00950   while(tmpfile2)
00951     {
00952     resfile2 << dummyline << endl;
00953     tmpfile2.getline(dummyline,ONE27,'\n');
00954     }
00955   resfile2.close();
00956   tmpfile2.close();
00957 
00958 // ______Tidy up______
00959 //  if (processerror)
00960 //    ERROR(__FILE__,__LINE__,"updateprocesscontrols: resfile some problem.");
00961   if (remove("scratchcopy"))                            // remove file
00962     WARNING.print("Could not remove file: scratchcopy.");
00963   } // END updateprocesscontrols
00964 
00965 
00966 /****************************************************************
00967  *    checkprocessing                                           *
00968  *                                                              *
00969  * Checks if requested processing is possible.                  *
00970  * checkprocess[i] contains already processed                    *
00971  *  (master index is mis-used to indicate)                      *
00972  * inputgeneral.process[i] contains requests                     *
00973  * requirements for processing can be found in software folder  *
00974  * general if step is requested:                                *
00975  *  0) check already                                            *
00976  *  1) check requirements (other steps/files)                   *
00977  *  2) set checkprocessed true                                   *
00978  *                                                              *
00979  * input:                                                       *
00980  * output:                                                      *
00981  *  - void (no exit hopefully)                                  *
00982  *  - checkprocess is filled with what is already processed      *
00983  *                                                              *
00984  *BUG: filled with what will be processed as well...            *
00985  *BUG??: not correctly passed back ???                          *
00986  *                                                              *
00987  *    Bert Kampes, 14-Dec-1998                                  *
00988  ****************************************************************/
00989 void checkprocessing(
00990         const input_gen &generalinput,
00991         int16 checkprocess[NUMPROCESSES])
00992   {
00993   TRACE_FUNCTION("checkprocessing (BK 14-Dec-1998)")
00994   char          dummyline[ONE27] = " ";
00995   //char          word[EIGHTY]     = " ";
00996   const char*   file;
00997   int16         checkprocess2[NUMPROCESSES+1];   // check with filecontent
00998 
00999   checkprocess2[NUMPROCESSES]=0;
01000   register int32 i;
01001   for (i=0;i<NUMPROCESSES;i++)
01002     {
01003     checkprocess[i]=0;
01004     checkprocess2[i]=0;
01005     }
01006 
01007 // ______Fill checkprocess______
01008   for (int32 fileid=MASTERID; fileid<=INTERFID; fileid++)
01009     {
01010     if (fileid == MASTERID)
01011       file=generalinput.m_resfile;
01012     else if (fileid == SLAVEID)
01013       file=generalinput.s_resfile;
01014     else if (fileid == INTERFID)
01015       file=generalinput.i_resfile;
01016     else
01017       {
01018       PRINT_ERROR("checkprocessing, PANIC, wrong input")
01019       throw(input_error);
01020       }
01021 
01022     if (existed(file))
01023       {
01024       int32 breakit=0;
01025       while(breakit<3)                          // try 2 recover in case of error
01026         {
01027         ifstream resfile;// required to put in loop for g++v3.2// BK 08-Apr-2003
01028         //resfile.open(file, ios::in | ios::nocreate);
01029         resfile.open(file, ios::in);
01030         bk_assert(resfile,file,__FILE__,__LINE__);
01031 
01032         int32 linecnt=0;
01033         while (strcmp(dummyline,"Start_process_control"))
01034           {
01035           resfile.getline(dummyline,ONE27,'\n');
01036           DEBUG << "read line: " << dummyline << ends; 
01037           DEBUG.print();
01038           linecnt++;
01039           if (linecnt==200) 
01040             {
01041             WARNING.print("Checked first 200 lines, did not find: \"Start_process_control\".");
01042             break;
01043             }
01044           }
01045   
01046         // ______ Read processcontrols into array checkprocess ______
01047         linecnt=0;
01048         while (strcmp(dummyline,"End_process_control"))
01049           {
01050           resfile.getline(dummyline,ONE27,'\n');
01051           DEBUG << "read line: " << dummyline;
01052           DEBUG.print();
01053           fillprocessed(dummyline,checkprocess,fileid);
01054           linecnt++;
01055           if (linecnt==200) 
01056             {
01057             WARNING.print("Checked first 200 lines, did not find: \"End_process_control\".");
01058             break;
01059             }
01060           }
01061        
01062         // ______ Read resultsections in file for array checkprocess2 ______
01063         resfile.getline(dummyline,ONE27,'\n');          // read line
01064         while(resfile)
01065           {
01066           fillcheckprocess(dummyline,checkprocess2,fileid);       // check line
01067           resfile.getline(dummyline,ONE27,'\n');                // read line
01068           DEBUG << "read line: " << dummyline;
01069           DEBUG.print();
01070           }
01071         resfile.close();
01072       
01073         // ______ Check resultsections with process control flags ______
01074         bool dofixprocesscontrol=false;
01075         for (i=0;i<NUMPROCESSES;i++)
01076           {
01077           if (checkprocess[i] != checkprocess2[i])
01078             {
01079             dofixprocesscontrol=true;
01080             WARNING << "Step: " << i << " (" << processcontrol[i] 
01081                  << ") ";
01082             if (checkprocess[i]==1)
01083               WARNING << "in process control flag, but result is not in \"" 
01084                    << file << "\".";
01085             else
01086               WARNING << "not in process control flag, but result is in \"" 
01087                    << file << "\".";
01088             WARNING.print();
01089             if (generalinput.interactive) getanswer();
01090             } // something is wrong
01091           } // for all steps
01092   
01093         // ______ Check if repairs have to be made ______
01094         if (dofixprocesscontrol)
01095           {
01096           if (breakit == 1)
01097             {
01098             cerr << "\nAlready tried to fix process controls. Should I try again?\n"; 
01099             getanswer();
01100             }
01101           updateprocesscontrol(file, fileid);                   // repair routine
01102           breakit += 1;                                         // only one try
01103           }
01104         else // nothing strange 
01105           breakit = 10;                                         // > stop condition
01106       } // try to repair
01107     } // existed(file)
01108   } // for fileid
01109 
01110 
01111 // ______ Keep checkprocess like this (only what is actually in resultfile) ______
01112 // ______ and update a new array ______
01113   int16 checkprocesstmp[NUMPROCESSES];
01114   for (i=0; i<NUMPROCESSES; i++)
01115     checkprocesstmp[i]=checkprocess[i];
01116 
01117 // ====== Check with requested processes ======
01118 // ______ The order is important (BK 26mar2001) ______
01119 // ______ This means that to avoid warnings, filtrange should be after coarse corr.
01120 // ______ Master ______
01121   if (generalinput.process[pr_m_readfiles])                     // requested
01122     checkrequest(pr_m_readfiles,checkprocesstmp,0);             // no requirements
01123   if (generalinput.process[pr_m_crop])                          // requested
01124     checkrequest(pr_m_crop,checkprocesstmp,
01125                  1,pr_m_readfiles);                             // required (RN)?
01126     //checkrequest(pr_m_crop,checkprocesstmp,0);                  // no requirements
01127 //____RaffaeleNutricato START MODIFICATION SECTION 8
01128   if (generalinput.process[pr_m_oversample])                    // requested 
01129     checkrequest(pr_m_oversample,checkprocesstmp,1,pr_m_crop);  // oversample requires a cropped image 
01130 //____RaffaeleNutricato END MODIFICATION SECTION 8
01131   if (generalinput.process[pr_m_porbits])                       // requested
01132     checkrequest(pr_m_porbits,checkprocesstmp, 1,pr_m_readfiles);// required for time info
01133     if (checkprocess2[NUMPROCESSES])                            // extra check
01134       DEBUG.print("orbits from leader file will be deleted.");
01135   if (generalinput.process[pr_m_filtazi])                       // requested
01136     checkrequest(pr_m_filtazi,checkprocesstmp,
01137                  1,pr_m_crop);                                  // required
01138   if (generalinput.process[pr_m_EXTRA])                         // requested
01139     checkrequest(pr_m_EXTRA,checkprocesstmp,0);                 // no requirements
01140 
01141 // ______ Slave ______
01142   if (generalinput.process[pr_s_readfiles])                     // requested
01143     checkrequest(pr_s_readfiles,checkprocesstmp,0);             // no requirements
01144   if (generalinput.process[pr_s_crop])                          // requested
01145     checkrequest(pr_s_crop,checkprocesstmp,
01146                  1,pr_s_readfiles);                             // required for check
01147 //____RaffaeleNutricato START MODIFICATION SECTION 9
01148   if (generalinput.process[pr_s_oversample])                    // requested  
01149     checkrequest(pr_s_oversample,checkprocesstmp,1,pr_s_crop);  // oversample requires a cropped image 
01150 //____RaffaeleNutricato END MODIFICATION SECTION 9
01151   if (generalinput.process[pr_s_porbits])                       // requested
01152     checkrequest(pr_s_porbits,checkprocesstmp,
01153                  1,pr_s_readfiles);                             // required for time info
01154     if (checkprocess2[NUMPROCESSES])                            // extra check
01155       DEBUG.print("orbits from leader file will be deleted.");
01156   if (generalinput.process[pr_s_filtazi])                       // requested
01157     checkrequest(pr_s_filtazi,checkprocesstmp,
01158                  1,pr_s_crop);                                  // required
01159   if (generalinput.process[pr_s_EXTRA])                         // requested
01160     checkrequest(pr_s_EXTRA,checkprocesstmp,0);                 // no requirements
01161 
01162 // ______ Interferogram ______
01163   if (generalinput.process[pr_i_coarse])                        // requested
01164     checkrequest(pr_i_coarse,checkprocesstmp,
01165     2,pr_m_crop,pr_s_crop);                                     // required
01166   if (generalinput.process[pr_i_coarse2])                       // requested
01167     checkrequest(pr_i_coarse2,checkprocesstmp,
01168     2,pr_m_crop,pr_s_crop);                                     // required
01169   // orbits...
01170   if (generalinput.process[pr_m_filtrange])                     // requested
01171     checkrequest(pr_m_filtrange,checkprocesstmp,
01172                  2,pr_m_crop,pr_i_coarse2);                  // adviced
01173   // adaptive...
01174   //if (generalinput.process[pr_m_filtrange])                     // requested
01175   //  checkrequest(pr_m_filtrange,checkprocesstmp,
01176   //               2,pr_m_crop,pr_s_resample);                    // required
01177   //if (generalinput.process[pr_s_filtrange])                   // requested
01178   //  checkrequest(pr_s_filtrange,checkprocesstmp,
01179   //               1,pr_s_crop);                                // required
01180   if (generalinput.process[pr_i_fine])                          // requested
01181     checkrequest(pr_i_fine,checkprocesstmp,
01182     2,pr_m_crop,pr_s_crop);
01183   if (generalinput.process[pr_i_coregpm])                       // requested
01184     checkrequest(pr_i_coregpm,checkprocesstmp,
01185     1,pr_i_fine);
01186 
01187   // this should go here...
01188   // BK 24-Aug-2000
01189   if (generalinput.process[pr_s_resample])                      // requested
01190     checkrequest(pr_s_resample,checkprocesstmp,
01191                  1,pr_i_coregpm);                               // required
01192 
01193   if (generalinput.process[pr_i_interfero])                     // requested
01194     checkrequest(pr_i_interfero,checkprocesstmp,
01195     1,pr_s_resample);
01196   if (generalinput.process[pr_i_coherence])                     // requested
01197     checkrequest(pr_i_coherence,checkprocesstmp,
01198     1,pr_s_resample);
01199   if (generalinput.process[pr_i_comprefpha])                    // requested
01200     checkrequest(pr_i_comprefpha,checkprocesstmp,
01201     2,pr_m_readfiles,pr_s_readfiles);                           // orbits required
01202   if (generalinput.process[pr_i_subtrrefpha])                   // requested
01203     checkrequest(pr_i_subtrrefpha,checkprocesstmp,
01204     1,pr_i_interfero);                                          // required
01205     // 2,pr_i_comprefpha,pr_i_interfero);                       // required
01206   if (generalinput.process[pr_i_comprefdem])                    // requested
01207     checkrequest(pr_i_comprefdem,checkprocesstmp,
01208     2,pr_m_readfiles,pr_s_readfiles);                           // orbits required
01209   if (generalinput.process[pr_i_subtrrefdem])                   // requested
01210     checkrequest(pr_i_subtrrefdem,checkprocesstmp,
01211     2,pr_i_comprefdem,pr_i_interfero);                          // required
01212   if (generalinput.process[pr_i_filtphase])                     // requested
01213     checkrequest(pr_i_filtphase,checkprocesstmp,
01214     1,pr_i_interfero);                                          // required
01215   if (generalinput.process[pr_i_unwrap])                        // requested
01216     checkrequest(pr_i_unwrap,checkprocesstmp,
01217     1,pr_i_interfero);                                          // required
01218   if (generalinput.process[pr_i_slant2h])                       // requested
01219     checkrequest(pr_i_slant2h,checkprocesstmp,
01220     1,pr_i_unwrap);                                             // required
01221   if (generalinput.process[pr_i_geocoding])                     // requested
01222     checkrequest(pr_i_geocoding,checkprocesstmp,
01223     1,pr_i_slant2h);                                            // required
01224   if (generalinput.process[pr_i_dinsar])                        // requested
01225     checkrequest(pr_i_dinsar,checkprocesstmp,
01226     1,pr_i_interfero);                                          // required
01227   if (generalinput.process[pr_i_EXTRA2])                        // requested
01228     checkrequest(pr_i_EXTRA2,checkprocesstmp,0);                // no requirements
01229 
01230 // ______Tidy up______
01231   } // END checkprocesscontrol
01232 
01233 
01234 /****************************************************************
01235  *    checkrequest                                              *
01236  *                                                              *
01237  * Checks if requested processing step can be processed.        *
01238  *                                                              *
01239  * input:                                                       *
01240  *  - step to be processed                                      *
01241  *  - array of already processed steps                          *
01242  *  - optional: Number of req, and,                             *
01243  *                   steps that are required for this step      *
01244  * output:                                                      *
01245  *  - (updated) alreadyprocess[]                                *
01246  *                                                              *
01247  *                                                              *
01248  *    Bert Kampes, 16-Dec-1998                                  *
01249  ****************************************************************/
01250 void checkrequest(
01251         int16 step,
01252         int16 alreadyprocess[NUMPROCESSES],
01253         ...)
01254   {
01255   TRACE_FUNCTION("checkrequest (BK 16-Dec-1998)")
01256 
01257 // ______Check if step is already processed and update already______
01258   if (alreadyprocess[step])
01259     {
01260     ERROR << "Results of step: "
01261          << step << " (" << processcontrol[step]
01262          << ") already in result file.";
01263     PRINT_ERROR(ERROR.get_str())
01264     throw(input_error);
01265     }
01266   alreadyprocess[step]=1;                        // set to processed
01267 
01268   // ______Check with requirements______
01269   // ______ It seemed this has to be int instea of int16 on redhat 7.0 linux? ______
01270   // but why? BK 21-Nov-2000
01271   va_list arglist;                              // use ellipses
01272   va_start(arglist,alreadyprocess);
01273   /* *** SOME compiler required the second form, though it seems wrong,
01274      *** in order to compile doris comment out the second, and put a comment before 
01275      *** the first form. */
01276   // seems that while passing '...' type is converted to int, so use that here...
01277   //int16 N = va_arg(arglist, int16);             // number of arguments=first ellipses
01278   int16 N = va_arg(arglist, int);
01279 
01280   int16 requiredstep;
01281   for (register int32 i=0; i<N; i++)
01282     {
01283     /* *** SOME compiler required the second form, though it seems wrong,
01284        *** in order to compile doris comment out the second, and put a comment before 
01285        *** the first form. */
01286     //requiredstep = va_arg(arglist, int16);
01287     requiredstep = va_arg(arglist, int);
01288 
01289     if (!(alreadyprocess[requiredstep]))
01290       {
01291       WARNING << "Requested step: "
01292            << step << " (" << processcontrol[step]
01293            << ") seems impossible, because step "
01294            << requiredstep << " (" << processcontrol[requiredstep] 
01295            << ") is not in resultfile.";
01296       WARNING.print();
01297       }
01298     }
01299   va_end(arglist);
01300   } // END checkrequest
01301 
01302 
01303 /****************************************************************
01304  *    fillcheckprocess                                          *
01305  *                                                              *
01306  * Fills processing array for checking.                         *
01307  * Line comes from file, if processed is finished,              *
01308  *  checkprocess is filled                                      *
01309  * Looks for End_*:_NORMAL                                      *
01310  *                                                              *
01311  * input:                                                       *
01312  *  - line from result file                                     *
01313  *  - (empty) process control array                             *
01314  * output:                                                      *
01315  *  - (filled) process control array                            *
01316  *     normally m_pr* is filled if there is a choice            *
01317  *     except for pr_orbits: m_* =getorb ;s_* =readleader       *
01318  *     if there are more methods, the first one is flagged      *
01319  *                                                              *
01320  *    Bert Kampes, 16-Dec-1998                                  *
01321  ****************************************************************/
01322 void fillcheckprocess(
01323         const char *line,
01324         int16 checkprocess[NUMPROCESSES+1],
01325         int16 fileid)
01326   {
01327   TRACE_FUNCTION("fillcheckprocess (BK 16-Dec-1998)")
01328   if (line[0] != '*')                                   // always start with *
01329     return;
01330 
01331   // ______ Set up compare strings ______
01332   // could be done smarter...
01333   char *endnormal[NUMPROCESSES];
01334   char mread[ONE27];
01335   strcpy(mread,"* End_");
01336   strcat(mread,processcontrol[pr_m_readfiles]);
01337   strcat(mread,"_NORMAL");
01338   endnormal[pr_m_readfiles]=&mread[0];
01339 
01340   char mcrop[ONE27];
01341   strcpy(mcrop,"* End_");
01342   strcat(mcrop,processcontrol[pr_m_crop]);
01343   strcat(mcrop,"_NORMAL");
01344   endnormal[pr_m_crop]=&mcrop[0];
01345 
01346 //____RaffaeleNutricato START MODIFICATION SECTION 10
01347   char moversample[ONE27];
01348   strcpy(moversample,"* End_");
01349   strcat(moversample,processcontrol[pr_m_oversample]);
01350   strcat(moversample,"_NORMAL");
01351   endnormal[pr_m_oversample]=&moversample[0];
01352 //____RaffaeleNutricato END MODIFICATION SECTION 10
01353 
01354   char mporbits[ONE27];
01355   strcpy(mporbits,"* End_");
01356   strcat(mporbits,processcontrol[pr_m_porbits]);
01357   strcat(mporbits,"_NORMAL");
01358   endnormal[pr_m_porbits]=&mporbits[0];
01359 
01360   char mfiltazi[ONE27];
01361   strcpy(mfiltazi,"* End_");
01362   strcat(mfiltazi,processcontrol[pr_m_filtazi]);
01363   strcat(mfiltazi,"_NORMAL");
01364   endnormal[pr_m_filtazi]=&mfiltazi[0];
01365 
01366   char mfiltrange[ONE27];
01367   strcpy(mfiltrange,"* End_");
01368   strcat(mfiltrange,processcontrol[pr_m_filtrange]);
01369   strcat(mfiltrange,"_NORMAL");
01370   endnormal[pr_m_filtrange]=&mfiltrange[0];
01371 
01372   char mEXTRA[ONE27];
01373   strcpy(mEXTRA,"* End_");
01374   strcat(mEXTRA,processcontrol[pr_m_EXTRA]);
01375   strcat(mEXTRA,"_NORMAL");
01376   endnormal[pr_m_EXTRA]=&mEXTRA[0];
01377 
01378   char sread[ONE27];
01379   strcpy(sread,"* End_");
01380   strcat(sread,processcontrol[pr_s_readfiles]);
01381   strcat(sread,"_NORMAL");
01382   endnormal[pr_s_readfiles]=&sread[0];
01383 
01384   char scrop[ONE27];
01385   strcpy(scrop,"* End_");
01386   strcat(scrop,processcontrol[pr_s_crop]);
01387   strcat(scrop,"_NORMAL");
01388   endnormal[pr_s_crop]=&scrop[0];
01389 
01390 //____RaffaeleNutricato START MODIFICATION SECTION 11
01391   char soversample[ONE27];
01392   strcpy(soversample,"* End_");
01393   strcat(soversample,processcontrol[pr_s_oversample]);
01394   strcat(soversample,"_NORMAL");
01395   endnormal[pr_s_oversample]=&soversample[0];
01396 //____RaffaeleNutricato END MODIFICATION SECTION 11
01397 
01398   char sporbits[ONE27];
01399   strcpy(sporbits,"* End_");
01400   strcat(sporbits,processcontrol[pr_s_porbits]);
01401   strcat(sporbits,"_NORMAL");
01402   endnormal[pr_s_porbits]=&sporbits[0];
01403 
01404   char sfiltazi[ONE27];
01405   strcpy(sfiltazi,"* End_");
01406   strcat(sfiltazi,processcontrol[pr_s_filtazi]);
01407   strcat(sfiltazi,"_NORMAL");
01408   endnormal[pr_s_filtazi]=&sfiltazi[0];
01409 
01410   char sfiltrange[ONE27];
01411   strcpy(sfiltrange,"* End_");
01412   strcat(sfiltrange,processcontrol[pr_s_filtrange]);
01413   strcat(sfiltrange,"_NORMAL");
01414   endnormal[pr_s_filtrange]=&sfiltrange[0];
01415 
01416   char sresample[ONE27];
01417   strcpy(sresample,"* End_");
01418   strcat(sresample,processcontrol[pr_s_resample]);
01419   strcat(sresample,"_NORMAL");
01420   endnormal[pr_s_resample]=&sresample[0];
01421 
01422   char sEXTRA[ONE27];
01423   strcpy(sEXTRA,"* End_");
01424   strcat(sEXTRA,processcontrol[pr_s_EXTRA]);
01425   strcat(sEXTRA,"_NORMAL");
01426   endnormal[pr_s_EXTRA]=&sEXTRA[0];
01427 
01428   char icoarse[ONE27];
01429   strcpy(icoarse,"* End_");
01430   strcat(icoarse,processcontrol[pr_i_coarse]);
01431   strcat(icoarse,"_NORMAL");
01432   endnormal[pr_i_coarse]=&icoarse[0];
01433 
01434   char icoarse2[ONE27];
01435   strcpy(icoarse2,"* End_");
01436   strcat(icoarse2,processcontrol[pr_i_coarse2]);
01437   strcat(icoarse2,"_NORMAL");
01438   endnormal[pr_i_coarse2]=&icoarse2[0];
01439 
01440   char ifine[ONE27];
01441   strcpy(ifine,"* End_");
01442   strcat(ifine,processcontrol[pr_i_fine]);
01443   strcat(ifine,"_NORMAL");
01444   endnormal[pr_i_fine]=&ifine[0];
01445 
01446   char icoregpm[ONE27];
01447   strcpy(icoregpm,"* End_");
01448   strcat(icoregpm,processcontrol[pr_i_coregpm]);
01449   strcat(icoregpm,"_NORMAL");
01450   endnormal[pr_i_coregpm]=&icoregpm[0];
01451 
01452   char iinterfero[ONE27];
01453   strcpy(iinterfero,"* End_");
01454   strcat(iinterfero,processcontrol[pr_i_interfero]);
01455   strcat(iinterfero,"_NORMAL");
01456   endnormal[pr_i_interfero]=&iinterfero[0];
01457 
01458   char icoherence[ONE27];
01459   strcpy(icoherence,"* End_");
01460   strcat(icoherence,processcontrol[pr_i_coherence]);
01461   strcat(icoherence,"_NORMAL");
01462   endnormal[pr_i_coherence]=&icoherence[0];
01463 
01464   char icomprefpha[ONE27];
01465   strcpy(icomprefpha,"* End_");
01466   strcat(icomprefpha,processcontrol[pr_i_comprefpha]);
01467   strcat(icomprefpha,"_NORMAL");
01468   endnormal[pr_i_comprefpha]=&icomprefpha[0];
01469 
01470   char isubtrrefpha[ONE27];
01471   strcpy(isubtrrefpha,"* End_");
01472   strcat(isubtrrefpha,processcontrol[pr_i_subtrrefpha]);
01473   strcat(isubtrrefpha,"_NORMAL");
01474   endnormal[pr_i_subtrrefpha]=&isubtrrefpha[0];
01475 
01476   char icomprefdem[ONE27];
01477   strcpy(icomprefdem,"* End_");
01478   strcat(icomprefdem,processcontrol[pr_i_comprefdem]);
01479   strcat(icomprefdem,"_NORMAL");
01480   endnormal[pr_i_comprefdem]=&icomprefdem[0];
01481 
01482   char isubtrrefdem[ONE27];
01483   strcpy(isubtrrefdem,"* End_");
01484   strcat(isubtrrefdem,processcontrol[pr_i_subtrrefdem]);
01485   strcat(isubtrrefdem,"_NORMAL");
01486   endnormal[pr_i_subtrrefdem]=&isubtrrefdem[0];
01487 
01488   char ifiltphase[ONE27];
01489   strcpy(ifiltphase,"* End_");
01490   strcat(ifiltphase,processcontrol[pr_i_filtphase]);
01491   strcat(ifiltphase,"_NORMAL");
01492   endnormal[pr_i_filtphase]=&ifiltphase[0];
01493 
01494   char iunwrap[ONE27];
01495   strcpy(iunwrap,"* End_");
01496   strcat(iunwrap,processcontrol[pr_i_unwrap]);
01497   strcat(iunwrap,"_NORMAL");
01498   endnormal[pr_i_unwrap]=&iunwrap[0];
01499 
01500   char islant2h[ONE27];
01501   strcpy(islant2h,"* End_");
01502   strcat(islant2h,processcontrol[pr_i_slant2h]);
01503   strcat(islant2h,"_NORMAL");
01504   endnormal[pr_i_slant2h]=&islant2h[0];
01505 
01506   char igeocoding[ONE27];
01507   strcpy(igeocoding,"* End_");
01508   strcat(igeocoding,processcontrol[pr_i_geocoding]);
01509   strcat(igeocoding,"_NORMAL");
01510   endnormal[pr_i_geocoding]=&igeocoding[0];
01511 
01512   char idinsar[ONE27];
01513   strcpy(idinsar,"* End_");
01514   strcat(idinsar,processcontrol[pr_i_dinsar]);
01515   strcat(idinsar,"_NORMAL");
01516   endnormal[pr_i_dinsar]=&idinsar[0];
01517 
01518   char iEXTRA2[ONE27];
01519   strcpy(iEXTRA2,"* End_");
01520   strcat(iEXTRA2,processcontrol[pr_i_EXTRA2]);
01521   strcat(iEXTRA2,"_NORMAL");
01522   endnormal[pr_i_EXTRA2]=&iEXTRA2[0];
01523 
01524 // ======Fill checkprocessarray======
01525   if (fileid == MASTERID)
01526     {
01527     //<< "\n* End_" << processcontrol[pr_i_coarse] << "_NORMAL"
01528     //if (!strcmp(line,"* End_readfiles:_NORMAL"))
01529     if (!strcmp(line,endnormal[pr_m_readfiles]))
01530       checkprocess[pr_m_readfiles]=1;
01531     else if (!strcmp(line,"* End_leader_datapoints:_NORMAL"))   // fixed string...
01532       checkprocess[NUMPROCESSES]=1;
01533     else if (!strcmp(line,endnormal[pr_m_porbits]))
01534       checkprocess[pr_m_porbits]=1;
01535     else if (!strcmp(line,endnormal[pr_m_crop]))
01536       checkprocess[pr_m_crop]=1;
01537 //____RaffaeleNutricato START MODIFICATION SECTION 12
01538     else if (!strcmp(line,endnormal[pr_m_oversample])) 
01539       checkprocess[pr_m_oversample]=1; 
01540 //____RaffaeleNutricato END MODIFICATION SECTION 12
01541     else if (!strcmp(line,endnormal[pr_m_filtazi]))
01542       checkprocess[pr_m_filtazi]=1;
01543     else if (!strcmp(line,endnormal[pr_m_filtrange]))
01544       checkprocess[pr_m_filtrange]=1;
01545     else if (!strcmp(line,endnormal[pr_m_EXTRA]))
01546       checkprocess[pr_m_EXTRA]=1;
01547     }
01548 
01549   else if (fileid == SLAVEID)
01550     {
01551     if (!strcmp(line,endnormal[pr_s_readfiles]))
01552       checkprocess[pr_s_readfiles]=1;
01553     else if (!strcmp(line,"* End_leader_datapoints:_NORMAL"))   // fixed string...
01554       checkprocess[NUMPROCESSES]=1;
01555     else if (!strcmp(line,endnormal[pr_s_porbits]))
01556       checkprocess[pr_s_porbits]=1;
01557     else if (!strcmp(line,endnormal[pr_s_crop]))
01558       checkprocess[pr_s_crop]=1;
01559 //____RaffaeleNutricato START MODIFICATION SECTION 13
01560     else if (!strcmp(line,endnormal[pr_s_oversample])) 
01561       checkprocess[pr_s_oversample]=1; 
01562 //____RaffaeleNutricato END MODIFICATION SECTION 13
01563     else if (!strcmp(line,endnormal[pr_s_filtazi]))
01564       checkprocess[pr_s_filtazi]=1;
01565     else if (!strcmp(line,endnormal[pr_s_filtrange]))
01566       checkprocess[pr_s_filtrange]=1;
01567     else if (!strcmp(line,endnormal[pr_s_resample]))
01568       checkprocess[pr_s_resample]=1;
01569     else if (!strcmp(line,endnormal[pr_s_EXTRA]))
01570       checkprocess[pr_s_EXTRA]=1;
01571     }
01572 
01573   else if (fileid == INTERFID)
01574     {
01575 // ______Interferogram______
01576     if (!strcmp(line,endnormal[pr_i_coarse]))
01577       checkprocess[pr_i_coarse]=1;
01578     else if (!strcmp(line,endnormal[pr_i_coarse2]))
01579       checkprocess[pr_i_coarse2]=1;
01580     else if (!strcmp(line,endnormal[pr_i_fine]))
01581       checkprocess[pr_i_fine]=1;
01582     else if (!strcmp(line,endnormal[pr_i_coregpm]))
01583       checkprocess[pr_i_coregpm]=1;
01584     else if (!strcmp(line,endnormal[pr_i_interfero]))
01585       checkprocess[pr_i_interfero]=1;
01586     else if (!strcmp(line,endnormal[pr_i_coherence]))
01587       checkprocess[pr_i_coherence]=1;
01588     else if (!strcmp(line,endnormal[pr_i_comprefpha]))
01589       checkprocess[pr_i_comprefpha]=1;
01590     else if (!strcmp(line,endnormal[pr_i_subtrrefpha]))
01591       checkprocess[pr_i_subtrrefpha]=1;
01592     else if (!strcmp(line,endnormal[pr_i_comprefdem]))
01593       checkprocess[pr_i_comprefdem]=1;
01594     else if (!strcmp(line,endnormal[pr_i_subtrrefdem]))
01595       checkprocess[pr_i_subtrrefdem]=1;
01596     else if (!strcmp(line,endnormal[pr_i_filtphase]))
01597       checkprocess[pr_i_filtphase]=1;
01598     else if (!strcmp(line,endnormal[pr_i_unwrap]))
01599       checkprocess[pr_i_unwrap]=1;
01600     else if (!strcmp(line,endnormal[pr_i_slant2h]))
01601       checkprocess[pr_i_slant2h]=1;
01602     else if (!strcmp(line,endnormal[pr_i_geocoding]))
01603       checkprocess[pr_i_geocoding]=1;
01604     else if (!strcmp(line,endnormal[pr_i_dinsar]))
01605       checkprocess[pr_i_dinsar]=1;
01606     else if (!strcmp(line,endnormal[pr_i_EXTRA2]))
01607       checkprocess[pr_i_EXTRA2]=1;
01608     }
01609   else
01610     {
01611     PRINT_ERROR("wrong input.")
01612     throw(unhandled_case_error);
01613     }
01614   } // END fillcheckprocess
01615 
01616 
01617 /****************************************************************
01618  *    fillprocessed                                             *
01619  *                                                              *
01620  * Fills processing array for checking.                         *
01621  * Line comes from file, if processed is finished,              *
01622  *  checkprocess is filled                                      *
01623  * Reads process controls:       1/0                            *
01624  *                                                              *
01625  * input:                                                       *
01626  *  - line from result file                                     *
01627  *  - (empty) process control array                             *
01628  *                                                              *
01629  * output:                                                      *
01630  *  - (filled) process control array                            *
01631  *     normally m_pr* is filled if there is a choice            *
01632  *     except for pr_orbits: m_* =getorb ;s_* =readleader       *
01633  *     if there are more methods, the first one is flagged      *
01634  *                                                              *
01635  * See documentation page 14                                    *
01636  *    Bert Kampes, 16-Dec-1998                                  *
01637  ****************************************************************/
01638 void fillprocessed(
01639         const char *line,
01640         int16 checkprocess[NUMPROCESSES+1],
01641         int16 fileid)
01642   {
01643   TRACE_FUNCTION("fillprocessed (BK 16-Dec-1998)")
01644   bool  space=false;                            // line must contain 2 words
01645   char  ch='\t';                                // isspace
01646   int32         tin;
01647 
01648   int32 linesz = strlen(line);                  // w/o \0
01649   if (linesz > 30) 
01650     return;
01651   char  word[ONE27];                            // should be enough
01652 // ______ Disect line ______
01653   for (register int32 i=0;i<linesz;i++)
01654     {
01655     ch = line[i];
01656     word[i]=ch;
01657     if (isspace(tin=ch))
01658       {
01659       space = true;
01660       if (line[i-1]==':')                               // process_control: 1/0
01661         {
01662         word[i]='\0';                                   // replace space by \0
01663         break;                                          // for
01664         }
01665       else 
01666         {
01667         return;
01668         }
01669       }
01670     }                                   
01671   if (!space) return;                           // must be a space in line
01672 
01673   int16 processflag;
01674   if (line[linesz-1]=='0')
01675     processflag=0;
01676   else if (line[linesz-1]=='1')
01677     processflag=1;
01678   else 
01679     return;
01680 
01681 // ====== Fill process control ======
01682   switch (fileid)
01683     {
01684     case MASTERID:
01685       if      (!strcmp(word,processcontrol[pr_m_readfiles]))
01686         checkprocess[pr_m_readfiles]=processflag;
01687       else if (!strcmp(word,processcontrol[pr_m_porbits]))
01688         checkprocess[pr_m_porbits]=processflag;
01689       else if (!strcmp(word,processcontrol[pr_m_crop]))
01690         checkprocess[pr_m_crop]=processflag;
01691 //____RaffaeleNutricato START MODIFICATION SECTION 14
01692       else if (!strcmp(word,processcontrol[pr_m_oversample])) 
01693         checkprocess[pr_m_oversample]=processflag; 
01694 //____RaffaeleNutricato END MODIFICATION SECTION 14
01695       else if (!strcmp(word,processcontrol[pr_m_filtazi]))
01696         checkprocess[pr_m_filtazi]=processflag;
01697       else if (!strcmp(word,processcontrol[pr_m_filtrange]))
01698         checkprocess[pr_m_filtrange]=processflag;
01699       else if (!strcmp(word,processcontrol[pr_m_EXTRA]))
01700         checkprocess[pr_m_EXTRA]=processflag;
01701       else
01702         DEBUG.print("(Strange, also a word ending on :), not correct word.");
01703       break;
01704 
01705     case SLAVEID:
01706       if      (!strcmp(word,processcontrol[pr_s_readfiles]))
01707         checkprocess[pr_s_readfiles]=processflag;
01708       else if (!strcmp(word,processcontrol[pr_s_porbits]))
01709         checkprocess[pr_s_porbits]=processflag;
01710       else if (!strcmp(word,processcontrol[pr_s_crop]))
01711         checkprocess[pr_s_crop]=processflag;
01712 //____RaffaeleNutricato START MODIFICATION SECTION 15
01713       else if (!strcmp(word,processcontrol[pr_s_oversample])) 
01714         checkprocess[pr_s_oversample]=processflag; 
01715 //____RaffaeleNutricato END MODIFICATION SECTION 15
01716       else if (!strcmp(word,processcontrol[pr_s_filtazi]))
01717         checkprocess[pr_s_filtazi]=processflag;
01718       else if (!strcmp(word,processcontrol[pr_s_filtrange]))
01719         checkprocess[pr_s_filtrange]=processflag;
01720       else if (!strcmp(word,processcontrol[pr_s_resample]))
01721         checkprocess[pr_s_resample]=processflag;
01722       else if (!strcmp(word,processcontrol[pr_s_EXTRA]))
01723         checkprocess[pr_s_EXTRA]=processflag;
01724       else
01725         DEBUG.print("(Strange, also a word ending on :), not correct word.");
01726       break;
01727 
01728     // ______ Interferogram ______
01729     case INTERFID:
01730       if      (!strcmp(word,processcontrol[pr_i_coarse]))
01731         checkprocess[pr_i_coarse]=processflag;
01732       else if (!strcmp(word,processcontrol[pr_i_coarse2]))
01733         checkprocess[pr_i_coarse2]=processflag;
01734       else if (!strcmp(word,processcontrol[pr_i_fine]))
01735         checkprocess[pr_i_fine]=processflag;
01736       else if (!strcmp(word,processcontrol[pr_i_coregpm]))
01737         checkprocess[pr_i_coregpm]=processflag;
01738       else if (!strcmp(word,processcontrol[pr_i_interfero]))
01739         checkprocess[pr_i_interfero]=processflag;
01740       else if (!strcmp(word,processcontrol[pr_i_coherence]))
01741         checkprocess[pr_i_coherence]=processflag;
01742       else if (!strcmp(word,processcontrol[pr_i_comprefpha]))
01743         checkprocess[pr_i_comprefpha]=processflag;
01744       else if (!strcmp(word,processcontrol[pr_i_subtrrefpha]))
01745         checkprocess[pr_i_subtrrefpha]=processflag;
01746       else if (!strcmp(word,processcontrol[pr_i_comprefdem]))
01747         checkprocess[pr_i_comprefdem]=processflag;
01748       else if (!strcmp(word,processcontrol[pr_i_subtrrefdem]))
01749         checkprocess[pr_i_subtrrefdem]=processflag;
01750       else if (!strcmp(word,processcontrol[pr_i_filtphase]))
01751         checkprocess[pr_i_filtphase]=processflag;
01752       else if (!strcmp(word,processcontrol[pr_i_unwrap]))
01753         checkprocess[pr_i_unwrap]=processflag;
01754       else if (!strcmp(word,processcontrol[pr_i_slant2h]))
01755         checkprocess[pr_i_slant2h]=processflag;
01756       else if (!strcmp(word,processcontrol[pr_i_geocoding]))
01757         checkprocess[pr_i_geocoding]=processflag;
01758       else if (!strcmp(word,processcontrol[pr_i_dinsar]))
01759         checkprocess[pr_i_dinsar]=processflag;
01760       else if (!strcmp(word,processcontrol[pr_i_EXTRA2]))
01761         checkprocess[pr_i_EXTRA2]=processflag;
01762       else
01763         DEBUG.print("(Strange, also a word ending on :), not correct word.");
01764       break;
01765 
01766     default:
01767       PRINT_ERROR("wrong input.")
01768       throw(unhandled_case_error);
01769     } // switch fileid
01770   } // END fillprocessed
01771 
01772 
01773 
01774 /****************************************************************
01775  *    filelines                                                 *
01776  *                                                              *
01777  * Returns number of \n (enters).                               *
01778  * input:                                                       *
01779  *  - filename                                                  *
01780  * output:                                                      *
01781  *  - number of eols.                                           *
01782  *                                                              *
01783  *    Bert Kampes, 10-Jun-1999                                  *
01784  ****************************************************************/
01785 int32 filelines(
01786         const char *file)
01787   {
01788   TRACE_FUNCTION("filelines (BK 10-Jun-1999)")
01789   char dummyline[ONE27];
01790   register int32 nlines = 0;
01791   //ifstream ifile(file, ios::in | ios::nocreate);
01792   ifstream ifile(file, ios::in);
01793   bk_assert(ifile,file,__FILE__,__LINE__);
01794   while (ifile)
01795     {
01796     ifile.getline(dummyline,ONE27,'\n');
01797     nlines++;
01798     }
01799   ifile.clear();// g++ v3.2 may have a problem else
01800   ifile.close();
01801   return nlines-1;
01802   }  // END filelines
01803 
01804 
01805 /****************************************************************
01806  *    existed                                                   *
01807  *                                                              *
01808  * Returns true if file exists.                                 *
01809  * input:                                                       *
01810  *  - filename                                                  *
01811  * output:                                                      *
01812  *  - true if existi, false if not.                             *
01813  *                                                              *
01814  *    Bert Kampes, 24-Dec-1998                                  *
01815  ****************************************************************/
01816 bool existed(
01817         const char *file)
01818   {
01819   bool exists = false;
01820   //ifstream ifile(file, ios::in | ios::nocreate);
01821   ifstream ifile(file, ios::in);
01822   if (ifile)
01823     {
01824     exists = true;
01825     DEBUG << "file: " << file << " does exist.";
01826     }
01827   else
01828     {
01829     DEBUG << "file: " << file << " does not exist.";
01830     }
01831   DEBUG.print();
01832 
01833   ifile.close();
01834   return exists;
01835 //  return ifile;
01836   } // END exist
01837 
01838 
01839 /****************************************************************
01840  *    removedatleader                                           *
01841  *                                                              *
01842  * Part containing datapoints from leader is removed
01843  *   from resultfile. (because precise orbits will bew there)
01844  *                                                              *
01845  * input:                                                       *
01846  *  - file                                                      *
01847  * output:                                                      *
01848  *  - void, updated logfile,                                    *
01849  *                                                              *
01850  *    Bert Kampes, 07-Jan-1999                                  *
01851  ****************************************************************/
01852 void removedatleader(
01853         const char* file)
01854   {
01855   TRACE_FUNCTION("removedatleader (BK 07-Jan-1999)")
01856 
01857 // ______Copy relevant part to tmp file______
01858 // ______ then rename file to old name ______
01859   //ifstream ifile(file, ios::in | ios::nocreate);
01860   ifstream ifile(file, ios::in);
01861   bk_assert(ifile,file,__FILE__,__LINE__);
01862   ofstream tmpfile("scratchtmp", ios::out | ios::trunc);
01863   bk_assert(tmpfile,"removedatleader: scratchtmp",__FILE__,__LINE__);
01864 
01865 // ______Copy upto data section______
01866   char                  dummyline[ONE27];
01867 
01868   ifile.getline(dummyline,ONE27,'\n');          // to prevent twice last line
01869   while (ifile && strcmp(dummyline,"*_Start_leader_datapoints")) // fixed string...
01870     {
01871     tmpfile << dummyline << endl;
01872     ifile.getline(dummyline,ONE27,'\n');
01873     }
01874   if (!ifile) return;                                   // file eof?
01875 
01876 // ______Dont copy data section______
01877   while (ifile && strcmp(dummyline,"* End_leader_datapoints:_NORMAL"))  // fixed string..
01878     {
01879     ifile.getline(dummyline,ONE27,'\n');
01880     }
01881   ifile.getline(dummyline,ONE27,'\n');                                          
01882 
01883 // ______Copy rest of file______
01884   while (ifile)
01885     {
01886     tmpfile << dummyline << endl;
01887     ifile.getline(dummyline,ONE27,'\n');
01888     }
01889 
01890 // ______Tidy up______
01891   ifile.close();
01892   tmpfile.close();
01893   if (rename("scratchtmp",file))                        // rename file
01894     {
01895     ERROR << "Could not rename file: scratchtmp to: " << file;
01896     PRINT_ERROR(ERROR.get_str())
01897     throw(file_error);
01898     }
01899   } // END removedatleader
01900 
01901 
01902 /****************************************************************
01903  *    filesize                                                  *
01904  *                                                              *
01905  * Returns uint filesize of (closed) file in bytes.             *
01906  * input:                                                       *
01907  *  - filename                                                  *
01908  * output:                                                      *
01909  *  - size (B)                                                  *
01910  *                                                              *
01911  *    Bert Kampes, 08-Jan-1999                                  *
01912  ****************************************************************/
01913 // inline uint filesize(
01914 uint filesize(
01915         const char* file)
01916   {
01917   TRACE_FUNCTION("filesize (BK 08-Jan-1999)")
01918   //ifstream ifile(file, ios::in | ios::ate | ios::nocreate);
01919   // problem of g++ with ate, app does work ok, but
01920   //ifstream ifile(file, ios::in | ios::nocreate);
01921   ifstream ifile(file, ios::in);
01922 #ifdef __DEBUG
01923   bk_assert(ifile,file,__FILE__,__LINE__);
01924 #endif
01925   ifile.seekg(0,ios::end);                      // pointer to end...
01926   // closed automatically
01927   return ifile.tellg();
01928   } // END filesize
01929 
01930 
01931 /****************************************************************
01932  * getoverlap                                                   *
01933  *                                                              *
01934  * overlap of 2 windows in same coord. system                   *
01935  #%// BK 21-Sep-2000
01936  ****************************************************************/
01937 window getoverlap(
01938         const window &master,
01939         const window &slave)
01940   {
01941   TRACE_FUNCTION("getoverlap (BK 10-Mar-1999)")
01942   window overlap = slave;
01943   if (master.linelo>overlap.linelo) overlap.linelo=master.linelo;
01944   if (master.linehi<overlap.linehi) overlap.linehi=master.linehi;
01945   if (master.pixlo >overlap.pixlo)  overlap.pixlo =master.pixlo;
01946   if (master.pixhi <overlap.pixhi)  overlap.pixhi =master.pixhi;
01947   return overlap;
01948   } // getoverlap
01949 
01950 
01951 /****************************************************************
01952  * getoverlap                                                   *
01953  *                                                              *
01954  * compute approx. rectangular overlap (master coord.)          *
01955  * between master/slave with help of transformation polynomial  *
01956  * Bert Kampes 10-Mar-99                                        *
01957  ****************************************************************/
01958 window getoverlap(
01959         const slcimage      &master,
01960         const slcimage      &slave,
01961         const matrix<real8> &cpmL,
01962         const matrix<real8> &cpmP)
01963   {
01964   TRACE_FUNCTION("getoverlap (BK 10-Mar-1999)")
01965 
01966 // ______ Normalize data for polynomial ______
01967   const real8 minL = master.originalwindow.linelo;
01968   const real8 maxL = master.originalwindow.linehi;
01969   const real8 minP = master.originalwindow.pixlo;
01970   const real8 maxP = master.originalwindow.pixhi;
01971 
01972   INFO << "getoverlap: polynomial normalized by factors: "
01973        << minL << " " << maxL << " " << minP << " " << maxP
01974        << " to [-2,2]";
01975   INFO.print();
01976 
01977 // ______offset = A(slave system) - A(master system)______
01978 // ______Corners of slave in master system______
01979 // ______Offsets for slave corners (approx.)______
01980 // ______ approx: defined as offset = f(l,p)_M in master system not slave.
01981   real8 approxoffL = cpmL(0,0);                         // zero order term;
01982   real8 approxoffP = cpmP(0,0);                         // zero order term;
01983 
01984 //  real8 sL00 = slave.currentwindow.linelo - 
01985 //                polyval(slave.currentwindow.linelo - approxoffL,
01986 //                        slave.currentwindow.pixlo  - approxoffP, cpmL);
01987 // ______ Use normalized polynomial ______
01988   const real8 sL00 = slave.currentwindow.linelo - 
01989        polyval(normalize(real8(slave.currentwindow.linelo)-approxoffL,minL,maxL),
01990                normalize(real8(slave.currentwindow.pixlo) -approxoffP,minP,maxP),
01991                cpmL);
01992   const real8 sP00 = slave.currentwindow.pixlo -
01993        polyval(normalize(real8(slave.currentwindow.linelo)-approxoffL,minL,maxL),
01994                normalize(real8(slave.currentwindow.pixlo) -approxoffP,minP,maxP),
01995                cpmP);
01996   const real8 sL0N = slave.currentwindow.linelo -
01997        polyval(normalize(real8(slave.currentwindow.linelo)-approxoffL,minL,maxL),
01998                normalize(real8(slave.currentwindow.pixhi) -approxoffP,minP,maxP),
01999                cpmL);
02000   const real8 sP0N = slave.currentwindow.pixhi -
02001        polyval(normalize(real8(slave.currentwindow.linelo)-approxoffL,minL,maxL),
02002                normalize(real8(slave.currentwindow.pixhi) -approxoffP,minP,maxP),
02003                cpmP);
02004   const real8 sLN0 = slave.currentwindow.linehi -
02005        polyval(normalize(real8(slave.currentwindow.linehi)-approxoffL,minL,maxL),
02006                normalize(real8(slave.currentwindow.pixlo) -approxoffP,minP,maxP),
02007                cpmL);
02008   const real8 sPN0 = slave.currentwindow.pixlo -
02009        polyval(normalize(real8(slave.currentwindow.linehi)-approxoffL,minL,maxL),
02010                normalize(real8(slave.currentwindow.pixlo) -approxoffP,minP,maxP),
02011                cpmP);
02012   const real8 sLNN = slave.currentwindow.linehi -
02013        polyval(normalize(real8(slave.currentwindow.linehi)-approxoffL,minL,maxL),
02014                normalize(real8(slave.currentwindow.pixhi) -approxoffP,minP,maxP),
02015                cpmL);
02016   const real8 sPNN = slave.currentwindow.pixhi -
02017        polyval(normalize(real8(slave.currentwindow.linehi)-approxoffL,minL,maxL),
02018                normalize(real8(slave.currentwindow.pixhi) -approxoffP,minP,maxP),
02019                cpmP);
02020 
02021 
02022 //  // ______make window rectangular + int______
02023 //  // ______window is uint type______
02024 //    if (sL00 < 0.) sL00 = 0.;
02025 //    if (sP00 < 0.) sP00 = 0.;
02026 //    window slaveinmaster = {ceil(max(sL00,sL0N)),
02027 //                            floor(min(sLN0,sLNN)),
02028 //                            ceil(max(sP00,sPN0)),
02029 //                            floor(min(sP0N,sPNN))};
02030 
02031 
02032 // ______Corners of overlap master,slave in master system______
02033   window win;
02034   win.linelo = max(int32(master.currentwindow.linelo),
02035                    int32(ceil(max(sL00,sL0N))));
02036   win.linehi = min(int32(master.currentwindow.linehi),
02037                    int32(floor(min(sLN0,sLNN))));
02038   win.pixlo  = max(int32(master.currentwindow.pixlo),
02039                    int32(ceil(max(sP00,sPN0))));
02040   win.pixhi  = min(int32(master.currentwindow.pixhi),
02041                    int32(floor(min(sP0N,sPNN))));
02042 
02043 #ifdef __DEBUG
02044   DEBUG.print("Finished getoverlap");
02045   DEBUG.print("Approximate overlap master/slave window:");
02046   win.disp();
02047 #endif
02048   return win;
02049   } // END getoverlap
02050 
02051 
02052 /****************************************************************
02053  *    readcoeff                                                 *
02054  *                                                              *
02055  * Pattern is searched in file (1st word),                      *
02056  * After Pattern the Ncoeffs must follow                        *
02057  * next (Ncoeff) lines are assumed to contain the coefficients  *
02058  *                                                              *
02059  * e.g.: readcoeff(resfile,"Degree_flat:",9)                    *
02060  *                                                              *
02061  * input:                                                       *
02062  *  - file name to search                                       *
02063  *  - pattern to search for                                     *
02064  *                                                              *
02065  * output:                                                      *
02066  *  - matrix<real8> coefficients(Nc , 1)                        *
02067  *                                                              *
02068  *    Bert Kampes, 12-Mar-1999                                  *
02069  ****************************************************************/
02070 matrix<real8> readcoeff(
02071         const char* file,
02072         const char* pattern,
02073         const int16 Ncoeff)
02074   {
02075   TRACE_FUNCTION("readcoeff (BK 12-Mar-1999)")
02076   char                  dummyline[ONE27];
02077   char                  word[EIGHTY];
02078   bool                  foundword = false;
02079   matrix<real8>         coeffs(Ncoeff,1);               // store coefficients
02080 
02081 
02082   //ifstream infile(file, ios::in | ios::nocreate);
02083   ifstream infile(file, ios::in);
02084   bk_assert(infile,file,__FILE__,__LINE__);
02085 
02086 // ====== Search infile ======
02087   while (infile)
02088     {
02089     infile >> word;
02090     if (strcmp(pattern,word))                           // no pattern match.
02091       {
02092       infile.getline(dummyline,ONE27,'\n');             // goto next line.
02093       }
02094     else                                                // pattern match.
02095       {
02096       infile.getline(dummyline,ONE27,'\n');             // start data
02097       foundword = true;
02098       for (register int32 i=0;i<Ncoeff;i++)
02099         {
02100         infile >> coeffs(i,0);
02101         infile.getline(dummyline,ONE27,'\n');           // goto next line.
02102         }
02103       break;                                            // file
02104       }                                                 // else
02105     }                                                   // file
02106   infile.close();
02107 
02108   if (!foundword)
02109     {
02110     ERROR << "readcoeff: file: " << file
02111          << ": could not find string \"" << pattern << "\".";
02112     PRINT_ERROR(ERROR.get_str());
02113     throw(file_error);
02114     }
02115   else
02116     {
02117     INFO << "read: " << Ncoeff << " coefficients after: \""
02118          << pattern << "\"";
02119     INFO.print();
02120     }
02121 
02122   return coeffs;
02123   } // END readcoeff
02124 
02125 
02126 
02127 /****************************************************************
02128  *    openfstream                                               *
02129  *                                                              *
02130  *  Open an input file stream by name                           *
02131  * input:                                                       *
02132  *  - fstream                                                   *
02133  *  - filename                                                  *
02134  * output:                                                      *
02135  *  - opened file, check yourself with assert                   *
02136  *                                                              *
02137  *    Bert Kampes, 11-Sep-2004                                  *
02138  ****************************************************************/
02139 void openfstream(
02140         ifstream &stream,
02141         const char* ifilename)
02142   {
02143   TRACE_FUNCTION("openfstream (BK 11-Sep-2004)")
02144   DEBUG << "Opening input file: " << ifilename;
02145   DEBUG.print();
02146   #ifdef __NO_IOS_BINARY__
02147   stream.open(ifilename, ios::in);
02148   #else
02149   stream.open(ifilename, ios::in | ios::binary);
02150   #endif
02151   } // END openfstream
02152 
02153 
02154 
02155 /****************************************************************
02156  *    openfstream                                               *
02157  *                                                              *
02158  *  Open an output file stream by name                          *
02159  * input:                                                       *
02160  *  - ofstream                                                  *
02161  *  - filename                                                  *
02162  *  - overwrite bool                                            *
02163  * output:                                                      *
02164  *  - opened file, check yourself with assert                   *
02165  *                                                              *
02166  *    Bert Kampes, 11-Sep-2004                                  *
02167  ****************************************************************/
02168 void openfstream(
02169         ofstream &stream,
02170         const char* ofilename,
02171         const bool overwrite)
02172   {
02173   TRACE_FUNCTION("openfstream (BK 11-Sep-2004)")
02174   DEBUG << "Opening output file: " << ofilename;
02175   DEBUG.print();
02176   if (overwrite == true)
02177     {
02178     #ifdef __NO_IOS_BINARY__
02179     stream.open(ofilename, ios::out | ios::trunc);
02180     #else
02181     stream.open(ofilename, ios::out | ios::binary | ios::trunc);
02182     #endif
02183     }
02184   else
02185     {
02186     if (existed(ofilename) == true)
02187       {
02188       ERROR << "output file \": " 
02189             << ofilename << "\" exists, use OVERWRITE ON";
02190       PRINT_ERROR(ERROR.get_str())
02191       throw(file_error);
02192       }
02193     else
02194       {
02195       #ifdef __NO_IOS_BINARY__
02196       stream.open(ofilename, ios::out);
02197       #else
02198       stream.open(ofilename, ios::out | ios::binary);
02199       #endif
02200       }
02201     }
02202   } // END openfstream
02203 
02204 
02205 
02206 
02207 /****************************************************************
02208  *    bk_assert                                                 *
02209  *                                                              *
02210  *  Check opened input fstream                                  *
02211  * input:                                                       *
02212  *  - fstream                                                   *
02213  *  - filedescription                                           *
02214  *  - __FILE__                                                  *
02215  *  - __LINE__                                                  *
02216  * output:                                                      *
02217  *  - exit or ok                                                *
02218  *                                                              *
02219  *    Bert Kampes, 04-Jun-1999                                  *
02220  ****************************************************************/
02221 void bk_assert(
02222         const ifstream &stream,
02223         const char* ofilename,
02224         const char* callingfile,
02225         int32 linenumber)
02226   {
02227   TRACE_FUNCTION("bk_assert (BK 04-Jun-1999)")
02228   DEBUG << "Opened input file:  " << ofilename;
02229   DEBUG.print();
02230   if (!stream)
02231     {
02232     ERROR << "Unable to open input file: "      << ofilename
02233          << " in source file: "                 << callingfile
02234          << " at line: "                        << linenumber;
02235     PRINT_ERROR(ERROR.get_str());
02236     throw(file_error);
02237     }
02238   } // END bk_assert
02239 
02240 
02241 /****************************************************************
02242  *    bk_assert                                                 *
02243  *                                                              *
02244  *  Check opened output fstream                                 *
02245  * input:                                                       *
02246  *  - fstream                                                   *
02247  *  - filedescription                                           *
02248  *  - __FILE__                                                  *
02249  *  - __LINE__                                                  *
02250  * output:                                                      *
02251  *  - exit or ok                                                *
02252  *                                                              *
02253  *    Bert Kampes, 04-Jun-1999                                  *
02254  ****************************************************************/
02255 void bk_assert(
02256         const ofstream &stream,
02257         const char* ofilename,
02258         const char* callingfile,
02259         int32 linenumber)
02260   {
02261   TRACE_FUNCTION("bk_assert (BK 04-Jun-1999)")
02262   DEBUG << "Opened output file: " << ofilename;
02263   DEBUG.print();
02264   if (!stream)
02265     {
02266     ERROR << "Unable to open output file: "     << ofilename
02267          << " in source file: "                 << callingfile
02268          << " at line: "                        << linenumber
02269          << " (OVERWRIT OFF/non existing directory?)";
02270     PRINT_ERROR(ERROR.get_str());
02271     throw(file_error);
02272     }
02273   } // END bk_assert
02274 
02275 
02276 /****************************************************************
02277  *    tolower                                                   *
02278  *                                                              *
02279  * Convert string to lower case                                 * 
02280  * input:                                                       *
02281  *  - __LINE__                                                  *
02282  * output:                                                      *
02283  *  - converted lowercase string                                *
02284  *                                                              *
02285  *    Bert Kampes, 06-Sep-1999                                  *
02286  ****************************************************************/
02287 void tolower(char *s)
02288   {
02289   TRACE_FUNCTION("tolower (BK 06-Sep-1999)")
02290   while (*s != '\0')
02291     *s++ = tolower(*s);                 // cctype
02292   }
02293 
02294 /****************************************************************
02295  *    toupper                                                   *
02296  *                                                              *
02297  * Convert string to upper case                                 * 
02298  * input:                                                       *
02299  *  - __LINE__                                                  *
02300  * output:                                                      *
02301  *  - converted uppercase string                                *
02302  *                                                              *
02303  *    Bert Kampes, 06-Sep-1999                                  *
02304  ****************************************************************/
02305 void toupper(char *s)
02306   {
02307   TRACE_FUNCTION("toupper (BK 06-Sep-1999)")
02308   while (*s != '\0')
02309     *s++ = toupper(*s);                 // cctype
02310   }
02311 
02312 

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