USGS

Isis 3.0 Application Source Code Reference

Home

campt.cpp

Go to the documentation of this file.
00001 #include "Isis.h"
00002 
00003 #include <string>
00004 #include <iomanip> 
00005 
00006 #include "Brick.h"
00007 #include "Camera.h"
00008 #include "CameraPointInfo.h"
00009 #include "iException.h"
00010 #include "iTime.h"
00011 #include "Progress.h"
00012 #include "SpecialPixel.h"
00013 
00014 using namespace std; 
00015 using namespace Isis;
00016 
00017 void IsisMain() {
00018   UserInterface &ui = Application::GetUserInterface();
00019 
00020   // Set up CameraPointInfo and set file
00021   CameraPointInfo campt;
00022   campt.SetCube(ui.GetFilename("FROM"));
00023 
00024   Progress prog;
00025   prog.SetMaximumSteps(1);
00026 
00027   // See if the user will allow outside locations
00028   campt.AllowOutside(ui.GetBoolean("ALLOWOUTSIDE"));
00029 
00030   // Depending on what type is selected, set values accordingly
00031   PvlGroup *point = NULL;
00032   if (ui.GetString("TYPE") == "IMAGE") {
00033     double sample = 0.0;
00034     double line = 0.0;
00035     if (ui.WasEntered("SAMPLE") && ui.WasEntered("LINE")) {
00036       sample = ui.GetDouble("SAMPLE");
00037       line = ui.GetDouble("LINE");
00038       point = campt.SetImage(sample, line);
00039     }
00040     else {
00041       if (ui.WasEntered("SAMPLE")) {
00042         sample = ui.GetDouble("SAMPLE");
00043         point = campt.SetSample(sample);
00044       }
00045       else if (ui.WasEntered("LINE")) {
00046         line = ui.GetDouble("LINE");
00047         point = campt.SetLine(line);
00048       }
00049       else {
00050         point = campt.SetCenter();
00051       }
00052     }    
00053   }
00054   else {
00055     double lat = ui.GetDouble("LATITUDE");
00056     double lon = ui.GetDouble("LONGITUDE");
00057     point = campt.SetGround(lat,lon);
00058   } 
00059  
00060   prog.CheckStatus();
00061 
00062   // Log it
00063   Application::Log((*point));
00064 
00065   if (ui.WasEntered("TO")) {
00066     // Get user params from ui
00067     string outFile = Filename(ui.GetFilename("TO")).Expanded();
00068     bool exists = Filename(outFile).Exists();
00069     bool append = ui.GetBoolean("APPEND");
00070 
00071     // Write the pvl group out to the file
00072     if (ui.GetString("FORMAT") == "PVL") {
00073       Pvl temp;
00074       temp.SetTerminator("");
00075       temp.AddGroup((*point));
00076       if (append) {
00077         temp.Append(outFile);
00078       }
00079       else {
00080         temp.Write(outFile);
00081       }
00082     } 
00083   
00084     // Create a flatfile from PVL data
00085     // The flatfile is comma delimited and can be imported into Excel
00086     else {
00087       ofstream os;
00088       bool writeHeader = false;
00089       if (append) {
00090         os.open(outFile.c_str(),ios::app);
00091         if (!exists) {
00092           writeHeader = true;
00093         }
00094       }
00095       else {
00096         os.open(outFile.c_str(),ios::out);
00097         writeHeader = true;
00098       } 
00099 
00100       if(writeHeader) {
00101         for(int i = 0; i < (*point).Keywords(); i++) {
00102           if((*point)[i].Size() == 3) {
00103             os << (*point)[i].Name() << "X," 
00104                << (*point)[i].Name() << "Y," 
00105                << (*point)[i].Name() << "Z";
00106           }
00107           else {
00108             os << (*point)[i].Name();
00109           }
00110 
00111           if(i < point->Keywords()-1) {
00112             os << ",";
00113           }
00114         }
00115         os << endl;
00116       }
00117       
00118       for(int i = 0; i < (*point).Keywords(); i++) {
00119         if((*point)[i].Size() == 3) {
00120           os << (string)(*point)[i][0] << "," 
00121              << (string)(*point)[i][1] << "," 
00122              << (string)(*point)[i][2];
00123         }
00124         else {
00125           os << (string)(*point)[i];
00126         }
00127         
00128         if(i < (*point).Keywords()-1) {
00129           os << ",";
00130         }
00131       }
00132       os << endl;
00133     }
00134   }
00135   else {
00136     if (ui.GetString("FORMAT") == "FLAT") {
00137       string msg = "Flat file must have a name.";
00138       throw Isis::iException::Message(Isis::iException::User, msg, _FILEINFO_ );
00139     }
00140   }
00141   delete point;
00142   point = NULL;
00143   prog.CheckStatus();
00144 }