/* fis2raw.c */ /* Copyright (C) 2006 Icare - http://www.icare.univ-lille1.fr Fabrice Ducos, fabrice.ducos@icare.univ-lille1.fr This program is a free software; you can redistribute it and/or modify it under the terms of the CeCILL Public License as published by www.cecill.info (License version 2 or later). 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 CeCILL Public License for more details. You should have received a copy of the CeCILL Public License along with this program; if not, please contact www.cecill.info If you have any questions or concerns regarding this program, please email to problem@icare.univ-lille1.fr For general information about the ICARE Project, please email to icare-contact@univ-lille.fr */ #include #include #include #include #include #include "read_fis.h" void usage() { fprintf(stderr, "usage: fis2raw [-v] \n\n"); fprintf(stderr, "converts a FIS file (FORMAT IMAGE STANDARD, .fis extension) into a .raw file\n"); fprintf(stderr, "The FIS format is one of the numerous formats in which MSG (METEOSAT SECOND GENERATION) data\n"); fprintf(stderr, "are provided. In order to let the user read easily the content of such files without bothering with a\n"); fprintf(stderr, "new format, fis2raw converts it into a simple raw file (a simple binary array of values with no header).\n\n"); fprintf(stderr, "The option -v makes fis2raw display the number of values in the output raw file and the size in bytes of\n"); fprintf(stderr, "each value (unfortunately, at the author's knowledge the FIS format does not provide information about\n"); fprintf(stderr, "the signed or unsigned nature of the values, so fis2raw cannot do miracles and you will have to figure it out yourself)\n"); } int main(int argc, char *argv[]) { int ret; char *ifilename; char ilongname[FILENAME_MAX]; char *ibasename; char ofilename[FILENAME_MAX]; FILE *ostream; size_t npix, pix_size; size_t nwritten; void *counts; char *ptr_dot_fis; int index_dot_raw; int verbose_mode = 0; if (argc !=2 && argc != 3) { usage(); return EXIT_FAILURE; } if (argc == 2) { ifilename = argv[1]; } else { assert(argc == 3); if (strcmp(argv[1], "-v") == 0) { verbose_mode = 1; } else { usage(); return EXIT_FAILURE; } ifilename = argv[2]; } strncpy(ilongname, ifilename, sizeof(ofilename) - 1); ibasename = basename(ilongname); ptr_dot_fis = strstr(ibasename, ".fis"); if (ptr_dot_fis == NULL) { fprintf(stderr, "fis2raw: %s: expects a file with extension .fis\n", ifilename); return -1; } assert(ptr_dot_fis[4] == '\0'); /* will fail if .fis is not the last extension */ index_dot_raw = ptr_dot_fis - ibasename; assert(0 <= index_dot_raw && index_dot_raw < sizeof(ofilename)); strncpy(ofilename, ibasename, sizeof(ofilename) - 1); strcpy(&ofilename[index_dot_raw], ".raw"); #ifdef DEBUG printf("ofilename %s\n", ofilename); #endif ostream = fopen(ofilename, "w"); assert(ostream != NULL); ret = read_fis(ifilename, &counts, &npix, &pix_size, 1); if (verbose_mode) { printf("fis2raw: %s: %d values of %d bytes\n", ofilename, npix, pix_size); } nwritten = fwrite(counts, pix_size, npix, ostream); if (nwritten != npix) { perror(ifilename); return EXIT_FAILURE; } assert(nwritten == npix); free(counts); if (fclose(ostream)) { perror(ofilename); return EXIT_FAILURE; } return ret; }