bufr2synop 0.24.0
bufr2tac_json.c
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2013-2018 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 bufr2tac_json.c
22 \brief Output a struct \ref metreport in json form
23*/
24#include "bufr2tac.h"
25
26int print_json_alphanum ( FILE *f, char *type, char *alphanum, struct metreport *m )
27{
28 fprintf ( f, " { \n \"type\": \"%s\",\n", type );
29 if ( m->h != NULL )
30 {
31 fprintf ( f, " \"bufrfile\": \"%s\",\n", m->h->filename );
32 fprintf ( f, " \"gts_header\": \"%s %s %s %s\",\n", m->h->bname, m->h->center, m->h->dtrel, m->h->order );
33 }
34 fprintf ( f, " \"observation_datetime\": \"%s\",\n", m->t.datime );
35 fprintf ( f, " \"geo\": { \n" );
36 if ( strlen ( m->g.index ) )
37 {
38 fprintf ( f, " \"index\": \"%s\",\n", m->g.index );
39 }
40 if ( strlen ( m->g.name ) )
41 {
42 fprintf ( f, " \"name\": \"%s\",\n", m->g.name );
43 }
44 if ( strlen ( m->g.country ) )
45 {
46 fprintf ( f, " \"country\": \"%s\",\n", m->g.country );
47 }
48 fprintf ( f, " \"latitude\": %.6lf,\n", m->g.lat );
49 fprintf ( f, " \"longitude\": %.6lf,\n", m->g.lon );
50 fprintf ( f, " \"altitude\": %.1lf\n", m->g.alt );
51 fprintf ( f, " },\n" );
52 fprintf ( f, " \"report\": \"%s\"\n", alphanum );
53 fprintf ( f, " }" );
54 return 0;
55}
56/*!
57 \fn int print_json(FILE *f, struct metreport *m)
58 \brief prints a struct \ref metreport in json format
59 \param f pointer to a file already open by caller routine
60 \param m pointer to a struct \ref metreport containing the data to print
61*/
62int print_json ( FILE *f, struct metreport *m )
63{
64 fprintf ( f, "{\"metreport\" :" );
65 if ( m->alphanum[0] )
66 {
67 print_json_alphanum ( f, m->type, m->alphanum, m );
68 }
69
70 if ( m->alphanum2[0] ) //TTBB
71 {
72 fprintf ( f, "," );
73 print_json_alphanum ( f, m->type2, m->alphanum2, m );
74 }
75
76 if ( m->alphanum3[0] ) //TTCC
77 {
78 fprintf ( f, "," );
79 print_json_alphanum ( f, m->type3, m->alphanum3, m );
80 }
81 if ( m->alphanum4[0] ) //TTDD
82 {
83 fprintf ( f, "," );
84 print_json_alphanum ( f, m->type4, m->alphanum4, m );
85 }
86
87 fprintf ( f, "\n}\n" );
88 return 0;
89}
Include header file for binary bufr2tac.
int print_json(FILE *f, struct metreport *m)
prints a struct metreport in json format
Definition: bufr2tac_json.c:62
int print_json_alphanum(FILE *f, char *type, char *alphanum, struct metreport *m)
Definition: bufr2tac_json.c:26
char center[8]
Definition: bufrdeco.h:709
char dtrel[16]
Definition: bufrdeco.h:710
char order[8]
Definition: bufrdeco.h:711
char bname[16]
Definition: bufrdeco.h:708
char filename[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:712
char datime[16]
Definition: metcommon.h:63
double lat
Definition: bufr2tac.h:299
double lon
Definition: bufr2tac.h:300
double alt
Definition: bufr2tac.h:301
char index[16]
Definition: bufr2tac.h:296
char name[80]
Definition: bufr2tac.h:297
char country[80]
Definition: bufr2tac.h:298
all the information for a meteorological report in WMO text format from a BUFR file
Definition: bufr2tac.h:309
char alphanum[REPORT_LENGTH]
Definition: bufr2tac.h:321
char type4[8]
Definition: bufr2tac.h:326
char type[8]
Definition: bufr2tac.h:320
char type3[8]
Definition: bufr2tac.h:324
struct gts_header * h
Definition: bufr2tac.h:313
char type2[8]
Definition: bufr2tac.h:322
char alphanum3[REPORT_LENGTH]
Definition: bufr2tac.h:325
struct met_datetime t
Definition: bufr2tac.h:314
struct met_geo g
Definition: bufr2tac.h:315
char alphanum2[REPORT_LENGTH]
Definition: bufr2tac.h:323
char alphanum4[REPORT_LENGTH]
Definition: bufr2tac.h:327