/*************************************************************************** * 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 "gmaofiledata.h" const string GMAOFileData::latitude_name="YDim"; const string GMAOFileData::longitude_name="XDim"; const string GMAOFileData::time_name="Time"; const string GMAOFileData::height_name="Height"; // unused for 2D products GMAOFileData::GMAOFileData(const string& name, const int geos_version): FileData(name,"r"),MeteoFileData(name,"r"),HDFFileData(name,"r",false) { // init attributes product_id=""; // if not specified, try to guess the GEOS version of the files, else set it with the version given set_geos_version(geos_version); // validate the filename and if valid, extracts informations from it parse_filename(this->name); // initialize the attributes specific to a product init(); } void GMAOFileData::init( ) { assert(geos_version==4 || geos_version==5); /********** GMAO GEOS-5xx **********/ if (geos_version==5) { // set the time coverage of one file char c_prod_id_end=*product_id.rbegin(); // the last character of the product ID if (c_prod_id_end=='x') { // met_x products // the met_x products are the only one that have 5 time levels, and so 8 files per day nb_time_level=8; delta_time=10800.; // = nb_seconds_per_day/nb_time_level; time_coverage=10800.; // time covered by one file } else { // all other products have 4 time levels nb_time_level=4; delta_time=21600.; // = nb_seconds_per_day/nb_time_level; time_coverage=21600.; // time covered by one file } // set the grid characteristics : the (lat,lon) grid is common for all products, but for 3D products, the number of height levels can vary with the product delta_lat=0.5; delta_lon=2./3.; lat_lon_index_max[0]=360; lat_lon_index_max[1]=539; // height grid depends of the product. Keep it null for 2D products if (c_prod_id_end=='v') // prs_v, dyn_v, cld_v, mst_v, tmp_v, wnd_v products nb_height_level=72; else if (c_prod_id_end=='e') // met_e products nb_height_level=73; else if (c_prod_id_end=='p') // met_p products nb_height_level=36; } /********** GMAO GEOS-4xx **********/ else if (geos_version==4) { // the last character of the product ID. It permits to identify groups of products having the same characteristics char c_prod_id_end=*product_id.rbegin(); // set the time coverage of one file time_coverage=86400.; // the number of seconds for one day // set the grid characteristics, which is different between ozone products the other ones if (product_id!="tsyn2d_chm_x" && product_id!="tsyn3d_chm_p") { // for non ozone products delta_lat=1.; delta_lon=1.25; lat_lon_index_max[0]=180; lat_lon_index_max[1]=287; } else { delta_lat=2.; delta_lon=2.5; lat_lon_index_max[0]=90; lat_lon_index_max[1]=144; } // height grid depends of the product. Keep it null for 2D products if (c_prod_id_end=='p') // profiles products. Only chm_p has an uncommon resolution product_id=="tsyn3d_chm_p"?nb_height_level=42:nb_height_level=36; // set the time resolution : different for 2D (ie product_id ending with 'x') and 3D ones (ending with 'p') if (c_prod_id_end=='x') { // 8 measure per day for 2D products nb_time_level=8; delta_time=10800.; // = time_coverage/nb_time_level; } else if (c_prod_id_end=='p') { // 4 measure per day for 3D products nb_time_level=4; delta_time=21600.; // = time_coverage/nb_time_level; } } // load profiles dimensions load_hdf_file(); load_height_level(); load_time_level(); free_hdf_file(); } GMAOFileData::~GMAOFileData( ) { } bool GMAOFileData::check_filename( const string& filename ) const { string fname=get_tail(filename); // the filename without its directory // check product provider int pos = fname.find_first_of(".",0); if (geos_version==4 && fname.substr(0,pos)!="DAS") { invalid_filename e(__FILE__,__LINE__,filename,"GMAO"); throw e; } else if (geos_version==5 && fname.substr(0,pos)!="D5CALIP1" && fname.substr(0,pos)!="D5CALIP2") { invalid_filename e(__FILE__,__LINE__,filename,"GMAO"); throw e; } // check config pos+=1; string config=fname.substr(pos,3); if (geos_version==4 && config!="llk" && config!="flk") { invalid_filename e(__FILE__,__LINE__,filename,"GMAO"); throw e; } else if (geos_version==5 && config!="ops") { invalid_filename e(__FILE__,__LINE__,filename,"GMAO"); throw e; } // check mode pos+=4; if (fname.substr(pos,3)!="asm") { invalid_filename e(__FILE__,__LINE__,filename,"GMAO"); throw e; } // check filetype pos+=4; string s_product=fname.substr(pos,12); if ( geos_version==4 && s_product!="tsyn2d_mis_x" && s_product!="tsyn3d_mis_p" && s_product!="tavg2d_eng_x" && s_product!="tavg2d_str_x" && s_product!="tavg2d_lsm_x" && s_product!="tavg2d_cld_x" && s_product!="tavg3d_cld_p" && s_product!="tavg3d_mom_p" && s_product!="tavg3d_mst_p" && s_product!="tavg3d_tmp_p" && s_product!="tavg3d_trp_p" && s_product!="tsyn2d_chm_x" && s_product!="tsyn3d_chm_p") { invalid_filename e(__FILE__,__LINE__,filename,"GMAO"); throw e; } else if ( geos_version==5 && s_product!="inst2d_met_x" && s_product!="inst3d_met_p" && s_product!="tavg2d_met_x" && s_product!="tavg3d_prs_v" && s_product!="tavg3d_dyn_v" && s_product!="tavg3d_cld_v" && s_product!="tavg3d_met_e" && s_product!="tavg3d_mst_v" && s_product!="tavg3d_tmp_v" && s_product!="tavg3d_wnd_v") { invalid_filename e(__FILE__,__LINE__,filename,"GMAO"); throw e; } // check expid pos+=13; string expid=fname.substr(pos,5); if (geos_version==4 && expid.substr(0,5)!="GEOS4") { invalid_filename e(__FILE__,__LINE__,filename,"GMAO"); throw e; } else if (geos_version==5 && expid.substr(0,5)!="GEOS5") { invalid_filename e(__FILE__,__LINE__,filename,"GMAO"); throw e; } // check extension pos+=13; string ext=fname.substr(fname.size()-3,3); if (geos_version==4 && ext[0]!='V') { invalid_filename e(__FILE__,__LINE__,filename,"GMAO"); throw e; } else if (geos_version==5 && ext!="hdf") { invalid_filename e(__FILE__,__LINE__,filename,"GMAO"); throw e; } return true; } void GMAOFileData::parse_filename( const string& filename ) { assert(geos_version==4 || geos_version==5); check_filename(filename); // validate filename string fname=get_tail(filename); // the filename without its directory // Read the product ID if (geos_version==5) product_id=fname.substr(fname.size()-42,12); else if (geos_version==4) product_id=fname.substr(fname.size()-46,12); // extract the date string s_date(""); if (geos_version==5) { s_date=fname.substr(fname.size()-21,13)+"00"; date->set_date_str(s_date.c_str(),"%Y%m%d_%H%M%S"); } else if (geos_version==4) { s_date=fname.substr(fname.size()-25,10)+"0000"; date->set_date_str(s_date.c_str(),"%Y%m%d%H%M%S"); } } void GMAOFileData::get_sds_fill_value( const string & sds_name, void * fill_value ) { get_hdf_file()->get_sds_attr(sds_name.c_str(),"missing_value",fill_value); } void GMAOFileData::load_height_level( ) { if (nb_height_level>0) { // only profiles products have a height dimension height_level=new float64[nb_height_level]; read_data(height_level,height_name.c_str()); } } void GMAOFileData::load_time_level( ) { if (nb_time_level>0) { time_level=new float64[nb_time_level]; read_data(time_level,time_name.c_str()); } } void GMAOFileData::set_geos_version( const int geos_version ) { if (geos_version!=0) this->geos_version=geos_version; // guess the GEOS version using the filename else if (name.find("GEOS4")!=string::npos) this->geos_version=4; else if (name.find("GEOS5")!=string::npos) this->geos_version=5; else { // doesn't seem to be a valid GEOS version invalid_filename e(__FILE__,__LINE__,name,"GMAO"); throw e; } }