1 |
/* |
2 |
* smpl_05.c $DRMS/proj/cookbook/ |
3 |
* |
4 |
* Populates the data series created from noaa_ar.jsd with the data in |
5 |
* noaa_ar.dat |
6 |
* Illustrates features of the DRMS_Keyword struct, and writing to DRMS |
7 |
* records |
8 |
* |
9 |
* Usage: |
10 |
* smpl_05 [ds= dat= ] |
11 |
* |
12 |
* Revision history is at end of file. |
13 |
*/ |
14 |
|
15 |
|
16 |
char *module_name = "CookbookRecipe:05"; |
17 |
char *version_id = "1.0"; |
18 |
|
19 |
#include <jsoc_main.h> |
20 |
|
21 |
ModuleArgs_t module_args[] = { |
22 |
{ARG_STRING, "ds", "drms.noaa_ar", "name of data series"}, |
23 |
{ARG_STRING, "data", "noaa_ar.dat", "file containing input data"}, |
24 |
{ARG_FLAG, "v", "", "verbose flag"}, |
25 |
{ARG_END} |
26 |
}; |
27 |
|
28 |
|
29 |
int DoIt (void) { |
30 |
CmdParams_t *params = &cmdparams; |
31 |
DRMS_Record_t *record; |
32 |
FILE *datafile; |
33 |
TIME obstime; |
34 |
int arnum, lathg, lonhg, loncm, area, extent, count; |
35 |
char timestr[64], class[16], type[16]; |
36 |
size_t linelen = 256; |
37 |
char *line = (char *)malloc (linelen); |
38 |
int rct = 0, status = 0; |
39 |
|
40 |
char *series = strdup (params_get_str (params, "ds")); |
41 |
char *filename = strdup (params_get_str (params, "data")); |
42 |
int verbose = cmdparams_exists (&cmdparams, "v"); |
43 |
|
44 |
datafile = fopen (filename, "r"); |
45 |
|
46 |
while (getline (&line, &linelen, datafile) >=0) { |
47 |
sscanf (line, "%s %d %d %d %d %d %s %d %d %s", timestr, &arnum, |
48 |
&lathg, &loncm, &lonhg, &area, class, &extent, &count, type); |
49 |
obstime = sscan_time (timestr); |
50 |
record = drms_create_record (drms_env, series, DRMS_PERMANENT, &status); |
51 |
if (!record) { |
52 |
fprintf (stderr, "Error: Unable to create record %d in series %s\n", |
53 |
rct, series); |
54 |
fprintf (stderr, " Does series exist and is it writeable by you?\n"); |
55 |
return 1; |
56 |
} |
57 |
drms_setkey_time (record, "Date", obstime); |
58 |
drms_setkey_int (record, "Region", arnum); |
59 |
drms_setkey_int (record, "Lat", lathg); |
60 |
drms_setkey_int (record, "Lon", loncm); |
61 |
drms_setkey_int (record, "CarrLon", lonhg); |
62 |
drms_setkey_int (record, "Area", area); |
63 |
drms_setkey_int (record, "Extent", extent); |
64 |
drms_setkey_int (record, "Count", count); |
65 |
drms_setkey_string (record, "Class", class); |
66 |
drms_setkey_string (record, "Type", type); |
67 |
drms_close_record (record, DRMS_INSERT_RECORD); |
68 |
rct++; |
69 |
} |
70 |
|
71 |
fclose (datafile); |
72 |
if (verbose) printf ("wrote %d records\n", rct); |
73 |
return status; |
74 |
} |
75 |
/* |
76 |
* Revision History |
77 |
* |
78 |
* 09.07.29 file created by R Bogart |
79 |
*/ |