// Program to search in seisan nordic file the calculated stress drop, // user must be call it with command line argumens. The fist argument // is obligatory and the rest are optionals. The program can be call // the following way: // // getstressdrop [-c ] [-s ] [-p ] // // the is the maximum stress drop to consider in the searching process. // the is a file with the station-channels list, with the same format // that is written in the line SPEC of the S-FILES nordic format. // the is the file with the longitude latitude. The last points // of the polygon must be equal to the first (close polygon) // // Output will be a file , with the number of stressdrop // by step of 10 bars. // and a file with the list of earthquake magnitude vs stressdrop // Also is printed out the average stress drop. // // Written by Bladimir Moreno, August 30, 2014 //----------------------------------------------------------------------- #include #include char stalist[100][20]; // to load the stations-channels // Subroutine to search in a polygon. Return 1 if found it, else return 0 int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) { int i, j, c = 0; if(!nvert) return 1; for (i = 0, j = nvert-1; i < nvert; j = i++) { if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) c = !c; } return c; } // Subroutine to search if station-chanel is the user list. Return 1 if found it,else return 0 int stainclude(int nsta,char* staname) { int i=0; int found = 0; if(!nsta) return 1; for(i=0; i [ -c ] [ -s ] [ -p ]\n"); return; } if(argc>2) { for(i=2; i0) printf(" \n"); // blank line, new earthquake printf("%s\n",line); ++i; } if(strstr(line,"SPEC") && strstr(line,"MO") && strstr(line,"ST") && !strstr(line,"SPEC AVERAGE") && !strstr(line,"SPEC SD")) { // get stressdrop and Mw strncpy(station,line+6,8); station[8]=0; strncpy(cad,line+75,3); cad[3]=0; sscanf(cad,"%f",&fval); // get Mw if(fval>0) { // ignore stressdrop when Mw=0 strncpy(cad,line+25,5); cad[5]=0; sscanf(cad,"%f",&stressdrop); if((stressdrop < stresscut) && (stressdrop > 1) && stainclude(nsta,station) && pnpoly(npoints,longitude,latitude,xlon,ylat) ){ line[79]=0; // remove return printf("%.79s\n",line); // stressdrop selected stress[j]=stressdrop; mw[j]=fval; nquake[j]=i; // to control same earthquake ++j; ++nj; } } } if(!strncmp(line," ",3)) first = 1; // new earthquake } fclose(f); if(j==0) { // no selection found printf("%s\n","No earthquake was selected by the criteria"); return; } // Calculate average of stressdrop and Mw for individual earthquakes float summw=mw[0]; float sumstress=stress[0]; int l=1; // count earthquakes selected by criteria int n=1; // count stressdrop for individual earthqauke for(k=0; k<(stresscut/10);++k) class[k]=0; for(i=1; i(k*10)) && (avg_stress[i]<=((k+1)*10))) class[k]++; fprintf(fout,"%5.2f %6.1f\n",avg_mw[i],avg_stress[i]); } fclose(fout); // Calculate max average stressdrop maxstressdrop = 0; for(i=0; i