00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 char *module_name = "CookbookRecipe:05";
00017 char *version_id = "1.0";
00018
00019 #include <jsoc_main.h>
00020
00021 ModuleArgs_t module_args[] = {
00022 {ARG_STRING, "ds", "drms.noaa_ar", "name of data series"},
00023 {ARG_STRING, "data", "noaa_ar.dat", "file containing input data"},
00024 {ARG_FLAG, "v", "", "verbose flag"},
00025 {ARG_END}
00026 };
00027
00028
00029 int DoIt (void) {
00030 CmdParams_t *params = &cmdparams;
00031 DRMS_Record_t *record;
00032 FILE *datafile;
00033 TIME obstime;
00034 int arnum, lathg, lonhg, loncm, area, extent, count;
00035 char timestr[64], class[16], type[16];
00036 size_t linelen = 256;
00037 char *line = (char *)malloc (linelen);
00038 int rct = 0, status = 0;
00039
00040 char *series = strdup (params_get_str (params, "ds"));
00041 char *filename = strdup (params_get_str (params, "data"));
00042 int verbose = cmdparams_exists (&cmdparams, "v");
00043
00044 datafile = fopen (filename, "r");
00045
00046 while (getline (&line, &linelen, datafile) >=0) {
00047 sscanf (line, "%s %d %d %d %d %d %s %d %d %s", timestr, &arnum,
00048 &lathg, &loncm, &lonhg, &area, class, &extent, &count, type);
00049 obstime = sscan_time (timestr);
00050 record = drms_create_record (drms_env, series, DRMS_PERMANENT, &status);
00051 if (!record) {
00052 fprintf (stderr, "Error: Unable to create record %d in series %s\n",
00053 rct, series);
00054 fprintf (stderr, " Does series exist and is it writeable by you?\n");
00055 return 1;
00056 }
00057 drms_setkey_time (record, "Date", obstime);
00058 drms_setkey_int (record, "Region", arnum);
00059 drms_setkey_int (record, "Lat", lathg);
00060 drms_setkey_int (record, "Lon", loncm);
00061 drms_setkey_int (record, "CarrLon", lonhg);
00062 drms_setkey_int (record, "Area", area);
00063 drms_setkey_int (record, "Extent", extent);
00064 drms_setkey_int (record, "Count", count);
00065 drms_setkey_string (record, "Class", class);
00066 drms_setkey_string (record, "Type", type);
00067 drms_close_record (record, DRMS_INSERT_RECORD);
00068 rct++;
00069 }
00070
00071 fclose (datafile);
00072 if (verbose) printf ("wrote %d records\n", rct);
00073 return status;
00074 }
00075
00076
00077
00078
00079