/* ---------------------------------------------------------------------- */ /* ttime.c return travel time for given depth and distance 26 Jan 98 dpa Created. Use traveltimes.dat file for table lookup trav arg1 arg2 > delta distance traveltime arg1 depth in km arg2 distance in degrees 27 Jan 98 dpa Added interpolation for time/distance. Modified to return "no_data" for invalid entries 11 Mar 98 dpa tt.c new function uses the table2.h travel times, including 0 and 10 km depths and 0 distance. 26 Jul 98 dpa callable as a subroutine, Split into two files, tt.c and tt_obj.c 23 Apr 99 dpa Moved "time" to "itime" so no collide with Unix. 17 May 99 dpa Moved boundary condition tests to here Hand in pointers to itime and distance returned values. Hand in "out" flag to detemine ascii output to stdout 09 Oct 00 dpa Corrected interpolation integer error 11 Oct 02 dpa Added interpolation of depth /* ---------------------------------------------------------------------- */ #define TTIME_VERSION "2.2" /* ---------------------------------------------------------------------- */ #include "table2.h" /* ---------------------------------------------------------------------- */ interpolate(depth, theta, time, distance) float depth, theta; float *time, *distance; { int i,i2,j; float d,t; float a,b,s; i = (int)((depth/10)+.5); j = (int)theta; if ((j+1 < ENTRIES) && (i+1 < SIZE)) { /* interpolate depth and distance */ s = (depth/10) - ((float)(int)(depth/10)); a = traveltimes[i][j+1] - traveltimes[i][j]; a = traveltimes[i][j] + (a*s); b = traveltimes[i+1][j+1] - traveltimes[i+1][j]; b = traveltimes[i+1][j] + (b*s); *distance = theta; d = theta - ((float)(int)theta); t = b - a; *time = a + (t*d); if (*time < traveltimes[i][j]) *time = -1; /* don't interp -1 */ } else { *time = traveltimes[i][j]; *distance = (float)((int)theta); } return i; } /* ---------------------------------------------------------------------- */ int tt_lookup(out, depth, distance, otime, odist) int out; /* flag ascii output to stdout */ float depth; /* depth in km */ float distance; /* angular distance in degrees */ float *otime; /* output travel time */ float *odist; /* output interpolated distance */ { int i; if ((depth < 0 ) || (depth > 2880)) { if (out) printf("%s: depth error: %.2f allowed range is 0-2880\n", "tt_lookup",depth); return -1; } if ((distance < 0) || (distance > 98)) { if (out) printf("%s: distance error: %.2f allowed range is 0-98\n", "tt_lookup",distance); return -2; } i = interpolate(depth, distance, otime, odist); if (out) { if (*otime != -1) { printf("%.2f km\t%.2f deg\t%.2f sec\n", (float)i*10,*odist,*otime); } else { printf("%.2f km\t%.2f deg\tno_data\n", (float)i*10,*odist); } } return (i); } /* ---------------------------------------------------------------------- */ /* EOF ttime.c */