Observation
|
00001 /* HiRISE Data Component 00002 00003 PIRL CVS ID: Data_Component.hh,v 1.38 2020/02/14 01:17:18 schaller Exp 00004 00005 Copyright (C) 2004-2020 Arizona Board of Regents on behalf of the Lunar and 00006 Planetary Laboratory at the University of Arizona. 00007 00008 Licensed under the Apache License, Version 2.0 (the "License"); you may not use 00009 this file except in compliance with the License. You may obtain a copy of the 00010 License at 00011 00012 http://www.apache.org/licenses/LICENSE-2.0 00013 00014 Unless required by applicable law or agreed to in writing, software distributed 00015 under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 00016 CONDITIONS OF ANY KIND, either express or implied. See the License for the 00017 specific language governing permissions and limitations under the License. 00018 */ 00019 00020 #ifndef _HiRISE_Data_Component_ 00021 #define _HiRISE_Data_Component_ 00022 00023 #include "Instrument.hh" 00024 00025 // PIRL 00026 #include "Data_Block.hh" 00027 00028 #if defined (INCLUDE_PVL) 00029 // idaeim::PVL 00030 #include "PVL.hh" 00031 #endif 00032 00033 #include <iostream> 00034 #include <string> 00035 #include <vector> 00036 00038 namespace UA 00039 { 00041 namespace HiRISE 00042 { 00043 /*============================================================================== 00044 Types 00045 */ 00046 #ifndef INT_8_TYPE 00047 #define INT_8_TYPE char 00048 #endif 00049 00050 typedef INT_8_TYPE int_8; 00051 00052 #ifndef U_INT_8_TYPE 00053 #define U_INT_8_TYPE unsigned char 00054 #endif 00055 00056 typedef U_INT_8_TYPE u_int_8; 00057 00058 #ifndef INT_16_TYPE 00059 #define INT_16_TYPE short int 00060 #endif 00061 00062 typedef INT_16_TYPE int_16; 00063 00064 #ifndef U_INT_16_TYPE 00065 #define U_INT_16_TYPE unsigned short int 00066 #endif 00067 00068 typedef U_INT_16_TYPE u_int_16; 00069 00070 #ifndef INT_32_TYPE 00071 #define INT_32_TYPE int 00072 #endif 00073 00074 typedef INT_32_TYPE int_32; 00075 00076 #ifndef U_INT_32_TYPE 00077 #define U_INT_32_TYPE unsigned int 00078 #endif 00079 00080 typedef U_INT_32_TYPE u_int_32; 00081 00082 #ifndef INT_64_TYPE 00083 #define INT_64_TYPE long int 00084 #endif 00085 00086 typedef INT_64_TYPE int_64; 00087 00088 #ifndef U_INT_64_TYPE 00089 #define U_INT_64_TYPE unsigned long int 00090 #endif 00091 00092 typedef U_INT_64_TYPE u_int_64; 00093 00095 typedef PIRL::Data_Block::Index Index; 00096 00098 typedef u_int_16 Pixel_type; 00099 00100 /******************************************************************************* 00101 Data_Component 00102 */ 00121 class Data_Component 00122 : public Instrument, 00123 public PIRL::Data_Block 00124 { 00125 public: 00126 /*============================================================================== 00127 Constants: 00128 */ 00130 static const char* const 00131 ID; 00132 00137 static const int 00138 DECIMAL, 00139 HEX, 00140 BOOLEAN; 00141 00143 static const char 00144 PATHNAME_DELIMITER; 00145 00147 static const int 00148 UTC_SECONDS_PRECISION; 00149 00151 static const char 00152 SUBSECONDS_DELIMITER; 00153 00154 #if defined (INCLUDE_CSPICE) 00155 00161 static const char* const 00162 SPICE_METAKERNEL_VARIABLE; 00163 00165 static const char* const 00166 DEFAULT_SPICE_METAKERNEL; 00167 00169 static const int 00170 MRO_CLOCK_ID; 00171 00172 #endif // INCLUDE_SPICE 00173 00174 static const char* const 00175 INVALID_UTC_TIME; 00176 00177 /*============================================================================== 00178 Constructors 00179 */ 00200 Data_Component 00201 ( 00202 const char** names = NULL, 00203 unsigned int size = 0, 00204 const Index* offsets = NULL, 00205 const Index indexed_arrays[][2] = NULL, 00206 Data_Order order = Data_Block::MSB 00207 ); 00208 00227 Data_Component (const Data_Component& component, bool data_duplicate = true); 00228 00243 Data_Component& operator= (const Data_Component& component); 00244 00252 virtual ~Data_Component (); 00253 00254 /*============================================================================== 00255 Accessors 00256 */ 00267 virtual std::string id () const; 00268 00276 virtual const char* name () const = 0; 00277 00285 const char* name (Index element) const; 00286 00296 virtual u_int_32 get (Index element, Index index = 0) const; 00297 00308 virtual Data_Component& put 00309 (const u_int_32 value, Index element, Index index = 0); 00310 00311 #if defined (INCLUDE_PVL) 00312 /*============================================================================== 00313 PVL 00314 */ 00323 virtual idaeim::PVL::Aggregate* PVL () const = 0; 00324 00325 #endif // defined (INCLUDE_PVL) 00326 00327 /*============================================================================== 00328 Printing 00329 */ 00353 virtual std::ostream& print 00354 (std::ostream& stream = std::cout, bool verbose = false) const = 0; 00355 00370 std::ostream& print_element (const Index element, int format = DECIMAL, 00371 std::ostream& stream = std::cout, int width = 0) const; 00372 00382 std::ostream& print_element (const Index element, std::ostream& stream) const 00383 {return print_element (element, DECIMAL, stream, 0);} 00384 00415 std::ostream& print_element_location (const Index element, 00416 std::ostream& stream = std::cout) const; 00417 00432 unsigned int element_location_print_width (Index element) const; 00433 00439 unsigned int name_field_width () const; 00440 00462 Data_Component& name_field_width (unsigned int width); 00463 00464 /*============================================================================== 00465 Validation 00466 */ 00471 virtual bool is_valid () const = 0; 00472 00473 /*------------------------------------------------------------------------------ 00474 Data 00475 */ 00501 Data_Block& data (void* const block); 00502 00523 Data_Block& attach (void* const block, unsigned int size); 00524 00539 Data_Component& resize (unsigned int size); 00540 00546 unsigned char* data () const 00547 {return PIRL::Data_Block::data ();} 00548 00556 unsigned int local_data () 00557 {return Local_Data;} 00558 00598 u_int_16 internet_checksum () const; 00599 00600 //.............................................................................. 00601 private: 00602 00604 unsigned int 00605 Local_Data; 00606 00608 const char** 00609 Names; 00610 00612 unsigned int 00613 Max_Name_Length; 00614 00616 unsigned int 00617 Name_Field_Width; 00618 00619 }; // class Data_Component 00620 00621 00622 /*============================================================================== 00623 Output operator 00624 */ 00632 std::ostream& operator<< 00633 (std::ostream& stream, const Data_Component& component); 00634 00635 /******************************************************************************* 00636 Helpers 00637 */ 00666 std::ostream& print_value (u_int_32 value, int format = Data_Component::DECIMAL, 00667 std::ostream& stream = std::cout, int width = 0); 00668 00669 #if defined (INCLUDE_PVL) 00670 /*------------------------------------------------------------------------------ 00671 PVL 00672 */ 00674 enum Parameter_Class_Selection 00675 { 00676 AGGREGATE_PARAMETER = -1, 00677 ANY_PARAMETER = 0, 00678 ASSIGNMENT_PARAMETER = 1 00679 }; 00680 00715 idaeim::PVL::Parameter* 00716 PVL_parameter 00717 ( 00718 idaeim::PVL::Aggregate& aggregate, 00719 std::string pathname, 00720 bool case_sensitive = false, 00721 int skip = 0, 00722 Parameter_Class_Selection parameter_class = ANY_PARAMETER 00723 ); 00724 00744 std::vector<std::string> 00745 PVL_values 00746 ( 00747 idaeim::PVL::Aggregate& aggregate, 00748 std::string pathname, 00749 bool case_sensitive = false, 00750 int skip = 0 00751 ); 00752 00769 bool 00770 PVL_value 00771 ( 00772 idaeim::PVL::Aggregate& aggregate, 00773 std::string pathname, 00774 unsigned int value, 00775 bool case_sensitive = false, 00776 int skip = 0 00777 ); 00778 00779 bool 00780 PVL_value 00781 ( 00782 idaeim::PVL::Aggregate& aggregate, 00783 std::string pathname, 00784 int value, 00785 bool case_sensitive = false, 00786 int skip = 0 00787 ); 00788 00805 bool 00806 PVL_value 00807 ( 00808 idaeim::PVL::Aggregate& aggregate, 00809 std::string pathname, 00810 const std::string& value, 00811 bool case_sensitive = false, 00812 int skip = 0 00813 ); 00814 00815 #endif // defined (INCLUDE_PVL) 00816 00817 /*------------------------------------------------------------------------------ 00818 Time 00819 */ 00873 std::string UTC_time 00874 (double seconds, unsigned int epoch = Instrument::SPACECRAFT_EPOCH); 00875 00876 00878 enum Clock_Selector 00879 { 00880 HiRISE_Clock, 00881 MRO_Clock 00882 }; 00883 00905 std::string clock_count (double seconds, Clock_Selector clock = HiRISE_Clock); 00906 00915 double seconds 00916 (const std::string& clock_count, Clock_Selector clock = HiRISE_Clock); 00917 00918 /*------------------------------------------------------------------------------ 00919 Files 00920 */ 00926 bool file_exists (const std::string& filename); 00927 00942 std::string pathname (const std::string& filename = ""); 00943 00956 std::string pathname 00957 ( 00958 const std::string& directory, 00959 const std::string& filename, 00960 const std::string& extension 00961 ); 00962 00972 std::string filename (const std::string& pathname); 00973 00974 /*------------------------------------------------------------------------------ 00975 Stringy thingies 00976 */ 00991 std::string bits (const unsigned int value, unsigned int count = 0); 00992 01000 unsigned int max_strlen (const char** strings); 01001 01008 std::string to_upper (const std::string& characters); 01009 01022 std::string shift (std::string lines, int amount); 01023 01039 std::string plural (int count); 01040 01041 /*------------------------------------------------------------------------------ 01042 Miscellaneous 01043 */ 01048 std::string hostname (); 01049 01059 bool member_of 01060 (const unsigned int value, const unsigned int *array, int size); 01061 01071 bool member_of 01072 (const char* const value, const char* const array[], int size); 01073 01074 01075 } // namespace HiRISE 01076 } // namespace UA 01077 #endif