/* ------------------------------------------------------------------------- /* GIS Laboratory /* Division of Geological and Planetary Sciences /* Caltech /* ------------------------------------------------------------------------- /* Program : EPI_READ.AML (Read and Process Quake Epicenter Data) /* Purpose : Generate a point coverage that represents the locations of /* earthquake epicenters and populate the point attribute table /* with event attributes /* ------------------------------------------------------------------------- /* Calls : none /* Called by: ARC prompt /* ------------------------------------------------------------------------- /* Arguments: in_file - path to file containing input data /* Globals : none /* ------------------------------------------------------------------------- /* Notes : The program runs from the ARC prompt and does the following: /* 1) reads epicenters and associated attributes from an ascii /* file that is in a specific format. /* 2) constructs a point file and an attribute file /* 3) generates a point coverage from the earthquake point file. /* 4) runs the BUILD function on the point file and adds the /* item DEPTH_M (depth in meters). /* 5) creates an INFO file and adds the following data from /* the attribute file: /* -ID - the id of the quake event /* DEPTH_M - event depth, meters /* DATE - event month/day/year /* MAG - magnitude /* DEPTH_KM - event depth, km /* 6) joins the data to the .PAT file. /* 7) calculates the depth, in meters, into the depth_m item. /* /* /* A sample of the datafile is as such: /* /* date time mag lat long depth Qual. /* 81/05/17 01:56:49.5 L 2.1 c 34.03 -118.26 4.8 A 516171 46 59 0 0 /* 81/05/26 10:07:19.7 L 2.0 l 33.94 -118.28 6.0 D 3179793 12 0 0 0 /* 81/05/29 13:39:31.3 L 2.0 c 33.88 -118.17 8.4 C 516779 45 73 0 0 /* /* ------------------------------------------------------------------------- /* History : 06/30/97 - Tony Soeller; program created /* ========================================================================= &args in_file /*. &severity &error &routine bailout &severity &warning &ignore /* Open the epicenter events file &s fileunit1 = [open %in_file% open_status -r] &if %open_status% ne 0 &then &return Could not open file %in_file%. /* Assemble the current date as a string &s today = [translate [date -usa] _ /] /* Define the names of the coordinate and attribute files; delete if existant &s coor_file = epi.%today% &if [exists %coor_file% -file] &then &s delete_status [delete %coor_file% -file] &s att_file = att.%today% &if [exists %att_file% -file] &then &s delete_status [delete %att_file% -file] /* Open the point file where coordinates will be stored &if [exists quake.code -info] &then &s delete_stat = [delete quake.code -info] /* Open the point file where coordinates will be stored &s fileunit2 = [open %coor_file% open_status -w] &if %open_status% ne 0 &then &return Could not open file %coor_file%. /* Open the attribute file where, uh, attributes will be stored &s fileunit3 = [open %att_file% open_status -w] &if %open_status% ne 0 &then &return Could not open file %att_file%. /* Bypass the first (header) record &s vals = [unquote [read %fileunit1% eof]] /* Loop through each line in the epicenter file extracting the longitude and /* latitude values and the desired attributes. Store the longitude and latitude /* values in one file and the attributes in a second file. &s rec_no = 1 &do &while %eof% ne 102 &s vals = [read %fileunit1% eof] &if %eof% eq 102 &then &goto the_end &s lat = [substr %vals% 30 5] &s long = [substr %vals% 36 7] &s year = [substr %vals% 1 2] &s month = [substr %vals% 4 2] &s day = [substr %vals% 7 2] &s mag = [unquote [substr %vals% 23 3]] &s depth = [unquote [substr %vals% 45 4]] &s date = %month%/%day%/%year% &s coord_record = %rec_no%,%long%,%lat% &s write_stat = [write %fileunit2% %coord_record%] &s att_record = %rec_no%,%date%,%mag%,%depth% &s write_stat = [write %fileunit3% %att_record%] &s rec_no = %rec_no% + 1 &label the_end &end /* Complete the point file &s write_stat = [write %fileunit2% end] /* Close the files &s closestat = [close -all] /* Define the path of the look-up table for INFO &s path = [path %att_file%] /* Generate, build, and add items to the point cover &s cov_name = epi_%today% generate %cov_name% input %coor_file% points quit /* exit from GENERATE build %cov_name% point additem %cov_name%.pat %cov_name%.pat depth_m 4 5 b /* Create INFO table that will store the quake attribute data &data arc info arc define QUAKE.CODE [translate %cov_name%]-ID,4,5,B DATE,8,8,D MAG,8,3,F,1 DEPTH_KM,8,4,F,1 add from %path% q stop &end /* Join the data from the "quake table" to the .PAT joinitem %cov_name%.pat quake.code %cov_name%.pat ~ %cov_name%-id depth_m linear /* In ARCEDIT calculate the depth in meters arcedit editc %cov_name% editf point sel all calc depth_m = depth_km * 1000 save quit /* Delete the QUAKE.CODE file &s delete_stat = [delete quake.code -info] &s delete_stat = [delete %coor_file% -file] &s delete_stat = [delete %att_file% -file] &return quake_proc.aml completed successfully. /**************************************************************************** &routine BAILOUT &s .error$flag 1 &s ok [close -all] &return &inform Error condition in epi_read.aml