/* filetypes.cpp */ /* remap Copyright (C) 2006 Fabrice Ducos, fabrice.ducos@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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include /* fnmatch (pattern matching) */ #include "common.h" #include "filetypes.h" static char *patterns[] = { "", "MOD021??.A???????.????.???.?????????????*.hdf", /* MOD021KM: MODIS TERRA */ "MYD021??.A???????.????.???.?????????????*.hdf", /* MYD021KM: MODIS AQUA */ "MOD03.A???????.????.???.?????????????.hdf", /* MOD03: MODIS TERRA geolocation data */ "MYD03.A???????.????.???.?????????????.hdf", /* MYD03: MODIS AQUA geolocation data */ "CAL_IIR_L1-*.hdf", /* IIR/CALIPSO */ "SEVIRI_OVER_*.hdf", /* HDF SEVIRI (from Icare) */ "H-000-MSG1__-MSG1________-?????????-CYCLE____-????????????", /* XRIT SEVIRI */ //"P3L2T???[0-9][0-9][0-9][0-9][0-9][0-9][A-Z]D", /* PARASOL */ // does not currently work with the current implementation of print_supported_files() "P3L2T??????????D", /* PARASOL */ NULL }; using namespace std; static size_t npatterns = sizeof(patterns)/sizeof(*patterns) - 1; /* converts a filetype code into a cstr (for debugging purposes) */ char *filetype_to_cstr(filetype_type filetype) { static char cstr_filetype[STRING_MAXLEN]; switch (filetype) { case FILETYPE_EQUIRECT: strcpy(cstr_filetype, "Equirectangular projection, user defined input"); break; case FILETYPE_MOD021KM: strcpy(cstr_filetype, "Modis Terra 1km radiance product"); break; case FILETYPE_MYD021KM: strcpy(cstr_filetype, "Modis Aqua 1km radiance product"); break; case FILETYPE_MOD03: strcpy(cstr_filetype, "Modis Terra geolocation data"); break; case FILETYPE_MYD03: strcpy(cstr_filetype, "Modis Aqua geolocation data"); break; case FILETYPE_CAL_IIR_L1: strcpy(cstr_filetype, "IIR Calipso Level1"); break; case FILETYPE_HDF_SEVIRI: strcpy(cstr_filetype, "Icare Seviri Mosaic, hdf"); break; case FILETYPE_XRIT_SEVIRI: strcpy(cstr_filetype, "Seviri XRIT format"); break; case FILETYPE_PARASOL: strcpy(cstr_filetype, "Parasol"); break; default : strcpy(cstr_filetype, "Unknown"); break; } // switch return cstr_filetype; } filetype_type get_filetype(const char *filename) { unsigned int ipattern; char filename_[STRING_MAXLEN]; /* basename may modify its argument so we work on a copy of it */ strcpy(filename_, filename); for (ipattern = 0 ; ipattern < npatterns ; ipattern++) { char *pattern = patterns[ipattern]; if (pattern && fnmatch(pattern, basename(filename_), 0) == 0) { filetype_type filetype = static_cast(ipattern); return filetype; } } return FILETYPE_UNKNOWN; } void print_supported_filetypes() { cout << "Supported input types include: " << endl; for (unsigned int ipattern = 0 ; ipattern < npatterns ; ipattern++) { const char *pattern = patterns[ipattern]; filetype_type pattern_type = get_filetype(pattern); // FIXME: 'pattern' is not exactly a filename: for instance [0-9] does not count for ONE character const char *cstr_pattern_type = filetype_to_cstr(pattern_type); if (pattern_type == FILETYPE_EQUIRECT) { cout << " " << cstr_pattern_type << endl; } else { cout << " " << pattern << " (" << cstr_pattern_type << ")" << endl; } } }