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

tankputaway.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: tankputaway_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.5  2001/04/12 03:47:36  lombard
00011  *     revised putaway include files; cleaned up some comments
00012  *
00013  *     Revision 1.4  2001/03/28 04:50:27  lombard
00014  *     ripped out the junk that was attempting to multiplex traces.
00015  *     It works much better now, and uses less memory.
00016  *
00017  *     Revision 1.3  2000/09/20 18:06:24  lucky
00018  *     Removed fixed number of MAX_MSGS. Instead we allocate as many
00019  *     slots for messages as our max buffer can hold, and we remember
00020  *     that number so that we can free at the end.
00021  *
00022  *     Revision 1.2  2000/03/10 23:19:03  davidk
00023  *     changed the tankputaway interface to match the new PA interface in
00024  *     putaway.c
00025  *
00026  *     Revision 1.1  2000/02/14 18:51:48  lucky
00027  *     Initial revision
00028  *
00029  *
00030  */
00031 
00032 /* tankputaway.c.c 
00033 
00034   Lucky Vidmar Mon Aug  2 10:15:46 MDT 1999
00035 
00036         These routines are called from putaway.c. They implement writing
00037   selected trace data into files which can be read by tankplayer.
00038 */
00039 
00040 /*
00041   Tank putaway routines revised to make them work. The idea now is simple:
00042   Write a single file containing all the TRACEBUF messages for one SCN,
00043   followed by all the TRACEBUF messages for the next. The order of the
00044   SCNs or TRACEBUF messages doesn't matter.
00045   Then to make this into a tankplayer file, use Lynn Dietz' remux_tbuf
00046   program, currently in Contrib/Menlo.  Pete Lombard, MArch 2001
00047 */
00048 
00049 #include <stdio.h>
00050 #include <stdlib.h>
00051 #include <string.h>
00052 #include <earthworm.h>
00053 #include <trace_buf.h>
00054 #include <swap.h>
00055 #include <pa_subs.h>
00056 
00057 #define         MAXTXT                  150
00058 
00059 static char     TankFile[MAXTXT];
00060 static FILE     *fpTank;
00061 
00062 /* Initialization function, 
00063 *       This is the Put Away startup intializer. This is called when    *
00064 *       the system first comes up. Here is a chance to look around      *
00065 *       and see if it's possible to do business, and to complain        *
00066 *       if not, BEFORE an event has to be processed.                    *
00067 */
00068 int TANKPA_init(char *OutDir, int debug)
00069 {
00070   if (OutDir == NULL)
00071   {
00072     logit ("e", "TANKPA_init: Invalid arguments passed in.\n");
00073     return EW_FAILURE;
00074   }
00075 
00076   if (debug == 1)
00077     logit ("", "In TANKPA_init\n");
00078 
00079 
00080   /* Make sure that the output directory exists */
00081   if (CreateDir (OutDir) != EW_SUCCESS)
00082   {
00083     logit ("e", "TANKPA_init: Call to CreateDir failed\n");
00084     return EW_FAILURE;
00085   }
00086 
00087 
00088   if (debug == 1)
00089     logit ("", "Done TANKPA_init\n");
00090 
00091   return EW_SUCCESS; 
00092 
00093 }
00094 
00095 /****************************************************************************
00096 *       This is the Put Away event initializer. It's called when a snippet  *
00097 *       has been received, and is about to be processed.                    *
00098 *       It gets to see the pointer to the TraceRequest array,               *
00099 *       and the number of loaded trace structures.                          *
00100 *****************************************************************************/
00101 int TANKPA_next_ev(char * EventID, char *OutDir, char *EventDate, 
00102                    char *EventTime, int debug)
00103 {
00104 
00105   char  tmp1[256];
00106 
00107   if ((OutDir == NULL) || (EventDate == NULL) || 
00108       (EventTime == NULL) || (EventID == NULL))
00109   {
00110     logit ("e", "TANKPA_next_ev: Invalid parameters passed in.\n");
00111     return EW_FAILURE;
00112   }
00113 
00114   if (debug == 1)
00115     logit ("", "In TANKPA_next_ev\n");
00116 
00117 
00118   /* Tank files will be written in the following format:
00119    *   TankFile = OutDir/yyyymmdd_hhmmss-iiii.tnk
00120    */
00121 
00122   /* build the event file name */
00123   sprintf (tmp1, "%s_%s_%s", EventDate, EventTime, EventID);
00124 
00125   /* NT can handle "/" as a path separator here;        *
00126    *  it's only the NT command-shell that requires "\"  */
00127   sprintf (TankFile, "%s/%s", OutDir, tmp1); 
00128 
00129   /* open the file */
00130   if ((fpTank = fopen (TankFile, "wb")) == NULL)
00131   {
00132     logit ("e", "TANKPA_init: Can't open %s.\n", TankFile);
00133     return EW_FAILURE;
00134   }
00135 
00136   if (debug == 1)
00137     logit ("", "opened %s\n", TankFile);
00138 
00139   if (debug == 1)
00140     logit ("", "Done TANKPA_next_ev\n");
00141 
00142   return EW_SUCCESS;
00143 
00144 }
00145 
00146 /*****************************************************************************
00147  *   This is the working entry point into the disposal system. This routine  *
00148  *   gets called for each trace snippet which has been recovered. It gets    *
00149  *   to see the corresponding SNIPPET structure, and the event id            *
00150  *****************************************************************************/
00151 /* Process one channel of data */
00152 int TANKPA_next(TRACE_REQ *getThis, int debug)
00153 {
00154   TRACE_HEADER  *in_head;
00155   char          *in_msg; 
00156   int          byte_per_sample;
00157   long         this_size, ret;
00158 
00159   if (debug == 1)
00160     logit ("", "In TANKPA_next\n");
00161 
00162   if ((in_msg = getThis->pBuf) == NULL)
00163   {
00164     logit ("e", "TANKPA_next: in_msg buffer is NULL\n");
00165     return EW_FAILURE;
00166   }
00167 
00168   /* loop through all the messages for this s-c-n */
00169   while ((long) in_msg < (long) getThis->actLen + (long) getThis->pBuf) 
00170   {
00171     /* read the header inforamtion for each TRACE_BUF message */
00172     in_head = (TRACE_HEADER *) in_msg;
00173 
00174     /* Swap bytes, if necessary, to make this message 
00175      * readable on this architecture
00176      *************************************************/
00177     WaveMsgMakeLocal (in_head);
00178 
00179 
00180     byte_per_sample  = atoi (&in_head->datatype[1]); /* input sample size */
00181 
00182     /* how big is the current message? */
00183     this_size = sizeof (TRACE_HEADER) + (byte_per_sample * in_head->nsamp);
00184 
00185 
00186     /* Copy the message */
00187     ret = fwrite (in_msg, sizeof (char), this_size, fpTank);
00188     if (ret != this_size)
00189     {
00190       logit ("e", "TANKPA_next: Write to %s failed.\n", TankFile);
00191       return EW_FAILURE;
00192     }
00193 
00194   /* Increment incoming message */
00195   in_msg += this_size;
00196 
00197   }
00198   if (debug == 1)
00199     logit ("", "TANKPA_next: done with <%s.%s.%s>\n", in_head->sta, 
00200            in_head->chan, in_head->net);
00201 
00202   return EW_SUCCESS;
00203 
00204 }
00205 
00206 /************************************************************************
00207 *       This is the Put Away end event routine. It's called after we've     *
00208 *       finished processing one event.                                  *
00209 *************************************************************************/
00210 int TANKPA_end_ev(int debug)
00211 {
00212 
00213  fclose (fpTank);
00214 
00215  if (debug == 1)
00216    logit ("", "Closed %s. Done TANKPA_end_ev\n", TankFile);
00217 
00218  return EW_SUCCESS;
00219 }
00220 
00221 
00222 /************************************************************************
00223 *       This is the Put Away close routine. It's called after when      *
00224 *       we're being shut down.                                          *
00225 *************************************************************************/
00226 int TANKPA_close(int debug)
00227 {
00228 
00229   if (debug == 1)
00230     logit ("", "In TANKPA_close, doing nothing useful.\n");
00231 
00232   return EW_SUCCESS;
00233 }
00234 

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