ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/cookbook/smpl_02.c
Revision: 1.2
Committed: Mon Jul 27 23:42:16 2009 UTC (14 years, 2 months ago) by rick
Content type: text/plain
Branch: MAIN
CVS Tags: NetDRMS_Ver_2-7, NetDRMS_Ver_2-4, NetDRMS_Ver_2-5, Ver_5-10, Ver_5-14, Ver_5-13, Ver_5-12, Ver_5-11, Ver_5-2, NetDRMS_Ver_9-9, NetDRMS_Ver_2-2, Ver_5-6, NetDRMS_Ver_2-1, Ver_5-5, NetDRMS_Ver_2-6, NetDRMS_Ver_2-3, Ver_5-8, Ver_5-7, Ver_5-9, NetDRMS_Ver_2-0b1, Ver_5-3, NetDRMS_Ver_2-0b, NetDRMS_Ver_2-0
Changes since 1.1: +64 -42 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 rick 1.1 /*
2     * smpl_02.c $DRMS/proj/cookbook/
3     *
4 rick 1.2 * 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
7 rick 1.1 *
8     * Usage:
9 rick 1.2 * smpl_02 [-avVH]
10     *
11     * Bugs:
12     * The module is of no particular use, and exists merely for heuristic
13     * and testing purposes.
14 rick 1.1 *
15     * Revision history is at end of file.
16     */
17    
18 rick 1.2 #include <jsoc_main.h>
19 rick 1.1 char *module_name = "CookbookRecipe:02";
20     char *version_id = "1.0";
21    
22     ModuleArgs_t module_args[] = {
23 rick 1.2 {ARG_STRING, "name", "Not Specified", "a string"},
24     {ARG_INT, "ival", "1", "a positive integer", "[1,)"},
25     {ARG_INTS, "iptr", "[0]", "array of integers"},
26     {ARG_FLOAT, "fval", "0.0", "a real number"},
27     {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"},
37 rick 1.1 {ARG_END}
38     };
39    
40     int DoIt (void) {
41     CmdParams_t *params = &cmdparams;
42 rick 1.2 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];
50    
51     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");
58    
59     printf ("name = %s\n", name);
60     printf ("fval = %g\n", fval);
61     printf ("ival = %d\n", ival);
62     sprint_time (tbuf, tval, "UT", 3);
63     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 rick 1.1 }
75 rick 1.2 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]);
81 rick 1.1 }
82    
83 rick 1.2 return (0);
84 rick 1.1 }
85    
86     /*
87     * Revision History
88     *
89 rick 1.2 * 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
91 rick 1.1 */