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

File: [Development] / JSOC / proj / cookbook / smpl_03.c (download)
Revision: 1.2, Mon Jul 27 22:42:09 2009 UTC (14 years, 1 month ago) by rick
Branch: MAIN
CVS Tags: Ver_LATEST, Ver_DRMSLATEST, Ver_9-5, Ver_9-41, Ver_9-4, Ver_9-3, Ver_9-2, Ver_9-1, Ver_9-0, Ver_8-8, Ver_8-7, Ver_8-6, Ver_8-5, Ver_8-4, Ver_8-3, Ver_8-2, Ver_8-12, Ver_8-11, Ver_8-10, Ver_8-1, Ver_8-0, Ver_7-1, Ver_7-0, Ver_6-4, Ver_6-3, Ver_6-2, Ver_6-1, Ver_6-0, Ver_5-9, Ver_5-8, Ver_5-7, Ver_5-6, Ver_5-5, Ver_5-3, Ver_5-2, Ver_5-14, Ver_5-13, Ver_5-12, Ver_5-11, Ver_5-10, NetDRMS_Ver_LATEST, NetDRMS_Ver_9-9, NetDRMS_Ver_9-5, NetDRMS_Ver_9-41, NetDRMS_Ver_9-4, NetDRMS_Ver_9-3, NetDRMS_Ver_9-2, NetDRMS_Ver_9-1, NetDRMS_Ver_9-0, NetDRMS_Ver_8-8, NetDRMS_Ver_8-7, NetDRMS_Ver_8-6, NetDRMS_Ver_8-5, NetDRMS_Ver_8-4, NetDRMS_Ver_8-3, NetDRMS_Ver_8-2, NetDRMS_Ver_8-12, NetDRMS_Ver_8-11, NetDRMS_Ver_8-10, NetDRMS_Ver_8-1, NetDRMS_Ver_8-0, NetDRMS_Ver_7-1, NetDRMS_Ver_7-0, NetDRMS_Ver_6-4, NetDRMS_Ver_6-3, NetDRMS_Ver_6-2, NetDRMS_Ver_6-1, NetDRMS_Ver_6-0, NetDRMS_Ver_2-7, NetDRMS_Ver_2-6, NetDRMS_Ver_2-5, NetDRMS_Ver_2-4, NetDRMS_Ver_2-3, NetDRMS_Ver_2-2, NetDRMS_Ver_2-1, NetDRMS_Ver_2-0b1, NetDRMS_Ver_2-0b, NetDRMS_Ver_2-0, HEAD
Changes since 1.1: +37 -33 lines
*** empty log message ***

 *  smpl_03.c						$DRMS/proj/cookbook/
 *  Prints a list of the series names known to DRMS, with record counts
 *    for each
 *  Illustrates the connection to the DRMS database and ways that SQL
 *    queries can be directly run and the results analyzed at the lowest
 *    level of the DRMS API
 *  Usage:
 *    smpl_03 [nmax= ...]
 *  Revision history is at end of file.

char *module_name = "CookbookRecipe:03";
char *version_id = "1.0";

#include <jsoc_main.h>
#include <regex.h>

ModuleArgs_t module_args[] = {
  {ARG_INT,	"nmax",	"100", "maximum number of series to be listed"},

int DoIt (void) {
  CmdParams_t *params = &cmdparams;
  DB_Text_Result_t *qres, *sqres;
  int series, seriesct;
  char query[DRMS_MAXQUERYLEN];

  int nmax = params_get_int (params, "nmax");
  	/*  Query the database to get all series names from the master list  */
  sprintf (query, "select seriesname from %s()", DRMS_MASTER_SERIES_TABLE);
  if ((qres = drms_query_txt (drms_env->session, query)) == NULL) {
    fprintf (stderr, "Cant find DRMS\n");
    return 1;
  seriesct = qres->num_rows;
  printf ("%d series found", seriesct);
  if (seriesct > nmax) {
    seriesct = nmax;
    printf (" (only the first %d will be listed)", seriesct);
  printf ("\n");

  for (series = 0; series < seriesct; series++) {
    char *seriesname = qres->field[series][0];
    printf ("%s\t", seriesname);
    sprintf (query, "select count (recnum) from %s", seriesname);
       /*  Query the database to get the record count from the series table  */
			  /*  (every data series must have a "recnum" field) */
    if (sqres = drms_query_txt (drms_env->session, query)) {
      printf ("%s", sqres->field[0][0]);
      db_free_text_result (sqres);
    } else printf ("?");
    printf ("\n");

  db_free_text_result (qres);
  return 0;

 *  Revision History
 *  09.04.20	file created by R Bogart

Karen Tian
Powered by
ViewCVS 0.9.4