#include "isf_bul.h" /* Parses a line asuming it to be a data type line. Format is: DATA_TYPE data_type:subtype data_format:subformat Only data_type is required. If there is extra text it is ignored. No checks are made as to whether data_type is valid or not. Returns 0 if the line is a properly formatted data type line Returns 20 and writes a diagnostic to isf_bulletin_error on error. */ int read_data_type(char *line, char *data_type, char *subtype, char *data_format,char *subformat) { int i,j; /* Chars 1-9: should be the string 'DATA_TYPE' */ if (strncmp(line,"DATA_TYPE",9) != 0){ sprintf (isf_bulletin_error,"not a data_type line: %s",line); return 20; } /* Initialise strings - some of which may not be set. */ strcpy(data_type,""); strcpy(subtype,""); strcpy(data_format,""); strcpy(subformat,""); /* Check that comment part isn't too long. */ if ( strlen(line) > ISF_COMM_LEN+9 ){ sprintf (isf_bulletin_error,"line too long: %s",line); return 20; } /* Go through the rest of the line one character at a time, separating words either on white space or ':' */ i=9; j=0; while (line[i] == ' '){i++;} while (line[i]){ if (line[i]==' ' || line[i]=='\0' || line[i]==':' || line[i]=='\n'){ data_type[j]='\0'; break; } data_type[j++]=line[i++]; } if (line[i] == ':'){ j=0; i++; while (line[i]){ if (line[i]==' ' || line[i]=='\0' || line[i]=='\n'){ subtype[j]='\0'; break; } subtype[j++]=line[i++]; } } if (line[i] == ' '){ while (line[i] == ' '){i++;} j=0; while (line[i]){ if (line[i]==' ' || line[i]=='\0' || line[i]==':' || line[i]=='\n'){ data_format[j]='\0'; break; } data_format[j++]=line[i++]; } } if (line[i] == ':'){ j=0; i++; while (line[i]){ if (line[i]==' ' || line[i]=='\0' || line[i]=='\n'){ subformat[j]='\0'; break; } subformat[j++]=line[i++]; } } return 0; } /* Parses a line asuming it to be an event title line. Requires event ID to be present but allows lines with no region. Returns 0 if the line is a properly formatted event ID line. Returns 20 and writes a diagnostic to isf_bulletin_error on error. */ int read_event_id(char *line, char *evid, char *region) { char substr[ISF_LINE_LEN]; /* Chars 1-5: must be the word 'Event'. Char 6: must be a space. */ if (strncmp(line,"Event ",6) && strncmp(line,"EVENT ",6)){ sprintf (isf_bulletin_error,"not an event title line: %s",line); return 20; } /* Chars 7-14: event ID */ if (!partline(evid,line,6,8)){ sprintf (isf_bulletin_error,"missing evid: %s",line); return 20; } if (check_whole(evid)){ sprintf (isf_bulletin_error,"bad evid: %s",line); return 20; } /* Not quite right but lots of people hit CR after evid */ if (strlen(line) < 16) return 0; /* Char 15: must be a space */ if (line[14] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 15: %s",line); return 20; } /* Chars 16-80: geographic region if there */ partline(region,line,15,65); /* Check for extra characters after char 80. */ if (partline(substr,line,80,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Tests a line to discover if it is an origin header line. Returns 0 if the line is a properly formatted origin header line. Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_origin_head(char *line) { char substr[ISF_LINE_LEN]; char head[] = " Date Time Err RMS Latitude Longitude Smaj Smin Az Depth Err Ndef Nsta Gap mdist Mdist Qual Author OrigID"; int headlen = 136; if (strncmp(line,head,headlen) != 0){ sprintf (isf_bulletin_error,"not an origin header: %s",line); return 20; } /* Check for extra characters after char 136. */ if (partline(substr,line,headlen,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line asuming it to be an origin line. Values are asigned to variables, the pointers to which have been sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is a properly formatted origin line. Returns 20 and writes a diagnostic to isf_bulletin_error on error. */ int read_origin(char *line, int *yyyy, int *mm, int *dd, int *hh, int *mi, int *ss, int *msec, char *timfix, float *stime, float *sdobs, float *lat, float *lon, char *epifix, float *smaj, float *smin, int *strike, float *depth, char *depfix, float *sdepth, int *ndef, int *nsta, int *gap, float *mindist, float *maxdist, char *antype, char *loctype, char *etype, char *author, char *origid) { char substr[ISF_LINE_LEN]; /* Chars 1-4: year. */ if (!partline(substr,line,0,4)){ sprintf (isf_bulletin_error,"missing year: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad year: %s",line); return 20; } *yyyy = atoi(substr); /* Char 5: '/' character. */ if (line[4] != '/'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 6-7: month. */ if (!partline(substr,line,5,2)){ sprintf (isf_bulletin_error,"missing month: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad month: %s",line); return 20; } *mm = atoi(substr); /* Char 8: '/' character. */ if (line[7] != '/'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 9-10: day. */ if (!partline(substr,line,8,2)){ sprintf (isf_bulletin_error,"missing day: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad day: %s",line); return 20; } *dd = atoi(substr); /* Char 11: space. */ if (line[10] != ' '){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 12,13: hour. */ if (!partline(substr,line,11,2)){ sprintf (isf_bulletin_error,"missing hour: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad hour: %s",line); return 20; } *hh = atoi(substr); /* Char 14: ':' character. */ if (line[13] != ':'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 15,16: minute. */ if (!partline(substr,line,14,2)){ sprintf (isf_bulletin_error,"missing minute: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad minute: %s",line); return 20; } *mi = atoi(substr); /* Char 17: ':' character. */ if (line[16] != ':'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 18,19: integral second. */ if (!partline(substr,line,17,2)){ sprintf (isf_bulletin_error,"missing second: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad second: %s",line); return 20; } *ss = atoi(substr); /* Char 20-22: msec or spaces. */ /* Allow decimal place with no numbers after it. */ if (partline(substr,line,20,2)){ /* Char 20: '.' character */ if (line[19] != '.'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 21,22: 10s of msec. */ if (!isdigit(line[20])){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *msec = (line[20]-'0')*100; if (isdigit(line[21])){ *msec += (line[21]-'0')*10; } else if (line[21] != ' ') { sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } } else { /* Char 20: '.' character or space */ if (line[19] != '.' && line[19] != ' '){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *msec = ISF_NULL; } /* Char 23: timfix - either f or space. */ if (line[22] == ' ' || line[22] == 'f'){ *timfix = line[22]; } else { sprintf (isf_bulletin_error,"bad timfix: %s",line); return 20; } /* Char 24: space. */ if (line[23] != ' '){ sprintf (isf_bulletin_error,"bad format, char 24: %s",line); return 20; } /* Chars 25-29: origin time error - float if anything. */ if (partline(substr,line,24,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad stime: %s",line); return 20; } *stime = (float)atof(substr); } else { *stime = ISF_NULL; } /* Char 30: space. */ if (line[29] != ' '){ sprintf (isf_bulletin_error,"bad format, char 30: %s",line); return 20; } /* Chars 31-35: rms (sdobs) - float if anything. */ if (partline(substr,line,30,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad sdobs: %s",line); return 20; } *sdobs = (float)atof(substr); } else { *sdobs = ISF_NULL; } /* Char 36: space. */ if (line[35] != ' '){ sprintf (isf_bulletin_error,"bad format, char 36: %s",line); return 20; } /* Chars 37-44: lattitude - must be there. */ if (!partline(substr,line,36,8)){ sprintf (isf_bulletin_error,"missing lattitude: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad lattitude: %s",line); return 20; } *lat = (float)atof(substr); /* Char 45: space. */ if (line[44] != ' '){ sprintf (isf_bulletin_error,"bad format, char 45: %s",line); return 20; } /* Chars 46-54: longitude - must be float. */ if (!partline(substr,line,45,9)){ sprintf (isf_bulletin_error,"missing longitude: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad longitude: %s",line); return 20; } *lon = (float)atof(substr); /* Char 55: epifix - either f or space. */ if (line[54] == ' ' || line[54] == 'f'){ *epifix = line[54]; } else { sprintf (isf_bulletin_error,"bad epifix: %s",line); return 20; } /* Chars 56-60: semi-major axis of error ellipse - float if there. */ /* This is departure from format but smaj < smin is daft. */ if (partline(substr,line,55,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad smaj: %s",line); return 20; } *smaj = (float)atof(substr); } else { *smaj = ISF_NULL; } /* Char 61: space. */ if (line[60] != ' '){ sprintf (isf_bulletin_error,"bad format, char 61: %s",line); return 20; } /* Chars 62-66: semi-minor axis of error ellipse - float if there. */ if (partline(substr,line,61,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad smin: %s",line); return 20; } *smin = (float)atof(substr); } else { *smin = ISF_NULL; } /* Char 67: space. */ if (line[66] != ' '){ sprintf (isf_bulletin_error,"bad format, char 67: %s",line); return 20; } /* Chars 68-70: strike - integer if there. */ if (partline(substr,line,67,3)){ if (check_int(substr)){ sprintf (isf_bulletin_error,"bad strike: %s",line); return 20; } *strike = atoi(substr); } else { *strike = ISF_NULL; } /* Char 71: space. */ if (line[70] != ' '){ sprintf (isf_bulletin_error,"bad format, char 71: %s",line); return 20; } /* Chars 72-76: depth - float if there. */ if (partline(substr,line,71,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad depth: %s",line); return 20; } *depth = (float)atof(substr); } else { *depth = ISF_NULL; } /* Char 77: depfix - either f,d, or space. */ if (line[76] == ' ' || line[76] == 'f' || line[76] == 'd'){ *depfix = line[76]; } else { sprintf (isf_bulletin_error,"bad depfix: %s",line); return 20; } /* Char 78: space. */ if (line[77] != ' '){ sprintf (isf_bulletin_error,"bad format, char 78: %s",line); return 20; } /* Chars 79-82: depth error - float if there. */ if (partline(substr,line,78,4)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad sdepth: %s",line); return 20; } *sdepth = (float)atof(substr); } else { *sdepth = ISF_NULL; } /* Char 83: space. */ if (line[82] != ' '){ sprintf (isf_bulletin_error,"bad format, char 83: %s",line); return 20; } /* Chars 84-87: ndef - integer if there. */ if (partline(substr,line,83,4)){ if (check_int(substr)){ sprintf (isf_bulletin_error,"bad ndef: %s",line); return 20; } *ndef = atoi(substr); } else { *ndef = ISF_NULL; } /* Char 88: space. */ if (line[87] != ' '){ sprintf (isf_bulletin_error,"bad format, char 88: %s",line); return 20; } /* Chars 89-92: nsta - integer if there. */ if (partline(substr,line,88,4)){ if (check_int(substr)){ sprintf (isf_bulletin_error,"bad nsta: %s",line); return 20; } *nsta = atoi(substr); } else { *nsta = ISF_NULL; } /* Char 93: space. */ if (line[92] != ' '){ sprintf (isf_bulletin_error,"bad format, char 93: %s",line); return 20; } /* Chars 94-96: gap - integer if there */ if (partline(substr,line,93,3)){ if (check_int(substr)){ sprintf (isf_bulletin_error,"bad gap: %s",line); return 20; } *gap = atoi(substr); } else { *gap = ISF_NULL; } /* Char 97: space. */ if (line[96] != ' '){ sprintf (isf_bulletin_error,"bad format, char 97: %s",line); return 20; } /* Chars 98-103: minimum distance - float if there. */ if (partline(substr,line,97,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mindist: %s",line); return 20; } *mindist = (float)atof(substr); } else { *mindist = ISF_NULL; } /* Char 104: space. */ if (line[103] != ' '){ sprintf (isf_bulletin_error,"bad format, char 104: %s",line); return 20; } /* Chars 105-110: maximum distance - float if there. */ if (partline(substr,line,104,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad maxdist: %s",line); return 20; } *maxdist = (float)atof(substr); } else { *maxdist = ISF_NULL; } /* Char 111: space. */ if (line[110] != ' '){ sprintf (isf_bulletin_error,"bad format, char 111: %s",line); return 20; } /* Char 112: analysis type - either space, a, m, or g. */ if (line[111] == ' ' || line[111] == 'a' || line[111] == 'm' || \ line[111] =='g' ){ *antype = line[111]; } else { sprintf (isf_bulletin_error,"bad antype: %s",line); return 20; } /* Char 113: space. */ if (line[112] != ' '){ sprintf (isf_bulletin_error,"bad format, char 113: %s",line); return 20; } /* Char 114: location method - either space, i, p, g, or o. */ if (line[113] == ' ' || line[113] == 'i' || line[113] == 'p' || \ line[113] =='g' || line[113] == 'o'){ *loctype = line[113]; } else { sprintf (isf_bulletin_error,"bad loctype: %s",line); return 20; } /* Char 115: space. */ if (line[114] != ' '){ sprintf (isf_bulletin_error,"bad format, char 115: %s",line); return 20; } /* Chars 116-117: event type, any characters allowed but must be there. */ if (!partline(etype,line,115,2)){ strcpy(etype,""); } else if (strlen(etype) != ISF_ETYPE_LEN){ sprintf (isf_bulletin_error,"bad etype: %s",line); return 20; } /* Char 118: space. */ if (line[117] != ' '){ sprintf (isf_bulletin_error,"bad format, char 118: %s",line); return 20; } /* Chars 119-127: author, any characters allowed but must be there. */ if (!partline(author,line,118,9)){ sprintf (isf_bulletin_error,"missing author: %s",line); return 20; } if (check_whole(author)){ sprintf (isf_bulletin_error,"bad author: %s",line); return 20; } /* Char 128: space */ if (line[127] != ' '){ sprintf (isf_bulletin_error,"bad format, char 128: %s",line); return 20; } /* Chars 129-136: origin ID, any characters allowed but must be there. */ if (!partline(origid,line,128,8)){ sprintf (isf_bulletin_error,"missing origid: %s",line); return 20; } if (check_whole(origid)){ sprintf (isf_bulletin_error,"bad origid: %s",line); return 20; } /* Check for extra stuff after char 136. */ if (partline(substr,line,136,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line to test whether it is a prime origin label. Returns 0 if the line is a properly formatted prime origin line. Returns 20 and writes a diagnostic to isf_bulletin_error if not. */ int read_origin_prime(char *line) { char substr[ISF_LINE_LEN]; if (strncmp(line," (#PRIME)",9)){ sprintf (isf_bulletin_error,"not a prime comment: %s",line); return 20; } if (partline(substr,line,10,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line to test whether it is a centroid origin label. Returns 0 if the line is a properly formatted centroid origin line. Returns 20 and writes a diagnostic to isf_bulletin_error if not. */ int read_origin_centroid(char *line) { char substr[ISF_LINE_LEN]; if (strncmp(line," (#CENTROID)",12)){ sprintf (isf_bulletin_error,"not a centroid comment: %s",line); return 20; } if (partline(substr,line,13,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line assuming it to be an origin parameter formatted comment. Accepts any number of parameter=value pairs as long as the line is short enough. Returns 0 if the line is a properly formatted origin paramter line. Returns 20 and writes a diagnostic to isf_bulletin_error if not. */ int read_origin_param(char *line, char **param, char **value, char **error, int *numparam) { int i,j,k; char *pair[ISF_NUM_PARAM]; char substr[ISF_LINE_LEN]; pair[0] = (char *)malloc(ISF_COMM_LEN); /* Chars 1-9: should be the string ' (#PARAM ' */ if (strncmp(line," (#PARAM ",9) != 0){ sprintf (isf_bulletin_error,"not an origin parameter line: %s",line); return 20; } if ( strlen(line) > ISF_COMM_LEN+10 ){ sprintf (isf_bulletin_error,"line too long: %s",line); return 20; } /* Go through the rest of the line one character at a time, separating words on ' ' to get param=value pairs. */ i=9; j=0; k=0; while (line[i] == ' '){i++;} while (line[i]){ if (line[i]==')' || line[i]=='\0' || line[i]=='\n'){ pair[k][j]='\0'; k++; break; } if (line[i]==' '){ pair[k][j]='\0'; i++; j=0; pair[++k] = (char *)malloc(ISF_COMM_LEN); } else { pair[k][j++]=line[i++]; } } *numparam=k; /* Check for extra stuff */ if (partline(substr,line,++i,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } /* Go through the seperate pairs splitting them into param and value */ for (k=0; k< *numparam; k++){ param[k] = (char *)malloc(ISF_COMM_LEN); value[k] = (char *)malloc(ISF_COMM_LEN); i=0; j=0; while (pair[k][i]){ if (pair[k][i]=='\0'){ sprintf (isf_bulletin_error,"param without value: %s",line); return 20; } if (pair[k][i]=='='){ param[k][j]='\0'; break; } param[k][j++]=pair[k][i++]; } i++; j=0; while (pair[k][i]){ if (pair[k][i]=='\0'){ value[k][j]='\0'; break; } value[k][j++]=pair[k][i++]; } } /* Go through the values in case any of them include an error value. */ for (k=0; k< *numparam; k++){ error[k] = (char *)malloc(ISF_COMM_LEN); i=0; while (value[k][i]){ if (value[k][i]=='\0'){ break; } if (value[k][i]=='+'){ error[k] = &value[k][i+1]; value[k][i]='\0'; break; } i++; } } return 0; } /* Tests a line to discover if it is a first moment tensor header comment. Returns 0 if the line is a first moment tensor header line. Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_momten_head_1(char *line) { char substr[ISF_LINE_LEN]; char head[] = " (#MOMTENS sc M0 fCLVD MRR MTT MPP MRT MTP MPR NST1 NST2 Author )"; int headlen = 88; if (strncmp(line,head,headlen) != 0){ sprintf (isf_bulletin_error,"not a momten header: %s",line); return 20; } if (partline(substr,line,headlen,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Tests a line to discover if it is a second moment tensor header comment. Returns 0 if the line is a second moment tensor header line. Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_momten_head_2(char *line) { char substr[ISF_LINE_LEN]; char head[] = " (# eM0 eCLVD eRR eTT ePP eRT eTP ePR NCO1 NCO2 Duration )"; int headlen = 88; if (strncmp(line,head,headlen) != 0){ sprintf (isf_bulletin_error,"not a momten header2: %s",line); return 20; } if (partline(substr,line,headlen,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line asuming it to be a first moment tensor data comment. Values are asigned to variables, the pointers to which have been sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is a properly formatted first moment tensor data line. Returns 20 and writes a diagnostic to isf_bulletin_error on error. */ int read_momten_line_1(char *line, int *scale_factor, float *scalar_moment, float *fclvd, float *mrr, float *mtt, float *mpp, float *mrt, float *mtp, float *mpr, int *nsta1, int *nsta2, char *author) { char substr[ISF_LINE_LEN]; /* Chars 1-11: should be the string ' (# ' */ if (strncmp(line," (# ",11) != 0){ sprintf (isf_bulletin_error,"not a moment tensor line: %s",line); return 20; } /* Chars 12,13: scale factor - integer */ if (!partline(substr,line,11,2)){ sprintf (isf_bulletin_error,"missing scale factor: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad scale factor: %s",line); return 20; } *scale_factor = atoi(substr); /* Char 14: must be a space */ if (line[13] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 14: %s",line); return 20; } /* Chars 15-19: scalar seismic moment - must be float. */ if (!partline(substr,line,14,5)){ sprintf (isf_bulletin_error,"missing moment: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad moment: %s",line); return 20; } *scalar_moment = (float)atof(substr); /* Char 20: must be a space */ if (line[19] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 20: %s",line); return 20; } /* Chars 21-25: fCLVD, float if anything */ if (partline(substr,line,20,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad fclvd: %s",line); return 20; } *fclvd = (float)atof(substr); } else { *fclvd = ISF_NULL; } /* Char 26: must be a space */ if (line[25] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 26: %s",line); return 20; } /* Chars 27-32: radial-radial element, float if anything */ if (partline(substr,line,26,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mrr: %s",line); return 20; } *mrr = (float)atof(substr); } else { *mrr = ISF_NULL; } /* Char 33: must be a space */ if (line[32] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 33: %s",line); return 20; } /* Chars 34-39: theta-theta element, float if anything */ if (partline(substr,line,33,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mtt: %s",line); return 20; } *mtt = (float)atof(substr); } else { *mtt = ISF_NULL; } /* Char 40: must be a space */ if (line[39] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 40: %s",line); return 20; } /* Chars 41-46: phi-phi element, float if anything */ if (partline(substr,line,40,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mpp: %s",line); return 20; } *mpp = (float)atof(substr); } else { *mpp = ISF_NULL; } /* Char 47: must be a space */ if (line[46] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 47: %s",line); return 20; } /* Chars 48-53: radial-theta element, float if anything */ if (partline(substr,line,47,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mrt: %s",line); return 20; } *mrt = (float)atof(substr); } else { *mrt = ISF_NULL; } /* Char 54: must be a space */ if (line[53] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 54: %s",line); return 20; } /* Chars 55-60: theta-phi element, float if anything */ if (partline(substr,line,54,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mtp: %s",line); return 20; } *mtp = (float)atof(substr); } else { *mtp = ISF_NULL; } /* Char 61: must be a space */ if (line[60] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 61: %s",line); return 20; } /* Chars 62-67: phi-radial element, float if anything */ if (partline(substr,line,61,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mpr: %s",line); return 20; } *mpr = (float)atof(substr); } else { *mpr = ISF_NULL; } /* Char 68: must be a space */ if (line[67] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 68: %s",line); return 20; } /* Chars 69-72: nsta1, int if anything */ if (partline(substr,line,68,4)){ if (check_int(substr)){ sprintf (isf_bulletin_error,"bad nsta1: %s",line); return 20; } *nsta1 = atoi(substr); } else { *nsta1 = ISF_NULL; } /* Char 73: must be a space */ if (line[72] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 73: %s",line); return 20; } /* Chars 74-77: nsta2, int if anything */ if (partline(substr,line,73,4)){ if (check_int(substr)){ sprintf (isf_bulletin_error,"bad nsta2: %s",line); return 20; } *nsta2 = atoi(substr); } else { *nsta2 = ISF_NULL; } /* Char 78: must be a space */ if (line[77] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 78: %s",line); return 20; } /* Chars 79-87: author, any characters allowed but must be there. */ if (!partline(author,line,78,9)){ sprintf (isf_bulletin_error,"missing author: %s",line); return 20; } if (check_whole(author)){ sprintf (isf_bulletin_error,"bad author: %s",line); return 20; } /* Check for extra characters - could be close bracket somewhere. */ if (partline(substr,line,87,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line asuming it to be a second moment tensor data comment. Values are asigned to variables, the pointers to which have been sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is properly formatted second moment tensor data. Returns 20 and writes a diagnostic to isf_bulletin_error on error. */ int read_momten_line_2(char *line, float *scalar_moment_unc, float *fclvd_unc, float *mrr_unc, float *mtt_unc, float *mpp_unc, float *mrt_unc, float *mtp_unc, float *mpr_unc, int *ncomp1, int *ncomp2, float *duration) { char substr[ISF_LINE_LEN]; /* Chars 1-14: should be the string ' (# '. */ if (strncmp(line," (# ",14) != 0){ sprintf (isf_bulletin_error,"not a moment tensor line: %s",line); return 20; } /* Chars 15-19: uncertainty in scalar seismic moment - float if there. */ if (partline(substr,line,14,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad scalar_moment_unc: %s",line); return 20; } *scalar_moment_unc = (float)atof(substr); } else { *scalar_moment_unc = ISF_NULL; } /* Char 20: must be a space. */ if (line[19] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 20: %s",line); return 20; } /* Chars 21-25: uncertainty in fCLVD, float if anything. */ if (partline(substr,line,20,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad fclvd_unc: %s",line); return 20; } *fclvd_unc = (float)atof(substr); } else { *fclvd_unc = ISF_NULL; } /* Char 26: must be a space. */ if (line[25] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 26: %s",line); return 20; } /* Chars 27-32: uncertainty in radial-radial element, float if anything. */ if (partline(substr,line,26,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mrr_unc: %s",line); return 20; } *mrr_unc = (float)atof(substr); } else { *mrr_unc = ISF_NULL; } /* Char 33: must be a space. */ if (line[32] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 33: %s",line); return 20; } /* Chars 34-39: uncertainty in theta-theta element, float if anything. */ if (partline(substr,line,33,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mtt_unc: %s",line); return 20; } *mtt_unc = (float)atof(substr); } else { *mtt_unc = ISF_NULL; } /* Char 40: must be a space */ if (line[39] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 40: %s",line); return 20; } /* Chars 41-46: uncertainty in phi-phi element, float if anything. */ if (partline(substr,line,40,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mpp_unc: %s",line); return 20; } *mpp_unc = (float)atof(substr); } else { *mpp_unc = ISF_NULL; } /* Char 47: must be a space */ if (line[46] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 47: %s",line); return 20; } /* Chars 48-53: uncertainty in radial-theta element, float if anything. */ if (partline(substr,line,47,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mrt_unc: %s",line); return 20; } *mrt_unc = (float)atof(substr); } else { *mrt_unc = ISF_NULL; } /* Char 54: must be a space. */ if (line[53] != ' ' ){ sprintf (isf_bulletin_error,"bad format: %s",line); return 20; } /* Chars 55-60: uncertainty in theta-phi element, float if anything. */ if (partline(substr,line,54,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mtp_unc: %s",line); return 20; } *mtp_unc = (float)atof(substr); } else { *mtp_unc = ISF_NULL; } /* Char 61: must be a space. */ if (line[60] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 61: %s",line); return 20; } /* Chars 62-67: uncertainty in phi-radial element, float if anything. */ if (partline(substr,line,61,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mpr_unc: %s",line); return 20; } *mpr_unc = (float)atof(substr); } else { *mpr_unc = ISF_NULL; } /* Char 68: must be a space. */ if (line[67] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 68: %s",line); return 20; } /* Chars 69-72: ncomp1, int if anything. */ if (partline(substr,line,68,4)){ if (check_int(substr)){ sprintf (isf_bulletin_error,"bad ncomp1: %s",line); return 20; } *ncomp1 = atoi(substr); } else { *ncomp1 = ISF_NULL; } /* Char 73: must be a space */ if (line[72] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 73: %s",line); return 20; } /* Chars 74-77: ncomp2, int if anything. */ if (partline(substr,line,73,4)){ if (check_int(substr)){ sprintf (isf_bulletin_error,"bad ncomp2: %s",line); return 20; } *ncomp2 = atoi(substr); } else { *ncomp2 = ISF_NULL; } /* Char 78: must be a space. */ if (line[77] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 78: %s",line); return 20; } /* Chars 79-86: duration, float if anything. */ if (partline(substr,line,78,8)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad duration: %s",line); return 20; } *duration = (float)atof(substr); } else { *duration = ISF_NULL; } /* Check for extra stuff - not including close bracket. */ if (partline(substr,line,86,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Tests a line to discover if it is a fault plane header comment. Returns 0 if the line is a fault plane header. Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_fault_plane_head(char *line) { char substr[ISF_LINE_LEN]; char head[] = " (#FAULT_PLANE Typ Strike Dip Rake NP NS Plane Author )"; int headlen = 64; if (strncmp(line,head,headlen) != 0){ sprintf (isf_bulletin_error,"not a fault plane header: %s",line); return 20; } if (partline(substr,line,headlen,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line asuming it to be a fault plane data comment. Could be first or second plane, the only difference is whether author field is expected or not. Values are asigned to variables, the pointers to which have been sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is a properly formatted fault plane data line. Returns 20 and writes a diagnostic to isf_bulletin_error on error. */ int read_fault_plane (char *line, char *f_type, float *strike, float *dip, float *rake, int *np, int *ns, char *f_plane, char *author) { char substr[ISF_LINE_LEN]; int line_num; /* Chars 1-3: the strings ' (#' or ' (+', */ /* depending on whether this is the first or second plane given. */ /* Chars 4-15: spaces. */ if (strncmp(line," (# ",15) == 0){ line_num = 1; } else if (strncmp(line," (+ ",15) == 0){ line_num = 2; } else { sprintf (isf_bulletin_error,"not a fault plane line: %s",line); return 20; } /* Chars 16-18: fault plane solution type. */ if (partline(f_type,line,15,3)){ if (strcmp(f_type,"FM") && strcmp(f_type,"BB") && strcmp(f_type,"BDC")){ sprintf (isf_bulletin_error,"bad f_type: %s",line); return 20; } } else { strcpy(f_type,""); } /* Char 19: must be a space */ if (line[18] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 19: %s",line); return 20; } /* Chars 20-25: strike, must be float. */ if (!partline(substr,line,19,6)){ sprintf (isf_bulletin_error,"missing strike: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad strike: %s",line); return 20; } *strike = (float)atof(substr); /* Char 26: must be a space. */ if (line[25] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 26: %s",line); return 20; } /* Chars 27-31: dip, must be float. */ if (!partline(substr,line,26,5)){ sprintf (isf_bulletin_error,"missing dip: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad dip: %s",line); return 20; } *dip = (float)atof(substr); /* Char 32: must be a space. */ if (line[31] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 32: %s",line); return 20; } /* Chars 33-39: rake, float - need not be there if both planes given. */ if (partline(substr,line,32,7)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad rake: %s",line); return 20; } *rake = (float)atof(substr); } else { *rake = ISF_NULL; } /* Char 40: must be a space. */ if (line[39] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 40: %s",line); return 20; } /* Chars 41-43: np, int if there. */ if (partline(substr,line,40,3)){ if (check_int(substr)){ sprintf (isf_bulletin_error,"bad np: %s",line); return 20; } *np = atoi(substr); } else { *np = ISF_NULL; } /* Char 44: must be a space. */ if (line[43] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 44: %s",line); return 20; } /* Chars 45-47: ns, int if there. */ if (partline(substr,line,44,3)){ if (check_int(substr)){ sprintf (isf_bulletin_error,"bad ns: %s",line); return 20; } *ns = atoi(substr); } else { *ns = ISF_NULL; } /* Char 48: must be a space. */ if (line[47] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 48: %s",line); return 20; } /* Chars 49-53: plane identification. */ if (partline(f_plane,line,48,5)){ if (strcmp(f_plane,"FAULT") != 0 && strcmp(f_plane,"AUXIL") != 0){ sprintf (isf_bulletin_error,"bad f_plane: %s",line); return 20; } } else { strcpy(f_plane,""); } /* Chars 54-63: First plane has author, don't read for second plane. */ if (line_num==1){ /* Char 54: must be a space */ if (line[53] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 54: %s",line); return 20; } /* Chars 55-63: author, any characters allowed but must be there */ if (!partline(author,line,54,9)){ sprintf (isf_bulletin_error,"missing author: %s",line); return 20; } if (check_whole(author)){ sprintf (isf_bulletin_error,"bad author: %s",line); return 20; } } /* Check for extra stuff - not including close bracket */ if (partline(substr,line,63,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Tests a line to discover if it is a principal axes header comment. Returns 0 if the line is a principal axes header. Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_axes_head(char *line) { char substr[ISF_LINE_LEN]; char head[] = " (#PRINAX sc T_val T_azim T_pl B_val B_azim B_pl P_val P_azim P_pl Author )"; int headlen = 83; if (strncmp(line,head,headlen) != 0){ sprintf (isf_bulletin_error,"not an axes header: %s",line); return 20; } if (partline(substr,line,headlen,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Tests a line to discover if it is a principal axes error header comment. This line may or may not be present regardless of whether there is an error data line or not. Returns 0 if the line is a principal axes error header. Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_axes_err_head(char *line) { char substr[ISF_LINE_LEN]; char head[] = " (+ eTv eTa eTp eBv eBa eBp ePv ePa ePp fCLVD )"; int headlen = 83; if (strncmp(line,head,headlen) != 0){ sprintf (isf_bulletin_error,"not an axes error header: %s",line); return 20; } if (partline(substr,line,headlen,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line asuming it to be a principal axes data comment. Values are asigned to variables, the pointers to which have been sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is a properly formatted principal axes data line. Returns 20 and writes a diagnostic to isf_bulletin_error on error. */ int read_axes(char *line, int *scale_factor, float *t_val, float *t_azim, float *t_pl, float *b_val, float *b_azim, float *b_pl, float *p_val, float *p_azim, float *p_pl, char *author) { char substr[ISF_LINE_LEN]; /* Chars 1-10: should be the string ' (# '. */ if (strncmp(line," (# ",10) != 0){ sprintf (isf_bulletin_error,"not an axes line: %s",line); return 20; } /* Chars 11,12: scale factor - int if there. */ if (partline(substr,line,10,2)){ if (check_int(substr)){ sprintf (isf_bulletin_error,"bad scale factor: %s",line); return 20; } *scale_factor = atoi(substr); } else { *scale_factor = ISF_NULL; } /* Char 13: must be a space. */ if (line[12] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 13: %s",line); return 20; } /* Chars 14-19: t value - float if there. */ if (partline(substr,line,13,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad t_val: %s",line); return 20; } *t_val = (float)atof(substr); } else { *t_val = ISF_NULL; } /* Char 20: must be a space. */ if (line[19] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 20: %s",line); return 20; } /* Chars 21-26: t azim, must be float. */ if (!partline(substr,line,20,6)){ sprintf (isf_bulletin_error,"missing t_azim: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad t_azim: %s",line); return 20; } *t_azim = (float)atof(substr); /* Char 27: must be a space. */ if (line[26] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 27: %s",line); return 20; } /* Chars 28-32: t plunge, must be float. */ if (!partline(substr,line,27,5)){ sprintf (isf_bulletin_error,"missing t_pl: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad t_pl: %s",line); return 20; } *t_pl = (float)atof(substr); /* Char 33: must be a space. */ if (line[32] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 33: %s",line); return 20; } /* Chars 34-39: b value - float if there. */ if (partline(substr,line,33,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad b_val: %s",line); return 20; } *b_val = (float)atof(substr); } else { *b_val = ISF_NULL; } /* Char 40: must be a space. */ if (line[39] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 40: %s",line); return 20; } /* Chars 41-46: b azim, must be float. */ if (!partline(substr,line,40,6)){ sprintf (isf_bulletin_error,"missing b_azim: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad b_azim: %s",line); return 20; } *b_azim = (float)atof(substr); /* Char 47: must be a space. */ if (line[46] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 47: %s",line); return 20; } /* Chars 48-52: b plunge, must be float. */ if (!partline(substr,line,47,5)){ sprintf (isf_bulletin_error,"missing b_pl: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad b_pl: %s",line); return 20; } *b_pl = (float)atof(substr); /* Char 53: must be a space. */ if (line[52] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 53: %s",line); return 20; } /* Chars 54-59: p value - float if there. */ if (partline(substr,line,53,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad p_val: %s",line); return 20; } *p_val = (float)atof(substr); } else { *p_val = ISF_NULL; } /* Char 60: must be a space. */ if (line[59] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 60: %s",line); return 20; } /* Chars 61-66: p azim, must be float. */ if (!partline(substr,line,60,6)){ sprintf (isf_bulletin_error,"missing p_azim: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad p_azim: %s",line); return 20; } *p_azim = (float)atof(substr); /* Char 67: must be a space. */ if (line[66] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 67: %s",line); return 20; } /* Chars 68-72: p plunge, must be float */ if (!partline(substr,line,67,5)){ sprintf (isf_bulletin_error,"missing p_pl: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad p_pl: %s",line); return 20; } *p_pl = (float)atof(substr); /* Char 73: must be a space. */ if (line[72] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 73: %s",line); return 20; } /* Chars 74-82: author, any characters allowed but must be there. */ if (!partline(author,line,73,9)){ sprintf (isf_bulletin_error,"missing author: %s",line); return 20; } if (check_whole(author)){ sprintf (isf_bulletin_error,"bad author: %s",line); return 20; } /* Check for extra stuff - not including close bracket. */ if (partline(substr,line,82,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line asuming it to be a principal axes error comment. Values are asigned to variables, the pointers to which have been sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is a properly formatted principal axes error line. Returns 20 and writes a diagnostic to isf_bulletin_error on error. */ int read_axes_err(char *line, float *t_val_unc, float *t_azim_unc, float *t_pl_unc, float *b_val_unc, float *b_azim_unc, float *b_pl_unc, float *p_val_unc, float *p_azim_unc, float *p_pl_unc, float *fclvd) { char substr[ISF_LINE_LEN]; /* Chars 1-14: should be the string ' (+ '. */ if (strncmp(line," (+ ",10) != 0){ sprintf (isf_bulletin_error,"not an axes err line: %s",line); return 20; } /* Chars 15-19: t value uncertainty. */ if (partline(substr,line,14,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad t_val_unc: %s",line); return 20; } *t_val_unc = (float)atof(substr); } else { *t_val_unc = ISF_NULL; } /* Char 20: must be a space. */ if (line[19] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 20: %s",line); return 20; } /* Chars 21-26: t azim uncertainty. */ if (partline(substr,line,20,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad t_azim_unc: %s",line); return 20; } *t_azim_unc = (float)atof(substr); } else { *t_azim_unc = ISF_NULL; } /* Char 27: must be a space. */ if (line[26] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 27: %s",line); return 20; } /* Chars 28-32: t plunge uncertainty. */ if (partline(substr,line,27,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad t_pl_unc: %s",line); return 20; } *t_pl_unc = (float)atof(substr); } else { *t_pl_unc = ISF_NULL; } /* Char 33,34: must be a spaces. */ if (line[32] != ' ' || line[33] != ' '){ sprintf (isf_bulletin_error,"bad format, char 33,34: %s",line); return 20; } /* Chars 35-39: b value uncertainty. */ if (partline(substr,line,34,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad b_val_unc: %s",line); return 20; } *b_val_unc = (float)atof(substr); } else { *b_val_unc = ISF_NULL; } /* Char 40: must be a space. */ if (line[39] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 40: %s",line); return 20; } /* Chars 41-46: b azim uncertainty. */ if (partline(substr,line,40,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad b_azim_unc: %s",line); return 20; } *b_azim_unc = (float)atof(substr); } else { *b_azim_unc = ISF_NULL; } /* Char 47: must be a space. */ if (line[46] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 47: %s",line); return 20; } /* Chars 48-52: b plunge uncertainty. */ if (partline(substr,line,47,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad b_pl_unc: %s",line); return 20; } *b_pl_unc = (float)atof(substr); } else { *b_pl_unc = ISF_NULL; } /* Char 53,54: must be a spaces. */ if (line[52] != ' ' || line[53] != ' ' ){ sprintf (isf_bulletin_error,"bad format, chars 53,54: %s",line); return 20; } /* Chars 55-59: p value uncertainty. */ if (partline(substr,line,54,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad p_val_unc: %s",line); return 20; } *p_val_unc = (float)atof(substr); } else { *p_val_unc = ISF_NULL; } /* Char 60: must be a space. */ if (line[59] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 60: %s",line); return 20; } /* Chars 61-66: p azim uncertainty. */ if (partline(substr,line,60,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad p_azim_unc: %s",line); return 20; } *p_azim_unc = (float)atof(substr); } else { *p_azim_unc = ISF_NULL; } /* Char 67: must be a space. */ if (line[66] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 67: %s",line); return 20; } /* Chars 68-72: p plunge uncertainty. */ if (partline(substr,line,67,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad p_pl_unc: %s",line); return 20; } *p_pl_unc = (float)atof(substr); } else { *p_pl_unc = ISF_NULL; } /* Char 73: must be a space. */ if (line[72] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 73: %s",line); return 20; } /* Chars 74-78: fclvd. */ if (partline(substr,line,73,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad fclvd: %s",line); return 20; } *fclvd = (float)atof(substr); } else { *fclvd = ISF_NULL; } /* Check for extra stuff - not including close bracket. */ if (partline(substr,line,78,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* To check that a line is a good magnitude block header line. Returns 0 if the line is a magnitude block header. Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_netmag_head(char *line) { char substr[ISF_LINE_LEN]; char head[] = "Magnitude Err Nsta Author OrigID"; int headlen = 38; if (strncmp(line,head,headlen) != 0){ sprintf (isf_bulletin_error,"not a netmag header: %s",line); return 20; } if (partline(substr,line,headlen,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line assuming that it is a magnitude sub-block data line. Values are asigned to variables, the pointers to which have been sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is a properly formatted magnitude line, Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_netmag( char *line, char *magtype, char* magind, float* mag, float* magerr, int* nsta, char* author, char* origid) { char substr[ISF_LINE_LEN]; /* Chars 1-5: magnitude type, any characters allowed but must be there. */ if (!partline(magtype,line,0,5)){ sprintf (isf_bulletin_error,"missing magtype: %s",line); return 20; } if (check_whole(magtype)){ sprintf (isf_bulletin_error,"bad magtype: %s",line); return 20; } /* Char 6: less than or greater than indicator or space only. */ if (line[5] == ' ' || line[5] == '<' || line[5] == '>'){ *magind = line[5]; } else { sprintf (isf_bulletin_error,"bad magind: %s",line); return 20; } /* Chars 7-10: magnitude, must be float. */ if (!partline(substr,line,6,4)){ sprintf (isf_bulletin_error,"missing magnitude: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad magnitude: %s",line); return 20; } *mag = (float)atof(substr); /* Char 11: must be a space. */ if (line[10] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 11: %s",line); return 20; } /* Chars 12-14: magnitude error, float if anything. */ if (partline(substr,line,11,3)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad magnitude error: %s",line); return 20; } *magerr = (float)atof(substr); } else { *magerr = ISF_NULL; } /* Char 15: must be a space. */ if (line[14] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 15: %s",line); return 20; } /* Chars 16-19: number of stations, integer if anything. */ if (partline(substr,line,15,4)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad nsta: %s",line); return 20; } *nsta = atoi(substr); } else { *nsta = ISF_NULL; } /* Char 20: must be a space. */ if (line[19] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 20: %s",line); return 20; } /* Chars 21-29: author, any characters allowed but must be there. */ if (!partline(author,line,20,9)){ sprintf (isf_bulletin_error,"missing author: %s",line); return 20; } if (check_whole(author)){ sprintf (isf_bulletin_error,"bad author: %s",line); return 20; } /* Char 30: must be a space. */ if (line[29] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 30: %s",line); return 20; } /* Chars 31-38: origin ID, any characters allowed but must be there. */ if (!partline(origid,line,30,8)){ sprintf (isf_bulletin_error,"missing origid: %s",line); return 20; } if (check_whole(origid)){ sprintf (isf_bulletin_error,"bad origid: %s",line); return 20; } /* Check for extra stuff after char 38. */ if (partline(substr,line,38,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* The stations contributing to a given netmag can follow in one or more formated comment lines and are separated by spaces. The array of station code strings sta has size n, if the subroutine is being run on a second or subsequent line then n will already be set and will be updated by this routine as more codes are added. */ int read_netmag_sta(char *line, char **sta, int* n) { int i,j,line_len; /* If it is the first then initialise array of station codes. */ /* If not it must be a follow on line or something is wrong. */ if (strncmp(" (#STATIONS ",line,12) == 0){ *n = 0; sta[*n] = (char *)malloc(ISF_STA_LEN+1); } else if(strncmp(" (+ ",line,12) == 0){ if (*n > ISF_NUM_STA ){ sprintf (isf_bulletin_error,"too many stations: %s",line); return 20; } sta[*n] = (char *)malloc(ISF_STA_LEN+1); } else{ sprintf (isf_bulletin_error,"bad station list format: %s",line); return 20; } /* Don't read close bracket, if there's one there. */ for (i=strlen(line)-1; i>0; i--){ if (line[i] == '\n') continue; if (line[i] == ' ') continue; if (line[i] == ')') continue; break; } line_len=i+1; if ( line_len > ISF_LINE_LEN ){ sprintf (isf_bulletin_error,"line too long: %s",line); return 20; } /* Fill array of station codes. */ /* As each code is finished allocate memory for the next. */ for (i=12,j=0; i 0){ /* Check that this looks like a station code. */ if (!isupper(sta[*n][0])){ sprintf (isf_bulletin_error,"illegal station: %s",sta[*n]); return 20; } sta[*n][j] = '\0'; if (++(*n) > ISF_NUM_STA ){ sprintf (isf_bulletin_error,"too many stations: %s",line); return 20; } sta[*n] = (char *)malloc(ISF_NET_LEN+ISF_STA_LEN); j=0; } continue; } if (j>ISF_NET_LEN+ISF_STA_LEN){ sprintf (isf_bulletin_error,"station code too long: %s",line); return 20; } sta[*n][j++] = line[i]; } /* Check that the last one looks like a station code. */ if (!isupper(sta[*n][0])){ sprintf (isf_bulletin_error,"illegal station: %s",sta[*n]); return 20; } sta[(*n)++][j] = '\0'; return 0; } /* Parses a line assuming it to be an netmag basis formatted comment. Returns 0 if the line is a properly formatted netmag basis line. Returns 20 and writes a diagnostic to isf_bulletin_error if not. */ int read_netmag_basis(char *line, char *param, char *value) { char substr[ISF_LINE_LEN]; int i,j; strcpy(param,""); strcpy(value,""); /* Chars 1-9: should be the string ' (#BASIS '. */ if (strncmp(line," (#BASIS ",9) != 0){ sprintf (isf_bulletin_error,"not a netmag basis line: %s",line); return 20; } if ( strlen(line) > ISF_LINE_LEN ){ sprintf (isf_bulletin_error,"line too long: %s",line); return 20; } /* Go through the rest of the line one character at a time, separating words on '='. */ i=9; j=0; while (line[i] == ' '){i++;} while (line[i]){ if (line[i]==' ' || line[i]==')' || line[i]=='\0' || line[i]=='\n'){ sprintf (isf_bulletin_error,"param without value: %s",line); return 20; } if (line[i]=='='){ param[j]='\0'; break; } param[j++]=line[i++]; } i++; j=0; while (line[i]){ if (line[i]==' ' || line[i]=='\0' || line[i]==')' || line[i]=='\n'){ if (j==0){ sprintf (isf_bulletin_error,"param without value: %s",line); return 20; } value[j]='\0'; break; } value[j++]=line[i++]; } /* Check for extra stuff */ if (partline(substr,line,++i,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Tests a line to discover if it is a effects block header line. Returns 0 if the line is a effects block header. Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_effects_head(char *line) { char substr[ISF_LINE_LEN]; char head[] = "Effects Loctyp Location Intensity Scale Author"; int headlen = 69; if (strncmp(line,head,headlen) != 0){ sprintf (isf_bulletin_error,"not an effects header: %s",line); return 20; } if (partline(substr,line,headlen,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line assuming that it is an effects block data line. Values are asigned to variables, the pointers to which have been sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is a properly formatted effects line, Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_effects(char *line, char *heard, char *felt, char *damage, char *casualties, char *uplift, char *subsidence, char *fault, char *tsunami, char *seiche, char *volcano, char *acoustic, char *gravity, char *t_wave, char *liquification, char *geyser, char *landslide, char *sandblow, char *cracks, char *lights, char *odours, char *loctype, float *lat, float *lon, float *dist, float *azim, char *country, char *postcode, char *net, char *sta, float *intensity1, char *modifier, float *intensity2, char *scale, char* author) { char substr[ISF_LINE_LEN]; /* Char 1: heard flag. */ if (line[0] == 'H' || line[0] == '_'){ *heard = line[0]; } else { sprintf (isf_bulletin_error,"bad heard flag: %s",line); return 20; } /* Char 2: felt flag. */ if (line[1] == 'F' || line[1] == '_'){ *felt = line[1]; } else { sprintf (isf_bulletin_error,"bad felt flag: %s",line); return 20; } /* Char 3: damage flag. */ if (line[2] == 'D' || line[2] == '_'){ *damage = line[2]; } else { sprintf (isf_bulletin_error,"bad damage flag: %s",line); return 20; } /* Char 4: casualties flag. */ if (line[3] == 'C' || line[3] == '_'){ *casualties = line[3]; } else { sprintf (isf_bulletin_error,"bad casualties flag: %s",line); return 20; } /* Char 5: uplift flag. */ if (line[4] == 'U' || line[4] == '_'){ *uplift = line[4]; } else { sprintf (isf_bulletin_error,"bad uplift flag: %s",line); return 20; } /* Char 6: subsidence flag. */ if (line[5] == 'S' || line[5] == '_'){ *subsidence = line[5]; } else { sprintf (isf_bulletin_error,"bad subsidence flag: %s",line); return 20; } /* Char 7 surface faulting flag. */ if (line[6] == 'F' || line[6] == '_'){ *fault = line[6]; } else { sprintf (isf_bulletin_error,"bad fault flag: %s",line); return 20; } /* Char 8 tsunami flag. */ if (line[7] == 'T' || line[7] == 'Q' || line[7] == '_'){ *tsunami = line[7]; } else { sprintf (isf_bulletin_error,"bad tsunami flag: %s",line); return 20; } /* Char 9 seiche flag. */ if (line[8] == 'S' || line[8] == 'Q' || line[8] == '_'){ *seiche = line[8]; } else { sprintf (isf_bulletin_error,"bad seiche flag: %s",line); return 20; } /* Char 10 volcano flag. */ if (line[9] == 'V' || line[9] == '_'){ *volcano = line[9]; } else { sprintf (isf_bulletin_error,"bad volcano flag: %s",line); return 20; } /* Char 11 acoustic flag. */ if (line[10] == 'A' || line[10] == '_'){ *acoustic = line[10]; } else { sprintf (isf_bulletin_error,"bad acoustic flag: %s",line); return 20; } /* Char 12 gravity flag. */ if (line[11] == 'G' || line[11] == '_'){ *gravity = line[11]; } else { sprintf (isf_bulletin_error,"bad gravity flag: %s",line); return 20; } /* Char 13 t_wave flag. */ if (line[12] == 'T' || line[12] == '_'){ *t_wave = line[12]; } else { sprintf (isf_bulletin_error,"bad t_wave flag: %s",line); return 20; } /* Char 14 liquification flag. */ if (line[13] == 'L' || line[13] == '_'){ *liquification = line[13]; } else { sprintf (isf_bulletin_error,"bad liquification flag: %s",line); return 20; } /* Char 15 geyser flag. */ if (line[14] == 'G' || line[14] == '_'){ *geyser = line[14]; } else { sprintf (isf_bulletin_error,"bad geyser flag: %s",line); return 20; } /* Char 16 landslide flag. */ if (line[15] == 'S' || line[15] == '_'){ *landslide = line[15]; } else { sprintf (isf_bulletin_error,"bad landslide flag: %s",line); return 20; } /* Char 17 sandblow flag. */ if (line[16] == 'B' || line[16] == '_'){ *sandblow = line[16]; } else { sprintf (isf_bulletin_error,"bad sandblow flag: %s",line); return 20; } /* Char 18 cracks flag. */ if (line[17] == 'C' || line[17] == '_'){ *cracks = line[17]; } else { sprintf (isf_bulletin_error,"bad cracks flag: %s",line); return 20; } /* Char 19 lights flag */ if (line[18] == 'V' || line[18] == '_'){ *lights = line[18]; } else { sprintf (isf_bulletin_error,"bad lights flag: %s",line); return 20; } /* Char 20 odours flag. */ if (line[19] == 'O' || line[19] == '_'){ *odours = line[19]; } else { sprintf (isf_bulletin_error,"bad odours flag: %s",line); return 20; } /* Char 21: must be a space. */ if (line[20] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 21: %s",line); return 20; } /* Chars 22-27: loctype. Checked below to see if sensible. */ if (!partline(loctype,line,21,6)){ sprintf (isf_bulletin_error,"missing loctype: %s",line); return 20; } /* Char 28: must be a space. */ if (line[27] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 28: %s",line); return 20; } /* Chars 29-46: depend on loctype. */ if (strcmp(loctype,"Summar")==0){ /* Chars 29-46 should be blank. */ if (partline(substr,line,28,18)){ sprintf (isf_bulletin_error,"bad summar format: %s",line); return 20; } } else if (strcmp(loctype,"LatLon")==0){ /* Chars 29-36: lattitude - must be float. */ if (!partline(substr,line,28,8)){ sprintf (isf_bulletin_error,"missing lattitude: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad lattitude: %s",line); return 20; } *lat = (float)atof(substr); /* Char 37: space */ if (line[36] != ' '){ sprintf (isf_bulletin_error,"bad format, char 38: %s",line); return 20; } /* Chars 38-46: longitude - must be float. */ if (!partline(substr,line,37,9)){ sprintf (isf_bulletin_error,"missing longitude: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad longitude: %s",line); return 20; } *lon = (float)atof(substr); } else if (strcmp(loctype,"DistAz")==0){ /* Chars 29-36: distance - must be float */ if (!partline(substr,line,28,8)){ sprintf (isf_bulletin_error,"missing distance: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad distance: %s",line); return 20; } *dist = (float)atof(substr); /* Char 37: space */ if (line[36] != ' '){ sprintf (isf_bulletin_error,"bad format, char 38: %s",line); return 20; } /* Chars 38-42: azimuth. */ if (!partline(substr,line,37,5)){ sprintf (isf_bulletin_error,"missing azimuth: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad azimuth: %s",line); return 20; } *azim = (float)atof(substr); /* Chars 43-46 should be blank. */ if (partline(substr,line,42,4)){ sprintf (isf_bulletin_error,"bad DistAz format: %s",line); return 20; } } else if (strcmp(loctype,"CoPost")==0){ /* Chars 29-31: country code. */ if (!partline(country,line,28,3)){ sprintf (isf_bulletin_error,"missing country: %s",line); return 20; } /* Char 32: space */ if (line[31] != ' '){ sprintf (isf_bulletin_error,"bad format, char 32: %s",line); return 20; } /* Chars 33-42: post code. */ if (!partline(postcode,line,32,10)){ sprintf (isf_bulletin_error,"missing post code: %s",line); return 20; } /* Chars 43-46 should be blank. */ if (partline(substr,line,42,4)){ sprintf (isf_bulletin_error,"bad CoPost format: %s",line); return 20; } } else if (strcmp(loctype,"StaNet")==0){ /* Chars 29-37: network code. */ if (!partline(net,line,28,9)){ sprintf (isf_bulletin_error,"missing network: %s",line); return 20; } /* Char 38: space. */ if (line[37] != ' '){ sprintf (isf_bulletin_error,"bad format, char 38: %s",line); return 20; } /* Chars 39-43: station code. */ if (!partline(sta,line,38,5)){ sprintf (isf_bulletin_error,"missing station code: %s",line); return 20; } /* Chars 44-46 should be blank */ if (partline(substr,line,43,3)){ sprintf (isf_bulletin_error,"bad StaNet format: %s",line); return 20; } } else { sprintf (isf_bulletin_error,"unknown loctype: %s",line); return 20; } /* Char 47: space. */ if (line[46] != ' '){ sprintf (isf_bulletin_error,"bad format, char 47: %s",line); return 20; } /* Chars 48-51: first intensity. */ /* If no first intensity then don't allow second one or scale. */ if (partline(substr,line,47,4)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad intensity: %s",line); return 20; } *intensity1 = (float)atof(substr); /* Char 52: intensity modifier. */ if (line[51] == ' ' || line[51] == '-' || line[51] == '+'){ *modifier = line[51]; } else { sprintf (isf_bulletin_error,"bad intensity modifier: %s",line); return 20; } /* Chars 53-56: second intensity, only allowed if modifier is '-'. */ if (*modifier == '-'){ if (!partline(substr,line,52,4)){ sprintf (isf_bulletin_error,"missing intensity 2: %s",line); return 20; } if (check_float(substr)){ sprintf (isf_bulletin_error,"bad intensity 2: %s",line); return 20; } *intensity2 = (float)atof(substr); } else { if (partline(substr,line,52,4)){ sprintf (isf_bulletin_error,"bad intensity format: %s",line); return 20; } *intensity2 = ISF_NULL; } /* Char 57: space. */ if (line[56] != ' '){ sprintf (isf_bulletin_error,"bad format, char 57: %s",line); return 20; } /* Chars 58-62: intensity scale. */ if (!partline(scale,line,57,5)){ sprintf (isf_bulletin_error,"missing intensity scale: %s",line); return 20; } if (check_whole(scale)){ sprintf (isf_bulletin_error,"bad intensity scale: %s",line); return 20; } } else if (partline(substr,line,47,15)){ sprintf (isf_bulletin_error,"bad intensity format: %s",line); return 20; } else { *intensity1 = ISF_NULL; *modifier = ' '; *intensity2 = ISF_NULL; strcpy(scale,""); } /* Char 63: space. */ if (line[62] != ' '){ sprintf (isf_bulletin_error,"bad format, char 63: %s",line); return 20; } /* Chars 64-72: author, any characters allowed but must be there. */ if (!partline(author,line,63,9)){ sprintf (isf_bulletin_error,"missing author: %s",line); return 20; } if (check_whole(author)){ sprintf (isf_bulletin_error,"bad author: %s",line); return 20; } /* Check for extra stuff. */ if (partline(substr,line,72,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Tests a line to discover if it is a phase block header line. Returns 0 if the line is a phase block header. Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_phase_head(char *line) { char substr[ISF_LINE_LEN]; char head[] = "Sta Dist EvAz Phase Time TRes Azim AzRes Slow SRes Def SNR Amp Per Qual Magnitude ArrID"; int headlen = 122; if (strncmp(line,head,headlen) != 0){ sprintf (isf_bulletin_error,"not a phase header: %s",line); return 20; } if (partline(substr,line,headlen,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line assuming that it is a phase block data line. Values are asigned to variables, the pointers to which have been sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is a properly formatted phase line, Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_phase(char *line, char *sta, float *dist, float *esaz, char *phase, int *hh, int *mi, int *ss, int *msec, float *timeres, float *azim, float *azimres, float *slow, float *slowres, char *timedef, char *azimdef, char *slowdef, float *snr, float *amp, float *per, char *picktype, char *sp_fm, char *detchar, char *magtype, char *magind, float *mag, char *arrid) { char substr[ISF_LINE_LEN]; /* Chars 1-5: station code. */ if (!partline(sta,line,0,5)){ sprintf (isf_bulletin_error,"missing sta: %s",line); return 20; } if (check_whole(sta)){ sprintf (isf_bulletin_error,"bad sta: %s",line); return 20; } /* Char 6: must be a space. */ if (line[5] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 6: %s",line); return 20; } /* Chars 7-12: distance, float if there. */ if (partline(substr,line,6,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad distance: %s",line); return 20; } *dist = (float)atof(substr); } else { *dist = ISF_NULL; } /* Char 13: must be a space. */ if (line[12] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 13: %s",line); return 20; } /* Chars 14-18: event to sta azimuth, float if there. */ if (partline(substr,line,13,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad esaz: %s",line); return 20; } *esaz = (float)atof(substr); } else { *esaz = ISF_NULL; } /* Char 19: must be a space. */ if (line[18] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 19: %s",line); return 20; } /* Chars 20-27: phase code - can be null. */ if (partline(phase,line,19,8)){ if (check_whole(phase)){ sprintf (isf_bulletin_error,"bad phase: %s",line); return 20; } } else{ strcpy(phase,""); } /* Char 28: must be a space. */ if (line[27] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 28: %s",line); return 20; } /* Chars 29-40: time - can be null. */ if (partline(substr,line,28,12)){ /* Chars 29,30: hour. */ if (!partline(substr,line,28,2)){ sprintf (isf_bulletin_error,"missing hour: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad hour: %s",line); return 20; } *hh = atoi(substr); /* Char 31: ':' character. */ if (line[30] != ':'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 32,33: minute */ if (!partline(substr,line,31,2)){ sprintf (isf_bulletin_error,"missing minute: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad minute: %s",line); return 20; } *mi = atoi(substr); /* Char 34: ':' character */ if (line[33] != ':'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 35,36: integral second. */ if (!partline(substr,line,34,2)){ sprintf (isf_bulletin_error,"missing second: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad second: %s",line); return 20; } *ss = atoi(substr); /* Char 37-40: msec or spaces. */ /* Allow decimal place without any numbers after it. */ if (partline(substr,line,37,3)){ /* Char 37: '.' character */ if (line[36] != '.'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 38-40: msec. */ if (!isdigit(line[37])){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *msec = (line[37]-'0')*100; if (isdigit(line[38])){ *msec += (line[38]-'0')*10; } else if (line[38] != ' ' || line[39] != ' ') { sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } if (isdigit(line[39])){ *msec += (line[39]-'0'); } else if (line[39] != ' ') { sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } } else { /* Char 37: '.' character or space. */ if (line[36] != '.' && line[36] != ' '){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *msec = ISF_NULL; } } else { *hh = ISF_NULL; *mi = ISF_NULL; *ss = ISF_NULL; *msec = ISF_NULL; } /* Char 41: must be a space */ if (line[40] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 41: %s",line); return 20; } /* Chars 42-46: time residual, float if there */ if (partline(substr,line,41,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad timeres: %s",line); return 20; } *timeres = (float)atof(substr); } else { *timeres = ISF_NULL; } /* Char 47: must be a space */ if (line[46] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 47: %s",line); return 20; } /* Chars 48-52: observed azimuth, float if there */ if (partline(substr,line,47,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad azim: %s",line); return 20; } *azim = (float)atof(substr); } else { *azim = ISF_NULL; } /* Char 53: must be a space */ if (line[52] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 53: %s",line); return 20; } /* Chars 54-58: azimuth residual, float if there */ if (partline(substr,line,53,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad azimres: %s",line); return 20; } *azimres = (float)atof(substr); } else { *azimres = ISF_NULL; } /* Char 59: must be a space */ if (line[58] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 59: %s",line); return 20; } /* Chars 60-65: slowness, float if there */ if (partline(substr,line,59,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad slow: %s",line); return 20; } *slow = (float)atof(substr); } else { *slow = ISF_NULL; } /* Char 66: must be a space */ if (line[65] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 66: %s",line); return 20; } /* Chars 67-72: slowness residual, float if there */ if (partline(substr,line,66,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad slowres: %s",line); return 20; } *slowres = (float)atof(substr); } else { *slowres = ISF_NULL; } /* Char 73: must be a space */ if (line[72] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 73: %s",line); return 20; } /* Char 74: time defining flag. */ if (line[73] == 'T' || line[73] == '_'){ *timedef = line[73]; } else if (line[73] == ' '){ *timedef = '_'; } else { sprintf (isf_bulletin_error,"bad timedef flag: %s",line); return 20; } /* Char 75: azimuth defining flag */ if (line[74] == 'A' || line[74] == '_'){ *azimdef = line[74]; } else if (line[74] == ' '){ *azimdef = '_'; } else { sprintf (isf_bulletin_error,"bad azimdef flag: %s",line); return 20; } /* Char 76: slowness defining flag */ if (line[75] == 'S' || line[75] == '_'){ *slowdef = line[75]; } else if (line[75] == ' '){ *slowdef = '_'; } else { sprintf (isf_bulletin_error,"bad slowdef flag: %s",line); return 20; } /* Char 77: must be a space */ if (line[76] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 77: %s",line); return 20; } /* Chars 78-82: signal-to noise, float if there */ if (partline(substr,line,77,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad snr: %s",line); return 20; } *snr = (float)atof(substr); } else { *snr = ISF_NULL; } /* Char 83: must be a space */ if (line[82] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 83: %s",line); return 20; } /* Chars 84-92: amplitude, float if there */ if (partline(substr,line,83,9)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad amp: %s",line); return 20; } *amp = (float)atof(substr); } else { *amp = ISF_NULL; } /* Char 93: must be a space */ if (line[92] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 93: %s",line); return 20; } /* Chars 94-98: period, float if there */ if (partline(substr,line,93,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad per: %s",line); return 20; } *per = (float)atof(substr); } else { *per = ISF_NULL; } /* Char 99: must be a space */ if (line[98] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 99: %s",line); return 20; } /* Char 100: picktype */ if (line[99]=='a' || line[99]=='m' || line[99]=='_'){ *picktype = line[99]; } else if (line[99] == ' '){ *picktype = '_'; } else { sprintf (isf_bulletin_error,"bad picktype: %s",line); return 20; } /* Char 101: sp_fm */ if (line[100]=='c' || line[100]=='d' || line[100]=='_' ){ *sp_fm = line[100]; } else if (line[100] == ' '){ *sp_fm = '_'; } else { sprintf (isf_bulletin_error,"bad sp_fm: %s",line); return 20; } /* Char 102: detchar */ if (line[101]=='i' || line[101]=='e' || line[101]=='q' || line[101]=='_'){ *detchar = line[101]; } else if (line[101] == ' '){ *detchar = '_'; } else { sprintf (isf_bulletin_error,"bad detchar: %s",line); return 20; } /* Char 103: must be a space */ if (line[102] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 103: %s",line); return 20; } /* Chars 104-108: magnitude type. */ if (partline(magtype,line,103,5)){ if (check_whole(magtype)){ sprintf (isf_bulletin_error,"bad magtype: %s",line); return 20; } } else{ strcpy(magtype,""); } /* Char 109: less than or greater than indicator or space only. */ if (line[108] == ' ' || line[108] == '<' || line[108] == '>'){ *magind = line[108]; } else { sprintf (isf_bulletin_error,"bad magind: %s",line); return 20; } /* Chars 110-113: magnitude, float if there */ if (partline(substr,line,109,4)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mag: %s",line); return 20; } *mag = (float)atof(substr); } else { *mag = ISF_NULL; } /* Char 114: must be a space */ if (line[113] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 114: %s",line); return 20; } /* Chars 115-122: arrival ID, any characters allowed but must be there. */ if (!partline(arrid,line,114,8)){ sprintf (isf_bulletin_error,"missing arrid: %s",line); return 20; } if (check_whole(arrid)){ sprintf (isf_bulletin_error,"bad arrid: %s",line); return 20; } /* Check for extra stuff */ if (partline(substr,line,122,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line assuming that it is a phase origid line. Returns 0 if the line is a phase block origid line. Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_phase_origid(char *line, char *origid) { char substr[ISF_LINE_LEN]; /* Chars 1-10: comment start string and space. */ if (strncmp(line," (#OrigID ",10)){ sprintf (isf_bulletin_error,"not a phase origin line: $s",line); return 20; } /* Chars 11-18: origin ID */ if (!partline(origid,line,10,8)){ sprintf (isf_bulletin_error,"missing origid: %s",line); return 20; } if (check_whole(origid)){ sprintf (isf_bulletin_error,"bad origid: %s",line); return 20; } /* Check for extra stuff - not including close bracket. */ if (partline(substr,line,18,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Tests a line to discover if it is a phase info block header line. Returns 0 if the line is a phase info block header. Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_phase_info_head(char *line) { char substr[ISF_LINE_LEN]; char head[] = "Net Chan F Low_F HighF AuthPhas Date eTime wTime eAzim wAzim eSlow wSlow eAmp ePer eMag Author ArrID"; int headlen = 123; if (strncmp(line,head,headlen) != 0){ sprintf (isf_bulletin_error,"not a phase info header: %s",line); return 20; } if (partline(substr,line,headlen,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line assuming that it is a phase info block data line. Values are asigned to variables sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is a properly formatted phase info line, Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_phase_info(char *line, char *net, char *chan, char *filter, float *filter_min, float *filter_max, char *phase, int *yyyy, int *mm, int *dd, float *time_unc, float *time_weight, float *azim_unc, float *azim_weight, float *slow_unc, float *slow_weight, float *amp_unc, float *per_unc, float *mag_unc, char *author, char *arrid) { char substr[ISF_LINE_LEN]; /* Chars 1-9: network code. */ if (partline(net,line,0,9)){ if (check_whole(net)){ sprintf (isf_bulletin_error,"bad net: %s",line); return 20; } } else { strcpy(net,""); } /* Char 10: must be a space. */ if (line[9] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 10: %s",line); return 20; } /* Chars 11-13: channel. */ if (partline(chan,line,10,3)){ if (check_whole(chan)){ sprintf (isf_bulletin_error,"bad chan: %s",line); return 20; } } else { strcpy(chan,""); } /* Char 14: must be a space. */ if (line[13] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 14: %s",line); return 20; } /* Char 15: filter. */ if (line[14] == '0' || line[14] == 'C' || line[14] == ' '){ *filter = line[14]; } else { sprintf (isf_bulletin_error,"bad filter: %s",line); return 20; } /* Char 16: must be a space. */ if (line[15] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 16: %s",line); return 20; } /* Chars 17-21: minimum filter frequency. */ if (partline(substr,line,16,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad filter_min: %s",line); return 20; } *filter_min = (float)atof(substr); } else { *filter_min = ISF_NULL; } /* Char 22: must be a space. */ if (line[21] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 22: %s",line); return 20; } /* Chars 23-27: maximum filter frequency. */ if (partline(substr,line,22,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad filter_max: %s",line); return 20; } *filter_max = (float)atof(substr); } else { *filter_max = ISF_NULL; } /* Char 28: must be a space. */ if (line[27] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 28: %s",line); return 20; } /* Chars 29-36: author's phase. */ if (partline(phase,line,28,8)){ if (check_whole(phase)){ sprintf (isf_bulletin_error,"bad phase: %s",line); return 20; } } else { strcpy(phase,""); } /* Char 37: must be a space. */ if (line[36] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 37: %s",line); return 20; } /* Chars 38-47: arrival date. */ if (partline(substr,line,37,10)){ /* Chars 38-41: year. */ if (!partline(substr,line,37,4)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *yyyy = atoi(substr); /* Char 42: '/' character */ if (line[41] != '/'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 43,44: month. */ if (!partline(substr,line,42,2)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *mm = atoi(substr); /* Char 45: '/' character. */ if (line[44] != '/'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 46,47: day. */ if (!partline(substr,line,45,2)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *dd = atoi(substr); } else { *yyyy = ISF_NULL; *mm = ISF_NULL; *dd = ISF_NULL; } /* Char 48: must be a space. */ if (line[47] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 48: %s",line); return 20; } /* Chars 49-54: uncertainty in arrival time. */ if (partline(substr,line,48,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad time_unc: %s",line); return 20; } *time_unc = (float)atof(substr); } else { *time_unc = ISF_NULL; } /* Char 55: must be a space. */ if (line[54] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 55: %s",line); return 20; } /* Chars 56-60: time weight. */ if (partline(substr,line,55,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad time_weight: %s",line); return 20; } *time_weight = (float)atof(substr); } else { *time_weight = ISF_NULL; } /* Char 61: must be a space. */ if (line[60] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 61: %s",line); return 20; } /* Chars 62-66: azimuth uncertainty. */ if (partline(substr,line,61,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad azim_unc: %s",line); return 20; } *azim_unc = (float)atof(substr); } else { *azim_unc = ISF_NULL; } /* Char 67: must be a space. */ if (line[66] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 67: %s",line); return 20; } /* Chars 68-72: azimuth weight. */ if (partline(substr,line,67,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad azim_weight: %s",line); return 20; } *azim_weight = (float)atof(substr); } else { *azim_weight = ISF_NULL; } /* Char 73: must be a space. */ if (line[72] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 73: %s",line); return 20; } /* Chars 74-79: slowness uncertainty. */ if (partline(substr,line,73,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad slow_unc: %s",line); return 20; } *slow_unc = (float)atof(substr); } else { *slow_unc = ISF_NULL; } /* Char 80: must be a space. */ if (line[79] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 80: %s",line); return 20; } /* Chars 81-85: slowness weight. */ if (partline(substr,line,80,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad slow_weight: %s",line); return 20; } *slow_weight = (float)atof(substr); } else { *slow_weight = ISF_NULL; } /* Char 86: must be a space. */ if (line[85] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 86: %s",line); return 20; } /* Chars 87-95: amplitude unceratinty. */ if (partline(substr,line,86,9)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad amp_unc: %s",line); return 20; } *amp_unc = (float)atof(substr); } else { *amp_unc = ISF_NULL; } /* Char 96: must be a space. */ if (line[95] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 96: %s",line); return 20; } /* Chars 97-101: period uncertainty. */ if (partline(substr,line,96,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad per_unc: %s",line); return 20; } *per_unc = (float)atof(substr); } else { *per_unc = ISF_NULL; } /* Char 102: must be a space. */ if (line[101] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 102: %s",line); return 20; } /* Chars 103-105: uncertainty in station magnitude. */ if (partline(substr,line,102,3)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mag_unc: %s",line); return 20; } *mag_unc = (float)atof(substr); } else { *mag_unc = ISF_NULL; } /* Char 106: must be a space. */ if (line[105] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 106: %s",line); return 20; } /* Chars 107-115: author. */ if (partline(author,line,106,9)){ if (check_whole(author)){ sprintf (isf_bulletin_error,"bad author: %s",line); return 20; } } else { strcpy(author,""); } /* Char 116: must be a space. */ if (line[115] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 116: %s",line); return 20; } /* Chars 117-124: arrival ID, any characters allowed but must be there */ if (!partline(arrid,line,116,8)){ sprintf (isf_bulletin_error,"missing arrid: %s",line); return 20; } if (check_whole(arrid)){ sprintf (isf_bulletin_error,"bad arrid: %s",line); return 20; } /* Check for extra stuff after char 124 */ if (partline(substr,line,124,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line assuming it to be an additional phase measurement line. Accepts any number of parameter=value pairs as long as the line is short enough. Returns 0 if the line is a properly formatted phase measurement line. Returns 20 and writes a diagnostic to isf_bulletin_error if not. */ int read_phase_measure(char *line, char **param, char **value, char **error, int *numparam) { int i,j,k; char *pair[ISF_NUM_PARAM]; char substr[ISF_LINE_LEN]; pair[0] = (char *)malloc(ISF_COMM_LEN); /* Chars 1-10: should be the comment format string */ if (strncmp(line," (#MEASURE ",11) != 0){ sprintf (isf_bulletin_error,"not a phase measure line: %s",line); return 20; } if ( strlen(line) > ISF_COMM_LEN+11 ){ sprintf (isf_bulletin_error,"line too long: %s",line); return 20; } /* Go through the rest of the line one character at a time, separating words on ' ' to get param=value pairs*/ i=11; j=0; k=0; while (line[i] == ' '){i++;} while (line[i]){ if (line[i]==')' || line[i]=='\0' || line[i]=='\n'){ pair[k][j]='\0'; k++; break; } if (line[i]==' '){ pair[k][j]='\0'; i++; j=0; pair[++k] = (char *)malloc(ISF_COMM_LEN); } else { pair[k][j++]=line[i++]; } } *numparam=k; /* Check for extra stuff */ if (partline(substr,line,++i,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } /* Go through the seperate words splitting them into param and value */ for (k=0; k< *numparam; k++){ param[k] = (char *)malloc(ISF_COMM_LEN); value[k] = (char *)malloc(ISF_COMM_LEN); i=0; j=0; while (pair[k][i]){ if (pair[k][i]=='\0'){ sprintf (isf_bulletin_error,"param without value: %s",line); return 20; } if (pair[k][i]=='='){ param[k][j]='\0'; break; } param[k][j++]=pair[k][i++]; } i++; j=0; while (pair[k][i]){ if (pair[k][i]=='\0'){ value[k][j]='\0'; break; } value[k][j++]=pair[k][i++]; } } /* Go through the values in case any of them include an error value. */ for (k=0; k< *numparam; k++){ error[k] = (char *)malloc(ISF_COMM_LEN); i=0; while (value[k][i]){ if (value[k][i]=='\0'){ break; } if (value[k][i]=='+'){ error[k] = &value[k][i+1]; value[k][i]='\0'; break; } i++; } } return 0; } /* Parses a line asuming it to be a minimum phase range line. Values are asigned to variables sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is a properly phase_min data line. Returns 20 and writes a diagnostic to isf_bulletin_error on error. */ int read_phase_min(char *line, float *timeoffset, float *azoffset, float *slowoffset, float *ampoffset, float *peroffset, float *magoffset) { char substr[ISF_LINE_LEN]; /* Chars 1-6: comment format string. */ if (strncmp(line," (#MIN",6) != 0){ sprintf (isf_bulletin_error,"not a phase min line: %s",line); return 20; } /* Chars 7-47: spaces. */ if (partline(substr,line,6,41)){ sprintf (isf_bulletin_error,"not a phase min line: %s",line); return 20; } /* Chars 48-54: time offset. */ if (partline(substr,line,47,7)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad timeoffset: %s",line); return 20; } *timeoffset = (float)atof(substr); } else { *timeoffset = ISF_NULL; } /* Chars 55-60: spaces. */ if (partline(substr,line,54,5)){ sprintf (isf_bulletin_error,"bad format, chars 55-60: %s",line); return 20; } /* Chars 61-66: azimuth offset. */ if (partline(substr,line,60,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad azoffset: %s",line); return 20; } *azoffset = (float)atof(substr); } else { *azoffset = ISF_NULL; } /* Chars 67-72: spaces. */ if (partline(substr,line,66,6)){ sprintf (isf_bulletin_error,"bad format, chars 67-72: %s",line); return 20; } /* Chars 73-79: slowness offset. */ if (partline(substr,line,72,7)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad slowoffset: %s",line); return 20; } *slowoffset = (float)atof(substr); } else { *slowoffset = ISF_NULL; } /* Chars 80-85: spaces. */ if (partline(substr,line,79,6)){ sprintf (isf_bulletin_error,"bad format, chars 80-85: %s",line); return 20; } /* Chars 86-95: amplitude offset. */ if (partline(substr,line,85,10)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad ampoffset: %s",line); return 20; } *ampoffset = (float)atof(substr); } else { *ampoffset = ISF_NULL; } /* Chars 96-101: period offset. */ if (partline(substr,line,95,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad peroffset: %s",line); return 20; } *peroffset = (float)atof(substr); } else { *peroffset = ISF_NULL; } /* Chars 102-105: magnitude offset. */ if (partline(substr,line,101,4)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad magoffset: %s",line); return 20; } *magoffset = (float)atof(substr); } else { *magoffset = ISF_NULL; } /* Check for extra stuff after char 105 */ if (partline(substr,line,105,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line asuming it to be a maximum phase range line. Values are asigned to variables sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is a properly phase_min data line. Returns 20 and writes a diagnostic to isf_bulletin_error on error. */ int read_phase_max(char *line, float *timeoffset, float *azoffset, float *slowoffset, float *ampoffset, float *peroffset, float *magoffset) { char substr[ISF_LINE_LEN]; /* Chars 1-6: comment format string. */ if (strncmp(line," (#MAX",6) != 0){ sprintf (isf_bulletin_error,"not a phase max line: %s",line); return 20; } /* Chars 7-47: spaces. */ if (partline(substr,line,6,41)){ sprintf (isf_bulletin_error,"not a phase max line: %s",line); return 20; } /* Chars 48-54: time offset. */ if (partline(substr,line,47,7)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad timeoffset: %s",line); return 20; } *timeoffset = (float)atof(substr); } else { *timeoffset = ISF_NULL; } /* Chars 55-60: spaces. */ if (partline(substr,line,54,5)){ sprintf (isf_bulletin_error,"bad format, chars 55-60: %s",line); return 20; } /* Chars 61-66: azimuth offset. */ if (partline(substr,line,60,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad azoffset: %s",line); return 20; } *azoffset = (float)atof(substr); } else { *azoffset = ISF_NULL; } /* Chars 67-72: spaces. */ if (partline(substr,line,66,6)){ sprintf (isf_bulletin_error,"bad format, chars 67-72: %s",line); return 20; } /* Chars 73-79: slowness offset. */ if (partline(substr,line,72,7)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad slowoffset: %s",line); return 20; } *slowoffset = (float)atof(substr); } else { *slowoffset = ISF_NULL; } /* Chars 80-85: spaces. */ if (partline(substr,line,79,6)){ sprintf (isf_bulletin_error,"bad format, chars 80-85: %s",line); return 20; } /* Chars 86-95: amplitude offset. */ if (partline(substr,line,85,10)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad ampoffset: %s",line); return 20; } *ampoffset = (float)atof(substr); } else { *ampoffset = ISF_NULL; } /* Chars 96-101: period offset. */ if (partline(substr,line,95,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad peroffset: %s",line); return 20; } *peroffset = (float)atof(substr); } else { *peroffset = ISF_NULL; } /* Chars 102-105: magnitude offset. */ if (partline(substr,line,101,4)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad magoffset: %s",line); return 20; } *magoffset = (float)atof(substr); } else { *magoffset = ISF_NULL; } /* Check for extra stuff after char 105 */ if (partline(substr,line,105,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line asuming it to be a phase correction line. Values are asigned to variables sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is a properly phase correction line. Returns 20 and writes a diagnostic to isf_bulletin_error on error. */ int read_phase_correc(char *line, float *timecorr, float *azcorr, float *slowcorr, float *ampcorr, float *percorr, float *magcorr) { char substr[ISF_LINE_LEN]; /* Chars 1-8: comment format string. */ if (strncmp(line," (#COREC",8) != 0){ sprintf (isf_bulletin_error,"not a phase correction line: %s",line); return 20; } /* Chars 9-47: spaces. */ if (partline(substr,line,8,39)){ sprintf (isf_bulletin_error,"not a phase correction line: %s",line); return 20; } /* Chars 48-54: time correction. */ if (partline(substr,line,47,7)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad timecorr: %s",line); return 20; } *timecorr = (float)atof(substr); } else { *timecorr = ISF_NULL; } /* Chars 55-60: spaces. */ if (partline(substr,line,54,5)){ sprintf (isf_bulletin_error,"bad format, chars 55-60: %s",line); return 20; } /* Chars 61-66: azimuth correction. */ if (partline(substr,line,60,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad azcorr: %s",line); return 20; } *azcorr = (float)atof(substr); } else { *azcorr = ISF_NULL; } /* Chars 67-72: spaces. */ if (partline(substr,line,66,6)){ sprintf (isf_bulletin_error,"bad format, chars 67-72: %s",line); return 20; } /* Chars 73-79: slowness correction. */ if (partline(substr,line,72,7)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad slowcorr: %s",line); return 20; } *slowcorr = (float)atof(substr); } else { *slowcorr = ISF_NULL; } /* Chars 80-85: spaces. */ if (partline(substr,line,79,6)){ sprintf (isf_bulletin_error,"bad format, chars 80-85: %s",line); return 20; } /* Chars 86-95: amplitude correction. */ if (partline(substr,line,85,10)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad ampcorr: %s",line); return 20; } *ampcorr = (float)atof(substr); } else { *ampcorr = ISF_NULL; } /* Chars 96-101: period correction. */ if (partline(substr,line,95,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad percorr: %s",line); return 20; } *percorr = (float)atof(substr); } else { *percorr = ISF_NULL; } /* Chars 102-106: magnitude correction. */ if (partline(substr,line,101,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad magcorr: %s",line); return 20; } *magcorr = (float)atof(substr); } else { *magcorr = ISF_NULL; } /* Check for extra stuff after char 106 */ if (partline(substr,line,106,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line asuming it to be an original phase data line. Values are asigned to variables sent as arguments. If an optional parameter is not given then the corresponding variable will have ISF_NULL assigned to it. Returns 0 if the line is a properly formatted original phase data line. Returns 20 and writes a diagnostic to isf_bulletin_error on error. */ int read_phase_original(char *line, char *chan, char *sta, int *yyyy, int *mm, int *dd, int *hh, int *mi, int *ss, int *msec, float *azim, float *slow, float *amp, float *per, float *mag) { char substr[ISF_LINE_LEN]; /* Chars 1-10: comment format string. */ if (strncmp(line," (#ORIG ",10) != 0){ sprintf (isf_bulletin_error,"not a phase original line: %s",line); return 20; } /* Chars 11-13: original channel. */ if (partline(chan,line,10,3)){ if (check_whole(chan)){ sprintf (isf_bulletin_error,"bad chan: %s",line); return 20; } } else { strcpy(chan,""); } /* Char 14: must be a space. */ if (line[13] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 14: %s",line); return 20; } /* Chars 15-22: original station code. */ if (partline(sta,line,14,8)){ if (check_whole(sta)){ sprintf (isf_bulletin_error,"bad sta: %s",line); return 20; } } else { strcpy(sta,""); } /* Char 23-37: must be a space. */ if (partline(substr,line,22,15)){ sprintf (isf_bulletin_error,"bad format, chars 23-37: %s",line); return 20; } /* Chars 38-60: arrival date and time. */ if (partline(substr,line,37,10)){ /* Chars 38-41: year */ if (!partline(substr,line,37,4)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *yyyy = atoi(substr); /* Char 42: '/' character */ if (line[41] != '/'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 43,44: month */ if (!partline(substr,line,42,2)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *mm = atoi(substr); /* Char 45: '/' character */ if (line[44] != '/'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 46,47: day */ if (!partline(substr,line,45,2)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *dd = atoi(substr); /* Char 48: space. */ if (line[47] != ' '){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 49,50: hour */ if (!partline(substr,line,48,2)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *hh = atoi(substr); /* Char 51: ':' character */ if (line[50] != ':'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 52,53: minute */ if (!partline(substr,line,51,2)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *mi = atoi(substr); /* Char 54: ':' character */ if (line[53] != ':'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 55,56: second */ if (!partline(substr,line,54,2)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } if (check_int(substr)){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *ss = atoi(substr); /* Char 57-60: msec or spaces. */ /* Allow decimal point with no numbers after it. */ if (partline(substr,line,57,3)){ /* Char 57: '.' character */ if (line[56] != '.'){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } /* Chars 58-60: msec */ if (!isdigit(line[57])){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *msec = (line[57]-'0')*100; if (isdigit(line[58])){ *msec += (line[58]-'0')*10; } else if (line[58] != ' ' || line[59] != ' ') { sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } if (isdigit(line[59])){ *msec += (line[59]-'0'); } else if (line[59] != ' ') { sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } } else { /* Char 57: '.' character or space. */ if (line[56] != '.' && line[56] != ' '){ sprintf (isf_bulletin_error,"bad date: %s",line); return 20; } *msec = ISF_NULL; } } else { *yyyy = ISF_NULL; *mm = ISF_NULL; *dd = ISF_NULL; *hh = ISF_NULL; *mi = ISF_NULL; *ss = ISF_NULL; *msec = ISF_NULL; } /* Char 61: must be a space. */ if (line[60] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 61: %s",line); return 20; } /* Chars 62-66: original azimuth. */ if (partline(substr,line,61,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad azim: %s",line); return 20; } *azim = (float)atof(substr); } else { *azim = ISF_NULL; } /* Char 67-73: must be a space. */ if (partline(substr,line,66,7)){ sprintf (isf_bulletin_error,"bad format, char 67-73: %s",line); return 20; } /* Chars 74-79: original slowness. */ if (partline(substr,line,73,6)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad slow: %s",line); return 20; } *slow = (float)atof(substr); } else { *slow = ISF_NULL; } /* Char 80-86: must be a space. */ if (partline(substr,line,79,7)){ sprintf (isf_bulletin_error,"bad format, char 80-86: %s",line); return 20; } /* Chars 87-95: original amplitude. */ if (partline(substr,line,86,9)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad amp: %s",line); return 20; } *amp = (float)atof(substr); } else { *amp = ISF_NULL; } /* Char 96: must be a space. */ if (line[95] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 96: %s",line); return 20; } /* Chars 97-101: original period. */ if (partline(substr,line,96,5)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad per: %s",line); return 20; } *per = (float)atof(substr); } else { *per = ISF_NULL; } /* Char 102: must be a space. */ if (line[101] != ' ' ){ sprintf (isf_bulletin_error,"bad format, char 102: %s",line); return 20; } /* Chars 103-105: original station magnitude. */ if (partline(substr,line,102,3)){ if (check_float(substr)){ sprintf (isf_bulletin_error,"bad mag: %s",line); return 20; } *mag = (float)atof(substr); } else { *mag = ISF_NULL; } /* Check for extra stuff after char 105 */ if (partline(substr,line,105,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; } /* Parses a line asuming it to be a comment line. Returns 0 if the line is a properly formatted comment line. Returns 20 and writes a diagnostic to isf_bulletin_error on error. */ int read_comment(char *line, char *comment) { if (strncmp(line," (",2) != 0){ sprintf (isf_bulletin_error,"not a comment: %s",line); return 20; } /* partline will clean off final bracket. */ if (partline(comment,line,2,0) > ISF_LINE_LEN){ sprintf (isf_bulletin_error,"comment too long: %s",line); return 20; } return 0; } /* Tests a line to discover if it is a stop line. Returns 0 if the line is a stop line. Returns 20 and writes a diagnostic to isf_bulletin_error otherwise. */ int read_stop(char *line) { char substr[ISF_LINE_LEN]; if (strncmp(line,"STOP",4) != 0){ sprintf (isf_bulletin_error,"not a stop line: %s",line); return 20; } if (partline(substr,line,4,0)){ sprintf (isf_bulletin_error,"extra characters at end: %s",line); return 20; } return 0; }