00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 using namespace std;
00018 #include <iostream>
00019 #include <fstream>
00020 #include <cstdlib>
00021 #include <cmath>
00022 #include <complex>
00023 #include <cstring>
00024
00025 void usage(char *programname)
00026 {
00027 cerr << "\nProgram: " << programname
00028 << " subtracts or adds phase of two complex float files\n"
00029 << "\n USAGE:\n\t" << programname
00030 << " infile1 infile2 [outfile [add==0]]\n\n"
00031 << " infile[12] contain complex values a+ib\n"
00032 << " outfile contains (a1+ib1)*conj(a2+ib2)\n\n"
00033 << " If add=1 then phase is added (not conj).\n\n"
00034 << " EXAMPLE:\n\t" << programname
00035 << " cint.raw cint2.raw subtract.raw"
00036 << "\ndefault output file == infile1.min.infile2\n\n"
00037 << "exit levels: 0:ok; -1: wrong input; 1:ifile; 2:ofile.\n\n\n";
00038 exit(-1);
00039 }
00040
00041
00042 int main(int argc, char* argv[])
00043 {
00044 char ident[] = "@(#)Doris software, kampes@geo.tudelft.nl";
00045 const int ONE27 = 127;
00046 char ifile1[ONE27];
00047 char ifile2[ONE27];
00048 char ofile[ONE27] = " ";
00049 bool add = false;
00050 const int sizeofelement = sizeof(complex<float>);
00051
00052
00053 switch (argc)
00054 {
00055 case 5:
00056 add=true;
00057
00058 case 4:
00059 strcpy(ofile,argv[3]);
00060
00061 case 3:
00062 strcpy(ifile2,argv[2]);
00063
00064 case 2:
00065 strcpy(ifile1,argv[1]);
00066 break;
00067 default:
00068 usage(argv[0]);
00069 }
00070
00071
00072 if (!strcmp(ofile," "))
00073 {
00074 strcpy(ofile,ifile1);
00075 strcat(ofile,".min.");
00076 strcpy(ofile,ifile2);
00077 }
00078
00079
00080 cerr << "Program parameters:\n\t" << argv[0] << " "
00081 << ifile1 << " " << ifile2 << " " << ofile << " " << add << endl;
00082 if (!strcmp(ofile,ifile1) || !strcmp(ofile,ifile2))
00083 {
00084 cerr << "input file name same as other one: "
00085 << ifile1 << " =? " << ofile << " =? " << ifile2 << endl;
00086 usage(argv[0]);
00087 }
00088
00089
00090
00091
00092 ifstream infile1(ifile1, ios::in | ios::binary);
00093 if (!infile1) cerr << "Problem opening file: " << ifile1 << endl, exit(1);
00094 infile1.seekg(0,ios::end);
00095 const int totalbytes1 = infile1.tellg();
00096 infile1.seekg(0,ios::beg);
00097
00098 ifstream infile2(ifile2, ios::in | ios::binary);
00099 if (!infile2) cerr << "Problem opening file: " << ifile2 << endl, exit(1);
00100 infile2.seekg(0,ios::end);
00101 const int totalbytes2 = infile2.tellg();
00102 infile2.seekg(0,ios::beg);
00103 if (totalbytes1!=totalbytes2)
00104 {
00105 cerr << "size of file1 != size of file2: "
00106 << totalbytes1 << "!=" << totalbytes2 << endl;
00107 exit(2);
00108 }
00109
00110 const int numberofpixels = totalbytes1/sizeofelement;
00111 ofstream outfile(ofile, ios::out | ios::binary | ios::trunc);
00112 if (!outfile) cerr << "Problem opening file: " << ofile << endl, exit(2);
00113 int tenpercent = int(floor(numberofpixels/10.));
00114 int percent = 0;
00115
00116 register complex<float> value1;
00117 register complex<float> value2;
00118
00119 if (add)
00120 {
00121 for (register int i=0; i<numberofpixels; ++i)
00122 {
00123 infile1.read((char*)&value1,sizeofelement);
00124 infile2.read((char*)&value2,sizeofelement);
00125 value1 *= value2;
00126 outfile.write((char*)&value1,sizeofelement);
00127 if (!(i%tenpercent))
00128 {
00129 cerr << "\rprocessed: " << percent << "%";
00130 percent += 10;
00131 }
00132 }
00133 }
00134 else
00135 {
00136 for (register int i=0; i<numberofpixels; ++i)
00137 {
00138 infile1.read((char*)&value1,sizeofelement);
00139 infile2.read((char*)&value2,sizeofelement);
00140 value1 *= conj(value2);
00141 outfile.write((char*)&value1,sizeofelement);
00142 if (!(i%tenpercent))
00143 {
00144 cerr << "\rprocessed: " << percent << "%";
00145 percent += 10;
00146 }
00147 }
00148 }
00149
00150
00151
00152 infile1.close();
00153 infile2.close();
00154 outfile.close();
00155 cout << "\n\nThank you for using " << argv[0] << "!\n";
00156 return 0;
00157 }
00158
00159