~fuzzgun/ccg/main

« back to all changes in this revision

Viewing changes to src/main.cpp

  • Committer: Bob Mottram
  • Date: 2013-12-24 22:08:11 UTC
  • Revision ID: git-v1:431ee9b681db4322ce9043fe96c1e3e08fbe8c45
Tidying

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
 
49
49
static void get_data_files(string data_directory, vector<string> &filenames)
50
50
{
51
 
    int retval = walk_dir(data_directory, ".\\.$", WS_DOTFILES|WS_DEFAULT|WS_MATCHDIRS,filenames);
 
51
    int retval =
 
52
                walk_dir(data_directory, ".\\.$",
 
53
                                 WS_DOTFILES|WS_DEFAULT|WS_MATCHDIRS,filenames);
52
54
        switch(retval) {
53
55
        case WALK_BADIO: {
54
 
                fprintf(stderr,"Directory '%s' Error %d: %s\n", data_directory.c_str(),errno,strerror(errno));
 
56
                fprintf(stderr,"Directory '%s' Error %d: %s\n",
 
57
                                data_directory.c_str(),errno,strerror(errno));
55
58
                break;
56
59
        }
57
60
        case WALK_NAMETOOLONG: {
58
 
                fprintf(stderr,"Directory name '%s' is too long\n", data_directory.c_str());
 
61
                fprintf(stderr,"Directory name '%s' is too long\n",
 
62
                                data_directory.c_str());
59
63
                break;
60
64
        }
61
65
        case WALK_BADPATTERN: {
65
69
        }
66
70
        if ((retval==WALK_OK) && (filenames.size()==0)) {
67
71
                /* directory exists but contains no files */
68
 
                fprintf(stderr,"No files found within the directory '%s'\n",data_directory.c_str());
 
72
                fprintf(stderr,"No files found within the directory '%s'\n",
 
73
                                data_directory.c_str());
69
74
        }
70
75
}
71
76
 
74
79
 
75
80
        // help
76
81
        opt->addUsage("Example: ");
77
 
        opt->addUsage("  cgg --start 1970 --end 2012 --sites data/sites.html --dir data --filename test.png");
 
82
        opt->addUsage("  cgg --start 1970 --end 2012 --sites data/sites.html " \
 
83
                                  "--dir data --filename test.png");
78
84
        opt->addUsage(" ");
79
85
        opt->addUsage("Usage: ");
80
86
        opt->addUsage("");
81
87
        opt->addUsage("     --start <year>           Starting year for the plot");
82
88
        opt->addUsage("     --end <year>             Ending year for the plot");
83
 
        opt->addUsage("     --gas <name>             The type of gas to be plotted, eg. co2");
84
 
        opt->addUsage("     --method <P|D|G|T|S|N|F> Method by which the sample was taken");
85
 
        opt->addUsage("     --dir <directory>        Directory containing CGG data");
86
 
        opt->addUsage("     --dataversion <version>  Version number of the CCG data format");
87
 
        opt->addUsage("     --sites <file>           HTML file containing site codes and locations");
88
 
        opt->addUsage("     --sitecodes <list>       List of site codes to be plotted");
89
 
        opt->addUsage("     --filename <file>        Filename for the image to save");
90
 
        opt->addUsage("     --minmax                 Show minimum and maximum values");
91
 
        opt->addUsage("     --monthly                Plot monthly rather than yearly");
92
 
        opt->addUsage("     --area <N,W,N,W>         Plot within a geographical area");
93
 
        opt->addUsage("     --latitudes <min,max>    Plot within a min and max latitude band");
 
89
        opt->addUsage("     --gas <name>             " \
 
90
                                  "The type of gas to be plotted, eg. co2");
 
91
        opt->addUsage("     --method <P|D|G|T|S|N|F> " \
 
92
                                  "Method by which the sample was taken");
 
93
        opt->addUsage("     --dir <directory>        " \
 
94
                                  "Directory containing CGG data");
 
95
        opt->addUsage("     --dataversion <version>  " \
 
96
                                  "Version number of the CCG data format");
 
97
        opt->addUsage("     --sites <file>           " \
 
98
                                  "HTML file containing site codes and locations");
 
99
        opt->addUsage("     --sitecodes <list>       " \
 
100
                                  "List of site codes to be plotted");
 
101
        opt->addUsage("     --filename <file>        " \
 
102
                                  "Filename for the image to save");
 
103
        opt->addUsage("     --minmax                 " \
 
104
                                  "Show minimum and maximum values");
 
105
        opt->addUsage("     --monthly                " \
 
106
                                  "Plot monthly rather than yearly");
 
107
        opt->addUsage("     --area <N,W,N,W>         " \
 
108
                                  "Plot within a geographical area");
 
109
        opt->addUsage("     --latitudes <min,max>    " \
 
110
                                  "Plot within a min and max latitude band");
94
111
        opt->addUsage("     --altitudes              Plot altitudes");
95
112
        opt->addUsage("     --change                 Plot rates of change");
96
 
        opt->addUsage("     --distribution           Plot the distribution of measurements");
97
 
        opt->addUsage("     --subhorizontal <value>  Horizontal position of the subtitle in the range 0.0 - 1.0");
98
 
        opt->addUsage("     --subvertical <value>    Vertical position of the subtitle in the range 0.0 - 1.0");
 
113
        opt->addUsage("     --distribution           " \
 
114
                                  "Plot the distribution of measurements");
 
115
        opt->addUsage("     --subhorizontal <value>  " \
 
116
                                  "Horizontal position of the subtitle in the range 0.0 - 1.0");
 
117
        opt->addUsage("     --subvertical <value>    " \
 
118
                                  "Vertical position of the subtitle in the range 0.0 - 1.0");
99
119
        opt->addUsage("     --runningaverage         Show a running average");
100
 
        opt->addUsage("     --label <name>           Label for the vertical axis of the graph");
 
120
        opt->addUsage("     --label <name>           " \
 
121
                                  "Label for the vertical axis of the graph");
101
122
        opt->addUsage("     --kmlsites <filename>    Save sites in KML format");
102
123
        opt->addUsage("     --kmlsamples <filename>  Save samples in KML format");
103
124
        opt->addUsage("  -V --version                Show version number");
167
188
        int graph_type = CCG_GRAPH_MEAN;
168
189
        if (opt->getFlag("altitudes")) {
169
190
                graph_type = CCG_GRAPH_ALTITUDES;
170
 
        }       
 
191
        }
171
192
        if (opt->getFlag("change")) {
172
193
                graph_type = CCG_GRAPH_RATE_OF_CHANGE;
173
 
        }       
 
194
        }
174
195
        if (opt->getFlag("distribution")) {
175
196
                graph_type = CCG_GRAPH_DISTRIBUTION;
176
 
        }       
 
197
        }
177
198
 
178
199
        bool monthly = false;
179
200
        if (opt->getFlag("monthly")) {
211
232
        string sites_filename = "";
212
233
        if (opt->getValue("sites") != NULL) {
213
234
                sites_filename = opt->getValue("sites");
214
 
                
 
235
 
215
236
                ccg::load_sites(sites_filename,
216
237
                                                data_version, sites);
217
238
        }
275
296
                string area_str = opt->getValue("area");
276
297
                parse_string(area_str, area);
277
298
                if (((int)area.size() > 0) && ((int)area.size() < 4)) {
278
 
                        printf("Only %d out of 4 area coordinates were specified.  Did you miss out a comma?\n", (int)area.size());
 
299
                        printf("Only %d out of 4 area coordinates were specified.  " \
 
300
                                   "Did you miss out a comma?\n", (int)area.size());
279
301
                        delete opt;
280
302
                        return 0;
281
303
                }
394
416
 
395
417
        return 0;
396
418
}
397