(file) Return to smpl_03.c CVS log (file) (dir) Up to [Development] / JSOC / proj / cookbook

 1 rick  1.1 /*
 2            *  smpl_03.c						$DRMS/proj/cookbook/
 3            *
 4 rick  1.2  *  Prints a list of the series names known to DRMS, with record counts
 5            *    for each
 6            *  Illustrates the connection to the DRMS database and ways that SQL
 7            *    queries can be directly run and the results analyzed at the lowest
 8            *    level of the DRMS API
 9 rick  1.1  *
10            *  Usage:
11 rick  1.2  *    smpl_03 [nmax= ...]
12 rick  1.1  *
13            *  Revision history is at end of file.
14            */
15           
16           char *module_name = "CookbookRecipe:03";
17           char *version_id = "1.0";
18           
19           #include <jsoc_main.h>
20           #include <regex.h>
21           
22           ModuleArgs_t module_args[] = {
23 rick  1.2   {ARG_INT,	"nmax",	"100", "maximum number of series to be listed"},
24 rick  1.1   {ARG_END}
25           };
26           
27           int DoIt (void) {
28             CmdParams_t *params = &cmdparams;
29 rick  1.2   DB_Text_Result_t *qres, *sqres;
30 rick  1.1   int series, seriesct;
31             char query[DRMS_MAXQUERYLEN];
32           
33 rick  1.2   int nmax = params_get_int (params, "nmax");
34             	/*  Query the database to get all series names from the master list  */
35             sprintf (query, "select seriesname from %s()", DRMS_MASTER_SERIES_TABLE);
36             if ((qres = drms_query_txt (drms_env->session, query)) == NULL) {
37               fprintf (stderr, "Cant find DRMS\n");
38               return 1;
39             }
40             seriesct = qres->num_rows;
41             printf ("%d series found", seriesct);
42             if (seriesct > nmax) {
43               seriesct = nmax;
44               printf (" (only the first %d will be listed)", seriesct);
45             }
46             printf ("\n");
47           
48             for (series = 0; series < seriesct; series++) {
49               char *seriesname = qres->field[series][0];
50               printf ("%s\t", seriesname);
51               sprintf (query, "select count (recnum) from %s", seriesname);
52                  /*  Query the database to get the record count from the series table  */
53           			  /*  (every data series must have a "recnum" field) */
54 rick  1.2     if (sqres = drms_query_txt (drms_env->session, query)) {
55                 printf ("%s", sqres->field[0][0]);
56                 db_free_text_result (sqres);
57               } else printf ("?");
58               printf ("\n");
59             }
60 rick  1.1 
61 rick  1.2   db_free_text_result (qres);
62             return 0;
63 rick  1.1 }
64           
65           /*
66            *  Revision History
67            *
68            *  09.04.20	file created by R Bogart
69            */

Karen Tian
Powered by
ViewCVS 0.9.4