ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/cookbook/smpl_04.c
Revision: 1.2
Committed: Fri Nov 4 00:31:34 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.1: +1 -1 lines
Log Message:
strdup return of params_get_str()

File Contents

# Content
1 /*
2 * smpl_04.c $DRMS/proj/cookbook/
3 *
4 * Prints the number of unique records in the selected data series, and
5 * the defined number of data segments per record for the series
6 * Illustrates features of the DRMS_Record struct, and concept of uniqueness
7 * for DRMS records
8 *
9 * Usage:
10 * smpl_04 ds= ...
11 *
12 * Revision history is at end of file.
13 */
14
15 char *module_name = "CookbookRecipe:04";
16 char *version_id = "1.0";
17
18 #include <jsoc_main.h>
19 #include <regex.h>
20
21 ModuleArgs_t module_args[] = {
22 {ARG_STRING, "ds", "", "name of data series"},
23 {ARG_END}
24 };
25
26 int DoIt (void) {
27 CmdParams_t *params = &cmdparams;
28 DB_Text_Result_t *qres;
29 DRMS_Record_t *record;
30 regmatch_t pmatch[10];
31 int series, seriesct;
32 int status = 0;
33 char query[DRMS_MAXQUERYLEN];
34
35 char *ds = strdup (params_get_str (params, "ds"));
36
37 record = drms_template_record (drms_env, ds, &status);
38 if (record && !status) {
39 if (record->seriesinfo->pidx_num) {
40 char qry[1024];
41 sprintf (query, "select %s from %s group by %s",
42 (record->seriesinfo->pidx_keywords[0])->info->name, ds,
43 (record->seriesinfo->pidx_keywords[0])->info->name);
44 for (int i=1; i<record->seriesinfo->pidx_num; i++) {
45 sprintf (qry, ", %s",
46 (record->seriesinfo->pidx_keywords[i])->info->name);
47 strcat (query, qry);
48 }
49 if ((qres = drms_query_txt (drms_env->session, query))) {
50 printf ("%s contains %d unique records", ds, qres->num_rows);
51 db_free_text_result (qres);
52 }
53 } else printf ("%s: no records found", ds);
54 printf (", with %d data segment(s) per record\n", record->segments.num_total);
55 drms_free_record (record);
56 } else printf ("%s: no such series\n", ds);
57
58 return status;
59 }
60
61 /*
62 * Revision History
63 *
64 * 09.04.20 file created by R Bogart
65 */