/* PolderParasolFileData.cpp */ #include "polderparasolfiledata.h" #include "Hdf_sds.hpp" string Latitude="Latitude"; string Longitude="Longitude"; PolderParasolFileData::PolderParasolFileData(const string &filename, const string &mode) :FileData(filename,mode),FileDataReader(filename,mode),PARASOLFileData(filename,mode),cursds("") { size = 0; this->filename=filename; if (!exists_file(filename)) { bad_file e(filename); throw e; } int status = InitPolder(50,0); if(status!=PLD_OK) { bad_open_file e(filename,mode); throw e; } fileid = OpenProduct((char*)filename.c_str()); if(fileid==PLD_PRODUCT_EMPTY){ empty_parasol_file e(filename); throw e; }else if(fileid<0) { bad_open_file e(filename,mode); throw e; } char **borbit = new char*; char **eorbit = new char*; status = get_Date(fileid, borbit, eorbit); if(status!=PLD_OK) { bad_open_file e(filename,mode); throw e; } string begin = string(*borbit); string end = string(*eorbit); Date bdate; bdate.set_date_str(begin,(const char *) "%Y%m%d%H%M%S"); Date edate; edate.set_date_str(end,(const char *) "%Y%m%d%H%M%S"); free (*borbit); free (*eorbit); this->set_date(bdate); this->time_coverage=edate.get_epoch_time()-bdate.get_epoch_time(); vector dim = get_dataset_full_dimension(Latitude); maxLine = dim[1]; maxColumn = dim[0]; CloseProduct(fileid); fileid=-1; } void PolderParasolFileData::open_data_file() { fileid = OpenProduct((char*)filename.c_str()); } void PolderParasolFileData::close_data_file() { CloseProduct(fileid); fileid=-1; } PolderParasolFileData::~PolderParasolFileData() { CloseProduct(fileid); } void* PolderParasolFileData::read_data(void* buf, const char* sds_name, int * start, int * stride, int *edges, int rank) { if(Latitude==sds_name || Longitude==sds_name) { return (void*)read_data_latlon((float32*)buf, sds_name, start, stride, edges, rank); }else{ int code_type =this->get_dataset_data_type(sds_name); switch(code_type) { case DFNT_CHAR8 : { return (void*)read_data_T((char8*)buf, sds_name, start, stride, edges, rank, code_type); break ; } case DFNT_UCHAR8 : { return (void*)read_data_T((uchar8*)buf, sds_name, start, stride, edges, rank, code_type); break ; } case DFNT_INT8 : { return (void*)read_data_T((int8*)buf, sds_name, start, stride, edges, rank, code_type); break ; } case DFNT_UINT8 : { return (void*)read_data_T((uint8*)buf, sds_name, start, stride, edges, rank, code_type); break ; } case DFNT_INT16 : { return (void*)read_data_T((int16*)buf, sds_name, start, stride, edges, rank, code_type); break ; } case DFNT_UINT16 : { return (void*)read_data_T((uint16*)buf, sds_name, start, stride, edges, rank, code_type); break ; } case DFNT_INT32 : { return (void*)read_data_T((int32*)buf, sds_name, start, stride, edges, rank, code_type); break ; } case DFNT_UINT32 : { return (void*)read_data_T((uint32*)buf, sds_name, start, stride, edges, rank, code_type); break ; } case DFNT_FLOAT32 : { return (void*)read_data_T((float32*)buf, sds_name, start, stride, edges, rank, code_type); break ; } case DFNT_FLOAT64 : { return (void*)read_data_T((float64*)buf, sds_name, start, stride, edges, rank, code_type); break ; } default : { stringstream msg ; msg << "The type : "; msg << code_type; msg << " is unknown."; cout<<"file("<<__FILE__<<") line("<<__LINE__<<") "< dim =this->get_dataset_dimension(sds_name); for ( int i = 0 ; i (dim[i]>0)?(dim[i]-1):0) { bad_index e(start[i],(dim[i])); throw e; return false; } // test the selection length int stride_val; if ( stride!=NULL ) stride_val=stride[i]; else stride_val=1; if ( (start[i]+(edges[i]*stride_val))> dim[i] ) { bad_index e(start[i]+(edges[i]*stride_val),dim[i]-1); throw e; return false; } } return true; }; void PolderParasolFileData::init_read_write_null_input_param(const char* sds_name, int *&start, int *&stride, int *&edges, int &rank, bool * initialized_values) { initialized_values[0] = false; initialized_values[1] = false; initialized_values[2] = false; // if rank is not defined, set to the sds one if (rank==-1) rank = 2; // if start is not defined, allocate it with a rank size, and set its values to 0 if ( start == NULL ) { start = new int [rank]; initialized_values[0] = true; for ( int i = 0;i dim =this->get_dataset_dimension(sds_name); for ( int i = 0;i PolderParasolFileData::get_dataset_full_dimension(const string &sds_name) { vector v; int x = GetProductMaxpix (fileid); int y = x/2; v.push_back(x); v.push_back(y); return v; } vector PolderParasolFileData::get_dataset_dimension(const string &sds_name) { if(cursds != sds_name){ short c; short l; int x = GetProductMaxpix (fileid); int y = x/2; linemin=y; linemax=0; colmin=x; colmax=0; short *col= NULL; ExtractVariable_Grid(fileid, &col, &size, COLUMN); short *line= NULL; ExtractVariable_Grid(fileid, &line, &size, LINE); for(int i=0; i linemax) linemax=l; if(l < linemin) linemin=l; if(c > colmax) colmax=c; if(c < colmin) colmin=c; } } vector v; v.push_back(colmax-colmin); v.push_back(linemax-linemin); return v; } void PolderParasolFileData::get_dataset_fill_value(const string &sds_name, void* fill_value) { int code_type =this->get_dataset_data_type(sds_name); switch(code_type) { case DFNT_CHAR8 : { char8 x = static_cast((char8 )SCHAR_MIN); char8 **y; y = (char8**)&fill_value; (**y) = x; break ; } case DFNT_UCHAR8 : { uchar8 x = static_cast((uchar8 )UCHAR_MAX); uchar8 **y; y = (uchar8**)&fill_value; (**y) = x; break ; } case DFNT_INT8 : { int8 x = static_cast((int8 )SCHAR_MIN); int8 **y; y = (int8**)&fill_value; (**y) = x; break ; } case DFNT_UINT8 : { uint8 x = static_cast((uint8 )UCHAR_MAX); uint8 **y; y = (uint8**)&fill_value; (**y) = x; break ; } case DFNT_INT16 : { int16 x = static_cast((int16 )SHRT_MIN); int16 **y; y = (int16**)&fill_value; (**y) = x; break ; } case DFNT_UINT16 : { uint16 x = static_cast((uint16 )USHRT_MAX); uint16 **y; y = (uint16**)&fill_value; (**y) = x; break ; } case DFNT_INT32 : { int32 x = static_cast((int32 )LONG_MIN); int32 **y; y = (int32**)&fill_value; (**y) = x; break ; } case DFNT_UINT32 : { uint32 x = static_cast((uint32 )ULONG_MAX); uint32 **y; y = (uint32**)&fill_value; (**y) = x; break ; } case DFNT_FLOAT32 : { float32 x = static_cast((float32)-DBL_MAX); float32 **y; y = (float32**)&fill_value; (**y) = x; break ; } case DFNT_FLOAT64 : { float64 x = static_cast((float64)-LDBL_MAX); float64 **y; y = (float64**)&fill_value; (**y) = x; break ; } default : { stringstream msg ; msg << "The type : "; msg << code_type; msg << " is unknown."; cout<<"file("<<__FILE__<<") line("<<__LINE__<<") "<get_data_file_format()->get_data_format()->size()+2; }; string PolderParasolFileData::get_dataset_name(int i) { if(i<2){ if(i==0) return Latitude; else return Longitude; }else{ return data->get_data_file_format()->get_data_format()->at(i-2).name; } }; int PolderParasolFileData::get_dataset_idtype(string name) { int n = get_n_dataset(); int i=0; for(i=0; iget_data_file_format()->get_data_format()->at(data->get_data_entry_index(sds_name)).type; int format; switch(code_type) { case CHAR8 : { format = DFNT_CHAR8; break ; } case UCHAR8 : { format = DFNT_UCHAR8; break ; } case INT8 : { format = DFNT_INT8; break ; } case UINT8 : { format = DFNT_UINT8; break ; } case INT16 : { format = DFNT_INT16; break ; } case UINT16 : { format = DFNT_UINT16; break ; } case INT32 : { format = DFNT_INT32; break ; } case UINT32 : { format = DFNT_UINT32; break ; } case FLOAT12_4 : { // should be a float64 format = DFNT_FLOAT32; break ; } case EXP12_5 : { // should be a float64 format = DFNT_FLOAT32; break ; } default : { stringstream msg ; msg << "The type : "; msg << code_type; msg << " is unknown."; cout<<"file("<<__FILE__<<") line("<<__LINE__<<") "< dim = get_dataset_dimension(sds_name); if(rank==-1) rank = dim.size(); int osize =1; short l,c; for(uint i =0; i(malloc(sizeof(float32)*osize)); float32 fillvalue; getFillValues(fillvalue); get_dataset_fill_value(sds_name,&fillvalue); for(int i=0; i=start[0] && c=start[1] && lgetLatLon(line[i],col[i],&lat,&lon); // *** remplac� par this->getLatLon1(line[i],col[i],&lat,&lon); // *** Fin modif (*oval)[c * dim[1] + l] = lon; } } }else{ for(int i=0; i=start[0] && c=start[1] && lgetLatLon(line[i],col[i],&lat,&lon); // *** remplac� par this->getLatLon1(line[i],col[i],&lat,&lon); // *** Fin modif (*oval)[c * dim[1] + l] = lon; } } } } free(line); free(col); } else if(sds_name==Latitude) { short *col= NULL; ExtractVariable_Grid(fileid, &col, &size, COLUMN); short *line= NULL; ExtractVariable_Grid(fileid, &line, &size, LINE); float32 **oval = NULL; oval = (float32**)&data; float lat; float lon; if(stride_bool){ for(int i=0; i=start[0] && c=start[1] && lgetLatLon(line[i],col[i],&lat,&lon); // *** remplac� par this->getLatLon1(line[i],col[i],&lat,&lon); // *** Fin modif (*oval)[c * dim[1] + l] = lat; } } }else{ for(int i=0; i=start[0] && c=start[1] && lgetLatLon(line[i],col[i],&lat,&lon); // *** remplac� par this->getLatLon1(line[i],col[i],&lat,&lon); // *** Fin modif (*oval)[c * dim[1] + l] = lat; } } } } free(line); free(col); } // free the ressources allocated by this method free_read_write_allocations(are_limits_initialized, start, stride, edges); return data; } void PolderParasolFileData::get_fillValue(const string &sds_name, void *fillValue) { this->get_dataset_fill_value(sds_name, fillValue); }