ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/cookbook/smpl_01.c
(Generate patch)

Comparing proj/cookbook/smpl_01.c (file contents):
Revision 1.2 by rick, Mon Apr 20 21:56:31 2009 UTC vs.
Revision 1.3 by rick, Mon Jul 27 23:42:22 2009 UTC

# Line 1 | Line 1
1   /*
2   *  smpl_01.c                                           $DRMS/proj/cookbook/
3   *
4 < *  Annother simple module that does nothing but echo back the values of
5 < *    arguments. It illustrates the use of command line parsing and the
6 < *    variety of argument types; also introduces time string functions
4 > *  An extremely simple module that does (almost) nothing at all.
5 > *    It illustrates the structure of a DRMS module and exhibits
6 > *    return status behavior with use of the module verbose flags
7   *
8   *  Usage:
9   *    smpl_01 [-avVH]
# Line 14 | Line 14
14   *
15   *  Revision history is at end of file.
16   */
17 <
17 >                                                  /*  required .h inclusion  */
18   #include <jsoc_main.h>
19 +                                             /*  required module identifier  */
20   char *module_name = "CookbookRecipe:01";
21 +                                            /*  optional version identifier
22 +                      (recommended, and required for this particular module  */
23   char *version_id = "1.0";
24 <
24 >                                  /*  required module arguments declaration  */
25   ModuleArgs_t module_args[] = {
26 <  {ARG_STRING,  "name", "Not Specified", "a string"},
27 <  {ARG_INT,     "ival", "1", "a positive integer", "[1,)"},
28 <  {ARG_INTS,    "iptr", "[0]", "array of integers"},
29 <  {ARG_FLOAT,   "fval", "0.0", "a real number"},
30 <  {ARG_FLOAT,   "fvalns", "Unspecified", "a real number"},
28 <  {ARG_FLOATS,  "fptr", "{2.71828, 3.14159, -1}", "array of real numbers"},
29 <  {ARG_TIME,    "time", "1582.10.5_00:00:00",
30 <      "a time, in standard date_time format"},
31 <  {ARG_NUME, "colour", "", "enumerated choice without a default",
32 <      "red, orange, yellow, green, blue, indigo, violet"},
33 <  {ARG_NUME, "mois", "Brumaire", "enumerated choice with a default",
34 <      "Vendémiaire, Brumaire, Frimaire, Nivôse, Pluviôse, Ventôse, Germinal, \
35 <      Florial, Prairial, Messidor, Thermidor, Fructidor"},
36 <  {ARG_FLAG,    "e",    "", "a flag value"},
26 >                                   /*  module-specific argument declarators  */
27 >  {ARG_FLAG,    "a",    "", "force an abort"},
28 >  {ARG_FLAG,    "v",    "", "run in verbose mode"},
29 >  {ARG_STRING,  "print", "done", "message to print on successful completion"},
30 >                                       /*  required end (or blank) argument  */
31    {ARG_END}
32   };
33 <
33 >                                            /*  required module declaration  */
34   int DoIt (void) {
35 <  CmdParams_t *params = &cmdparams;
42 <  double *fpval;
43 <  int *ipval;
44 <  int i, fpvals, ipvals;
45 <  char *colours[] = {"red", "orange", "yellow", "green", "blue", "violet"};
46 <  char *moiss[] = {"Vendémiaire", "Brumaire", "Frimaire", "Nivôse", "Pluviôse",
47 <      "Ventôse", "Germinal", "Florial", "Prairial", "Messidor", "Thermidor",
48 <      "Fructidor"};
49 <  char key[64], tbuf[64];
35 >  int status;
36  
37 <  TIME tval = params_get_time (params, "time");
52 <  double fval = params_get_double (params, "fval");
53 <  int ival = params_get_int (params, "ival");
54 <  int colour = params_get_int (params, "colour");
55 <  int mois = params_get_int (params, "mois");
56 <  char *name = params_get_str (params, "name");
57 <  int flagset = params_isflagset (params, "e");
37 >  char *msg = cmdparams_get_str (&cmdparams, "print", &status);
38  
39 <  printf ("name = %s\n", name);
40 <  printf ("fval = %g\n", fval);
41 <  printf ("ival = %d\n", ival);
42 <  sprint_time (tbuf, tval, "UT", 3);
43 <  printf ("time = %s\n", tbuf);
64 <  printf ("colour = %d (%s)\n", colour, colours[colour]);
65 <  printf ("mois = %d (%s)\n", mois, moiss[mois]);
66 <  printf ("-e? : %d\n", flagset);
67 <
68 <  printf ("fpvals = %d\n", fpvals = params_get_int (params, "fptr_nvals"));
69 <  fpval = (double *)malloc (fpvals * sizeof (double));
70 <  for (i = 0; i < fpvals; i++) {
71 <    sprintf (key, "fptr_%d_value", i);
72 <    fpval[i] = params_get_double (params, key);
73 <    printf ("fpval[%d] = %g\n", i, fpval[i]);
74 <  }
75 <  printf ("ipvals = %d\n", ipvals = params_get_int (params, "iptr_nvals"));
76 <  ipval = (int *)malloc (ipvals * sizeof (int));
77 <  for (i = 0; i < ipvals; i++) {
78 <    sprintf (key, "iptr_%d_value", i);
79 <    ipval[i] = params_get_int (params, key);
80 <    printf ("ipval[%d] = %d\n", i, ipval[i]);
39 >  if (params_isflagset (&cmdparams, "v"))
40 >    printf ("running module %s version %s\n", module_name, version_id);
41 >  if (params_isflagset (&cmdparams, "a")) {
42 >    printf ("aborting\n");
43 >    return 1;
44    }
45  
46 <  return (0);
46 >  printf ("%s\n", msg);
47 >                                    /*  required status return to jsoc_main  */
48 >  return 0;
49   }
50  
51   /*
52   *  Revision History
53   *
54 < *  07.02.27    created by RSB, based on original using SSSC API
90 < *  09.04.14    minor mods to illustrate additional features of arg parsing
54 > *  09.04.13    file created by R Bogart
55   */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines