00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PARASOLDATAFILE_H
00021 #define PARASOLDATAFILE_H
00022
00023 #include "parasolfilereader.h"
00024
00031 class PARASOLData : public PARASOLFileReader {
00032 friend class PARASOLFileData;
00033
00034 PARASOLDataFormat *data_file_format;
00035
00036 public:
00037 DataFileDescriptorRecord *data_file_descriptor;
00038 protected:
00039 string filename;
00040
00041
00042 DataRecord *data;
00043
00044 virtual void read_data_file(const string &data_filename);
00049 const bool is_record_loaded(const Record &rec);
00053 void free_records();
00059 PARASOLFileRecord* init_record(const Record &rec);
00066 const int get_record_offset(const Record &rec);
00072 virtual const RecordFormat* get_record_format(const Record &rec);
00078 PARASOLFileRecord* get_record(const Record &rec);
00087
00088
00089
00090
00097
00104
00111
00118 vector <EntryBlock> get_entry_block (const Record rec, const int entry_idx) const;
00128
00137 template <class T>
00138 void apply_scaling(double* scaled_data, const T* count_data, const double & slope, const double & offset, const int & nb_val, const T count_fill_value=T(0));
00139 public:
00140 PARASOLData( const string data_filename="");
00141 virtual ~PARASOLData();
00145 void print_data_file_descriptor();
00146 virtual void print_data(){;};
00147
00158 bool read_data(void* buf, const int ¶m_index, int * start, int * edges, const int rank );
00163 const PARASOLDataFormat * get_data_file_format() {
00164 return data_file_format;
00165 }
00171 const int get_nb_data_record() const;
00176 const int get_sz_data_record() const;
00183 const int get_data_entry_index(const string &var_name) const;
00191 const int get_nb_val(const string &var_name, const int edges=-1, const int dir_idx=-1) const;
00199 const int get_nb_val(const int &var_index,const int edges=-1, const int dir_idx=-1) const;
00200 };
00201 template <class T>
00202 void PARASOLData::apply_scaling( double* scaled_data, const T* count_data, const double & slope, const double & offset, const int & nb_val, const T count_fill_value )
00203 {
00204
00205
00206 double decoded_fill_value=-DBL_MAX;
00207
00208 int level=PARASOLFileFormat::get_level(this->product);
00209 T missing_value=PARASOLFileFormat::get_missing_value<T>(level);
00210 T out_of_range_value=PARASOLFileFormat::get_out_of_range_value<T>(level);
00211
00212
00213 T count_val;
00214 for (int i = 0 ; i<nb_val ; ++i) {
00215 count_val=count_data[i];
00216 if ( (missing_value!=(T)(1) && count_val==missing_value ) ||
00217 (out_of_range_value!=(T)(1) && count_val==out_of_range_value ) )
00218
00219 scaled_data[i]=decoded_fill_value;
00220 else
00221
00222 scaled_data[i]=offset+slope*count_val;
00223 }
00224 }
00225
00226
00227 #endif