00001 /*-------------------------------------------------------------------------- 00002 $Id: apisamp.c,v 1.8 2007/12/18 14:40:13 fuxi Exp $ 00003 ---------------------------------------------------------------------------- 00004 00005 BUFR encoding and decoding software and library 00006 Copyright (c) 2007, Institute of Broadband Communication, TU-Graz 00007 on behalf of EUMETNET OPERA, http://www.knmi.nl/opera 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; version 2.1 00012 of the License. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 ---------------------------------------------------------------------------- 00024 00025 $Log: apisamp.c,v $ 00026 Revision 1.8 2007/12/18 14:40:13 fuxi 00027 added licence header 00028 00029 Revision 1.7 2007/12/10 11:22:23 fuxi 00030 removed depricated functions 00031 00032 Revision 1.6 2007/12/07 08:39:46 fuxi 00033 update to version 3.0 00034 00035 Revision 1.5 2005/06/01 09:49:23 helmutp 00036 update to version 2.3 00037 00038 Revision 1.4 2003/09/03 15:47:08 helmutp 00039 more compiler warnings 00040 00041 Revision 1.3 2003/09/03 15:42:59 helmutp 00042 fixed originating center and compiler warnings 00043 00044 Revision 1.2 2003/06/06 12:32:10 helmutp 00045 read_tables changed 00046 00047 Revision 1.1 2003/02/28 13:41:12 helmutp 00048 Initial revision 00049 00050 --------------------------------------------------------------------------- */ 00051 00052 00053 #include <stdlib.h> 00054 #include <stdio.h> 00055 #include <time.h> 00056 #include <string.h> 00057 #include "bufrlib.h" 00058 00059 /*===========================================================================*/ 00060 /* internal functions */ 00061 /*===========================================================================*/ 00062 00063 /*===========================================================================*/ 00064 int main () 00065 00066 { 00067 bufr_t msg; /* Our encoded BUFR message */ 00068 00069 dd descr[10]; /* This array must be large enough to hold all 00070 required descriptors */ 00071 varfl v[10]; /* This array must be huge enough to hold all 00072 corresponding data values */ 00073 sect_1_t s1; /* Here we store section 1 of BUFR message */ 00074 00075 /* Initialize basic data */ 00076 00077 memset (&msg, 0, sizeof(bufr_t)); 00078 00079 /* read supported data descriptors */ 00080 /* parameters are the table-directory 00081 (NULL to search in current dirctory), 00082 version of mtab, version of ltab, orcenter */ 00083 00084 if (read_tables(NULL, 11, 4, 255, 255) < 0) { 00085 fprintf (stderr, "Error reading tables.\n"); 00086 exit (EXIT_FAILURE); 00087 } 00088 00089 /* Prepare the data we want to encode 00090 00091 This represents the following information: 00092 00093 0 1 1 6.00000 0 1 1 WMO block number 00094 0 1 2 260.00000 0 1 2 WMO station number 00095 0 2 1 1.00000 0 2 1 Type of station 00096 00097 */ 00098 descr[0].f = 0; descr[0].x = 1; descr[0].y = 1; v[0] = 6; 00099 descr[1].f = 0; descr[1].x = 1; descr[1].y = 2; v[1] = 260; 00100 descr[2].f = 0; descr[2].x = 2; descr[2].y = 1; v[2] = 1; 00101 00102 /* Code the data (section 3 and 4) */ 00103 00104 if (!bufr_encode_sections34 (descr, 3, v, &msg)) { 00105 fprintf (stderr, "Error creating bufr message.\n"); 00106 exit (EXIT_FAILURE); 00107 } 00108 00109 /* Prepare data for Section 1 */ 00110 00111 s1.year = 2003; 00112 s1.mon = 1; 00113 s1.day = 17; 00114 s1.hour = 18; 00115 s1.min = 29; 00116 s1.mtab = 0; /* master table used */ 00117 s1.subcent = 255; /* originating subcenter */ 00118 s1.gencent = 255; /* originating center */ 00119 s1.updsequ = 0; /* original BUFR message */ 00120 s1.opsec = 1; /* no optional section */ 00121 s1.dcat = 6; /* message type */ 00122 s1.dcatst = 0; /* message subtype */ 00123 s1.vmtab = 11; /* version number of master table used */ 00124 s1.vltab = 4; /* version number of local table used */ 00125 00126 /* Setup section 0, 1, 2, 5 */ 00127 00128 if (!bufr_encode_sections0125 (&s1, &msg)) { 00129 fprintf (stderr, "Unable to create section 0, 1, 2 and/or 5\n"); 00130 exit (EXIT_FAILURE); 00131 } 00132 00133 /* Save coded data */ 00134 00135 if (!bufr_write_file (&msg, "output.buf")) { 00136 fprintf (stderr, "Error saving sections to file.\n"); 00137 exit (EXIT_FAILURE); 00138 } 00139 00140 exit (EXIT_SUCCESS); 00141 } 00142 00143 00144 /* end of file */ 00145 00146
1.5.4