Commit d13ef2e7 authored by Roman Racine's avatar Roman Racine

Fixed memory leak, libmseed users can now chose beteween steim1 and steim2

and chose the data quality header


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@1323 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent b268ebf0
......@@ -7,12 +7,11 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool.c,v 1.222 2010-08-20 05:53:58 racine Exp $
* $Id: nmxptool.c,v 1.223 2010-08-25 20:37:48 racine Exp $
*
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -160,7 +159,7 @@ int main (int argc, char **argv) {
int times_flow = 0;
int recv_errno = 0;
char *recv_errno_str;
/* char *recv_errno_str; */
char filename[500] = "";
char station_code[20] = "", channel_code[20] = "", network_code[20] = "";
......@@ -398,13 +397,13 @@ int main (int argc, char **argv) {
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_EXTRA, "%s.%s.%s\n",
NMXP_LOG_STR(NETCODE_OR_CURRENT_NETWORK), NMXP_LOG_STR(station_code), NMXP_LOG_STR(channel_code));
strncpy(msr_list_chan[i_chan]->network, NETCODE_OR_CURRENT_NETWORK, 11);
strncpy(msr_list_chan[i_chan]->station, station_code, 11);
strncpy(msr_list_chan[i_chan]->channel, channel_code, 11);
msr_list_chan[i_chan]->reclen = 512; /* byte record length */
msr_list_chan[i_chan]->encoding = DE_STEIM1; /* Steim 1 compression */
msr_list_chan[i_chan]->encoding = params.encoding; /* Steim 1 compression by default */
} else {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_CHANNEL,
......@@ -604,7 +603,6 @@ int main (int argc, char **argv) {
&& data_seed.err_general==0
#endif
) {
/* Process a packet and return value in NMXP_DATA_PROCESS structure */ /*STEFANO*/
if (pd != NULL) {
......@@ -621,6 +619,12 @@ int main (int argc, char **argv) {
pd->timing_quality = params.timing_quality;
}
/* set the data quality indicator */
if (pd) {
pd->quality_indicator = params.quality_indicator;
}
nmxp_data_trim(pd, params.start_time, params.end_time, 0);
/* To prevent to manage a packet with zero sample after nmxp_data_trim() */
......@@ -829,7 +833,7 @@ int main (int argc, char **argv) {
already_listen = 1;
pthread_attr_init(&attr_socket_listen);
pthread_attr_setdetachstate(&attr_socket_listen, PTHREAD_CREATE_DETACHED);
pthread_create(&thread_socket_listen, &attr_socket_listen, nmxptool_listen, (void *)params.listen_port);
pthread_create(&thread_socket_listen, &attr_socket_listen, nmxptool_listen, (void *) &params.listen_port);
pthread_attr_destroy(&attr_socket_listen);
}
#endif
......@@ -848,15 +852,30 @@ int main (int argc, char **argv) {
&& data_seed.err_general==0
#endif
) {
/* added 2010-07-26, RR */
if (pd != NULL) {
if (pd->pDataPtr != NULL) {
NMXP_MEM_FREE(pd->pDataPtr);
}
NMXP_MEM_FREE(pd);
}
/* Process Compressed or Decompressed Data */
pd = nmxp_receiveData(naqssock, channelList_subset, NETCODE_OR_CURRENT_NETWORK, params.timeoutrecv, &recv_errno);
/* Force value for timing_quality if declared in the command-line */
if(pd && params.timing_quality != -1) {
pd->timing_quality = params.timing_quality;
}
/* set the data quality indicator */
if (pd) {
pd->quality_indicator = params.quality_indicator;
}
if(!pd) {
pd_null_count++;
if((pd_null_count * params.timeoutrecv) >= timeoutrecv_warning) {
......@@ -1096,7 +1115,7 @@ int main (int argc, char **argv) {
if(*msr_list_chan) {
for(i_chan = 0; i_chan < channelList_subset->number; i_chan++) {
if(msr_list_chan[i_chan]) {
msr_free(&(msr_list_chan[i_chan]));
msr_free(&(msr_list_chan[i_chan]));
}
}
}
......@@ -1453,12 +1472,14 @@ int nmxptool_msr_send_mseed(NMXP_DATA_PROCESS *pd) {
msr->numsamples = pd->nSamp;
msr->datasamples = NMXP_MEM_MALLOC (sizeof(int) * (msr->numsamples));
msr->dataquality = pd->quality_indicator;
memcpy(msr->datasamples, pd->pDataPtr, sizeof(int) * pd->nSamp); /* pointer to 32-bit integer data samples */
/* msr_print(msr, 2); */
precords = msr_pack (msr, &nmxptool_msr_send_mseed_handler, pd, &psamples, flush, verbose);
NMXP_MEM_FREE(msr->datasamples);
if ( precords == -1 ) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN,
"Cannot pack records %s.%s.%s\n", pd->network, pd->station, pd->channel);
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool_chanseq.c,v 1.1 2008-04-09 07:58:07 mtheo Exp $
* $Id: nmxptool_chanseq.c,v 1.2 2010-08-25 20:37:48 racine Exp $
*
*/
......@@ -175,7 +175,7 @@ void nmxptool_chanseq_load_states(NMXP_CHAN_LIST_NET *chan_list, NMXPTOOL_CHAN_S
if(statefile) {
strncpy(statefilefilename, statefile, MAX_LEN_FILENAME);
strncat(statefilefilename, NMXP_STR_STATE_EXT, MAX_LEN_FILENAME);
strncat(statefilefilename, NMXP_STR_STATE_EXT, MAX_LEN_FILENAME - strlen(statefile));
fstatefile = fopen(statefilefilename, "r");
if(fstatefile == NULL) {
fstatefileINPUT = fopen(statefile, "r");
......@@ -202,7 +202,7 @@ void nmxptool_chanseq_load_states(NMXP_CHAN_LIST_NET *chan_list, NMXPTOOL_CHAN_S
if(statefile) {
strncpy(statefilefilename, statefile, MAX_LEN_FILENAME);
strncat(statefilefilename, NMXP_STR_STATE_EXT, MAX_LEN_FILENAME);
strncat(statefilefilename, NMXP_STR_STATE_EXT, MAX_LEN_FILENAME - strlen(statefile));
fstatefile = fopen(statefilefilename, "r");
if(fstatefile == NULL) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_CHANSTATE, "Unable to read channel states from %s!\n",
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool_getoptlong.c,v 1.114 2009-09-24 04:20:49 mtheo Exp $
* $Id: nmxptool_getoptlong.c,v 1.115 2010-08-25 20:37:48 racine Exp $
*
*/
......@@ -23,7 +23,6 @@
#include "nmxptool_getoptlong.h"
const NMXPTOOL_PARAMS NMXPTOOL_PARAMS_DEFAULT =
{
NULL,
......@@ -55,6 +54,8 @@ const NMXPTOOL_PARAMS NMXPTOOL_PARAMS_DEFAULT =
DEFAULT_NETWORKDELAY,
DEFAULT_LISTEN_PORT,
DEFAULT_TIMING_QUALITY,
DEFAULT_QUALITY_INDICATOR,
DEFAULT_ENCODING,
0,
0,
0,
......@@ -353,6 +354,12 @@ Other arguments:\n\
nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
-o, --outdirseed=DIR Output directory for SDS or BUD structure.\n\
Related to -m (default is current directory).\n");
nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
-q, --quality_indicator=IND Set the quality indicator to the given character. Seed 2.4 \n\
supports D (indeterminate), R (raw data), Q (quality controlled data) \n\
and M (data center modified). Defaults to D.\n");
nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
-x, --encoding=ENC Set the encoding. Either steim1 or steim2, defaults to steim1\n");
#endif
nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
......@@ -454,7 +461,7 @@ char *get_channel_list_argument_from_state_file(const char *filename) {
strncpy(ret_channel_string, str_chan, MAXSIZECHANNELSTRINGARGUMENT);
} else {
strncat(ret_channel_string, ",", MAXSIZECHANNELSTRINGARGUMENT);
strncat(ret_channel_string, str_chan, MAXSIZECHANNELSTRINGARGUMENT);
strncat(ret_channel_string, str_chan, MAXSIZECHANNELSTRINGARGUMENT-3);
}
}
fclose(fstatefile);
......@@ -573,6 +580,8 @@ int nmxptool_getopt_long(int argc, char **argv, NMXPTOOL_PARAMS *params)
#ifdef HAVE_LIBMSEED
{"writeseed", required_argument, NULL, 'm'},
{"outdirseed", required_argument, NULL, 'o'},
{"quality_indicator", required_argument, NULL, 'q'},
{"encoding", required_argument, NULL, 'x'},
#endif
{"writefile", no_argument, NULL, 'w'},
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
......@@ -602,6 +611,8 @@ int nmxptool_getopt_long(int argc, char **argv, NMXPTOOL_PARAMS *params)
#ifdef HAVE_LIBMSEED
strcat(optstr, "m:");
strcat(optstr, "o:");
strcat(optstr, "q:");
strcat(optstr, "x:");
#endif
strcat(optstr, "Q:");
......@@ -904,10 +915,36 @@ int nmxptool_getopt_long(int argc, char **argv, NMXPTOOL_PARAMS *params)
} 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));
"Mini-SEED output directory %s does not exist!\n", NMXP_LOG_STR(params->outdirseed));
}
}
break;
case 'q':
switch(optarg[0]) {
case 'D':
case 'R':
case 'Q':
case 'M':
params->quality_indicator = optarg[0];
break;
default:
ret_errors++;
nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY,
"Quality indicator %s is invalid! Must be D, R, Q or M!\n", NMXP_LOG_STR(optarg));
break;
}
break;
case 'x':
if (strcmp(optarg,"steim1") == 0) {
params->encoding = DE_STEIM1;
} else if (strcmp(optarg,"steim2") == 0) {
params->encoding = DE_STEIM2;
} else {
ret_errors++;
nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY,
"Encoding %s is invalid! Must either be steim1 or steim2!\n",NMXP_LOG_STR(optarg));
}
break;
#endif
case 'w':
......
......@@ -7,13 +7,18 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool_getoptlong.h,v 1.106 2010-03-25 12:53:15 mtheo Exp $
* $Id: nmxptool_getoptlong.h,v 1.107 2010-08-25 20:37:48 racine Exp $
*
*/
#ifndef NMXPTOOL_GETLONG_H
#define NMXPTOOL_GETLONG_H 1
#ifdef HAVE_LIBMSEED
#include <libmseed.h>
#endif
#include <getopt.h>
#include <stdint.h>
......@@ -65,6 +70,15 @@
#define DEFAULT_NETWORKDELAY_MINIMUM 3
#define DEFAULT_NETWORKDELAY_MAXIMUM 60
/* RR */
#define DEFAULT_QUALITY_INDICATOR 'D'
#ifdef HAVE_LIBMSEED
#define DEFAULT_ENCODING DE_STEIM1
#else
#define DEFAULT_ENCODING 0
#endif
/* Empiric constant values TODO */
#define DEFAULT_N_CHANNEL 9
#define DEFAULT_N_CHANNEL_MINIMUM 3
......@@ -111,6 +125,9 @@ typedef struct {
int networkdelay; /* sleep 'networkdelay' seconds before reconnect */
int listen_port; /* */
int timing_quality; /* timing quality parameter for functions send_raw*() */
/* RR */
char quality_indicator;
int8_t encoding;
int flag_listchannels;
int flag_listchannelsnaqs;
int flag_request_channelinfo;
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool_listen.c,v 1.9 2009-08-16 07:12:16 mtheo Exp $
* $Id: nmxptool_listen.c,v 1.10 2010-08-25 20:37:48 racine Exp $
*
*/
......@@ -365,7 +365,7 @@ int nmxptool_listen_print_seq_no(NMXP_DATA_PROCESS *pd) {
void *nmxptool_listen(void *arg)
{
int port_socket_listen = (int) arg;
int port_socket_listen = *(int*)arg;
int sockfd, new_fd; // listen on sock_fd, new connection on new_fd
struct sockaddr_in my_addr; // my address information
struct sockaddr_in their_addr; // connector's address information
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment