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

# rw_mag.h

Go to the documentation of this file.

    00001 /*
    00002  *   THIS FILE IS UNDER RCS - DO NOT MODIFY UNLESS YOU HAVE
    00003  *   CHECKED IT OUT USING THE COMMAND CHECKOUT.
    00004  *
    00005  *    $Id: rw__mag_8h-source.html 2161 2006-05-19 16:55:03Z paulf $
    00006  *
    00007  *    Revision history:
    00008  *     $Log$
    00008  *     Revision 1.1  2006/05/19 16:55:02  paulf
    00008  *     first inclusion
    00008  *
    00009  *     Revision 1.15  2002/06/10 16:17:58  lucky
    00010  *     Added mblg and changed mb label to Mb (per Harley)
    00011  *
    00012  *     Revision 1.14  2001/10/02 17:29:34  lucky
    00013  *     fixed doubles to floats of amplitudes and periods.
    00014  *
    00015  *     Revision 1.13  2001/08/07 16:49:27  lucky
    00016  *     Pre v6.0 checkin
    00017  *
    00018  *     Revision 1.12  2001/05/30 15:52:22  lucky
    00019  *     Added a comment/warning about the order of magnitude types array
    00020  *     and the associated string->number mappings.
    00021  *
    00022  *     Revision 1.11  2001/05/29 21:24:09  lucky
    00023  *     Changed order of MagNames to comply with what is in the database.
    00024  *     Note: Mag types ***MUST*** remain in the same order and with the same
    00025  *     numbers, otherwise the database thigies break.
    00026  *
    00027  *     Revision 1.10  2001/05/26 21:07:42  lombard
    00028  *     Changed ML_INFO struct to MAG_CHAN_INFO struct to make it more generic.
    00029  *     This structure should now work with most mag types.
    00030  *     Added Mwp, removed M0 from mag type table.
    00031  *     Changed some MAG_*_LEN macros to TRACE_*_LEN for consistency.
    00032  *     Added period (double) element to MAG_CHAN_INFO struct for future
    00033  *     use with body and surface wave magnitudes.
    00034  *
    00035  *     Revision 1.9  2001/05/22 18:45:33  lucky
    00036  *     Fixed the MagNames initialization to properly include Md. Also, had to increase
    00037  *     N_MAG_NAMES to 7 -- used to be 6, but there were seven entries??
    00038  *
    00039  *     Revision 1.8  2001/05/21 22:30:11  davidk
    00040  *     Added MAGTYPE constants and a duration magtype to the magtype table.
    00041  *
    00042  *     Revision 1.5  2001/05/01 22:39:31  davidk
    00043  *     moved the MagNames table out of the .h file and into rw_mag.c
    00044  *
    00045  *     Revision 1.4  2001/05/01 20:27:13  davidk
    00046  *     fixed syntax errors in an array declaration and in the rd_mag_sta() prototype.
    00047  *
    00048  *     Revision 1.3  2001/04/29 00:10:53  alex
    00049  *     alex: tweak for table of mag type strings and numbers
    00050  *
    00051  *     Revision 1.2  2001/04/06 18:04:26  lombard
    00052  *     added <earthworm.h> since it is needed for some macros.
    00053  *
    00054  *     Revision 1.1  2001/04/05 15:40:09  lombard
    00055  *     Initial revision
    00056  *
    00057  *
    00058  *
    00059  */
    00060
    00061 /* rw_mag.h
    00062  *
    00063  * Header file for the functions in rw_mag.c that
    00064  * convert from a TYPE_MAGNITUDE message to a structure
    00065  * and visa versa.
    00066  *
    00067  * Each TYPE_MAGNITUDE message is intended to contain information
    00068  * for one event.
    00069  *
    00070  * Timestamps are in seconds since 1970/01/01 00:00:00.00 UTC.
    00071  *
    00072  * written by Pete Lombard  February 2001
    00073  */
    00074
    00075 #ifndef RW_MAG_H
    00076 #define RW_MAG_H
    00077
    00078 #include <trace_buf.h>
    00079 #include <earthworm_defs.h> /* for mag types */
    00080
    00081 /* Define maximum lengths for strings/arrays
    00082    in and Earthworm TYPE_MAGNITUDE message
    00083  *********************************************/
    00084 #define MAG_ALG_LEN     8
    00085 #define MAG_NAME_LEN    6
    00086
    00087
    00088
    00089 /* Structure to contain magnitude summary information for one event
    00090    In the comments below, NTS = Null Terminated String
    00091  *********************************************************/
    00092 typedef struct _MAG_INFO {
    00093
    00094 /* fields supplied in first (summary) line of TYPE_MAGNITUDE msg */
    00095   double  mag;            /* REQUIRED: magnitude value */
    00096   double  error;          /* OPTIONAL: Error estimate (std deviation for Ml/AVG) */
    00097   double  quality;        /* OPTIONAL: [0.0 - 1.0], -1.0 for NULL                */
    00098   double  mindist;        /* OPTIONAL: Minumun distance from location to station *
    00099                            *   used in mag.[0.0 - d], -1.0 for NULL              */
    00100   int     azimuth;        /* OPTIONAL: Maximum azimuthal gap for stations *
    00101                            *   used in mag. [0 - 360], -1 for NULL        */
    00102   int     nstations;      /* OPTIONAL: Number of stations used to compute magnitude. */
    00103   int     nchannels;      /* OPTIONAL: Number of data channels used to compute magnitude. */
    00104   char    qid[EVENTID_SIZE];  /* REQUIRED: NTS, eventid data associates with    */
    00105   char    qauthor[AUTHOR_FIELD_SIZE]; /* REQUIRED: NTS, author of the eventid   *
    00106                                          *   (required if qid is given)           */
    00107   unsigned int origin_version;
    00108   unsigned int qdds_version;
    00109   int     imagtype;                /* REQUIRED: Magnitude type from MagNames table above */
    00110   char    szmagtype[MAG_NAME_LEN];   /* Magnitude type string */
    00111
    00112   char    algorithm[MAG_ALG_LEN];  /* OPTIONAL: NTS, AVG for average, *
    00113                                     *   MED for median, `_' for null) */
    00114 /* fields supplied by DBMS: */
    00115    double  tload;         /* time data was loaded into DBMS - this field is *
    00116                            *   not part of ascii TYPE_MAG msg,              *
    00117                            *   but may be filled when pulling data from DBMS*/
    00118   char *pMagAux;          /* pointer to auxiliary structure(s) specific for *
    00119                            *   the magnitude type                           */
    00120   size_t  size_aux;       /* Size of memory used for MagAux structure       */
    00121 } MAG_INFO;
    00122
    00123 /* Structure to contain generic magnitude information for one channel *
    00124  * This structure is expected to be used for most magnitude types,    *
    00125  * it consists of two pick times, amplitudes, and periods.
    00126  * Moment magnitude is an obvious exception to this.                  */
    00127 typedef struct _MAG_CHAN_INFO {
    00128    char    sta[TRACE_STA_LEN];    /* REQUIRED: NTS, Site code as per IRIS SEED      */
    00129    char    comp[TRACE_CHAN_LEN];  /* REQUIRED: NTS, Component code as per IRIS SEED */
    00130    char    net[TRACE_NET_LEN];    /* REQUIRED: NTS, Network code as per IRIS SEED   */
    00131   double   mag;           /* REQUIRED: local magnitude for this channel */
    00132   double   dist;          /* REQUIRED: station-event distance used for local magnitude */
    00133   double   corr;          /* REQUIRED: correction that was added to get this local mag */
    00134   double   Time1;         /* time of the first pick */
    00135   float    Amp1;          /* amplitude of the first pick */
    00136   float    Period1;       /* period associated with the first pick */
    00137   double   Time2;         /* time of the second pick (if used) */
    00138   float    Amp2;          /* amplitude of the second pick (if used) */
    00139   float    Period2;       /* period of the second pick (if used) */
    00140 } MAG_CHAN_INFO;
    00141
    00142
    00143 /* Function Prototypes
    00144  *********************/
    00145 int rd_mag( char *msg, int msglen, MAG_INFO *pMag );
    00146 int rd_chan_mag( char *msg, int msglen, MAG_CHAN_INFO *pMci, int size_ml);
    00147 int wr_mag( MAG_INFO *pMag, char *buf, int buflen );
    00148 int wr_chan_mag( MAG_CHAN_INFO *pMci, int nchannels, char *buf, int buflen );
    00149
    00150 /* Alex's crude parsers
    00151 ***********************/
    00152 /* reads the summary line of a mag message */
    00153 int rd_mag_sum(char* magMsg, int msgSize, MAG_INFO* magSum);
    00154
    00155 /* reads one mag message channel line */
    00156 int rd_mag_sta(char* magMsg, int msgSize, int nxtChar, MAG_CHAN_INFO* magSta);
    00157
    00158
    00159 #endif