00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <math.h>
00024 #include <string.h>
00025 #include <unistd.h>
00026
00027 #include <utils/utils.h>
00028
00029
00030 static char *help_msg[] =
00031 {
00032 " ",
00033 " earthquake [options] [parameters] ",
00034 " generate a random series of earthquakes. ",
00035 " ",
00036 " Options ",
00037 " v=yes : toggle verbose mode. [off] ",
00038 " help=yes : print this help message. ",
00039 " info=mercalli : print info on the Modified Mercalli Intensity Scale. ",
00040 " info=omori : print info on the Omori Seismic Scale. ",
00041 " ",
00042 " Parameters ",
00043 " n=value : generate value earthquakes. [100] ",
00044 " dt=value : find the biggest quake of over value days. [1] ",
00045 " mag=value : magnitude of the median quake is value. [1] ",
00046 " units=mercalli : output will be from the Modified Mercalli Intensity Scale.",
00047 " units=omori : output will be from the Omori Seismic Scale. ",
00048 " units=si : output will be in units of m/s^2. [default] ",
00049 " units=g : output will be in units of g (here on earth). ",
00050 " ",
00051 " Generate a random series of earthquakes based on the probability density ",
00052 " function: ",
00053 " p(x) = -log(a) a^x , with a^2 < 1 ",
00054 " a is determined by the median quake over the given time step. a is found ",
00055 " by: ",
00056 " a = 2^(-1/median_quake) ",
00057 " or if the mean quake is given, ",
00058 " a = e^(-1/mean_quake) ",
00059 " If a time step other than 1 is given, the maximum quake over this number of ",
00060 " time steps is returned. This is done using the distribution function: ",
00061 " P(x) = (1-a^x)^n ",
00062 " where n is the number of time steps. ",
00063 NULL
00064 };
00065
00066 static char *omori_msg[] =
00067 {
00068 " ",
00069 " The Omori Seismic Scale ",
00070 " ",
00071 " The Omori seismic scale is a seven-point scale that relates various ",
00072 " phenomena to maximum ground acceleration. It is based on the behavior of ",
00073 " typical Japanese structures and is still widely used in Japan. This ",
00074 " description is from Building Structures in Earthquake Countries by Alfredo ",
00075 " Montel (Lippincott, Philadelphia, 1912). Notice that its level I is ",
00076 " equivalent to a Mercalli intensity of VI. ",
00077 " ",
00078 " I. Maximum Acceleration = 300 mm per sec. per sec. ",
00079 " The shock is rather strong, so much so that it generally induces people",
00080 " to escape from their houses into the open. The walls of badly ",
00081 " constructed brick houses crack slightly and some parquet falls down; ",
00082 " ordinary wooden houses are shaken in such a degree that they loudly ",
00083 " creak; furniture is overturned; trees are visibly shaken; the water in ",
00084 " ponds and pools gets turbid, owing to the disturbance of the mud; ",
00085 " pendulum clocks stop; some very badly built factory chimneys are ",
00086 " damaged. ",
00087 " II. Maximum Acceleration = 900 mm per sec. per sec. ",
00088 " The walls in the wooden houses of Japan crack; old wooden houses get ",
00089 " slightly out of plumb; the Japanese tombstones and the badly ",
00090 " constructed stone lanterns are overturned; in a few cases the flow of ",
00091 " the thermal and mineral springs is changed; ordinary factory chimneys ",
00092 " are not damaged. ",
00093 " III. Maximum Acceleration = 1200 mm per sec. per sec. ",
00094 " About one-fourth of the factory chimneys are damaged; badly constructed",
00095 " brick houses are partially or totally destroyed; some old wooden houses",
00096 " are destroyed; wooden bridges are slightly damaged; some tombstones and",
00097 " stone lanterns are overturned; Japanese sliding doors (covered with ",
00098 " paper) are broken; the tiles of wooden houses are displaced; some ",
00099 " fragments of rocks are detached from the sides of the mountains. ",
00100 " IV. Maximum Acceleration = 2000 mm per sec. per sec. ",
00101 " All factory chimneys are ruined; the majority of the ordinary brick ",
00102 " houses are partially or totally destroyed; some wooden houses are ",
00103 " totally destroyed; the wooden sliding doors are mostly thrust out of ",
00104 " their channels; crevices from 2 to 3 inches (5 to 7-1/2 cm) wide appear",
00105 " in low and soft grounds; here and there the embankments are slightly ",
00106 " damaged; wooden bridges are partially destroyed; ordinarily constructed",
00107 " stone lanterns are overturned. ",
00108 " V. Maximum Acceleration = 2500 mm per sec. per sec. ",
00109 " All ordinary brick houses are very seriously damaged; about 3 percent ",
00110 " of the wooden houses are totally destroyed; some Buddhist temples are ",
00111 " ruined; the embankments are badly damaged; the railways are slightly ",
00112 " contorted; ordinary tombstones are overturned; brick walls are damaged;",
00113 " here and there, large fissures from 1 to 2 feet (30 to 60 cm) wide ",
00114 " appear along the banks of the watercourses. The water of rivers and ",
00115 " ditches is thrown on the banks; the contents of the wells are ",
00116 " disturbed; landslides occur. ",
00117 " VI. Maximum Acceleration = 4000 mm per sec. per sec. ",
00118 " The greater part of the Buddhist temples are ruined; from 50 to 80 ",
00119 " percent of the wooden houses are totally destroyed; the embankments are",
00120 " almost destroyed; the roads through paddy fields are ruined and ",
00121 " interrupted by fissures in such a degree that traffic by animals or ",
00122 " vehicles is impeded; the railways are very much contorted; great iron ",
00123 " bridges are destroyed; wooden bridges are partially or totally damaged;",
00124 " tombstones of solid construction are overturned; fissures some feet ",
00125 " wide appear in the soil, and are sometimes accompanied by jets of water",
00126 " and sand; iron or terra cotta tanks embedded in the ground are mostly ",
00127 " destroyed; all lowlying grounds are completely convulsed horizontally ",
00128 " as well as vertically in such a degree that sometimes the trees and all",
00129 " the vegetation on them die off; numerous landslides take place. ",
00130 " VII. Maximum Acceleration = much more than 4000 mm per sec. per sec. ",
00131 " All buildings are completely destroyed except a few wooden ",
00132 " constructions; some doors or wooden houses are thrown over distances ",
00133 " from 1 to 3 feet; enormous landslides with faults and shears of the ",
00134 " ground occur. ",
00135 " ",
00136 NULL
00137 };
00138
00139 static char *mercalli_msg[] =
00140 {
00141 " ",
00142 " The Modified Mercalli Intensity Scale ",
00143 " ",
00144 " I. Not felt except by a very few under especially favorable ",
00145 " circumstances. ",
00146 " II. Felt only by a few persons at rest, especially on upper floors of ",
00147 " buildings. Delicately suspended objects may swing. ",
00148 " III. Felt quite noticeably indoors, especially on upper floors of ",
00149 " buildings but many people do not recognize it as an earthquake. ",
00150 " Standing motor cars may rock slightly. Vibration like passing truck. ",
00151 " Duration estimated. ",
00152 " IV. During the day felt indoors by many, outdoors by few. At night some ",
00153 " awakened. Dishes, windows, and doors disturbed; walls make creaking ",
00154 " sound. Sensation like heavy truck striking building. Standing ",
00155 " motorcars rock noticeably. ",
00156 " V. Felt by nearly everyone; many awakened. Some dishes, windows, etc., ",
00157 " broken; a few instances of cracked plaster; unstable objects ",
00158 " overturned. Disturbance of trees, poles, and other tall objects ",
00159 " sometimes noticed. Pendulum clocks may stop. ",
00160 " VI. Felt by all; many frightened and run outdoors. Some heavy furniture ",
00161 " moved; a few instances of fallen plaster or damaged chimneys. Damage ",
00162 " slight. ",
00163 " VII. Everybody runs outdoors. Damage negligible in buildings of good design",
00164 " and construction slight to moderate in well built ordinary structures;",
00165 " considerable in poorly built or badly designed structures. Some ",
00166 " chimneys broken. Noticed by persons driving motor cars. ",
00167 " VIII. Damage slight in specially designed structures; considerable in ",
00168 " ordinary substantial buildings, with partial collapse; great in poorly",
00169 " built structures. Panel walls thrown out of frame structures. Fall of ",
00170 " chimneys, factory stacks, columns, monuments, walls. Heavy furniture ",
00171 " overturned. Sand and mud ejected in small amounts. Changes in well ",
00172 " water. Persons driving motor cars disturbed. ",
00173 " IX. Damage considerable in specially designed structures; well-designed ",
00174 " frame structures thrown out of plumb; great in substantial buildings, ",
00175 " with partial collapse. Buildings shifted off foundations. Ground ",
00176 " cracked conspicuously. Underground pipes broken. ",
00177 " X. Some well-built wooden structures destroyed; most masonry and frame ",
00178 " structures destroyed with foundations; ground badly cracked. Rails ",
00179 " bent. Landslides considerable from river banks and steep slopes. ",
00180 " Shifted sand and mud. Water splashed over banks. ",
00181 " XI. Few, if any (masonry), structures remain standing. Bridges destroyed. ",
00182 " Broad fissures in ground. Underground pipelines completely out of ",
00183 " service. Earth slumps and land slips in soft ground. Rails bent ",
00184 " greatly. ",
00185 " XII. Damage total. Waves seen on ground surfaces. Lines of sight and level ",
00186 " distorted. Objects thrown upward into the air. ",
00187 " ",
00188 NULL
00189 };
00190
00191 #define DEFAULT_N (100)
00192 #define DEFAULT_DT (1.)
00193 #define DEFAULT_MAG (1.)
00194 #define DEFAULT_VERBOSE 0
00195 #define DEFAULT_UNITS SI_UNITS
00196
00197 #define SI_UNITS 0
00198 #define MERCALLI_UNITS 1
00199 #define OMORI_UNITS 2
00200 #define G_UNITS 3
00201
00202 #define INFO_MERCALLI 0
00203 #define INFO_OMORI 1
00204
00205 double earthquake(double a,double dt);
00206 double convert_accel_to_si(double acceleration);
00207 double convert_accel_to_g(double acceleration);
00208 double convert_accel_to_omori(double acceleration);
00209 double convert_accel_to_mercalli(double acceleration);
00210 double convert_mercalli_to_accel(double mercalli);
00211 double convert_omori_to_accel(double omori);
00212 double convert_g_to_accel(double g);
00213 double convert_si_to_accel(double si);
00214
00215 int main(int argc, char *argv[])
00216 {
00217 char *unit_vals[] = { "si" , "mercalli" , "omori" , "g" , NULL };
00218 char *info_vals[] = { "mercalli" , "omori" , NULL };
00219 int i;
00220 int n, units, info;
00221 double dt, mag;
00222 gboolean verbose;
00223 double average_quake;
00224 double acceleration;
00225 double (*convert_func)(double);
00226 double (*convert_inv_func)(double);
00227 Eh_args *args;
00228
00229 args = eh_opts_init( argc , argv );
00230 if ( eh_check_opts( args , NULL , NULL , help_msg )!=0 )
00231 eh_exit(-1);
00232
00233 n = eh_get_opt_int ( args , "n" , DEFAULT_N );
00234 dt = eh_get_opt_dbl ( args , "dt" , DEFAULT_DT );
00235 mag = eh_get_opt_dbl ( args , "mag" , DEFAULT_MAG );
00236 verbose = eh_get_opt_bool( args , "v" , FALSE );
00237 units = eh_get_opt_key ( args , "units" , 0 , unit_vals );
00238 info = eh_get_opt_key ( args , "info" , -1 , info_vals );
00239
00240 switch ( info )
00241 {
00242 case INFO_MERCALLI:
00243 eh_print_message( stderr , mercalli_msg );
00244 eh_exit(0);
00245 case INFO_OMORI:
00246 eh_print_message( stderr , omori_msg );
00247 eh_exit(0);
00248 }
00249
00250 if ( verbose )
00251 {
00252 fprintf(stderr,"Magnitude : %f\n",mag);
00253 fprintf(stderr,"Dt : %f\n",dt);
00254 fprintf(stderr,"n : %d\n",n);
00255 }
00256
00257 switch ( units )
00258 {
00259 case SI_UNITS:
00260 convert_func = &convert_accel_to_si;
00261 convert_inv_func = &convert_si_to_accel;
00262 break;
00263 case MERCALLI_UNITS:
00264 convert_func = &convert_accel_to_mercalli;
00265 convert_inv_func = &convert_mercalli_to_accel;
00266 break;
00267 case OMORI_UNITS:
00268 convert_func = &convert_accel_to_omori;
00269 convert_inv_func = &convert_omori_to_accel;
00270 break;
00271 case G_UNITS:
00272 convert_func = &convert_accel_to_g;
00273 convert_inv_func = &convert_g_to_accel;
00274 break;
00275 }
00276
00277 if ( strcmp(g_basename(argv[0]),"quakeconvert_to")==0 )
00278 {
00279 while ( fscanf(stdin,"%lf",&acceleration)==1 )
00280 fprintf(stdout,"%f\n",convert_func(acceleration));
00281 return 0;
00282 }
00283 else if ( strcmp(g_basename(argv[0]),"quakeconvert_from")==0 )
00284 {
00285 while ( fscanf(stdin,"%lf",&acceleration)==1 )
00286 fprintf(stdout,"%f\n",convert_inv_func(acceleration));
00287 return 0;
00288 }
00289
00290 average_quake = convert_inv_func(mag);
00291
00292 for ( i=0 ; i<n ; i++ )
00293 {
00294 acceleration = earthquake(exp(-1./average_quake),dt);
00295 fprintf(stdout,"%f\n",convert_func(acceleration));
00296 }
00297
00298 return 0;
00299 }
00300
00301 double convert_accel_to_si(double acceleration)
00302 {
00303 return acceleration;
00304 }
00305
00306 double convert_si_to_accel(double si)
00307 {
00308 return si;
00309 }
00310
00311 double convert_accel_to_g(double acceleration)
00312 {
00313 return acceleration/9.81;
00314 }
00315
00316 double convert_g_to_accel(double g)
00317 {
00318 return g*9.81;
00319 }
00320
00321 double convert_accel_to_omori(double acceleration)
00322 {
00323 if ( acceleration <= .3 )
00324 return 1;
00325 else if ( acceleration <= .9 )
00326 return 2;
00327 else if ( acceleration <= 1.2 )
00328 return 3;
00329 else if ( acceleration <= 2. )
00330 return 4;
00331 else if ( acceleration <= 2.5 )
00332 return 5;
00333 else if ( acceleration <= 4 )
00334 return 6;
00335 else
00336 return 7;
00337 }
00338
00339 double convert_omori_to_accel(double omori)
00340 {
00341 if ( omori == 1 )
00342 return .3;
00343 else if ( omori == 2 )
00344 return .9;
00345 else if ( omori == 3 )
00346 return 1.2;
00347 else if ( omori == 4 )
00348 return 2.;
00349 else if ( omori == 5 )
00350 return 2.5;
00351 else
00352 return 4.;
00353 }
00354
00355 double convert_accel_to_mercalli(double acceleration)
00356 {
00357 return (log10(acceleration) + 2.5 ) * 3;
00358 }
00359
00360 double convert_mercalli_to_accel(double mercalli)
00361 {
00362 return pow(10,mercalli/3 - 2.5);
00363 }
00364
00365 int do_help(char *message[])
00366 {
00367 int i;
00368 char **p;
00369
00370 if ( message )
00371 for ( p=message ; *p ; fprintf(stderr,"%s\n",*p), p++ );
00372 else
00373 for (p=message,i=0 ; i<4 ; i++)
00374 fprintf(stderr,"%s\n",p[i]);
00375
00376 return 0;
00377 }
00378