Commit 647b6b2a authored by Matteo Quintiliani's avatar Matteo Quintiliani
Browse files

Added function nmxp_chan_subset()


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@50 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent 94e4e7db
......@@ -38,6 +38,10 @@ typedef enum {
} NMXP_DATATYPE;
/*! \brief Return type of data from a channel key */
#define getDataTypeFromKey(key) ((key >> 8) & 0xff)
/*! \brief Looks up a channel key in the list using the name
*
* \param name Channel name.
......@@ -58,6 +62,7 @@ int nmxp_chan_lookupKey(char* name, NMXP_CHAN_LIST *channelList);
*/
char *nmxp_chan_lookupName(uint32_t key, NMXP_CHAN_LIST *channelList);
/*! \brief Looks up a channel with specified data type.
*
* \param channelList Channel list.
......@@ -71,6 +76,20 @@ char *nmxp_chan_lookupName(uint32_t key, NMXP_CHAN_LIST *channelList);
NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dataType);
/*! \brief Looks up a channel with specified data type.
*
* \param channelList Channel list.
* \param dataType Type of channel.
* \param sta_chan_list String list of item STA.CHAN, separeted by space
*
* \return Channel list with specified dataType. It will need to be freed!
*
* \warning Returned value will need to be freed!
*
*/
NMXP_CHAN_LIST *nmxp_chan_subset(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dataType, char *sta_chan_list);
/*! Sort list by channel key
*
* \param channelList Channel List
......
......@@ -53,7 +53,7 @@ NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dat
for (i_chan = 0; i_chan < chan_number; i_chan++)
{
if ( ((channelList->channel[i_chan].key >> 8) & 0xff) == dataType) {
if ( getDataTypeFromKey(channelList->channel[i_chan].key) == dataType) {
ret_channelList->channel[ret_channelList->number].key = channelList->channel[i_chan].key;
strcpy(ret_channelList->channel[ret_channelList->number].name, channelList->channel[i_chan].name);
ret_channelList->number++;
......@@ -64,6 +64,31 @@ NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dat
}
NMXP_CHAN_LIST *nmxp_chan_subset(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dataType, char *sta_chan_list) {
NMXP_CHAN_LIST *ret_channelList = NULL;
int chan_number = channelList->number;
int i_chan = 0;
ret_channelList = (NMXP_CHAN_LIST *) malloc(sizeof(NMXP_CHAN_LIST));
ret_channelList->number = 0;
for (i_chan = 0; i_chan < chan_number; i_chan++)
{
if ( getDataTypeFromKey(channelList->channel[i_chan].key) == dataType) {
if(strstr(sta_chan_list, channelList->channel[i_chan].name)) {
// TODO improve the previous check if needed
ret_channelList->channel[ret_channelList->number].key = channelList->channel[i_chan].key;
strcpy(ret_channelList->channel[ret_channelList->number].name, channelList->channel[i_chan].name);
ret_channelList->number++;
}
}
}
return ret_channelList;
}
// Comparison Key Function
int chan_key_compare(const void *a, const void *b)
{
......
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