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

step1routines.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/step1routines.cc,v $
00032  * $Revision: 3.31 $
00033  * $Date: 2005/04/13 11:12:23 $
00034  * $Author: kampes $
00035  *
00036  * routines for initial work, reading SLC,
00037  * writing to internal format.
00038  * see e.g: http://earth.esa.int:81/sarslc
00039  ****************************************************************/
00040 
00041 
00042 #include "matrixbk.hh"
00043 #include "constants.hh"
00044 #include "slcimage.hh"                  // my slc image class
00045 #include "ioroutines.hh"                // ?
00046 #include "exceptions.hh"                 // my exceptions class
00047 
00048 #include <fstream>                      // for streams
00049 #include <iomanip>                      // setw
00050 #include <cstdlib>                      // atoi, system
00051 #include <cstring>                      // strcmp
00052 #include <cstdio>                       // some compilers, remove function
00053 #include <ctime>                        // some compilers, strptime function
00054 #include <netinet/in.h>                 // ntohl byteorder x86-HP unix
00055 //____RaffaeleNutricato START MODIFICATION SECTION 1
00056 #include <algorithm>        // max,min
00057 #include "conversion.hh"    // cr4toci2
00058 #include "utilities.hh"     // sinc8
00059 //____RaffaeleNutricato END MODIFICATION SECTION 1
00060 char *strptime(const char *s, const char  *format,  struct tm *tm);
00061 
00062 
00063 
00064 /****************************************************************
00065  *    julday()                                                  *
00066  * mm JAN=1, FEB=2, etc; id: day=1,2,3.., iyyy=1996             *
00067  *                                                              *
00068  #%// Bert Kampes, 07-Apr-2005
00069  ****************************************************************/
00070 #define IGREG (15+31L*(10+12L*1582))
00071 int32 julday(int32 id, int32 mm, int32 iyyy)
00072   {
00073   int32 jul;
00074   int32 ja,jy,jm;
00075   if (iyyy==0) 
00076     {
00077     //PRINT_ERROR("julday: error")
00078     //throw(some_error);
00079     WARNING.print("julday: year=0; impossible; continuing (only for Btemp computation)");
00080     return 0;
00081     }
00082   if (iyyy<0) ++iyyy;
00083   if (mm>2)
00084     {
00085     jy=iyyy;
00086     jm=mm+1;
00087     }
00088   else
00089     {
00090     jy=iyyy-1;
00091     jm=mm+13;
00092     }
00093   jul = int32(floor(365.25*jy)+floor(30.6001*jm)+id+1720995);
00094   if (id+31L*(mm+12L*iyyy) >= IGREG) 
00095     {
00096     ja   = int32(0.01*jy);
00097     jul += 2-ja+int32(0.25*ja);
00098     }
00099   return jul;
00100   }
00101 #undef IGREG
00102 
00103 
00104 
00105 /****************************************************************
00106  *    readvolume                                                *
00107  *                                                              *
00108  * reads volumefile                                             *
00109  *  and writes to scratchlogfile and resfile                    *
00110  *  checks if master is same as slave by id                     *
00111  * see: annex C ERS SAR.SLC CCTand EXABYTE                      *
00112  *      doc:er-is-epo-gs-5902.3                                 *
00113  http://earth.esa.int/rootcollection/sysutil/01008.html
00114  *                                                              *
00115  * input:                                                       *
00116  *  - struct: input options for readfiles                       *
00117  *  - 3 checks with other (slave or master) volumefile          *
00118  * output:                                                      *
00119  *  - void, scratchfiles: ?                                     *
00120  *                                                              *
00121  *    Bert Kampes, 11-Dec-1998                                  *
00122  * if radarsat, skip record number 4 of 360 bytes.              *
00123  * according to specs                                           *
00124  #%// Bert Kampes, 02-Aug-2004                                  *
00125  ****************************************************************/
00126 void readvolume(
00127         input_readfiles &readfiles_arg, 
00128         const char* checkvol1,
00129         const char* checkvol2,
00130         const char* checkvol3)
00131   {
00132   TRACE_FUNCTION("readvolume (BK 11-Dec-1998)")
00133   const int16           sizeb1 = 1,             // some constants for reading
00134                         sizeb4 = 4,             //   binary fields.
00135                         sizei4 = 4,             //   binary fields.
00136                         sizei8 = 8,
00137                         sizea8 = 8,
00138                         sizea12 = 12,
00139                         sizea16 = 16,
00140                         sizea28 = 28,
00141                         sizea40 = 40,
00142                         sizea60 = 60;
00143   uint                  lenrec1,                // length of record1
00144                         lenrec2,                // length of record2
00145                         lenrec3,                // length of record3
00146                         lenrec4,                // length of record4
00147                         numpointrec,            // volfile...
00148                         numrec,                 // volfile...
00149                         numvol;                 // volfile...
00150   char                  c4dummy[5],             // correctly 5 for \0
00151                         c8date[9],
00152                         c8time[9],
00153                         c8agency[9],            // correctly 9 for \0
00154                         c8nlins[9],             // correctly 9 for \0
00155                         c12logvol[13],
00156                         c12country[13],
00157                         c12facility[13],        // correctly 13 for \0
00158                         c16physid[17],
00159                         c16logvolid[17],
00160                         c16setid[17],
00161                         c16checkfilename[17],
00162                         c16dataref[17],         // correctly 17 for \0
00163                         c28leaderrefclass[29],
00164                         c28datarefclass[29],
00165                         c40typespec[41],
00166                         c40physvolid[41],
00167                         c40sceneid[41],
00168                         c40sceneloc[41],
00169                         c60product[61];
00170   // --- Check for Atlantis processor (RSAT?) #%// Bert Kampes, 02-Aug-2004 ---
00171   uint rec_seq;// type B4
00172   unsigned char rec_sub1, rec_type, rec_sub2, rec_sub3;// type B1
00173 
00174 // ======Open files====== 
00175   // ___ check if opened correctly, if not, try to use uppercase
00176   // ___ from SCENE1/lea_01.001 #%// BK 27-Nov-2003
00177   ifstream volumefile;
00178   openfstream(volumefile,readfiles_arg.volfile);
00179   bk_assert(volumefile,readfiles_arg.volfile,__FILE__,__LINE__);
00180 
00181 // ______First check control arguments, allow check to be wrong ______
00182   DEBUG.print("readvol: check on filename consistency.");
00183   for (register int32 i=0; i<999; i++)                          // try some times
00184     {
00185     volumefile.seekg(44,ios::beg);
00186     volumefile.read((char*)&c16physid,sizea16);         // physical logical volume ID
00187     c16physid[16]='\0';
00188     volumefile.read((char*)&c16logvolid,sizea16);       // logical volume ID
00189     c16logvolid[16]='\0';
00190     volumefile.read((char*)&c16setid,sizea16);          // volume set ID
00191     c16setid[16]='\0';
00192 
00193     if ((!strcmp(checkvol1,c16physid)) &&                       // check failed
00194         (!strcmp(checkvol2,c16logvolid)) &&
00195         (!strcmp(checkvol3,c16setid)))
00196       {
00197       if (i==0) // first time
00198         {
00199         WARNING.print(
00200         "Volume file of master and slave seem to be the same, please change cd.");
00201         getanswer();                                    // wait
00202         }
00203 
00204       else if (i==1)    // second time
00205         {
00206         WARNING << "ID of volume file 1: "
00207              << c16physid << ": " << c16logvolid << ": " << c16setid;
00208         WARNING.print();
00209         WARNING << "ID of volume file 2: "
00210              << checkvol1 << ":" << checkvol2 << ":" << checkvol3;
00211         WARNING.print();
00212         WARNING.print("Next time I will assume they are different.");
00213         getanswer();                                    // wait
00214         }
00215 
00216       else // if i == 2, enough tries
00217         {
00218         break;
00219         }
00220       }
00221     else                                                // check passed
00222       {
00223       break;
00224       }
00225     }
00226 
00227 
00228   // ======Read volumefile======
00229   // --- RECORD 1 ---
00230   DEBUG.print("record 1 of volume file.");
00231   volumefile.seekg(0,ios::beg);// place pointer at beginning of file
00232   volumefile.read((char*)&rec_seq,sizeb4);// record number
00233   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
00234   volumefile.read((char*)&rec_sub1,sizeb1);// first record sub type code
00235   volumefile.read((char*)&rec_type,sizeb1);// record type code
00236   volumefile.read((char*)&rec_sub2,sizeb1);// second record sub type code
00237   volumefile.read((char*)&rec_sub3,sizeb1);// third record sub type code
00238   DEBUG.print("Expecting record 1 with code {192,192,18,18}");
00239   DEBUG << "rec_seq: " << rec_seq 
00240         << "; rec_sub1: " << int(rec_sub1)
00241         << "; rec_type: " << int(rec_type)
00242         << "; rec_sub2: " << int(rec_sub2)
00243         << "; rec_sub3: " << int(rec_sub3);
00244   DEBUG.print();
00245 
00246   // --- Read important fields ---
00247   volumefile.seekg(8,ios::beg);
00248   volumefile.read((char*)&lenrec1,sizeb4);              // length of record1
00249   lenrec1 = ntohl(lenrec1);     // bk 6 jul 2000, byteorder x86 machines.
00250   if (lenrec1 != 360 )
00251     {
00252     WARNING.print("probably something wrong here, byte order x86 (?).");
00253     WARNING << "readvolume: length of record 1 = \""
00254          <<  lenrec1 << "\"; expected \"360\" for ESA SLC (full scene).";
00255     WARNING.print();
00256     }
00257   volumefile.seekg(32,ios::beg);
00258   volumefile.read((char*)&c12logvol,sizea12);           // logical volume etc.
00259   c12logvol[12]='\0';
00260   volumefile.seekg(112,ios::beg);
00261   volumefile.read((char*)&c8date,sizea8);               // generating date
00262   c8date[8]='\0';
00263   volumefile.read((char*)&c8time,sizea8);               // generating time
00264   c8time[8]='\0';
00265   volumefile.read((char*)&c12country,sizea12);          // generating country
00266   c12country[12]='\0';
00267   volumefile.read((char*)&c8agency,sizea8);             // generating agency
00268   c8agency[8]='\0';
00269   volumefile.read((char*)&c12facility,sizea12);         // generating facility
00270   c12facility[12]='\0';
00271   volumefile.read((char*)&c4dummy,sizei4);              // #pointer records in vol.
00272   c4dummy[4]='\0';
00273   numpointrec = atoi(c4dummy);
00274 
00275   if (readfiles_arg.sensor_id!=SLC_RSAT)
00276     {
00277     if (numpointrec!=2)
00278       {
00279       ERROR << "readvolume: number of pointer records = \""
00280            <<  c4dummy << "\"; expected \"2\" for ESA SLC (full scene)." << ends;
00281       WARNING.print(ERROR.get_str());// Jan Kianicka report atlantis processor
00282       WARNING.print("but for Atlantis processor this may be correct?");
00283       ERROR.reset();
00284       }
00285     }
00286   else
00287     if (numpointrec!=3)
00288       WARNING.print("expected 3 poitner records for Radarsat?");
00289 
00290   volumefile.read((char*)&c4dummy,sizei4);              // #records in vol.
00291   c4dummy[4]='\0';
00292   numrec = atoi(c4dummy);
00293   if (readfiles_arg.sensor_id!=SLC_RSAT)
00294     {
00295     if (numrec!=4)
00296       {
00297       ERROR << "readvolume: number of records = \""
00298            <<  c4dummy << "\"; expected \"4\" for ESA SLC (full scene)." << ends;
00299       WARNING.print(ERROR.get_str());
00300       ERROR.reset();
00301       }
00302     }
00303   else
00304     if (numrec!=5)
00305       WARNING.print("expected 5 records for Radarsat?");
00306   volumefile.read((char*)&c4dummy,sizei4);              // #vol.
00307   c4dummy[4]='\0';
00308   numvol = atoi(c4dummy);
00309   if (readfiles_arg.sensor_id!=SLC_RSAT)
00310     if (numvol!=1)
00311       {
00312       ERROR << "readvolume: number of volumes = \""
00313            <<  c4dummy << "\"; expected \"1\" for ESA SLC (full scene)." << ends;
00314       WARNING.print(ERROR.get_str());
00315       ERROR.reset();
00316       }
00317 
00318 
00319   // --- RECORD 2 ---
00320   const uint startrec2 = lenrec1;
00321   volumefile.seekg(startrec2,ios::beg);
00322   volumefile.read((char*)&rec_seq,sizeb4);// record number
00323   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
00324   volumefile.read((char*)&rec_sub1,sizeb1);// first record sub type code
00325   volumefile.read((char*)&rec_type,sizeb1);// record type code
00326   volumefile.read((char*)&rec_sub2,sizeb1);// second record sub type code
00327   volumefile.read((char*)&rec_sub3,sizeb1);// third record sub type code
00328   DEBUG.print("Expecting record 2 with code {219,192,18,18}");
00329   DEBUG << "rec_seq: " << rec_seq 
00330         << "; rec_sub1: " << int(rec_sub1)
00331         << "; rec_type: " << int(rec_type)
00332         << "; rec_sub2: " << int(rec_sub2)
00333         << "; rec_sub3: " << int(rec_sub3);
00334   DEBUG.print();
00335 
00336   // --- Read important fields ---
00337   volumefile.seekg(startrec2+8,ios::beg);               //  leader file pointer rec.
00338   DEBUG.print("record 2 of volume file.");
00339   volumefile.read((char*)&lenrec2,sizeb4);              // length of record2
00340   lenrec2 = ntohl(lenrec2);     // bk 6 jul 2000, byteorder x86 machines.
00341   if (lenrec2 != 360 )
00342     {
00343     WARNING.print("probably something wrong here, byte order x86. (?)");
00344     WARNING << "readvolume: length of record 2 = \""
00345          <<  lenrec2 << "\"; expected \"360\" for ESA SLC (full scene).";
00346     WARNING.print();
00347     }
00348   volumefile.seekg(startrec2+20,ios::beg);
00349   volumefile.read((char*)&c16checkfilename,sizea16);    // referenced file name
00350   c16checkfilename[16]='\0';
00351   volumefile.read((char*)&c28leaderrefclass,sizea28);   // referenced file class
00352   c28leaderrefclass[28]='\0';
00353 
00354 
00355   // --- RECORD 3 ---
00356   DEBUG.print("record 3 of volume file.");
00357   const uint startrec3 = lenrec1 + lenrec2;
00358   volumefile.seekg(startrec3,ios::beg);
00359   volumefile.read((char*)&rec_seq,sizeb4);// record number
00360   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
00361   volumefile.read((char*)&rec_sub1,sizeb1);// first record sub type code
00362   volumefile.read((char*)&rec_type,sizeb1);// record type code
00363   volumefile.read((char*)&rec_sub2,sizeb1);// second record sub type code
00364   volumefile.read((char*)&rec_sub3,sizeb1);// third record sub type code
00365   DEBUG.print("Expecting record 3 with code {219,192,18,18}");
00366   DEBUG << "rec_seq: " << rec_seq 
00367         << "; rec_sub1: " << int(rec_sub1)
00368         << "; rec_type: " << int(rec_type)
00369         << "; rec_sub2: " << int(rec_sub2)
00370         << "; rec_sub3: " << int(rec_sub3);
00371   DEBUG.print();
00372 
00373   // --- Read important fields ---
00374   volumefile.seekg(startrec3+8,ios::beg);               //  data file pointer rec.
00375   volumefile.read((char*)&lenrec3,sizeb4);              // length of record3
00376   lenrec3 = ntohl(lenrec3);     // bk 6 jul 2000, byteorder x86 machines.
00377   if (lenrec3 != 360 )
00378     {
00379     WARNING.print("probably something wrong here, byte order x86. (?)");
00380     WARNING << "readvolume: length of record 3 = \""
00381          <<  lenrec3 << "\"; expected \"360\" for ESA SLC (full scene).";
00382     WARNING.print();
00383     }
00384   volumefile.seekg(startrec3+20,ios::beg);
00385   volumefile.read((char*)&c16dataref,sizea16);          // referenced file name
00386   c16dataref[16]='\0';
00387   volumefile.read((char*)&c28datarefclass,sizea28);     // referenced file class
00388   c28datarefclass[28]='\0';
00389   volumefile.seekg(startrec3+100,ios::beg);             // numlines for checking
00390   volumefile.read((char*)&c8nlins,sizei8);
00391   c8nlins[8]='\0';
00392 
00393 
00394   // --- RECORD 4 ---
00395   uint startrec4 = lenrec1 + lenrec2 + lenrec3;
00396   //if (readfiles_arg.sensor_id==SLC_RSAT)
00397   //   startrec4=startrec4+360;// skip trailer record for RSAT
00398   DEBUG.print("record 4 of volume file.");
00399   DEBUG << "readvolume::rec4: start at byte: " << startrec4;
00400   DEBUG.print();
00401   // --- Check this record, RSAT has for us useless trailer info as rec.4 ---
00402   // --- while next record of 360 is the text record of ERS ---
00403   // ---start test for ATLANTIS (RSAT) ------------------------------------------
00404   DEBUG.print("VMP: Expecting record 4 with code {18,63,18,18}");
00405   volumefile.seekg(startrec4,ios::beg);
00406   volumefile.read((char*)&rec_seq,sizeb4);// record number
00407   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
00408   volumefile.read((char*)&rec_sub1,sizeb1);// first record sub type code
00409   volumefile.read((char*)&rec_type,sizeb1);// record type code
00410   volumefile.read((char*)&rec_sub2,sizeb1);// second record sub type code
00411   volumefile.read((char*)&rec_sub3,sizeb1);// third record sub type code
00412   DEBUG << "rec_seq: " << rec_seq 
00413         << "; rec_sub1: " << int(rec_sub1)
00414         << "; rec_type: " << int(rec_type)
00415         << "; rec_sub2: " << int(rec_sub2)
00416         << "; rec_sub3: " << int(rec_sub3);
00417   DEBUG.print();
00418   if (int(rec_sub1)==18 && int(rec_type)==63 && int(rec_sub2)==18 && int(rec_sub3)==18)
00419     {
00420     DEBUG.print("This is the expected text record with code {18,63,18,18}");
00421     readfiles_arg.sar_processor = SARPR_VMP;// set determined sar processor/format
00422     }
00423   else
00424     {
00425     //WARNING.print("This is not the expected text record, trying next one.")
00426     readfiles_arg.sar_processor = SARPR_ATL;// set determined sar processor/format
00427     if (readfiles_arg.sensor_id!=SLC_RSAT)
00428       {
00429       DEBUG.print("This is NOT the expected text record with code {18,63,18,18}");
00430       DEBUG.print("I assume in following Atlantis processed data (ERS or RSAT).");
00431       DEBUG.print("If this is not the case, please contact b.m.kampes@lr.tudelft.nl");
00432       }
00433     volumefile.seekg(startrec4+8,ios::beg);             //  text record
00434     volumefile.read((char*)&lenrec4,sizeb4);            // length of record4
00435     lenrec4   = ntohl(lenrec4); // bk 6 jul 2000, byteorder x86 machines.
00436     startrec4 = startrec4 + lenrec4;// hopefully there is a next record
00437     }
00438   // ---end test for ATLANTIS (RSAT) -------------------------------------------
00439 
00440   // --- Read important fields ---
00441   volumefile.seekg(startrec4+8,ios::beg);               //  text record
00442   volumefile.read((char*)&lenrec4,sizeb4);              // length of record4
00443   lenrec4 = ntohl(lenrec4);     // bk 6 jul 2000, byteorder x86 machines.
00444   if (lenrec4 != 360 )
00445     {
00446     WARNING.print("probably something wrong here, byte order x86. (?)");
00447     WARNING << "readvolume: length of record 3 = \""
00448          <<  lenrec4 << "\"; expected \"360\" for ESA SLC (full scene).";
00449     WARNING.print();
00450     }
00451   volumefile.seekg(startrec4+16,ios::beg);
00452   volumefile.read((char*)&c40typespec,sizea40);         // product type specifier 
00453   c40typespec[40]='\0';
00454   volumefile.read((char*)&c60product,sizea60);          // loc&date product gen.
00455   c60product[60]='\0';
00456   volumefile.read((char*)&c40physvolid,sizea40);        // physical vol id
00457   c40physvolid[40]='\0';
00458   volumefile.read((char*)&c40sceneid,sizea40);          // scene id
00459   c40sceneid[40]='\0';
00460   volumefile.read((char*)&c40sceneloc,sizea40);         // scene loc
00461   c40sceneloc[40]='\0';
00462 
00463   volumefile.close();
00464 
00465 
00466 // ====== Write results to scratch files ======
00467   ofstream scratchlogfile("scratchlogvol", ios::out | ios::trunc);
00468   bk_assert(scratchlogfile,"scratchlogvol",__FILE__,__LINE__);
00469 
00470 // ______Write information to scratchfiles______
00471   scratchlogfile << "\n*******************************************************************"
00472                  << "\n* EXTRACTED DATA FROM VOLUME FILE: " 
00473                  <<  readfiles_arg.volfile << " *"
00474                  << "\n*******************************************************************"
00475 
00476                  << "\n\nVolume descriptor record"
00477                  << "\n------------------------"
00478                  << "\nLogical volume generating facility software "
00479                  << "\n +release and revision level: \t\t\t"
00480                  <<  c12logvol
00481                  << "\nID of physical volume containing "
00482                  << "\n +this volume descriptor: \t\t\t"
00483                  <<  c16physid
00484                  << "\nLogical volume identifier: \t\t\t"
00485                  <<  c16logvolid
00486                  << "\nVolume set identifier: \t\t\t\t"
00487                  <<  c16setid
00488                  << "\nLogical volume creation date (YYYYMMDD): \t"
00489                  <<  c8date
00490                  << "\nLogical volume creation time (HHMMSSDD): \t"     // DD=deci-secs
00491                  <<  c8time
00492                  << "\nLogical volume generation country: \t\t"
00493                  <<  c12country
00494                  << "\nLogical volume generating agency: \t\t"
00495                  <<  c8agency
00496                  << "\nLogical volume generation facility: \t\t"
00497                  <<  c12facility
00498 
00499                  << "\n\nLeader file pointer record"
00500                  << "\n--------------------------"
00501                  << "\nReferenced file name: \t\t\t\t"
00502                  <<  c16checkfilename
00503                  << "\nReferenced file class: \t\t\t\t"
00504                  <<  c28leaderrefclass
00505 
00506                  << "\n\nData file pointer record"
00507                  << "\n------------------------"
00508                  << "\nReferenced file name: \t\t\t\t"
00509                  <<  c16dataref
00510                  << "\nReferenced file class: \t\t\t\t"
00511                  <<  c28datarefclass
00512                  << "\nNumber of records in referenced file: \t\t"
00513                  <<  c8nlins
00514 
00515                  << "\n\nText record"
00516                  << "\n-----------"
00517                  << "\nProduct type specifier: \t\t\t"
00518                  <<  c40typespec
00519                  << "\nLocation and date/time of product creation: \t"
00520                  <<  c60product
00521                  << "\nPhysical volume identification: \t\t"
00522                  <<  c40physvolid
00523                  << "\nScene identification: \t\t\t\t"
00524                  <<  c40sceneid
00525                  << "\nScene location: \t\t\t\t"
00526                  <<  c40sceneloc
00527                  << "\nEND VOLUME FILE "
00528                  <<  readfiles_arg.volfile
00529                  <<  endl << endl;
00530   scratchlogfile.close();
00531 
00532   ofstream scratchresfile("scratchresvol", ios::out | ios::trunc);
00533   bk_assert(scratchresfile,"scratchresvol",__FILE__,__LINE__);
00534   scratchresfile
00535     << "\n*******************************************************************";
00536   if (readfiles_arg.fileid==MASTERID)
00537     scratchresfile << "\n*_Start_" << processcontrol[pr_m_readfiles];
00538   if (readfiles_arg.fileid==SLAVEID)
00539     scratchresfile << "\n*_Start_" << processcontrol[pr_m_readfiles];
00540   scratchresfile
00541     << "\n*******************************************************************"
00542     << "\nVolume file: \t\t\t\t\t" 
00543     <<  readfiles_arg.volfile
00544     << "\nVolume_ID: \t\t\t\t\t"
00545     <<  c16physid
00546     << "\nVolume_identifier: \t\t\t\t"
00547     <<  c16logvolid
00548     << "\nVolume_set_identifier: \t\t\t\t"
00549     <<  c16setid
00550     << "\n(Check)Number of records in ref. file: \t\t"
00551     <<  atoi(c8nlins);
00552   // --- write new string to determine sar processor ---
00553   // --- this is used in cropping the data ---
00554   if (readfiles_arg.sar_processor==SARPR_VMP)
00555     scratchresfile << "\nSAR_PROCESSOR:  \t\t\t\tVMP";
00556   if (readfiles_arg.sar_processor==SARPR_ATL)
00557     scratchresfile << "\nSAR_PROCESSOR:  \t\t\t\tATLANTIS";
00558   if (readfiles_arg.sar_processor==SARPR_TUD)
00559     scratchresfile << "\nSAR_PROCESSOR:  \t\t\t\tTUD";
00560   //
00561   if (readfiles_arg.sensor_id==SLC_RSAT)
00562     scratchresfile
00563       << "\nProduct type specifier: \t\t\t"
00564       <<  "RSAT";// else it is just "PRODUCT:", but it is used in CROP step
00565   else
00566     scratchresfile
00567       << "\nProduct type specifier: \t\t\t"
00568       <<  c40typespec;
00569   scratchresfile
00570     << "\nLogical volume generating facility: \t\t\t"
00571     <<  c12facility
00572     << "\nLogical volume creation date: \t\t\t"
00573     <<  c8date
00574     << "\nLocation and date/time of product creation: \t"
00575     <<  c60product
00576     << "\nScene identification: \t\t\t\t"
00577     <<  c40sceneid
00578     << "\nScene location: \t\t\t\t"
00579     <<  c40sceneloc
00580     << endl;
00581   scratchresfile.close();
00582 
00583 // ______Tidy up______
00584   PROGRESS.print("readvolume finished.");
00585   } // END READVOLUME
00586 
00587 
00588 
00589 /****************************************************************
00590  *    readleader                                                *
00591  *                                                              *
00592  * reads leaderfile                                             *
00593  *  and writes to scratchlogfile, scratchresfile                *
00594  * checks with volumefile #lines                                *
00595  *                                                              *
00596  * input:                                                       *
00597  *  - struct with arguments for step0                           *
00598  *  - check with volumefile                                     *
00599  * output:                                                      *
00600  *  - scratchlogfile                                            *
00601  *  - scratchresfile                                            *
00602  *  - scratchdatapoints                                         *
00603  * see: annex C ERS SAR.SLC CCTand EXABYTE                      *
00604  *      doc:er-is-epo-gs-5902.3                                 *
00605  *                                                              *
00606  *    Bert Kampes, 11-Dec-1998                                  *
00607  * Included RSAT format based on document of ASF                *
00608  #%// Bert Kampes, 03-Aug-2004                                  *
00609  ****************************************************************/
00610 void readleader(
00611         input_readfiles &readfiles_arg,
00612         const int32 checklines)
00613   {
00614   TRACE_FUNCTION("readleader (BK 11-Dec-1998)")
00615   const int16           sizea2 = 2,
00616                         sizeb1 = 1,             // some constants for reading
00617                         sizeb4 = 4,             // some constants for reading
00618                         sizei4 = 4,             //   binary fields.
00619                         sizea4 = 4,             //   binary fields.
00620                         sizei8 = 8,
00621                         sizea8 = 8,
00622                         sizea12 = 12,
00623                         sizea16 = 16,
00624                         sizef16 = 16,
00625                         sizei16 = 16,
00626                         sized22 = 22,
00627                         sizea24 = 24,
00628                         sizea32 = 32,
00629                         sizea64 = 64;
00630   uint                  lenrec1,                // length of record1
00631                         lenrec2,                // length of record2
00632                         lenrec3,                // length of record3
00633                         lenrec4,                // bc length of record4
00634                         lenrec5,                // bc/gk length of record5
00635                         lenrec6,                // gk length of record6 
00636                         lenrec7;                // bk rsat record
00637  char                   c2motioncomp[3],
00638                         c4dummy[5],             // correctly 5 for \0
00639                         c4year[5],
00640                         c4month[5],
00641                         c4day[5],
00642                         c4dayofyear[5],
00643                         c4conversion[5],
00644                         c4compression[5],
00645                         c4clutterlock[5],
00646                         c4autofocus[5],
00647                         c8dummy[9],             // dummy
00648                         c8orbitnr[9],
00649                         c8platformlat[9],
00650                         c8platformlon[9],
00651                         c8platformheading[9],
00652                         c8clockangle[9],
00653                         c8incidence[9],
00654                         c8freq[9],
00655                         c8systemid[9],
00656                         c8versionid[9],
00657                         c8satclockstep[9],
00658                         c8extindex[9],
00659                         c8qperch[9],
00660                         c8timeline[9],
00661                         c8timepix[9],
00662                         c8linecontent[9],
00663                         c12qdesc[13],
00664                         c16dummy[17],
00665                         c16lat11[17], c16lon11[17],
00666                         c16lat1N[17], c16lon1N[17],
00667                         c16latNN[17], c16lonNN[17],
00668                         c16latN1[17], c16lonN1[17],
00669                         c16leafilename[17],
00670                         c16centerlat[17], 
00671                         c16centerlon[17], 
00672                         c16centerheading[17],
00673                         c16ellipsoid[17],
00674                         c16semimajor[17],
00675                         c16semiminor[17],
00676                         c16GM[17],
00677                         c16J2[17],
00678                         c16J3[17],
00679                         c16J4[17],
00680                         c16scenelength[17],
00681                         c16scenewidth[17],
00682                         c16platformid[17],
00683                         c16wavelength[17],
00684                         c16facilityid[17],
00685                         c16numpix[17],
00686                         c16numlin[17],
00687                         c16interpix[17],
00688                         c16interlin[17],
00689                         c16pulse[17],
00690                         c16ampconst[17],
00691                         c16amplinear[17],
00692                         c16ampquadratic[17],
00693                         c16ampcubic[17],
00694                         c16ampquartic[17],
00695                         c16phaseconst[17],
00696                         c16phaselinear[17],
00697                         c16phasequadratic[17],
00698                         c16phasecubic[17],
00699                         c16phasequartic[17],
00700                         c16sattimecode[17],
00701                         c16samplingrate[17],
00702                         c16rangedelay[17],
00703                         c16ranpulselen[17],
00704                         c16dci[17],
00705                         c16dcq[17],
00706                         c16boresight[17],
00707                         c16imbalance[17],
00708                         c16prf[17],
00709                         c16looksazi[17],
00710                         c16looksrange[17],
00711                         c16bandazi[17],
00712                         c16bandrange[17],
00713                         c16bandazitot[17],
00714                         c16bandrangetot[17],
00715                         c16inputsource[17],
00716                         c16resrange[17],
00717                         c16resazi[17],
00718                         c16linespace[17],
00719                         c16pixspace[17],
00720                         c16atdoppcconst[17],
00721                         c16atdoppclinear[17],
00722                         c16atdoppcquadratic[17],
00723                         c16xtdoppcconst[17],
00724                         c16xtdoppclinear[17],
00725                         c16xtdoppcquadratic[17],
00726                         c16atdopprconst[17],
00727                         c16atdopprlinear[17],
00728                         c16atdopprquadratic[17],
00729                         c16xtdopprconst[17],
00730                         c16xtdopprlinear[17],
00731                         c16xtdopprquadratic[17],
00732                         c16rcompdes[17],
00733                         c16zd1strange[17],
00734                         c16zdcenrange[17],
00735                         c16zdlstrange[17],
00736                         c16orien[17],
00737                         c16platincl[17],
00738                         c16platascn[17],
00739                         c16geocenter[17],
00740                         c16platalt[17],
00741                         c16plathead[17],
00742                         c16platgs[17],
00743                         c16refmajor[17],
00744                         c16refminor[17],
00745                         c16ltposerr[17],
00746                         c16ctposerr[17],
00747                         c16rposerr[17],
00748                         c22dummy[23],
00749                         c22seconds[23],
00750                         c22interval[23],
00751                         c22gmha[23],
00752                         c24zd1stazitime[25],
00753                         c24zdcenazitime[25],
00754                         c24zdlstazitime[25],
00755                         c32sceneref[33],
00756                         c32scenetime[33],
00757                         c32sensorid[33],
00758                         c32typespec[33],
00759                         c32algid[33],
00760                         c32projection[33],
00761                         c32sattime[33],
00762                         c32weightrange[33],
00763                         c32weightazi[33],
00764                         c32refellips[33],
00765                         c64rcs[65];
00766 
00767   // --- Check for RSAT #%// Bert Kampes, 02-Aug-2004 ---
00768   uint rec_seq;// type B4
00769   unsigned char rec_sub1, rec_type, rec_sub2, rec_sub3;// type B1
00770 
00771 
00772 
00773 // ======Open files====== 
00774   ifstream leaderfile;
00775   openfstream(leaderfile,readfiles_arg.leaderfile);
00776   bk_assert(leaderfile,readfiles_arg.leaderfile,__FILE__,__LINE__);
00777 
00778   // ======Read leaderfile======
00779   // --- RECORD 1 ---
00780   leaderfile.seekg(0,ios::beg);// place pointer at beginning of file
00781   leaderfile.read((char*)&rec_seq,sizeb4);// record number
00782   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
00783   leaderfile.read((char*)&rec_sub1,sizeb1);// first record sub type code
00784   leaderfile.read((char*)&rec_type,sizeb1);// record type code
00785   leaderfile.read((char*)&rec_sub2,sizeb1);// second record sub type code
00786   leaderfile.read((char*)&rec_sub3,sizeb1);// third record sub type code
00787   DEBUG.print("Expecting record 1 with code {63,192,18,18}");
00788   DEBUG << "rec_seq: " << rec_seq 
00789         << "; rec_sub1: " << int(rec_sub1)
00790         << "; rec_type: " << int(rec_type)
00791         << "; rec_sub2: " << int(rec_sub2)
00792         << "; rec_sub3: " << int(rec_sub3);
00793   DEBUG.print();
00794 
00795   // --- Read important data ---
00796   leaderfile.seekg(8,ios::beg);                         // file descriptor record
00797   leaderfile.read((char*)&lenrec1,sizeb4);              // length of record1
00798   lenrec1 = ntohl(lenrec1);     // bk 6 jul 2000, byteorder x86 machines.
00799   DEBUG << "readleader::record 1 of leader file: length: " << lenrec1;
00800   DEBUG.print();
00801   if (lenrec1 != 720 )
00802     {
00803     WARNING.print("probably something wrong here, byte order x86.");
00804     WARNING << "readleader: length of record 1 = \""
00805          <<  lenrec1 << "\"; expected \"720\" for ESA SLC (full scene).";
00806     WARNING.print();
00807     }
00808   leaderfile.seekg(48,ios::beg);
00809   leaderfile.read((char*)&c16leafilename,sizea16);      // file name
00810   c16leafilename[16]='\0';
00811 
00812 
00813   // --- RECORD 2 ---
00814   DEBUG.print("readleader::reading record 2 of leader file.");
00815   uint startrec2 = lenrec1;
00816   leaderfile.seekg(startrec2,ios::beg);// place pointer at beginning of record
00817   leaderfile.read((char*)&rec_seq,sizeb4);// record number
00818   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
00819   leaderfile.read((char*)&rec_sub1,sizeb1);// first record sub type code
00820   leaderfile.read((char*)&rec_type,sizeb1);// record type code
00821   leaderfile.read((char*)&rec_sub2,sizeb1);// second record sub type code
00822   leaderfile.read((char*)&rec_sub3,sizeb1);// third record sub type code
00823   DEBUG.print("ERS:  Expecting record 2 with code {10,10,31,20}");
00824   DEBUG.print("RSAT: Expecting record 2 with code {18,10,18,20}");
00825   DEBUG.print("RSAT record length is 4096, ERS 1886, but");
00826   DEBUG.print("ERS contains more info on zero doppler times, etc.");
00827   DEBUG.print("RSAT seems to have that info in the data file.");
00828   DEBUG << "rec_seq: " << rec_seq 
00829         << "; rec_sub1: " << int(rec_sub1)
00830         << "; rec_type: " << int(rec_type)
00831         << "; rec_sub2: " << int(rec_sub2)
00832         << "; rec_sub3: " << int(rec_sub3);
00833   DEBUG.print();
00834 
00835   // ___ Read important parameters ___
00836   leaderfile.seekg(startrec2+8,ios::beg);               // slc data set summary record
00837   leaderfile.read((char*)&lenrec2,sizeb4);              // length of record2
00838   lenrec2 = ntohl(lenrec2);     // bk 6 jul 2000, byteorder x86 machines.
00839   DEBUG << "readleader::record 2: start at: " << lenrec1 << "; length: " << lenrec2;
00840   DEBUG.print();
00841   //if (readfiles_arg.sensor_id==SLC_RSAT)
00842   if (readfiles_arg.sar_processor==SARPR_ATL)
00843     {
00844     if (lenrec2 != 4096)
00845       {
00846       WARNING.print("SARPR_ATL (RSAT) has 4096 record length, but other value found?");
00847       }
00848     }
00849   else
00850     {
00851     if (lenrec2 != 1886)
00852       {
00853       WARNING.print("SARPR_ATL (RSAT) has 4096 record length");
00854       WARNING.print("probably something wrong here, byte order on x86?");
00855       WARNING << "readleader: length of record 2 = \""
00856            <<  lenrec2 << "\"; expected \"1886\" for ESA SLC (full scene).  continuing";
00857       WARNING.print();
00858       }
00859     }
00860 
00861 
00862   // ______Scene parameters______
00863   leaderfile.seekg(startrec2+36,ios::beg);
00864   leaderfile.read((char*)&c32sceneref,sizea32);         // scene ref. number
00865   c32sceneref[32]='\0';
00866   leaderfile.read((char*)&c32scenetime,sizea32);        // scene center time
00867   c32scenetime[32]='\0';
00868   leaderfile.seekg(startrec2+116,ios::beg);
00869   leaderfile.read((char*)&c16centerlat,sizef16);        // centre latitude
00870   c16centerlat[16]='\0';
00871   leaderfile.read((char*)&c16centerlon,sizef16);        // centre longitude
00872   c16centerlon[16]='\0';
00873   leaderfile.read((char*)&c16centerheading,sizef16);    // center true heading
00874   c16centerheading[16]='\0';
00875   leaderfile.read((char*)&c16ellipsoid,sizea16);        // ell. designated 
00876   c16ellipsoid[16]='\0';
00877   leaderfile.read((char*)&c16semimajor,sizef16);        // ell. semi major
00878   c16semimajor[16]='\0';
00879   leaderfile.read((char*)&c16semiminor,sizef16);        // ell. semi minor
00880   c16semiminor[16]='\0';
00881   leaderfile.read((char*)&c16GM,sizef16);               // GM
00882   c16GM[16]='\0';
00883   leaderfile.read((char*)&c16dummy,sizef16);            // dummy
00884   leaderfile.read((char*)&c16J2,sizef16);               // J2
00885   c16J2[16]='\0';
00886   leaderfile.read((char*)&c16J3,sizef16);               // J3
00887   c16J3[16]='\0';
00888   leaderfile.read((char*)&c16J4,sizef16);               // J4
00889   c16J4[16]='\0';
00890   leaderfile.read((char*)&c16dummy,sizef16);            // dummy
00891   leaderfile.read((char*)&c16dummy,sizef16);            // dummy
00892   leaderfile.read((char*)&c8dummy,sizei8);              // center line#
00893   c8dummy[8]='\0';
00894   uint scenecenterline = atoi(c8dummy);
00895   leaderfile.read((char*)&c8dummy,sizei8);              // center pixel#
00896   c8dummy[8]='\0';
00897   uint scenecenterpixel = atoi(c8dummy);
00898   leaderfile.read((char*)&c16scenelength,sizef16);      // scene length
00899   c16scenelength[16]='\0';
00900   leaderfile.read((char*)&c16scenewidth,sizef16);       // scene width
00901   c16scenewidth[16]='\0';
00902 
00903 // ______General mission / sensor parameters______
00904   leaderfile.seekg(startrec2+396,ios::beg);
00905   leaderfile.read((char*)&c16platformid,sizea16);       // platform mission id
00906   c16platformid[16]='\0';
00907   leaderfile.read((char*)&c32sensorid,sizea32);         // sensor id
00908   c32sensorid[32]='\0';
00909   leaderfile.read((char*)&c8orbitnr,sizea8);            // orbit number
00910   c8orbitnr[8]='\0';
00911   leaderfile.read((char*)&c8platformlat,sizea8);        // platform latitude
00912   c8platformlat[8]='\0';
00913   leaderfile.read((char*)&c8platformlon,sizea8);        // platform longitude
00914   c8platformlon[8]='\0';
00915   leaderfile.read((char*)&c8platformheading,sizea8);    // platform heading
00916   c8platformheading[8]='\0';
00917   leaderfile.read((char*)&c8clockangle,sizea8);         // sensor clock angle
00918   c8clockangle[8]='\0';
00919   leaderfile.read((char*)&c8incidence,sizea8);          // incidence angle
00920   c8incidence[8]='\0';
00921   leaderfile.read((char*)&c8freq,sizea8);               // radar frequency
00922   c8freq[8]='\0';
00923   leaderfile.read((char*)&c16wavelength,sizea16);       // radar wavelength
00924   c16wavelength[16]='\0';
00925   leaderfile.read((char*)&c2motioncomp,sizea2);         // indicator for compensation
00926   c2motioncomp[2]='\0';
00927   leaderfile.read((char*)&c16pulse,sizea16);            // range pulse code specifier
00928   c16pulse[16]='\0';
00929   leaderfile.read((char*)&c16ampconst,sizef16);         // amplitude constant term
00930   c16ampconst[16]='\0';
00931   leaderfile.read((char*)&c16amplinear,sizef16);        // amplitude linear term
00932   c16amplinear[16]='\0';
00933   leaderfile.read((char*)&c16ampquadratic,sizef16);     // amplitude quadrati term
00934   c16ampquadratic[16]='\0';
00935   leaderfile.read((char*)&c16ampcubic,sizef16);         // amplitude cubic term
00936   c16ampcubic[16]='\0';
00937   leaderfile.read((char*)&c16ampquartic,sizef16);       // amplitude quartic term
00938   c16ampquartic[16]='\0';
00939   leaderfile.read((char*)&c16phaseconst,sizef16);       // phase constant term
00940   c16phaseconst[16]='\0';
00941   leaderfile.read((char*)&c16phaselinear,sizef16);      // phase linear term
00942   c16phaselinear[16]='\0';
00943   leaderfile.read((char*)&c16phasequadratic,sizef16);   // phase quadratic term
00944   c16phasequadratic[16]='\0';
00945   leaderfile.read((char*)&c16phasecubic,sizef16);       // phase cubicterm
00946   c16phasecubic[16]='\0';
00947   leaderfile.read((char*)&c16phasequartic,sizef16);     // phase quartic term
00948   c16phasequartic[16]='\0';
00949   leaderfile.read((char*)&c8extindex,sizei8);           // chirp extraction
00950   c8extindex[8]='\0';
00951   leaderfile.read((char*)&c8dummy,sizei8);              // spare
00952   leaderfile.read((char*)&c16samplingrate,sizef16);     // range
00953   c16samplingrate[16]='\0';
00954   leaderfile.read((char*)&c16rangedelay,sizef16);       // delay
00955   c16rangedelay[16]='\0';
00956   leaderfile.read((char*)&c16ranpulselen,sizef16);      // range pulselength
00957   c16ranpulselen[16]='\0';
00958   leaderfile.read((char*)&c4conversion,sizea4);         // flag
00959   c4conversion[4]='\0';
00960   leaderfile.read((char*)&c4compression,sizea4);        // flag
00961   c4compression[4]='\0';
00962   leaderfile.read((char*)&c16dummy,sizef16);            // reserved
00963   leaderfile.read((char*)&c16dummy,sizef16);            // reserved
00964   leaderfile.read((char*)&c8qperch,sizei8);             // quantization
00965   c8qperch[8]='\0';
00966   leaderfile.read((char*)&c12qdesc,sizea12);            // quantization description
00967   c12qdesc[12]='\0';
00968   leaderfile.read((char*)&c16dci,sizef16);              // bias for i comp.
00969   c16dci[16]='\0';
00970   leaderfile.read((char*)&c16dcq,sizef16);              // bias for q comp.
00971   c16dcq[16]='\0';
00972   leaderfile.read((char*)&c16imbalance,sizef16);        // gain imbalance i&q
00973   c16imbalance[16]='\0';
00974   leaderfile.read((char*)&c16dummy,sizef16);            // spare
00975   leaderfile.read((char*)&c16dummy,sizef16);            // spare
00976   leaderfile.read((char*)&c16dummy,sizef16);            // reserved
00977   leaderfile.read((char*)&c16boresight,sizef16);        // antenna
00978   c16boresight[16]='\0';
00979   leaderfile.read((char*)&c4dummy,sizea4);              // reserved
00980   leaderfile.read((char*)&c16prf,sizef16);              // pulse repetition frequency
00981   c16prf[16]='\0';
00982 
00983 // ______Sensor specific parameters______
00984   leaderfile.seekg(startrec2+982,ios::beg);
00985   leaderfile.read((char*)&c16sattimecode,sizei16);      // sat time code
00986   c16sattimecode[16]='\0';
00987   leaderfile.read((char*)&c32sattime,sizea32);          // sat time
00988   c32sattime[32]='\0';
00989   leaderfile.read((char*)&c8satclockstep,sizei8);       // sat clock step length
00990   c8satclockstep[8]='\0';
00991 
00992 // ______General processing parameters______
00993   leaderfile.seekg(startrec2+1046,ios::beg);
00994   leaderfile.read((char*)&c16facilityid,sizea16);       // proc. facility id
00995   c16facilityid[16]='\0';
00996   leaderfile.read((char*)&c8systemid,sizea8);           // proc. system id
00997   c8systemid[8]='\0';
00998   leaderfile.read((char*)&c8versionid,sizea8);          // proc. version id
00999   c8versionid[8]='\0';
01000   leaderfile.read((char*)&c16dummy,sizef16);            // dummy
01001   leaderfile.read((char*)&c16dummy,sizef16);            // dummy
01002   leaderfile.read((char*)&c32typespec,sizea32);         // produkt type spec.
01003   c32typespec[32]='\0';
01004   leaderfile.read((char*)&c32algid,sizea32);            // proc. alg. id
01005   c32algid[32]='\0';
01006   leaderfile.read((char*)&c16looksazi,sizef16);         // number of looks
01007   c16looksazi[16]='\0';
01008   leaderfile.read((char*)&c16looksrange,sizef16);       // number of looks
01009   c16looksrange[16]='\0';
01010   leaderfile.read((char*)&c16bandazi,sizef16);          // bandwidth
01011   c16bandazi[16]='\0';
01012   leaderfile.read((char*)&c16bandrange,sizef16);        // bandwidth
01013   c16bandrange[16]='\0';
01014   leaderfile.read((char*)&c16bandazitot,sizef16);       // bandwidth
01015   c16bandazitot[16]='\0';
01016   leaderfile.read((char*)&c16bandrangetot,sizef16);     // bandwidth
01017   c16bandrangetot[16]='\0';
01018   leaderfile.read((char*)&c32weightazi,sizea32);        // weighting function
01019   c32weightazi[32]='\0';
01020   leaderfile.read((char*)&c32weightrange,sizea32);      // weighting function
01021   c32weightrange[32]='\0';
01022   leaderfile.read((char*)&c16inputsource,sizea16);      // data input
01023   c16inputsource[16]='\0';
01024   leaderfile.read((char*)&c16resrange,sizef16);         // resolution
01025   c16resrange[16]='\0';
01026   leaderfile.read((char*)&c16resazi,sizef16);           // resolution
01027   c16resazi[16]='\0';
01028   leaderfile.read((char*)&c16dummy,sizef16);            // reserved
01029   leaderfile.read((char*)&c16dummy,sizef16);            // reserved
01030   leaderfile.read((char*)&c16atdoppcconst,sizef16);     // along track centroid
01031   c16atdoppcconst[16]='\0';
01032   leaderfile.read((char*)&c16atdoppclinear,sizef16);    // along track centroid
01033   c16atdoppclinear[16]='\0';
01034   leaderfile.read((char*)&c16atdoppcquadratic,sizef16); // along track centroid
01035   c16atdoppcquadratic[16]='\0';
01036   leaderfile.read((char*)&c16dummy,sizef16);            // spare
01037   leaderfile.read((char*)&c16xtdoppcconst,sizef16);     // cross track centroid
01038   c16xtdoppcconst[16]='\0';
01039   leaderfile.read((char*)&c16xtdoppclinear,sizef16);    // cross track centroid
01040   c16xtdoppclinear[16]='\0';
01041   leaderfile.read((char*)&c16xtdoppcquadratic,sizef16); // cross track centroid
01042   c16xtdoppcquadratic[16]='\0';
01043   leaderfile.read((char*)&c8timepix,sizea8);            // time direction
01044   c8timepix[8]='\0';
01045   leaderfile.read((char*)&c8timeline,sizea8);           // time direction
01046   c8timeline[8]='\0';
01047   leaderfile.read((char*)&c16atdopprconst,sizef16);     // along track rate
01048   c16atdopprconst[16]='\0';
01049   leaderfile.read((char*)&c16atdopprlinear,sizef16);    // along track rate
01050   c16atdopprlinear[16]='\0';
01051   leaderfile.read((char*)&c16atdopprquadratic,sizef16); // along track rate
01052   c16atdopprquadratic[16]='\0';
01053   leaderfile.read((char*)&c16dummy,sizef16);            // spare
01054   leaderfile.read((char*)&c16xtdopprconst,sizef16);     // cross track rate
01055   c16xtdopprconst[16]='\0';
01056   leaderfile.read((char*)&c16xtdopprlinear,sizef16);    // cross track rate
01057   c16xtdopprlinear[16]='\0';
01058   leaderfile.read((char*)&c16xtdopprquadratic,sizef16); // cross track rate
01059   c16xtdopprquadratic[16]='\0';
01060   leaderfile.read((char*)&c16dummy,sizef16);            // spare
01061   leaderfile.read((char*)&c8linecontent,sizea8);        // indicator
01062   c8linecontent[8]='\0';
01063   leaderfile.read((char*)&c4clutterlock,sizea4);        // flag
01064   c4clutterlock[4]='\0';
01065   leaderfile.read((char*)&c4autofocus,sizea4);          // flag
01066   c4autofocus[4]='\0';
01067   leaderfile.read((char*)&c16linespace,sizef16);        // 
01068   c16linespace[16]='\0';
01069   leaderfile.read((char*)&c16pixspace,sizef16);         // 
01070   c16pixspace[16]='\0';
01071   leaderfile.read((char*)&c16rcompdes,sizea16);         // range compression designator
01072   c16rcompdes[16]='\0';
01073 
01074 
01075 
01076   // --- RSAT does not fill this spare part of the record (blanks) ---
01077   DEBUG.print("Assuming user has specified method RSAT if it is RSAT.");
01078   DEBUG.print("although we could also easily detect it before");
01079   bool skipmapprojrecord = false;       // some problem s with old IPAF?
01080   uint numdatapoints=99999;
01081   char  c16incangle1strange[17],                        //bc
01082         c16incanglecenrange[17],                        //bc
01083         c16incanglelstrange[17],                        //bc
01084         calK[17],                                       //gk
01085         repplspwr[17];                                  //gk
01086   char  c4numvalid[5];                                  //bk
01087   char  c4numinvalid[5];                                //bk
01088   strcpy(c16incangle1strange,     "skipped");
01089   strcpy(c16incanglecenrange,     "skipped");
01090   strcpy(c16incanglelstrange,     "skipped");
01091   strcpy(calK,                    "skipped");
01092   strcpy(repplspwr,               "skipped");
01093   strcpy(c4numvalid,              "999");
01094   strcpy(c4numinvalid,            "999");
01095   matrix<real8> STATE;// has to be declared at large scope, used later.
01096   matrix<real8> STATE_INERTIAL;// has to be declared at large scope, used later.
01097 
01098 
01099 //if (readfiles_arg.sar_processor!=SARPR_ATL)
01100 // seems ERS data are same, also with Atlantis, so only check for RSAT here.
01101 if (readfiles_arg.sensor_id!=SLC_RSAT)
01102   {
01103   DEBUG.print("Reading rest of this record, which for RSAT is empty.");
01104 
01105   // ______Sensor specific local use segment______
01106   leaderfile.seekg(startrec2+1766,ios::beg);
01107   leaderfile.read((char*)&c16zd1strange,sizef16);       // zero doppler 1st pixel
01108   c16zd1strange[16]='\0';
01109   leaderfile.read((char*)&c16zdcenrange,sizef16);       // zero doppler centre pixel
01110   c16zdcenrange[16]='\0';
01111   leaderfile.read((char*)&c16zdlstrange,sizef16);       // zero doppler last pixel 2way
01112   c16zdlstrange[16]='\0';
01113   leaderfile.read((char*)&c24zd1stazitime,sizea24);     // zero doppler 1st pixel
01114   c24zd1stazitime[24]='\0';
01115   leaderfile.read((char*)&c24zdcenazitime,sizea24);     // zero doppler 1st pixel
01116   c24zdcenazitime[24]='\0';
01117   leaderfile.read((char*)&c24zdlstazitime,sizea24);     // zero doppler 1st pixel
01118   c24zdlstazitime[24]='\0';
01119 
01120 
01121   // --- RECORD 3 ---
01122   DEBUG.print("record 3 of leader file (ERS).");
01123   uint startrec3 = lenrec1 + lenrec2;
01124   leaderfile.seekg(startrec3,ios::beg);//     map projection data record
01125   leaderfile.read((char*)&rec_seq,sizeb4);//  record number
01126   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
01127   leaderfile.read((char*)&rec_sub1,sizeb1);// first record sub type code
01128   leaderfile.read((char*)&rec_type,sizeb1);// record type code
01129   leaderfile.read((char*)&rec_sub2,sizeb1);// second record sub type code
01130   leaderfile.read((char*)&rec_sub3,sizeb1);// third record sub type code
01131   DEBUG.print("ERS:  Expecting record 3 with code {10,20,31,20}");
01132   DEBUG.print("RSAT: Expecting record 3 with code {18,60,18,20}");
01133   DEBUG.print("RSAT record length is 4096, ERS 1886, but");
01134   DEBUG.print("ERS contains more info on zero doppler times, etc.");
01135   DEBUG.print("RSAT seems to have that in data file");
01136   DEBUG << "rec_seq: " << rec_seq 
01137         << "; rec_sub1: " << int(rec_sub1)
01138         << "; rec_type: " << int(rec_type)
01139         << "; rec_sub2: " << int(rec_sub2)
01140         << "; rec_sub3: " << int(rec_sub3);
01141   DEBUG.print();
01142 
01143   // ___ Read important information ___
01144   leaderfile.seekg(startrec3+8,ios::beg);               //  map projection data record
01145   leaderfile.read((char*)&lenrec3,sizeb4);              // length of record3
01146   lenrec3 = ntohl(lenrec3);     // bk 6 jul 2000, byteorder x86 machines.
01147   DEBUG << "readleader::record 3: start at: " << startrec3 << "; length: " << lenrec3;
01148   DEBUG.print();
01149 
01150   //if (lenrec3 != 1620 ) // quarter scene 1046 (?)
01151   if (lenrec3 < 1620 ) // quarter scene 1046 (?)
01152     {
01153     WARNING.print("Probably something wrong here, byte order on x86?");
01154     WARNING.print("you may also be trying to read leader of ESA.RAW not ESA.SLC.");
01155     WARNING.print("format (or quarter scene).");
01156     WARNING.print("We try to do something useful still, but be careful.");
01157     WARNING.print("Skipping map projection record, not in ESA.RAW leaderfile format.");
01158     WARNING << "readleader: length of record 3 = \""
01159          <<  lenrec3 << "\"; expected \"1620\" for ESA SLC (full scene).";
01160     WARNING.print();
01161     lenrec3 = 0;
01162     skipmapprojrecord = true;
01163     }
01164   // --- Trying to read anyway if it is longer ---
01165   if (lenrec3 > 1620 ) // atlantis? rec2 is 4096 not 1886 (?)
01166     {
01167     //skipmapprojrecord = true;// no: want to read it sometimes...
01168     WARNING.print("record length longer than expected.  Atlantis?.  reading map.");
01169     WARNING.print("seems not ok. assuming mapprojection record not present");
01170     WARNING.print("trying to read further with next record");
01171     startrec3 = lenrec1+lenrec2+lenrec3;// try to continue with rec4??? rec3 seems platform data
01172     lenrec3 = 0;// so next time this record is read, but with platform data format...
01173     }
01174 
01175   // skip map projection record if not present ...
01176   // BK 18-Jul-2000
01177   if (skipmapprojrecord) // not present, do not read.
01178     {
01179     WARNING.print("Skipping map projection record. Not found.");
01180     WARNING.print("Continuing with platform position data.");
01181     }
01182   else // ESA.SLC format, do read map proj. record.
01183     {
01184     // ______ Map projection general information ______
01185     leaderfile.seekg(startrec3+28,ios::beg);
01186     leaderfile.read((char*)&c32projection,sizea32);     // map proj. descr.
01187     c32projection[32]='\0';
01188     leaderfile.read((char*)&c16numpix,sizei16);         // numpixels
01189     c16numpix[16]='\0';
01190     leaderfile.read((char*)&c16numlin,sizei16);         // numlines
01191     c16numlin[16]='\0';
01192 
01193 
01194     // ______ Continue ______
01195     leaderfile.read((char*)&c16interpix,sizef16);       // dist inter-pixel
01196     c16interpix[16]='\0';
01197     leaderfile.read((char*)&c16interlin,sizef16);       // dist inter-lines
01198     c16interlin[16]='\0';
01199     leaderfile.read((char*)&c16orien,sizef16);          // orientation at output
01200     c16orien[16]='\0';
01201     leaderfile.read((char*)&c16platincl,sizef16);       // actual platform inclination
01202     c16platincl[16]='\0';
01203     leaderfile.read((char*)&c16platascn,sizef16);       // actual ascending node
01204     c16platascn[16]='\0';
01205     leaderfile.read((char*)&c16geocenter,sizef16);      // 
01206     c16geocenter[16]='\0';
01207     leaderfile.read((char*)&c16platalt,sizef16);        // altitude
01208     c16platalt[16]='\0';
01209     leaderfile.read((char*)&c16platgs,sizef16);         // ground speed
01210     c16platgs[16]='\0';
01211     leaderfile.read((char*)&c16plathead,sizef16);       // heading
01212     c16plathead[16]='\0';
01213     leaderfile.read((char*)&c32refellips,sizea32);      // ellipsoid
01214     c32refellips[32]='\0';
01215     leaderfile.read((char*)&c16refmajor,sizef16);       // semi major
01216     c16refmajor[16]='\0';
01217     leaderfile.read((char*)&c16refminor,sizef16);       // semi minor
01218     c16refminor[16]='\0';
01219   
01220     // ______ Coordinates of four corner points ______
01221     leaderfile.seekg(startrec3+1072,ios::beg);
01222     leaderfile.read((char*)&c16lat11,sizef16);          // lat. 1st line 1st pix.
01223     c16lat11[16]='\0';
01224     leaderfile.read((char*)&c16lon11,sizef16);          // lon. 1st line 1st pix.
01225     c16lon11[16]='\0';
01226     leaderfile.read((char*)&c16lat1N,sizef16);          // lat. 1st line last pix.
01227     c16lat1N[16]='\0';
01228     leaderfile.read((char*)&c16lon1N,sizef16);          // lon. 1st line last pix.
01229     c16lon1N[16]='\0';
01230     leaderfile.read((char*)&c16latNN,sizef16);          // lat. last line last pix.
01231     c16latNN[16]='\0';
01232     leaderfile.read((char*)&c16lonNN,sizef16);          // lon. last line last pix.
01233     c16lonNN[16]='\0';
01234     leaderfile.read((char*)&c16latN1,sizef16);          // lat. last line 1st pix.
01235     c16latN1[16]='\0';
01236     leaderfile.read((char*)&c16lonN1,sizef16);          // lon. last line 1st pix.
01237     c16lonN1[16]='\0';
01238   } // end skip map proj.
01239 
01240 
01241   // --- RECORD 4 ---
01242   DEBUG.print("record 4 of leader file.");
01243   uint startrec4=lenrec1+lenrec2+lenrec3;
01244   leaderfile.seekg(startrec4+8,ios::beg);               //  slc platform position data record
01245   leaderfile.read((char*)&lenrec4,sizeb4);              // length of record4
01246   lenrec4 = ntohl(lenrec4);     // bk 6 jul 2000, byteorder x86 machines.
01247   DEBUG << "readleader::record 4: start at: " << startrec4 
01248         << "; length (variable): " << lenrec4;
01249   DEBUG.print();
01250 
01251 
01252 // ______ Positional data points ______
01253   leaderfile.seekg(startrec4+140,ios::beg);
01254   leaderfile.read((char*)&c4dummy,sizei4);              // number of data points
01255   c4dummy[4]='\0';
01256   numdatapoints = atoi(c4dummy);
01257   leaderfile.read((char*)&c4year,sizei4);               // year
01258   c4year[4]='\0';
01259   leaderfile.read((char*)&c4month,sizei4);              // month
01260   c4month[4]='\0';
01261   leaderfile.read((char*)&c4day,sizei4);                // day
01262   c4day[4]='\0';
01263   leaderfile.read((char*)&c4dayofyear,sizei4);          // day of year
01264   c4dayofyear[4]='\0';
01265   leaderfile.read((char*)&c22seconds,sized22);          // sec
01266   c22seconds[22]='\0';
01267   leaderfile.read((char*)&c22interval,sized22);         // interval time
01268   c22interval[22]='\0';
01269   leaderfile.read((char*)&c64rcs,sizea64);              // ref. coord. system
01270   c64rcs[64]='\0';
01271   leaderfile.read((char*)&c22gmha,sized22);             // greenwich mean hour angle
01272   c22gmha[22]='\0';
01273   leaderfile.read((char*)&c16ltposerr,sizef16);         // along track pos. error
01274   c16ltposerr[16]='\0';
01275   leaderfile.read((char*)&c16ctposerr,sizef16);         // across track pos. error
01276   c16ctposerr[16]='\0';
01277   leaderfile.read((char*)&c16rposerr,sizef16);          // radial pos. error
01278   c16rposerr[16]='\0';
01279 
01280 // ______ Read statevector of data points ______
01281   if (numdatapoints==0) // test, sometimes on linux problems
01282     {
01283     WARNING.print("numdatapoints=0: probalbly something wrong with filepointer");
01284     WARNING.print("But continuing, be very careful!");
01285     numdatapoints=1;                                    // arbitrary...
01286     STATE.resize(6,numdatapoints);                      // storage statevector
01287     }
01288   else
01289     {
01290     STATE.resize(6,numdatapoints);                      // storage statevector
01291     for (register int32 i=0;i<numdatapoints;i++)        // number of data points
01292       {
01293       leaderfile.seekg(startrec4+386+i*132,ios::beg);   // start ith datarecord
01294       for (register int32 j=0;j<6;j++)                  // read x,y,z,xdot,ydot,zdot
01295         {
01296         leaderfile.read((char*)&c22dummy,sized22);
01297         c22dummy[22]='\0';
01298         STATE(j,i)=atof(c22dummy);
01299         }
01300       }
01301     }
01302 
01303   // --- RECORD 5 (Bianca Cassee) slc facility related data record [general type]) ---
01304   DEBUG.print("record 5 of leader file.");              //bc 18 dec 2003
01305   uint startrec5=lenrec1+lenrec2+lenrec3+lenrec4;       //bc
01306   leaderfile.seekg(startrec5+8,ios::beg);       //slc facility related 
01307   leaderfile.read((char*)&lenrec5,sizeb4);      //bc length of record4
01308   lenrec5 = ntohl(lenrec5);                     //byteorder x86 machines.
01309   DEBUG << "readleader::record 5: start at: " << startrec5 
01310         << "; length: " << lenrec5;
01311   DEBUG.print();
01312  
01313 
01314   // ______ Calibration information  ______              //bc
01315   leaderfile.seekg(startrec5+582,ios::beg);             //bc
01316   leaderfile.read((char*)&c16incangle1strange,sizef16); //bc
01317   c16incangle1strange[16]='\0';                         //bc
01318   leaderfile.read((char*)&c16incanglecenrange,sizef16); //bc
01319   c16incanglecenrange[16]='\0';                         // gk bc
01320   leaderfile.read((char*)&c16incanglelstrange,sizef16); //bc
01321   c16incanglelstrange[16]='\0';                         //bc
01322   leaderfile.seekg(startrec5+662,ios::beg);             //gk
01323   leaderfile.read((char*)&calK,sizef16);                //gk
01324   calK[16]='\0';                                        //gk
01325   leaderfile.seekg(startrec5+566,ios::beg);             //gk
01326   leaderfile.read((char*)&repplspwr,sizef16);           //gk
01327   repplspwr[16]='\0';                                   //gk
01328   // ___ BK: number of invalid samples at end (DPAF/UKPAF problem) ___
01329   char  c4SWSTflag[5];                                  //bk
01330   char  c4SWSTchange[5];                                //bk
01331   char  c4missingrawlines[5];                           //bk
01332   char  c4validperline[5];                              //bk
01333   leaderfile.seekg(startrec5+98,ios::beg);
01334   leaderfile.read((char*)&c4SWSTflag,sizei4);           // numsamples
01335   c4SWSTflag[4]='\0';
01336   if (atoi(c4SWSTflag) != 0)
01337     WARNING.print("SWST was not constant");
01338   leaderfile.seekg(startrec5+138,ios::beg);
01339   leaderfile.read((char*)&c4SWSTchange,sizei4);         // numsamples
01340   c4SWSTchange[4]='\0';
01341   if (atoi(c4SWSTchange) != 0)
01342     {
01343     WARNING << "c4SWSTchange: " << c4SWSTchange;
01344     WARNING.print();
01345     }
01346   leaderfile.seekg(startrec5+142,ios::beg);
01347   leaderfile.read((char*)&c4missingrawlines,sizei4);            // numsamples
01348   c4missingrawlines[4]='\0';
01349   if (atoi(c4missingrawlines) != 0)
01350     {
01351     WARNING << "c4missingrawlines: " << c4missingrawlines;
01352     WARNING.print();
01353     }
01354   leaderfile.seekg(startrec5+1722,ios::beg);
01355   leaderfile.read((char*)&c4validperline,sizei4);               // numsamples
01356   c4validperline[4]='\0';
01357   DEBUG << "c4validperline: " << c4validperline;
01358   DEBUG.print();
01359 
01360   /*
01361   leaderfile.seekg(startrec5+XXX,ios::beg);
01362   leaderfile.read((char*)&c4numvalid,sizei4);           // numsamples
01363   c4numvalid[4]='\0';
01364   leaderfile.read((char*)&c4numinvalid,sizei4);         // zero padded at end
01365   c4numinvalid[4]='\0';
01366   if (atoi(c4numinvalid) != 0)
01367     {
01368     WARNING << "Number of invalid samples " << c4numinvalid 
01369             << " not 0: rsr may be wrongly computed.";
01370     WARNING.print();
01371     }
01372   */
01373 
01374   //  // --- RECORD 6 (slc facility related data record [pcs type]) ---
01375   //  DEBUG.print("record 6 of leader file.");                 //gk 28 jan 2004
01376   //  uint startrec6=lenrec1+lenrec2+lenrec3+lenrec4+lenrec5;  //gk
01377   //  leaderfile.seekg(startrec6+8,ios::beg);       //slc facility related 
01378   //  leaderfile.read((char*)&lenrec6,sizeb4);      //gk length of record5
01379   //  lenrec6 = ntohl(lenrec6);                     //byteorder x86 machines.
01380   //  DEBUG << "readleader::record 6: start at: " << startrec6 
01381   //        << "; length: " << lenrec6;
01382   //  DEBUG.print();
01383 
01384   }// endif ERS/RSAT
01385 else//RSAT method specified
01386   {
01387   skipmapprojrecord = true;// RSAT does not have this here
01388   // --- RECORD 3 (skip) ---
01389   DEBUG.print("record 3 of RSAT leader file (data quality).");
01390   uint startrec3 = lenrec1 + lenrec2;
01391   leaderfile.seekg(startrec3,ios::beg);//
01392   leaderfile.read((char*)&rec_seq,sizeb4);//  record number
01393   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
01394   leaderfile.read((char*)&rec_sub1,sizeb1);// first record sub type code
01395   leaderfile.read((char*)&rec_type,sizeb1);// record type code
01396   leaderfile.read((char*)&rec_sub2,sizeb1);// second record sub type code
01397   leaderfile.read((char*)&rec_sub3,sizeb1);// third record sub type code
01398   DEBUG.print("ERS:  Expecting record 3 with code {10,20,31,20}");
01399   DEBUG.print("RSAT: Expecting record 3 with code {18,60,18,20}");
01400   DEBUG.print("RSAT record length should be 1620, ERS 1620");
01401   DEBUG << "rec_seq: " << rec_seq 
01402         << "; rec_sub1: " << int(rec_sub1)
01403         << "; rec_type: " << int(rec_type)
01404         << "; rec_sub2: " << int(rec_sub2)
01405         << "; rec_sub3: " << int(rec_sub3);
01406   DEBUG.print();
01407   leaderfile.seekg(startrec3+8,ios::beg);//
01408   leaderfile.read((char*)&lenrec3,sizeb4);// length of record3
01409   lenrec3 = ntohl(lenrec3);     // bk 6 jul 2000, byteorder x86 machines.
01410   DEBUG << "readleader::record 3: start at: " << startrec3 
01411         << "; length: " << lenrec3;
01412   DEBUG.print();
01413   if (int(rec_sub1)==18 && int(rec_type)==60 && int(rec_sub2)==18 && int(rec_sub3)==20)
01414     DEBUG.print("This is the expected RSAT record with code {18,60,18,20}");
01415   else
01416     WARNING.print("This is NOT the expected 3rd RSAT record with code {18,60,18,20}");
01417 
01418 
01419   // --- RECORD 4 (skip) ---
01420   DEBUG.print("record 4 of RSAT leader file (data hist).");
01421   uint startrec4 = lenrec1 + lenrec2 + lenrec3;
01422   leaderfile.seekg(startrec4,ios::beg);//
01423   leaderfile.read((char*)&rec_seq,sizeb4);//  record number
01424   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
01425   leaderfile.read((char*)&rec_sub1,sizeb1);// first record sub type code
01426   leaderfile.read((char*)&rec_type,sizeb1);// record type code
01427   leaderfile.read((char*)&rec_sub2,sizeb1);// second record sub type code
01428   leaderfile.read((char*)&rec_sub3,sizeb1);// third record sub type code
01429   DEBUG.print("ERS:  Expecting record 4 with code {10,30,31,20}");
01430   DEBUG.print("RSAT: Expecting record 4 with code {18,70,18,20}");
01431   DEBUG.print("RSAT record length should be 16920");
01432   DEBUG << "rec_seq: " << rec_seq 
01433         << "; rec_sub1: " << int(rec_sub1)
01434         << "; rec_type: " << int(rec_type)
01435         << "; rec_sub2: " << int(rec_sub2)
01436         << "; rec_sub3: " << int(rec_sub3);
01437   DEBUG.print();
01438   leaderfile.seekg(startrec4+8,ios::beg);//
01439   leaderfile.read((char*)&lenrec4,sizeb4);// length of record4
01440   lenrec4 = ntohl(lenrec4);     // bk 6 jul 2000, byteorder x86 machines.
01441   DEBUG << "readleader::record 4: start at: " << startrec4 
01442         << "; length: " << lenrec4;
01443   DEBUG.print();
01444   if (int(rec_sub1)==18 && int(rec_type)==70 && int(rec_sub2)==18 && int(rec_sub3)==20)
01445     DEBUG.print("This is the expected RSAT record with code {18,70,18,20}");
01446   else
01447     WARNING.print("This is NOT the expected 4th RSAT record with code {18,70,18,20}");
01448 
01449 
01450   // --- RECORD 5 (skip) ---
01451   DEBUG.print("record 5 of RSAT leader file (data hist).");
01452   uint startrec5 = lenrec1 + lenrec2 + lenrec3 + lenrec4;
01453   leaderfile.seekg(startrec5,ios::beg);//
01454   leaderfile.read((char*)&rec_seq,sizeb4);//  record number
01455   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
01456   leaderfile.read((char*)&rec_sub1,sizeb1);// first record sub type code
01457   leaderfile.read((char*)&rec_type,sizeb1);// record type code
01458   leaderfile.read((char*)&rec_sub2,sizeb1);// second record sub type code
01459   leaderfile.read((char*)&rec_sub3,sizeb1);// third record sub type code
01460   DEBUG.print("ERS:  Expecting record 5 with code {10,200,31,50}");
01461   DEBUG.print("RSAT: Expecting record 5 with code {18,70,18,20}");
01462   DEBUG.print("RSAT record length should be 16920");
01463   DEBUG << "rec_seq: " << rec_seq 
01464         << "; rec_sub1: " << int(rec_sub1)
01465         << "; rec_type: " << int(rec_type)
01466         << "; rec_sub2: " << int(rec_sub2)
01467         << "; rec_sub3: " << int(rec_sub3);
01468   DEBUG.print();
01469   leaderfile.seekg(startrec5+8,ios::beg);//
01470   leaderfile.read((char*)&lenrec5,sizeb4);// length of record5
01471   lenrec5 = ntohl(lenrec5);     // bk 6 jul 2000, byteorder x86 machines.
01472   DEBUG << "readleader::record 5: start at: " << startrec5 
01473         << "; length: " << lenrec5;
01474   DEBUG.print();
01475   if (int(rec_sub1)==18 && int(rec_type)==70 && int(rec_sub2)==18 && int(rec_sub3)==20)
01476     DEBUG.print("This is the expected RSAT record with code {18,70,18,20}");
01477   else
01478     WARNING.print("This is NOT the expected 5th RSAT record with code {18,70,18,20}");
01479 
01480 
01481   // --- RECORD 6 (read a bit) ---
01482   DEBUG.print("record 6 of RSAT leader file (detailed proc. param.).");
01483   uint startrec6 = lenrec1 + lenrec2 + lenrec3 + lenrec4 + lenrec5;
01484   leaderfile.seekg(startrec6,ios::beg);//
01485   leaderfile.read((char*)&rec_seq,sizeb4);//  record number
01486   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
01487   leaderfile.read((char*)&rec_sub1,sizeb1);// first record sub type code
01488   leaderfile.read((char*)&rec_type,sizeb1);// record type code
01489   leaderfile.read((char*)&rec_sub2,sizeb1);// second record sub type code
01490   leaderfile.read((char*)&rec_sub3,sizeb1);// third record sub type code
01491   DEBUG.print("ERS:  Expecting record 6 with code {10,200,31,50}");
01492   DEBUG.print("RSAT: Expecting record 6 with code {18,120,18,20}");
01493   DEBUG.print("RSAT record length should be 7726");
01494   DEBUG << "rec_seq: " << rec_seq 
01495         << "; rec_sub1: " << int(rec_sub1)
01496         << "; rec_type: " << int(rec_type)
01497         << "; rec_sub2: " << int(rec_sub2)
01498         << "; rec_sub3: " << int(rec_sub3);
01499   DEBUG.print();
01500   leaderfile.seekg(startrec6+8,ios::beg);//
01501   leaderfile.read((char*)&lenrec6,sizeb4);// length of record5
01502   lenrec6 = ntohl(lenrec6);     // bk 6 jul 2000, byteorder x86 machines.
01503   DEBUG << "readleader::record 6: start at: " << startrec6
01504         << "; length: " << lenrec6;
01505   DEBUG.print();
01506   if (int(rec_sub1)==18 && int(rec_type)==120 && int(rec_sub2)==18 && int(rec_sub3)==20)
01507     DEBUG.print("This is the expected RSAT record with code {18,120,18,20}");
01508   else
01509     WARNING.print("This is NOT the expected 6th RSAT record with code {18,120,18,20}");
01510 
01511   DEBUG.print("todo: read asc/desc, BEAM, etc.");
01512   // TODO: Annex B-11: LEA record 6
01513   // if center lat not known, it seems here too, ignore them
01514 
01515 
01516   // --- RECORD 7 (read platform data) ---
01517   DEBUG.print("record 7 of RSAT leader file (platform pos. data).");
01518   DEBUG.print("this is exact same as for ERS, but in later record.");
01519   uint startrec7 = lenrec1 + lenrec2 + lenrec3 + lenrec4 + lenrec5 + lenrec6;
01520   leaderfile.seekg(startrec7,ios::beg);//
01521   leaderfile.read((char*)&rec_seq,sizeb4);//  record number
01522   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
01523   leaderfile.read((char*)&rec_sub1,sizeb1);// first record sub type code
01524   leaderfile.read((char*)&rec_type,sizeb1);// record type code
01525   leaderfile.read((char*)&rec_sub2,sizeb1);// second record sub type code
01526   leaderfile.read((char*)&rec_sub3,sizeb1);// third record sub type code
01527   DEBUG.print("RSAT: Expecting record 7 with code {18,30,18,20}");
01528   DEBUG.print("RSAT record length should be 8960");
01529   DEBUG << "rec_seq: " << rec_seq 
01530         << "; rec_sub1: " << int(rec_sub1)
01531         << "; rec_type: " << int(rec_type)
01532         << "; rec_sub2: " << int(rec_sub2)
01533         << "; rec_sub3: " << int(rec_sub3);
01534   DEBUG.print();
01535   leaderfile.seekg(startrec7+8,ios::beg);//
01536   leaderfile.read((char*)&lenrec7,sizeb4);// length of record5
01537   lenrec7 = ntohl(lenrec7);     // bk 6 jul 2000, byteorder x86 machines.
01538   DEBUG << "readleader::record 7: start at: " << startrec7
01539         << "; length: " << lenrec7;
01540   DEBUG.print();
01541   if (int(rec_sub1)==18 && int(rec_type)==30 && int(rec_sub2)==18 && int(rec_sub3)==20)
01542     DEBUG.print("This is the expected RSAT record with code {18,30,18,20}");
01543   else
01544     WARNING.print("This is NOT the expected 7th RSAT record with code {18,30,18,20}");
01545   // ______ Keppler elements may be useful to get some sort of orbit data points ______
01546   // ______ by evaluating them myself, in earth fixed system ______
01547   char  c16semimajor[17];
01548   char  c16inclination[17];
01549   char  c16eccentricity[17];
01550   char  c16argofperi[17];
01551   char  c16lonofnode[17];
01552   char  c16meananomaly[17];
01553   leaderfile.seekg(startrec7+44,ios::beg);
01554   leaderfile.read((char*)&c16semimajor,sizef16);
01555   c16semimajor[16]='\0';
01556   leaderfile.read((char*)&c16inclination,sizef16);
01557   c16inclination[16]='\0';
01558   leaderfile.read((char*)&c16eccentricity,sizef16);
01559   c16eccentricity[16]='\0';
01560   leaderfile.read((char*)&c16argofperi,sizef16);
01561   c16argofperi[16]='\0';
01562   leaderfile.read((char*)&c16lonofnode,sizef16);
01563   c16lonofnode[16]='\0';
01564   leaderfile.read((char*)&c16meananomaly,sizef16);
01565   c16meananomaly[16]='\0';
01566   INFO.print("Orbit Kepplerian elements follow:");
01567   INFO << "c16semimajor [km]:     " << c16semimajor;
01568   INFO.print();
01569   INFO << "c16inclination [rad]:  " << c16inclination;
01570   INFO.print();
01571   INFO << "c16eccentricity [-]:   " << c16eccentricity;
01572   INFO.print();
01573   INFO << "c16argofperi [rad]:    " << c16argofperi;
01574   INFO.print();
01575   INFO << "c16lonofnode [rad]:    " << c16lonofnode;
01576   INFO.print();
01577   INFO << "c16meananomaly [rad]:  " << c16meananomaly;
01578   INFO.print();
01579   //real8 semimajor = atof(c16semimajor);
01580 
01581   // ______ Positional data points ______
01582   leaderfile.seekg(startrec7+140,ios::beg);
01583   leaderfile.read((char*)&c4dummy,sizei4);              // number of data points
01584   c4dummy[4]='\0';
01585   numdatapoints = atoi(c4dummy);
01586   leaderfile.read((char*)&c4year,sizei4);               // year of first data point
01587   c4year[4]='\0';
01588   leaderfile.read((char*)&c4month,sizei4);              // month of first data point
01589   c4month[4]='\0';
01590   leaderfile.read((char*)&c4day,sizei4);                // day of first data point
01591   c4day[4]='\0';
01592   leaderfile.read((char*)&c4dayofyear,sizei4);          // daynumber of year
01593   c4dayofyear[4]='\0';
01594   leaderfile.read((char*)&c22seconds,sized22);          // sec of day of first point
01595   c22seconds[22]='\0';
01596   leaderfile.read((char*)&c22interval,sized22);         // interval time
01597   c22interval[22]='\0';
01598   leaderfile.read((char*)&c64rcs,sizea64);              // ref. coord. system
01599   c64rcs[64]='\0';
01600   leaderfile.read((char*)&c22gmha,sized22);             // greenwich mean hour angle
01601   c22gmha[22]='\0';
01602   leaderfile.read((char*)&c16ltposerr,sizef16);         // along track pos. error
01603   c16ltposerr[16]='\0';
01604   leaderfile.read((char*)&c16ctposerr,sizef16);         // across track pos. error
01605   c16ctposerr[16]='\0';
01606   leaderfile.read((char*)&c16rposerr,sizef16);          // radial pos. error
01607   c16rposerr[16]='\0';
01608 
01609   // --- Maybe Julian Day is useful for conversion ---
01610   INFO << "Seconds of day of first data point: " << c22seconds;
01611   INFO.print();
01612   INFO << "Day of data:        " << c4day;
01613   INFO.print();
01614   INFO << "Month of data:      " << c4month;
01615   INFO.print();
01616   INFO << "Year of data:       " << c4year;
01617   INFO.print();
01618   int32 jd_statevector = julday(atoi(c4day),atoi(c4month),atoi(c4year));
01619   INFO << "Julian Day of data: " << jd_statevector;
01620   INFO.print();
01621 
01622 
01623   // ______ Read statevector of data points ______
01624   STATE.resize(6,numdatapoints);                        // storage statevector
01625   for (register int32 i=0;i<numdatapoints;i++)          // number of data points
01626     {
01627     leaderfile.seekg(startrec7+386+i*132,ios::beg);     // start ith datarecord
01628     for (register int32 j=0;j<6;j++)                    // read x,y,z,xdot,ydot,zdot
01629       {
01630       leaderfile.read((char*)&c22dummy,sized22);
01631       c22dummy[22]='\0';
01632       STATE(j,i)=atof(c22dummy);
01633       }
01634     }
01635   // --- if this is an inertial system (rsat) we need to convert to earth fixed ---
01636   // --- Moreover: we want to reduce the number of data points to local arc ------- 
01637   WARNING.print("Convert orbit data to earth fixed (please check this).");
01638   if (!(strcmp(c64rcs,"INERTIAL")))
01639     INFO.print("Inertial system for orbit: transforming to Earth fixed.");
01640   else
01641     WARNING.print("system for orbit: transforming to Earth fixed (?).");
01642   // This angle refers to ascending node of equator crossing (time), ie. where Z=0
01643   // not to first state vectors time!  so following is wrong... ?
01644   // note that we have also the Keppler elements, etc.
01645   real8 csi2cse  = -1.0;// 1 for initial to earth fixed, -1 for back transform
01646   real8 GMHA     = deg2rad(atof(c22gmha));// Greenwich Mean Hour Angle in [deg]
01647   real8 earthrot = 7.292115856E-5;// [rad/s] 2pi rad in 23h56'04.091" (siderial day)
01648   // can we simply use the given Greenwich mean angle to rotate around Z?
01649   // or do we need to take precesion.nutation polarwobble into account?
01650   // to what (time) does the annotated GMHA refer?
01651   DEBUG << "GMHA [rad]: " << GMHA; 
01652   DEBUG.print();
01653   DEBUG << "Convertion from inertial to earth fixed [1/-1]: " << csi2cse; 
01654   DEBUG.print();
01655   DEBUG << "earthrot [rad/s]: " << earthrot; 
01656   DEBUG.print();
01657   // --- Create a new state vector matrix ---
01658   // --- these computation could be checked by using TIEPOINT, the center point -----
01659   // --- Limit to only 2 points before, 2 after scene, and use polyfit(3) interp. ---
01660   // --- Still this seems to have a large error... ---
01661   STATE_INERTIAL = STATE;// copy the Z values
01662   for (register int32 i=0;i<numdatapoints;i++)  // number of data points
01663     {
01664     real8 dt       = real8(i)*atof(c22interval);// since annotated GMHA???
01665     real8 angle    = csi2cse*(GMHA+earthrot*dt);// current angle of Greenwich
01666     DEBUG << "current angle for this data point [deg]: " << rad2deg(angle); 
01667     DEBUG.print();
01668     STATE(0,i)     = cos(angle)*STATE_INERTIAL(0,i)-sin(angle)*STATE_INERTIAL(1,i);// x
01669     STATE(1,i)     = sin(angle)*STATE_INERTIAL(0,i)+cos(angle)*STATE_INERTIAL(1,i);// y
01670     //STATE(2,i)     = STATE_INERTIAL(2,i);// Z is same
01671     STATE(3,i)     = -1.0*csi2cse*earthrot*
01672                      (sin(angle)*STATE_INERTIAL(0,i)+cos(angle)*STATE_INERTIAL(1,i))+
01673                       cos(angle)*STATE_INERTIAL(3,i)-sin(angle)*STATE_INERTIAL(4,i);// xdot
01674     STATE(4,i)     = csi2cse*earthrot*
01675                      (cos(angle)*STATE_INERTIAL(0,i)-sin(angle)*STATE_INERTIAL(1,i))+
01676                       sin(angle)*STATE_INERTIAL(3,i)+cos(angle)*STATE_INERTIAL(4,i);// ydot
01677     //STATE(5,i)     = STATE_INERTIAL(5,i);// Zdot is same ?
01678     }
01679   INFO.print("info on fast/slow time is obtained in readdat, not here.");
01680   WARNING.print("todo: reduce the number of orbital data to arc around area only");
01681   // --- Limit the data points to 2 points before/after: 32 minutes ---
01682   // --- better yet, interpolate using keppler to 5 points 5 seconds dt over take ---
01683 }
01684 
01685   leaderfile.close();
01686 
01687 
01688 
01689 // ====== Compute prf and rsr and use these (based on data is better) ======
01690   if (readfiles_arg.sar_processor==SARPR_ATL)
01691     skipmapprojrecord = true;
01692   real8 prfcomputed;            // [Hz]  written to result file
01693   real8 rsrcomputed;            // [MHz] written to result file
01694   if (skipmapprojrecord==true)  // not present in old? ESA.SLC versions?
01695     {
01696     strcpy(c32projection,"skipped");
01697     strcpy(c16numpix,    "skipped");
01698     strcpy(c16numlin,    "skipped");
01699     //strcpy(c16numpix,     c16scenewidth);
01700     //strcpy(c16numlin,     c16scenelength);
01701     strcpy(c16interpix,  "skipped");
01702     strcpy(c16interlin,  "skipped");
01703     strcpy(c16orien,     "skipped");
01704     strcpy(c16platincl,  "skipped");
01705     strcpy(c16platascn,  "skipped");
01706     strcpy(c16geocenter, "skipped");
01707     strcpy(c16platalt,   "skipped");
01708     strcpy(c16platgs,    "skipped");
01709     strcpy(c16plathead,  "skipped");
01710     strcpy(c32refellips, "skipped");
01711     strcpy(c16refmajor,  "skipped");
01712     strcpy(c16refminor,  "skipped");
01713     strcpy(c16lat11,     "skipped");
01714     strcpy(c16lon11,     "skipped");
01715     strcpy(c16lat1N,     "skipped");
01716     strcpy(c16lon1N,     "skipped");
01717     strcpy(c16latNN,     "skipped");
01718     strcpy(c16lonNN,     "skipped");
01719     strcpy(c16latN1,     "skipped");
01720     strcpy(c16lonN1,     "skipped");
01721     WARNING.print("Using nominal values for PRF, RSR, not computed.");
01722     WARNING.print(" + because map projection record not present(?).");
01723     prfcomputed = atof(c16prf);                 // Hz
01724     rsrcomputed = atof(c16samplingrate);        // MHz
01725     }
01726   else
01727     {
01728     // ______ Check prf ______
01729     struct tm tijdstart;
01730     struct tm tijdend;
01731     strptime(c24zd1stazitime,"%d-%b-%Y %T",&tijdstart);
01732     strptime(c24zdlstazitime,"%d-%b-%Y %T",&tijdend);
01733     int32 index=0;
01734     while (c24zd1stazitime[index] != '.')
01735       ++index;
01736     char fracsec1st[25];
01737     strcpy(fracsec1st,&c24zd1stazitime[index+1]);
01738     index=0;
01739     while (c24zdlstazitime[index] != '.')
01740       ++index;
01741     char fracseclst[25];
01742     strcpy(fracseclst,&c24zdlstazitime[index+1]);
01743     const real8 ta1 = atof(fracsec1st)/1000. +
01744       real8(tijdstart.tm_sec + 60*tijdstart.tm_min + 3600*tijdstart.tm_hour);
01745     const real8 taN = atof(fracseclst)/1000. +
01746       real8(tijdend.tm_sec + 60*tijdend.tm_min + 3600*tijdend.tm_hour);
01747     // BK 28-Sep-2000: numlin -1 !
01748     prfcomputed = (atof(c16numlin) - 1.) / (taN-ta1);
01749   
01750     // ______ compute rsr ______
01751     //  const real8 tr1     = atof(c16zd1strange);              // 2way ms
01752     //  const real8 trN     = atof(c16zdlstrange);              // 2way ms
01753     // BK 28-Sep-2000: numpix -1 !
01754     rsrcomputed = 0.001 * (atof(c16numpix)-1.0) /
01755                   (atof(c16zdlstrange)-atof(c16zd1strange));    // MHz
01756     } // else skipped map projection record
01757    
01758   // BK 28-Oct-2003, for Atlantis processor
01759   // ___ Check if rsr is in MHz, assume about 20 MHz ---
01760   //if (rsrcomputed>10000000.0 && rsrcomputed<30000000.0)
01761   if (rsrcomputed>10000.0)
01762     {
01763     WARNING.print("Adapting RSR from Hz to MHz.");
01764     WARNING << "Old value rsrcomputed: " << rsrcomputed
01765             << "; new value rsrcomputed: " << rsrcomputed/1e6;
01766     WARNING.print();
01767     rsrcomputed/=1e6;
01768     }
01769   real8 rangebandwidth = atof(c16bandrangetot);
01770   if (rangebandwidth < 1.0)// e.g. JERS not annotated.
01771     {
01772     WARNING.print("computed rangebandwidth < 1.0 ignoring this.");
01773     rangebandwidth = rsrcomputed;// set this to no oversampling
01774     }
01775   //if (rangebandwidth>10000000.0 && rangebandwidth<30000000.0)
01776   if (rangebandwidth>10000.0)
01777     {
01778     WARNING.print("Adapting RBW from Hz to MHz.");
01779     WARNING << "Old value rangebandwidth: " << rangebandwidth
01780             << "; new value rangebandwidth: " << rangebandwidth/1e6;
01781     WARNING.print();
01782     rangebandwidth/=1e6;
01783     }
01784 
01785 
01786 // ====== Write information to scratchfiles ======
01787   ofstream scratchlogfile("scratchloglea", ios::out | ios::trunc);
01788   bk_assert(scratchlogfile,"readleader: scratchloglea",__FILE__,__LINE__);
01789 
01790   scratchlogfile 
01791     << "\n\n*******************************************************************"
01792     << "\n* EXTRACTED DATA FROM LEADER FILE: " 
01793     <<  readfiles_arg.leaderfile << " *"
01794     << "\n*******************************************************************"
01795 
01796     << "\n\nFile descriptor record"
01797     << "\n----------------------"
01798     << "\nFile name: "
01799     <<  c16leafilename
01800 
01801     << "\n\nSLC data set summary record: scene parameters"
01802     << "\n---------------------------------------------"
01803     << "\nScene reference number: \t\t\t\t" // (e.g. orbit-frame number): "
01804     <<  c32sceneref
01805     << "\nScene centre time (UTC) <YYYYMMDDhhmmssttt>: \t\t"
01806     <<  c32scenetime
01807     << "\nProcessed scene centre geodetic latitude"
01808     << "\n +(positive for North latitude) (degrees): \t\t"
01809     <<  c16centerlat
01810     << "\nProcessed scene centre longitude"
01811     << "\n +(negative for West longitude) (degrees): \t\t"
01812     <<  c16centerlon
01813     << "\nProcessed scene centre true heading (degrees): \t\t"
01814     <<  c16centerheading
01815     << "\nEllipsoid designator: \t\t\t\t\t"
01816     <<  c16ellipsoid
01817     << "\nEllipsoid semimajor axis (km): \t\t\t\t"
01818     <<  c16semimajor
01819     << "\nEllipsoid semiminor axis (km): \t\t\t\t"
01820     <<  c16semiminor
01821     << "\nEarth mass times grav. const. (M.G) (kg.m/s^2): \t"
01822     <<  c16GM
01823     << "\nEllipsoid J2 parameter: \t\t\t\t"
01824     <<  c16J2
01825     << "\nEllipsoid J3 parameter: \t\t\t\t"
01826     <<  c16J3
01827     << "\nEllipsoid J4 parameter: \t\t\t\t"
01828     <<  c16J4
01829     << "\nScene center line number (the line number at "
01830     << "\n +the scene centre including zero fill): \t\t"
01831     <<  scenecenterline
01832     << "\nScene center pixel number (the pixel number at"
01833     << "\n +the scene centre including zero fill): \t\t"
01834     <<  scenecenterpixel
01835     << "\nProcessed scene length incl. zero fill (km): \t\t"
01836     <<  c16scenelength
01837     << "\nProcessed scene width incl. zero fill (km): \t\t"
01838     <<  c16scenewidth
01839    
01840     << "\n\nSLC data set summary record: general mission/sensor parameters"
01841     << "\n--------------------------------------------------------------"
01842     << "\nSensor platform mission identifier: \t\t\t"
01843     <<  c16platformid
01844     << "\nSensor ID, mode of op. for this channel: \t\t"
01845     <<  c32sensorid
01846     << "\nOrbit number: \t\t\t\t\t\t\t"
01847     <<  c8orbitnr
01848     << "\nSensor platform geodetic latitude at nadir"
01849     << "\n +corresponding to scene centre"
01850     << "\n +(positive for North latitude) (degrees): \t\t\t"
01851     <<  c8platformlat
01852     << "\nSensor platform geodetic longitude at nadir"
01853     << "\n +corresponding to scene centre"
01854     << "\n +(negative for West longitude) (degrees): \t\t\t"
01855     <<  c8platformlon
01856     << "\nSensor platform heading at nadir"
01857     << "\n +corresponding to scene centre"
01858     << "\n +(clockwise positive from North) (degrees): \t\t\t"
01859     <<  c8platformheading
01860     << "\nSensor clock angle as measured relative to"
01861     << "\n +sensor platform flight direction (degrees): \t"
01862     <<  c8clockangle
01863     << "\nIncidence angle at scene centre as derived"
01864     << "\n +from sensor platform orientation (degrees): \t"
01865     <<  c8incidence
01866     << "\nRadar frequency (GHz): \t\t\t\t\t\t"
01867     <<  c8freq
01868     << "\nRadar wavelength (meters): \t\t\t"
01869     <<  c16wavelength
01870     << "\nMotion compensator identifier"
01871     << "\n +(00=no, 01=on board, 10=in processor, 11=both): \t"
01872     <<  c2motioncomp
01873     << "\nRange pulse specifier: \t\t\t\t\t"
01874     <<  c16pulse
01875     << "\nNominal range pulse (chirp) amplitude coefficient,"
01876     << "\n +constant term: \t\t\t\t\t"
01877     <<  c16ampconst
01878     << "\n +linear term (sec-1): \t\t\t\t\t"
01879     <<  c16amplinear
01880     << "\n +quadratic term (sec-2): \t\t\t\t"
01881     <<  c16ampquadratic
01882     << "\n +cubic term (sec-3): \t\t\t\t\t"
01883     <<  c16ampcubic
01884     << "\n +quartic term (sec-4): \t\t\t\t"
01885     <<  c16ampquartic
01886     << "\nNominal range pulse (chirp) phase coefficient,"
01887     << "\n +constant term (cycles): \t\t\t\t"
01888     <<  c16phaseconst
01889     << "\n +linear term (Hz): \t\t\t\t\t"
01890     <<  c16phaselinear
01891     << "\n +quadratic term (Hz/sec): \t\t\t\t"
01892     <<  c16phasequadratic
01893     << "\n +cubic term (Hz/sec2): \t\t\t\t"
01894     <<  c16phasecubic
01895     << "\n +quartic term (Hz/sec3): \t\t\t\t"
01896     <<  c16phasequartic
01897     << "\nDown linked chirp extraction index (samples): \t\t\t"
01898     <<  c8extindex
01899     << "\nRange sampling rate (MHz): \t\t\t\t"
01900     <<  c16samplingrate
01901     << "\nRange gate delay at early ege (in time)"
01902     << "\n +at the start of the image (microsec): \t"
01903     <<  c16rangedelay
01904     << "\nRange pulse length (microsec): \t\t\t\t"
01905     <<  c16ranpulselen
01906     << "\nBase band conversion flag: \t\t\t"
01907     <<  c4conversion
01908     << "\nRange compressed flag (YES=range compressed data): \t"
01909     <<  c4compression
01910     << "\nQuantization per channel I & Q"
01911     << "\n +(5I 5Q/6I 6Q for OGRB/OBRC) (bits): \t\t\t\t"
01912     <<  c8qperch
01913     << "\nQuantizer descriptor: \t\t\t\t\t"
01914     <<  c12qdesc
01915     << "\nDC Bias for I-component (actual value): \t\t"
01916     <<  c16dci
01917     << "\nDC Bias for Q-component (actual value): \t\t"
01918     <<  c16dcq
01919     << "\nGain imbalance for I & Q (actual value): \t\t"
01920     <<  c16imbalance
01921     << "\nAntenna mechanical boresight angle"
01922     << "\n +relative to platform vertical axis: \t\t\t"
01923     <<  c16boresight
01924     << "\nPulse Repetition Frequency (PRF) (actual value): \t"
01925     <<  c16prf
01926 
01927     << "\n\nSLC data set summary record: sensor specific parameters"
01928     << "\n-------------------------------------------------------"
01929   
01930     << "\nSatellite encoded binary time code: \t\t\t"
01931     <<  c16sattimecode
01932     << "\nSatellite clock time (UTC) (YYYYMMDDhhmmssttt): \t"
01933     <<  c32sattime
01934     << "\nSatellite clock step length (nanosec): \t\t\t\t"
01935     <<  c8satclockstep
01936 
01937     << "\n\nSLC data set summary record: general processing parameters"
01938     << "\n----------------------------------------------------------"
01939     << "\nProcessing facility identifier: \t\t\t"
01940     <<  c16facilityid
01941     << "\nProcessing system identifier: \t\t\t\t"
01942     <<  c8systemid
01943     << "\nProcessing version identifier: \t\t\t\t"
01944     <<  c8versionid
01945     << "\nProduct type specifier: \t\t\t\t"
01946     <<  c32typespec
01947     << "\nProcessing algorithm identifier: \t\t\t"
01948     <<  c32algid
01949     << "\nNominal number of looks processed in azimuth (looks): \t"
01950     <<  c16looksazi
01951     << "\nNominal number of looks processed in range (looks): \t"
01952     <<  c16looksrange
01953     << "\nBandwidth per look in azimuth (null-to-null) (Hz): \t"
01954     <<  c16bandazi
01955     << "\nBandwidth per look in range (MHz): \t\t\t"
01956     <<  c16bandrange
01957     << "\nTotal processor bandwidth in azimuth (Hz): \t\t"
01958     <<  c16bandazitot
01959     << "\nTotal processor bandwidth in range (MHz): \t\t"
01960     <<  c16bandrangetot
01961     << "\nWeighting function designator in azimuth: \t\t"
01962     <<  c32weightazi
01963     << "\nWeighting function designator in range: \t\t"
01964     <<  c32weightrange
01965     << "\nData input source: \t\t\t\t\t"
01966     <<  c16inputsource
01967     << "\nNominal resolution in range (3-dB width) (m): \t\t"
01968     <<  c16resrange
01969     << "\nNominal resolution in azimuth (3-dB width) (m): \t"
01970     <<  c16resazi
01971     << "\nAlong track Doppler frequency centroid"
01972     << "\n +at early edge of image"
01973     << "\n +constant term (Hz): \t\t\t\t\t"
01974     <<  c16atdoppcconst
01975     << "\n +linear term (Hz/sec): \t\t\t\t"
01976     <<  c16atdoppclinear
01977     << "\n +quadratic term (Hz/sec/sec): \t\t\t\t"
01978     <<  c16atdoppcquadratic
01979     << "\nCross track Doppler frequency centroid"
01980     << "\n +at early edge of image"
01981     << "\n +constant term (Doppler centroid) (Hz): \t\t"
01982     <<  c16xtdoppcconst
01983     << "\n +linear term (Slope of Doppler centroid) (Hz/sec): \t"
01984     <<  c16xtdoppclinear
01985     << "\n +quadratic term (Hz/sec/sec): \t\t\t\t"
01986     <<  c16xtdoppcquadratic
01987     << "\nTime direction indicator along pixel direction: \t"
01988     <<  c8timepix
01989     << "\nTime direction indicator along line direction: \t\t"
01990     <<  c8timeline
01991     << "\nAlong track Doppler frequency rate"
01992     << "\n +at early edge of image"
01993     << "\n +constant term (Hz/sec): \t\t\t\t"
01994     <<  c16atdopprconst
01995     << "\n +linear term (Hz/sec/sec): \t\t\t\t"
01996     <<  c16atdopprlinear
01997     << "\n +quadratic term (Hz/sec/sec/sec): \t\t\t"
01998     <<  c16atdopprquadratic
01999     << "\nCross track Doppler frequency rate"
02000     << "\n +at early edge of image"
02001     << "\n +constant term (Azimuth FM rate) (Hz/sec): \t\t"
02002     <<  c16xtdopprconst
02003     << "\n +linear term (Slope of Azimuth FM rate) (Hz/sec/sec): \t"
02004     <<  c16xtdopprlinear
02005     << "\n +quadratic term (Hz/sec/sec/sec): \t\t\t"
02006     <<  c16xtdopprquadratic
02007     << "\nLine content indicator: \t\t\t\t"
02008     <<  c8linecontent
02009     << "\nClutterlock applied flag: \t\t\t\t"
02010     <<  c4clutterlock
02011     << "\nAutofocussing applied flag: \t\t\t\t"
02012     <<  c4autofocus
02013     << "\nLine spacing (m): \t\t\t\t\t"
02014     <<  c16linespace
02015     << "\nPixel spacing (in range) (m): \t\t\t\t"
02016     <<  c16pixspace
02017     << "\nProcessor range compression designator: \t\t"
02018     <<  c16rcompdes
02019    
02020     << "\n\nSLC data set summary record: sensor specific local use segment"
02021     << "\n--------------------------------------------------------------"
02022     << "\nZero-doppler range time (two-way)"
02023     << "\n +of first range pixel (millisec): \t\t\t"
02024     <<  c16zd1strange
02025     << "\n +of centre range pixel (millisec): \t\t\t"
02026     <<  c16zdcenrange
02027     << "\n +of last range pixel (millisec): \t\t\t"
02028     <<  c16zdlstrange
02029     << "\nZero-doppler azimuth time"
02030     << "\n +of first azimuth pixel (UTC): \t\t"
02031     <<  c24zd1stazitime
02032     << "\n +of centre azimuth pixel (UTC): \t\t"
02033     <<  c24zdcenazitime
02034     << "\n +of last azimuth pixel (UTC): \t\t\t"
02035     <<  c24zdlstazitime
02036    
02037     << "\n\nMap projection data record: general information"
02038     << "\n-----------------------------------------------"
02039     << "\nMap projection descriptor: \t\t\t\t"
02040     <<  c32projection
02041     << "\nNumber of pixels per line of image: \t\t\t"
02042     <<  c16numpix
02043     << "\nNumber of lines: \t\t\t\t\t"
02044     <<  c16numlin
02045     << "\nNominal inter-pixel distance in output scene (m): \t"
02046     <<  c16interpix
02047     << "\nNominal inter-line distance in output scene (m): \t"
02048     <<  c16interlin
02049     << "\nOrientation at output scene centre"
02050     << "\n +[for geodetic products this is simply the"
02051     << "\n +convergence of the meridians, ie: the angle"
02052     << "\n +between geographic north and map grid north"
02053     << "\n +(angle of projection axis from true North)] (degrees): "
02054     <<  c16orien
02055     << "\nActual platform orbital inclination (degrees): \t\t"
02056     <<  c16platincl
02057     << "\nActual ascending node (longitude at equator) (degrees): "
02058     <<  c16platascn
02059     << "\nGeocentre to platform distance at input scene centre: \t"
02060     <<  c16geocenter
02061     << "\nPlatform geodetic altitude over the ellipsoid: \t\t"
02062     <<  c16platalt
02063     << "\nGround speed at nadir at input scene centre time: \t"
02064     <<  c16platgs
02065     << "\nPlatform heading at nadir"
02066     << "\n +corresponding to scene centre (degrees): \t\t"
02067     <<  c16plathead
02068     << "\nName of reference ellipsoid: \t\t\t\t"
02069     <<  c32refellips
02070     << "\nSemimajor axis of ref.ellipsoid (km): \t\t\t"
02071     <<  c16refmajor
02072     << "\nSemiminor axis of ref.ellipsoid (km): \t\t\t"
02073     <<  c16refminor
02074    
02075     << "\n\nMap projection data record: coordinates of four corner points"
02076     << "\n-------------------------------------------------------------"
02077     << "\n1st line 1st pixel geodetic latitude"
02078     << "\n +(positive for North latitude) (degrees): \t\t"
02079     <<  c16lat11
02080     << "\n1st line 1st pixel geodetic longitude"
02081     << "\n +(negative for West longitude) (degrees): \t\t"
02082     <<  c16lon11
02083     << "\n1st line last pixel geodetic latitude (degrees): \t"
02084     <<  c16lat1N
02085     << "\n1st line last pixel geodetic longitude (degrees): \t"
02086     <<  c16lon1N
02087     << "\nlast line last pixel geodetic latitude (degrees): \t"
02088     <<  c16latNN
02089     << "\nlast line last pixel geodetic longitude (degrees): \t"
02090     <<  c16lonNN
02091     << "\nlast line 1st pixel geodetic latitude (degrees): \t"
02092     <<  c16latN1
02093     << "\nlast line 1st pixel geodetic longitude (degrees): \t"
02094     <<  c16lonN1
02095    
02096     << "\n\nSLC platform position data record: positional data points"
02097     << "\n---------------------------------------------------------"
02098     << "\nNumber of data points: \t\t\t\t"
02099     <<  numdatapoints
02100     << "\nYear of data point <YYYY>: \t\t\t"
02101     <<  c4year
02102     << "\nMonth of data point <$$MM>: \t\t\t"
02103     <<  c4month
02104     << "\nDay of data point <$$DD>: \t\t\t"
02105     <<  c4day
02106     << "\nDay in the year <GMT> (jan 1st=day 1): \t\t"
02107     <<  c4dayofyear
02108     << "\nSeconds of day of data: \t\t\t"
02109     <<  c22seconds
02110     << "\nTime interval between data points: \t\t"
02111     <<  c22interval
02112     << "\nReference coordinate system: \t\t\t"
02113     <<  c64rcs
02114     << "\nGreenwich mean hour angle (degrees): \t\t"
02115     <<  c22gmha
02116     << "\nAlong track position error (meters): \t\t"
02117     <<  c16ltposerr
02118     << "\nAcross track position error (meters): \t\t"
02119     <<  c16ctposerr
02120     << "\nRadial position error (meters): \t\t"
02121     <<  c16rposerr
02122     
02123     << "\n\nSLC facility related data record [general type]: calibration information"
02124     << "\n------------------------------------------------------------------------" 
02125     << "\nIncidence angle at first range pixel (at mid-azimuth): \t"
02126     <<  c16incangle1strange //bc
02127     << "\nIncidence angle at centre range pixel (at mid-azimuth): " 
02128     <<  c16incanglecenrange //bc
02129     << "\nIncidence angle at last range pixel (at mid-azimuth): \t"
02130     <<  c16incanglelstrange //bc
02131     << "\nAbsolute calibration constant K: \t"
02132     <<  calK     //gk
02133     << "\nLenrec6: \t"
02134     <<  lenrec6  //gk
02135     << "\nReplica Pulse Power: \t"
02136     <<  repplspwr//gk
02137     << "\nNumber of valid samples:   \t\t\t" << c4numvalid
02138     << "\nNumber of invalid samples: \t\t\t" << c4numinvalid
02139     <<  endl;
02140   int32 point;
02141 
02142   // --- STATE VECTORS in INERTIAL SYSTEM ---
02143   // only convert these if RSAT and ATLANTIS?
02144 //if (readfiles_arg.sensor_id==SLC_RSAT)
02145 if (readfiles_arg.sensor_id==SLC_RSAT && readfiles_arg.sar_processor==SARPR_ATL)
02146   {
02147   scratchlogfile << "\nRSAT: INERTIAL system orbital data as in leaderfile";
02148   for (register int32 k=0;k<numdatapoints;k++)          // number of data points
02149     {
02150     point = k+1;
02151     real8 secofday = atof(c22seconds) + real8(k)*atof(c22interval);
02152   scratchlogfile << "\nSLC platform position data record: data point: " << point
02153                  << "\n------------------------------------------------\n"
02154                  << point << " data point - Seconds of day (s):    \t\t"
02155                  << setprecision(13) 
02156                  << secofday << endl
02157                  << point << " data point - Position vector X (m): \t\t"
02158                  << setprecision(13) 
02159                  << STATE_INERTIAL(0,k) << endl
02160                  << point << " data point - Position vector Y (m): \t\t"
02161                  << setprecision(13) 
02162                  << STATE_INERTIAL(1,k) << endl
02163                  << point << " data point - Position vector Z (m): \t\t"
02164                  << setprecision(13) 
02165                  << STATE_INERTIAL(2,k) << endl
02166                  << point << " data point - Velocity vector X (mm/s): \t"
02167                  << setprecision(13) 
02168                  << STATE_INERTIAL(3,k) << endl
02169                  << point << " data point - Velocity vector Y (mm/s): \t"
02170                  << setprecision(13) 
02171                  << STATE_INERTIAL(4,k) << endl
02172                  << point << " data point - Velocity vector Z (mm/s): \t"
02173                  << setprecision(13) 
02174                  << STATE_INERTIAL(5,k) << endl;
02175     }
02176   scratchlogfile << "\nRSAT: and converted to earth fixed using GMHA:";
02177   }
02178 
02179   // --- STATE VECTORS in EARTH FIXED SYSTEM ---
02180   for (register int32 k=0;k<numdatapoints;k++)          // number of data points
02181     {
02182     point = k+1;
02183     real8 secofday = atof(c22seconds) + real8(k)*atof(c22interval);
02184   scratchlogfile << "\nSLC platform position data record: data point: " << point
02185                  << "\n------------------------------------------------\n"
02186                  << point << " data point - Seconds of day (s):    \t\t"
02187                  << setprecision(13) 
02188                  << secofday << endl
02189                  << point << " data point - Position vector X (m): \t\t"
02190                  << setprecision(13) 
02191                  << STATE(0,k) << endl
02192                  << point << " data point - Position vector Y (m): \t\t"
02193                  << setprecision(13) 
02194                  << STATE(1,k) << endl
02195                  << point << " data point - Position vector Z (m): \t\t"
02196                  << setprecision(13) 
02197                  << STATE(2,k) << endl
02198                  << point << " data point - Velocity vector X (mm/s): \t"
02199                  << setprecision(13) 
02200                  << STATE(3,k) << endl
02201                  << point << " data point - Velocity vector Y (mm/s): \t"
02202                  << setprecision(13) 
02203                  << STATE(4,k) << endl
02204                  << point << " data point - Velocity vector Z (mm/s): \t"
02205                  << setprecision(13) 
02206                  << STATE(5,k) << endl;
02207     }
02208 
02209   scratchlogfile << "\nEND LEADER FILE "
02210                  <<  readfiles_arg.leaderfile
02211                  <<  endl << endl;
02212   scratchlogfile.close();
02213 
02214 
02215 
02216   // ___ "repair" bandwidth if not given, e.g., in JERS? ___
02217   if (atof(c16bandazitot) < 1.0)
02218     {
02219     WARNING.print("could not find azimuth band width, using prf...");
02220     strcpy(c16bandazitot,c16prf);
02221     }
02222   if (atof(c16bandrangetot) < 1.0)
02223     {
02224     WARNING.print("could not find range band width, using rsr...");
02225     strcpy(c16bandrangetot,c16samplingrate);
02226     }
02227 
02228   real8 wavelength_computed = atof(c16wavelength);// seems freq. not ok for RSAT
02229   // --- seems not all information there for Atlantis CEOS ---
02230   //if (readfiles_arg.sensor_id!=SLC_RSAT)
02231   if (readfiles_arg.sar_processor!=SARPR_ATL)
02232     {
02233     INFO << "Computing wavelength from radar freq. " << c8freq << "GHz";// GHz
02234     INFO.print();
02235     wavelength_computed = (0.000000001*SOL/atof(c8freq));// seems more reliable, BK 03/04
02236     INFO << "Annotated wavelength: " << c16wavelength << " re-computed: " << wavelength_computed;
02237     INFO.print();
02238     }
02239 
02240 // email KKMohanty: time indicator is different then line counter, i.e, image
02241 // can be flipped up/down left/right.  The utilities converting line number to
02242 // az_time can thus be confused.  Repair this.
02243 //  Time direction indicator along pixel direction:         INCREASE or DECREASE
02244 //  Time direction indicator along line direction:          INCREASE or DECREASE
02245 // BK 20-Apr-2004
02246   INFO.print("Checking time indicator along line direction.");
02247   // ___ check indicator in line direction ___
02248   if (!strcmp(c8timeline,"INCREASE"))
02249     {
02250     INFO.print("Time indicator along line direction is INCREASE, this is OK.");
02251     }
02252   else if (!strcmp(c8timeline,"DECREASE"))
02253     {
02254     WARNING.print("Time indicator along line direction is DECREASE: should adapt times.");
02255     WARNING.print("TODO: done for RSAT, not for ERS.");
02256     // ___ Adapt the time of first line/last line, such that orbit is correctly ___
02257     // ___ interpolated and line2ta works OK ___
02258     }
02259   else
02260     {
02261     WARNING.print("unexpected: time indicator along line direction not INCREASE nor DECREASE.");
02262     }
02263   // ___ check indicator in pixel direction ___
02264   if (!strcmp(c8timepix,"INCREASE"))
02265     {
02266     INFO.print("Time indicator along pixel direction is INCREASE, this is OK.");
02267     }
02268   else if (!strcmp(c8timepix,"DECREASE"))
02269     {
02270     WARNING.print("Time indicator along pixel direction is DECREASE: should adapt times.");
02271     WARNING.print("TODO: done for RSAT, not for ERS.");
02272     }
02273   else
02274     {
02275     WARNING.print("unexpected: time indicator along pixel direction not INCREASE nor DECREASE.");
02276     }
02277 
02278 
02279 
02280   ofstream scratchresfile("scratchreslea", ios::out | ios::trunc);
02281   bk_assert(scratchresfile,"readleader: scratchreslea",__FILE__,__LINE__);
02282   scratchresfile
02283     << "Leader file:                                 \t" 
02284     <<  readfiles_arg.leaderfile
02285     << "\nSensor platform mission identifer:         \t"
02286     <<  c32sensorid
02287     << "\nScene_centre_latitude:                     \t"
02288     <<  c16centerlat
02289     << "\nScene_centre_longitude:                    \t"
02290     <<  c16centerlon
02291     << "\nRadar_wavelength (m):                      \t"
02292     //<< setw(30) // important to have enough digits
02293     << setprecision(16) // important to have enough digits
02294     <<  wavelength_computed;
02295     // <<  c16wavelength;
02296 
02297     // ______ Azimuth ______
02298 //if (readfiles_arg.sensor_id==SLC_RSAT)
02299 if (readfiles_arg.sar_processor==SARPR_ATL)
02300   {
02301   WARNING.print("First_pixel_azimuth_time not in leader, but done in readdat.");
02302   scratchresfile
02303     << "\nRSAT_First_pixel_azimuth_time (UTC):            \t"
02304     <<  "skipped_see_datfile_below";
02305     //<<  c24zd1stazitime;
02306   }
02307 else
02308   {
02309   scratchresfile
02310     << "\nFirst_pixel_azimuth_time (UTC):            \t"
02311     <<  c24zd1stazitime;
02312   }
02313   scratchresfile
02314     // email to ESA, they said this value is most accurate and should be used.
02315     //<< "\nPulse_Repetition_Frequency (actual, Hz):   \t"
02316     //<<  c16prf
02317     // (but that seems strange to me...)
02318       << "\nPulse_Repetition_Frequency (computed, Hz): \t"
02319       << setprecision(16)
02320       <<  prfcomputed
02321     << "\nTotal_azimuth_band_width (Hz):             \t"
02322     <<  c16bandazitot
02323     << "\nWeighting_azimuth:                         \t"
02324     <<  c32weightazi
02325     << "\nXtrack_f_DC_constant (Hz, early edge):     \t"
02326     <<  c16xtdoppcconst
02327     << "\nXtrack_f_DC_linear (Hz/s, early edge):     \t"
02328     <<  c16xtdoppclinear
02329     << "\nXtrack_f_DC_quadratic (Hz/s/s, early edge): \t"
02330     <<  c16xtdoppcquadratic;
02331 
02332 
02333     // ______ Range ______
02334 //if (readfiles_arg.sensor_id==SLC_RSAT)
02335 if (readfiles_arg.sar_processor==SARPR_ATL)
02336   {
02337   WARNING.print("Range_time_to_first_pixel not in leader, but done in readdat.");
02338   scratchresfile
02339     << "\nRSAT_Range_time_to_first_pixel (2way) (ms):     \t"
02340     <<  "skipped_see_datfile_below";
02341     //<<  c16zd1strange;
02342   }
02343 else
02344   {
02345   scratchresfile
02346     << "\nRange_time_to_first_pixel (2way) (ms):     \t"
02347     //<< setprecision(16) // this is a string..
02348     <<  c16zd1strange;
02349   }
02350   scratchresfile
02351     << "\nRange_sampling_rate (computed, MHz):       \t"
02352     << setprecision(16)
02353     <<  rsrcomputed
02354     //<< "\nRange_sampling_rate (leaderfile, MHz):      \t"
02355     //<<  c16samplingrate
02356     << "\nTotal_range_band_width (MHz):               \t"
02357     <<  rangebandwidth
02358     //<<  c16bandrangetot //new^, check if it is in MHz as expected.
02359     << "\nWeighting_range:                            \t"
02360     <<  c32weightrange
02361     << endl;
02362 
02363   scratchresfile.setf(ios::fixed | ios::floatfield);
02364   scratchresfile 
02365     << "\n\n*******************************************************************"
02366     << "\n*_Start_leader_datapoints"
02367     << "\n*******************************************************************"
02368     << "\nt(s)\t\tX(m)\t\tY(m)\t\tZ(m)"
02369     << "\nNUMBER_OF_DATAPOINTS: \t\t\t"
02370     <<  numdatapoints
02371     << endl;
02372 
02373   for (register int32 l=0;l<numdatapoints;l++)          // number of data points
02374     {
02375     scratchresfile 
02376       << setprecision(10) 
02377       << atof(c22seconds)+real4(l)*atof(c22interval);
02378     for (register int32 m=0;m<3;m++)                    // no velocities
02379       {
02380       scratchresfile 
02381         << " \t" 
02382         << setprecision(13) 
02383         << STATE(m,l);
02384       }
02385     scratchresfile << endl;
02386     }
02387   scratchresfile 
02388     << "\n*******************************************************************"
02389     << "\n* End_leader_datapoints:_NORMAL"      // fixed string...
02390     << "\n*******************************************************************\n";
02391   scratchresfile.close();
02392 
02393 
02394 // ______ Check with volumefile (but first write what is read) ______
02395   if (atoi(c16numlin) != checklines)
02396     {
02397     WARNING << "Number of lines of leader file seems "
02398          << "not to be consistent with volume file: "
02399          <<  c16numlin << " != " << checklines;
02400     WARNING.print();
02401     WARNING.print("This may be caused by wrong? format SLC of this PAF, check parameterpool.");
02402     }
02403   if (100*((atof(c16prf)-prfcomputed)/prfcomputed) > 2.)
02404     WARNING.print("deviation PRF computed from PRF read in leaderfile > 2%");
02405   if (100*((atof(c16samplingrate)-rsrcomputed)/rsrcomputed) > 2.)
02406     WARNING.print("deviation range sampling rate computed from RSR read in leaderfile > 2%");
02407 
02408 
02409 // ______ Write some info ______
02410   INFO << "Number of lines, pixels:               "
02411        << c16numlin << " " << c16numpix;
02412   INFO.print();
02413   INFO << "Pulse repetition frequency (Hz):       "
02414        << c16prf << ends;
02415   INFO.print();
02416   INFO << "Pulse repetition frequency (computed): " 
02417        << setprecision(16) << prfcomputed;
02418   INFO.print();
02419   INFO << "Range sampling rate (Mhz):             "
02420        << c16samplingrate << ends;
02421   INFO.print();
02422   INFO << "Range sampling rate (computed Mhz):    " 
02423        << setprecision(16) << rsrcomputed;
02424   INFO.print();
02425   INFO << "UTC of first azimuth line:             "
02426        << c24zd1stazitime;
02427   INFO.print();
02428   INFO << "UTC of last azimuth line:              "
02429        << c24zdlstazitime;
02430   INFO.print();
02431   INFO << "Range time to first pixel (2way ms):   "
02432        << c16zd1strange;
02433   INFO.print();
02434   INFO << "Range time to last pixel (2way ms):    "
02435        << c16zdlstrange;
02436   INFO.print();
02437   INFO << "First corner of image (lat,lon):       "
02438        << c16lat11 << " " << c16lon11;
02439   INFO.print();
02440   INFO << "Second corner of image (lat,lon):      "
02441        << c16lat1N << " " << c16lon1N;
02442   INFO.print();
02443   INFO << "Third corner of image (lat,lon):       "
02444        << c16latNN << " " << c16lonNN;
02445   INFO.print();
02446   INFO << "Fourth corner of image (lat,lon):      "
02447        << c16latN1 << " " << c16lonN1;
02448   INFO.print();
02449 
02450   INFO << "Weighting function designator azimuth: "
02451        << c32weightazi;
02452   INFO.print();
02453   toupper(c32weightazi);
02454   if (strncmp(c32weightazi,"HAMMING",7))
02455     {
02456     WARNING << INFO.get_str() << " not HAMMING.";
02457     WARNING.print();
02458     }
02459   INFO << "Weighting function designator range:   "
02460        << c32weightrange;
02461   INFO.print();
02462   toupper(c32weightrange);
02463   if (strncmp(c32weightrange,"HAMMING",7))
02464     {
02465     WARNING << INFO.get_str() << " not HAMMING.";
02466     WARNING.print();
02467     }
02468     
02469   PROGRESS.print("readleader finished.");
02470   } // END READLEADER
02471 
02472 
02473 
02474 /****************************************************************
02475  *    readnull                                                  *
02476  *                                                              *
02477  * reads nullfile                                               *
02478  *  and writes to scratchlogfile, scratchresfile                *
02479  * see: annex C ERS SAR.SLC CCTand EXABYTE                      *
02480  *      doc:er-is-epo-gs-5902.3                                 *
02481  *                                                              *
02482  *    Bert Kampes, 11-Dec-1998                                  *
02483  ****************************************************************/
02484 void readnull(
02485         const input_readfiles &readfiles_arg)
02486   {
02487 // ======Open files====== 
02488   ifstream nullfile;
02489   openfstream(nullfile,readfiles_arg.nullfile);
02490   bk_assert(nullfile,readfiles_arg.nullfile,__FILE__,__LINE__);
02491 
02492   ofstream scratchlogfile("scratchlognull", ios::out | ios::trunc);
02493   bk_assert(scratchlogfile,"readnull: scratchlognull",__FILE__,__LINE__);
02494 
02495   ofstream scratchresfile("scratchresnull", ios::out | ios::trunc);
02496   bk_assert(scratchresfile,"readnull: scratchresnull",__FILE__,__LINE__);
02497 
02498 // ======Read nullfile======
02499   DEBUG.print("nullfile should be read?");
02500 
02501 // ______Tidy up______
02502   nullfile.close();
02503   scratchlogfile.close();
02504   scratchresfile.close();
02505   PROGRESS.print("readnull finished.");
02506   } // END READNUL
02507 
02508 
02509 
02510 /****************************************************************
02511  *    readdat                                                   *
02512  *                                                              *
02513  * Extract info from data file,                                 *
02514  *  see also appendix C of CD-R distribution (ESA).             *
02515  * checks with volumefile #lines                                *
02516  * checks some things like numchannels                          *
02517  *                                                              *
02518  * info is written to scratchresfile?                           *
02519  *                                                              *
02520  *    Bert Kampes, 21-Dec-1998                                  *
02521  ****************************************************************/
02522 void readdat(
02523         input_readfiles &readfiles_arg,
02524         const int32 checklines)
02525   {
02526   TRACE_FUNCTION("readdat (BK 21-Dec-1998)")
02527   const int16           sizeb4 = 4,             // some constants for reading
02528                         sizeb1 = 1,
02529                         sizei4 = 4,             //   binary fields.
02530                         sizei6 = 6,
02531                         sizei8 = 8;
02532   uint                  numchannels,            // number of channels (=1?)
02533                         leftborder,             // offset (=0?)
02534                         rightborder,            // offset (=0?)
02535                         bottomborder,           // offset (=0?)
02536                         topborder;              // offset (=0?)
02537   uint                  numdatarec,             // number of SAR DATA records
02538                         numlines,               // number of lines
02539                         numpixels,              // number of pixels
02540                         numbytesdata,           // bytes per line
02541                         lendatarec2;            // SAR DATA records length
02542   char                  c4[5],                  // correctly 5 for \0
02543                         c6[7],                  // correctly 7 for \0
02544                         c8[9];                  // correctly 9 for \0
02545 
02546 
02547   // --- Check for RSAT #%// Bert Kampes, 02-Aug-2004 ---
02548   uint rec_seq;// type B4
02549   unsigned char rec_sub1, rec_type, rec_sub2, rec_sub3;// type B1
02550 
02551 
02552 
02553 // ______Open files______ 
02554   ifstream datfile;
02555   openfstream(datfile,readfiles_arg.datfile);
02556   bk_assert(datfile,readfiles_arg.datfile,__FILE__,__LINE__);
02557 
02558 
02559   // --- RECORD 1 ---
02560   DEBUG.print("record 1 of data file (ERS and RSAT).");
02561   datfile.seekg(0,ios::beg);//
02562   datfile.read((char*)&rec_seq,sizeb4);//  record number
02563   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
02564   datfile.read((char*)&rec_sub1,sizeb1);// first record sub type code
02565   datfile.read((char*)&rec_type,sizeb1);// record type code
02566   datfile.read((char*)&rec_sub2,sizeb1);// second record sub type code
02567   datfile.read((char*)&rec_sub3,sizeb1);// third record sub type code
02568   DEBUG.print("ERS/RSAT: Expecting record 1 with code {63,192,18,18}");
02569   DEBUG << "rec_seq: " << rec_seq 
02570         << "; rec_sub1: " << int(rec_sub1)
02571         << "; rec_type: " << int(rec_type)
02572         << "; rec_sub2: " << int(rec_sub2)
02573         << "; rec_sub3: " << int(rec_sub3);
02574   DEBUG.print();
02575   if (int(rec_sub1)==63 && int(rec_type)==192 && int(rec_sub2)==18 && int(rec_sub3)==18)
02576     DEBUG.print("This is the expected record with code {63,192,18,18}");
02577   else
02578     WARNING.print("This is NOT the expected record with code {63,192,18,18}");
02579   uint                  lenrec1;                // length of record1
02580   datfile.seekg(8,ios::beg);//
02581   datfile.read((char*)&lenrec1,sizeb4);// length of record
02582   lenrec1 = ntohl(lenrec1);     // bk 6 jul 2000, byteorder x86 machines.
02583   DEBUG.print("ERS:  Expecting record 1 with length 10012");
02584   DEBUG.print("RSAT: Expecting record 1 with length 16252");
02585   DEBUG << "readdat::record 1: start at: " << 0
02586         << "; length: " << lenrec1;
02587   DEBUG.print();
02588 
02589 
02590   // ====== Get general info ======
02591   datfile.seekg(180,ios::beg);
02592   datfile.read((char*)&c6,sizei6);              // number of SAR DATA records (lines)
02593   c6[6]='\0';
02594     numdatarec = atoi(c6);
02595   datfile.read((char*)&c6,sizei6);              // SAR DATA record length
02596   c6[6]='\0';
02597     lendatarec2 = atoi(c6);
02598   datfile.seekg(232,ios::beg);                  // SAR Related data
02599   datfile.read((char*)&c4,4);
02600   c4[4]='\0';
02601   numchannels = atoi(c4);
02602   datfile.read((char*)&c8,sizei8);
02603   c8[8]='\0';
02604   numlines = atoi(c8);
02605 
02606   datfile.read((char*)&c4,sizei4);
02607     c4[4]='\0';
02608     leftborder = atoi(c4);
02609   datfile.read((char*)&c8,sizei8);              // number of pixels
02610     c8[8]='\0';
02611     numpixels = atoi(c8);
02612   datfile.read((char*)&c4,sizei4);
02613     c4[4]='\0';
02614     rightborder = atoi(c4);
02615   datfile.read((char*)&c4,sizei4);
02616     c4[4]='\0';
02617     topborder = atoi(c4);
02618   datfile.read((char*)&c4,sizei4);
02619     c4[4]='\0';
02620     bottomborder = atoi(c4);
02621 
02622   datfile.seekg(280,ios::beg);                  // Record data
02623   datfile.read((char*)&c8,sizei8);
02624   c8[8]='\0';
02625   numbytesdata = atoi(c8);
02626 
02627 
02628 // ======Write to scratchfiles======
02629   ofstream scratchlogdat("scratchlogdat", ios::out | ios::trunc);
02630   bk_assert(scratchlogdat,"readdat: scratchlogdat",__FILE__,__LINE__);
02631 
02632   scratchlogdat << "\n\n*******************************************************************"
02633                 << "\n* EXTRACTED DATA FROM DATA FILE: " 
02634                 <<  readfiles_arg.datfile << " *"
02635                 << "\n*******************************************************************"
02636                 << "\nNumber of SAR channels in file:         \t"
02637                 <<  numchannels
02638                 << "\nNumber of lines:                        \t"
02639                 <<  numlines
02640                 << "\nNumber of pixels:                       \t"
02641                 <<  numpixels
02642                 << "\nNumber of left border pixels per line:  \t"
02643                 <<  leftborder
02644                 << "\nNumber of right border pixels per line: \t"
02645                 <<  rightborder
02646                 << "\nNumber of topborder lines:              \t"
02647                 <<  topborder
02648                 << "\nNumber of bottom border lines:          \t"
02649                 <<  bottomborder
02650                 << "\nNumber of bytes per data group:         \t"
02651                 <<  numbytesdata
02652                 <<  endl;
02653   scratchlogdat.close();
02654 
02655 
02656   // --- write RESULTFILE, add info for RSAT which was not in LEADER ---
02657   ofstream scratchresdat("scratchresdat", ios::out | ios::trunc);
02658   bk_assert(scratchresdat,"readdat: scratchresdat",__FILE__,__LINE__);
02659   scratchresdat << "Datafile: \t\t\t\t\t"
02660                 <<  readfiles_arg.datfile
02661                 << "\nNumber_of_lines_original: \t\t\t"
02662                 <<  numlines
02663                 << "\nNumber_of_pixels_original: \t\t\t"
02664                 <<  numpixels;
02665 
02666   // --- if rsat, read datfile further, write az/rg time ----------------
02667 //if (readfiles_arg.sensor_id==SLC_RSAT)
02668 if (readfiles_arg.sar_processor==SARPR_ATL)
02669   {
02670   // --- RECORD 2 ---
02671   uint startrec2 = lenrec1;
02672   DEBUG.print("record 2 of data file (RSAT).");
02673   datfile.seekg(startrec2,ios::beg);//
02674   datfile.read((char*)&rec_seq,sizeb4);//  record number
02675   rec_seq = ntohl(rec_seq);// Bert Kampes, 07-Apr-2005
02676   datfile.read((char*)&rec_sub1,sizeb1);// first record sub type code
02677   datfile.read((char*)&rec_type,sizeb1);// record type code
02678   datfile.read((char*)&rec_sub2,sizeb1);// second record sub type code
02679   datfile.read((char*)&rec_sub3,sizeb1);// third record sub type code
02680   DEBUG.print("RSAT: Expecting record 2 with code {50,11,18,20}");
02681   DEBUG << "rec_seq: " << rec_seq 
02682         << "; rec_sub1: " << int(rec_sub1)
02683         << "; rec_type: " << int(rec_type)
02684         << "; rec_sub2: " << int(rec_sub2)
02685         << "; rec_sub3: " << int(rec_sub3);
02686   DEBUG.print();
02687   if (int(rec_sub1)==50 && int(rec_type)==11 && int(rec_sub2)==18 && int(rec_sub3)==20)
02688     DEBUG.print("This is the expected record with code {50,11,18,20}");
02689   else
02690     WARNING.print("This is NOT the expected record with code {50,11,18,20}");
02691   uint                  lenrec2;                // length of record2
02692   datfile.seekg(startrec2+8,ios::beg);//
02693   datfile.read((char*)&lenrec2,sizeb4);// length of record
02694   lenrec2 = ntohl(lenrec2);     // bk 6 jul 2000, byteorder x86 machines.
02695   DEBUG.print("RSAT: Expecting record 2 with length variable");
02696   DEBUG << "readdat::record 2: start at: " << startrec2
02697         << "; length: " << lenrec2;
02698   DEBUG.print();
02699   uint startrec3 = lenrec1+lenrec2;
02700   uint startrecN = lenrec1+(numlines-1)*lenrec2;// start of last record
02701   // --- azimuth time to first line (depends on decrease/increase): ---
02702   uint zdmsecofday1 = 99999;// B4 
02703   uint zdmsecofday2 = 99999;// B4
02704   uint zdmsecofdayN = 99999;// B4
02705   datfile.seekg(startrec2+44,ios::beg);//
02706   datfile.read((char*)&zdmsecofday1,sizeb4);//  range to first pix
02707   zdmsecofday1 = ntohl(zdmsecofday1);// Bert Kampes, 07-Apr-2005
02708   datfile.seekg(startrec3+44,ios::beg);//
02709   datfile.read((char*)&zdmsecofday2,sizeb4);//  range to first pix
02710   zdmsecofday2 = ntohl(zdmsecofday2);// Bert Kampes, 07-Apr-2005
02711   datfile.seekg(startrecN+44,ios::beg);//
02712   datfile.read((char*)&zdmsecofdayN,sizeb4);//  range to first pix
02713   zdmsecofdayN = ntohl(zdmsecofdayN);// Bert Kampes, 07-Apr-2005
02714   INFO << "zdmsecofday1: " << zdmsecofday1;
02715   INFO.print();
02716   DEBUG << "zdmsecofday2: " << zdmsecofday2;
02717   DEBUG.print();
02718   INFO << "zdmsecofdayN: " << zdmsecofdayN;
02719   INFO.print();
02720   // --- Check PRF/RSR ---
02721   real8 prf_check = real8(numlines-1)/(abs(real8(zdmsecofday1)-real8(zdmsecofdayN))/1000.0);
02722   INFO << "PRF check (computed [Hz]): " << prf_check;
02723   INFO.print();
02724   
02725 
02726   // format should be: "22-AUG-1997 18:22:10.246"
02727   if (zdmsecofday1 < zdmsecofdayN)// increase, use ZD time of first line
02728     {
02729     INFO.print("INCREASING azimuth time detected RSAT");
02730     }
02731   else // decrease: use first-numlines*prf? or read last record.
02732     {
02733     INFO.print("DECREASING azimuth time detected (flip image up-down) RSAT");
02734     zdmsecofday1 = zdmsecofdayN;// use last record (line) as first line (flip)
02735     startrec2    = startrecN;// use last record (line) as first line (flip)
02736     }
02737   // --- Format the string UTC ---
02738   uint acq_year = 1999;
02739   uint acq_day  = 19;
02740   datfile.seekg(startrec2+36,ios::beg);//
02741   datfile.read((char*)&acq_year,sizeb4);//  range to first pix
02742   acq_year = ntohl(acq_year);// Bert Kampes, 07-Apr-2005
02743   datfile.read((char*)&acq_day,sizeb4);//  range to first pix
02744   acq_day = ntohl(acq_day);// Bert Kampes, 07-Apr-2005
02745   INFO << "acq_year: " << acq_year;
02746   INFO.print();
02747   INFO << "acq_day: " << acq_day;
02748   INFO.print();
02749   // --- fill tm struct using daynumber with strptime, re-format it using strftime ---
02750   char datestring[13];// e.g., "25-Jan-1999"
02751   struct tm tm_tmp;
02752   char buf[9]; // e.g., "1999 191";
02753   sprintf(buf,"%4d %03d", acq_year,acq_day);
02754   strptime(buf,"%Y %j",&tm_tmp);
02755   int q = strftime(datestring,12,"%d-%b-%Y",&tm_tmp);// q: number of bytes written
02756   INFO << "numbytes in datestring: (12?) " << q;
02757   INFO.print();
02758 
02759   // --- Fill important part: (sec of day) ---
02760   char c24zd1stazitime[25];
02761   int32 hour = int32(real8(zdmsecofday1)/1000.0/60.0/60.0);// floor
02762   int32 min  = int32((real8(zdmsecofday1)-hour*1000.0*60.0*60.0)/1000.0/60.0);// floor
02763   int32 sec  = int32((real8(zdmsecofday1)-hour*1000.0*60.0*60.0-min*1000.0*60.0)/1000.0);// floor
02764   int32 msec = int32((real8(zdmsecofday1)-hour*1000.0*60.0*60.0-min*1000.0*60.0-1000.0*sec));// floor
02765   //sprintf(c24zd1stazitime,"01-JAN-1990 %02d:%02d:%02d.%03d", hour,min,sec,msec);
02766   sprintf(c24zd1stazitime,"%11s %02d:%02d:%02d.%03d", datestring, hour,min,sec,msec);
02767   INFO << "c24zd1stazitime: " << c24zd1stazitime;
02768   INFO.print();
02769 
02770   // --- range time to first pixel is distance -------------------------
02771   uint range1st = 99999;//
02772   uint rangelst = 99999;
02773   datfile.seekg(startrec2+64,ios::beg);//
02774   datfile.read((char*)&range1st,sizeb4);//  range to first pix
02775   range1st = ntohl(range1st);// Bert Kampes, 07-Apr-2005
02776   datfile.seekg(startrec2+72,ios::beg);//
02777   datfile.read((char*)&rangelst,sizeb4);//  range to last pix
02778   rangelst = ntohl(rangelst);// Bert Kampes, 07-Apr-2005
02779   real8 zd1strange = (range1st<rangelst) ? 2000.0*range1st/SOL : 2000.0*rangelst/SOL;
02780   INFO << "range1st: " << range1st;
02781   INFO.print();
02782   INFO << "rangelst: " << rangelst;
02783   INFO.print();
02784   // --- Check PRF/RSR ---
02785   real8 rsr_check = real8(numpixels-1)/abs(2000000.0*(real8(range1st)-real8(rangelst))/SOL);
02786   INFO << "RSR check (computed [MHz]): " << rsr_check;
02787   INFO.print();
02788   
02789   //char dummydate[] = "01-JAN-1990 ";// not used except maybe getorb later
02790   //WARNING.print("RSAT: using a dummy date for orbit, only secofday important.");
02791   scratchresdat
02792     << "\nFirst_pixel_azimuth_time (UTC):            \t"
02793     //    << "22-AUG-1997 18:22:10.246"
02794     << c24zd1stazitime
02795     << "\nRange_time_to_first_pixel (2way) (ms):     \t"
02796     << setprecision(16)
02797     <<  zd1strange;
02798   }
02799 
02800   scratchresdat << "\n*******************************************************************";
02801   if (readfiles_arg.fileid == MASTERID)
02802     scratchresdat <<  "\n* End_" << processcontrol[pr_m_readfiles] << "_NORMAL";
02803   if (readfiles_arg.fileid == SLAVEID)
02804     scratchresdat <<  "\n* End_" << processcontrol[pr_s_readfiles] << "_NORMAL";
02805   scratchresdat << "\n*******************************************************************"
02806                 << endl;
02807   scratchresdat.close();
02808   datfile.close();
02809 
02810 // ______Tidy up______
02811   if (numchannels != 1)                         // ??
02812     {
02813     WARNING << "code 904: Number of channels in file: "
02814          << readfiles_arg.datfile << " = " 
02815          << numchannels << " != 1 ";
02816     WARNING.print();
02817     WARNING.print("this means SLC FORMAT IS DIFFERENT THEN EXPECTED.");
02818     }
02819 
02820 // ______ Check with volumefile ______
02821   if (numlines != checklines)
02822     {
02823     WARNING << "code 902: data file: "
02824          << readfiles_arg.datfile
02825          << " numlin=" << numlines
02826          << " vs.  volume file: "
02827          << readfiles_arg.volfile
02828          << " numlin=" << checklines;
02829     WARNING.print();
02830     WARNING.print(" +this means data and volume file seem not to correspond.");
02831     }
02832 
02833 // ______ Check with previous section ______
02834   if (numlines != numdatarec) 
02835     {
02836     WARNING << "code 904: Number of lines seems not to be consistent in file: " 
02837          << readfiles_arg.datfile << " : " << numlines << " != " << numdatarec;
02838     WARNING.print();
02839     WARNING.print(" +this means SLC FORMAT IS DIFFERENT THEN EXPECTED.");
02840     }
02841   if (bottomborder != topborder != leftborder != rightborder != 0)
02842     {
02843     WARNING << "code 904: Not implemented: offset border: left,right,bottom,top: " 
02844          << leftborder << "," << rightborder << "," << bottomborder << "," 
02845          << topborder << " in file: " << readfiles_arg.datfile;
02846     WARNING.print();
02847     WARNING.print(" +this means SLC FORMAT IS DIFFERENT THEN EXPECTED.");
02848     }
02849 
02850   if ((numbytesdata / 4) != numpixels)
02851     {
02852     WARNING << "code 904: Number of pixels seems to be inconsistent in file: "  
02853          << readfiles_arg.datfile << ": " 
02854          << numpixels << " != " << (numbytesdata / 4);
02855     WARNING.print();
02856     WARNING.print("this means SLC FORMAT IS DIFFERENT THEN EXPECTED.");
02857     }
02858   PROGRESS.print("readdat (header info) finished.");
02859   } // END readdat
02860 
02861 
02862 
02863 /****************************************************************
02864  *    writeslc                                                  *
02865  *                                                              *
02866  * Inputfile in ceos slc format is converted to                 *
02867  *  raw format outputfile.                                      *
02868  * Some info is extracted from header,                          *
02869  *  see also appendix C of CD-R distribution (ESA).             *
02870  * checks with volumefile #lines                                *
02871  *                                                              *
02872  * A buffer (BUFFERMEMSIZE) is used to increase speed.          *
02873  * Input is the inputfile and outputfile,                       *
02874  *  an identifier for this run,                                 *
02875  *  the area which should be converted (default is total image) *
02876  * info is written to scratchresfile                            *
02877  http://earth.esa.int/rootcollection/sysutil/01008.html
02878  *                                                              *
02879  *    Bert Kampes, 11-Dec-1998                                  *
02880  ****************************************************************/
02881 void writeslc(
02882         const input_gen &generalinput,
02883         const input_crop &crop_arg,
02884         const int       checklines)
02885   {
02886   const int16           sizeb4 = 4,             // some constants for reading
02887                         sizei4 = 4,             //   binary fields.
02888                         sizei6 = 6,
02889                         sizei8 = 8;
02890   uint                  lenrec1;                // length of general record1
02891   uint                  lenrec2;                // (nominal) length of data records
02892   char                  c4[5],                  // correctly 5 for \0
02893                         c6[7],                  // correctly 7 for \0
02894                         c8[9];                  // correctly 9 for \0
02895 
02896   // ______ Write some info ______ 
02897   TRACE_FUNCTION("writeslc (BK 11-Dec-1998)")
02898   PROGRESS.print("Start cropping slc data.");
02899   #ifdef __X86PROCESSOR__
02900   INFO.print("Swapping Big Endian (CEOS input) to Little Endian (your platform).");
02901   #else
02902   INFO.print("NO byte swapping performed, you must be on Big Endian platform.");
02903   #endif
02904 
02905   // ______ Open files ______ 
02906   ifstream datfile;
02907   openfstream(datfile,crop_arg.filein1);
02908   bk_assert(datfile,crop_arg.filein1,__FILE__,__LINE__);
02909 
02910   // ====== Get data such as recordlength ======
02911   datfile.seekg(8,ios::beg);
02912   datfile.read((char*)&lenrec1,sizeb4);         // length of record1
02913   lenrec1 = ntohl(lenrec1);     // bk 6 jul 2000, byteorder x86 machines.
02914   DEBUG.print("record 1 of data file.");
02915   if (lenrec1 != 19612 )  // quarter scene 10012? JERS 22196?
02916     {
02917     WARNING << "writeslc: length of record 1 = \""
02918          <<  lenrec1 << "\"; expected \"19612\" for ERS SLC (CEOS, full scene).";
02919     WARNING.print();
02920     DEBUG.print("10012 seems ERS quarter scene?");
02921     DEBUG.print("22196 seems JERS scene?");
02922     }
02923 
02924   datfile.seekg(180,ios::beg);
02925   datfile.read((char*)&c6,sizei6);              // number of SAR DATA records (lines)
02926     c6[6]='\0';
02927     const uint numdatarec = atoi(c6);
02928   DEBUG << "numdatarec: " << numdatarec;
02929   DEBUG.print();
02930   //datfile.seekg(186,ios::beg);
02931   datfile.read((char*)&c6,sizei6);              // SAR DATA record length
02932     c6[6]='\0';
02933     const uint lendatarec2 = atoi(c6);
02934   DEBUG << "lendatarec2: " << lendatarec2;
02935   DEBUG.print();
02936   datfile.seekg(232,ios::beg);                  // SAR Related data
02937   datfile.read((char*)&c4,4);
02938     c4[4]='\0';
02939     const uint numchannels = atoi(c4);
02940   DEBUG << "numchannels: " << numchannels;
02941   DEBUG.print();
02942 
02943   datfile.read((char*)&c8,sizei8);
02944     c8[8]='\0';
02945     uint numlines = atoi(c8);
02946   DEBUG << "numlines: " << numlines;
02947   DEBUG.print();
02948 
02949   datfile.read((char*)&c4,sizei4);
02950     c4[4]='\0';
02951     const uint leftborder = atoi(c4);
02952   DEBUG << "leftborder: " << leftborder;
02953   DEBUG.print();
02954   datfile.read((char*)&c8,sizei8);              // number of pixels
02955     c8[8]='\0';
02956     uint numpixels = atoi(c8);
02957   DEBUG << "numpixels: " << numpixels;
02958   DEBUG.print();
02959   datfile.read((char*)&c4,sizei4);
02960     c4[4]='\0';
02961     const uint rightborder = atoi(c4);
02962   DEBUG << "rightborder: " << rightborder;
02963   DEBUG.print();
02964   datfile.read((char*)&c4,sizei4);
02965     c4[4]='\0';
02966     const uint topborder = atoi(c4);
02967   DEBUG << "topborder: " << topborder;
02968   DEBUG.print();
02969   datfile.read((char*)&c4,sizei4);
02970     c4[4]='\0';
02971     const uint bottomborder = atoi(c4);
02972   DEBUG << "bottomborder: " << bottomborder;
02973   DEBUG.print();
02974 
02975   datfile.seekg(280,ios::beg);                  // Record data
02976   datfile.read((char*)&c8,sizei8);
02977     c8[8]='\0';
02978     const uint numbytesdata = atoi(c8);
02979   DEBUG << "numbytesdata: " << numbytesdata;
02980   DEBUG.print();
02981 
02982 
02983 // ====== Check with volumefile / internal ======
02984   if (numlines != checklines)
02985     {
02986     WARNING << "code 902: data file: "
02987          << crop_arg.filein1
02988          << " numlin=" << numlines
02989          << " vs. volume file: "
02990          << crop_arg.filein1
02991          << " numlin=" << checklines;
02992     WARNING.print();
02993     WARNING.print(" +this means data and volume file seem not to correspond.");
02994     }
02995 
02996 // ______ Check with previous section ______
02997   if (numlines != numdatarec) 
02998     {
02999     WARNING << "code 904: Number of lines seems not to be consistent in file: " 
03000          << crop_arg.filein1 << " : " << numlines << " != " << numdatarec;
03001     WARNING.print();
03002     WARNING.print(" +this means SLC FORMAT IS DIFFERENT THEN EXPECTED.");
03003     }
03004   if ((numbytesdata / 4) != numpixels)
03005     {
03006     WARNING << "code 904: Number of pixels seems to be inconsistent in file: "  
03007          << crop_arg.filein1 << ": " 
03008          << numpixels << " != " << (numbytesdata / 4);
03009     WARNING.print();
03010     WARNING.print(" +this means SLC FORMAT IS DIFFERENT THEN EXPECTED.");
03011     }
03012 
03013 
03014 // ====== Start copy input to output (raw) format with buffer======
03015 // ______ Check and process optional offset parameters______
03016 // ______ Lcnlow is corner line, lcnhi is other corner, pcnlow, pixel coord. low etc.
03017   uint linestart  = 1;                                  // counters for loops
03018   uint lineend    = numlines;
03019   uint pixelstart = 1;
03020   uint pixelend   = numpixels;                          // only for resultfile
03021 
03022   if (crop_arg.dbow.linehi!=0 && crop_arg.dbow.linelo!=0 && 
03023       crop_arg.dbow.pixhi!=0 && crop_arg.dbow.pixlo!=0)
03024     {
03025     window tempdbow(crop_arg.dbow.linelo, crop_arg.dbow.linehi,
03026                     crop_arg.dbow.pixlo,  crop_arg.dbow.pixhi);
03027     if (crop_arg.dbow.linehi>numlines)
03028       {
03029       WARNING << "Specified input DBOW linehi > numlines: "
03030            << crop_arg.dbow.linehi << " > " << numlines
03031            << ". I set linehi = " << numlines;
03032       WARNING.print();
03033       tempdbow.linehi=numlines;
03034       }
03035     if (crop_arg.dbow.pixhi>numpixels)
03036       {
03037       WARNING << "Specified input DBOW pixhi > numpixels: "
03038            << crop_arg.dbow.pixhi << " > " << numpixels
03039            << ". I set pixhi = " << numpixels;
03040       WARNING.print();
03041       tempdbow.pixhi=numpixels;
03042       }
03043 // ______ Only hi values are possibly adapted, low is a constant ______
03044     numlines   = tempdbow.linehi - crop_arg.dbow.linelo + 1;
03045     numpixels  = tempdbow.pixhi  - crop_arg.dbow.pixlo  + 1;
03046 
03047     linestart  = crop_arg.dbow.linelo;
03048     lineend    = tempdbow.linehi;
03049     pixelstart = crop_arg.dbow.pixlo;
03050     pixelend   = tempdbow.pixhi;                        // only for resultfile
03051     }
03052 
03053 // ______ Note complex<short> not in ANSI c ______
03054   matrix <int16>        LINE(1,2*numpixels);            // size of short
03055 
03056 // ====== Process requested lines ======
03057   ofstream datoutfile;
03058   openfstream(datoutfile,crop_arg.fileout1,generalinput.overwrit);
03059   bk_assert(datoutfile,crop_arg.fileout1,__FILE__,__LINE__);
03060 
03061   // ______ info on data, to avoid X86 problems ______
03062   // ______ according to CEOS specs, byte 13-16 is first complex pixel, etc. ______
03063   datfile.seekg(lenrec1+12,ios::beg);
03064   matrix <int16> TMPSHORT(1,2);
03065   datfile >> TMPSHORT;          // read in first complex pixel for test
03066   real8 tmpmag = sqrt(
03067     real8(int16(ntohs(TMPSHORT(0,0)))*int16(ntohs(TMPSHORT(0,0)))) + 
03068     real8(int16(ntohs(TMPSHORT(0,1)))*int16(ntohs(TMPSHORT(0,1)))));
03069   DEBUG << "First complex element in datafile: ("
03070        << int16(ntohs(TMPSHORT(0,0))) << ","
03071        << int16(ntohs(TMPSHORT(0,1)))
03072        << "); mag = " << tmpmag;
03073   DEBUG.print();
03074   if (tmpmag > 10000.)
03075     {
03076     WARNING.print(DEBUG.get_str());
03077     WARNING.print("this is a byteorder problem on X86? (use ntohs)");
03078     }
03079   DEBUG << "TEST: (realpart): " << TMPSHORT(0,0)
03080        << ", (imagpart): " << TMPSHORT(0,1);
03081   DEBUG.print();
03082   DEBUG << "TEST: htons(realpart): " << htons(TMPSHORT(0,0))
03083        << ", htons(imagpart): " << htons(TMPSHORT(0,1));
03084   DEBUG.print();
03085   DEBUG << "TEST: ntohs(realpart): " << ntohs(TMPSHORT(0,0))
03086        << ", ntohs(imagpart): " << ntohs(TMPSHORT(0,1));
03087   DEBUG.print();
03088   DEBUG << "TEST: short int(ntohs(realpart)): " << int16(ntohs(TMPSHORT(0,0)))
03089        << ", (imagpart): " << int16(ntohs(TMPSHORT(0,1)));
03090   DEBUG.print();
03091 
03092 
03093   // ====== perline is faster than perbuffer, less memory etc. BK1998 ======
03094   datfile.seekg(lenrec1+(linestart-1)*lendatarec2+8,ios::beg);
03095   datfile.read((char*)&lenrec2,sizeb4);         // length of first record
03096   lenrec2 = ntohl(lenrec2);     // bk 6 jul 2000, byteorder x86 machines.
03097 
03098   if (lenrec2 != lendatarec2)
03099     {
03100     ERROR << "code 904: Length of datarecords seems to be inconsistent in file: "  
03101          << crop_arg.filein1 << ": " 
03102          << lenrec2 << " != " << lendatarec2;
03103     WARNING.print(ERROR.get_str());
03104     ERROR.reset();
03105     }
03106 
03107   const int32 TEN        = 10;
03108   const int32 TENPERCENT = int32((.5*TEN+numlines)/TEN);        // number of lines
03109   int32 percentage       = 0;                                   // initialization
03110   const int32 tmpstart   = lenrec1+12-lendatarec2+(pixelstart-1)*4;     // sizeof=4
03111   for (register int32 linecnt=linestart; linecnt<=lineend; linecnt++)
03112     {
03113     if (!((linecnt-linestart)%TENPERCENT))
03114       {
03115       PROGRESS << "WRITESLC: " << setw(3) << percentage << "%";
03116       PROGRESS.print();
03117       percentage += TEN;
03118       }
03119     datfile.seekg(tmpstart+linecnt*lendatarec2,ios::beg);
03120     datfile    >> LINE;
03121     // ______ BK 13 July 2000: swapbytes for X86 (intel) linux cpus ______
03122     #ifdef __X86PROCESSOR__
03123     for (int ii=0; ii<LINE.pixels(); ++ii)
03124       LINE(0,ii) = int16(ntohs(LINE(0,ii)));    // changed from htons 171100 BK
03125     #endif
03126     datoutfile << LINE;
03127     }
03128   datfile.close();                                      // close files
03129   datoutfile.close();
03130 
03131 
03132 
03133 // ====== Write results to scratchfile ======
03134   ofstream scratchresfile("scratchres2raw", ios::out | ios::trunc);
03135   bk_assert(scratchresfile,"writeslc: scratchres2raw",__FILE__,__LINE__);
03136   scratchresfile
03137     << "\n\n*******************************************************************\n";
03138     //<< "\n*_Start_crop:\t\t\t"
03139     //<<  crop_arg.idcrop
03140   if (crop_arg.fileid == MASTERID)
03141     scratchresfile <<  "*_Start_" << processcontrol[pr_m_crop];
03142   if (crop_arg.fileid == SLAVEID)
03143     scratchresfile <<  "*_Start_" << processcontrol[pr_s_crop];
03144   scratchresfile
03145     << "\t\t\t" <<  crop_arg.idcrop
03146     << "\n*******************************************************************"
03147     << "\nData_output_file: \t\t\t\t" 
03148     <<  crop_arg.fileout1
03149     << "\nData_output_format: \t\t\t\t" 
03150     << "complex_short"
03151 
03152 // ______ updateslcimage greps these ______
03153     << "\nFirst_line (w.r.t. original_image): \t\t"
03154     <<  linestart
03155     << "\nLast_line (w.r.t. original_image): \t\t" 
03156     <<  lineend
03157     << "\nFirst_pixel (w.r.t. original_image): \t\t" 
03158     <<  pixelstart
03159     << "\nLast_pixel (w.r.t. original_image): \t\t" 
03160     <<  pixelend
03161     << "\n*******************************************************************";
03162   if (crop_arg.fileid == MASTERID)
03163     scratchresfile <<  "\n* End_" << processcontrol[pr_m_crop] << "_NORMAL";
03164   if (crop_arg.fileid == SLAVEID)
03165     scratchresfile <<  "\n* End_" << processcontrol[pr_s_crop] << "_NORMAL";
03166   scratchresfile
03167     << "\n*******************************************************************"
03168     <<  endl;
03169   scratchresfile.close();
03170 
03171 // ______ Tidy up do checks here ______
03172   if (numchannels != 1)                         // ??
03173     {
03174     WARNING << "code 904: Number of channels in file: "
03175          << crop_arg.filein1 << " = " 
03176          << numchannels << " != 1 ";
03177     WARNING.print();
03178     WARNING.print("this means SLC FORMAT IS DIFFERENT THEN EXPECTED.");
03179     }
03180   if (bottomborder != topborder != leftborder != rightborder != 0)
03181     {
03182     WARNING << "code 904: Not implemented: offset border: left,right,bottom,top: " 
03183          << leftborder << "," << rightborder << "," << bottomborder << "," 
03184          << topborder << " in file: " << crop_arg.filein1;
03185     WARNING.print();
03186     WARNING.print("this means SLC FORMAT IS DIFFERENT THEN EXPECTED.");
03187     }
03188   PROGRESS.print("WRITESLC: 100%");
03189   } // END writeslc
03190 
03191 
03192 
03193 /****************************************************************
03194  *    envisatdump_data                                          *
03195  *                                                              *
03196  * Via a system call to the c-program envisat_dump_data, the    *
03197  * SLC data is wrtten to file.  The resfile is here created.    *
03198  * envisatdumpdata writes SLC data out in host order.           *
03199  * it is important that crop_arg.dbow is correctly filled.      *
03200  *    Bert Kampes, 16-JUN-2003                                  *
03201  ****************************************************************/
03202 void envisat_dump_data(
03203         const input_crop &crop_arg)
03204   {
03205   // ______ Write some info ______ 
03206   TRACE_FUNCTION("envisat_dump_data (BK 16-Jun-2003)")
03207   // ______ Build command ______
03208   // ______ make sure l0 etc. are correctly defined ______
03209   // ____ assume these are filled correctly ___
03210   INFO.reset();
03211   if (crop_arg.dbow.linehi!=0 && crop_arg.dbow.linelo!=0 && 
03212       crop_arg.dbow.pixhi!=0 && crop_arg.dbow.pixlo!=0)
03213     INFO << "envisat_dump_data " << crop_arg.filein1 
03214          << " " << crop_arg.fileout1
03215          << " " << crop_arg.dbow.linelo 
03216          << " " << crop_arg.dbow.linehi
03217          << " " << crop_arg.dbow.pixlo
03218          << " " << crop_arg.dbow.pixhi << ends;
03219   else
03220     INFO << "envisat_dump_data " << crop_arg.filein1 
03221          << " " << crop_arg.fileout1 << ends;
03222   //INFO << endl << ends;
03223   char cmd[512];// command string
03224   strcpy(cmd, INFO.get_str());
03225   INFO.print("With following command the envisat data was cropped.");
03226   INFO.print(cmd);
03227   PROGRESS.print("system call may take some time...");
03228   system(cmd);// this does the work
03229   INFO.reset();
03230   INFO.print();
03231 
03232   // ====== Write results to scratchfile ======
03233   ofstream scratchresfile("scratchres2raw", ios::out | ios::trunc);
03234   bk_assert(scratchresfile,"writeslc: scratchres2raw",__FILE__,__LINE__);
03235   scratchresfile
03236     << "\n\n*******************************************************************\n";
03237   if (crop_arg.fileid == MASTERID)
03238     scratchresfile <<  "*_Start_" << processcontrol[pr_m_crop];
03239   if (crop_arg.fileid == SLAVEID)
03240     scratchresfile <<  "*_Start_" << processcontrol[pr_s_crop];
03241   scratchresfile
03242     << "\t\t\t" <<  crop_arg.idcrop
03243     << "\n*******************************************************************"
03244     << "\nData_output_file: \t\t\t\t" 
03245     <<  crop_arg.fileout1
03246     << "\nData_output_format: \t\t\t\t" 
03247     << "complex_short"
03248     // ______ updateslcimage greps these ______
03249     << "\nFirst_line (w.r.t. original_image): \t\t"
03250     <<  crop_arg.dbow.linelo
03251     << "\nLast_line (w.r.t. original_image): \t\t" 
03252     <<  crop_arg.dbow.linehi
03253     << "\nFirst_pixel (w.r.t. original_image): \t\t" 
03254     <<  crop_arg.dbow.pixlo
03255     << "\nLast_pixel (w.r.t. original_image): \t\t" 
03256     <<  crop_arg.dbow.pixhi
03257     << "\n*******************************************************************";
03258   if (crop_arg.fileid == MASTERID)
03259     scratchresfile <<  "\n* End_" << processcontrol[pr_m_crop] << "_NORMAL";
03260   if (crop_arg.fileid == SLAVEID)
03261     scratchresfile <<  "\n* End_" << processcontrol[pr_s_crop] << "_NORMAL";
03262   scratchresfile
03263     << "\n*******************************************************************"
03264     <<  endl;
03265   scratchresfile.close();
03266 
03267   } // END envisat_dump_data
03268 
03269 
03270 
03271 //____RaffaeleNutricato START MODIFICATION SECTION 2
03272 /****************************************************************
03273  *    OversampleSLC                                             *
03274  *                                                              *
03275  * Oversamples the SLC by an integer factor.                    *
03276  * For now only range oversampling is performed.                *
03277  *    Raffaele Nutricato, 12-Jan-2004                           *
03278  ****************************************************************/
03279 void  OversampleSLC(
03280         const input_gen        &generalinput,
03281         const slcimage         &imageinfo,
03282         const input_oversample &oversampleinput,
03283         const int16            fileid)
03284   {
03285   TRACE_FUNCTION("OversampleSLC (Raffaele Nutricato 12-Jan-2004)")
03286 
03287   char infile[EIGHTY];  // Input file which is master/slave.raw renamed as .old
03288   char outfile[EIGHTY]; // Output file which is the oversampled version.
03289 
03290   const int32 OsrRange        = oversampleinput.OsrRange;   // Range oversampling ratio.
03291   const int32 OsrAzimuth      = oversampleinput.OsrAzimuth; // Azimuth oversampling ratio.
03292   const int32 FilterSize      = oversampleinput.FilterSize; // Length of the kernel for the oversampling. 
03293 
03294   strcpy(infile,imageinfo.file);
03295   strcpy(outfile,oversampleinput.fileoutovs);
03296 
03297   // ______Open input file_____
03298   ifstream ifile;
03299   openfstream(ifile,infile);
03300   bk_assert(ifile,infile,__FILE__,__LINE__);
03301 
03302   // ______Open output file_____
03303   ofstream ofile;
03304   openfstream(ofile,outfile,generalinput.overwrit);
03305   bk_assert(ofile,outfile,__FILE__,__LINE__);
03306 
03307   // Compute the size of original cropped image 
03308   int32 numlines, numpixels;
03309   numlines   = imageinfo.currentwindow.linehi - imageinfo.currentwindow.linelo + 1;
03310   numpixels  = imageinfo.currentwindow.pixhi  - imageinfo.currentwindow.pixlo  + 1;
03311 
03312   // define the accuracy of the digital signal processing!
03313   #define RN_DSP_ACCURACY    double
03314   #define RN_DSP_CPXACCURACY complr8
03315 
03316   matrix <RN_DSP_CPXACCURACY>   LINE_IN(1,OsrRange*(numpixels-1) +1); // RN zero filled copy of the downloaded data. 
03317   matrix <RN_DSP_CPXACCURACY>   LINE_OUT(1,OsrRange*numpixels);   // RN oversampled line.
03318 
03319 
03320   // ______Interpolation kernel section______
03321   int32 interp_size = FilterSize  * OsrRange - 1; 
03322   matrix <RN_DSP_CPXACCURACY>   INTERP_KERNEL(1,interp_size);   
03323 
03324   // Generate the interpolator impulse response 
03325   RN_DSP_ACCURACY invosr = 1.0 / RN_DSP_ACCURACY(OsrRange); 
03326   RN_DSP_ACCURACY interpsamplepos = invosr - RN_DSP_ACCURACY(FilterSize) / 2.0; 
03327   for (int32 i = 0; i < interp_size; i++) 
03328     { 
03329     INTERP_KERNEL(0,i) = RN_DSP_CPXACCURACY(sinc(interpsamplepos),0); 
03330     interpsamplepos += invosr; 
03331     } 
03332 
03333 
03334   // ______Loop on the lines to oversample______
03335   const int32 TEN        = 10;
03336   const int32 TENPERCENT = int32(floor((.5*TEN+numlines)/TEN));   // number of lines
03337   int32 percentage       = 0;                                     // initialization
03338   for (register int32 linecnt=0; linecnt<numlines; linecnt++)
03339     {
03340     if (!(linecnt%TENPERCENT))
03341       {
03342       PROGRESS << "OVERSAMPLESLC: " << setw(3) << percentage << "%";
03343       PROGRESS.print();
03344       percentage += TEN;
03345       }
03346       switch (imageinfo.formatflag)
03347         {
03348         case FORMATCR4:
03349             {
03350           matrix<real4> bufferrreal4(1,1);
03351           matrix<real4> bufferrimag4(1,1);
03352           for (int32 ii=0; ii<numpixels; ++ii)
03353             {
03354             ifile >> bufferrreal4;
03355             ifile >> bufferrimag4;
03356             // ______Generate a zero filled copy of LINE______
03357             LINE_IN(0,OsrRange*ii) = RN_DSP_CPXACCURACY(bufferrreal4(0,0),bufferrimag4(0,0)); // RN LINE_IN must be cleaned!!!
03358             }
03359           break;
03360           } 
03361         // ______ Convert first to ci2 before writing to file ______
03362         case FORMATCI2:
03363           {
03364           matrix<int16> bufferrealint16(1,1);
03365           matrix<int16> bufferimagint16(1,1);
03366           for (int32 ii=0; ii<numpixels; ++ii)
03367             {
03368             ifile >> bufferrealint16;
03369             ifile >> bufferimagint16;
03370             // ______Generate a zero filled copy of LINE______
03371             LINE_IN(0,OsrRange*ii) = RN_DSP_CPXACCURACY(bufferrealint16(0,0),bufferimagint16(0,0)); // RN LINE_IN must be cleaned!!!
03372             }
03373           break;
03374           }
03375           default:
03376             PRINT_ERROR("Unknown input format for the cropped image.");
03377             throw(unhandled_case_error);
03378         } // end switch
03379 
03380      
03381       // ______Spatial convolution between LINE_IN and INTERP_KERNEL______
03382       int jmin, jmax, RN_k, minpos, maxpos;
03383       RN_k = 0;
03384       minpos = (interp_size-1)/2;
03385       maxpos = (interp_size-1)/2 + (LINE_IN.pixels() - 1) + OsrRange - 1;
03386 
03387       for (int ii=minpos; ii<=maxpos; ii++)
03388         {
03389         LINE_OUT(0,RN_k) = 0; 
03390         jmin = max(int32(0), int32(ii-interp_size+1));
03391         jmax = min(int32(ii),int32(LINE_IN.pixels()-1));
03392         for (int j=jmin;j <= jmax;j++)
03393           LINE_OUT(0,RN_k) += LINE_IN(0,j) * INTERP_KERNEL(0,ii-j);
03394         RN_k++;
03395         }
03396 
03397 
03398       // ______Write LINE_OUT in the output file______
03399       switch (oversampleinput.oformatflag)
03400         {
03401         // ______ Convert first to cr4 before writing to file ______
03402         case FORMATCR4:
03403           {
03404           complr4 buffercr4;
03405           for (int ii=0; ii < LINE_OUT.pixels();ii++)
03406             {  
03407             buffercr4 = complr4(LINE_OUT(0,ii));
03408             ofile.write((char*)&buffercr4,sizeof(complr4));
03409             }
03410           break;
03411           } 
03412         // ______ Convert first to ci2 before writing to file ______
03413         case FORMATCI2:
03414           {
03415           compli16 bufferci16;
03416           for (int ii=0; ii < LINE_OUT.pixels();ii++)
03417             {  
03418             bufferci16 = cr4toci2(complr4(LINE_OUT(0,ii)));
03419             ofile.write((char*)&bufferci16,sizeof(compli16));
03420             }
03421           break;
03422           }
03423           default:
03424             PRINT_ERROR("Unknown output format for the oversampled image.");
03425             throw(unhandled_case_error);
03426         } // end switch
03427 
03428        LINE_IN.clean(); 
03429        } // end for
03430 
03431     #undef RN_DSP_ACCURACY 
03432     #undef RN_DSP_CPXACCURACY 
03433 
03434   // Close files
03435   ifile.close();
03436   ofile.close();
03437 
03438 
03439 // ====== Write results to scratchfile ======
03440   ofstream scratchresfile("scratchoversample", ios::out | ios::trunc);
03441   bk_assert(scratchresfile,"OversampleSLC: scratchoversample",__FILE__,__LINE__);
03442   scratchresfile
03443     << "\n\n*******************************************************************\n";
03444   if (fileid == MASTERID)
03445   {
03446     scratchresfile <<  "*_Start_" << processcontrol[pr_m_oversample];
03447     scratchresfile << "\t\t\t" <<  "master";
03448   }
03449   if (fileid == SLAVEID)
03450     {
03451     scratchresfile <<  "*_Start_" << processcontrol[pr_s_oversample];
03452     scratchresfile << "\t\t\t" <<  "slave";
03453     }
03454   scratchresfile
03455     << "\n*******************************************************************"
03456     << "\nData_output_file: \t\t\t\t" 
03457     <<  outfile
03458     << "\nData_output_format: \t\t\t\t";
03459     if (oversampleinput.oformatflag==FORMATCR4)
03460       scratchresfile << "complex_real4";
03461     if (oversampleinput.oformatflag==FORMATCI2)
03462       scratchresfile << "complex_short";
03463 // ______ updateslcimage greps these ______
03464   scratchresfile 
03465     << "\nFirst_line (w.r.t. original_image):  \t\t"
03466     <<  imageinfo.currentwindow.linelo
03467     << "\nLast_line (w.r.t. original_image):   \t\t" 
03468     <<  imageinfo.currentwindow.linehi
03469     << "\nFirst_pixel (w.r.t. original_image): \t\t" 
03470     <<  imageinfo.currentwindow.pixlo
03471     << "\nLast_pixel (w.r.t. original_image):  \t\t" 
03472     <<  imageinfo.currentwindow.pixhi;
03473   scratchresfile 
03474     << "\nMultilookfactor_azimuth_direction:   \t\t"
03475     << 1.0/OsrAzimuth
03476     << "\nMultilookfactor_range_direction:     \t\t"
03477     << 1.0/OsrRange;
03478   scratchresfile 
03479     << "\nNumber of lines (multilooked):       \t\t"
03480     << OsrAzimuth*(imageinfo.currentwindow.linehi-imageinfo.currentwindow.linelo+1)
03481     << "\nNumber of pixels (multilooked):      \t\t"
03482     << OsrRange*(imageinfo.currentwindow.pixhi-imageinfo.currentwindow.pixlo+1);
03483   scratchresfile 
03484     << "\nFirst_line_ (w.r.t. ovs_image):       \t\t"
03485     <<  (imageinfo.currentwindow.linelo-1)*OsrAzimuth+1
03486     << "\nLast_line_ (w.r.t. ovs_image):        \t\t" 
03487     <<  imageinfo.currentwindow.linehi*OsrAzimuth
03488     << "\nFirst_pixel_ (w.r.t. ovs_image):      \t\t" 
03489     <<  (imageinfo.currentwindow.pixlo-1)*OsrRange+1
03490     << "\nLast_pixel_ (w.r.t. ovs_image):       \t\t" 
03491     <<  imageinfo.currentwindow.pixhi*OsrRange;
03492   scratchresfile 
03493     << "\n*******************************************************************";
03494   if (fileid == MASTERID)
03495     scratchresfile <<  "\n* End_" << processcontrol[pr_m_oversample] << "_NORMAL";
03496   if (fileid == SLAVEID)
03497     scratchresfile <<  "\n* End_" << processcontrol[pr_s_oversample] << "_NORMAL";
03498   scratchresfile
03499     << "\n*******************************************************************"
03500     <<  endl;
03501   scratchresfile.close();
03502 
03503   PROGRESS.print("OVERSAMPLESLC: 100%");
03504   } // END OversampleSLC
03505 //____RaffaeleNutricato END MODIFICATION SECTION 2
03506 
03507 
03508 
03509 
03510 /****************************************************************
03511  *    radarsat_dump_data                                        *
03512  *                                                              *
03513  * Inputfile in ceos slc format is converted to                 *
03514  *  raw format outputfile.                                      *
03515  * image is flipped if time direction is not INCREASE,INCREASE  *
03516  * crop is thus done either geometric correct, or if specified  *
03517  * DBOW a bit strange ... ?
03518  #%// Bert Kampes, 04-Aug-2004
03519  ****************************************************************/
03520 void radarsat_dump_data(
03521         const input_gen &generalinput,
03522         const input_crop &crop_arg)
03523   {
03524   const int16           sizeb4 = 4,             // some constants for reading
03525                         sizeb1 = 1,             //   binary fields.
03526                         sizei4 = 4,             //   binary fields.
03527                         sizei6 = 6,
03528                         sizei8 = 8;
03529   uint                  lenrec1;                // length of general record1
03530   uint                  lenrec2;                // (nominal) length of data records
03531   char                  c4[5],                  // correctly 5 for \0
03532                         c6[7],                  // correctly 7 for \0
03533                         c8[9];                  // correctly 9 for \0
03534   // --- Check for RSAT #%// Bert Kampes, 02-Aug-2004 ---
03535   uint rec_seq;// type B4
03536   unsigned char rec_sub1, rec_type, rec_sub2, rec_sub3;// type B1
03537 
03538   // ______ Write some info ______ 
03539   TRACE_FUNCTION("radarsat_dump_data (Bert Kampes 04-Aug-2004)")
03540   PROGRESS.print("Start cropping slc data for RADARSAT.");
03541   #ifdef __X86PROCESSOR__
03542   INFO.print("Swapping Big Endian (CEOS input) to Little Endian (your platform).");
03543   #else
03544   INFO.print("NO byte swapping performed, you must be on Big Endian platform.");
03545   #endif
03546 
03547   // ______ Open files ______ 
03548   ifstream datfile;
03549   openfstream(datfile,crop_arg.filein1);
03550   bk_assert(datfile,crop_arg.filein1,__FILE__,__LINE__);
03551 
03552   // ====== Get data such as recordlength ======
03553   // --- RECORD 1 ---
03554   DEBUG.print("record 1 of data file (ERS and RSAT).");
03555   datfile.seekg(0,ios::beg);//
03556   datfile.read((char*)&rec_seq,sizeb4);//  record number
03557   rec_seq = ntohl(rec_seq);     // bk 6 jul 2000, byteorder x86 machines.
03558   datfile.read((char*)&rec_sub1,sizeb1);// first record sub type code
03559   datfile.read((char*)&rec_type,sizeb1);// record type code
03560   datfile.read((char*)&rec_sub2,sizeb1);// second record sub type code
03561   datfile.read((char*)&rec_sub3,sizeb1);// third record sub type code
03562   DEBUG.print("RSAT: Expecting record 1 with code {63,192,18,18}");
03563   DEBUG << "rec_seq: " << rec_seq 
03564         << "; rec_sub1: " << int(rec_sub1)
03565         << "; rec_type: " << int(rec_type)
03566         << "; rec_sub2: " << int(rec_sub2)
03567         << "; rec_sub3: " << int(rec_sub3);
03568   DEBUG.print();
03569   if (int(rec_sub1)==63 && int(rec_type)==192 && int(rec_sub2)==18 && int(rec_sub3)==18)
03570     DEBUG.print("This is the expected record with code {63,192,18,18}");
03571   else
03572     WARNING.print("This is NOT the expected record with code {63,192,18,18}");
03573   datfile.seekg(8,ios::beg);//
03574   datfile.read((char*)&lenrec1,sizeb4);// length of record
03575   lenrec1 = ntohl(lenrec1);     // bk 6 jul 2000, byteorder x86 machines.
03576   DEBUG.print("RSAT: Expecting record 1 with length 16252");
03577   DEBUG << "radarsat_dump_data::record 1: start at: " << 0
03578         << "; length: " << lenrec1;
03579   DEBUG.print();
03580 
03581   // --- Get some info in RECORD 1 ---
03582   datfile.seekg(180,ios::beg);
03583   datfile.read((char*)&c6,sizei6);              // number of SAR DATA records (lines)
03584     c6[6]='\0';
03585     const uint numdatarec = atoi(c6);
03586   DEBUG << "numdatarec: " << numdatarec;
03587   DEBUG.print();
03588   //datfile.seekg(186,ios::beg);
03589   datfile.read((char*)&c6,sizei6);              // SAR DATA record length
03590     c6[6]='\0';
03591     const uint lendatarec2 = atoi(c6);
03592   DEBUG << "lendatarec2: " << lendatarec2;
03593   DEBUG.print();
03594   datfile.seekg(232,ios::beg);                  // SAR Related data
03595   datfile.read((char*)&c4,4);
03596     c4[4]='\0';
03597     const uint numchannels = atoi(c4);
03598   DEBUG << "numchannels: " << numchannels;
03599   DEBUG.print();
03600 
03601   datfile.read((char*)&c8,sizei8);
03602     c8[8]='\0';
03603     uint numlines = atoi(c8);
03604   DEBUG << "numlines: " << numlines;
03605   DEBUG.print();
03606 
03607   datfile.read((char*)&c4,sizei4);
03608     c4[4]='\0';
03609     const uint leftborder = atoi(c4);
03610   DEBUG << "leftborder: " << leftborder;
03611   DEBUG.print();
03612   datfile.read((char*)&c8,sizei8);              // number of pixels
03613     c8[8]='\0';
03614     uint numpixels = atoi(c8);
03615   DEBUG << "numpixels: " << numpixels;
03616   DEBUG.print();
03617   datfile.read((char*)&c4,sizei4);
03618     c4[4]='\0';
03619     const uint rightborder = atoi(c4);
03620   DEBUG << "rightborder: " << rightborder;
03621   DEBUG.print();
03622   datfile.read((char*)&c4,sizei4);
03623     c4[4]='\0';
03624     const uint topborder = atoi(c4);
03625   DEBUG << "topborder: " << topborder;
03626   DEBUG.print();
03627   datfile.read((char*)&c4,sizei4);
03628     c4[4]='\0';
03629     const uint bottomborder = atoi(c4);
03630   DEBUG << "bottomborder: " << bottomborder;
03631   DEBUG.print();
03632 
03633   datfile.seekg(280,ios::beg);                  // Record data
03634   datfile.read((char*)&c8,sizei8);
03635     c8[8]='\0';
03636     const uint numbytesdata = atoi(c8);
03637   DEBUG << "numbytesdata: " << numbytesdata;
03638   DEBUG.print();
03639 
03640 // ______ Check with previous section ______
03641   if (numlines != numdatarec) 
03642     {
03643     WARNING << "code 904: Number of lines seems not to be consistent in file: " 
03644          << crop_arg.filein1 << " : " << numlines << " != " << numdatarec;
03645     WARNING.print();
03646     WARNING.print("this means SLC FORMAT IS DIFFERENT THEN EXPECTED.");
03647     }
03648   if ((numbytesdata / 4) != numpixels)
03649     {
03650     WARNING << "code 904: Number of pixels seems to be inconsistent in file: "  
03651          << crop_arg.filein1 << ": " 
03652          << numpixels << " != " << (numbytesdata / 4);
03653     WARNING.print();
03654     WARNING.print("this means SLC FORMAT IS DIFFERENT THEN EXPECTED.");
03655     }
03656 
03657 
03658 // ====== Start copy input to output (raw) format with buffer======
03659 // ______ Check and process optional offset parameters______
03660 // ______ Lcnlow is corner line, lcnhi is other corner, pcnlow, pixel coord. low etc.
03661   uint linestart  = 1;                  // counters for loops, first=1;
03662   uint lineend    = numlines;
03663   uint pixelstart = 1;                  // first pix is 1
03664   uint pixelend   = numpixels;          // only for resultfile
03665 
03666   if (crop_arg.dbow.linehi!=0 && crop_arg.dbow.linelo!=0 && 
03667       crop_arg.dbow.pixhi!=0 && crop_arg.dbow.pixlo!=0)
03668     {
03669     WARNING.print("cropping data may be difficult, due to INC/DECREASE storage");
03670     window tempdbow(crop_arg.dbow.linelo, crop_arg.dbow.linehi,
03671                     crop_arg.dbow.pixlo,  crop_arg.dbow.pixhi);
03672     if (crop_arg.dbow.linehi>numlines)
03673       {
03674       WARNING << "Specified input DBOW linehi > numlines: "
03675            << crop_arg.dbow.linehi << " > " << numlines
03676            << ". I set linehi = " << numlines;
03677       WARNING.print();
03678       tempdbow.linehi=numlines;
03679       }
03680     if (crop_arg.dbow.pixhi>numpixels)
03681       {
03682       WARNING << "Specified input DBOW pixhi > numpixels: "
03683            << crop_arg.dbow.pixhi << " > " << numpixels
03684            << ". I set pixhi = " << numpixels;
03685       WARNING.print();
03686       tempdbow.pixhi=numpixels;
03687       }
03688     // ______ Only hi values are possibly adapted, low is a constant ______
03689     numlines   = tempdbow.linehi - crop_arg.dbow.linelo + 1;
03690     numpixels  = tempdbow.pixhi  - crop_arg.dbow.pixlo  + 1;
03691 
03692     linestart  = crop_arg.dbow.linelo;
03693     lineend    = tempdbow.linehi;
03694     pixelstart = crop_arg.dbow.pixlo;
03695     pixelend   = tempdbow.pixhi;                        // only for resultfile
03696     }
03697 
03698 
03699   // --- Find out if data is stored increasing in line/pix ---
03700   // --- RECORD 2 ---
03701   uint startrec2 = lenrec1;
03702   DEBUG.print("record 2 of data file (RSAT).");
03703   datfile.seekg(startrec2,ios::beg);//
03704   datfile.read((char*)&rec_seq,sizeb4);//  record number
03705   rec_seq = ntohl(rec_seq);     // bk 6 jul 2000, byteorder x86 machines.
03706   datfile.read((char*)&rec_sub1,sizeb1);// first record sub type code
03707   datfile.read((char*)&rec_type,sizeb1);// record type code
03708   datfile.read((char*)&rec_sub2,sizeb1);// second record sub type code
03709   datfile.read((char*)&rec_sub3,sizeb1);// third record sub type code
03710   DEBUG.print("RSAT: Expecting record 2 with code {50,11,18,20}");
03711   DEBUG << "rec_seq: " << rec_seq 
03712         << "; rec_sub1: " << int(rec_sub1)
03713         << "; rec_type: " << int(rec_type)
03714         << "; rec_sub2: " << int(rec_sub2)
03715         << "; rec_sub3: " << int(rec_sub3);
03716   DEBUG.print();
03717   if (int(rec_sub1)==50 && int(rec_type)==11 && int(rec_sub2)==18 && int(rec_sub3)==20)
03718     DEBUG.print("This is the expected record with code {50,11,18,20}");
03719   else
03720     WARNING.print("This is NOT the expected record with code {50,11,18,20}");
03721   datfile.seekg(startrec2+8,ios::beg);//
03722   datfile.read((char*)&lenrec2,sizeb4);// length of record
03723   lenrec2 = ntohl(lenrec2);     // bk 6 jul 2000, byteorder x86 machines.
03724   DEBUG.print("RSAT: Expecting record 2 with length variable");
03725   DEBUG << "radarsat_dump_data::record 2: start at: " << startrec2
03726         << "; length: " << lenrec2;
03727   DEBUG.print();
03728   uint startrec3 = lenrec1+lenrec2;
03729   uint startrecN = lenrec1+(numlines-1)*lenrec2;// start of last record
03730   // --- azimuth time to first line (depends on decrease/increase): ---
03731   uint zdmsecofday1 = 99999;// B4 
03732   uint zdmsecofday2 = 99999;// B4
03733   uint zdmsecofdayN = 99999;// B4
03734   datfile.seekg(startrec2+44,ios::beg);//
03735   datfile.read((char*)&zdmsecofday1,sizeb4);//  range to first pix
03736   zdmsecofday1 = ntohl(zdmsecofday1);   // bk 6 jul 2000, byteorder x86 machines.
03737   datfile.seekg(startrec3+44,ios::beg);//
03738   datfile.read((char*)&zdmsecofday2,sizeb4);//  range to first pix
03739   zdmsecofday2 = ntohl(zdmsecofday2);   // bk 6 jul 2000, byteorder x86 machines.
03740   datfile.seekg(startrecN+44,ios::beg);//
03741   datfile.read((char*)&zdmsecofdayN,sizeb4);//  range to first pix
03742   zdmsecofdayN = ntohl(zdmsecofdayN);   // bk 6 jul 2000, byteorder x86 machines.
03743   INFO << "zdmsecofday1: " << zdmsecofday1;
03744   INFO.print();
03745   DEBUG << "zdmsecofday2: " << zdmsecofday2;
03746   DEBUG.print();
03747   INFO << "zdmsecofdayN: " << zdmsecofdayN;
03748   INFO.print();
03749   bool increasing_line = true;// assume this
03750   // --- I assume linestart is smaller than end, so swap them if required ---
03751   if (zdmsecofday1 < zdmsecofdayN)// increase, use ZD time of first line
03752     {
03753     INFO.print("INCREASE line direction detected (OK).");
03754     }
03755   else // decreasing lines: flip up-down
03756     {
03757     WARNING.print("DECREASE line direction detected: I will flip up-down the RSAT data");
03758     increasing_line = false;
03759     }
03760 
03761   // --- range time to first pixel is distance -------------------------
03762   uint range1st = 99999;//
03763   uint rangelst = 99999;
03764   datfile.seekg(startrec2+64,ios::beg);//
03765   datfile.read((char*)&range1st,sizeb4);//  range to first pix
03766   range1st = ntohl(range1st);   // bk 6 jul 2000, byteorder x86 machines.
03767   datfile.seekg(startrec2+72,ios::beg);//
03768   datfile.read((char*)&rangelst,sizeb4);//  range to last pix
03769   rangelst = ntohl(rangelst);   // bk 6 jul 2000, byteorder x86 machines.
03770   INFO << "range1st: " << range1st;
03771   INFO.print();
03772   INFO << "rangelst: " << rangelst;
03773   INFO.print();
03774   bool increasing_pix  = true;// assume this
03775   if (range1st < rangelst)// increase
03776     {
03777     INFO.print("INCREASE pixel direction detected (OK).");
03778     }
03779   else // decrease: flip data left-right
03780     {
03781     WARNING.print("DECREASE pixel direction detected: I will flip left-right the RSAT data");
03782     increasing_pix = false;
03783     }
03784  
03785 
03786 
03787   // ====== Process requested lines ======
03788   ofstream datoutfile;
03789   openfstream(datoutfile,crop_arg.fileout1,generalinput.overwrit);
03790   bk_assert(datoutfile,crop_arg.fileout1,__FILE__,__LINE__);
03791 
03792   // ______ info on data, to avoid X86 problems ______
03793   // ______ according to RSAT CEOS specs, byte 192-195 is first complex pixel, etc. ______
03794   datfile.seekg(lenrec1+192,ios::beg);
03795   matrix <int16> TMPSHORT(1,2);
03796   datfile >> TMPSHORT;          // read in first complex pixel for test
03797   real8 tmpmag = sqrt(
03798     real8(int16(ntohs(TMPSHORT(0,0)))*int16(ntohs(TMPSHORT(0,0)))) + 
03799     real8(int16(ntohs(TMPSHORT(0,1)))*int16(ntohs(TMPSHORT(0,1)))));
03800   DEBUG << "First complex element in datafile: ("
03801        << int16(ntohs(TMPSHORT(0,0))) << ","
03802        << int16(ntohs(TMPSHORT(0,1)))
03803        << "); mag = " << tmpmag;
03804   DEBUG.print();
03805   if (tmpmag > 10000.)
03806     {
03807     WARNING.print(DEBUG.get_str());
03808     WARNING.print("this is a byteorder problem on X86? (use ntohs)");
03809     }
03810   DEBUG << "TEST: (realpart): " << TMPSHORT(0,0)
03811        << ", (imagpart): " << TMPSHORT(0,1);
03812   DEBUG.print();
03813   DEBUG << "TEST: htons(realpart): " << htons(TMPSHORT(0,0))
03814        << ", htons(imagpart): " << htons(TMPSHORT(0,1));
03815   DEBUG.print();
03816   DEBUG << "TEST: ntohs(realpart): " << ntohs(TMPSHORT(0,0))
03817        << ", ntohs(imagpart): " << ntohs(TMPSHORT(0,1));
03818   DEBUG.print();
03819   DEBUG << "TEST: short int(ntohs(realpart)): " << int16(ntohs(TMPSHORT(0,0)))
03820        << ", (imagpart): " << int16(ntohs(TMPSHORT(0,1)));
03821   DEBUG.print();
03822 
03823 
03824   // --- Simple way pix by pix reading so we can easily flip if req. ---
03825   datfile.seekg(lenrec1+(linestart-1)*lendatarec2+8,ios::beg);
03826   datfile.read((char*)&lenrec2,sizeb4);         // length of first record
03827   lenrec2 = ntohl(lenrec2);     // bk 6 jul 2000, byteorder x86 machines.
03828   if (lenrec2 != lendatarec2)
03829     {
03830     ERROR << "code 904: Length of datarecords seems to be inconsistent in file: "  
03831          << crop_arg.filein1 << ": " 
03832          << lenrec2 << " != " << lendatarec2;
03833     WARNING.print(ERROR.get_str());
03834     ERROR.reset();
03835     }
03836 
03837 
03838   // ______ Note complex<short> not in ANSI c ______
03839   int32 percentage       = 0;                           // initialization
03840   const int32 TENPERCENT = int32((5+numlines)/10);      // number of lines
03841   for (register int32 linecnt=linestart; linecnt<=lineend; linecnt++)
03842     {
03843     int32 line2read = (increasing_line==true) ? linecnt : lineend-(linecnt-linestart);
03844     for (register int32 pixcnt=pixelstart; pixcnt<=pixelend; pixcnt++)
03845       {
03846       int32 pix2read = (increasing_pix==true) ? pixcnt : pixelend-(pixcnt-pixelstart);
03847       // --- set pointer before complex pixel to read ---
03848       uint tmpstart = lenrec1+192+(line2read-1)*lendatarec2+(pix2read-1)*4;
03849       datfile.seekg(tmpstart,ios::beg);
03850       datfile    >> TMPSHORT;
03851       // ______ BK 13 July 2000: swapbytes for X86 (intel) linux cpus ______
03852       #ifdef __X86PROCESSOR__
03853       TMPSHORT(0,0) = int16(ntohs(TMPSHORT(0,0)));// byteswap
03854       TMPSHORT(0,1) = int16(ntohs(TMPSHORT(0,1)));// byteswap
03855       #endif
03856       datoutfile << TMPSHORT;
03857       }
03858     if (!((linecnt-linestart)%TENPERCENT))
03859       {
03860       PROGRESS << "radarsat_dump_data: " << setw(3) << percentage << "%";
03861       PROGRESS.print();
03862       percentage += 10;
03863       }
03864     }
03865   datfile.close();                                      // close files
03866   datoutfile.close();
03867 
03868 
03869 
03870 // ====== Write results to scratchfile ======
03871   ofstream scratchresfile("scratchres2raw", ios::out | ios::trunc);
03872   bk_assert(scratchresfile,"writeslc: scratchres2raw",__FILE__,__LINE__);
03873   scratchresfile
03874     << "\n\n*******************************************************************\n";
03875   if (crop_arg.fileid == MASTERID)
03876     scratchresfile <<  "*_Start_" << processcontrol[pr_m_crop];
03877   if (crop_arg.fileid == SLAVEID)
03878     scratchresfile <<  "*_Start_" << processcontrol[pr_s_crop];
03879   scratchresfile
03880     << "\t\t\t" <<  crop_arg.idcrop
03881     << "\n*******************************************************************"
03882     << "\nData_output_file: \t\t\t\t" 
03883     <<  crop_arg.fileout1
03884     << "\nData_output_format: \t\t\t\t" 
03885     << "complex_short"
03886 
03887     // ______ updateslcimage greps these ______
03888     << "\nFirst_line (w.r.t. original_image): \t\t"
03889     <<  linestart
03890     << "\nLast_line (w.r.t. original_image): \t\t" 
03891     <<  lineend
03892     << "\nFirst_pixel (w.r.t. original_image): \t\t" 
03893     <<  pixelstart
03894     << "\nLast_pixel (w.r.t. original_image): \t\t" 
03895     <<  pixelend
03896     << "\n*******************************************************************";
03897   if (crop_arg.fileid == MASTERID)
03898     scratchresfile <<  "\n* End_" << processcontrol[pr_m_crop] << "_NORMAL";
03899   if (crop_arg.fileid == SLAVEID)
03900     scratchresfile <<  "\n* End_" << processcontrol[pr_s_crop] << "_NORMAL";
03901   scratchresfile
03902     << "\n*******************************************************************"
03903     <<  endl;
03904   scratchresfile.close();
03905 
03906 // ______ Tidy up do checks here ______
03907   if (numchannels != 1)                         // ??
03908     {
03909     WARNING << "code 904: Number of channels in file: "
03910          << crop_arg.filein1 << " = " 
03911          << numchannels << " != 1 ";
03912     WARNING.print();
03913     WARNING.print("this means SLC FORMAT IS DIFFERENT THEN EXPECTED.");
03914     }
03915   if (bottomborder != topborder != leftborder != rightborder != 0)
03916     {
03917     WARNING << "code 904: Not implemented: offset border: left,right,bottom,top: " 
03918          << leftborder << "," << rightborder << "," << bottomborder << "," 
03919          << topborder << " in file: " << crop_arg.filein1;
03920     WARNING.print();
03921     WARNING.print("this means SLC FORMAT IS DIFFERENT THEN EXPECTED.");
03922     }
03923   PROGRESS.print("radarsat_dump_data: 100%");
03924   } // END radarsat_dump_data
03925 
03926 

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