Commit 67645b5d authored by Matteo Quintiliani's avatar Matteo Quintiliani

Changes from tag nmxptool_1_2_4_beta2-branch-miniseedfiles-fixed


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@1223 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent 0dfe3174
......@@ -2,13 +2,14 @@
nmxptool Release History
#########################
* Release 1.2.4-beta2 (2009/02/16)
* Release 1.2.4-beta3 (2009/03/10)
- Improved saving of mini-SEED files into SDS and BUD structure,
now it is possible to store mini-SEED in near-real-time from NaqsServer.
- Added feature: packets converted in mini-SEED records can be directly sent
to the Seedlink server by the function send_mseed(), in place of using
the function send_raw_depoch(). (option -K or -k).
- Added feature: SeisComP templates for retrieving
Data On Demand with minimun delay
- Fixed bug: possible string overflow in nmxp_chan_lookupName()
- Added SeisComP templates for retrieving Data On Demand with minimun delay.
- Fixed bug: possible string overflow in nmxp_chan_lookupName().
* Release 1.2.3 (2009/01/15)
- Added feature: mini-SEED files can be saved directly within a
......
......@@ -11,7 +11,7 @@ m4_define([major_version], [1])
m4_define([minor_version], [2])
m4_define([micro_version], [4])
# Comment build_version for stable release
m4_define([build_version], [beta2])
m4_define([build_version], [beta3])
m4_ifdef([build_version], [
m4_define([version],
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_data.h,v 1.29 2008-11-05 14:51:28 mtheo Exp $
* $Id: nmxp_data.h,v 1.30 2009-03-10 14:34:57 mtheo Exp $
*
*/
......@@ -128,11 +128,25 @@ typedef struct {
} NMXP_DATA_PROCESS;
/*! \brief For SDS or BUD directory structure */
typedef enum {
NMXP_TYPE_WRITESEED_SDS = 0,
NMXP_TYPE_WRITESEED_BUD
} NMXP_DATA_SEED_TYPEWRITE;
#define NMXP_DATA_MAX_SIZE_FILENAME 1024
#define NMXP_DATA_MAX_NUM_OPENED_FILE 200
/*! \brief Parameter structure for functions that handle mini-seed records */
typedef struct {
char srcname[50];
FILE *outfile_mseed;
char filename_mseed[500];
int n_open_files;
int last_open_file;
int cur_open_file;
FILE *outfile_mseed[NMXP_DATA_MAX_NUM_OPENED_FILE];
char filename_mseed[NMXP_DATA_MAX_NUM_OPENED_FILE][NMXP_DATA_MAX_SIZE_FILENAME];
char outdirseed[NMXP_DATA_MAX_SIZE_FILENAME];
char default_network[5];
NMXP_DATA_SEED_TYPEWRITE type_writeseed;
NMXP_DATA_PROCESS *pd;
} NMXP_DATA_SEED;
/*! \brief Initialize a structure NMXP_DATA_PROCESS
......@@ -231,14 +245,41 @@ int nmxp_data_parse_date(const char *pstr_date, NMXP_TM_T *ret_tmt);
*/
double nmxp_data_tm_to_time(NMXP_TM_T *tmt);
/*! \brief
*/
char *nmxp_data_gnu_getcwd ();
/*! \brief
*/
int nmxp_data_mkdirp(const char *filename);
/*! \brief Initialize a structure NMXP_DATA_SEED
*
* \param data_seed Pointer to a NMXP_DATA_SEED structure.
*
*/
int nmxp_data_seed_init(NMXP_DATA_SEED *data_seed);
int nmxp_data_seed_init(NMXP_DATA_SEED *data_seed, char *default_network, char *outdirseed, NMXP_DATA_SEED_TYPEWRITE type_writeseed);
/*! \brief Open file in a structure NMXP_DATA_SEED, in case close file before.
*
* \param data_seed Pointer to a NMXP_DATA_SEED structure.
*
*/
int nmxp_data_seed_fopen(NMXP_DATA_SEED *data_seed, char *filenameseed);
/*! \brief Close file in a structure NMXP_DATA_SEED
*
* \param data_seed Pointer to a NMXP_DATA_SEED structure.
*
*/
int nmxp_data_seed_fclose(NMXP_DATA_SEED *data_seed, int i);
/*! \brief Close all file in a structure NMXP_DATA_SEED
*
* \param data_seed Pointer to a NMXP_DATA_SEED structure.
*
*/
int nmxp_data_seed_fclose_all(NMXP_DATA_SEED *data_seed);
/*! \brief Write mini-seed records from a NMXP_DATA_PROCESS structure.
*
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_data.c,v 1.62 2008-11-05 15:24:16 mtheo Exp $
* $Id: nmxp_data.c,v 1.63 2009-03-10 14:34:57 mtheo Exp $
*
*/
......@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include "config.h"
......@@ -26,7 +27,6 @@
#include <libmseed.h>
#endif
/*
For a portable version of timegm(), set the TZ environment variable to
UTC, call mktime() and restore the value of TZ. Something like
......@@ -675,30 +675,254 @@ double nmxp_data_tm_to_time(NMXP_TM_T *tmt) {
return ret_d;
}
int nmxp_data_seed_init(NMXP_DATA_SEED *data_seed) {
data_seed->srcname[0] = 0;
data_seed->outfile_mseed = NULL;
data_seed->filename_mseed[0] = 0;
return 0;
#ifdef HAVE_GETCWD
/* TODO */
#endif
char *nmxp_data_gnu_getcwd () {
size_t size = 512;
while (1)
{
char *buffer = (char *) malloc (size);
if (getcwd (buffer, size) == buffer)
return buffer;
free (buffer);
if (errno != ERANGE)
return NULL;
size *= 2;
}
}
#ifdef HAVE_MKDIR
/* TODO */
#endif
#ifdef HAVE_WINDOWS_H
const char nmxp_data_sepdir = '\\';
#else
const char nmxp_data_sepdir = '/';
#endif
int nmxp_data_mkdirp(const char *filename) {
#ifndef HAVE_WINDOWS_H
mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
#endif
char *dir = strdup(filename);
int i, l;
int error=0;
if(!filename) return -1;
dir = strdup(filename);
if(!dir) return -1;
l = strlen(dir);
i = 0;
while(i < l && error != -1) {
if(dir[i] == nmxp_data_sepdir && i > 0) {
dir[i] = 0;
/* nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "trying to create %s...\n", dir); */
if(chdir(dir) == -1) {
#ifndef HAVE_WINDOWS_H
error=mkdir(dir, mode);
#else
error=mkdir(dir);
#endif
}
dir[i] = nmxp_data_sepdir;
}
i++;
}
if(error != -1) {
#ifndef HAVE_WINDOWS_H
error=mkdir(dir, mode);
#else
error=mkdir(dir);
#endif
}
free(dir);
return error;
}
#ifdef HAVE_LIBMSEED
int nmxp_data_seed_init(NMXP_DATA_SEED *data_seed, char *outdirseed, char *default_network, NMXP_DATA_SEED_TYPEWRITE type_writeseed) {
int i;
if(outdirseed) {
strncpy(data_seed->outdirseed, outdirseed, NMXP_DATA_MAX_SIZE_FILENAME);
} else {
strncpy(data_seed->outdirseed, nmxp_data_gnu_getcwd(), NMXP_DATA_MAX_SIZE_FILENAME);
}
strncpy(data_seed->default_network, default_network, 5);
data_seed->type_writeseed = type_writeseed;
data_seed->n_open_files = 0;
data_seed->last_open_file = -1;
data_seed->cur_open_file = -1;
for(i=0; i < NMXP_DATA_MAX_NUM_OPENED_FILE; i++) {
data_seed->outfile_mseed[i] = NULL;
data_seed->filename_mseed[i][0] = 0;
}
data_seed->pd = NULL;
return 0;
}
int nmxp_data_seed_fopen(NMXP_DATA_SEED *data_seed, char *filenameseed) {
int i;
int found;
if(filenameseed) {
found=0;
i=0;
while(i < data_seed->n_open_files && !found) {
if( strcmp(filenameseed, data_seed->filename_mseed[i]) == 0) {
found = 1;
} else {
i++;
}
}
if(found) {
data_seed->cur_open_file = i;
/* nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_EXTRA, "Curr [%3d/%3d] %s\n", data_seed->cur_open_file, data_seed->n_open_files,
data_seed->filename_mseed[data_seed->cur_open_file]); */
} else {
data_seed->last_open_file = (data_seed->last_open_file + 1) % NMXP_DATA_MAX_NUM_OPENED_FILE;
nmxp_data_seed_fclose(data_seed, data_seed->last_open_file);
strncpy(data_seed->filename_mseed[data_seed->last_open_file], filenameseed, NMXP_DATA_MAX_SIZE_FILENAME);
data_seed->outfile_mseed[data_seed->last_open_file] = fopen(data_seed->filename_mseed[data_seed->last_open_file], "a+");
if(data_seed->n_open_files < NMXP_DATA_MAX_NUM_OPENED_FILE) {
data_seed->n_open_files++;
}
data_seed->cur_open_file = data_seed->last_open_file;
/* nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_EXTRA, "Open [%3d/%3d] %s\n", data_seed->cur_open_file, data_seed->n_open_files,
data_seed->filename_mseed[data_seed->cur_open_file]); */
}
}
return 0;
}
int nmxp_data_seed_fclose(NMXP_DATA_SEED *data_seed, int i) {
if(i >= 0 && i < NMXP_DATA_MAX_NUM_OPENED_FILE) {
if(data_seed->outfile_mseed[i]) {
/* nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_EXTRA, "Close [%3d/%3d] %s\n", i, data_seed->n_open_files, data_seed->filename_mseed[i]); */
fclose(data_seed->outfile_mseed[i]);
data_seed->outfile_mseed[i] = NULL;
data_seed->filename_mseed[i][0] = 0;
}
}
return 0;
}
int nmxp_data_seed_fclose_all(NMXP_DATA_SEED *data_seed) {
int i;
for(i=0; i < NMXP_DATA_MAX_NUM_OPENED_FILE; i++) {
nmxp_data_seed_fclose(data_seed, i);
}
data_seed->n_open_files = 0;
data_seed->last_open_file = -1;
data_seed->cur_open_file = -1;
return 0;
}
#define NMXP_DATA_NETCODE_OR_DEFAULT_NETWORK ( ( (data_seed->pd) && (data_seed->pd->network[0] != 0) )? data_seed->pd->network : data_seed->default_network )
int nmxp_data_get_filename_ms(NMXP_DATA_SEED *data_seed, char *dirseedchan, char *filenameseed) {
int ret = 0;
dirseedchan[0] = 0;
filenameseed[0] = 0;
if(data_seed->type_writeseed == NMXP_TYPE_WRITESEED_SDS) {
snprintf(dirseedchan, NMXP_DATA_MAX_SIZE_FILENAME, "%s%c%d%c%s%c%s%c%s.D", data_seed->outdirseed, nmxp_data_sepdir,
nmxp_data_year_from_epoch(data_seed->pd->time),
nmxp_data_sepdir,
NMXP_DATA_NETCODE_OR_DEFAULT_NETWORK,
nmxp_data_sepdir,
data_seed->pd->station,
nmxp_data_sepdir,
data_seed->pd->channel);
snprintf(filenameseed, NMXP_DATA_MAX_SIZE_FILENAME, "%s.%s..%s.D.%d.%03d",
NMXP_DATA_NETCODE_OR_DEFAULT_NETWORK,
data_seed->pd->station,
data_seed->pd->channel,
nmxp_data_year_from_epoch(data_seed->pd->time),
nmxp_data_yday_from_epoch(data_seed->pd->time));
} else if(data_seed->type_writeseed == NMXP_TYPE_WRITESEED_BUD) {
snprintf(dirseedchan, NMXP_DATA_MAX_SIZE_FILENAME, "%s%c%s%c%s", data_seed->outdirseed,
nmxp_data_sepdir,
NMXP_DATA_NETCODE_OR_DEFAULT_NETWORK,
nmxp_data_sepdir,
data_seed->pd->station);
snprintf(filenameseed, NMXP_DATA_MAX_SIZE_FILENAME, "%s.%s..%s.%d.%03d",
data_seed->pd->station,
NMXP_DATA_NETCODE_OR_DEFAULT_NETWORK,
data_seed->pd->channel,
nmxp_data_year_from_epoch(data_seed->pd->time),
nmxp_data_yday_from_epoch(data_seed->pd->time));
}
return ret;
}
/* Private function for writing mini-seed records */
static void nmxp_data_msr_write_handler (char *record, int reclen, void *pdata_seed) {
NMXP_DATA_SEED *data_seed = pdata_seed;
if( data_seed->outfile_mseed ) {
if ( fwrite(record, reclen, 1, data_seed->outfile_mseed) != 1 ) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN,
"Error writing %s to output file\n", data_seed->filename_mseed);
static void nmxp_data_msr_write_handler (char *record, int reclen, void *pdata_seed) {
int err = 0;
NMXP_DATA_SEED *data_seed = pdata_seed;
char filenameseed[NMXP_DATA_MAX_SIZE_FILENAME];
char dirseedchan[NMXP_DATA_MAX_SIZE_FILENAME];
if(data_seed->pd == NULL) {
err++;
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_EXTRA, "pd is NULL in nmxp_data_msr_write_handler()!\n");
}
if(err==0) {
nmxp_data_get_filename_ms(data_seed, dirseedchan, filenameseed);
}
if(err==0) {
if(chdir(dirseedchan) == -1) {
/* nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_EXTRA, "Directory %s does not exist!\n", dirseedchan); */
if(nmxp_data_mkdirp(dirseedchan) == -1) {
err++;
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_EXTRA, "Directory %s has not been created!\n", dirseedchan);
} else {
/* nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Directory %s created!\n", dirseedchan); */
if(chdir(dirseedchan) == -1) {
err++;
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_EXTRA, "Directory %s should be created but it does not exist!\n", dirseedchan);
}
}
} else {
/*
/* nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Directory %s exists!\n", dirseedchan); */
}
}
if(err==0) {
nmxp_data_seed_fopen(data_seed, filenameseed);
if( data_seed->outfile_mseed[data_seed->cur_open_file] ) {
if ( fwrite(record, reclen, 1, data_seed->outfile_mseed[data_seed->cur_open_file]) != 1 ) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN,
"Error opening file %s\n", data_seed->filename_mseed);
*/
"Error writing %s to output file\n", data_seed->filename_mseed[data_seed->cur_open_file]);
}
} else {
/* nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Error opening file %s\n", data_seed->filename_mseed); */
}
}
}
int nmxp_data_msr_pack(NMXP_DATA_PROCESS *pd, NMXP_DATA_SEED *data_seed, void *pmsr) {
......@@ -732,14 +956,16 @@ int nmxp_data_msr_pack(NMXP_DATA_PROCESS *pd, NMXP_DATA_SEED *data_seed, void *p
msr->datasamples = NMXP_MEM_MALLOC (sizeof(int) * (msr->numsamples));
memcpy(msr->datasamples, pd->pDataPtr, sizeof(int) * pd->nSamp); /* pointer to 32-bit integer data samples */
msr_srcname (msr, data_seed->srcname, 0);
pDataDest = msr->datasamples;
/* msr_print(msr, 2); */
data_seed->pd = pd;
/* Pack the record(s) */
precords = msr_pack (msr, &nmxp_data_msr_write_handler, data_seed->srcname, &psamples, 1, verbose);
precords = msr_pack (msr, &nmxp_data_msr_write_handler, data_seed, &psamples, 1, verbose);
data_seed->pd = NULL;
if ( precords == -1 ) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN,
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool.c,v 1.209 2009-02-16 07:51:50 mtheo Exp $
* $Id: nmxptool.c,v 1.210 2009-03-10 14:34:57 mtheo Exp $
*
*/
......@@ -122,57 +122,6 @@ MSRecord *msr_list_chan[MAX_N_CHAN];
int ew_check_flag_terminate = 0;
#ifdef HAVE_WINDOWS_H
const char sepdir = '\\';
#else
const char sepdir = '/';
#endif
#ifdef HAVE_MKDIR
/* TODO */
#endif
int mkdirp(const char *filename) {
#ifndef HAVE_WINDOWS_H
mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
#endif
char *dir = strdup(filename);
int i, l;
int error=0;
if(!filename) return -1;
dir = strdup(filename);
if(!dir) return -1;
l = strlen(dir);
i = 0;
while(i < l && error != -1) {
if(dir[i] == sepdir && i > 0) {
dir[i] = 0;
/* nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "trying to create %s...\n", dir); */
if(chdir(dir) == -1) {
#ifndef HAVE_WINDOWS_H
error=mkdir(dir, mode);
#else
error=mkdir(dir);
#endif
}
dir[i] = sepdir;
}
i++;
}
if(error != -1) {
#ifndef HAVE_WINDOWS_H
error=mkdir(dir, mode);
#else
error=mkdir(dir);
#endif
}
free(dir);
return error;
}
int main (int argc, char **argv) {
int32_t connection_time;
int request_SOCKET_OK;
......@@ -202,7 +151,6 @@ int main (int argc, char **argv) {
int recv_errno = 0;
char dirseedchan[1024];
char filename[500] = "";
char station_code[20] = "", channel_code[20] = "", network_code[20] = "";
......@@ -319,7 +267,9 @@ int main (int argc, char **argv) {
if(params.type_writeseed) {
ms_loginit((void*)&nmxptool_log_miniseed, NULL, (void*)&nmxptool_logerr_miniseed, "error: ");
/* Init mini-SEED variables */
nmxp_data_seed_init(&data_seed);
nmxp_data_seed_init(&data_seed, params.outdirseed,
CURRENT_NETWORK,
(params.type_writeseed == TYPE_WRITESEED_BUD)? NMXP_TYPE_WRITESEED_BUD : NMXP_TYPE_WRITESEED_SDS);
}
#endif
......@@ -597,116 +547,6 @@ int main (int argc, char **argv) {
}
}
#ifdef HAVE_LIBMSEED
if(params.type_writeseed) {
/* Open output Mini-SEED file */
if(nmxp_chan_cpy_sta_chan(channelList_subset->channel[request_chan].name, station_code, channel_code, network_code)) {
if(params.type_writeseed == TYPE_WRITESEED_BUD) {
sprintf(dirseedchan, "%s%c%s%c%s", params.outdirseed, sepdir,
NETCODE_OR_CURRENT_NETWORK, sepdir,
station_code);
} else {
sprintf(dirseedchan, "%s%c%d%c%s%c%s%c%s.D", params.outdirseed, sepdir,
nmxp_data_year_from_epoch(params.start_time), sepdir,
NETCODE_OR_CURRENT_NETWORK, sepdir,
station_code, sepdir,
channel_code);
}
if(chdir(dirseedchan) == -1) {
/* nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_EXTRA, "Directory %s does not exist!\n", dirseedchan); */
if(mkdirp(dirseedchan) == -1) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_EXTRA, "Directory %s has not been created!\n", dirseedchan);
} else {
/* nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Directory %s created!\n", dirseedchan); */
if(chdir(dirseedchan) == -1) {
/* ERROR */
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_EXTRA, "Directory %s should be created but it does not exist!\n", dirseedchan);
}
}
} else {
/* nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "Directory %s exists!\n", dirseedchan); */
}
/*
sprintf(data_seed.filename_mseed, "%s.%s.%s_%s_%s.miniseed",
NETCODE_OR_CURRENT_NETWORK,
station_code,
channel_code,
str_start_time,
str_end_time);
*/
/* TODO if the requested data covers different days
* filename contains also the year and the yday of the end time, this breaks both SDS and BUD structure */
if( ( nmxp_data_year_from_epoch(params.start_time) == nmxp_data_year_from_epoch(params.end_time) )
&& ( nmxp_data_yday_from_epoch(params.start_time) == nmxp_data_yday_from_epoch(params.end_time)) ) {
if(params.type_writeseed == TYPE_WRITESEED_BUD) {
sprintf(data_seed.filename_mseed, "%s.%s..%s.%d.%03d",
station_code,
NETCODE_OR_CURRENT_NETWORK,
channel_code,
nmxp_data_year_from_epoch(params.start_time),
nmxp_data_yday_from_epoch(params.start_time));
} else {
sprintf(data_seed.filename_mseed, "%s.%s..%s.D.%d.%03d",
NETCODE_OR_CURRENT_NETWORK,
station_code,
channel_code,
nmxp_data_year_from_epoch(params.start_time),
nmxp_data_yday_from_epoch(params.start_time));
}
} else {
if(params.type_writeseed == TYPE_WRITESEED_BUD) {
sprintf(data_seed.filename_mseed, "%s.%s..%s.%d.%03d-%d.%03d",
station_code,
NETCODE_OR_CURRENT_NETWORK,
channel_code,
nmxp_data_year_from_epoch(params.start_time),
nmxp_data_yday_from_epoch(params.start_time),
nmxp_data_year_from_epoch(params.end_time),
nmxp_data_yday_from_epoch(params.end_time));
} else {
sprintf(data_seed.filename_mseed, "%s.%s..%s.D.%d.%03d-%d.%03d",
NETCODE_OR_CURRENT_NETWORK,
station_code,
channel_code,
nmxp_data_year_from_epoch(params.start_time),
nmxp_data_yday_from_epoch(params.start_time),
nmxp_data_year_from_epoch(params.end_time),
nmxp_data_yday_from_epoch(params.end_time));
}
}
} else {
sprintf(filename, "%s_%s_%s.miniseed",
channelList_subset->channel[request_chan].name,
str_start_time,
str_end_time);
}
data_seed.outfile_mseed = fopen(data_seed.filename_mseed, "r");
if(data_seed.outfile_mseed) {
nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "File %s already exist. It will not be overrode.\n",
NMXP_LOG_STR(data_seed.filename_mseed));
fclose(data_seed.outfile_mseed);
data_seed.outfile_mseed = NULL;
} else {
data_seed.outfile_mseed = fopen(data_seed.filename_mseed, "w");
if(!data_seed.outfile_mseed) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_EXTRA, "Can not open file %s!\n",
NMXP_LOG_STR(data_seed.filename_mseed));
}
}
}
#endif
if(params.flag_writefile && outfile) {
/* Compute SNCL line */
......@@ -823,14 +663,6 @@ int main (int argc, char **argv) {
outfile = NULL;
}
#ifdef HAVE_LIBMSEED
if(params.type_writeseed && data_seed.outfile_mseed) {
/* Close output Mini-SEED file */
fclose(data_seed.outfile_mseed);
data_seed.outfile_mseed = NULL;
}
#endif
} else {
/* TODO: error message */
}
......@@ -872,6 +704,12 @@ int main (int argc, char **argv) {
} /* END while(exitdapcondition) */
#ifdef HAVE_LIBMSEED
if(params.type_writeseed) {
nmxp_data_seed_fclose_all(&data_seed);
}
#endif
/* DAP Step 8: Send a Terminate message (optional) */
nmxp_sendTerminateSubscription(naqssock, NMXP_SHUTDOWN_NORMAL, "Bye!");
......@@ -926,23 +764,6 @@ int main (int argc, char **argv) {
channelList_subset_waste = NULL;
}
#ifdef HAVE_LIBMSEED
if(params.type_writeseed) {
/* Open output Mini-SEED file */
sprintf(data_seed.filename_mseed, "%s.realtime.miniseed",
CURRENT_NETWORK);
data_seed.outfile_mseed = fopen(data_seed.filename_mseed, "w");
if(!data_seed.outfile_mseed) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_EXTRA, "Can not open file %s!\n",
NMXP_LOG_STR(data_seed.filename_mseed));
} else {
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_EXTRA, "Opened file %s!\n",
NMXP_LOG_STR(data_seed.filename_mseed));
}
}
#endif
/* PDS Step 4: Send a Request Pending (optional) */
/* PDS Step 5: Send AddChannels */
......@@ -1169,9 +990,8 @@ int main (int argc, char **argv) {
flushing_raw_data_stream();
#ifdef HAVE_LIBMSEED
if(params.type_writeseed && data_seed.outfile_mseed) {
/* Close output Mini-SEED file */
fclose(data_seed.outfile_mseed);
if(params.type_writeseed) {
nmxp_data_seed_fclose_all(&data_seed);
}
#endif
......@@ -1547,8 +1367,6 @@ int nmxptool_msr_send_mseed(NMXP_DATA_PROCESS *pd) {
msr->datasamples = NMXP_MEM_MALLOC (sizeof(int) * (msr->numsamples));
memcpy(msr->datasamples, pd->pDataPtr, sizeof(int) * pd->nSamp); /* pointer to 32-bit integer data samples */
/* ??? TODO msr_srcname (msr, data_seed->srcname, 0); ??? */
/* msr_print(msr, 2); */
precords = msr_pack (msr, &nmxptool_msr_send_mseed_handler, pd, &psamples, flush, verbose);
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool_getoptlong.c,v 1.110 2009-03-09 14:54:21 mtheo Exp $
* $Id: nmxptool_getoptlong.c,v 1.111 2009-03-10 14:34:57 mtheo Exp $
*
*/
......@@ -66,24 +66,6 @@ const NMXPTOOL_PARAMS NMXPTOOL_PARAMS_DEFAULT =
};
#ifdef HAVE_GETCWD
/* TODO */
#endif
char *gnu_getcwd () {
size_t size = 512;
while (1)
{
char *buffer = (char *) malloc (size);
if (getcwd (buffer, size) == buffer)
return buffer;
free (buffer);
if (errno != ERANGE)
return NULL;
size *= 2;
}
}
void nmxptool_author_support() {
nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
Matteo Quintiliani - Istituto Nazionale di Geofisica e Vulcanologia - Italy\n\
......@@ -190,7 +172,7 @@ NMXP_LOG_STR(DAP_VERSION)
#ifdef HAVE___SRC_SEEDLINK_PLUGIN_C
nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
%s <option ... option> -k\n\
%s <option ... option> [ -k | -K ]\n\
Launched as SeedLink plug-in to feed the SL-Server.\n\
\n", NMXP_LOG_STR(PACKAGE_NAME));
#endif
......@@ -359,7 +341,7 @@ Other arguments:\n\
-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\
Related to -o.\n",
Packets are appended to existing files. Related to -o.\n",
TYPE_WRITESEED_SDS, TYPE_WRITESEED_BUD,
TYPE_WRITESEED_SDS, TYPE_WRITESEED_BUD);
nmxp_log(NMXP_LOG_NORM_NO, NMXP_LOG_D_ANY, "\
......@@ -900,7 +882,7 @@ int nmxptool_getopt_long(int argc, char **argv, NMXPTOOL_PARAMS *params)
params->outdirseed = optarg;
if(params->outdirseed) {
if(chdir(params->outdirseed) == 0) {
params->outdirseed = gnu_getcwd();
params->outdirseed = nmxp_data_gnu_getcwd();
}
}
break;
......@@ -1130,7 +1112,7 @@ int nmxptool_check_params(NMXPTOOL_PARAMS *params) {
} else {