orsa_file_mercury.cc

Go to the documentation of this file.
00001 /* 
00002    ORSA - Orbit Reconstruction, Simulation and Analysis
00003    Copyright (C) 2002-2004 Pasquale Tricarico
00004    
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU General Public License
00007    as published by the Free Software Foundation; either version 2
00008    of the License, or (at your option) any later version.
00009    
00010    As a special exception, Pasquale Tricarico gives permission to
00011    link this program with Qt commercial edition, and distribute the
00012    resulting executable, without including the source code for the Qt
00013    commercial edition in the source distribution.
00014    
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019    
00020    You should have received a copy of the GNU General Public License
00021    along with this program; if not, write to the Free Software
00022    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 */
00024 
00025 #include "orsa_file.h"
00026 
00027 #include <iostream>
00028 
00029 using namespace std;
00030 
00031 namespace orsa {
00032   
00033   // Mercury5IntegrationFile
00034   
00035   Mercury5IntegrationFile::Mercury5IntegrationFile(OrbitStream &osin) {
00036     os = &osin;
00037     cols = C10;
00038     status = CLOSE;
00039   }
00040   
00041   Mercury5IntegrationFile::Mercury5IntegrationFile(OrbitStream &osin, M5COLS c_in) {
00042     os   = &osin;
00043     cols = c_in; 
00044     status = CLOSE;
00045   }
00046   
00047   void Mercury5IntegrationFile::Read() {
00048     
00049     // if (file == 0) Open();
00050     if (status == CLOSE) Open();
00051     
00052     if (status != OPEN_R){ 
00053       cerr << "problems encountered when opening file.\n" << endl;
00054     }
00055     
00056     os->resize(0);
00057     os->timestep = 0.0;
00058     OrbitWithEpoch fo;
00059     REWIND_FILE(file); 
00060     
00061     // read the first 4 lines containing the header
00062     int l;
00063     char line[1024],label[1024];
00064     for (l=0;l<4;l++) {
00065       GETS_FILE(line,1024,file);
00066       if (l==1) { // second line
00067         sscanf(line,"%s",label);
00068         os->label = label;
00069         // cerr << "LABEL: [" << os->label << "]" << endl;
00070       }
00071     }
00072     
00073     double a,e,i,omega_per,omega_nod,M;
00074     double time,time_old=0,timestep;
00075     // start reading
00076     
00077     if (cols == C7) {
00078       while (GETS_FILE(line,1024,file) != 0) {
00079         
00080         /* while ( (fscanf(file,"%lf %lf %lf %lf %lf %lf %lf",
00081            &time,&a,&e,&i,&omega_per,&omega_nod,&M)) != EOF ) {
00082         */
00083         
00084         sscanf(line,"%lf %lf %lf %lf %lf %lf %lf",
00085                &time,&a,&e,&i,&omega_per,&omega_nod,&M);
00086         
00087         timestep  = time - time_old;
00088         time_old  = time;
00089         if (os->size() == 2) { 
00090           os->timestep = FromUnits(timestep,DAY); // read in days, save in the current time units
00091           cerr << "timestep set to: " << os->timestep << endl;
00092         }
00093         
00094         fo.epoch.SetTime(FromUnits(time,DAY)); // read in days, save in the current time units
00095         
00096         fo.a                = FromUnits(a,AU);
00097         fo.e                = e;
00098         fo.i                = (pi/180.0)*i;
00099         fo.omega_node       = (pi/180.0)*omega_nod;
00100         fo.omega_pericenter = (pi/180.0)*omega_per;
00101         fo.M                = (pi/180.0)*M;
00102         
00103         os->push_back(fo);
00104       }
00105     }
00106     
00107     if (cols == C10) {
00108       double dummy;
00109       while (GETS_FILE(line,1024,file) != 0) {
00110         /* while ( (fscanf(file,"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
00111            &time,&a,&e,&i,&omega_per,&omega_nod,&M,&dummy,&dummy,&dummy))!= EOF ) {
00112         */
00113 
00114         sscanf(line,"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
00115                &time,&a,&e,&i,&omega_per,&omega_nod,&M,&dummy,&dummy,&dummy);
00116         
00117         timestep  = time - time_old;
00118         time_old  = time;
00119         if (os->size() == 2) { 
00120           os->timestep = FromUnits(timestep,DAY); // read in days, save in the current time units
00121           cerr << "timestep set to: " << os->timestep << endl;
00122         }
00123         
00124         fo.epoch.SetTime(FromUnits(time,DAY)); // read in days, save in the current time units
00125         
00126         fo.a                = FromUnits(a,AU);
00127         fo.e                = e;
00128         fo.i                = (pi/180.0)*i;
00129         fo.omega_node       = (pi/180.0)*omega_nod;
00130         fo.omega_pericenter = (pi/180.0)*omega_per;
00131         fo.M                = (pi/180.0)*M;
00132         
00133         os->push_back(fo);
00134       }
00135     }  
00136   }
00137   
00138 } // namespace orsa

Generated on Fri Nov 3 20:37:42 2006 for liborsa by  doxygen 1.4.7