/*************************************************************************** * Copyright (C) 2005 by Nicolas PASCAL * * nicolas.pascal@icare.univ-lille1.fr * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the *--------------- * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "omifiledata.h" const string OMIFileData::latitude_sds_name="Latitude"; const string OMIFileData::longitude_sds_name="Longitude"; const string OMIFileData::time_sds_name="Time"; const float OMIFileData::colocation_tolerance=0.05; OMIFileData::OMIFileData(const string &name,const string & mode): FileData(name,mode),SatelliteFileData(name,mode),HDF5FileData(name,mode) { init(); } void OMIFileData::init() { lat_data=NULL; lon_data=NULL; time_data=NULL; // extract the acquisition date from the file name string short_filename = get_tail(get_name()); parse_filename(short_filename); HDF5FileData::open_data_file(); vector v; lat_lon_index_max =this->get_dataset_dimension(latitude_sds_name); track_size=1; for(uint i=0; i(0)); float lat_max=lat+coloc_tolerance; // biggest latitude acceptable float lon_max=lon+coloc_tolerance; // biggest longitude acceptable PixelType pix_max(&lat_max,&lon_max,vector(0)); // set the range of colocated points candidates I_Pixel i_pix_min=lower_bound(v_pixel.begin(),v_pixel.end(),pix_min); I_Pixel i_pix_max=upper_bound(v_pixel.begin(),v_pixel.end(),pix_max); // cout<<"Pix Min ["<get_val()[0]<<","<get_val()[1]<<"]"<get_val()[0]<<","<get_val()[1]<<"]"<get_lat()-lat); delta_lon=abs(i_pix->get_lon()-lon); if (delta_latget_lat()<<","<get_lon()<<") ["<get_val()[0]<<","<get_val()[1]<<"]"<get_val()[0]; _nearest_pix_idx[1]=i_pix->get_val()[1]; } } } if (!data_already_loaded) free_geolocation_data(); nearest_pix_idx[0]=_nearest_pix_idx[0]; nearest_pix_idx[1]=_nearest_pix_idx[1]; return (nearest_pix_idx[0]!=-1 && nearest_pix_idx[1]!=-1); } void OMIFileData::load_geolocation_data() { if (!is_geolocation_data_loaded()) { // read lat, lon data if (lat_data==NULL) lat_data=static_cast(read_data(static_cast(lat_data),latitude_sds_name.c_str(),NULL,NULL,NULL)); if (lon_data==NULL) lon_data=static_cast(read_data(static_cast(lon_data),longitude_sds_name.c_str(),NULL,NULL,NULL)); if (time_data==NULL) time_data=static_cast(read_data(static_cast(time_data),time_sds_name.c_str(),NULL,NULL,NULL)); // build the sorted pixels list load_v_pixel(); } } void OMIFileData::load_v_pixel() { vector sds_index(2); // indexes [y,x] of a pixel in a MODIS SDS int y_max=lat_lon_index_max[0],x_max=lat_lon_index_max[1]; int buffer_idx=0; // linear index to access 2D lat/lon data arrays for (int y_idx=0;y_idx