Commit 367b1666 authored by Matteo Quintiliani's avatar Matteo Quintiliani
Browse files

Added nmxp_chan_cpy_sta_chan()


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@130 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent d719e195
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -47,6 +47,21 @@ typedef enum {



/*! \brief Copy station code and channel code from name
 *
 * \param name string containing STA.CHAN
 * \param[out] station_code Pointer to string for station code
 * \param[out] channel_code Pointer to string for char code
 *
 * \warning Parametes can not be NULL!
 *
 * \retval 1 on success
 * \retval 0 on error
 *
 */
int nmxp_chan_cpy_sta_chan(const char *station_dot_channel, char *station_code, char *channel_code);


/*! \brief Match station_dot_channel against pattern, treating errors as no match.
 *
 * \param station_dot_channel STA.CHAN format
+31 −0
Original line number Diff line number Diff line
@@ -15,6 +15,37 @@
#include <string.h>
#include <stdlib.h>

int nmxp_chan_cpy_sta_chan(const char *station_dot_channel, char *station_code, char *channel_code) {
    int ret = 0;
    char *sta_code_tmp, *cha_code_tmp;

    if(station_dot_channel || station_code || channel_code) {
	station_code[0] = 0;
	channel_code[0] = 0;

	/* validate pattern channel */
	sta_code_tmp = strdup(station_dot_channel);
	if( (cha_code_tmp = strchr(sta_code_tmp, '.')) == NULL ) {
	    nmxp_log(1, 0, "Name %s is not in STA.CHAN format!\n", station_dot_channel);
	} else {
	    if(cha_code_tmp) {
		*cha_code_tmp++ = '\0';
		strcpy(station_code, sta_code_tmp);
		strcpy(channel_code, cha_code_tmp);
		free(sta_code_tmp);
		ret = 1;
	    } else {
		nmxp_log(1, 0, "Name %s is not in STA.CHAN format! Channel is missing?\n", station_dot_channel);
	    }
	}
    } else {
	nmxp_log(1, 0, "Some parameter is NULL in nmxp_chan_cpy_sta_chan().\n",  station_dot_channel);
    }

    return ret;
}



/*
 * Match string against the extended regular expression in
+7 −8
Original line number Diff line number Diff line
@@ -442,7 +442,7 @@ int nmxp_data_msr_pack(NMXP_DATA_PROCESS *pd, NMXP_DATA_SEED *data_seed, void *p
    MSRecord *msr = pmsr;
    int psamples;
    int precords;
    flag verbose = 1;
    flag verbose = 0;

    int *pDataDest = NULL;

@@ -469,19 +469,18 @@ int nmxp_data_msr_pack(NMXP_DATA_PROCESS *pd, NMXP_DATA_SEED *data_seed, void *p
	msr_srcname (msr, data_seed->srcname, 0);

	pDataDest = msr->datasamples;
	nmxp_log(0, 0, "x0 %d, xn %d\n", pDataDest[0], pDataDest[msr->numsamples-1]);
	nmxp_log(0, 1, "x0 %d, xn %d\n", pDataDest[0], pDataDest[msr->numsamples-1]);

	/* Pack the record(s) */
	msr_print(msr, 2);
	/* msr_print(msr, 2); */

	/* Pack the record(s) */
	precords = msr_pack (msr, &nmxp_data_msr_write_handler, data_seed->srcname, &psamples, 1, verbose);

	msr_print(msr, 2);

	if ( precords == -1 )
	    ms_log (2, "Cannot pack records\n");
	else
	    ms_log (1, "Packed %d samples into %d records\n", psamples, precords);
	else {
	    /* ms_log (1, "Packed %d samples into %d records\n", psamples, precords); */
	}

    }