bufr2synop 0.24.0
bufrnoaa_io.c
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2013-2022 by Guillermo Ballester Valor *
3 * gbv@ogimet.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20/*!
21 \file bufrnoaa_io.c
22 \brief File with I/O code for bufrnoaa binary
23*/
24#ifndef CONFIG_H
25# include "config.h"
26# define CONFIG_H
27#endif
28
29#include "bufrnoaa.h"
30
31void print_usage ( void )
32{
34 printf ( "Usage: \n" );
35 printf ( "\n%s -i input_file [-h][-v][-f][-l][-F prefix][-T T2_selection][-O selo][-S sels][-U selu]\n" , OWN);
36 printf ( " -h Print this help\n" );
37 printf ( " -v Print information about build and version\n" );
38 printf ( " -i Input file. Complete input path file for NOAA *.bin bufr archive file\n" );
39 printf ( " -2 Input file is formatted in alternative form: Headers has '#' instead of '*' marks and no sep after '7777'\n");
40 printf ( " -l list the names of reports in input file\n" );
41 printf ( " -f Extract selected reports and write them in files, one per bufr message, as \n" );
42 printf ( " example '20110601213442_ISIE06_SBBR_012100_RRB.bufr'. First field in name is input file timestamp \n" );
43 printf ( " Other fields are from header\n" );
44 printf ( " -F prefix. Builds an archive file with the same format as NOAA one but just with selected messages\n" );
45 printf ( " witgh option -T. Resulting name is 'prefix_input_filename'\n" );
46 printf ( " If no -F option no archive bin file is created.\n" );
47 printf ( " If no message is selected, the a void file is created.\n" );
48 printf ( " File timestamp is the same than input file\n" );
49 printf ( " -T T2_selection. A string with selection. A character per type (T2 code)\n" );
50 printf ( " 'S' = Surface . 'O'= Oceanographic. 'U'= upper air\n" );
51 printf ( " If no -T argument then nothing is selected\n" );
52 printf ( " -S sels. String with selection for A1 when T2='S'\n" );
53 printf ( " By default all A1 are selected\n" );
54 printf ( " -O selo. String with selection for A1 when T2='O'\n" );
55 printf ( " By default all A1 are selected\n" );
56 printf ( " -U sels. String with selection for A1 when T2='U'\n" );
57 printf ( " By default all A1 are selected\n" );
58}
59
60/*!
61 \fn char *bufrnoaa_get_version(char *version, char *build, char *builder, int *version_major, int *version_minor, int *version_patch)
62 \brief Get strings with version information and build date and time
63 \param version pointer to string with version as result if not NULL
64 \param build pointer to string with compiler and compilation date and time if not NULL
65 \param builder pointer to string with builder utility. 'cmake' or 'autotools' if not NULL
66 \param version_major pointer to string with version_major component if not NULL
67 \param version_minor pointer to string with version_minor component if not NULL
68 \param version_patch pointer to string with version_patch component if not NULL
69
70 Retuns string pointer \a version.
71 */
72char *bufrnoaa_get_version(char *version, char *build, char *builder, int *version_major, int *version_minor, int *version_patch)
73{
74 int major = 0, minor = 0, patch = 0;
75 char *c;
76
77 if (version == NULL)
78 return NULL;
79 sprintf(version, "%s", VERSION);
80 // default values
81 sscanf(version, "%d.%d.%d", &major, &minor, &patch);
82 if (build)
83 {
84 c = build;
85#if defined(__INTEL_COMPILER)
86 c += sprintf(build, "using INTEL C compiler icc %d.%d ", __INTEL_COMPILER, __INTEL_COMPILER_UPDATE);
87#elif defined(__clang_version__)
88 c += sprintf(build, "using clang C compiler ", __clang_version__);
89#elif defined(__GNUC__)
90 c += sprintf(build, "using GNU C compiler gcc %d.%d.%d ", __GNUC__ , __GNUC_MINOR__ , __GNUC_PATCHLEVEL__);
91#elif defined(_MSC_VER)
92 c += sprintf(build, "using MICROSOFT C compiler %d ", _MSC_VER);
93#else
94 c += sprintf(build, "using an unknown C compiler ");
95#endif
96 sprintf(c,"at %s %s",__DATE__,__TIME__);
97 }
98
99 if (builder)
100#ifdef BUILD_USING_CMAKE
101 strcpy(builder, "cmake");
102#else
103 strcpy(builder, "autotools");
104#endif
105 if (version_major)
106 *version_major = major;
107 if (version_minor)
108 *version_minor = minor;
109 if (version_patch)
110 *version_patch = patch;
111 return version;
112}
113
115{
116 char version[16], build[64], builder[32];
117
118 bufrnoaa_get_version(version, build, builder, NULL, NULL, NULL);
119 printf ("%s: Version '%s' built %s and %s.\n" , OWN, VERSION, build, builder);
120}
121
122/*!
123 \fn int read_args( int _argc, char * _argv[])
124 \brief read the arguments from stdio
125 \param _argc number of arguments passed
126 \param _argv array of arguments
127
128 Returns 1 if succcess, -1 othewise
129*/
130int read_args ( int _argc, char * _argv[] )
131{
132 int iopt;
133
134 ENTRADA[0] = '\0';
135 SEL[0] = '\0';
136 SELS[0] = '\0';
137 SELO[0] = '\0';
138 SELU[0] = '\0';
139 PREFIX[0] = '\0';
140 SELECT = 0;
141 INDIVIDUAL = 0;
142 COLECT = 0;
143 LISTF = 0;
144 VERBOSE = 1;
145 HEADER_MARK = '*';
146 strcpy(FINAL_SEP, SEP);
147
148 /*
149 Read input options
150 */
151 while ( ( iopt = getopt ( _argc, _argv, "hv2i:flF:O:qS:T:U:" ) ) !=-1 )
152 switch ( iopt )
153 {
154 case 'i':
155 if ( strlen ( optarg ) < 256 )
156 strcpy ( ENTRADA, optarg );
157 break;
158 case '2':
159 HEADER_MARK = '#';
160 FINAL_SEP[0] = 0;
161 break;
162 case 'f':
163 INDIVIDUAL = 1;
164 break;
165 case 'q':
166 VERBOSE = 0;
167 break;
168 case 'l':
169 LISTF = 1;
170 break;
171 case 'F':
172 if ( strlen ( optarg ) && strlen ( optarg ) < 64 )
173 {
174 strcpy ( PREFIX, optarg );
175 COLECT = 1;
176 }
177 break;
178 case 'T':
179 if ( strlen ( optarg ) < 64 )
180 {
181 strcpy ( SEL, optarg );
182 SELECT = 1;
183 }
184 break;
185 case 'S':
186 if ( strlen ( optarg ) < 64 )
187 {
188 strcpy ( SELS, optarg );
189 }
190 break;
191 case 'O':
192 if ( strlen ( optarg ) < 64 )
193 {
194 strcpy ( SELO, optarg );
195 }
196 break;
197 case 'U':
198 if ( strlen ( optarg ) < 64 )
199 {
200 strcpy ( SELU, optarg );
201 }
202 break;
203 case 'v':
205 exit ( EXIT_SUCCESS );
206 break;
207 case 'h':
208 default:
209 print_usage();
210 exit ( EXIT_SUCCESS );
211 }
212
213 if ( ENTRADA[0] == '\0' )
214 {
215 printf ( "%s: It is needed an input file. Use -i option\n", OWN );
216 return -1;
217 }
218 return 1;
219}
220
char ENTRADA[256]
Definition: bufrdeco_json.c:27
char SEP[]
Definition: bufrnoaa.c:206
int SELECT
Definition: bufrnoaa.c:192
char HEADER_MARK
Definition: bufrnoaa.c:202
char SELU[64]
Definition: bufrnoaa.c:199
char FINAL_SEP[4]
Definition: bufrnoaa.c:207
int INDIVIDUAL
Definition: bufrnoaa.c:192
char OWN[]
Definition: bufrnoaa.c:205
char PREFIX[64]
Definition: bufrnoaa.c:201
char SELS[64]
Definition: bufrnoaa.c:198
int LISTF
Definition: bufrnoaa.c:193
int VERBOSE
Definition: bufrnoaa.c:192
char SELO[64]
Definition: bufrnoaa.c:200
int COLECT
Definition: bufrnoaa.c:192
inclusion file for binary bufrnoaa
int read_args(int _argc, char *_argv[])
read the arguments from stdio
Definition: bufrnoaa_io.c:130
void print_version()
Definition: bufrnoaa_io.c:114
void print_usage(void)
Definition: bufrnoaa_io.c:31
char * bufrnoaa_get_version(char *version, char *build, char *builder, int *version_major, int *version_minor, int *version_patch)
Get strings with version information and build date and time.
Definition: bufrnoaa_io.c:72
#define VERSION
Definition: config.h:8