Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

global_loc_rw.h

Go to the documentation of this file.
00001 #ifndef _GLOBAL_LOC_H
00002 #define _GLOBAL_LOC_H
00003 /*---------------------------------------------------------------------------*/
00004 
00005 #include <earthworm_defs.h> /* amp types */
00006 #include <trace_buf.h> /*  TRACE_STA_LEN, TRACE_CHAN_LEN, TRACE_NET_LEN, TRACE_LOC_LEN */
00007 #include <global_msg.h>
00008 
00009 /*---------------------------------------------------------------------------*/
00010 /* ==========================================================================
00011 **                    SIZE DEFINES AND LIMITS
00012 ** ========================================================================= */
00013 
00014 /* Global Amp 01  SUPERCEDED
00015 **
00016 ** AMP <author> <sequence_number> <version> <station> <comp> <net> <loc> <pick_time> <amplitude_type> <amplitude> <associated_period>
00017 **
00018 ** AMP 001002003 sssssssssssssss vv ssssss cccccccc nnnnnnnn llllllll yyyymmddhhmmss.sss T aaaaaaaaaaaaa.aa pppppppp.ppppppp
00019 **
00020 ** Global Amp 02  SUPERCEDED
00021 **
00022 ** AMP <author> <version> <station> <comp> <net> <loc> <amplitude_type> <amplitude> <associated_period>
00023 **
00024 ** AMP 001002003 vv ssssss cccccccc nnnnnnnn llllllll T aaaaaaaaaaaaa.aa pppppppp.ppppppp
00025 **
00026 ** Global Amp 03  SUPERCEDED
00027 **
00028 ** AMP <author> <pick_sequence> <version> <station> <comp> <net> <loc> <amplitude_type> <amplitude> <associated_period>
00029 **
00030 ** AMP 001002003 sssssssssssssss vv ssssss cccccccc nnnnnnnn llllllll T aaaaaaaaaaaaa.aa pppppppp.ppppppp
00031 **
00032 ** Global Amp 04
00033 **
00034 ** AMP <author> <pick_sequence> <version> <station> <comp> <net> <loc> <amp_time> <amplitude_type> <amplitude> <associated_period>
00035 **
00036 ** AMP 001002003 sssssssssssssss vv ssssss cccccccc nnnnnnnn llllllll yyyymmddhhmmss.sss T aaaaaaaaaaaaa.aa pppppppp.ppppppp
00037 **                                                                                                                          \n
00038 **                                                                                                                           \0
00039 **           1         2         3         4         5         6         7         8         9         0         1         2
00040 ** 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
00041 **
00042 **  NOTE: These are not fixed-width fields, the counter is only to assist with in determining the maximum size
00043 */
00044 
00045 #define GLOBAL_AMPLINE_MAXBUFSIZE (122 + BUFF_OVERRUN_SIZE)
00046 
00047 typedef char GLOBAL_AMPLINE_BUFFER[GLOBAL_AMPLINE_MAXBUFSIZE+1];
00048 
00049 
00050 typedef struct _GLOBAL_AMPLINE_STRUCT
00051 {
00052    unsigned short     version;  /* only set using InitGlobalAMP() or InitGlobalLoc() */
00053    MSG_LOGO           logo;
00054    long               pick_sequence;
00055    char               station[TRACE_STA_LEN];
00056    char               channel[TRACE_CHAN_LEN]; /* aka "component" */
00057    char               network[TRACE_NET_LEN];
00058    char               location[TRACE_LOC_LEN];
00059    char               amp_time[19];
00060    AMPLITUDE_TYPE     amptype;
00061    double             adcounts; /* a/d counts */
00062    double             period;   /* seconds    */
00063 } GLOBAL_AMPLINE_STRUCT;
00064 
00065 
00066 
00067 /* Global Phase 01
00068 **
00069 ** PHS <author> <sequence_number> <version> <station> <comp> <net> <loc> <pick_time> <phase_name> <quality> <polarity> <namp>
00070 **
00071 ** PHS 001002003 sssssssssssssss vv ssssss cccccccc nnnnnnnn llllllll nnnnnnnn yyyymmddhhmmss.sss qqqqqqqqqqqqq.qq p 10000
00072 **                                                                                                     1         1
00073 **           1         2         3         4         5         6         7         8         9         0         1
00074 ** 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
00075 **
00076 **  NOTE: These are not fixed-width fields, the counter is only to assist in determining the maximum size
00077 */
00078 
00079 #define MAX_AMPS_PER_GLOBALPHASE  (AMPTYPE_COUNT - 1)
00080 
00081 #define GLOBAL_PHSLINE_SUM_MAXSIZE (119+ BUFF_OVERRUN_SIZE)
00082 
00083 typedef char GLOBAL_PHSLINE_SUM_BUFFER[GLOBAL_PHSLINE_SUM_MAXSIZE+1];
00084 
00085 #define GLOBAL_PHSLINE_MAXBUFSIZE (GLOBAL_PHSLINE_SUM_MAXSIZE + (MAX_AMPS_PER_GLOBALPHASE * GLOBAL_AMPLINE_MAXBUFSIZE) )
00086 
00087 typedef char GLOBAL_PHSLINE_BUFFER[GLOBAL_PHSLINE_MAXBUFSIZE+1];
00088 
00089 typedef struct _GLOBAL_PHSLINE_STRUCT
00090 {
00091    unsigned short         version;  /* only set using InitGlobalPhase() or InitGlobalLoc() */
00092    MSG_LOGO               logo;
00093    long                   sequence;
00094    char                   station[TRACE_STA_LEN];
00095    char                   channel[TRACE_CHAN_LEN]; /* aka "component" */
00096    char                   network[TRACE_NET_LEN];
00097    char                   location[TRACE_LOC_LEN];
00098    char                   pick_time[19];
00099    char                   phase_name[9];
00100    double                 quality;
00101    char                   polarity;
00102    GLOBAL_AMPLINE_STRUCT  amps[MAX_AMPS_PER_GLOBALPHASE]; /*  -1 because unknown/invalid not used */
00103 } GLOBAL_PHSLINE_STRUCT;
00104 
00105 
00106 
00107 
00108 
00109 /* Global Location 02 (SUM line)
00110 **
00111 ** SUM <author> <version> <event_id> <origin_id> <origin_time> <lat> <lon> <z> <gap> <dmin> <rms> <id> <pick_count> <nph>
00112 **
00113 ** SUM 001002003 vvvvv eeeeeeeeeeeee ooooo YYYYMMDDhhmmss.sss -90.0000 -180.0000 -000.000 000.00 000.00 00.000 100000000000 10000
00114 **
00115 **           1         2         3         4         5         6         7         8         9         0         1         2         3
00116 ** 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123
00117 **
00118 **  NOTE: These are not fixed-width fields, the counter is only to assist in determining the maximum size
00119 */
00120 
00121 #define GLOBAL_LOC_SUM_MAXSIZE (127 + BUFF_OVERRUN_SIZE)
00122 
00123 typedef char GLOBAL_LOC_SUM_BUFFER[GLOBAL_LOC_SUM_MAXSIZE+1];
00124 
00125 
00126 #define GLOBAL_LOC_MAXPHS  250   /* max phases in global loc msg     */
00127 
00128 #define GLOBAL_LOC_MAXBUFSIZE (GLOBAL_LOC_SUM_MAXSIZE + (GLOBAL_LOC_MAXPHS * GLOBAL_PHSLINE_MAXBUFSIZE) )
00129 
00130 typedef char GLOBAL_LOC_BUFFER[GLOBAL_LOC_MAXBUFSIZE+1];
00131 
00132 
00133 typedef struct GLOBAL_LOC_DATA
00134 {
00135    unsigned short         version; /* only set using InitGlobalLoc */
00136    MSG_LOGO               logo;
00137    long                   event_id;
00138    long                   origin_id; /* which edition of event_id contained herein */
00139    char                   origin_time[19];
00140    double                 lat;
00141    double                 lon;
00142    float                  depth;
00143    float                  gap;
00144    float                  dmin;
00145    float                  rms;
00146    short                  pick_count; /* number of picks used to calculate origin (reported by glass) */
00147    short                  nphs;       /* number of valid phase structures included */
00148    GLOBAL_PHSLINE_STRUCT  phases[GLOBAL_LOC_MAXPHS];
00149 } GLOBAL_LOC_STRUCT;
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 /* ==========================================================================
00160 
00161 **                    FUNCTION PROTOTYPES
00162 
00163 ** ========================================================================= */
00164 
00165 
00166 
00167 /* InitGlobalAmp
00168 ** InitGlobalPhase
00169 ** InitGlobalLoc
00170 **
00171 **   Used to initialize, including allocate working memory for
00172 **   a global message struct.
00173 **
00174 **
00175 ** PARAMETER:
00176 **    p_struct -- pointer to structure to contain the message information
00177 **
00178 ** RETURNS:
00179 **    GLOBAL_MSG_SUCCESS
00180 **    GLOBAL_MSG_NULL = structure pointer is NULL
00181 */
00182 GLOBAL_MSG_STATUS InitGlobalAmpLine( GLOBAL_AMPLINE_STRUCT * p_struct );
00183 GLOBAL_MSG_STATUS InitGlobalPhaseLine( GLOBAL_PHSLINE_STRUCT * p_struct );
00184 GLOBAL_MSG_STATUS InitGlobalLoc( GLOBAL_LOC_STRUCT * p_struct );
00185 
00186 
00187 
00188 
00189 /* WriteAmpToBuffer
00190 ** WritePhaseToBuffer
00191 ** WriteLocToBuffer
00192 **
00193 **    Writes a global message structure to a buffer.
00194 **
00195 ** PARAMETERS:
00196 **    p_struct -- the source structure
00197 **    p_buffer -- the target buffer
00198 **                (on successful return, buffer will be null-terminated)
00199 **    p_length -- the available buffer size
00200 **
00201 ** RETURNS:
00202 **    GLOBAL_MSG_SUCCESS
00203 **    GLOBAL_MSG_NULL = structure pointer is NULL
00204 **    GLOBAL_MSG_VERSINVALID = invalid message version
00205 **    GLOBAL_MSG_BADPARAM = buffer pointer is NULL
00206 **    GLOBAL_MSG_TOOSMALL = buffer not large enough to contain message
00207 **                          (may be partly written anyway)
00208 **    GLOBAL_MSG_DEFINESMALL = max buffer size too small for normal write
00209 */
00210 GLOBAL_MSG_STATUS WriteAmpLineToBuffer( GLOBAL_AMPLINE_STRUCT * p_struct, char * p_buffer, unsigned int p_length );
00211 GLOBAL_MSG_STATUS WritePhaseLineToBuffer( GLOBAL_PHSLINE_STRUCT * p_struct, char * p_buffer, unsigned int p_length );
00212 GLOBAL_MSG_STATUS WriteLocToBuffer( GLOBAL_LOC_STRUCT * p_struct, char * p_buffer, unsigned int p_length );
00213 
00214 
00215 
00216 /* StringToAmp
00217 ** StringToPhase
00218 ** StringToLoc
00219 **
00220 **   Parses any global message from a supplied string.
00221 **
00222 **   Do not include the "PHS " or "AMP " line id strings.
00223 **
00224 ** RETURNS:
00225 **    GLOBAL_MSG_SUCCESS
00226 **    GLOBAL_MSG_NULL = structure pointer is NULL
00227 **    GLOBAL_MSG_VERSINVALID = invalid message version
00228 **    GLOBAL_MSG_BADPARAM    = string pointer is NULL
00229 **    GLOBAL_MSG_FORMATERROR = invalid string format
00230 **    GLOBAL_MSG_MAXCHILDREN = too many children [StringToLoc() only]
00231 **    GLOBAL_MSG_BADCHILD = invalid child line [StringToLoc() only]
00232 */
00233 GLOBAL_MSG_STATUS StringToAmpLine( GLOBAL_AMPLINE_STRUCT * p_amp, char * p_string );
00234 GLOBAL_MSG_STATUS StringToPhaseLine( GLOBAL_PHSLINE_STRUCT * p_phase, char * p_string );
00235 GLOBAL_MSG_STATUS StringToLoc( GLOBAL_LOC_STRUCT * p_loc, char * p_string );
00236 
00237 
00238 /* AddAmpToPhase
00239 ** AddPhaseToLoc
00240 **
00241 **    Add an Amp to a Phase, or a Phase to a Location
00242 **
00243 ** RETURNS
00244 **    number 0 - n = index of successfully added item
00245 **    GLOBAL_MSG_NULL = location structure pointer is NULL
00246 **    GLOBAL_MSG_VERSINVALID = invalid message version (location)
00247 **    GLOBAL_MSG_BADPARAM = child pointer is NULL, or version invalid
00248 **    GLOBAL_MSG_MAXCHILDREN = too many children (of this type)
00249 */
00250 int AddAmpLineToPhase( GLOBAL_PHSLINE_STRUCT * p_phase
00251                      , GLOBAL_AMPLINE_STRUCT * p_amp
00252                      );
00253 int AddPhaseLineToLoc( GLOBAL_LOC_STRUCT     * p_loc
00254                      , GLOBAL_PHSLINE_STRUCT * p_phase
00255                      );
00256 
00257 
00258 
00259 /* GetLocPhaseIndex
00260 **
00261 **    Find the location index of an Amp or Phase or Amp in another structure
00262 **
00263 ** RETURNS
00264 **   p_loc.nphs = item does not exist in the location
00265 **   other = index of item in the nphs[] or namp[] array
00266 */
00267 int GetLocPhaseIndex( GLOBAL_LOC_STRUCT     * p_loc
00268                     , GLOBAL_PHSLINE_STRUCT * p_phase
00269                     );
00270 
00271 /* ClearAmps
00272 ** ClearPhases
00273 **
00274 **    Used to clear work structure of children's data
00275 **
00276 ** RETURNS
00277 **    GLOBAL_MSG_SUCCESS
00278 **    GLOBAL_MSG_NULL = location structure pointer is NULL
00279 **    GLOBAL_MSG_VERSINVALID = invalid message version
00280 */
00281 GLOBAL_MSG_STATUS ClearAmpLines( GLOBAL_PHSLINE_STRUCT * p_phase );
00282 GLOBAL_MSG_STATUS ClearPhaseLines( GLOBAL_LOC_STRUCT * p_loc );
00283 
00284 #endif
00285 
00286 
00287 

Generated on Tue May 6 09:16:02 2003 for Earthworm Libs by doxygen1.3-rc3