decbufr.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002 
00003     BUFR encoding and decoding software and library
00004     Copyright (c) 2007,  Institute of Broadband Communication, TU-Graz
00005     on behalf of EUMETNET OPERA, http://www.knmi.nl/opera
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; version 2.1 
00010     of the License.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
00020 
00021 ----------------------------------------------------------------------------
00022 
00023 FILE:          DECBUFR.C
00024 IDENT:         $Id: decbufr.c,v 1.12 2007/12/18 14:40:13 fuxi Exp $
00025 
00026 AUTHORS:       Juergen Fuchsberger, Helmut Paulitsch, Konrad Koeck
00027                Institute of Communication and Wave Propagation, 
00028                Technical University Graz, Austria
00029 
00030 VERSION NUMBER:3.0
00031 
00032 DATE CREATED:  18-DEC-2001
00033 
00034 STATUS:        DEVELOPMENT FINISHED
00035 
00036 AMENDMENT RECORD:
00037 
00038 $Log: decbufr.c,v $
00039 Revision 1.12  2007/12/18 14:40:13  fuxi
00040 added licence header
00041 
00042 Revision 1.11  2007/12/07 08:17:14  fuxi
00043 update to version 3.0
00044 
00045 Revision 1.10  2005/06/01 09:47:06  helmutp
00046 update version
00047 
00048 Revision 1.9  2005/04/04 15:43:06  helmutp
00049 update to version 2.3
00050 use subcenter and generating center
00051 
00052 Revision 1.8  2003/06/11 09:13:26  helmutp
00053 added version string
00054 
00055 Revision 1.7  2003/06/06 11:57:26  helmutp
00056 support for descriptor tables with different versions
00057 
00058 Revision 1.6  2003/03/27 17:17:39  helmutp
00059 update to version 2.2
00060 
00061 Revision 1.5  2003/03/24 15:42:44  kon
00062 Added support of multiple CAPPIs
00063 
00064 Revision 1.4  2003/03/13 17:22:45  helmutp
00065 allow tables to be specified on command line
00066 
00067 Revision 1.3  2003/03/11 10:30:42  helmutp
00068 fixed memory leaks
00069 
00070 Revision 1.2  2003/03/06 17:12:32  helmutp
00071 update to version 2.1
00072 
00073 Revision 1.1  2003/02/28 13:41:12  helmutp
00074 Initial revision
00075 
00076 --------------------------------------------------------------------------- */
00077 
00088 #include <stdlib.h>
00089 #include <stdio.h>
00090 #include <string.h>
00091 #include "bufrlib.h"
00092 #include "bufr_io.h"
00093 
00094 extern int _opera_mode;
00095 
00096 /*===========================================================================*/
00097 /* internal functions                                                        */
00098 /*===========================================================================*/
00099 
00100 #define RIOUTFILE  "img.dec"    /* Name of file for uncompressed radar image */
00101 
00102 char *usage = "usage: decbufr [-v] [-d tabdir] input_file output_file [image_file]\n";
00103 char *version = "decbufr V3.0, 5-Dec-2007\n";
00104 
00105 /*===========================================================================*/
00106 int main (int argc, char** argv)
00107 
00108 {
00109     char destfile[200], buffile[200];
00110     char *table_dir = NULL;
00111     char imgfile[200];  /* filename of uncompressed image */
00112     sect_1_t s1;
00113     bufr_t bufr_msg;    /* structure holding encoded bufr message */
00114 
00115     /* initialize variables */
00116 
00117     memset (&bufr_msg, 0, sizeof (bufr_t));
00118     memset (&s1, 0, sizeof (sect_1_t));
00119 
00120     /* check command line parameter */
00121 
00122     while (argc > 1 && *argv[1] == '-')
00123     {
00124         if (*(argv[1] + 1) == 'v')
00125             fprintf (stderr, "%s", version);
00126         else if (*(argv[1] + 1) == 'd')
00127         {
00128             if (argc < 2)
00129             {
00130                 fprintf (stderr, "Missing parameter for -d\n\n%s", usage);
00131                 exit (EXIT_FAILURE);
00132             }
00133             table_dir = argv[2];
00134             argc--;
00135             argv++;
00136         }
00137         else
00138         {
00139             fprintf (stderr, "Invalid parameter %s\n\n%s", argv[1], usage);
00140             exit (EXIT_FAILURE);
00141         }
00142         argc--;
00143         argv++;
00144     }
00145 
00146     /* Get input- and output-filenames from the command-line */
00147 
00148     if (argc < 3)
00149     {
00150         fprintf (stderr, "%s", usage);
00151         exit (EXIT_FAILURE);
00152     }
00153     strcpy (buffile, argv[1]);
00154     strcpy (destfile, argv[2]);
00155 
00156     if (argc > 3) 
00157         strcpy (imgfile, argv[3]);
00158     else 
00159         strcpy (imgfile, RIOUTFILE);
00160 
00161     /* read source-file. Therefore allocate memory to hold the complete
00162        BUFR-message */
00163 
00164     if (!bufr_read_file (&bufr_msg, buffile)) {
00165         bufr_free_data (&bufr_msg);
00166         exit (EXIT_FAILURE);
00167     }
00168 
00169     /* decode section 1 */
00170 
00171     if (!bufr_decode_sections01 (&s1, &bufr_msg)) {
00172         bufr_free_data (&bufr_msg);
00173         exit (EXIT_FAILURE);
00174     }
00175 
00176     /* check for opera bufr file */
00177 
00178     if (s1.gencent == 255 || s1.subcent == 255) {
00179         _opera_mode = 1;
00180     } else {
00181         _opera_mode = 0;
00182     }
00183 
00184     /* Write section 1 to ASCII file */
00185 
00186     if (!bufr_sect_1_to_file (&s1, "section.1.out")) {
00187         bufr_free_data (&bufr_msg);
00188         exit (EXIT_FAILURE);
00189     }
00190 
00191 
00192     /* read descriptor tables */
00193 
00194     if (read_tables (table_dir, s1.vmtab, s1.vltab, s1.subcent, 
00195                      s1.gencent) < 0) {
00196         bufr_free_data (&bufr_msg);
00197         free_descs();
00198         exit (EXIT_FAILURE);
00199     }
00200 
00201     /* decode data descriptor- and data-section now */
00202 
00203     if (!bufr_data_to_file (destfile, imgfile, &bufr_msg)) {
00204         fprintf (stderr, "unable to decode BUFR-message !\n");
00205         bufr_free_data (&bufr_msg);
00206         free_descs();
00207         exit (EXIT_FAILURE);
00208     }
00209 
00210 #ifdef VERBOSE
00211     {
00212         int i;
00213         for (i = 0; i < 6; i++) {
00214             fprintf (stderr, "section %d length = %d\n", i, bufr_msg.secl[i]);
00215         }
00216     }
00217 #endif
00218 
00219     bufr_free_data (&bufr_msg);
00220     free_descs();
00221     exit (EXIT_SUCCESS);
00222 }
00223 
00224 /* end of file */

Generated on Tue Dec 18 16:52:45 2007 for OPERA BUFR software by  doxygen 1.5.4