00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _ORSA_FILE_H_
00026 #define _ORSA_FILE_H_
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include "config.h"
00030 #endif
00031
00032 #include "orsa_analysis.h"
00033 #include "orsa_config.h"
00034 #include "orsa_orbit.h"
00035 #ifdef HAVE_GSL
00036 #include "orsa_orbit_gsl.h"
00037 #endif // HAVE_GSL
00038 #include "orsa_universe.h"
00039 #include "orsa_body.h"
00040 #include "orsa_file_jpl.h"
00041
00042 #ifdef HAVE_LIBZ
00043 #include <zlib.h>
00044 #endif
00045
00046 #include <string>
00047 #include <map>
00048 #include <list>
00049 #include <cstdio>
00050
00051 #ifdef HAVE_LIBZ
00052 #define FILE_TYPE gzFile
00053 #define OPEN_FILE gzopen
00054 #define CLOSE_FILE gzclose
00055 #define REWIND_FILE gzrewind
00056 #define GETS_FILE(buffer,length,file) gzgets((file),(buffer),(length))
00057 #define PUTS_FILE(buffer,file) gzputs((file),(buffer))
00058 #define READ_FILE(buffer,size,num,file) gzread((file),(buffer),(size)*(num))
00059 #define WRITE_FILE(buffer,size,num,file) gzwrite((file),(buffer),(size)*(num))
00060 #define SEEK_FILE(file,offset,whence) gzseek((file),(offset),(whence))
00061 #define FLUSH_FILE(file) gzflush((file),Z_FULL_FLUSH)
00062 #define OPEN_READ "rb"
00063 #define OPEN_WRITE "wb"
00064 #else
00065 #define FILE_TYPE FILE*
00066 #define OPEN_FILE fopen
00067 #define CLOSE_FILE fclose
00068 #define REWIND_FILE rewind
00069 #define GETS_FILE(buffer,length,file) fgets((buffer),(length),(file))
00070 #define PUTS_FILE(buffer,file) fputs((buffer),(file))
00071 #define READ_FILE(buffer,size,num,file) fread((buffer),(size),(num),(file))
00072 #define WRITE_FILE(buffer,size,num,file) fwrite((buffer),(size),(num),(file))
00073 #define SEEK_FILE(file,offset,whence) fseek((file),(offset),(whence))
00074 #define FLUSH_FILE(file) fflush((file))
00075 #define OPEN_READ "r"
00076 #define OPEN_WRITE "w"
00077 #endif
00078
00079 namespace orsa {
00080
00081 enum FILE_STATUS {CLOSE,OPEN_R,OPEN_W};
00082
00083
00084 class File {
00085 public:
00086 File() {
00087 status = CLOSE;
00088 file = 0;
00089 }
00090
00091 virtual ~File() {
00092 Close();
00093 };
00094
00095 public:
00096 void Close();
00097
00098 public:
00099 inline virtual std::string GetFileName () const { return filename; }
00100
00101 inline virtual void SetFileName (std::string name_in) {
00102 if (status != CLOSE) Close();
00103 filename = name_in;
00104 }
00105
00106 inline virtual void SetFileName (char * name_in) {
00107 std::string n = name_in;
00108 SetFileName (n);
00109 }
00110
00111 protected:
00112 std::string filename;
00113 FILE_TYPE file;
00114 FILE_STATUS status;
00115 };
00116
00117
00118
00119
00120 class ReadFile : public File {
00121 public:
00122 ReadFile() : File() { }
00123 void Open();
00124 virtual void Read() = 0;
00125 };
00126
00127
00128 class WriteFile : public File {
00129 public:
00130 WriteFile() : File() { }
00131 void Open();
00132 virtual void Write() = 0;
00133 };
00134
00135
00136 class ReadWriteFile : public File {
00137 public:
00138 ReadWriteFile() : File() { }
00139 void Open(const FILE_STATUS st = OPEN_R);
00140 virtual void Read() = 0;
00141 virtual void Write() = 0;
00142 };
00143
00144
00145
00146 enum M5COLS {C7,C10};
00147
00148
00149 class Mercury5IntegrationFile : public ReadFile {
00150
00151 public:
00152 Mercury5IntegrationFile(OrbitStream&);
00153 Mercury5IntegrationFile(OrbitStream&, M5COLS);
00154
00155 public:
00156 void Read();
00157
00158 M5COLS cols;
00159
00160 public:
00161
00162
00163 private:
00164 OrbitStream *os;
00165 };
00166
00167
00168 class RadauModIntegrationFile : public ReadFile {
00169
00170 public:
00171 RadauModIntegrationFile(OrbitStream&);
00172
00173 public:
00174
00175
00176 public:
00177 void Read();
00178
00179 private:
00180 OrbitStream *os;
00181 };
00182
00183
00184 class SWIFTFile : public ReadFile {
00185 public:
00186 SWIFTFile(OrbitStream&);
00187
00188 public:
00189 void Read();
00190 int AsteroidsInFile();
00191
00192 public:
00193
00194
00195 public:
00196 OrbitStream *os;
00197 };
00198
00199
00200 class LocationFile : public ReadFile {
00201 public:
00202 LocationFile();
00203
00204 public:
00205 void Read();
00206
00207 public:
00208 Vector ObsPos(const std::string, const Date&);
00209
00210 public:
00211 std::map<std::string,Location> locations;
00212
00213 public:
00214
00215 std::list<std::string> codes;
00216 };
00217
00218
00219 extern LocationFile * location_file;
00220
00221
00222 class MPCObsFile : public ReadFile {
00223 public:
00224
00225 MPCObsFile();
00226
00227 public:
00228 void Read();
00229
00230 public:
00231 bool ReadNominalOrbit(OrbitWithEpoch &);
00232
00233 public:
00234 std::vector<Observation> obs;
00235 };
00236
00237
00238 class RWOFile : public ReadFile {
00239 public:
00240 RWOFile();
00241
00242 public:
00243 void Read();
00244
00245 public:
00246 std::vector<Observation> obs;
00247 };
00248
00249
00250 class AsteroidDatabaseFile : public ReadFile {
00251 public:
00252 AsteroidDatabaseFile() : ReadFile() { db = 0; }
00253 public:
00254 AsteroidDatabase *db;
00255 public:
00256 inline virtual void read_progress(int, bool&, bool&) { };
00257 inline virtual void read_finished() { };
00258 };
00259
00260
00261
00262 class AstDySMatrixFile : public AsteroidDatabaseFile {
00263 public:
00264 AstDySMatrixFile();
00265 ~AstDySMatrixFile();
00266 public:
00267 void Read();
00268 };
00269
00270
00271
00272 class NEODYSCAT : public AsteroidDatabaseFile {
00273 public:
00274 NEODYSCAT();
00275 ~NEODYSCAT();
00276 public:
00277 void Read();
00278 };
00279
00280
00281 class JPLDastcomNumFile : public AsteroidDatabaseFile {
00282 public:
00283 JPLDastcomNumFile();
00284 virtual ~JPLDastcomNumFile();
00285 void Read();
00286 };
00287
00288 class JPLDastcomUnnumFile : public AsteroidDatabaseFile {
00289 public:
00290 JPLDastcomUnnumFile();
00291 virtual ~JPLDastcomUnnumFile();
00292 void Read();
00293 };
00294
00295 class JPLDastcomCometFile : public AsteroidDatabaseFile {
00296 public:
00297 JPLDastcomCometFile();
00298 virtual ~JPLDastcomCometFile();
00299 void Read();
00300 };
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 class AstorbFile : public AsteroidDatabaseFile {
00318
00319 public:
00320 AstorbFile();
00321 virtual ~AstorbFile();
00322
00323 public:
00324 void Read();
00325
00326
00327
00328
00329 public:
00330
00331
00332 public:
00333
00334
00335
00336
00337
00338
00339 };
00340
00341
00342
00343 class MPCOrbFile : public AsteroidDatabaseFile {
00344 public:
00345 MPCOrbFile();
00346 ~MPCOrbFile();
00347
00348 public:
00349 void Read();
00350
00351 public:
00352
00353
00354
00355
00356
00357
00358 };
00359
00360
00361
00362 class MPCCometFile : public AsteroidDatabaseFile {
00363 public:
00364 MPCCometFile();
00365 ~MPCCometFile();
00366
00367 public:
00368 void Read();
00369
00370 public:
00371
00372
00373
00374
00375
00376
00377 };
00378
00379
00380
00381 enum OrsaFileDataType {
00382 OFDT_END_OF_FILE=0,
00383 OFDT_UNIVERSE=1,
00384 OFDT_EVOLUTION=2,
00385 OFDT_FRAME=3,
00386 OFDT_BODY=4
00387 };
00388
00389 inline void convert(OrsaFileDataType &ofdt, const unsigned int i) {
00390 switch(i) {
00391 case 0: ofdt = OFDT_END_OF_FILE; break;
00392 case 1: ofdt = OFDT_UNIVERSE; break;
00393 case 2: ofdt = OFDT_EVOLUTION; break;
00394 case 3: ofdt = OFDT_FRAME; break;
00395 case 4: ofdt = OFDT_BODY; break;
00396
00397 default:
00398 ORSA_ERROR("conversion problem: i = %i",i);
00399 break;
00400 }
00401 }
00402
00403
00404 class OrsaFile : public ReadWriteFile {
00405
00406 public:
00407 OrsaFile();
00408
00409 public:
00410 void Read();
00411 void Write();
00412
00413 public:
00414 static bool GoodFile(const std::string&);
00415
00416 private:
00417 virtual void make_new_universe(Universe**,length_unit,mass_unit,time_unit,UniverseType,ReferenceSystem,TimeScale);
00418 virtual void make_new_evolution(Evolution**);
00419
00420 protected:
00421 void Write(Universe**);
00422 void Read( Universe**);
00423 void Write(Evolution**);
00424 void Read( Evolution**);
00425 void Write(Frame*,bool=false);
00426 void Read( Frame*,bool=false);
00427 void Write(Body*);
00428 void Read( Body*);
00429 void Write(BodyWithEpoch*);
00430 void Read( BodyWithEpoch*);
00431
00432 void Write(const Integrator *);
00433 void Read( Integrator**);
00434
00435 void Write(const Interaction *);
00436 void Read( Interaction**);
00437 void Write(std::string*);
00438 void Read( std::string*);
00439 void Write(orsa::Vector*);
00440 void Read( orsa::Vector*);
00441 void Write(bool*);
00442 void Read( bool*);
00443 void Write(unsigned int*);
00444 void Read( unsigned int*);
00445 void Write(int*);
00446 void Read( int*);
00447 void Write(double*);
00448 void Read( double*);
00449 void Write(IntegratorType*);
00450 void Read( IntegratorType*);
00451 void Write(InteractionType*);
00452 void Read( InteractionType*);
00453 void Write(time_unit*);
00454 void Read( time_unit*);
00455 void Write(length_unit*);
00456 void Read( length_unit*);
00457 void Write(mass_unit*);
00458 void Read( mass_unit*);
00459 void Write(Date*);
00460 void Read( Date*);
00461 void Write(UniverseTypeAwareTime*);
00462 void Read( UniverseTypeAwareTime*);
00463 void Write(UniverseTypeAwareTimeStep*);
00464 void Read( UniverseTypeAwareTimeStep*);
00465 void Write(ReferenceSystem*);
00466 void Read( ReferenceSystem*);
00467 void Write(UniverseType*);
00468 void Read( UniverseType*);
00469 void Write(TimeScale*);
00470 void Read( TimeScale*);
00471 void Write(OrsaFileDataType*);
00472 void Read( OrsaFileDataType*);
00473 void Write(JPL_planets*);
00474 void Read( JPL_planets*);
00475 void Write(TimeStep*);
00476 void Read( TimeStep*);
00477
00478 private:
00479 size_t read_swap(void *ptr, unsigned int size);
00480
00481 private:
00482 unsigned int byte_order;
00483 std::string orsa_version;
00484 OrsaFileDataType last_ofdt_read;
00485 bool swap_bytes;
00486 };
00487
00488
00489 class OrsaConfigFile : public ReadWriteFile {
00490 public:
00491 OrsaConfigFile();
00492
00493
00494 void Read();
00495 void Write();
00496
00497 private:
00498 std::list<ConfigEnum> list_enum;
00499
00500
00501
00502 };
00503
00504
00505 inline void remove_leading_trailing_spaces(std::string &s) {
00506
00507 const int first = s.find_first_not_of(" ");
00508 s.erase(0,first);
00509
00510 const int last = s.find_last_not_of(" ");
00511 s.erase(last+1,s.size());
00512 }
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528 class OrsaPaths {
00529 public:
00530 OrsaPaths();
00531 OrsaPaths(const std::string &config_path);
00532 static const char * work_path() { return path; }
00533 static char path_separator() { return _path_separator; }
00534
00535
00536 private:
00537 void set_path_separator();
00538 void set_path();
00539
00540 private:
00541 static char * path;
00542 static char _path_separator;
00543 };
00544
00545 extern OrsaPaths *orsa_paths;
00546
00547
00548
00549
00550 class TLEFile : public ReadFile {
00551 public:
00552 TLEFile();
00553 void Read();
00554 public:
00555 inline virtual void read_progress(int) { };
00556 public:
00557 std::vector<BodyWithEpoch> sat;
00558 };
00559
00560 }
00561
00562 #endif // _ORSA_FILE_H_