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

read_arc.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: read__arc_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.6  2000/12/06 17:50:32  lucky
00011  *     Make sure that the onset is read and stored
00012  *
00013  *     Revision 1.5  2000/09/12 19:07:34  lucky
00014  *     Defined separate FM fields for S and P picks
00015  *
00016  *     Revision 1.4  2000/08/21 19:49:39  lucky
00017  *     Fixed read_phs so that the Hpck structure is filled with the information
00018  *     for both the P and S wave picks.
00019  *
00020  *     Revision 1.3  2000/04/04 22:51:23  davidk
00021  *     changed the starting column position for the read of sumP->e1dp
00022  *     (the intermediate principal error) from 61 to 64.  Due to the error,
00023  *     e1dp was being set to an excessively large value that caused an
00024  *     error to occur in orareport as it inserted the bad value into the DB.
00025  *
00026  *     Revision 1.2  2000/03/30 15:43:39  davidk
00027  *     added code to handle additional arc message fields in both
00028  *     the summary and phase lines, that are used by orareport,
00029  *     so that orareport can use the read_arc routines.
00030  *
00031  *     Revision 1.1  2000/02/14 18:51:48  lucky
00032  *     Initial revision
00033  *
00034  *
00035  */
00036 
00037 /* Routines for reading HYP2000ARC summary lines and phase lines.
00038  * These routines are provided for the use of arc2trig and two UW-spcific 
00039  * modules, uw_report and eqtee. They only read the fields that are
00040  * required by these modules.
00041  * If you need to read more info from the HYP2000ARC message, feel free to
00042  * make additions here. You probably will need to add to the structures in
00043  * read_arc.h as well.
00044  * Completely rewritten by Pete Lombard, 12/03/1998
00045  */
00046 
00047 #include <stdio.h>
00048 #include <stdlib.h>  /* for atof() */
00049 #include <string.h>
00050 #include <chron3.h>
00051 #include <read_arc.h>
00052 
00053 /********************************
00054  * Internal function prototypes *
00055  ********************************/
00056 static int strib( char* );
00057 static void read_fl2( char*, float* );
00058 static void read_fl1( char*, float* );
00059 static void read_i(char*, int* );
00060 
00061 /********************************
00062  * External function prototypes *
00063  ********************************/
00064 void logit( char *, char *, ... );          /* logit.c      sys-independent  */
00065 
00066 /**************************************************************
00067  * read_hyp() reads the hypocenter line from an archive msg into an 
00068  *            Hsum structure (defined in read_arch.h)
00069  *
00070  *      Inputs: sumLine - character string holding the summary line
00071  *              shdw - character string holding the summary shadow line
00072  *              sumP - pointer to Hsum structure provided by the caller
00073  *      returns 0 on success, -1 on parsing errors
00074  *
00075  ****************************************************************/
00076 
00077 int read_hyp( char *sumLine, char *shdw, struct Hsum *sumP )
00078 {
00079   char   str[200];
00080   float  deg, min;
00081   float  sign;
00082   int    len;
00083 
00084   /* Initialize the output structure
00085   **********************************/
00086   memset( sumP, 0, sizeof(struct Hsum) ); 
00087  
00088   /* Copy incoming string to a local buffer so we can alter it.
00089   ************************************************************/
00090   strncpy ( str, sumLine, 165 ); /* this should be enough chars for us */
00091   len = strlen( sumLine );       /* note length of original summary line */
00092 
00093 /*------------------------------------------------------------------------
00094 Sample HYP2000ARC archive summary line and its shadow.  The summary line
00095 may be up to 188 characters long.  Its full format is described in
00096 documentation (hyp2000.shadow.doc) by Fred Klein.
00097 199204290117039536 2577120 2407  475  0 18 98 17  16 5975 128175 6  58343COA  38    0  57 124 21   0 218  0  8COA WW D 24X   0  0L  0  0     10123D343 218Z  0   0  \n
00098 YYYYMMDDHHMMSSssLLsLLLLlllsllllDDDDDMMMpppGGGnnnRRRRAAADDEEEEAAADDMMMMCCCrrreeeerrssshhhhvvvvpppssssddddsssdddmmmapdacpppsaeeewwwmaaawwwIIIIIIIIIIlmmmwwwwammmwwwwVvN
00099 $1                                                                                0343   0   0\n
00100 0123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 12345
00101 0         1         2         3         4         5         6         7         8         9        10        11        12        13        14        15        16
00102 ------------------------------------------------------------------------*/
00103   
00104   /* Read origin time
00105   ******************/
00106   strncpy( sumP->cdate,    str,     14 ); /* YYYYMMDDHHMMSS */
00107   sumP->cdate[14] = '.';
00108   strncpy( sumP->cdate+15, str+14,  2 );  /* hundreths of seconds */
00109   sumP->cdate[17] = '\0';
00110   sumP->ot = julsec17( sumP->cdate );
00111   if ( sumP->ot == 0.0 ) 
00112   {
00113     logit( "t", "read_hyp: Error decoding origin time: %s\n",
00114            sumP->cdate );
00115     return( -1 );
00116   }
00117   
00118   /* Read the rest of the card, back to front
00119   ******************************************/
00120   if( len >= 154 )
00121   {
00122   /* We're not reading fields beyond str[154] (Fortran column 155) */
00123     str[154] = '\0';
00124     read_fl1( str+150, &sumP->wtpref );
00125     str[150] = '\0';
00126     read_fl2( str+147, &sumP->Mpref );
00127     sumP->labelpref = str[146];
00128   }
00129   str[146] = '\0';  sumP->qid  = atol( str+136 );
00130   
00131   /* Added by davidk 20000317 for use by DB PutArc */
00132   sumP->mdtype=str[117]; /* coda dur mag type */
00133 
00134   str[107+3]  = '\0';  
00135   read_fl2( str+107, &sumP->mdmad ); /* Mag XX */
00136 
00137   str[100+4]  = '\0';  
00138   read_fl1( str+100, &sumP->mdwt ); /* Mag Wt. */
00139   /* End: Added by davidk 20000317  */
00140 
00141   str[93]  = '\0';  
00142   read_fl2( str+89, &sumP->erz );
00143   str[89]  = '\0';
00144   read_fl2( str+85, &sumP->erh );
00145   str[80]  = '\0';  
00146   read_fl2( str+76, &sumP->e2 );
00147   str[76]  = '\0';
00148   strncpy( sumP->reg, str+73, 4 );
00149   str[73]  = '\0';
00150   read_fl2( str+70, &sumP->Md );
00151   str[70]  = '\0';
00152   read_fl2( str+66, &sumP->e1 );
00153   str[66]  = '\0';  
00154   read_i( str+64, &sumP->e1dp );
00155   str[64]  = '\0';
00156   read_i( str+61, &sumP->e1az );
00157   str[61]  = '\0';
00158   read_fl2( str+57, &sumP->e0 );
00159   str[57]  = '\0';
00160   read_i( str+55, &sumP->e0dp );
00161   str[55]  = '\0';
00162   read_i( str+52, &sumP->e0az );
00163   str[52]  = '\0';
00164   read_fl2( str+48, &sumP->rms );
00165   str[48]  = '\0';
00166   read_i( str+45, &sumP->dmin );
00167   str[45]  = '\0';
00168   read_i( str+42, &sumP->gap );
00169   str[42]  = '\0';
00170   read_i( str+39, &sumP->nph );
00171   str[36]  = '\0';
00172   read_fl2( str+31, &sumP->z );
00173   
00174   /* longitude */
00175   str[31]  = '\0';  min        = (float)(atof( str+27 )/100.0);
00176   if ( str[26] == ' ' || str[26] == 'W' || str[26] == 'w' ) 
00177     sign = -1.0;
00178   else
00179     sign = 1.0;
00180   str[26]  = '\0';  deg        = (float)atof( str+23 );
00181   sumP->lon = (float)(sign * ( deg + min / 60.0 ));
00182 
00183   /* latitude */
00184   str[23]  = '\0';  min        = (float)(atof( str+19 )/100.0);
00185   if ( str[18] == 'S' || str[18] == 's' )
00186     sign = -1.0;
00187   else
00188     sign = 1.0;
00189   str[18]  = '\0';  deg        = (float)atof( str+16 );
00190   sumP->lat = (float)(sign * ( deg + min / 60.0 ));
00191 
00192   return ( 0 );
00193 }
00194 
00195 
00196 /***************************************************************
00197  * read_phs() reads a phase line & its shadow from archive msg 
00198  *            into an Hpck structure (defined in read_arch.h)
00199  *      Inputs: phs - character string holding one phase line
00200  *              shdw - character string holding the phase shadow line
00201  *              pckP - pointer to Hpck structure provided by the caller
00202  *     
00203  *      returns 0 on success, -1 on parsing errors
00204  *
00205  ***************************************************************/
00206 
00207 int read_phs( char *phs, char *shdw, struct Hpck *pckP )
00208 {
00209         char    str[120];
00210         float   Psec, Ssec;
00211         int     i;
00212         double  Cat; /* common arrival time up to yyyymmddhhmm */
00213 
00214    
00215 /*------------------------------------------------------------------------
00216 Sample TYPE_HYP2000ARC station archive card (P-arrival) and a shadow card 
00217   (as output by hyp2000) (phase card is 112 chars; shadow is up to 104 chars):
00218 PWM  NC VVHZ  PD0199204290117  877  -8136    0   0   0      0 0  0  61   0 169 8400  0   77 88325  0 932   0WD \n
00219 SSSSSNNxcCCCxrrFWYYYYMMDDHHMMPPPPPRRRRWWWSSSSSrrxWRRRRAAAAAAAuuWWWDDDDddddEEEEAAAwwppprDDDDAAAMMMmmmppppssssSDA\
00220 $   6 5.49 1.80 7.91 3.30 0.10 PSN0   77 PHP3 1853 39 340 47 245 55 230 63  86 71  70 77  48           \n
00221 $xnnnAA.AAQQ.QQaa.aaqq.qqRR.RRxccccDDDDDxPHpwAAAAATTTAAAAtttaaaaTTTAAAAtttaaaaTTTAAAAtttaaaaMMMwwwnnnnp\
00222 0123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123
00223 --------------------------------------------------------------------------*/
00224 
00225 
00226   /* Copy phase string to a local buffer so we can alter it.
00227   ************************************************************/
00228   memset(str,0,120);
00229   strncpy ( str, phs, 120 );
00230 
00231   /* Data source code */
00232   pckP->datasrc = str[108];
00233 
00234   /* Duration magnitude */
00235   str[94+3] = '\0';
00236   read_fl2( str+94, &pckP->Md);
00237 
00238   /* azimuth to station */
00239   str[91+3] = '\0';
00240   read_i( str+91, &pckP->azm);
00241 
00242   /* Coda duration */
00243   str[87+4] = '\0';
00244   read_i( str+87, &pckP->codalen );
00245 
00246   /* duration magnitude weight code */
00247   str[82+1] = '\0';
00248   read_i( str+82, &pckP->codawt );
00249 
00250   /* emergence angle at source */
00251   str[78+3] = '\0';
00252   read_i( str+78, &pckP->takeoff);
00253 
00254   /* epicentral distance */
00255   str[74+4] = '\0';
00256   read_fl1( str+74, &pckP->dist);
00257 
00258   /* S weight actually used */
00259   str[63+3]  = '\0';
00260   read_fl2( str+63, &pckP->Swt);
00261 
00262   /* S travel time residual */
00263   str[50+4]  = '\0';
00264   read_fl2( str+50, &pckP->Sres );
00265 
00266   /* Assigned S weight code */
00267   str[49+1]  = '\0';
00268   read_i( str+49, &pckP->Squal );
00269 
00270   pckP->Sfm = str[48];
00271 
00272   /* S phase label */
00273   pckP->Slabel = str[47];
00274 
00275   /* S phase onset */
00276   pckP->Sonset = str[46];
00277 
00278   /* Second of S arrival */
00279   str[41+5]  = '\0';  
00280   Ssec = (float)(atof( str+41 )/100.0 );
00281 
00282   /* P weight actually used */
00283   str[38+3]  = '\0';
00284   read_fl2( str+38, &pckP->Pwt);
00285 
00286   /* P travel time residual */
00287   str[34+4]  = '\0';
00288   read_fl2( str+34, &pckP->Pres );
00289 
00290   /* Seconds of P arrival */
00291   str[29+5]  = '\0';  
00292   Psec = (float)(atof( str+29 )/100.0 );
00293 
00294   /* Figure out the common time */
00295   strncpy( pckP->cdate, str+17, 12 ); /* YYYYMMDDHHMM */
00296   pckP->cdate[12] = '\0';
00297   strcat(pckP->cdate, "00.00" );
00298   Cat = julsec17( pckP->cdate );
00299   if ( Cat == 0.0 ) 
00300   {
00301     logit( "t", "read_phs: Error decoding arrival time: %s\n",
00302                     pckP->cdate );
00303     return( -1 );
00304   }
00305 
00306   /* Calculate P and S arrival times */
00307   pckP->Pat = Cat + Psec;
00308   pckP->Sat = Cat + Ssec;
00309 
00310   /* Assigned P weight code */
00311   str[16+1]  = '\0';
00312   read_i( str+16, &pckP->Pqual );
00313 
00314   pckP->Pfm = str[15];
00315 
00316   /* P phase label */
00317   pckP->Plabel = str[14];
00318 
00319   /* P phase onset */
00320   pckP->Ponset = str[13];
00321 
00322   /* Component code */
00323   str[9+3]  = '\0';  
00324   strcpy(pckP->comp, str+9); 
00325   strib(pckP->comp);
00326 
00327   /* network code */
00328   str[5+2]   = '\0';  
00329   strcpy(pckP->net,  str +5); 
00330   strib(pckP->net);
00331 
00332   /* station site code */
00333   str[5]   = '\0';  
00334   strcpy(pckP->site, str); 
00335   strib(pckP->site);
00336 
00337 
00338   /* Copy shadow string to a local buffer so we can alter it.
00339   ************************************************************/
00340   memset(str,0,120);
00341   strncpy ( str, shdw, 120 );
00342 
00343   str[88+4] = '\0';
00344   read_i( str+88,  &(pckP->caav[5]) );
00345 
00346   str[85+3] = '\0';
00347   read_i( str+85, &(pckP->ccntr[5]) );
00348 
00349   str[81+4] = '\0';
00350   read_i( str+81,  &(pckP->caav[4]) );
00351 
00352   str[78+3] = '\0';
00353   read_i( str+78, &(pckP->ccntr[4]) );
00354 
00355   str[74+4] = '\0';
00356   read_i( str+74,  &(pckP->caav[3]) );
00357 
00358   str[71+3] = '\0';
00359   read_i( str+71, &(pckP->ccntr[3]) );
00360 
00361   str[67+4] = '\0';
00362   read_i( str+67,  &(pckP->caav[2]) );
00363 
00364   str[64+3] = '\0';
00365   read_i( str+64, &(pckP->ccntr[2]) );
00366 
00367   str[60+4] = '\0';
00368   read_i( str+60,  &(pckP->caav[1]) );
00369 
00370   str[57+3] = '\0';
00371   read_i( str+57, &(pckP->ccntr[1]) );
00372 
00373   str[53+4] = '\0';
00374   read_i( str+53,  &(pckP->caav[0]) );
00375 
00376   str[50+3] = '\0';
00377   read_i( str+50, &(pckP->ccntr[0]) );
00378 
00379   for( i=0; i<6; i++ ) 
00380   {
00381     if( pckP->ccntr[i]==0 ) 
00382     {
00383             pckP->ccntr[i]    = (long)NULL;
00384       pckP->caav[i]     = (long)NULL;
00385     }
00386   }
00387 
00388   str[45+5] = '\0';
00389   read_i( str+45, &pckP->pamp );
00390 
00391   str[35+5] = '\0';
00392   read_i( str+35, &pckP->codalenObs);
00393 
00394 
00395   return ( 0 );
00396 }
00397 
00398 
00399 /*
00400  * Strip trailing blanks and newlines from string.
00401  */
00402 static int strib( char *string )
00403 {
00404   int i, length;
00405   
00406   length = strlen( string );
00407   if ( length )
00408   {
00409     for ( i = length-1; i >= 0; i-- )
00410     {
00411       if ( string[i] == ' ' || string[i] == '\n' )
00412         string[i] = '\0';
00413       else
00414         return ( i+1 );
00415     }
00416   } 
00417   else
00418     return length;
00419   return ( i+1 );
00420 }
00421 
00422 static void read_fl2( char* str, float* quant )
00423 {
00424   if ( strib( str ) )
00425     *quant = (float)(atof( str)/100.0 );
00426   else
00427     *quant = NO_FLOAT_VAL;
00428 }
00429 
00430 static void read_fl1( char* str, float* quant )
00431 {
00432   if ( strib( str ) )
00433     *quant = (float)(atof( str)/10.0 );
00434   else
00435     *quant = NO_FLOAT_VAL;
00436 }
00437 
00438 static void read_i( char* str, int* quant )
00439 {
00440   if ( strib( str ) )
00441     *quant = atoi( str );
00442   else
00443     *quant = NO_INT_VAL;
00444 }
00445 

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