ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/cookbook/smpl_05.c
Revision: 1.3
Committed: Fri Nov 4 00:31:49 2011 UTC (11 years, 10 months ago) by rick
Content type: text/plain
Branch: MAIN
CVS Tags: NetDRMS_Ver_6-4, NetDRMS_Ver_8-0, NetDRMS_Ver_6-2, NetDRMS_Ver_6-3, NetDRMS_Ver_6-0, NetDRMS_Ver_6-1, Ver_6-0, Ver_6-1, Ver_6-2, Ver_6-3, Ver_6-4, NetDRMS_Ver_8-8, Ver_8-5, NetDRMS_Ver_7-0, NetDRMS_Ver_8-1, Ver_7-0, Ver_LATEST, NetDRMS_Ver_LATEST, NetDRMS_Ver_8-12, NetDRMS_Ver_8-10, NetDRMS_Ver_8-11, NetDRMS_Ver_9-1, NetDRMS_Ver_9-0, NetDRMS_Ver_9-3, NetDRMS_Ver_9-2, NetDRMS_Ver_9-5, NetDRMS_Ver_9-4, NetDRMS_Ver_8-2, NetDRMS_Ver_8-3, NetDRMS_Ver_9-41, Ver_9-41, Ver_DRMSLATEST, NetDRMS_Ver_8-4, NetDRMS_Ver_8-5, NetDRMS_Ver_8-6, Ver_8-8, NetDRMS_Ver_8-7, Ver_8-2, Ver_9-3, Ver_8-0, Ver_8-1, Ver_8-6, Ver_8-7, Ver_8-4, Ver_8-11, Ver_7-1, Ver_9-1, Ver_8-3, NetDRMS_Ver_7-1, Ver_9-5, Ver_9-4, Ver_8-10, Ver_9-2, Ver_8-12, Ver_9-0, HEAD
Changes since 1.2: +2 -2 lines
Log Message:
strdup return of params_get_str()

File Contents

# Content
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 */