/* This code handles the calculation of the magnitude */ /* of a station reading given various input from stdin */ /* The currently supported magnitudes are: Ml, Ms, Mb */ /* input is station type amplitude frequency lat, lon and depth of the event */ /* types are - LZ which translates to Ms */ /* PZ " " " Mb */ /* WA " " " Ml */ /* note - the station ajustments are the latest avaible */ /* how to make this work.... */ /* read in station locations and station adjustments */ /* wait for input ... until 1. amp reading */ /* 2. quit */ /* for 1 obivously read in line figure which mag to calc */ /* and output the magnitude */ /* for 2. end */ /* needed subroutines .... */ /* read in station locations into array */ /* calculate distance between 2 points */ /* calc Mb */ /* calc Ms */ /* calc Ml */ #include #include #include #include "calc_mag.h" #include "option_code.h" void main (int argc, char *argv[]) { Station_Struct *sta_list; int num_stat; int count=0; int use_station=-1; int use_delta=-1; int use_evt=-1; int i; char stat_pos_file[]="/usr/contrib/data/bdsn/bdsn.coord"; char ml_adjust_file[]="/data/02/bdsn/PROGRAMS/st_relp/st_relp_mladj_bdsn"; char opts[]="ml_file,coor_file,delta,evt_coor,evt_del"; char line[1000]; char *token; char station[5]; char type[5]; double amplitude; double magnitude; double elat,e_lat; double elon,e_lon; double frequency; double depth,e_dep; double edel,e_del; /* deal with command line stuff */ /* what options should there be? */ /* 1. input with delta instead of lat, lon */ /* 2. input event info on command line */ /* (lat etc and delta etc ) */ /* 3. Alternate files (station list/ adjustments) */ for (i=0;i=argc) {print_err_syntax(argv[i]);break;} strcpy(ml_adjust_file,argv[i++]); break; case 1: /* stat_pos_file */ if (i+1>=argc) {print_err_syntax(argv[i]);break;} strcpy(stat_pos_file,argv[i++]); break; case 2: /* use delta */ use_delta=1; break; case 3: /* single evt mode */ use_evt=1; if (i+3>=argc) {print_err_syntax(argv[i]);break;} e_lat=atof(argv[i+1]); e_lon=atof(argv[i+2]); e_dep=atof(argv[i+3]); i+=3; break; case 4: /* use delta, single evt mode */ use_evt=1; use_delta=1; if (i+2>=argc) {print_err_syntax(argv[i]);break;} e_del=atof(argv[i+1]); e_dep=atof(argv[i+2]); i+=2; break; case -1: default: { fprintf (stderr,"Do not know option :%s\n",argv[i]); print_syntax(); exit(-1); } } } sta_list=read_station_pos (&num_stat, stat_pos_file); read_ml_adjust(num_stat, sta_list, ml_adjust_file); /* deal with the input stuff */ while (!feof(stdin)) { gets(line); /* fprintf (stderr,"%s\n",line); */ /* 1. get first token */ token=strtok(line," "); if (!strcmp(token,"quit")){break;} strcpy(station,token); while(token!=NULL) { switch(count++) { case 0: strcpy(station,token); if (!strcmp(token,"quit")){break;} break: case 1: strcpy(type,token);break; case 2: amplitude=atof(token);break; case 3: frequency=atof(token);break; case 4: elat=atof(token);break; case 5: elon=atof(token);break; case 6: depth=atof(token);break; } token=strtok(NULL," "); } use_station=find_station(station,num_stat,sta_list); if (use_station==-1) { fprintf(stderr,"Can not find %s in the station list\n",station); strcpy(type,"NU"); } /* now run the magnitude calculations */ if (!strcmp(type,"WA")) { magnitude=calc_ml(amplitude,sta_list[use_station],elat,elon); printf ("Calc ML %s %lf\n",type,magnitude); } else if (!strcmp(type,"PZ")) { magnitude=calc_mb(amplitude,frequency,sta_list[use_station],elat,elon,depth); /* fprintf (stderr,"Calc MB %s %lf\n",type,magnitude); */ printf ("Calc MB %s %lf\n",type,magnitude); } else if (!strcmp(type,"LZ")) { magnitude=calc_ms(amplitude,frequency,sta_list[use_station],elat,elon); printf ("Calc MS %s %lf\n",type,magnitude); /* fprintf (stderr,"Calc MS %s %lf\n",type,magnitude); */ } else if (!strcmp(type,"NU")) { } else { fprintf(stderr,"Can not decode type %s\n",type); } fflush(stdout); count=0;; } } void read_ml_adjust(int num_stat, Station_Struct *sta_list, char *file) { FILE *in_file; char station[4]; float adjust; int i; int found=0; in_file=fopen(file,"r"); if (in_file==NULL) { fprintf(stderr,"Can not open %s\n",file); } while (!feof(in_file)) { if (fscanf(in_file,"%s %f",station,&adjust)==NULL) {break;} /* match the station to the station_list */ for (i=0;i