Changeset 4637


Ignore:
Timestamp:
10/27/11 02:06:35 (10 years ago)
Author:
quintiliani
Message:

First patch for ticket #186 .
Localmag is now able to read the arc file from command line.
Changed the function getArcSum() and renamed to getArc().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/seismic_processing/localmag/lm_util.c

    r4617 r4637  
    158158 
    159159/* Internal function prototypes */ 
    160 static int getArcSum(char *, EVENT *); 
     160static int getArc(char *, EVENT *); 
    161161static void initSaveTrace(EVENT *, LMPARAMS *); 
    162162static void termSaveTrace(EVENT *, LMPARAMS *); 
     
    184184    /* Read a hyp2000 archive message, from stdin or from file */ 
    185185    /* For now, we will read arc msgs only from stdin */ 
    186     if ( (rc = getArcSum("", pEvt)) < 0) 
     186    if ( (rc = getArc("", pEvt)) < 0) 
    187187      return rc; 
    188188    break; 
     
    19141914 
    19151915/* 
    1916  * getArcSum: Read the summary line of a hyp2000 archive message and  
     1916 * getArc: Read content of a hyp2000 archive message and  
    19171917 *     fill in part of the EVENT structure. 
    19181918 *  Arguments: filename: archive file name; if filename is empty or NULL, 
     
    19241924 * PRELIMINARY: may change method of geting ARC summary line 
    19251925 */ 
    1926 static int getArcSum(char *filename, EVENT *pEvt) 
     1926static int getArc(char *filename, EVENT *pEvt) 
    19271927{ 
    19281928  int rc = 0; 
    19291929  char line[MAX_ARC_LINE+1]; 
     1930  char arcmsg[MAX_BYTES_PER_EQ+1]; 
    19301931  int open_file = 0; 
     1932  int error = 0; 
    19311933  FILE *fp; 
     1934 
     1935  /* Prevent over bound null terminated string */ 
     1936  line[MAX_ARC_LINE] = 0; 
     1937  arcmsg[MAX_BYTES_PER_EQ] = 0; 
    19321938 
    19331939  if (filename == NULL || strlen(filename) == 0) 
     
    19461952  } 
    19471953   
    1948   if ( fgets(line, MAX_ARC_LINE, fp) != NULL) 
    1949   { 
     1954  /* Put all file content into a string, since procArc has been changed */ 
     1955  arcmsg[0] = 0; 
     1956  while( fgets(line, MAX_ARC_LINE, fp) != NULL  &&  error == 0) { 
     1957 
    19501958    /* Make sure we got a whole line */ 
    19511959    if (line[strlen(line)-1] != '\n') 
    19521960    { 
    19531961      logit("", "Warning: line from archive message too long, truncated;" 
    1954             "\nFirst 40 chars: %40s\n", line); 
    1955     } 
    1956  
    1957     if (procArc( line, pEvt) < 0) 
     1962          "\nFirst 40 chars: %40s\n", line); 
     1963      line[strlen(line)-1] = '\n'; 
     1964    } 
     1965 
     1966    if (strlen(line) + 1 > MAX_BYTES_PER_EQ - strlen(arcmsg)) { 
     1967      logit("e", "Arc messge would be truncated.\n"); 
     1968      error = -1; 
     1969    } else { 
     1970      strncat(arcmsg, line, MAX_BYTES_PER_EQ - strlen(arcmsg) - 1); 
     1971    } 
     1972 
     1973  } 
     1974 
     1975  if ( error == 0 ) 
     1976  { 
     1977    if (procArc( arcmsg, pEvt) < 0) 
    19581978    {  /* Don't complain, procArc already did */ 
    19591979      rc = -1; 
     
    19631983  else 
    19641984  { 
    1965     logit("", "getArcSum: nothing to read from event message\n"); 
     1985    logit("", "getArc: nothing to read from event message\n"); 
    19661986    rc = -1; 
    19671987  } 
Note: See TracChangeset for help on using the changeset viewer.