Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <fstream>
00024 #include <stdio.h>
00025
00026 #include "UNV2411_Structure.hxx"
00027 #include "UNV_Utilities.hxx"
00028
00029 using namespace std;
00030 using namespace UNV;
00031 using namespace UNV2411;
00032
00033 static string _label_dataset = "2411";
00034
00035 UNV2411::TRecord::TRecord():
00036 exp_coord_sys_num(0),
00037 disp_coord_sys_num(0),
00038 color(11)
00039 {}
00040
00041 void UNV2411::Read(std::ifstream& in_stream, TDataSet& theDataSet)
00042 {
00043 if(!in_stream.good())
00044 EXCEPTION(runtime_error,"ERROR: Input file not good.");
00045
00046
00047
00048
00049
00050 if(!beginning_of_dataset(in_stream,_label_dataset))
00051 EXCEPTION(runtime_error,"ERROR: Could not find "<<_label_dataset<<" dataset!");
00052
00057 TNodeLab aLabel;
00058 std::string num_buf;
00059 for(; !in_stream.eof();){
00060 in_stream >> aLabel ;
00061 if(aLabel == -1){
00062
00063 break;
00064 }
00065
00066 TRecord aRec;
00067 in_stream>>aRec.exp_coord_sys_num;
00068 in_stream>>aRec.disp_coord_sys_num;
00069 in_stream>>aRec.color;
00070
00071
00072
00073
00074
00075 for(int d = 0; d < 3; d++){
00076 in_stream>>num_buf;
00077 aRec.coord[d] = D_to_e(num_buf);
00078 }
00079
00080 theDataSet.insert(TDataSet::value_type(aLabel,aRec));
00081 }
00082 }
00083
00084
00085 void UNV2411::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
00086 {
00087 if(!out_stream.good())
00088 EXCEPTION(runtime_error,"ERROR: Output file not good.");
00089
00090
00091
00092
00093 out_stream<<" -1\n";
00094 out_stream<<" "<<_label_dataset<<"\n";
00095
00096 TDataSet::const_iterator anIter = theDataSet.begin();
00097 for(; anIter != theDataSet.end(); anIter++){
00098 const TNodeLab& aLabel = anIter->first;
00099 const TRecord& aRec = anIter->second;
00100 char buf[78];
00101 sprintf(buf, "%10d%10d%10d%10d\n",
00102 aLabel,
00103 aRec.exp_coord_sys_num,
00104 aRec.disp_coord_sys_num,
00105 aRec.color);
00106 out_stream<<buf;
00107
00108
00109 sprintf(buf, "%25.16E%25.16E%25.16E\n",
00110 aRec.coord[0],
00111 aRec.coord[1],
00112 aRec.coord[2]);
00113 out_stream<<buf;
00114 }
00115
00116
00117
00118
00119
00120 out_stream<<" -1\n";
00121 }