• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

/home/pascal/depot/filedata/src/parasoldata.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Nicolas PASCAL   *
00003  *   nicolas.pascal@icare.univ-lille1.fr   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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     // record storage classes
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 // //     void get_entry_group_range( const Record & record_code,
00088 // //                                 const RecordFormat::iterator &entry_group_start,
00089 // //                                 RecordFormat::iterator &entry_group_end,
00090 // //                                 int &nb_val);
00097 //     const int get_entry_group_size(const int entry_idx);
00104 //     const int get_entry_group_size(const Record rec, const int entry_idx);
00111 //     const int get_entry_group_nb_val(const Record rec, const int entry_idx) const;
00118     vector <EntryBlock> get_entry_block (const Record rec, const int entry_idx) const;
00128 //     const int get_entry_offset( const Record rec, const int entry_idx, const int record_idx=-1, const int direction_index=-1, const int val_index=-1);
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 &param_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     // the fill value to use in the scaled data
00206     double decoded_fill_value=-DBL_MAX;
00207     // the fill values used in the count data
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     // apply the scaling
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           // there is a missing value for this type and the count data is a missing one. IDEM for out_of_range values
00219           scaled_data[i]=decoded_fill_value;
00220         else
00221           // good value -> apply the scaling
00222           scaled_data[i]=offset+slope*count_val;
00223     }
00224 }
00225 
00226 
00227 #endif

Generated on Thu Feb 14 2013 17:59:03 for filedata.kdevelop by  doxygen 1.7.1