nmxp_chan.h 7.14 KB
Newer Older
1 2
/*! \file
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
3
 * \brief Channels for Nanometrics Protocol Library
4 5 6 7 8 9
 *
 * Author:
 * 	Matteo Quintiliani
 * 	Istituto Nazionale di Geofisica e Vulcanologia - Italy
 *	quintiliani@ingv.it
 *
10
 * $Id: nmxp_chan.h,v 1.27 2010-09-14 09:38:52 mtheo Exp $
Matteo Quintiliani's avatar
Matteo Quintiliani committed
11
 *
12 13 14 15 16
 */

#ifndef NMXP_CHAN_H
#define NMXP_CHAN_H 1

17
#include <stdint.h>
18

19 20
#define NMXP_CHAN_MAX_SIZE_STR_PATTERN 20

Matteo Quintiliani's avatar
Matteo Quintiliani committed
21 22 23 24 25 26 27 28 29 30
/*! \brief Channel list */
typedef struct NMXP_META_CHAN_LIST {
    int32_t key;
    char name[12];
    int32_t start_time;
    int32_t end_time;
    char network[12];
    struct NMXP_META_CHAN_LIST *next;
} NMXP_META_CHAN_LIST;

31 32 33 34 35 36 37
typedef enum {
    NMXP_META_SORT_KEY = 1,
    NMXP_META_SORT_NAME,
    NMXP_META_SORT_START_TIME,
    NMXP_META_SORT_END_TIME
} NMXP_META_CHAN_LIST_SORT_TYPE;

38

39 40 41
/*! \brief Max number of channels */
#define MAX_N_CHAN 2000

42 43
#define NMXP_CHAN_MAX_SIZE_NAME 24

44 45 46
/*! \brief The key/name info for one channel */
typedef struct {
    int32_t key;
47
    char name[NMXP_CHAN_MAX_SIZE_NAME];
48 49 50 51 52 53 54 55
} NMXP_CHAN_KEY_NET;

/*! \brief Channel list */
typedef struct {
    int32_t number;
    NMXP_CHAN_KEY_NET channel[MAX_N_CHAN];
} NMXP_CHAN_LIST_NET;

56
/*! \brief The key/name info for one channel */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
57
typedef struct {
Matteo Quintiliani's avatar
Matteo Quintiliani committed
58
    int32_t key;
59
    char name[12];
Matteo Quintiliani's avatar
Matteo Quintiliani committed
60
} NMXP_CHAN_KEY;
61

Matteo Quintiliani's avatar
Matteo Quintiliani committed
62 63
/*! \brief Channel list */
typedef struct {
64
    int32_t number;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
65 66
    NMXP_CHAN_KEY channel[MAX_N_CHAN];
} NMXP_CHAN_LIST;
67

68 69
/*! \brief Precis Channel item */
typedef struct {
Matteo Quintiliani's avatar
Matteo Quintiliani committed
70
    int32_t key;
71
    char name[12];
72 73
    int32_t start_time;
    int32_t end_time;
74 75 76 77
} NMXP_CHAN_PRECISITEM;

/*! \brief Precis Channel list */
typedef struct {
78
    int32_t number;
79 80
    NMXP_CHAN_PRECISITEM channel[MAX_N_CHAN];
} NMXP_CHAN_PRECISLIST;
81

Matteo Quintiliani's avatar
Matteo Quintiliani committed
82 83 84 85 86 87 88 89
/*! \brief Type of Data */
typedef enum {
    NMXP_DATA_TIMESERIES	= 1,
    NMXP_DATA_SOH		= 2,
    NMXP_DATA_TRANSERIAL	= 6
} NMXP_DATATYPE;

/*! \brief Precis list request body */
90 91 92 93
typedef struct {
    int32_t instr_id;
    NMXP_DATATYPE datatype;
    int32_t type_of_channel;
94
} NMXP_PRECISLISTREQUEST;
95

Matteo Quintiliani's avatar
Matteo Quintiliani committed
96 97 98 99 100
/*! \brief Channel info request body */
typedef struct {
    int32_t key;
    char name[12];
    char network[12];
101
} NMXP_CHANNELINFORESPONSE;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
102 103 104 105 106

/*! \brief Channel info request body */
typedef struct {
    int32_t key;
    int32_t ignored;
107
} NMXP_CHANNELINFOREQUEST;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
108

109

110 111 112 113
/*! \brief Character separator for channel list */
#define sep_chan_list  ','


114 115 116
/*! \brief Return type of data from a channel key */
#define getDataTypeFromKey(key) ((key >> 8) & 0xff)

Matteo Quintiliani's avatar
Matteo Quintiliani committed
117 118 119
/*! \brief Return channel number from a channel key */
#define getChannelNumberFromKey(key) ((key) & 0x000f)

120

121

122 123
/*! \brief Copy station code and channel code from name
 *
124
 * \param net_dot_station_dot_channel string containing NET.STA.CHAN where NET. is optional
125
 * \param[out] station_code Pointer to string for station code
126
 * \param[out] channel_code Pointer to string for channel code
127 128
 * \param[out] network_code Pointer to string for network code
 * \param[out] location_code Pointer to string for location code
129 130 131 132 133 134 135
 *
 * \warning Parametes can not be NULL!
 *
 * \retval 1 on success
 * \retval 0 on error
 *
 */
136
int nmxp_chan_cpy_sta_chan(const char *net_dot_station_dot_channel, char *station_code, char *channel_code, char *network_code, char *location_code);
137 138


139 140
/*! \brief Match station_dot_channel against pattern, treating errors as no match.
 *
141 142
 * \param net_dot_station_dot_channel NET.STA.CHAN format (NET. is optional)
 * \param pattern N1.STA.?HZ or N2.STA.H?Z or STA.HH? or STA.?H? or ....
143 144 145 146 147 148 149
 *
 * \retval 1 for match
 * \retval 0 for no match
 * \retval -1 on error for invalid pattern
 * \retval -2 on error for invalid station_dot_channel
 *
 */
150
int nmxp_chan_match(const char *net_dot_station_dot_channel, char *pattern);
151 152 153



154
/*! \brief Looks up a channel key in the list using the name
155
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
156 157
 * \param name Channel name.
 * \param channelList Channel list.
158
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
159
 * \return Key of the channel with name. -1 On error.
160 161
 *
 */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
162
int nmxp_chan_lookupKey(char* name, NMXP_CHAN_LIST *channelList);
163

164 165 166 167 168 169 170 171 172

/*! \brief Looks up a channel name in the list using a key
 *
 * \param key Channel key.
 * \param channelList Channel list.
 *
 * \return Index of channel with key. -1 on error.
 *
 */
173
int nmxp_chan_lookupKeyIndex(int32_t key, NMXP_CHAN_LIST_NET *channelList);
174 175


176
/*! \brief Looks up a channel name in the list using a key
177
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
178 179
 * \param key Channel key.
 * \param channelList Channel list.
180
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
181
 * \return Name of channel with key. NULL on error.
182
 *
183 184
 * \warning Returned value will need to be freed!
 *
185
 */
186
char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST_NET *channelList);
187

188

189 190 191 192 193 194 195 196 197 198
/*! \brief Looks up a channel with specified data type.
 *
 * \param channelList Channel list.
 * \param dataType Type of channel.
 *
 * \return Channel list with specified dataType. It will need to be freed!
 *
 * \warning Returned value will need to be freed!
 *
 */
199
NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dataType);
200

201

202 203 204 205
/*! \brief Looks up a channel with specified data type.
 *
 * \param channelList Channel list.
 * \param dataType Type of channel.
206
 * \param sta_chan_list String list of item STA.CHAN, separeted by comma.
207
 * \param network_code_default Default Network code
208
 * \param location_code_default Default Location code
209 210 211 212 213 214
 *
 * \return Channel list with specified dataType. It will need to be freed!
 *
 * \warning Returned value will need to be freed!
 *
 */
215
NMXP_CHAN_LIST_NET *nmxp_chan_subset(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dataType, char *sta_chan_list, const char *network_code_default, const char *location_code_default);
216 217


218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
/*! Sort list by channel key
 *
 * \param channelList Channel List
 *
 */
void nmxp_chan_sortByKey(NMXP_CHAN_LIST *channelList);


/*! Sort list by channel name
 *
 * \param channelList Channel List
 *
 */
void nmxp_chan_sortByName(NMXP_CHAN_LIST *channelList);

233 234 235 236 237 238

/*! Print channel information
 *
 * \param channelList Channel List
 *
 */
239 240 241
void nmxp_chan_print_channelList(NMXP_CHAN_LIST *channelList);


242 243 244 245
/*! Print channel information using channel pattern list
 *
 * \param channelList Channel List
 * \param sta_chan_list Channel pattern list
246 247
 * \param flag_statefile If it is not zero the output can be redirected to
 * create an input state file. Otherwise a more human readable output.
248 249
 *
 */
250
void nmxp_chan_print_channelList_with_match(NMXP_CHAN_LIST *channelList, char *sta_chan_list, int flag_statefile);
251 252


253 254 255 256 257 258
/*! Print channel information
 *
 * \param channelList Channel List
 *
 */
void nmxp_chan_print_netchannelList(NMXP_CHAN_LIST_NET *channelList);
259

Matteo Quintiliani's avatar
Matteo Quintiliani committed
260 261 262

void nmxp_meta_chan_free(NMXP_META_CHAN_LIST **chan_list);

263
NMXP_META_CHAN_LIST *nmxp_meta_chan_add(NMXP_META_CHAN_LIST **chan_list, int32_t key, char *name, int32_t start_time, int32_t end_time, char *network, NMXP_META_CHAN_LIST_SORT_TYPE sorttype);
Matteo Quintiliani's avatar
Matteo Quintiliani committed
264 265 266 267 268 269 270 271 272 273 274

NMXP_META_CHAN_LIST *nmxp_meta_chan_search_key(NMXP_META_CHAN_LIST *chan_list, int32_t key);

NMXP_META_CHAN_LIST *nmxp_meta_chan_set_name(NMXP_META_CHAN_LIST *chan_list, int32_t key, char *name);

NMXP_META_CHAN_LIST *nmxp_meta_chan_set_times(NMXP_META_CHAN_LIST *chan_list, int32_t key, int32_t start_time, int32_t end_time);

NMXP_META_CHAN_LIST *nmxp_meta_chan_set_network(NMXP_META_CHAN_LIST *chan_list, int32_t key, char *network);

void nmxp_meta_chan_print(NMXP_META_CHAN_LIST *chan_list);

275 276
void nmxp_meta_chan_print_with_match(NMXP_META_CHAN_LIST *chan_list, char *sta_chan_list);

277 278
#endif