nmxptool_getoptlong.c 38.1 KB
Newer Older
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1 2 3 4 5 6 7 8 9
/*! \file
 *
 * \brief Nanometrics Protocol Tool
 *
 * Author:
 * 	Matteo Quintiliani
 * 	Istituto Nazionale di Geofisica e Vulcanologia - Italy
 *	quintiliani@ingv.it
 *
10
 * $Id: nmxptool_getoptlong.c,v 1.113 2009-08-16 08:58:21 mtheo Exp $
Matteo Quintiliani's avatar
Matteo Quintiliani committed
11 12 13
 *
 */

14 15 16 17
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

18 19 20
#include <errno.h>
#include <unistd.h>

21 22 23 24 25 26
#include "config.h"
#include "nmxp.h"

#include "nmxptool_getoptlong.h"


27
const NMXPTOOL_PARAMS NMXPTOOL_PARAMS_DEFAULT =
28 29
{
    NULL,
30 31
    DEFAULT_PORT_DAP,
    DEFAULT_PORT_PDS,
32 33 34
    NULL,
    NULL,
    NULL,
35 36
    0.0,
    0.0,
37
    DEFAULT_INTERVAL_NO_VALUE,
38 39
    NULL,
    NULL,
40 41
    DEFAULT_STC,
    DEFAULT_RATE,
42
    NULL,
Matteo Quintiliani's avatar
Matteo Quintiliani committed
43
    DEFAULT_DELAY,
44 45
    DEFAULT_MAX_TOLERABLE_LATENCY,
    DEFAULT_TIMEOUTRECV,
46
    DEFAULT_VERBOSE_LEVEL,
47
    NULL,
48
    NULL,
49
    NULL,
50
    DEFAULT_TYPE_WRITESEED,
51
    DEFAULT_BUFFERED_TIME,
52
    DEFAULT_N_CHANNEL,
53
    DEFAULT_USEC,
54
    DEFAULT_MAX_TIME_TO_RETRIEVE,
55
    DEFAULT_NETWORKDELAY,
56
    DEFAULT_LISTEN_PORT,
57
    0,
58 59 60 61
    0,
    0,
    0,
    0,
62
    0,
63
    0,
64
    0,
65 66 67
    0
};

68 69

void nmxptool_author_support() {
70
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
71 72
Matteo Quintiliani - Istituto Nazionale di Geofisica e Vulcanologia - Italy\n\
Mail bug reports and suggestions to <%s>.\n",
73
	    NMXP_LOG_STR(PACKAGE_BUGREPORT)
74 75 76 77
	    );
}


Matteo Quintiliani's avatar
Matteo Quintiliani committed
78 79 80
#define PDS_VERSION "1.4"
#define DAP_VERSION "1.0"

81
void nmxptool_version() {
82
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
83
%s %s, tool for Nanometrics Protocols\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
84 85 86
         Private Data Stream %s, Data Access Protocol %s\n",
	NMXP_LOG_STR(PACKAGE_NAME), NMXP_LOG_STR(PACKAGE_VERSION),
	NMXP_LOG_STR(PDS_VERSION), NMXP_LOG_STR(DAP_VERSION)
87
	/*
88
	nmxp_log_version()
89
	*/
90
	    );
Matteo Quintiliani's avatar
Matteo Quintiliani committed
91 92

    nmxptool_supports();
93 94
}

95

Matteo Quintiliani's avatar
Matteo Quintiliani committed
96
void nmxptool_supports() {
97
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
98
         Enabled features: libmseed ");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
99
#ifdef HAVE_LIBMSEED
100
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "YES");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
101
#else
102
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "NO");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
103 104
#endif

105
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, ", SeedLink ");
106
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
107
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "YES");
108
#else
109
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "NO");
110 111
#endif

112
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, ", Earthworm ");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
113
#ifdef HAVE_EARTHWORMOBJS
114
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "YES");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
115
#else
116
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "NO");
117 118 119 120 121 122 123 124 125
#endif
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, ".\n");

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
         Using pthread: ");
#ifdef HAVE_PTHREAD_H
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "YES");
#else
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "NO");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
126
#endif
127 128 129 130 131

#ifdef NMXP_MEM_DEBUG
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, ". Enabled memdebug");
#endif

132
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, ".\n");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
133 134
}

135

136 137
void nmxptool_usage(struct option long_options[])
{
138
    nmxptool_version();
Matteo Quintiliani's avatar
Matteo Quintiliani committed
139

140
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
141
\n\
142
Usage: %s -H hostname  [  -C channellist ]  -l | -L \n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
143
             Print list of the available Time Series channels\n\
144
             on DataServer and NaqsServer respectively.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
145 146 147 148
\n",
NMXP_LOG_STR(PACKAGE_NAME));

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
149
       %s -H hostname -C channellist [...]\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
150
             Receive data in near real-time from NaqsServer by PDS %s\n\
151
\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
152
       %s -H hostname -F statefile [-A SECs] [...]\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
153 154
             Receive data from NaqsServer and, in case, retrieve previous\n\
             data from DataServer up to SECs seconds before.\n\
155 156
\n",
NMXP_LOG_STR(PACKAGE_NAME),
Matteo Quintiliani's avatar
Matteo Quintiliani committed
157 158 159 160 161 162 163 164
NMXP_LOG_STR(PDS_VERSION),
NMXP_LOG_STR(PACKAGE_NAME));

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
       %s -H hostname -C channellist -s DATE -e DATE [...]\n\
       %s -H hostname -C channellist -s DATE -t TIME [...]\n\
             Receive a temporal interval of data from DataServer by DAP %s\n\
\n",
165 166
NMXP_LOG_STR(PACKAGE_NAME),
NMXP_LOG_STR(PACKAGE_NAME),
Matteo Quintiliani's avatar
Matteo Quintiliani committed
167 168
NMXP_LOG_STR(DAP_VERSION)
);
Matteo Quintiliani's avatar
Matteo Quintiliani committed
169 170

#ifdef HAVE_EARTHWORMOBJS
171
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
172
       %s nmxptool.d\n\
173
             Launched as Earthworm module to redirect data into the EW-Rings.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
174
             Refer to nmxptool_cmd.html into the Earthworm documentation.\n\
175
\n", NMXP_LOG_STR(PACKAGE_NAME));
176 177 178 179
#endif

#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
180
       %s <option ... option> [ -k  |  -K ]\n\
181
             Launched as SeedLink plug-in to feed the SL-Server.\n\
182
\n", NMXP_LOG_STR(PACKAGE_NAME));
Matteo Quintiliani's avatar
Matteo Quintiliani committed
183 184
#endif

185
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
186
       %s --help | -h\n\
187
             Print this help.\n\
188
\n", NMXP_LOG_STR(PACKAGE_NAME));
189 190

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
191
Main arguments:\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
192
  -H, --hostname=HOST     NaqsServer/DataServer hostname or IP address.\n\
193
  -C, --channels=LIST     List of NET.STA.CHAN separated by comma.\n\
194
                          NET  is optional and used only for output.\n\
195 196
                          STA  can be '*', it stands for all stations.\n\
                          CHAN can contain '?', it stands for any character.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
197
                          Network code will be assigned from the first\n\
198
                          pattern that includes station and channel.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
199
                          DO NOT USE with -F.\n\
200 201 202 203
                                Example: N1.AAA.HH?,N2.*.HH?,MMM.BH?\n\
                          Second pattern includes the first. Unless AAA, all\n\
                          stations with HH channels will have network to N2.\n\
                          Station MMM will have default network defined by -N.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
204
  -F, --statefile=FILE    List of channel patterns, as in -C. One for each line.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
205 206 207
                          Load/Save time of the last sample of each channel\n\
                          into a file with the same name, same directory,\n\
                          appending the suffix '%s'.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
208
                          Allow data continuity when short disconnections occur.\n\
209
                          Related to -A and -f, it enables -b.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
210 211 212
                          DO NOT USE with -C.\n",
			  NMXP_STR_STATE_EXT
);
213 214

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
215
  -A, --maxdataretr=SECs  Max amount of data of the past to retrieve from the\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
216
                          DataServer when program restarts (default %d) [%d..%d].\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
217 218 219
                          0 to disable connection to DataServer.\n\
                          If this option is equal to zero and -F is used,\n\
                          only data buffered by NaqsServer will be retrieved.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
220 221 222
                          Rather than using -A, it is preferable, inside the section\n\
                          Datastream of the file Naqs.ini, setting DataBufferLength \n\
                          to a high value. -A allows to retrieve much more\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
223
                          data of the past when the program restarts but it\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
224
                          considerably slows down the execution.\n\
225 226 227
                          It is extremely harmful when you have many channels,\n\
                          in this case you might consider to subdivide the\n\
                          channels into different nmxptool instances.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
228
                          Related to -F.\n\
229 230 231 232 233 234 235
\n",
	    DEFAULT_MAX_TIME_TO_RETRIEVE,
	    DEFAULT_MAX_TIME_TO_RETRIEVE_MINIMUM,
	    DEFAULT_MAX_TIME_TO_RETRIEVE_MAXIMUM
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
236 237
PDS arguments for NaqsServer:\n\
  -P, --portpds=PORT      NaqsServer port number (default %d).\n\
238 239
  -S, --stc=SECs          Short-Term-Completion (default %d).\n\
                          -1 is for Raw Stream, no Short-Term-Completion.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
240
                             Packets contain compressed data. Related to -M, -T.\n\
241 242
                             It enables --rate=-1.\n\
                           0 decompressed packets are received in chronological\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
243
                             order without waiting for missing packets.\n\
244
                          [1..300] decompressed packets are received in\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
245
                             chronological order but waiting for missing packets\n\
246
                             at most SECs seconds.\n\
247 248 249 250 251
  -R, --rate=Hz           Receive data with specified sample rate (default %d).\n\
                          -1 for original sample rate and compressed data.\n\
                           0 for original sample rate and decompressed data.\n\
                          >0 for specified sample rate and decompressed data.\n\
  -b, --buffered          Request also recent packets into the past.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
252
  -B, --buffdate=DATE     Request also recent packets into the past\n\
253 254 255 256 257 258
                          but consider only samples after DATE.\n",
	    DEFAULT_PORT_PDS,
	    DEFAULT_STC,
	    DEFAULT_RATE);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
259
  -f, --mschan=mSECs/nC   mSECs are milliseconds to wait before the next request,\n\
260
                          nC is the number of channels to request at a time.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
261
                          Delaying and requesting few channels at a time make\n\
262 263
                          data buffering on NaqsServer side more efficient.\n\
                          Determined empiric values are default %d/%d.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
264
                          Condition: TotalNumberOfChannels * (mSECs/nC) < %d sec. \n\
265
                          Related to -F and -b. 0/0 for disabling.\
266
\n",
267
DEFAULT_USEC / 1000, DEFAULT_N_CHANNEL, NMXP_MAX_MSCHAN_MSEC / 1000);
268 269

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
270
  -L, --listchannelsnaqs  List of the available Time Series channels on NaqsServer.\n\
271
  -M, --maxlatency=SECs   Max tolerable latency (default %d) [%d..%d].\n\
272 273 274 275
                          Enable NaqsServer to send out retransmission requests\n\
                          for missed packets. Inside the section NetworkInterface\n\
                          of the file Naqs.ini set RetxRequest to Enabled.\n\
                          If RetxRequest is not enabled then -M is ineffective.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
276
  -T, --timeoutrecv=SECs  Time-out for flushing queued packets of each channel.\n\
277
                          It sets --mschan=0/0 (default %d, no time-out) [%d..%d].\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
278
                          -T is useful for retrieving Data On Demand with minimum delay.\n\
279
                          -M, -T are usable only with Raw Stream, -S=-1.\n\
280
                          In general, -M and -T are not used together.\n\
281
                          Receiving signals interrupts the time out.\n\
282 283 284 285 286 287 288 289 290 291 292
\n\
",
	    DEFAULT_MAX_TOLERABLE_LATENCY,
	    DEFAULT_MAX_TOLERABLE_LATENCY_MINIMUM,
	    DEFAULT_MAX_TOLERABLE_LATENCY_MAXIMUM,
	    DEFAULT_TIMEOUTRECV,
	    DEFAULT_TIMEOUTRECV_MINIMUM,
	    DEFAULT_TIMEOUTRECV_MAXIMUM
	  );

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
293
DAP arguments for DataServer:\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
294
  -D, --portdap=PORT      DataServer port number (default %d).\n\
295 296 297 298 299 300 301
  -s, --start_time=DATE   Start time in date format.\n\
  -e, --end_time=DATE     End time in date format.\n\
                          DATE can be in formats:\n\
                              <date>,<time> | <date>\n\
                          where:\n\
                              <date> = yyyy/mm/dd | yyy.jjj\n\
                              <time> = hh:mm:ss | hh:mm:ss.dddd | hh:mm\n\
302 303 304
  -t, --interval=TIME     Time interval from start_time (greater than zero).\n\
                          TIME is in seconds, otherwise append 'm' for minutes\n\
                          'h' for hours or 'd' for days. [1 sec .. %d days]\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
305
                          DO NOT USE with -e.\n\
306
  -d, --delay=TIME        Receive continuosly data with delay [%d sec .. %d days].\n\
307 308
  -u, --username=USER     DataServer username.\n\
  -p, --password=PASS     DataServer password.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
309
  -l, --listchannels      List of the available Time Series channels on DataServer.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
310
  -i, --channelinfo       Print channelinfo (network name) when using -l.\n\
311 312
\n\
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
313
DEFAULT_PORT_DAP,
314
(DEFAULT_INTERVAL_MAXIMUM / 86400),
315
DEFAULT_DELAY_MINIMUM,
316
(DEFAULT_DELAY_MAXIMUM / 86400));
317

318
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
319
Other arguments:\n\
320
  -N, --network=NET       Default output Network code. (default '%s').\n\
321
  -n, --location=LOC      Default output Location code. DISABLED!\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
322
  -v, --verbose=LEVEL     Be verbose. LEVEL is a bitmap:\n\
323
                          %d Channel State, %d Channel, %d Raw Stream,\n\
324 325 326
                          %d CRC32, %d Connection flow,\n\
                          %d Packet Management, %d Extra, %d Date,\n\
                          %d Gap, %d DOD, %d All messages.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
327
  -g, --logdata           Print info about packet data.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
328
  -G, --logsample         Print sample values of packets. Includes -g.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
329
",
330
	    NMXP_LOG_STR(DEFAULT_NETWORK),
331
	    NMXP_LOG_D_CHANSTATE,
332 333 334 335 336 337 338 339 340 341
	    NMXP_LOG_D_CHANNEL,
	    NMXP_LOG_D_RAWSTREAM,
	    NMXP_LOG_D_CRC,
	    NMXP_LOG_D_CONNFLOW,
	    NMXP_LOG_D_PACKETMAN,
	    NMXP_LOG_D_EXTRA,
	    NMXP_LOG_D_DATE,
	    NMXP_LOG_D_GAP,
	    NMXP_LOG_D_DOD,
	    NMXP_LOG_D_ANY
342 343 344
		);

#ifdef HAVE_LIBMSEED
345
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
346 347 348
  -m, --writeseed=[TYPE]  Pack received data in Mini-SEED records and\n\
                          store them within a SDS or BUD structure.\n\
                          TYPE can be '%c' or '%c' (-m%c or -m%c)\n\
349
                          Packets are appended to existing files. Related to -o.\n",
350 351
			  TYPE_WRITESEED_SDS, TYPE_WRITESEED_BUD,
			  TYPE_WRITESEED_SDS, TYPE_WRITESEED_BUD);
352
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
353
  -o, --outdirseed=DIR    Output directory for SDS or BUD structure.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
354
                          Related to -m (default is current directory).\n");
355 356
#endif

357
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
358
  -w, --writefile         Dump received packets to a file.\n");
359

360
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
361
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
362
  -k, --slink=PLUGINID    Send received data to SeedLink as a plug-in.\n\
363
                          Data are sent by send_raw_depoch().\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
364 365
                          This option, inside the file seedlink.ini, must be\n\
                          the last without adding value for PLUGINID!\n\
366 367 368 369 370 371 372 373 374
                          PLUGINID is set by SeisComP daemon.\n\
                          Not usable together with -K.\n");
#endif

#ifdef HAVE_LIBMSEED
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
  -K, --slinkms=PLUGINID  Send received data to SeedLink as a plug-in.\n\
                          This option is similar to previous -k,\n\
375 376
                          using -K the program converts data into mini-SEED\n\
                          records and sends them by the function send_mseed()\n\
377 378 379
                          instead of send_raw_depoch().\n\
                          Not usable together with -k.\n");
#endif
380
#endif
381

382
#ifndef HAVE_WINDOWS_H
383
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
384 385
  -E, --testport=PORT     Accept 'telnet' connection on PORT\n\
                          for data testing and diagnostic purposes.\n");
386
#endif
387

388
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
389
  -V, --version           Print tool version.\n\
390
  -h, --help              Print this help.\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
391 392
\n");

393 394 395 396 397
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Signal handling:\n\
   INT QUIT TERM          Sending these signals to %s causes it\n\
                          to immediately attempt to gracefully terminate.\n\
                          It may take several seconds to complete exiting.\n\
398
   ALRM                   Print current info about Raw Stream buffer.\n\
399 400 401
   HUP PIPE               Ignored. (SIG_IGN)\n\
\n", NMXP_LOG_STR(PACKAGE_NAME));

402
    nmxptool_author_support();
403 404 405 406 407

    /*
    if(long_options) {
	int i=0;
	while(long_options[i].name) {
408 409 410
	    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "%s %d %d %d %c\n",
	    NMXP_LOG_STR(long_options[i].name), long_options[i].has_arg,
	    (long_options[i].flag)? *(long_options[i].flag) : 0, long_options[i].val, long_options[i].val);
411 412 413 414 415 416 417
	    i++;
	}
    }
    */
}


418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
#define MAXSIZE_LINE_CHAN_STATE 2048
#define MAXSIZECHANNELSTRINGARGUMENT 8000
#define MAXSIZE_CHANNEL_STRING 64

char *get_channel_list_argument_from_state_file(const char *filename) {
    char *ret_channel_string = NULL;
    char line[MAXSIZE_LINE_CHAN_STATE];
    char str_chan[MAXSIZE_CHANNEL_STRING];
    int k;
    FILE *fstatefile = NULL;

    fstatefile = fopen(filename, "r");

    /* Read only channel names from state file */
    if(fstatefile) {
433
	ret_channel_string = (char *) NMXP_MEM_MALLOC(MAXSIZECHANNELSTRINGARGUMENT);
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
	ret_channel_string[0] = 0;
	while(fgets(line, MAXSIZE_LINE_CHAN_STATE, fstatefile) != NULL) {
	    k = 0;
	    while(line[k] != 0
		    &&  line[k] != ' '
		    &&  line[k] != 10
		    &&  line[k] != 13
		    &&  k < MAXSIZE_CHANNEL_STRING) {
		str_chan[k] = line[k];
		k++;
	    }
	    str_chan[k] = 0;
	    if(ret_channel_string[0] == 0) {
		strncpy(ret_channel_string, str_chan, MAXSIZECHANNELSTRINGARGUMENT);
	    } else {
		strncat(ret_channel_string, ",", MAXSIZECHANNELSTRINGARGUMENT);
		strncat(ret_channel_string, str_chan, MAXSIZECHANNELSTRINGARGUMENT);
	    }
	}
	fclose(fstatefile);
    }
    return ret_channel_string;
}

458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
int nmxptool_read_time(char *str_input, int32_t *pvalue) {
    char str_value[100];
    int len_int;
    int32_t value;
    int j;
    char unit = 'X';
    int ret_errors = 0;

    value = 0;
    strncpy(str_value, str_input, 100);
    len_int = strlen(str_value);
    if(len_int <= 0) {
	/* ERROR */
	ret_errors++;
    } else {
	j=0;
	while(j < len_int  && str_value[j] >= '0' && str_value[j] <= '9') {
	    j++;
	}
	if(j < len_int) {
	    if(j == len_int-1) {
		unit = str_value[j];
		str_value[j] = 0;
		if(unit == 'm' || unit == 'h' || unit == 'd') {
		    value = atoi(str_value);
		    switch(unit) {
			case 'm' :
			    value *= 60;
			    break;
			case 'h' :
			    value *= ( 60 * 60 );
			    break;
			case 'd' :
			    value *= ( 60 * 60 * 24 );
			    break;
		    }
		} else {
		    ret_errors++;
		    nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
			    "Syntax of time '%s' is not correct!\n", NMXP_LOG_STR(str_value));
		}
	    } else {
		ret_errors++;
		nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
			"Syntax of time '%s' is not correct!\n", NMXP_LOG_STR(str_value));
	    }
	} else {
	    /* All numbers, then seconds */
	    value = atoi(str_value);
	}

    }

    *pvalue = value;
    return ret_errors;
}

515
int nmxptool_getopt_long(int argc, char **argv, NMXPTOOL_PARAMS *params)
516
{
517 518
    int ret_errors = 0;

519
    NMXP_TM_T tmp_tmt;
520 521 522 523
    int i;
    char one_time_option[255];
    int c;

524
    /*
525 526 527
    int len_int, j;
    char unit = 'X';
    char str_interval[100];
528
    */
529

530 531
    char *sep = NULL;

532 533 534 535 536 537 538 539
    struct option long_options[] =
    {
	/* These options set a flag. */
	/* It is not safe use reference to params in this way */
	/* {"verbose",        no_argument,       &(params->flag_verbose), 1}, */
	/* {"quiet",          no_argument,       &(params->flag_verbose), 0}, */
	/* These options don't set a flag.
	 *                   We distinguish them by their indices. */
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
	{"hostname",     required_argument, NULL, 'H'},
	{"portpds",      required_argument, NULL, 'P'},
	{"portdap",      required_argument, NULL, 'D'},
	{"channels",     required_argument, NULL, 'C'},
	{"network",      required_argument, NULL, 'N'},
	{"location",     required_argument, NULL, 'n'},
	{"stc",          required_argument, NULL, 'S'},
	{"rate",         required_argument, NULL, 'R'},
	{"start_time",   required_argument, NULL, 's'},
	{"end_time",     required_argument, NULL, 'e'},
	{"interval",     required_argument, NULL, 't'},
	{"delay",        required_argument, NULL, 'd'},
	{"username",     required_argument, NULL, 'u'},
	{"password",     required_argument, NULL, 'p'},
	{"maxlatency",   required_argument, NULL, 'M'},
	{"timeoutrecv",  required_argument, NULL, 'T'},
	{"verbose",      required_argument, NULL, 'v'},
	{"bufferedt",    required_argument, NULL, 'B'},
558
	{"maxdataretr",  required_argument, NULL, 'A'},
559
	/* Following are flags */
560
	{"logdata",      no_argument,       NULL, 'g'},
Matteo Quintiliani's avatar
Matteo Quintiliani committed
561
	{"logsample",    no_argument,       NULL, 'G'},
562 563 564 565
	{"buffered",     no_argument,       NULL, 'b'},
	{"listchannels", no_argument,       NULL, 'l'},
	{"listchannelsnaqs", no_argument,   NULL, 'L'},
	{"channelinfo",  no_argument,       NULL, 'i'},
566
#ifdef HAVE_LIBMSEED
567
	{"writeseed",    required_argument, NULL, 'm'},
568
	{"outdirseed",   required_argument, NULL, 'o'},
569
#endif
570
	{"writefile",    no_argument,       NULL, 'w'},
571
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
572
	{"slink",        required_argument, NULL, 'k'},
573
#endif
574 575 576 577 578
#ifdef HAVE_LIBMSEED
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
	{"slinkms",      required_argument, NULL, 'K'},
#endif
#endif
579
#ifndef HAVE_WINDOWS_H
580
	{"socketport",   required_argument, NULL, 'E'},
581
#endif
582
	{"statefile",    required_argument, NULL, 'F'},
583
	{"mschan",       required_argument, NULL, 'f'},
584 585
	{"help",         no_argument,       NULL, 'h'},
	{"version",      no_argument,       NULL, 'V'},
586 587 588
	{0, 0, 0, 0}
    };

589
    char optstr[300] = "H:P:D:C:N:n:S:R:s:e:t:d:u:p:M:T:v:B:A:F:f:gGblLiwhV";
590

Matteo Quintiliani's avatar
Matteo Quintiliani committed
591 592 593
    int option_index = 0;


594
#ifdef HAVE_LIBMSEED
595
    strcat(optstr, "m:");
596
    strcat(optstr, "o:");
597
#endif
598

599 600 601
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
    strcat(optstr, "k:");
#endif
602

603 604 605 606 607 608
#ifdef HAVE_LIBMSEED
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
    strcat(optstr, "K:");
#endif
#endif

609 610 611
#ifndef HAVE_WINDOWS_H
    strcat(optstr, "E:");
#endif
612 613 614 615 616 617 618 619 620

    /* getopt_long stores the option index here. */
    /* init array for checking one time option */
    for(i=0; i<255; i++) {
	one_time_option[i] = 0;
    }


    /* init params */
621
    memcpy(params, &NMXPTOOL_PARAMS_DEFAULT, sizeof(NMXPTOOL_PARAMS_DEFAULT));
622

623 624 625 626 627 628 629 630 631 632 633 634 635 636
    /* Check number of command line arguments for earthworm */
    if (argc == 2)
    {
	int l = strlen(argv[1]);
	if(l >= 3) {
	    if(argv[1][0] != '-') {
		if(argv[1][l-2] == '.'  &&  argv[1][l-1] == 'd') {
		    params->ew_configuration_file = argv[1];
		    return 0;
		}
	    }
	}
    }

637 638 639 640 641 642 643
    while ( (c = getopt_long (argc, argv, optstr, long_options, &option_index)) != -1) {

	/* BE CAREFUL if use synonym options !!! */
	one_time_option[c]++;

	if(one_time_option[c] > 1) {
	    ret_errors++;
644
	    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "Replicated option -%c (value %s)\n", c, NMXP_LOG_STR(optarg));
645 646 647 648 649 650 651
	} else {
	    switch (c)
	    {
		case 0:
		    /* If this option set a flag, do nothing else now. */
		    if (long_options[option_index].flag != 0)
			break;
652 653 654 655 656
		    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "option %s",
			    NMXP_LOG_STR(long_options[option_index].name));
		    if (optarg) {
			nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, " with arg %s", NMXP_LOG_STR(optarg));
		    }
657
		    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\n");
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
		    break;

		case 'H':
		    params->hostname = optarg;
		    break;

		case 'P':
		    params->portnumberpds = atoi(optarg);
		    break;

		case 'D':
		    params->portnumberdap = atoi(optarg);
		    break;

		case 'C':
673
		    if(params->channels) {
674 675
			nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
				"Channels have been already defined by State File (option -F)!\n");
676 677
			ret_errors++;
		    } else {
678
			params->channels = NMXP_MEM_STRDUP(optarg);
679
		    }
680 681 682 683 684 685
		    break;

		case 'N':
		    params->network = optarg;
		    break;

686
		case 'n':
687 688 689 690 691
		    if(1) {
			nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "Location is currently disabled!\n");
		    } else {
			params->location = optarg;
		    }
692 693
		    break;

694 695
		case 'S':
		    params->stc = atoi(optarg);
696
		    nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Short-Term-Completion %d.\n", params->stc);
697 698 699 700 701 702
		    break;

		case 'R':
		    params->rate = atoi(optarg);
		    break;

703
		case 's':
704
		    if(nmxp_data_parse_date(optarg, &tmp_tmt) == -1) {
705
			/* MESSAGE ERROR */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
706
			ret_errors++;
707
		    } else {
708
			params->start_time = nmxp_data_tm_to_time(&tmp_tmt);
709 710 711 712
		    }
		    break;

		case 'e':
713
		    if(nmxp_data_parse_date(optarg, &tmp_tmt) == -1) {
714
			/* MESSAGE ERROR */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
715
			ret_errors++;
716
		    } else {
717
			params->end_time = nmxp_data_tm_to_time(&tmp_tmt);
718 719 720
		    }
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
721
		case 't':
722
		    ret_errors += nmxptool_read_time(optarg, &(params->interval) );
Matteo Quintiliani's avatar
Matteo Quintiliani committed
723 724
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
725
		case 'd':
726
		    ret_errors += nmxptool_read_time(optarg, &(params->delay) );
Matteo Quintiliani's avatar
Matteo Quintiliani committed
727 728
		    break;

729 730 731 732 733 734 735 736
		case 'u':
		    params->datas_username = optarg;
		    break;

		case 'p':
		    params->datas_password = optarg;
		    break;

737
		case 'M':
Matteo Quintiliani's avatar
Matteo Quintiliani committed
738
		    params->max_tolerable_latency = atoi(optarg);
739 740
		    nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Max_tolerable_latency %d\n",
			    params->max_tolerable_latency);
Matteo Quintiliani's avatar
Matteo Quintiliani committed
741 742
		    break;

743
		case 'T':
744
		    params->timeoutrecv = atoi(optarg);
745 746
		    nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Time-out receiving %d\n",
			    params->timeoutrecv);
747 748
		    break;

749 750 751 752
		case 'v':
		    params->verbose_level = atoi(optarg);
		    break;

753 754 755
		case 'B':
		    params->flag_buffered = 1;
		    if(nmxp_data_parse_date(optarg, &tmp_tmt) == -1) {
756
			/* MESSAGE ERROR */
757 758 759 760 761 762
			ret_errors++;
		    } else {
			params->buffered_time = nmxp_data_tm_to_time(&tmp_tmt);
		    }
		    break;

763 764
		case 'A':
		    if(optarg) {
765
			params->max_data_to_retrieve = atoi(optarg);
766
		    }
767
		    nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Max_time_to_retrieve %d\n", params->max_data_to_retrieve);
768
		    break;
769

770 771 772
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
		case 'k':
		    params->flag_slink = 1;
773 774 775 776 777 778 779 780 781
		    if(params->flag_slinkms) {
			nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
				"Options -k and -K are declared in the same command line!\n");
			ret_errors++;
		    } else {
			params->plugin_slink = optarg;
			if(params->plugin_slink) {
			    nmxp_log_set_prefix(params->plugin_slink);
			}
782
		    }
783 784 785
		    break;
#endif

786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
#ifdef HAVE_LIBMSEED
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
		case 'K':
		    params->flag_slinkms = 1;
		    if(params->flag_slink) {
			nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
				"Options -k and -K are declared in the same command line!\n");
			ret_errors++;
		    } else {
			params->plugin_slink = optarg;
			if(params->plugin_slink) {
			    nmxp_log_set_prefix(params->plugin_slink);
			}
		    }
		    break;
#endif
#endif

804
#ifndef HAVE_WINDOWS_H
805 806
		case 'E':
		    params->listen_port = atoi(optarg);
807
		    break;
808
#endif
809

810
		case 'F':
811
		    params->flag_buffered = 1;
812
		    params->statefile = optarg;
813 814 815 816 817 818
		    if(params->channels == NULL) {
			params->channels = get_channel_list_argument_from_state_file(params->statefile);
			if(params->channels) {
			    /* Do nothing */
			} else {
			    ret_errors++;
819 820
			    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY,
				    "State file %s not found or unable to read!\n", NMXP_LOG_STR(params->statefile));
821
			}
822 823
		    } else {
			ret_errors++;
824 825
			nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
				"Channels have been already defined by option -C!\n");
826 827 828
		    }
		    break;

829 830 831 832 833
		case 'f':
		    sep = strstr(optarg, "/");
		    if(sep) {
			sep[0] = 0;
			sep++;
834
			params->usec = atoi(optarg) * 1000;
835
			params->n_channel = atoi(sep);
836 837
			nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY,
				"Channels %d usec %d!\n", params->n_channel, params->usec);
838 839
		    } else {
			ret_errors++;
840 841
			nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
				"Syntax error in option -%c %s!\n", c, NMXP_LOG_STR(optarg));
842 843 844
		    }
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
845
		case 'g':
846 847 848
		    params->flag_logdata = 1;
		    break;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
849
		case 'G':
Matteo Quintiliani's avatar
Matteo Quintiliani committed
850
		    params->flag_logdata = 1;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
851 852 853
		    params->flag_logsample = 1;
		    break;

854
		case 'b':
855
		    params->flag_buffered = 1;
856 857
		    break;

858 859 860 861
		case 'l':
		    params->flag_listchannels = 1;
		    break;

862 863 864 865
		case 'L':
		    params->flag_listchannelsnaqs = 1;
		    break;

866 867 868 869
		case 'i':
		    params->flag_request_channelinfo = 1;
		    break;

870 871
#ifdef HAVE_LIBMSEED
		case 'm':
872 873 874 875 876 877 878 879 880 881 882 883 884
		    if(optarg && strlen(optarg) == 1) {
			params->type_writeseed = optarg[0];
			if(params->type_writeseed != TYPE_WRITESEED_SDS
				&& params->type_writeseed != TYPE_WRITESEED_BUD) {
			    ret_errors++;
			    nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
				    "Syntax error in option -%c %s!\n", c, NMXP_LOG_STR(optarg));
			}
		    } else {
			ret_errors++;
			nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY,
				"Syntax error in option -%c %s!\n", c, NMXP_LOG_STR(optarg));
		    }
885
		    break;
886 887 888
		case 'o':
		    params->outdirseed = optarg;
		    if(params->outdirseed) {
889 890 891 892 893 894
			if(nmxp_data_dir_exists(params->outdirseed)) {
			    params->outdirseed =  nmxp_data_dir_abspath(params->outdirseed);
			} else {
			    ret_errors++;
			    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY,
				    "Mini-SEED output directory %s does not exists!\n", NMXP_LOG_STR(params->outdirseed));
895 896 897
			}
		    }
		    break;
898 899 900 901 902 903 904 905 906 907 908
#endif

		case 'w':
		    params->flag_writefile = 1;
		    break;

		case 'h':
		    nmxptool_usage(long_options);
		    exit (1);
		    break;

909 910
		case 'V':
		    nmxptool_version();
Matteo Quintiliani's avatar
Matteo Quintiliani committed
911
		    nmxptool_author_support();
912 913 914
		    exit (1);
		    break;

915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
		case '?':
		    /* getopt_long already printed an error message. */
		    ret_errors++;
		    break;

		default:
		    nmxptool_usage(long_options);
		    exit (1);
	    }
	}
    }

    /* Print any remaining command line arguments (not options). */
    if (optind < argc)
    {
	ret_errors += optind;

932
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "non-option ARGV-elements: ");
Matteo Quintiliani's avatar
Matteo Quintiliani committed
933 934
	while (optind < argc) {
	    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "%s ",
935 936
		    NMXP_LOG_STR(argv[optind]));
	    optind++;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
937
	}
938 939 940 941 942 943 944
	putchar ('\n');
    }

    return ret_errors;
}


945 946 947 948 949
void nmxptool_log_params(NMXPTOOL_PARAMS *params) {
    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
    char *hostname: %s\n\
    int portnumberdap: %d\n\
    int portnumberpds: %d\n\
950
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
951
    NMXP_LOG_STR(params->hostname),
952 953 954 955 956
    params->portnumberdap,
    params->portnumberpds
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
957
    char *channels: %s\n\
958
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
959
    NMXP_LOG_STR(params->channels)
960 961 962
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
963 964 965 966 967
    char *network: %s\n\
    char *location: %s\n\
    double start_time: %f\n\
    double end_time: %f\n\
    int32_t interval: %d\n\
968
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
969 970
    NMXP_LOG_STR(params->network),
    NMXP_LOG_STR(params->location),
971 972 973 974 975 976 977
    params->start_time,
    params->end_time,
    params->interval
);


    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
978 979
    char *datas_username: %s\n\
    char *datas_password: %s\n\
980
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
981 982
    NMXP_LOG_STR(params->datas_username),
    NMXP_LOG_STR(params->datas_password)
983 984 985
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
986 987 988 989 990 991 992
    int32_t stc: %d\n\
    int32_t rate: %d\n\
    char *plugin_slink: %s\n\
    int32_t delay: %d\n\
    int32_t max_tolerable_latency: %d\n\
    int32_t timeoutrecv: %d\n\
    int32_t verbose_level: %d\n\
993 994 995
",
    params->stc,
    params->rate,
Matteo Quintiliani's avatar
Matteo Quintiliani committed
996
    NMXP_LOG_STR(params->plugin_slink),
997 998 999 1000 1001 1002 1003
    params->delay,
    params->max_tolerable_latency,
    params->timeoutrecv,
    params->verbose_level
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
1004 1005
    char *ew_configuration_file: %s\n\
    char *statefile: %s\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1006
    int32_t max_data_to_retrieve: %d\n\
1007
",
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1008 1009
    NMXP_LOG_STR(params->ew_configuration_file),
    NMXP_LOG_STR(params->statefile),
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1010
    params->max_data_to_retrieve
1011 1012 1013
);

    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_EXTRA, "\
1014
    double buffered_time: %f\n\
1015
    char type_writeseed: %c\n\
1016 1017 1018 1019 1020
    int flag_listchannels: %d\n\
    int flag_listchannelsnaqs: %d\n\
    int flag_request_channelinfo: %d\n\
    int flag_writefile: %d\n\
    int flag_slink: %d\n\
1021
    int flag_slinkms: %d\n\
1022 1023
    int flag_buffered: %d\n\
    int flag_logdata: %d\n\
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1024
    int flag_logsample: %d\n\
1025 1026
",
    params->buffered_time,
1027
    params->type_writeseed,
1028 1029 1030 1031 1032
    params->flag_listchannels,
    params->flag_listchannelsnaqs,
    params->flag_request_channelinfo,
    params->flag_writefile,
    params->flag_slink,
1033
    params->flag_slinkms,
1034
    params->flag_buffered,
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1035 1036
    params->flag_logdata,
    params->flag_logsample
1037 1038 1039
    );
}

1040 1041


1042
int nmxptool_check_params(NMXPTOOL_PARAMS *params) {
1043 1044
    int ret = 0;

1045 1046 1047
    if(params->ew_configuration_file != NULL) {
	/* Do nothing */
    } else if(params->hostname == NULL) {
1048
	ret = -1;
1049
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<hostname> is required!\n");
1050
    } else if(params->flag_listchannels) {
1051 1052 1053 1054 1055
	if(params->flag_listchannelsnaqs) {
	    ret = -1;
	    nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "-l and -L can not be used together!\n");
	}
    } else if(params->flag_listchannelsnaqs) {
1056 1057 1058
	/* Do nothing */
    } else if(params->hostname == NULL) {
	ret = -1;
1059
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<hostname> is required!\n");
1060 1061
    } else if(params->channels == NULL) {
	ret = -1;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1062
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "Channel list is required!\n");
1063
    } else if(params->start_time == 0.0 &&  params->end_time != 0.0) {
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1064
	ret = -1;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1065
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<end_time> is required when declaring <start_time>!\n");
1066
    } else if(params->start_time != 0.0  &&  params->end_time != 0.0  && params->interval != DEFAULT_INTERVAL_NO_VALUE) {
Matteo Quintiliani's avatar
Matteo Quintiliani committed
1067
	ret = -1;
1068
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<start_time> has to be used with either <end_time> or <interval>!\n");
1069 1070 1071
    } else if(params->interval != DEFAULT_INTERVAL_NO_VALUE && params->interval <= 0) {
	ret = -1;
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<interval> has to be greater than zero!\n");
1072 1073 1074
    } else if(params->interval > DEFAULT_INTERVAL_MAXIMUM) {
	ret = -1;
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<interval> has to be less than %d seconds (%d days)!\n", DEFAULT_INTERVAL_MAXIMUM, DEFAULT_INTERVAL_MAXIMUM / 86400);
1075
    } else if(params->start_time != 0.0   &&   params->end_time != 0.0
1076
	    && params->start_time >= params->end_time) {
1077
	ret = -1;
1078
	nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "<start_time> is less than <end_time>!\n");
Matteo Quintiliani's avatar