Isis 3.0 Application Source Code Reference |
Home |
00001 /** 00002 * @file 00003 * $Revision$ 00004 * $Date$ 00005 * $Id$ 00006 * 00007 * Unless noted otherwise, the portions of Isis written by the USGS are 00008 * public domain. See individual third-party library and package descriptions 00009 * for intellectual property information, user agreements, and related 00010 * information. 00011 * 00012 * Although Isis has been used by the USGS, no warranty, expressed or 00013 * implied, is made by the USGS as to the accuracy and functioning of such 00014 * software and related material nor shall the fact of distribution 00015 * constitute any such warranty, and no responsibility is assumed by the 00016 * USGS in connection therewith. 00017 * 00018 * For additional information, launch 00019 * $ISISROOT/doc//documents/Disclaimers/Disclaimers.html 00020 * in a browser or see the Privacy & Disclaimers page on the Isis website, 00021 * http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on 00022 * http://www.usgs.gov/privacy.html. 00023 */ 00024 #include <string> 00025 #include <vector> 00026 #include <numeric> 00027 #include <iostream> 00028 #include <sstream> 00029 #include <algorithm> 00030 #include <functional> 00031 00032 #include "SpiceKernel.h" 00033 #include "CkKernelWriter.h" 00034 #include "Filename.h" 00035 #include "Pvl.h" 00036 #include "Cube.h" 00037 #include "iString.h" 00038 #include "TextFile.h" 00039 #include "Application.h" 00040 #include "NaifStatus.h" 00041 #include "iException.h" 00042 00043 #include "naif/SpiceUsr.h" 00044 00045 using namespace std; 00046 00047 namespace Isis { 00048 00049 SpiceKernel::SpiceKernel() { 00050 init(); 00051 } 00052 00053 void SpiceKernel::add(const std::string &cfile) { 00054 Cube cube; 00055 cube.open(cfile); 00056 add(cube); 00057 return; 00058 } 00059 00060 void SpiceKernel::add(Cube &cube) { 00061 _segments.push_back(SpiceSegment(cube)); 00062 return; 00063 } 00064 const SpiceSegment &SpiceKernel::operator[](const int i) const { 00065 return (_segments[i]); 00066 } 00067 00068 00069 bool CheckSegment(const SpiceSegment *s1, const SpiceSegment *s2) { 00070 return (s1->startTime() < s2->startTime()); 00071 } 00072 00073 std::string SpiceKernel::getSummary(const std::string &commfile) const { 00074 vector<const SpiceSegment *> seglist; 00075 for ( int i = 0 ; i < size() ; i++) { 00076 seglist.push_back(&_segments[i]); 00077 } 00078 00079 // Sorts the Segment pointers 00080 stable_sort(seglist.begin(), seglist.end(), CheckSegment); 00081 00082 string comment = getCkComment(commfile); 00083 00084 // Collect comments from each segment 00085 for ( unsigned int i = 0 ; i < seglist.size() ; i++ ) { 00086 comment += seglist[i]->getComment(); 00087 } 00088 return (comment); 00089 } 00090 00091 void SpiceKernel::write(const std::string &kname, const std::string &comfile, 00092 const int cktype) const { 00093 vector<const SpiceSegment *> seglist; 00094 int comChars(0); 00095 for ( int i = 0 ; i < size() ; i++) { 00096 seglist.push_back(&_segments[i]); 00097 comChars += _segments[i].getComment().size(); 00098 } 00099 00100 stable_sort(seglist.begin(), seglist.end(), CheckSegment); 00101 00102 string comment = getCkComment(comfile); 00103 comChars += comment.size(); 00104 00105 // Create the output file. 00106 try { 00107 NaifStatus::CheckErrors(); 00108 CkKernelWriter ckwriter(kname, comChars+512, cktype); 00109 ckwriter.addComment(comment); 00110 NaifStatus::CheckErrors(); 00111 00112 // Write sorted segments 00113 for ( unsigned int i = 0 ; i < seglist.size() ; i++ ) { 00114 try { 00115 ckwriter.write(*seglist[i]); 00116 comment = seglist[i]->getComment(); 00117 ckwriter.addComment(comment); 00118 NaifStatus::CheckErrors(); 00119 } catch ( iException &ie ) { 00120 ostringstream mess; 00121 mess << "Failed to write segment, ID = " << seglist[i]->Id(); 00122 ie.Message(iException::Programmer, mess.str(), _FILEINFO_); 00123 throw; 00124 } 00125 } 00126 } 00127 catch ( iException &ie ) { 00128 ostringstream mess; 00129 mess << "Could not create output CK kernel file: " << kname; 00130 ie.Message(iException::User, mess.str(), _FILEINFO_); 00131 throw; 00132 } 00133 return; 00134 } 00135 00136 void SpiceKernel::init() { 00137 _segments.clear(); 00138 return; 00139 } 00140 00141 std::string SpiceKernel::getCkComment(const std::string &comFile) const { 00142 ostringstream comment; 00143 if ( !comFile.empty() ) { 00144 TextFile txt(comFile); 00145 string cline; 00146 while ( txt.GetLineNoFilter(cline )) { 00147 comment << cline << "\n"; 00148 } 00149 } 00150 else { 00151 comment << "\ 00152 ****************************************************************************\n\ 00153 USGS ISIS (ckwriter) Generated CK Kernel\n\ 00154 Created By: " << Application::UserName() << "\n\ 00155 Date Created: " << Application::DateTime() << "\n\ 00156 ****************************************************************************\n\ 00157 \n\ 00158 Orientation Data in the File\n\ 00159 -----------------------------------------------------------------------\n\ 00160 \n\ 00161 This file contains orientation and potentially derived angular\n\ 00162 rates (where possible/specified).\n\ 00163 \n\ 00164 \n\ 00165 Status\n\ 00166 -----------------------------------------------------------------------\n\ 00167 \n\ 00168 This kernel was generated for the purpose of storing C-Smithed\n\ 00169 pointing updates generated through ISIS processing techniques\n\ 00170 (control nets, jitter analysis, etc...). These CK kernels\n\ 00171 are intended to mimick CKs provided by individual mission\n\ 00172 (NAV teams).\n\ 00173 \n\ 00174 Pedigree\n\ 00175 -----------------------------------------------------------------------\n\ 00176 \n\ 00177 This file was generated by an automated process. The ISIS\n\ 00178 application ckwriter was used to read CK kernel data\n\ 00179 contained within an ISIS cube file. It then writes it as an\n\ 00180 individual segment in the CK. Hence, a list of files can be\n\ 00181 written to a single CK kernel. However, mixing the instruments\n\ 00182 contained in a single CK kernel is discouraged.\n\ 00183 \n\ 00184 Individual segments coming from files will have a single record\n\ 00185 written for the center of the exposure (time) for framing \n\ 00186 instruments or a record/image line for line scan instruments.\n\ 00187 \n\ 00188 Creating type 3 CK kernels must contain at least 3 records for\n\ 00189 framing instruments to avoid roundoff error for the center of the\n\ 00190 exposure time of an image. Framing instruments should pad time\n\ 00191 using the spiceinit application options.\n\ 00192 \n\ 00193 \n\ 00194 Angular Rates\n\ 00195 -----------------------------------------------------------------------\n\ 00196 \n\ 00197 This kernel may or may not contain angular velocity vectors. Efforts\n\ 00198 are made to preserve and provide angular velocities where they\n\ 00199 originally existed.\n\ 00200 \n\ 00201 \n\ 00202 Usage Note\n\ 00203 -----------------------------------------------------------------------\n\ 00204 \n\ 00205 To make use of this file in a typical SPICE based application,\n\ 00206 you must supply a leapseconds kernel, a mission spacecraft clock\n\ 00207 kernel, and the instrument/spacecraft frame kernel. These files\n\ 00208 provide the supporting ancillary data to properly query this\n\ 00209 C-kernel for attitude content. They should be the same kernels that\n\ 00210 were originally used to initialize the image.\n\ 00211 \n\ 00212 Segments in this file are actually individual ISIS files where the\n\ 00213 internally cached SPICE data is extracted and transformed into the\n\ 00214 appropriate content to satisfy NAIF\'s SPICE kernel storage\n\ 00215 requirements. The contents of this kernel are summarized below.\n\ 00216 \n\ 00217 Segment (by file) Summary\n\ 00218 -----------------------------------------------------------------------\n\ 00219 \n\ 00220 The follow sections describe each segment in this CK kernel. Each\n\ 00221 segment is a file in the input list. When running ISIS spiceinit,\n\ 00222 the kernels listed for each file should be supplied to ensure proper\n\ 00223 geometry can be reproduced accurately.\n\ 00224 \n"; 00225 } 00226 00227 return (string(comment.str())); 00228 } 00229 00230 }; // namespace Isis 00231