USGS

Isis 3.0 Application Source Code Reference

Home

messspkgen.cpp

Go to the documentation of this file.
00001 #include "Isis.h"
00002 
00003 #include <iostream>
00004 #include <sstream>
00005 #include <string>
00006 
00007 #include <QString>
00008 
00009 #include "Filename.h"
00010 #include "Pvl.h"
00011 #include "PvlGroup.h"
00012 #include "PvlKeyword.h"
00013 #include "PvlObject.h"
00014 
00015 
00016 using namespace Isis;
00017 using std::string;
00018 
00019 
00020 string convertUtcToTdb(string utcTime);
00021 
00022 
00023 void IsisMain() {
00024   UserInterface &ui = Application::GetUserInterface();
00025 
00026   // Open the input file from the GUI or find the latest version of the DB file
00027   Filename dbFilename;
00028   if (ui.WasEntered("FROM")) {
00029     dbFilename = ui.GetFilename("FROM");
00030   }
00031   else {
00032     string dbString("$messenger/kernels/spk/kernels.????.db");
00033     dbFilename = dbString;
00034     dbFilename.HighestVersion();
00035   }
00036   Pvl kernelDb(dbFilename.Expanded());
00037 
00038   // Get our main objects
00039   PvlObject &position = kernelDb.FindObject("SpacecraftPosition");
00040 
00041   // Pull out the reconstructed group and set the ending time to our orbit
00042   // cutoff
00043   PvlGroup &reconstructed = position.FindGroup("Selection");
00044   PvlKeyword &time = reconstructed[reconstructed.Keywords() - 3];
00045   string reconstructedEnd = time[1];
00046   time[1] = convertUtcToTdb(ui.GetString("TIME"));
00047 
00048   // Get the predicted group from the previous file, set the start time to the
00049   // orbit cutoff and the end to whatever the reconstructed end was before
00050   PvlGroup predicted("Selection");
00051 
00052   PvlKeyword predictedTime("Time");
00053   predictedTime += time[1];
00054   predictedTime += reconstructedEnd;
00055   predicted.AddKeyword(predictedTime);
00056 
00057   PvlKeyword predictedFile("File");
00058   predictedFile += reconstructed.FindKeyword("File")[0];
00059   predicted.AddKeyword(predictedFile);
00060 
00061   predicted.AddKeyword(PvlKeyword("Type", "Predicted"));
00062 
00063   // Add the modified predicted group to the new DB file
00064   position.AddGroup(predicted);
00065 
00066   // Get the output filename, either user-specified or the latest version for
00067   // the kernels area (as run by makedb)
00068   Filename outDBfile;
00069   if (ui.WasEntered("TO")) {
00070     outDBfile = ui.GetFilename("TO");
00071   }
00072   else {
00073     outDBfile = dbFilename;
00074   }
00075 
00076   // Write the updated PVL as the new SPK DB file
00077   kernelDb.Write(outDBfile.Expanded());
00078 }
00079 
00080 
00081 string convertUtcToTdb(string utcTime) {
00082   // Remove any surrounding whitespace and the trailing " UTC", then replace
00083   // with TDB syntax
00084   QString orbitCutoffRaw = QString::fromStdString(utcTime);
00085   orbitCutoffRaw.trimmed();
00086   orbitCutoffRaw.remove(QRegExp(" UTC$"));
00087 
00088   // We need to swap around the day and the year in order to go from UTC to TDB.
00089   // The year will be the first and only occurrence of 4 numbers in a row, so
00090   // pull that out.
00091   QRegExp yearRx("(\\d{4})");
00092   int pos = yearRx.indexIn(orbitCutoffRaw);
00093   QString year = (pos > -1) ? yearRx.cap(1) : "";
00094 
00095   // The day will come at the beginning of the string, and will be 1 or 2
00096   // characters.  If it's only 1, add an extra 0 to make it 2.
00097   QRegExp dayRx("(^\\d{1,2})");
00098   pos = dayRx.indexIn(orbitCutoffRaw);
00099   QString day = (pos > -1) ? dayRx.cap(1) : "";
00100   if (day.length() == 1) day = "0" + day;
00101 
00102   // Swap the day and year
00103   orbitCutoffRaw.replace(yearRx, day);
00104   orbitCutoffRaw.replace(dayRx, year);
00105 
00106   // Tack on the necessary TDB tail
00107   string orbitCutoff = orbitCutoffRaw.toStdString();
00108   orbitCutoff += ".000 TDB";
00109   return orbitCutoff;
00110 }
00111