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

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

00001 //
00002 // C++ Interface: %{MODULE}
00003 //
00004 // Description:
00005 //
00006 //
00007 // Author: %{AUTHOR} <%{EMAIL}>, (C) %{YEAR}
00008 //
00009 // Copyright: See COPYING file that comes with this distribution
00010 //
00011 //
00012 #ifndef POLDERPARASOLFILEDATA_H
00013 #define POLDERPARASOLFILEDATA_H
00014 
00015 #include <string.h>
00016 #include <vector>
00017 #include <map>
00018 #include "filedatareader.h"
00019 #include "polder.h"
00020 #include <cmath>
00021 #include <cfloat>
00022 #include "hdfi.h"
00023 
00024 #include "parasolleader.h"
00025 #include "parasoldata.h"
00026 #include "parasolfiledata.h"
00027 #include "satellitefiledata.h"
00028 
00029 #include "Hdf_sds.hpp"
00030 
00031 using namespace std;
00032 
00036 class PolderParasolFileData : public FileDataReader, protected PARASOLFileData{
00037 public:
00038     PolderParasolFileData(const string &name = string(""), const string &mode = string("r"));
00039 
00040     virtual ~PolderParasolFileData();
00041 
00042     virtual void* read_data(void* data,
00043                             const char* sds_name,
00044                             int * start=NULL,
00045                             int * stride=NULL,
00046                             int *edges=NULL,
00047                             int rank=-1);
00048 
00049     virtual vector<int> get_dataset_dimension(const string &sds_name);
00050 
00051     void get_dataset_fill_value(const string &sds_name, void* fill_value);
00052 
00053     int get_n_dataset();
00054 
00055     string get_dataset_name(int i);
00056 
00057     int get_dataset_data_type(string sds_name);
00058 
00059     string get_values_attr_dataset(string sds_name,string attr_name);
00060 
00061     bool has_attr_dataset(string sds_name,string attr_name);
00062 
00066     void close_data_file();
00067 
00071     void open_data_file();
00072 
00073     void get_fillValue(const string &sds_name, void *fillValue);
00074 
00075 protected:
00076 
00077     short colmin;
00078     short linemin;
00079     short colmax;
00080     short linemax;
00081     string cursds;
00082 
00083     int fileid;
00084 
00085     string filename;
00086 
00090     string *var_list;
00091 
00095     int nb_var_list;
00096 
00097     int size;
00098 
00099     int maxLine;
00100     int maxColumn;
00101 
00102     void getLatLon(short line, short column, float32 *lat, float32 *lon);
00103     // *** Ajout B. Six - 24/05/2011 - voir polderparasolfiledata.cpp
00104     void getLatLon1(short line, short column, float32 *lat, float32 *lon);
00105     // *** Fin ajout
00106 
00107     short NINT(float32 x);
00108 
00109     void free_read_write_allocations( const bool *are_limits_initialized, int *start, int *stride, int *edges );
00110     const bool check_read_write_limits(const char* sds_name, int *start, int *stride, int *edges, const int rank);
00111     void init_read_write_null_input_param(const char* sds_name, int *&start, int *&stride, int *&edges, int &rank, bool * initialized_values);
00112 
00113     float32* read_data_latlon(float32* data, const char* sds_name, int * start, int * stride, int *edges, int rank);
00114     template<class T>
00115     T* read_data_T(T* data, const char* sds_name, int * start, int * stride, int *edges, int rank, int type);
00116 
00117     int get_dataset_idtype(string name);
00118 
00119     template <class T> void getFillValues(T &fillvalue);
00120 
00121     virtual void get_scaling(const string &sds_name, float64 &scale, float64 &offset);
00122 
00123     virtual vector<int> get_dataset_full_dimension(const string &sds_name);
00124 };
00125 
00126 template <class T>
00127 void PolderParasolFileData::getFillValues(T &fillvalue) {
00128     if ( typeid(T) == typeid(char8) ) {
00129         fillvalue = static_cast<T >((T )SCHAR_MIN);
00130     } else if ( typeid(T) == typeid(uchar8) ) {
00131         fillvalue = static_cast<T >((T )UCHAR_MAX);
00132     } else if ( typeid(T) == typeid(int8) ) {
00133         fillvalue = static_cast<T >((T )SCHAR_MIN);
00134     } else if ( typeid(T) == typeid(uint8) ) {
00135         fillvalue = static_cast<T >((T )UCHAR_MAX);
00136     } else if ( typeid(T) == typeid(int16) ) {
00137         fillvalue = static_cast<T >((T )SHRT_MIN);
00138     } else if ( typeid(T) == typeid(uint16) ) {
00139         fillvalue = static_cast<T >((T )USHRT_MAX);
00140     } else if ( typeid(T) == typeid(int32) ) {
00141         fillvalue = static_cast<T >((T )LONG_MIN);
00142     } else if ( typeid(T) == typeid(uint32) ) {
00143         fillvalue = static_cast<T >((T )ULONG_MAX);
00144     } else if ( typeid(T) == typeid(float32) ) {
00145         fillvalue = static_cast<T >((T )-DBL_MAX);
00146     } else if ( typeid(T) == typeid(float64) ) {
00147         fillvalue = static_cast<T >((T )-LDBL_MAX);
00148     }
00149 }
00150 
00151 template<class T>
00152 T* PolderParasolFileData::read_data_T(T* data,
00153                             const char* sds_name,
00154                             int * start,
00155                             int * stride,
00156                             int *edges,
00157                             int rank,
00158                             int type)
00159 {
00160     bool stride_bool;
00161     if(stride==NULL) stride_bool=true;
00162     else stride_bool=false;
00163 
00164     bool are_limits_initialized[3]; // check if start, stride or edges had been initialized in this method
00165     // --- initialize NULL input parametres ---
00166     init_read_write_null_input_param(sds_name, start, stride, edges,rank, are_limits_initialized);
00167     // check the selection limits
00168     check_read_write_limits(sds_name, start,stride,edges,rank); // throw bad_index in case of probleml
00169 
00170     // read the size of the sds data
00171     vector<int> dim = get_dataset_dimension(sds_name);
00172 
00173     if(rank==-1) rank = dim.size();
00174 
00175     int osize =1;
00176 
00177     for(int i =0; i<rank;i++){
00178         osize*=dim[i];
00179     }
00180     if (data==NULL) data = static_cast<T*>(malloc(sizeof(T)*osize));
00181     T fillvalue;
00182     getFillValues(fillvalue);
00183 
00184     get_dataset_fill_value(sds_name,&fillvalue);
00185     for(int i=0; i<osize; i++) data[i]=fillvalue;
00186 
00187     T *val= NULL;
00188 
00189     int param_ind = this->data->get_data_entry_index(sds_name)-6;
00190 
00191     if( type == DFNT_UINT8){
00192         ExtractVariable_Var_Byte(fileid, (unsigned char**)&val, param_ind);
00193     }else if( type == DFNT_UINT16){
00194         ExtractVariable_Var_Short(fileid, (unsigned short**)&val, param_ind);
00195     }else if( type == DFNT_UINT32){
00196         ExtractVariable_Var_Int(fileid, (unsigned int**)&val, param_ind);
00197     }else{
00198         ExtractVariable_Var(fileid, (float**)&val, param_ind);
00199     }
00200 
00201     short *line= NULL;
00202 
00203     ExtractVariable_Grid(fileid, &line, &size, LINE);
00204 
00205     short *col= NULL;
00206 
00207     ExtractVariable_Grid(fileid, &col, &size, COLUMN);
00208 
00209     T **oval = NULL;
00210 
00211     oval = (T**)&data;
00212 
00213     short l,c;
00214 
00215 
00216        if(stride_bool){
00217 
00218             for(int i=0; i<size; i++){
00219                 c=col[i]-colmin;
00220                 l=line[i]-linemin;
00221 
00222                 if(c>=start[0] && c<edges[0] && l>=start[1] && l<edges[1] ){
00223                     (*oval)[c * dim[1] + l] = val[i];
00224                 }
00225             }
00226 
00227         }else{
00228 
00229 
00230             for(int i=0; i<size; i++){
00231                 c=col[i]-colmin;
00232                 l=line[i]-linemin;
00233 
00234                 if(c>=start[0] && c<edges[0] && l>=start[1] && l<edges[1] ){
00235                     if(l%stride[0]==0 && c%stride[1]==0){
00236                         (*oval)[c * dim[1] + l] = val[i];
00237                     }
00238                 }
00239             }
00240         }
00241 
00242     free(line);
00243 
00244     free(col);
00245 
00246     // free the ressources allocated by this method
00247     free_read_write_allocations(are_limits_initialized, start, stride, edges);
00248 
00249     return data;
00250 
00251 }
00252 #endif

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