bufr2synop 0.24.0
Macros | Functions | Variables
update_tableD.c File Reference

This file includes the code for update_TableD binary. More...

#include "bufrdeco.h"
#include "config.h"
Include dependency graph for update_tableD.c:

Go to the source code of this file.

Macros

#define CONFIG_H
 

Functions

void print_usage (void)
 
int main (int argc, char *argv[])
 

Variables

const char SELF [] = "update_tableD"
 
char INPUT_FILE [256]
 
char REFERENCE_FILE [256]
 
char * TK [BUFR_MAXLINES_TABLED][16]
 
char REF [BUFR_MAXLINES_TABLED][CSV_MAXL]
 
char LIN [CSV_MAXL]
 
FILE * F
 
FILE * R
 

Detailed Description

This file includes the code for update_TableD binary.

It try to fill some field definitions for TableD from ECMWF. It fills the 'Title_en' for revisions prior 18_0_0 from this version.

Definition in file update_tableD.c.

Macro Definition Documentation

◆ CONFIG_H

#define CONFIG_H

Definition at line 34 of file update_tableD.c.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 54 of file update_tableD.c.

55{
56 int iopt, i, j, k, nt;
57 char caux[CSV_MAXL], caux2[CSV_MAXL];
58 char *tk[16];
59
60 // read arguments
61 INPUT_FILE[0] = 0;
62 REFERENCE_FILE[0] = 0;
63
64 while ( ( iopt = getopt ( argc, argv, "hi:r:" ) ) !=-1 )
65 switch ( iopt )
66 {
67 case 'i':
68 if ( strlen ( optarg ) < 256 )
69 strcpy ( INPUT_FILE, optarg );
70 break;
71 case 'r':
72 if ( strlen ( optarg ) < 256 )
73 strcpy ( REFERENCE_FILE, optarg );
74 break;
75 case 'h':
76 default:
78 exit ( EXIT_SUCCESS );
79 }
80
81 // Open reference file
82 if ( ( R = fopen ( REFERENCE_FILE, "r" ) ) == NULL )
83 {
84 fprintf ( stderr, "%s: Error. Cannot open file '%s'\n", SELF, REFERENCE_FILE );
85 exit ( EXIT_FAILURE );
86 }
87
88 // read and proccess refence file
89 i = 0;
90 while ( fgets ( REF[i], CSV_MAXL, R ) != NULL )
91 {
92 // Parse line
93 if ( parse_csv_line ( &nt, TK[i], REF[i] ) < 0 )
94 {
95 fprintf ( stderr, "%s: Error parsing csv line '%s' from file '%s'\n", SELF, LIN, INPUT_FILE );
96 fclose ( R );
97 exit ( EXIT_FAILURE );
98 }
99 i++;
100 }
101 fclose ( R );
102
103 // Open source file
104 if ( ( F = fopen ( INPUT_FILE, "r" ) ) == NULL )
105 {
106 fprintf ( stderr, "%s: Error. Cannot open file '%s'\n", SELF, INPUT_FILE );
107 exit ( EXIT_FAILURE );
108 }
109
110 // Read and process file
111 j = 0;
112 while ( fgets ( LIN, CSV_MAXL, F ) != NULL )
113 {
114 // Parse line
115 if ( parse_csv_line ( &nt, tk, LIN ) < 0 )
116 {
117 fprintf ( stderr, "%s: Error parsing csv line '%s' from file '%s'\n", SELF, LIN, INPUT_FILE );
118 fclose ( F );
119 exit ( EXIT_FAILURE );
120 }
121
122 printf ( "%s,", csv_quoted_string ( caux, tk[0] ) );
123 printf ( "%s,", csv_quoted_string ( caux, tk[1] ) );
124
125
126 if ( tk[2][0] == 0 ) //case of void field, lets go
127 {
128 caux[0] = 0;
129 // Search the same key tk[0] in reference file
130 for ( k = j; k < i ; k++ )
131 {
132 if ( strcmp ( TK[k][0], tk[0] ) == 0 )
133 {
134 strcpy ( caux2, TK[k][2] );
135 j = k;
136 break;
137 }
138 }
139 printf ( "%s,", csv_quoted_string ( caux, caux2 ) );
140
141 }
142 else
143 printf ( "%s,", csv_quoted_string ( caux, tk[2] ) );
144
145
146 printf ( "%s\n", csv_quoted_string ( caux, tk[3] ) );
147 }
148 fclose ( F );
149
150 exit ( EXIT_SUCCESS );
151}
#define CSV_MAXL
Maximum length in a string to be parsed as csv.
Definition: bufrdeco.h:128
int parse_csv_line(int *nt, char *tk[], char *lin)
Parse a csv line.
Definition: bufrdeco_csv.c:258
char * csv_quoted_string(char *out, char *in)
Transform a string to a quoted string to be inserted in a csv file.
Definition: bufrdeco_csv.c:48
char LIN[CSV_MAXL]
Definition: update_tableD.c:42
char INPUT_FILE[256]
Definition: update_tableD.c:38
char REF[BUFR_MAXLINES_TABLED][CSV_MAXL]
Definition: update_tableD.c:41
const char SELF[]
Definition: update_tableD.c:37
void print_usage(void)
Definition: update_tableD.c:46
char * TK[BUFR_MAXLINES_TABLED][16]
Definition: update_tableD.c:40
FILE * F
Definition: update_tableD.c:43
FILE * R
Definition: update_tableD.c:43
char REFERENCE_FILE[256]
Definition: update_tableD.c:39

References CSV_MAXL, csv_quoted_string(), F, INPUT_FILE, LIN, parse_csv_line(), print_usage(), R, REF, REFERENCE_FILE, SELF, and TK.

Here is the call graph for this function:

◆ print_usage()

void print_usage ( void  )

Definition at line 46 of file update_tableD.c.

47{
48 printf ( "%s %s\n", SELF, PACKAGE_VERSION );
49 printf ( "Usage: \n" );
50 printf ( "%s -i input_file -r reference_file [-h]\n" , SELF );
51 printf ( " -h Print this help\n" );
52}
#define PACKAGE_VERSION
Definition: config.h:4

References PACKAGE_VERSION, and SELF.

Referenced by main().

Here is the caller graph for this function:

Variable Documentation

◆ F

FILE* F

Definition at line 43 of file update_tableD.c.

Referenced by main().

◆ INPUT_FILE

char INPUT_FILE[256]

Definition at line 38 of file update_tableD.c.

Referenced by main().

◆ LIN

char LIN[CSV_MAXL]

Definition at line 42 of file update_tableD.c.

Referenced by main().

◆ R

FILE * R

Definition at line 43 of file update_tableD.c.

Referenced by main().

◆ REF

Definition at line 41 of file update_tableD.c.

Referenced by main().

◆ REFERENCE_FILE

char REFERENCE_FILE[256]

Definition at line 39 of file update_tableD.c.

Referenced by main().

◆ SELF

const char SELF[] = "update_tableD"

Definition at line 37 of file update_tableD.c.

Referenced by main(), and print_usage().

◆ TK

char* TK[BUFR_MAXLINES_TABLED][16]

Definition at line 40 of file update_tableD.c.

Referenced by main().