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

# putaway.c

Go to the documentation of this file.

    00001
    00002 /*
    00003  *   THIS FILE IS UNDER RCS - DO NOT MODIFY UNLESS YOU HAVE
    00004  *   CHECKED IT OUT USING THE COMMAND CHECKOUT.
    00005  *
    00006  *    $Id: putaway_8c-source.html 2161 2006-05-19 16:55:03Z paulf $
    00007  *
    00008  *    Revision history:
    00009  *     $Log$
    00009  *     Revision 1.1  2006/05/19 16:55:02  paulf
    00009  *     first inclusion
    00009  *
    00010  *     Revision 1.10  2002/03/20 21:07:01  cjbryan
    00011  *     added EventSubnet to SEISPA_next_ev call
    00012  *
    00013  *
    00014  * 3-feb-2001, S. Flower (British Geological Survey)
    00015  *     Added code for new 'gse_int' and 'seisan' output data types
    00016  *     All new code is prefixed with the initials 'SMF'
    00017
    00018  *     Revision 1.8  2001/04/12 03:47:36  lombard
    00019  *     Added include file putaway.h for function prototypes
    00020  *     Removed MaxTraceMsg argument from PA_init(), no longer used.
    00021  *
    00022  *     Revision 1.7  2001/03/22 20:56:29  cjbryan
    00023  *     deleted EventInst from PA_next_ev function call as it is no
    00024  *     longer needed by any of the putaway routines
    00025  *     cleaned up all other relic uses of EventInst and EventMod
    00026  *
    00027  *     Revision 1.6  2001/03/21 16:40:40  alex
    00028  *     deleted now extraneous EventMod variable
    00029  *
    00030  *     Revision 1.5  2001/03/21 02:15:28  alex
    00031  *     added EventSubnet to SUDSPA_next_ev call
    00032  *
    00033  *     Revision 1.4  2000/07/08 19:26:05  lombard
    00034  *     replace `=' in if statements with `=='; two of these were in PA_close().
    00035  *
    00036  *     Revision 1.3  2000/03/14 18:35:11  lucky
    00037  *     *** empty log message ***
    00038  *
    00039  *     Revision 1.2  2000/03/10 23:21:05  davidk
    00040  *     changed the putaway routines so that OutputFormat is specified at
    00041  *     initialization instead of per SCN.  Consolidated all of the EventID's
    00042  *     so that now there is a single EventID string that is passed into
    00043  *     PA_next_ev.
    00044  *     /
    00045  *
    00046  *     Revision 1.1  2000/02/14 18:51:48  lucky
    00047  *     Initial revision
    00048  *
    00049  *
    00050  */
    00051
    00052 /*
    00053     putaway.c
    00054
    00055   Thu Jul 22 13:21:09 MDT 1999 lucky
    00056
    00057    Separated the putaway routines for the following output
    00058    formats currently supported:
    00059         ah
    00060         sac
    00061         suds
    00062                 seisan
    00063                 gse_int
    00064         tank
    00065
    00066    This file will now become a library object, so that it can be
    00067    used by both trig2disk and wave2disk. Therefore, adding a new
    00068    output format will only require changing this file.
    00069
    00070
    00071  Wed Oct 20 09:53:50 MDT 1999 lucky
    00072
    00073    Fixed a bug which limited the size of the OutBuffer.
    00074
    00075
    00076 */
    00077
    00078 #include <string.h>
    00079 #include <earthworm.h>
    00080 #include <ws_clientII.h>
    00081 #include <ahhead.h>   /* for AHHEADSIZE */
    00082 #include <putaway.h>
    00083 #include <pa_subs.h>
    00084 #include <sachead.h>  /* for SACHEADERSIZE */
    00085
    00086 /* SMF: definitions for GSE and SEIsan putaway routines */
    00087 #include "gsehead.h"
    00088 #include "seihead.h"
    00089
    00090 #define         AH_FORMAT               0
    00091 #define         SAC_FORMAT              1
    00092 #define         SUDS_FORMAT             2
    00093 #define         TANK_FORMAT             3
    00094 /* SMF: new GSE format code - we use GSE_INT to allow future expansion
    00095  *      to the other GSE sub-format types (CM6 and CM8) */
    00096 #define         GSE_INT_FORMAT          4
    00097 /* SMF: new SEIsan format code */
    00098 #define         SEI_FORMAT              5
    00099
    00100
    00101 /* Initialization function,
    00102 *       This is the Put Away startup intializer. This is called when    *
    00103 *       the system first comes up. Here is a chance to look around      *
    00104 *       and see if it's possible to do business, and to complain        *
    00105 *       if not ,BEFORE an event has to be processed.                    *
    00106 */
    00107 int PA_init (char *DataFormat, long TraceBufferLen, long *OutBufferLen,
    00108              int *FormatInd, char *OutDir, char * OutputFormat, int debug)
    00109 {
    00110
    00111
    00112   if ((DataFormat == NULL) || (TraceBufferLen <= 0) ||
    00113       (OutBufferLen == NULL) || (FormatInd == NULL))
    00114   {
    00115     logit ("", "waveputaway: invalid parameters passed in.\n");
    00116     return EW_FAILURE;
    00117   }
    00118
    00119
    00120   /* size OutBuffer to  include header info */
    00121   if (strcmp (DataFormat,"ah") == 0)
    00122   {
    00123     *FormatInd = AH_FORMAT;
    00124     *OutBufferLen = TraceBufferLen + AHHEADSIZE;
    00125     if (AHPA_init (OutBufferLen, OutDir, debug) != EW_SUCCESS)
    00126     {
    00127       logit("", "waveputaway: Call to AHPA_init failed!\n" );
    00128       return EW_FAILURE;
    00129     }
    00130
    00131   }
    00132   else if (strcmp (DataFormat,"sac") == 0)
    00133   {
    00134     *FormatInd = SAC_FORMAT;
    00135     *OutBufferLen = TraceBufferLen + SACHEADERSIZE;
    00136     if (SACPA_init (*OutBufferLen, OutDir, OutputFormat, debug) != EW_SUCCESS)
    00137     {
    00138       logit("", "waveputaway: Call to SACPA_init failed!\n" );
    00139       return EW_FAILURE;
    00140     }
    00141   }
    00142   else if (strcmp (DataFormat,"suds") == 0)
    00143   {
    00144     *FormatInd = SUDS_FORMAT;
    00145     *OutBufferLen = TraceBufferLen;
    00146     if (SUDSPA_init (*OutBufferLen, OutDir, OutputFormat, debug) != EW_SUCCESS)
    00147     {
    00148       logit("", "waveputaway: Call to SUDSPA_init failed!\n" );
    00149       return EW_FAILURE;
    00150     }
    00151   }
    00152   else if (strcmp (DataFormat,"tank") == 0)
    00153   {
    00154     *FormatInd = TANK_FORMAT;
    00155     if (TANKPA_init (OutDir, debug) != EW_SUCCESS)
    00156     {
    00157       logit("", "waveputaway: Call to TANKPA_init failed!\n" );
    00158       return EW_FAILURE;
    00159     }
    00160   }
    00161   /* SMF: new code for GSE */
    00162   else if (strcmp (DataFormat,"gse_int") == 0)
    00163   {
    00164     *FormatInd = GSE_INT_FORMAT;
    00165     *OutBufferLen = TraceBufferLen;
    00166     if (GSEPA_init (OutDir, OutputFormat, debug) != EW_SUCCESS)
    00167     {
    00168       logit("", "waveputaway: Call to GSEPA_init failed!\n" );
    00169             return EW_FAILURE;
    00170     }
    00171   }
    00172   /* SMF: new code for SEIsan */
    00173   else if (strcmp (DataFormat,"seisan") == 0)
    00174   {
    00175     *FormatInd = SEI_FORMAT;
    00176     *OutBufferLen = TraceBufferLen;
    00177     if (SEIPA_init (OutDir, OutputFormat, debug) != EW_SUCCESS)
    00178     {
    00179       logit("", "waveputaway: Call to SEIPA_init failed!\n" );
    00180       return EW_FAILURE;
    00181     }
    00182   }
    00183   else
    00184   {
    00185     logit("","waveputaway: undefined DataFormat: %s\n", DataFormat);
    00186     return EW_FAILURE;
    00187   }
    00188
    00189
    00190
    00191
    00192   return EW_SUCCESS;
    00193
    00194 }
    00195
    00196
    00197 /****************************************************************************
    00198 *       This is the Put Away event initializer. It's called when a snippet
    00199 *       has been received, and is about to be processed.
    00200 *       It gets to see the pointer to the TraceRequest array,
    00201 *       and the number of loaded trace structures.
    00202 *****************************************************************************/
    00203 int PA_next_ev (char *EventID, TRACE_REQ *trace_req, int num_req,
    00204                 int FormatInd, char *OutDir, char *EventDate,
    00205                 char *EventTime, char *EventSubnet, int debug)
    00206 {
    00207
    00208
    00209   if ((trace_req == NULL) || (OutDir == NULL) || (EventDate == NULL) ||
    00210       (EventTime == NULL) || (EventID == NULL))
    00211   {
    00212     logit ("", "waveputaway: Invalid parameters passed in!\n");
    00213     return EW_FAILURE;
    00214   }
    00215
    00216
    00217   if (FormatInd == AH_FORMAT)
    00218   {
    00219     if (AHPA_next_ev (trace_req, num_req, OutDir,
    00220                       EventDate, EventTime, debug) != EW_SUCCESS)
    00221     {
    00222       logit ("", "waveputaway: Call to AHPA_next_ev failed!\n");
    00223       return EW_FAILURE;
    00224     }
    00225   }
    00226   else if (FormatInd == SAC_FORMAT)
    00227   {
    00228     if (SACPA_next_ev (EventID, trace_req, num_req, OutDir,
    00229                        EventDate, EventTime, debug) != EW_SUCCESS)
    00230     {
    00231       logit ("", "waveputaway: Call to SACPA_next_ev failed!\n");
    00232       return EW_FAILURE;
    00233     }
    00234   }
    00235   else if (FormatInd == SUDS_FORMAT)
    00236   {
    00237     if (SUDSPA_next_ev(EventID, trace_req, num_req, OutDir, EventDate,
    00238                        EventTime, EventSubnet, debug) != EW_SUCCESS)
    00239     {
    00240       logit ("", "waveputaway: Call to SUDSPA_next_ev failed!\n");
    00241       return EW_FAILURE;
    00242     }
    00243
    00244   }
    00245   else if (FormatInd == TANK_FORMAT)
    00246   {
    00247     if (TANKPA_next_ev (EventID, OutDir, EventDate,
    00248                         EventTime, debug) != EW_SUCCESS)
    00249     {
    00250       logit ("", "waveputaway: Call to TANKPA_next_ev failed!\n");
    00251       return EW_FAILURE;
    00252     }
    00253   }
    00254   /* SMF: new code for GSE */
    00255   else if (FormatInd == GSE_INT_FORMAT)
    00256   {
    00257     if (GSEPA_next_ev (trace_req, num_req, OutDir,
    00258                        EventDate, EventTime, debug) != EW_SUCCESS)
    00259     {
    00260       logit ("", "waveputaway: Call to GSEPA_next_ev failed!\n");
    00261       return EW_FAILURE;
    00262     }
    00263   }
    00264   /* SMF: new code for SEIsan */
    00265   else if (FormatInd == SEI_FORMAT)
    00266   {
    00267     if (SEIPA_next_ev (trace_req, num_req, OutDir,
    00268                        EventDate, EventTime, EventSubnet, debug) != EW_SUCCESS)
    00269     {
    00270       logit ("", "waveputaway: Call to SEIPA_next_ev failed!\n");
    00271       return EW_FAILURE;
    00272     }
    00273   }
    00274   else
    00275   {
    00276     logit ("", "waveputaway: undefined DataFormat: %d!\n", FormatInd);
    00277     return EW_FAILURE;
    00278   }
    00279
    00280
    00281   return EW_SUCCESS;
    00282 }
    00283
    00284
    00285
    00286 /*****************************************************************************
    00287 *   This is the working entry point into the disposal system. This routine
    00288 *   gets called for each trace snippet which has been recovered. It gets
    00289 *   to see the corresponding SNIPPET structure, and the event id
    00290 *****************************************************************************/
    00291 int PA_next (TRACE_REQ *getThis, int FormatInd,
    00292              double GapThresh, long OutBufferLen, int debug)
    00293 {
    00294
    00295   if (getThis == NULL)
    00296   {
    00297     logit ("e", "Invalid arguments passed in.\n");
    00298     return EW_FAILURE;
    00299   }
    00300
    00301   if (FormatInd == AH_FORMAT)
    00302   {
    00303     if (AHPA_next (getThis, GapThresh, OutBufferLen, debug) != EW_SUCCESS)
    00304     {
    00305       logit("", "waveputaway: Call to AHPA_next failed!\n");
    00306       return EW_FAILURE;
    00307     }
    00308   }
    00309   else if (FormatInd == SAC_FORMAT)
    00310   {
    00311     if (SACPA_next (getThis, GapThresh, OutBufferLen, debug) != EW_SUCCESS)
    00312     {
    00313       logit("", "waveputaway: Call to SACPA_next failed!\n");
    00314       return EW_FAILURE;
    00315     }
    00316   }
    00317   else if (FormatInd == SUDS_FORMAT)
    00318   {
    00319     if (SUDSPA_next (getThis, GapThresh, OutBufferLen, debug) != EW_SUCCESS)
    00320     {
    00321       logit("", "waveputaway: Call to SUDSPA_next failed!\n");
    00322       return EW_FAILURE;
    00323     }
    00324   }
    00325   else if (FormatInd == TANK_FORMAT)
    00326   {
    00327     if (TANKPA_next (getThis, debug) != EW_SUCCESS)
    00328     {
    00329       logit("", "waveputaway: Call to TANKPA_next failed!\n");
    00330       return EW_FAILURE;
    00331     }
    00332   }
    00333   /* SMF: new code for GSE */
    00334   else if (FormatInd == GSE_INT_FORMAT)
    00335   {
    00336     if (GSEPA_next (getThis, GapThresh, debug) != EW_SUCCESS)
    00337     {
    00338       logit("", "waveputaway: Call to GSEPA_next failed!\n");
    00339       return EW_FAILURE;
    00340     }
    00341   }
    00342   /* SMF: new code for SEIsan */
    00343   else if (FormatInd == SEI_FORMAT)
    00344   {
    00345     if (SEIPA_next (getThis, GapThresh, debug) != EW_SUCCESS)
    00346     {
    00347       logit("", "waveputaway: Call to SEIPA_next failed!\n");
    00348       return EW_FAILURE;
    00349     }
    00350   }
    00351   else
    00352   {
    00353     logit("", "waveputaway: undefined DataFormat: %d\n", FormatInd);
    00354     return EW_FAILURE;
    00355   }
    00356
    00357   return EW_SUCCESS;
    00358
    00359 }
    00360
    00361
    00362 /************************************************************************
    00363 *       This is the Put Away end event routine. It's called after we've *
    00364 *                                                                       *
    00365 *       finished processing one event.                                  *
    00366 *************************************************************************/
    00367 int PA_end_ev (int FormatInd, int debug)
    00368 {
    00369
    00370   if (FormatInd == AH_FORMAT)
    00371   {
    00372     if (AHPA_end_ev (debug) != EW_SUCCESS)
    00373     {
    00374       logit ("", "waveputaway: Call to AHPA_end_ev failed!\n");
    00375       return EW_FAILURE;
    00376     }
    00377   }
    00378   else if (FormatInd == SAC_FORMAT)
    00379   {
    00380     if (SACPA_end_ev (debug) != EW_SUCCESS)
    00381     {
    00382       logit ("", "waveputaway: Call to SACPA_end_ev failed!\n");
    00383       return EW_FAILURE;
    00384     }
    00385   }
    00386   else if (FormatInd == SUDS_FORMAT)
    00387   {
    00388     if (SUDSPA_end_ev (debug) != EW_SUCCESS)
    00389     {
    00390       logit ("", "waveputaway: Call to SUDSPA_end_ev failed!\n");
    00391       return EW_FAILURE;
    00392     }
    00393   }
    00394   else if (FormatInd == TANK_FORMAT)
    00395   {
    00396     if (TANKPA_end_ev (debug) != EW_SUCCESS)
    00397     {
    00398       logit ("", "waveputaway: Call to TANKPA_end_ev failed!\n");
    00399       return EW_FAILURE;
    00400     }
    00401   }
    00402   /* SMF: new code for GSE */
    00403   else if (FormatInd == GSE_INT_FORMAT)
    00404   {
    00405     if (GSEPA_end_ev (debug) != EW_SUCCESS)
    00406     {
    00407       logit ("", "waveputaway: Call to GSEPA_end_ev failed!\n");
    00408       return EW_FAILURE;
    00409     }
    00410   }
    00411   /* SMF: new code for SEIsan */
    00412   else if (FormatInd == SEI_FORMAT)
    00413   {
    00414     if (SEIPA_end_ev (debug) != EW_SUCCESS)
    00415     {
    00416       logit ("", "waveputaway: Call to SEIPA_end_ev failed!\n");
    00417       return EW_FAILURE;
    00418     }
    00419   }
    00420   else
    00421   {
    00422     logit ("", "waveputaway: undefined DataFormat: %d\n", FormatInd);
    00423     return EW_FAILURE;
    00424   }
    00425
    00426   return EW_SUCCESS;
    00427 }
    00428
    00429 /************************************************************************
    00430 *       This is the Put Away close routine. It's called after when      *
    00431 *       we're being shut down.                                          *
    00432 *************************************************************************/
    00433 int PA_close (int FormatInd, int debug)
    00434 {
    00435
    00436   if (FormatInd == AH_FORMAT)
    00437   {
    00438     if (AHPA_close (debug) != EW_SUCCESS)
    00439     {
    00440       logit ("", "waveputaway: Call to AHPA_close failed!\n");
    00441       return EW_FAILURE;
    00442     }
    00443   }
    00444   else if (FormatInd == SAC_FORMAT)
    00445   {
    00446     if (SACPA_close (debug) != EW_SUCCESS)
    00447     {
    00448       logit ("", "waveputaway: Call to SACPA_close failed!\n");
    00449       return EW_FAILURE;
    00450     }
    00451   }
    00452   else if (FormatInd == SUDS_FORMAT)
    00453   {
    00454     if (SUDSPA_close (debug) != EW_SUCCESS)
    00455     {
    00456       logit ("", "waveputaway: Call to SUDSPA_close failed!\n");
    00457       return EW_FAILURE;
    00458     }
    00459   }
    00460   else if (FormatInd == TANK_FORMAT)
    00461   {
    00462     if (TANKPA_close (debug) != EW_SUCCESS)
    00463     {
    00464       logit ("", "waveputaway: Call to TANKPA_close failed!\n");
    00465       return EW_FAILURE;
    00466     }
    00467   }
    00468   /* SMF: new code for GSE */
    00469   else if (FormatInd == GSE_INT_FORMAT)
    00470   {
    00471     if (GSEPA_close (debug) != EW_SUCCESS)
    00472     {
    00473       logit ("", "waveputaway: Call to GSEPA_close failed!\n");
    00474       return EW_FAILURE;
    00475     }
    00476   }
    00477   /* SMF: new code for SEIsan */
    00478   else if (FormatInd == SEI_FORMAT)
    00479   {
    00480     if (SEIPA_close (debug) != EW_SUCCESS)
    00481     {
    00482       logit ("", "waveputaway: Call to SEIPA_close failed!\n");
    00483       return EW_FAILURE;
    00484     }
    00485   }
    00486   else
    00487   {
    00488     logit ("", "waveputaway: undefined DataFormat: %d\n", FormatInd);
    00489     return EW_FAILURE;
    00490   }
    00491
    00492   return EW_SUCCESS;
    00493
    00494 }