/*************************************************************************** * 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 "meteofiledata.h" MeteoFileData::MeteoFileData(const std::string &name, const std::string &mode): FileData(name,mode) { time_coverage=-1.; delta_time=-1.; delta_lat=-1.; delta_lon=-1.; nb_height_level=0; height_level=NULL; nb_time_level=0; time_level=NULL; } const int MeteoFileData::get_lat_index( const float & lat ) const { assert(delta_lat!=-1.); if ( lat<-90. || lat>90. ) return -1; return static_cast(round((lat+90.)/delta_lat)); } const int MeteoFileData::get_lon_index( const float & lon ) const { assert(delta_lon!=-1.); if (lon<-180. || lon>180.) return -1; if (lon>=(180.-(delta_lon/2.))) // manage the extreme case : last and first cell are the same return 0; return static_cast(round((lon+180.)/delta_lon)); } const int MeteoFileData::get_time_index( const double & time ) const { assert(delta_time!=-1.); assert(delta_time!=0.); double time_min=date->get_TAI93_time(); double time_max=time_min+time_coverage; if ( timetime_max ) // the searched date doesn't fit with the meteo file one return -1; else { int idx = (int)round((time-time_min)/delta_time); if (idx == nb_time_level) // time_max-(delta_time/2) < time <= time_max --idx; return idx; } } double MeteoFileData::get_time_min( ) const { return date->get_TAI93_time(); } double MeteoFileData::get_time_max( ) const { return date->get_TAI93_time()+time_coverage; } const unsigned short MeteoFileData::get_nb_height_level( ) { return nb_height_level; } const double* MeteoFileData::get_height_level( ) { return height_level; // will be NULL for 2D products } const bool MeteoFileData::is_height_level_loaded( ) const { return (height_level!=NULL); } void MeteoFileData::free_height_level( ) { delete[] height_level; height_level=NULL; } const unsigned short MeteoFileData::get_nb_time_level( ) { return nb_time_level; } const double* MeteoFileData::get_time_level( ) { return time_level; } const bool MeteoFileData::is_time_level_loaded( ) const { return (time_level!=NULL); } void MeteoFileData::free_time_level( ) { delete[] time_level; time_level=NULL; } MeteoFileData::~MeteoFileData( ) { free_height_level(); free_time_level(); } const bool MeteoFileData::get_index( const float & lat, const float & lon, int * index ) const { if (index==NULL) return false; index[0]=get_lat_index(lat); index[1]=get_lon_index(lon); return true; } const bool MeteoFileData::get_index( const float & lat, const float & lon, const double & time, int * index ) { if (index==NULL) return false; index[0]=get_lat_index(lat); index[1]=get_lon_index(lon); load_time_level(); if (time_level==NULL) index[1]=-1; else index[1]=get_time_index(time); return true; }