00001
00002
00009 #ifndef __CDATAREADER_H__
00010 #define __CDATAREADER_H__
00011
00012 #include <QObject>
00013 #include <QVector>
00014
00015 #include <string>
00016 #include <map>
00017 #include <iostream>
00018 #include <cstdlib>
00019 #include <vector>
00020
00021 #include "CGlobals.hpp"
00022 #include "enums.hpp"
00023
00024 using namespace std;
00025
00026
00036 class CDataReader : public QObject
00037 {
00038 Q_OBJECT
00039
00040 static int num_readers;
00041
00042 signals:
00043 void readError(QString);
00044 void readProgress(int, QString, QString);
00045
00046 public:
00047
00048
00049 CDataReader(int ifile = -1);
00050
00051
00052
00053 virtual ~CDataReader();
00054
00055 virtual int numberOfParticles() const;
00056 virtual int particleType(const int & ipart) const;
00057 virtual int particleID(const int & ipart) const;
00058 virtual int particleIndex(const int & id) const;
00059 virtual double particleMass(const int & ipart) const;
00060 virtual double particleDensity(const int & ipart) const;
00061 virtual double particleSml(const int & ipart) const;
00062 virtual double particleSpecEnergy(const int & ipart) const;
00063 virtual double particleTemperature(const int & ipart) const;
00064 virtual double particleZ(const int & ipart) const;
00065 virtual double particleFe(const int & ipart) const;
00066 virtual double particleMg(const int & ipart) const;
00067 virtual double particleACEntropy(const int & ipart) const;
00068 virtual void particlePosition(const int & ipart, double &x, double &y, double &z);
00069 virtual void particleVelocity(const int & ipart, double &x, double &y, double &z);
00070
00071 bool current_file_present(bool showStatus = false);
00072 void set_file(const int& file);
00073 void set_filename(const std::string & filename);
00074 void set_auto_filename(const bool & fn);
00075 virtual void convertUnits();
00076
00077 virtual void setPrefix(const std::string & prefix);
00078 virtual std::string getPrefix() const;
00079
00080 virtual int currentFile() const;
00081 virtual int firstDump() const;
00082 virtual int lastDump() const;
00083
00084 virtual std::string get_filename();
00085 virtual int get_file_size();
00086
00087 virtual int getTypeStart(enums::types_t type);
00088 virtual int getTypeEnd(enums::types_t type);
00089 virtual double getTime(void);
00090
00091
00092
00093
00094
00095
00096
00097
00098 virtual bool check_files_present();
00099 virtual bool readFile();
00100
00101
00102 virtual int fortranTypeStart(enums::types_t type);
00103 virtual int fortranTypeEnd(enums::types_t type);
00104
00105 protected:
00106 int _currentFile;
00107 int file_size_;
00108
00109 std::string filename_;
00110 std::string _prefix;
00111 bool auto_filename_;
00113 std::vector<std::string> blocknames_;
00114 std::vector<int> blocklens_;
00115
00116 virtual void set_file_size();
00117
00118 void setFirstDump(int dump) { _firstDump = dump; }
00119 void setLastDump(int dump) { _lastDump = dump; }
00120
00121 private:
00122 int _firstDump;
00123 int _lastDump;
00124 };
00125
00126 #define NPRES 17
00127
00128
00133 class CDataGadget : public CDataReader
00134 {
00135 Q_OBJECT
00136
00137 signals:
00138 void addBlock(QString, int);
00139 void sendHeaderRow(QString, double);
00140 void sendHeaderRow(QString, QVector<qreal>);
00141
00142 public:
00143 CDataGadget(int ifile, int snapformat=2, int inumpersnap=1);
00144 ~CDataGadget();
00145
00146 std::string get_filename();
00147 bool check_files_present();
00148 void setSnapFormat(const int & format);
00149 void setInumPerSnap(const int & num);
00150
00151 int getSnapFormat() const;
00152
00153 bool readFile();
00154
00155 int getTypeStart(enums::types_t type);
00156 int getTypeEnd(enums::types_t type);
00157 double getTime(void);
00158
00159 private:
00160 void alloc_mem(void);
00161 void free_mem(void);
00162
00163 void fixStarIDs();
00164 void checkStarSanity();
00165
00166 void read_header(void);
00167 void sendTheHeader();
00168 bool read_info(std::string & label);
00169
00170 int getTypeIndex(const enums::types_t & type);
00171
00172 bool load_snapshot(const char * fname, const int & files);
00173 void pd_to_arrays();
00174 void add_bytes_read(const int & bytes);
00175 void read_blocksize(int & blocksize);
00176 void read_label(std::string & label);
00177
00178 void add_block(std::string blockname, int blocklen);
00179 int get_num_blocks();
00180 std::string get_blockname(const int & index);
00181 int get_blocklen(const int & index);
00182
00183 int _snapFormat;
00184 int _inumPerSnap;
00185 FILE * snapfile_;
00186 int _present[NPRES];
00187 };
00188
00189
00190 #endif // __DATAREADER_H__