/************************************************************************/ /* Make_IR: Populates the IR schema from the HT schema. */ /************************************************************************/ /* Author: Stephane Zuzlewski UC Berkeley Seismological Laboratory stephane@seismo.berkeley.edu Purpose: Modification History: Date Ver Who What --------------------------------------------------------------------- 1998/??/?? 1.0 SMZ Initial coding. 2002/06/30 2.0 SMZ Added support for HP filter in Filter chain (For NCSN IR). 2003/04/14 2.0 SMZ If no network code specified, look it in the the DB from station code. 2003/08/14 3.0 SMZ The time spans are now being coalesced. 2003/11/12 3.1 SMZ Added more parameters to channel comparison. 2005/01/18 3.2 SMZ Flat passband response are now being represented by a B053 (instead of a B054). 2006/03/08 3.3 SMZ Updated algorithm in function dg_filter. 2006/04/10 3.4 SMZ Updated algorithm compute_A0_Sd. 2006/06/01 3.5 SMZ Corrected bug with A0 frequency. 2006/06/01 3.6 SMZ Database connection string can now be specified in an environment variable. 2006/06/14 3.7 SMZ Normalization frequency for stage 1 is now picked from the sensor info. 2008/08/14 3.8 SMZ Trim trailing blanks from station name before inserting into Station_Data.staname. 2010/09/23 3.9 SMZ Delay & correction are now 0 for ADC stage. 2012/02/02 4.0 SMZ Changed lp_dg_filter algorithm based on Bob's feedback (overdamped case). 2012/05/21 4.1 SMZ Updated Stage 0 for polynomial response. 2013/11/18 4.2 SMZ Fixed bug with Response_PZ query. 2018/10/22 4.3 SMZ Fixed bug that showed up on Linux. 2019/09/05 4.4 SMZ Corrected lp_dg_filter algorithm based on Bob's feedback (overdamped case). */ /************************************************************************/ #ifndef lint static char sccsid[] = "%W% %G% %U%"; #endif #include #include #include #include #include #include #include "complex.h" EXEC ORACLE OPTION (ORACA=YES); EXEC SQL INCLUDE sqlca.h; #define TPI (8.*atan(1.)) #define PI (4.*atan(1.)) #define CABS(c) (hypot (c.real, c.imag)) #define log2(x) ((double)(log(x)/M_LN2)) #define CONNECT_STRING "user/passwd@db" #define NOMOREROWS 1403 #define VERSION "4.4" #define info stdout char *syntax[] = { "%s version " VERSION " -- Populates the IR schema from the HT schema.", "%s [-S station] [-N network] [-v] [-h]", " where:", " -h Help - prints syntax message.", " -v Verbose Mode.", " -S station Specifies a station code.", " -N network Specifies a network code.", " Environment variable DB_CONNECT --> Overwrites default database connection string.", NULL }; EXEC SQL BEGIN DECLARE SECTION; char user_pwd[80]; int i; int j; int k; int z; short ind; /* Indicator */ short ind2; /* Indicator */ short indremark; /* Indicator */ char sta[7]; /* Station code */ char sta2[7]; /* Station code */ char staname[51]; /* Station name */ char cha[7]; /* Channel code */ char net[9]; /* Network code */ char net2[9]; /* Network code */ int net_id; /* Network identifier */ char net_tmp[71]; /* Network */ int seqfil_id; /* Sequence of filters identifier */ char seqfil_name[81];/* Sequence of filters name */ char channel[4]; /* Channel name */ char seedchan[4]; /* SEED channel name */ char channelsrc[9]; /* Channel source */ char location[3]; /* SEED location */ char loc[3]; /* SEED location */ char loctmp[3]; /* SEED location */ double rgain; /* Gain */ double rfrequency; /* Frequency */ double samprate; /* Sampling rate */ double clock_drift; /* Clock drift */ char flags[28]; /* SEED channel flags */ char data_format[81];/* Data format */ int comp_type; /* Compression type identifier */ int unit_signal; /* Unit of signal responses identifier */ int unit_calib; /* Unit of calibration identifier */ int block_size; /* Block size */ int record_length; /* Record length */ char remark[31]; /* Optional comment */ char unitsignal[81]; /* Unit of signal responses identifier */ int data_pchannel_nb; /* Datalogger physical channel number */ int lchannel_nb; /* Logical channel number */ int data_nb; /* Datalogger number */ int digi_nb; /* Digitizer number */ int digi_pchannel_nb; /* Digitizer physical channel number */ int digi_rchannel_nb; /* Digitizer *REAL* channel number */ char digi_serial_nb[81]; /* Digitizer serial number */ char digi_polarity; /* Digitizer polarity */ int nb_filamp; /* Number of filter-amplifiers */ double azimuth; /* Azimuth */ double dip; /* Dip */ int filamp_nb; /* Filter-amplifier number */ int filamp_pchannel_nb; /* Filter-amplifier physical channel number */ int sensor_nb; /* Sensor number */ int data_id; /* Datalogger identifier */ int filamp_id; /* Filter-amplifier identifier */ int sensor_id; /* Sensor identifier */ char sensor_name[81]; /* Sensor name */ int component_nb; /* Component number */ double lat; /* Sensor latitude */ double lon; /* Sensor longitude */ double elev; /* Sensor elevation */ double slat; /* Station latitude */ double slon; /* Station longitude */ double selev; /* Station elevation */ double edepth; /* Sensor depth */ char data_type[81]; /* Datalogger type */ char udate[32]; /* Date */ char ondate[32]; /* Start date */ char offdate[32]; /* End date */ char on_date[32]; /* Start date */ char off_date[32]; /* End date */ char enddate[32]; /* End date */ int seqresp_id; /* Sequence of responses identifier */ int nb_resp; /* Number of responses */ double sensitivity; /* Sensitivity */ double frequency; /* Frequency */ char resp_type; /* Response type */ int resp_id; /* Response identifier */ int unit_in; /* Input units */ int unit_out; /* Output units */ char sunit_in[81]; /* Input units */ char sunit_out[81]; /* Output units */ int punit_in; /* Polynomial Input units */ int punit_out; /* Polynomial Output units */ char psunit_in[81]; /* Polynomial Input units */ char psunit_out[81]; /* Polynomial Output units */ char r_type; /* SEED response type */ char filter_type[3]; /* Filter type */ int nb_pole; /* Number of poles */ double corner_freq; /* Corner frequency */ double damping_value; /* Damping value */ char type; /* Type */ double r_value; /* Real value */ double i_value; /* Imaginary value */ double r_error; /* Real error */ double i_error; /* Imaginary error */ int pz_nb; /* Pole number */ int z_nb; /* Zero number */ int poid; /* Polynomial identifier */ char polyname[81]; /* Polynomial name */ char poly_type; /* Polynom type */ double lower_bound; /* Lower bound */ double upper_bound; /* Upper bound */ double max_error; /* Maximum error */ int nb_coeff; /* Number of coefficients */ double pn_value; /* Polynomial value */ double gain; /* Gain */ double in_sp_rate; /* Input sample rate */ double out_sp_rate; /* Output sample rate */ int offset; /* Offset */ double delay; /* Delay */ double correction; /* Correction */ char name[81]; /* FIR filter name */ char symmetry; /* FIR filter symmetry */ char sym[12]; /* FIR filter symmetry */ int nb_filter; /* Number of filters */ int nb_poles; /* Number of response poles */ int nb_zero; /* Number of response zeroes */ int nb_temp; /* Temporary variable */ int nb_fir_coeff; /* Number of coefficients in a FIR filter */ double fir_coeff; /* FIR filter coefficient */ double fir_error; /* FIR filter error */ double fir_gain; /* FIR filter gain */ double ogain; /* Overall gain */ int word_16; /* Word 16 */ int word_32; /* Word 32 */ int inid; /* Instrument identifier */ int format_id; /* Format identifier */ int count_id; /* Digital counts identifier */ int factor; /* Decimation factor */ double r_value; /* Real pole/zero */ double i_value; /* Imaginary pole/zero */ int int_tmp; /* Temporary integer */ int dic_key; char lddate[32]; /* Load date */ int Stage; /* Stage sequence number */ double A0; double Sd; EXEC SQL END DECLARE SECTION; /************************************************************************/ /* External variables and symbols. */ /************************************************************************/ char *cmdname; /* program name from command line. */ long SQLCODE; void sql_error(); /* Handles unrecoverable errors */ /************************************************************************/ /* print_syntax: */ /* Print the syntax description of program. */ /************************************************************************/ int print_syntax (char *cmd, /* program name. */ char *syntax[], /* syntax array. */ FILE *fp) /* FILE ptr for output. */ { int i; for (i=0; syntax[i] != NULL; i++) { fprintf (fp, syntax[i], cmd); fprintf (fp, "\n"); } return (0); } /************************************************************************/ /* Remove_Blank: */ /* */ /* Removes trailing blanks in a string. */ /************************************************************************/ char* Remove_Blank (char *s) { char *p = s + strlen (s); while (--p >= s) if (*p == ' ') *p = '\0'; else break; return (s); } /************************************************************************/ /* Convert_Date: */ /* */ /* Function to convert a Oracle date to a julian date. */ /************************************************************************/ char* Convert_Date (char d[32]) { EXEC SQL BEGIN DECLARE SECTION; char nd[32]; int day; EXEC SQL END DECLARE SECTION; static char fd[32]; EXEC SQL SELECT TO_CHAR (TO_DATE (:d, 'YYYY/MM/DD HH24:MI:SS'), 'DDD') INTO :nd FROM DUAL; sprintf (fd, "%.4s.%.3s.%.2s%.2s", d, nd, d+11, d+14); return (fd); } /************************************************************************/ /* compute_A0_Sd: */ /* Compute A0, Sd, and gain at rfreq for blockette 53 and 58. */ /* Given: pole and zeros, gain at freq. */ /************************************************************************/ compute_A0_Sd ( double gain, double freq, double rfreq, double *A0, double *Sd, DCOMPLEX Pole[128], DCOMPLEX Zero[128], int nb_pole, int nb_zero) { DCOMPLEX ciw, citf; double rgain; int i; /* Compute A0 for specified frequency and gain. */ ciw = dcmplx(0., TPI * freq); citf = dcmplx(1., 0.); for (i=0; i< nb_zero; i++) citf = dcmult (citf, dcsub(ciw,Zero[i])); for (i=0; i< nb_pole; i++) citf = dcdiv (citf, dcsub(ciw,Pole[i])); *A0 = 1./CABS(citf); *Sd = gain; /* Now that we have Sd and A0, compute gain at response frequency. */ ciw = dcmplx(0., TPI * rfreq); citf = dcmplx(1., 0.); for (i=0; i< nb_zero; i++) citf = dcmult (citf, dcsub(ciw,Zero[i])); for (i=0; i< nb_pole; i++) citf = dcdiv (citf, dcsub(ciw,Pole[i])); rgain = *Sd * *A0 * CABS(citf); /* *A0 = 1./CABS(citf);*/ *Sd = rgain; } /************************************************************************/ /* lp_dg_filter: */ /* Low pass Damping Given filter. */ /* A low pass damping given filter has 1 or 2 complex poles */ /* p = (-h*w, sqrt(1.-h*h)*w) */ /* p = (-h*w, -sqrt(1.-h*h)*w) */ /************************************************************************/ /* hp_dg_filter: */ /* High pass Damping Given filter. */ /* A high pass damping given filter has the same poles as a low */ /* pass damping given filter, and the same number of complex zeros.*/ /* z = (0., 0.) */ /************************************************************************/ int dg_filter (int np, /* number of poles to generate. */ double fc, /* filter corner frequency (hz). */ double h, /* fraction of critical damping. */ int pz_nb, /* Pole number */ DCOMPLEX Pole[128]) /* Poles */ { double wc; double ar, ai; int n = np; if (fc < 0.) fc = (-1.)/fc; wc = TPI * fc; ar = -h * wc; if (h <= 1) { ai = sqrt(1. - h*h) * wc; if (n--) { Pole[pz_nb].real = ar; Pole[pz_nb++].imag = ai; } if (n--) { Pole[pz_nb].real = ar; Pole[pz_nb++].imag = -ai; } } else /* Overdamped case */ { ai = sqrt(h*h - 1) * wc; if (n--) { Pole[pz_nb].real = ar + ai; Pole[pz_nb++].imag = 0.; } if (n--) { Pole[pz_nb].real = ar - ai; Pole[pz_nb++].imag = 0.; } } return (pz_nb); } /************************************************************************/ /* lp_bw_filter: */ /* Low pass Butterworth Filter */ /************************************************************************/ /* hp_bw_filter: */ /* High pass Butterworth Filter. */ /* A high pass Butterworth filter has the same poles as a low-pass */ /* Butterworth filter, but also has the a number of zeros (0.,0.) */ /* equal to the number of poles. */ /************************************************************************/ int bw_filter (int nbwfp, /* # of poles for butterworth filter. */ double bwfc, /* filter corner frequency (hz). */ int pz_nb, /* Pole number */ DCOMPLEX Pole[128]) /* Poles */ { double f2pp; /* 2 * the number of poles to generate. */ double wc; /* filter corner frequency (radians/sec)*/ double ak, ar, ai; int n_odd_poles; /* number of odd poles. */ int n_pole_pairs; /* number of even poles. */ int i; f2pp = 2. * nbwfp; if (bwfc < 0.) bwfc = (-1.)/bwfc; wc = TPI * bwfc; n_odd_poles = nbwfp % 2; n_pole_pairs = nbwfp / 2; for (i=1; i<=n_pole_pairs; i++) { ak = 2. * sin((2.*(double)i - 1.)*PI/f2pp); ar = ak * wc / 2.; ai = wc * sqrt (4. - ak*ak) / 2.; Pole[pz_nb].real = -ar; Pole[pz_nb++].imag = -ai; Pole[pz_nb].real = -ar; Pole[pz_nb++].imag = ai; } if (n_odd_poles > 0) { Pole[pz_nb].real = -wc; Pole[pz_nb++].imag = 0.; } return (pz_nb); } /************************************************************************/ /* Generate_Sta: */ /* Function to populate the Station_Data table. */ /************************************************************************/ void Generate_Sta ( char psta[7], /* Station code */ char pnet[9], /* Network code */ char pdate[32], /* Date of interest */ char edate[32], /* End Date */ int verbose) /* Verbose mode */ { EXEC SQL WHENEVER SQLERROR DO sql_error(); strcpy (sta2, psta); strcpy (net2, pnet); strcpy (udate, pdate); strcpy (enddate, edate); /* Retrieving station information */ EXEC SQL SELECT ondate, offdate, staname, lat, lon, elev INTO :ondate, :offdate, :staname, :slat, :slon, :selev FROM Station WHERE sta = :sta2 AND net = :net2 AND :udate >= ondate AND :udate < offdate; /* Inserting station information */ Remove_Blank(staname); word_16 = 10; word_32 = 3210; net_id = -1; if (!strcmp (net2, "BK")) strcpy (net_tmp, "Berkeley Digital Seismic Network (BDSN)"); else if (!strcmp (net2, "BP")) strcpy (net_tmp, "Parkfield High Resolution Seismic Network (HRSN)"); else if (!strcmp (net2, "SF")) strcpy (net_tmp, "San Andreas Fault Observatory at Depth (SAFOD)"); else if (!strcmp (net2, "BG")) strcpy (net_tmp, "Berkeley Geysers Network"); else if (!strcmp (net2, "CE")) strcpy (net_tmp, "California Strong Motion Instrumentation Program"); else if (!strcmp (net2, "NC")) strcpy (net_tmp, "Northern California Seismic Network (NCSN)"); else if (!strcmp (net2, "NN")) strcpy (net_tmp, "Western Great Basin/Eastern Sierra Nevada"); else if (!strcmp (net2, "NP")) strcpy (net_tmp, "United States National Strong-Motion Network"); else if (!strcmp (net2, "PG")) strcpy (net_tmp, "Pacific Gas and Electricity"); else if (!strcmp (net2, "UL")) strcpy (net_tmp, "USGS Low Frequency Geophysical Data Network"); else strcpy (net_tmp, net2); EXEC SQL SELECT id INTO :net_id FROM D_Abbreviation WHERE description = :net_tmp; if (net_id == (-1)) { EXEC SQL INSERT INTO D_Abbreviation (id, description) VALUES (abbseq.NEXTVAL, :net_tmp); EXEC SQL SELECT abbseq.CURRVAL INTO :net_id FROM DUAL; } EXEC SQL INSERT INTO Station_Data (net, sta, lat, lon, elev, staname, net_id, word_32, word_16, ondate, offdate, lddate) VALUES (:net2, :sta2, :slat, :slon, :selev, :staname, :net_id, :word_32, :word_16, :ondate, :enddate, SYSDATE); } /************************************************************************/ /* Store_Station_IR: */ /* Function to store a station response into a string. */ /************************************************************************/ void Store_Station_IR ( char psta[7], /* Station code */ char pnet[9], /* Network code */ char pdate[32], /* Date of interest */ char *sta_ir) /* Station String */ { char stmp[1024]; strcpy (sta_ir, ""); strcpy (udate, pdate); strcpy (sta2, psta); strcpy (net2, pnet); EXEC SQL SELECT ondate, offdate, staname, lat, lon, elev INTO :ondate, :offdate, :staname, :slat, :slon, :selev FROM Station WHERE sta = :sta2 AND net = :net2 AND :udate >= ondate AND :udate < offdate; Remove_Blank(staname); Remove_Blank(ondate); Remove_Blank(offdate); sprintf (stmp, "%s %s %.3f %.3f %.3f %s", sta2, net2, slat, slon, selev, staname);strcat (sta_ir, stmp); } /************************************************************************/ /* Generate_IR: */ /* Function to populate the IR Schema. */ /************************************************************************/ void Generate_IR ( char psta[7], /* Station code */ char pnet[9], /* Network code */ char pcha[7], /* SEED channel name */ char ploc[3], /* Location code */ char pdate[32], /* Date of interest */ char edate[32], /* End Date */ int verbose) /* Verbose mode */ { DCOMPLEX Pole[128]; DCOMPLEX Zero[128]; char *c_tmp; int Flag_Poly = 0; int Flag_Flat = 0; char channel_type; /* Location code */ if ((!strcmp (ploc, "-")) || (!strcmp (ploc, "--"))) strcpy (ploc, " "); /* Initializing stage sequence number and overall gain */ Stage = 1; ogain = 1.; /* Retrieving station information */ strcpy (udate, pdate); strcpy (sta2, psta); strcpy (net2, pnet); strcpy (cha, pcha); strcpy (loc, ploc); strcpy (enddate, edate); strcpy (lddate, ""); EXEC SQL SELECT lddate INTO :lddate FROM Station WHERE sta = :sta2 AND net = :net2 AND :udate >= ondate AND :udate < offdate; if (strlen (lddate) == 0) { printf ("\n No data found for this channel at this date (%s -- %s -- %s -- %s -- %s).\n\n", udate, sta2, net2, cha, loc); return; } EXEC SQL DECLARE chan_cursor CURSOR FOR SELECT sta, net, data_nb, pchannel_nb, lchannel_nb, seqfil_id, seedchan, channel, channelsrc, location, rgain, rfrequency, samprate, clock_drift, flags, data_format, comp_type, unit_signal, unit_calib, block_size, remark, ondate, offdate FROM Station_Datalogger_LChannel WHERE sta = :sta2 AND net = :net2 AND seedchan = :cha AND location = :loc AND :udate >= ondate AND :udate < offdate ORDER BY pchannel_nb, lchannel_nb; EXEC SQL OPEN chan_cursor; strcpy (remark, ""); EXEC SQL FETCH chan_cursor INTO :sta:ind, :net:ind, :data_nb:ind, :data_pchannel_nb:ind, :lchannel_nb:ind, :seqfil_id:ind2, :seedchan:ind, :channel:ind, :channelsrc:ind, :location:ind, :rgain:ind, :rfrequency:ind, :samprate:ind, :clock_drift:ind, :flags:ind, :data_format:ind, :comp_type:ind, :unit_signal:ind, :unit_calib:ind, :block_size:ind, :remark:indremark, :ondate:ind, :offdate:ind; while (sqlca.sqlcode != NOMOREROWS) { Flag_Poly = 0; Flag_Flat = 0; Remove_Blank (sta); Remove_Blank (net); Remove_Blank (seedchan); Remove_Blank (channel); Remove_Blank (channelsrc); if (indremark == (-1)) strcpy (remark, ""); else Remove_Blank (remark); Remove_Blank (location); /* Location */ if (strlen (location) == 0) strcpy (location, " "); /* Retrieving channel type */ EXEC SQL SELECT channel_type INTO :channel_type FROM Station_Datalogger_PChannel WHERE sta = :sta AND net = :net AND data_nb = :data_nb AND pchannel_nb = :data_pchannel_nb AND :udate >= ondate AND :udate < offdate; /* Synthetic channel */ if (channel_type == 'S') { ogain = 1.; /* Converting dates */ strcpy (on_date, Convert_Date (ondate)); strcpy (off_date, Convert_Date (enddate)); if (verbose) { printf ("\n\n ======== CHANNEL RESPONSE DATA ========"); printf ("\n Station:\t%s", sta); printf ("\n Network:\t%s", net); printf ("\n Channel:\t%s", seedchan); printf ("\n Location:\t%s", location); printf ("\n Start date:\t%s", on_date); printf ("\n End date:\t%s", off_date); printf ("\n =======================================\n"); } /* Retrieving station information */ EXEC SQL SELECT ondate, offdate, staname, lat, lon, elev INTO :ondate, :offdate, :staname, :slat, :slon, :selev FROM Station WHERE sta = :sta AND net = :net AND :udate >= ondate AND :udate < offdate; /* Inserting channel information */ inid = 0; strcpy (sensor_name, "Synthetic State of Health (SOH)"); EXEC SQL SELECT id INTO :inid FROM D_Abbreviation WHERE description = :sensor_name; if (inid == 0) { EXEC SQL INSERT INTO D_Abbreviation (id, description) VALUES (abbseq.NEXTVAL, :sensor_name); EXEC SQL SELECT abbseq.CURRVAL INTO :inid FROM DUAL; } record_length = (int)(log2 ((double)(block_size))); if (samprate < 0) samprate = (-1.)/samprate; azimuth = dip = edepth = 0.; EXEC SQL INSERT INTO Channel_Data (net, sta, seedchan, channel, channelsrc, location, inid, remark, unit_signal, unit_calib, lat, lon, elev, edepth, azimuth, dip, format_id, record_length, samprate, clock_drift, flags, ondate, offdate, lddate) VALUES (:net, :sta, :seedchan, :channel, :channelsrc, :location, :inid, :remark, :unit_signal, :unit_calib, :slat, :slon, :selev, :edepth, :azimuth, :dip, :comp_type, :record_length, :samprate, :clock_drift, :flags, :ondate, :enddate, SYSDATE); /* Inserting poles & zeros information */ r_type = 'D'; Stage = 1; A0 = 1.; EXEC SQL SELECT name INTO :unitsignal FROM D_Unit WHERE id = :unit_signal; if (verbose) { printf ("\n\n\n\t\t+--------------------------+"); printf ("\n\t\t| Response (Poles & Zeros) |"); printf ("\n\t\t+--------------------------+\n"); printf ("\n Transfer function type:\t%c", r_type); printf ("\n Stage sequence number:\t\t%d", Stage); printf ("\n Response in units lookup:\t%.10s", unitsignal); printf ("\n Response out units lookup:\t%.10s", unitsignal); printf ("\n A0 normalization factor:\t%8.6f", A0); printf ("\n Normalization frequency:\t%.3f", rfrequency); printf ("\n Number of zeroes:\t\t%d", 0); printf ("\n Number of poles:\t\t%d", 0); } /* Inserting P&Z information */ EXEC SQL INSERT INTO Poles_Zeros (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, pz_key, tf_type, unit_in, unit_out, AO, AF, lddate) VALUES (:net, :sta, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, :Stage, pzseq.NEXTVAL, :r_type, :unit_signal, :unit_signal, :A0, :rfrequency, SYSDATE); EXEC SQL INSERT INTO PZ (key, name, lddate) VALUES (pzseq.CURRVAL, NULL, SYSDATE); /* Inserting gain information */ gain = 1.; if (verbose) { printf ("\n\n\n\t\t+--------------+"); printf ("\n\t\t| Channel Gain |"); printf ("\n\t\t+--------------+\n"); printf ("\n Stage sequence number:\t\t%d", Stage); printf ("\n Gain:\t\t\t\t%10.6E", gain); printf ("\n Frequency of gain:\t\t%10.6E HZ", rfrequency); printf ("\n Number of calibrations:\t%d", 0); } EXEC SQL INSERT INTO Sensitivity (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, sensitivity, frequency, lddate) VALUES (:net, :sta, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, :Stage, :gain, :rfrequency, SYSDATE); /* Retrieving number of filters */ Stage++; if (ind2 != (-1)) { EXEC SQL SELECT nb_filter INTO :nb_filter FROM Filter_Sequence WHERE seqfil_id = :seqfil_id; } else nb_filter = 0; for (j=1;j<=nb_filter;j++) { EXEC SQL SELECT gain, frequency, in_sp_rate, out_sp_rate, offset, delay, correction, seqresp_id INTO :gain, :frequency, :in_sp_rate, :out_sp_rate, :offset, :delay, :correction, :seqresp_id FROM Filter WHERE filter_id = (SELECT filter_id FROM Filter_Sequence_Data WHERE seqfil_id = :seqfil_id AND filter_nb = :j); fir_gain = 1.; /* Retrieving number of responses */ EXEC SQL SELECT count(*) INTO :nb_resp FROM Response WHERE seqresp_id = :seqresp_id; /* DFILTER */ /* INPUT */ /* DELAY */ /* Generating response lines */ for (i=1;i<=nb_resp;i++) { EXEC SQL SELECT resp_type, resp_id, unit_in, unit_out, r_type INTO :resp_type, :resp_id, :unit_in, :unit_out, :r_type FROM Response WHERE seqresp_id = :seqresp_id AND resp_nb = :i; switch (resp_type) { case 'H': printf ("\n Error: Found HP response in DFILTER.\n"); break; case 'L': printf ("\n Error: Found LP response in DFILTER.\n"); break; case 'Z': printf ("\n Error: Found PZ response in DFILTER.\n"); break; case 'P': printf ("\n Error: Found PN response in DFILTER.\n"); break; case 'F': EXEC SQL SELECT name, symmetry, gain INTO :name, :symmetry, :fir_gain FROM Filter_FIR WHERE fir_id = :resp_id; switch (symmetry) { case 'O': strcpy (sym, "ODD"); break; case 'E': strcpy (sym, "EVEN"); break; case 'N': strcpy (sym, "NONE"); break; default: strcpy (sym, "ALL"); } Remove_Blank (name); /* FIR */ EXEC SQL SELECT count(*) INTO :nb_fir_coeff FROM Filter_FIR_Data WHERE fir_id = :resp_id; if (verbose) { printf ("\n\n\n\t\t+-------------------------+"); printf ("\n\t\t| Response (Coefficients) |"); printf ("\n\t\t+-------------------------+\n"); printf ("\n Transfer function type:\t%c", 'D'); printf ("\n Stage sequence number:\t\t%d", Stage); printf ("\n Response in units lookup:\t%.10s", "COUNTS"); printf ("\n Response out units lookup:\t%.10s", "COUNTS"); printf ("\n Number of numerators:\t\t%d", nb_fir_coeff); printf ("\n Number of denominators:\t%d", 0); } EXEC SQL SELECT id INTO :count_id from D_Unit WHERE name = 'COUNTS'; dic_key = 0; EXEC SQL SELECT key INTO :dic_key FROM DC WHERE name = :name; if (dic_key == 0) { EXEC SQL INSERT INTO Coefficients (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, dc_key, unit_in, unit_out, tf_type, lddate) VALUES (:net, :sta2, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, :Stage, dcseq.NEXTVAL, :count_id, :count_id, 'D', SYSDATE); EXEC SQL INSERT INTO DC (key, name, symmetry, storage, lddate) VALUES (dcseq.CURRVAL, :name, :symmetry, 'F', SYSDATE); if (nb_fir_coeff > 0) { if (verbose) printf ("\n Numerator coefficients:"); if (verbose) printf ("\n i\tcoefficient\terror"); for (z=1;z<=nb_fir_coeff;z++) { EXEC SQL SELECT coefficient, error INTO :fir_coeff, :fir_error:ind FROM Filter_FIR_Data WHERE fir_id = :resp_id AND coeff_nb = :z; /*if (verbose) printf ("\n %d\t%10.6E\t%10.6E", z, fir_coeff, fir_error);*/ EXEC SQL INSERT INTO DC_Data (key, row_key, type, coefficient, error) VALUES (dcseq.CURRVAL, :z, 'N', :fir_coeff, :fir_error); } } } else { EXEC SQL INSERT INTO Coefficients (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, dc_key, unit_in, unit_out, tf_type, lddate) VALUES (:net, :sta2, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, :Stage, :dic_key, :count_id, :count_id, 'D', SYSDATE); } break; } } factor = (int)(in_sp_rate/out_sp_rate); if (verbose) { printf ("\n\n\n\t\t+------------+"); printf ("\n\t\t| Decimation |"); printf ("\n\t\t+------------+\n"); printf ("\n Stage sequence number:\t\t%d", Stage); printf ("\n Input sample rate:\t\t%10.6E", in_sp_rate); printf ("\n Decimation factor:\t\t%d", factor); printf ("\n Decimation offset:\t\t%d", offset); printf ("\n Estimated delay (seconds):\t%10.6E", delay); printf ("\n Correction applied (seconds):\t%10.6E", correction); } EXEC SQL INSERT INTO Decimation (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, dm_key, lddate) VALUES (:net, :sta2, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, :Stage, dmseq.NEXTVAL, SYSDATE); EXEC SQL INSERT INTO DM (key, name, samprate, factor, offset, delay, correction, lddate) VALUES (dmseq.CURRVAL, NULL, :in_sp_rate, :factor, :offset, :delay, :correction, SYSDATE); gain *= fir_gain; if (verbose) { printf ("\n\n\n\t\t+--------------+"); printf ("\n\t\t| Channel Gain |"); printf ("\n\t\t+--------------+\n"); printf ("\n Stage sequence number:\t\t%d", Stage); printf ("\n Gain:\t\t\t\t%10.6E", gain); printf ("\n Frequency of gain:\t\t%10.6E HZ", frequency); printf ("\n Number of calibrations:\t%d", 0); } ogain *= gain; EXEC SQL INSERT INTO Sensitivity (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, sensitivity, frequency, lddate) VALUES (:net, :sta2, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, :Stage, :gain, :frequency, SYSDATE); Stage++; } /* Inserting final stage sensitivity information */ if (verbose) { printf ("\n\n\n\t\t+---------------------+"); printf ("\n\t\t| Channel Sensitivity |"); printf ("\n\t\t+---------------------+\n"); printf ("\n Stage sequence number:\t\t%d", 0); printf ("\n Sensitivity:\t\t\t%10.6E", ogain); printf ("\n Frequency of sensitivity:\t%10.6E HZ", rfrequency); printf ("\n Number of calibrations:\t%d\n\n\n", 0); } EXEC SQL INSERT INTO Sensitivity (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, sensitivity, frequency, lddate) VALUES (:net, :sta, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, 0, :ogain, :rfrequency, SYSDATE); } else /* Physical channel */ { EXEC SQL SELECT name INTO :unitsignal FROM D_Unit WHERE id = :unit_signal; if (ind2 != (-1)) EXEC SQL SELECT name INTO :seqfil_name FROM filter_sequence WHERE seqfil_id = :seqfil_id; else strcpy (name, ""); /* Retrieving datalogger identifier */ EXEC SQL SELECT data_id INTO :data_id FROM Station_Datalogger WHERE sta = :sta2 AND net = :net2 AND data_nb = :data_nb AND :udate >= ondate AND :udate < offdate; /* Retrieving digitizer links */ EXEC SQL SELECT digi_nb, pchannel_nb, digi_polarity, digi_channel INTO :digi_nb, :digi_pchannel_nb, :digi_polarity, :digi_rchannel_nb FROM Station_Digitizer_PChannel WHERE sta = :sta2 AND net = :net2 AND data_nb = :data_nb AND data_pchannel = :data_pchannel_nb AND :udate >= ondate AND :udate < offdate; /* Retrieving digitizer serial number */ EXEC SQL SELECT serial_nb INTO :digi_serial_nb FROM Station_Digitizer WHERE sta = :sta2 AND net = :net2 AND digi_nb = :digi_nb AND :udate >= ondate AND :udate < offdate; /* Retrieving number of filter-amplifiers */ EXEC SQL SELECT nb_filamp INTO :nb_filamp FROM Station WHERE sta = :sta2 AND net = :net2 AND :udate >= ondate AND :udate < offdate; /* Testing if filter/amplifier is present */ filamp_nb = 0; EXEC SQL SELECT filamp_nb, pchannel_nb INTO :filamp_nb, :filamp_pchannel_nb FROM Station_Filamp_PChannel WHERE sta = :sta2 AND net = :net2 AND next_hard_type = 'D' AND next_hard_nb = :digi_nb AND next_hard_pchannel = :digi_pchannel_nb AND :udate >= ondate AND :udate < offdate; /* Retrieving filter-amplifier and/or sensor information */ if (filamp_nb == 0) { EXEC SQL SELECT sensor_nb, component_nb, azimuth, dip INTO :sensor_nb, :component_nb, :azimuth, :dip FROM Station_Sensor_Component WHERE sta = :sta2 AND net = :net2 AND next_hard_type = 'D' AND next_hard_nb = :digi_nb AND next_hard_pchannel = :digi_pchannel_nb AND :udate >= ondate AND :udate < offdate; } else { EXEC SQL SELECT sensor_nb, component_nb, azimuth, dip INTO :sensor_nb, :component_nb, :azimuth, :dip FROM Station_Sensor_Component WHERE sta = :sta2 AND net = :net2 AND next_hard_type = 'F' AND next_hard_nb = :filamp_nb AND next_hard_pchannel = :filamp_pchannel_nb AND :udate >= ondate AND :udate < offdate; EXEC SQL SELECT filamp_id INTO :filamp_id FROM Station_Filamp WHERE sta = :sta2 AND net = :net2 AND filamp_nb = :filamp_nb AND :udate >= ondate AND :udate < offdate; } EXEC SQL SELECT sensor_id, lat, lon, elev, edepth INTO :sensor_id, :lat, :lon, :elev, :edepth FROM Station_Sensor WHERE sta = :sta2 AND net = :net2 AND sensor_nb = :sensor_nb AND :udate >= ondate AND :udate < offdate; Stage = 1; ogain = 1.; /* Retrieving sensor name */ EXEC SQL SELECT name INTO :sensor_name FROM Sensor WHERE sensor_id = :sensor_id; /* Trim trailing blanks */ Remove_Blank (sta2); Remove_Blank (seedchan); Remove_Blank (net); Remove_Blank (location); Remove_Blank (flags); Remove_Blank (sensor_name); Remove_Blank (unitsignal); Remove_Blank (digi_serial_nb); /* Location */ if (strlen (location) == 0) strcpy (location, " "); /* CHANNEL */ /* Retrieving datalogger type */ EXEC SQL SELECT data_type INTO :data_type FROM Datalogger WHERE data_id = :data_id; /* Retrieving station information */ EXEC SQL SELECT ondate, offdate, staname, lat, lon, elev INTO :ondate, :offdate, :staname, :slat, :slon, :selev FROM Station WHERE sta = :sta2 AND net = :net2 AND :udate >= ondate AND :udate < offdate; /* Trim trailing blanks */ Remove_Blank (data_type); Remove_Blank (data_format); Remove_Blank (ondate); Remove_Blank (offdate); /* Converting dates */ strcpy (on_date, Convert_Date (ondate)); strcpy (off_date, Convert_Date (enddate)); /* Generating Station line */ if (verbose) { printf ("\n\n ======== CHANNEL RESPONSE DATA ========"); printf ("\n Station:\t%s", sta2); printf ("\n Network:\t%s", net); printf ("\n Channel:\t%s", seedchan); printf ("\n Location:\t%s", location); printf ("\n Start date:\t%s", on_date); printf ("\n End date:\t%s", off_date); printf ("\n =======================================\n"); } /* Inserting channel information */ inid = 0; if (strlen (sensor_name) > 50) sensor_name[50] = '\0'; EXEC SQL SELECT id INTO :inid FROM D_Abbreviation WHERE description = :sensor_name; if (inid == 0) { EXEC SQL INSERT INTO D_Abbreviation (id, description) VALUES (abbseq.NEXTVAL, :sensor_name); EXEC SQL SELECT abbseq.CURRVAL INTO :inid FROM DUAL; } record_length = (int)(log2 ((double)(block_size))); if (samprate < 0) samprate = (-1.)/samprate; EXEC SQL INSERT INTO Channel_Data (net, sta, seedchan, channel, channelsrc, location, inid, remark, unit_signal, unit_calib, lat, lon, elev, edepth, azimuth, dip, format_id, record_length, samprate, clock_drift, flags, ondate, offdate, lddate) VALUES (:net, :sta2, :seedchan, :channel, :channelsrc, :location, :inid, :remark, :unit_signal, :unit_calib, :lat, :lon, :elev, :edepth, :azimuth, :dip, :comp_type, :record_length, :samprate, :clock_drift, :flags, :ondate, :enddate, SYSDATE); /* ATTR */ /* Retrieving component information */ EXEC SQL SELECT sensitivity, frequency, seqresp_id INTO :sensitivity, :frequency, :seqresp_id FROM Sensor_Component WHERE sensor_id = :sensor_id AND component_nb = :component_nb; /* Setting up new normalization frequency */ rfrequency = frequency; /* Retrieving number of responses */ EXEC SQL SELECT count(*) INTO :nb_resp FROM Response WHERE seqresp_id = :seqresp_id; /* Retrieving number of response lines */ nb_poles = 0; nb_zero = 0; pz_nb = 0; z_nb = 0; for (i=1;i<=nb_resp;i++) { EXEC SQL SELECT resp_type, resp_id INTO :resp_type, :resp_id FROM Response WHERE seqresp_id = :seqresp_id AND resp_nb = :i; switch (resp_type) { case 'H': EXEC SQL SELECT nb_pole INTO :nb_temp FROM Response_HP WHERE hp_id = :resp_id; nb_poles += nb_temp; nb_zero += nb_temp; break; case 'L': EXEC SQL SELECT nb_pole INTO :nb_temp FROM Response_LP WHERE lp_id = :resp_id; nb_poles += nb_temp; break; case 'Z': EXEC SQL SELECT count(*) INTO :nb_temp FROM Response_PZ WHERE pz_id = :resp_id AND type = 'P'; nb_poles += nb_temp; EXEC SQL SELECT count(*) INTO :nb_temp FROM Response_PZ WHERE pz_id = :resp_id AND type = 'Z'; nb_zero += nb_temp; break; case 'P': break; } } /* INSTR */ /* Generating response lines */ for (i=1;i<=nb_resp;i++) { EXEC SQL SELECT resp_type, resp_id, unit_in, unit_out, r_type INTO :resp_type, :resp_id, :unit_in, :unit_out, :r_type FROM Response WHERE seqresp_id = :seqresp_id AND resp_nb = :i; if (i == 1) { EXEC SQL SELECT Name INTO :sunit_in FROM D_Unit WHERE Id = :unit_in; EXEC SQL SELECT Name INTO :sunit_out FROM D_Unit WHERE Id = :unit_out; } switch (resp_type) { case 'H': EXEC SQL SELECT filter_type, nb_pole, corner_freq, damping_value INTO :filter_type, :nb_pole, :corner_freq, :damping_value FROM Response_HP WHERE hp_id = :resp_id; if (!strcmp (filter_type, "DG")) pz_nb = dg_filter (nb_pole, corner_freq, damping_value, pz_nb, Pole); else if (!strcmp (filter_type, "BW")) pz_nb = bw_filter (nb_pole, corner_freq, pz_nb, Pole); for (z=0;z 0) { if (verbose) printf ("\n Coefficients:"); if (verbose) printf ("\n\ti\tCoefficient\tError"); for (j=1;j<=nb_coeff;j++) { EXEC SQL SELECT pn_value INTO :pn_value:ind FROM Response_PN_Data WHERE pn_id = :resp_id AND pn_nb = :j; if (verbose) printf ("\n\t%d\t%10.6E\t%10.6E", j, pn_value, 0.); EXEC SQL INSERT INTO PN_Data (key, row_key, pn_value) VALUES (poseq.CURRVAL, :j, :pn_value); } } break; case 'N': Flag_Flat = 1; /*if (verbose) { printf ("\n\n\n\t\t+-------------------------+"); printf ("\n\t\t| Response (Coefficients) |"); printf ("\n\t\t+-------------------------+\n"); printf ("\n Transfer function type:\t%c", 'A'); printf ("\n Stage sequence number:\t\t%d", Stage); printf ("\n Response in units lookup:\t%.10s", sunit_in); printf ("\n Response out units lookup:\t%.10s", sunit_out); printf ("\n Number of numerators:\t\t%d", 0); printf ("\n Number of denominators:\t%d", 0); } EXEC SQL INSERT INTO Coefficients (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, dc_key, unit_in, unit_out, tf_type, lddate) VALUES (:net, :sta2, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, :Stage, NULL, :unit_in, :unit_out, 'A', SYSDATE);*/ if (verbose) { printf ("\n\n\n\t\t+--------------------------+"); printf ("\n\t\t| Response (Poles & Zeros) |"); printf ("\n\t\t+--------------------------+\n"); printf ("\n Transfer function type:\t%c", 'A'); printf ("\n Stage sequence number:\t\t%d", Stage); printf ("\n Response in units lookup:\t%.10s", sunit_in); printf ("\n Response out units lookup:\t%.10s", sunit_out); printf ("\n A0 normalization factor:\t%8.6f", 1.); printf ("\n Normalization frequency:\t%.3f", 0.); printf ("\n Number of zeroes:\t\t%d", 0); printf ("\n Number of poles:\t\t%d", 0); } /* Inserting P&Z information */ EXEC SQL INSERT INTO Poles_Zeros (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, pz_key, tf_type, unit_in, unit_out, AO, AF, lddate) VALUES (:net, :sta, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, :Stage, pzseq.NEXTVAL, 'A', :unit_in, :unit_out, 1., 0., SYSDATE); EXEC SQL INSERT INTO PZ (key, name, lddate) VALUES (pzseq.CURRVAL, NULL, SYSDATE); if (verbose) { printf ("\n\n\n\t\t+--------------+"); printf ("\n\t\t| Channel Gain |"); printf ("\n\t\t+--------------+\n"); printf ("\n Stage sequence number:\t\t%d", Stage); printf ("\n Gain:\t\t\t\t%10.6E", sensitivity); printf ("\n Frequency of gain:\t\t%10.6E HZ", frequency); printf ("\n Number of calibrations:\t%d", 0); } ogain *= sensitivity; EXEC SQL INSERT INTO Sensitivity (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, sensitivity, frequency, lddate) VALUES (:net, :sta2, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, :Stage, :sensitivity, :frequency, SYSDATE); break; } } if ((Flag_Poly == 0) && (Flag_Flat == 0)) { compute_A0_Sd (sensitivity, frequency, rfrequency, &A0, &Sd, Pole, Zero, nb_poles, nb_zero); if (verbose) { printf ("\n\n\n\t\t+--------------------------+"); printf ("\n\t\t| Response (Poles & Zeros) |"); printf ("\n\t\t+--------------------------+\n"); printf ("\n Transfer function type:\t%c", r_type); printf ("\n Stage sequence number:\t\t%d", Stage); printf ("\n Response in units lookup:\t%.10s", sunit_in); printf ("\n Response out units lookup:\t%.10s", sunit_out); printf ("\n A0 normalization factor:\t%8.6f", A0); printf ("\n Normalization frequency:\t%.3f", frequency); printf ("\n Number of zeroes:\t\t%d", nb_zero); printf ("\n Number of poles:\t\t%d", nb_poles); } /* Inserting P&Z information */ EXEC SQL INSERT INTO Poles_Zeros (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, pz_key, tf_type, unit_in, unit_out, AO, AF, lddate) VALUES (:net, :sta2, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, :Stage, pzseq.NEXTVAL, :r_type, :unit_in, :unit_out, :A0, :frequency, SYSDATE); EXEC SQL INSERT INTO PZ (key, name, lddate) VALUES (pzseq.CURRVAL, NULL, SYSDATE); if (nb_zero > 0) { if (verbose) printf ("\n Complex zeroes:"); if (verbose) printf ("\n\ti\treal\t\timag\t\treal_error\timag_error"); for (z=0;z 0) { if (verbose) printf ("\n Complex poles:"); if (verbose) printf ("\n\ti\treal\t\timag\t\treal_error\timag_error"); for (z=0;z 0) { if (verbose) printf ("\n Complex zeroes:"); if (verbose) printf ("\n\ti\treal\t\timag\t\treal_error\timag_error"); for (z=0;z 0) { if (verbose) printf ("\n Complex poles:"); if (verbose) printf ("\n\ti\treal\t\timag\t\treal_error\timag_error"); for (z=0;z 0) { if (verbose) printf ("\n Complex zeroes:"); if (verbose) printf ("\n\ti\treal\t\timag\t\treal_error\timag_error"); for (z=0;z 0) { if (verbose) printf ("\n Complex poles:"); if (verbose) printf ("\n\ti\treal\t\timag\t\treal_error\timag_error"); for (z=0;z 0) { if (verbose) printf ("\n Complex poles:"); if (verbose) printf ("\n\ti\treal\t\timag\t\treal_error\timag_error"); for (z=0;z 0) { if (verbose) printf ("\n Numerator coefficients:"); if (verbose) printf ("\n i\tcoefficient\terror"); for (z=1;z<=nb_fir_coeff;z++) { EXEC SQL SELECT coefficient, error INTO :fir_coeff, :fir_error:ind FROM Filter_FIR_Data WHERE fir_id = :resp_id AND coeff_nb = :z; if (verbose) printf ("\n %d\t%10.6E\t%10.6E", z, fir_coeff, fir_error); EXEC SQL INSERT INTO DC_Data (key, row_key, type, coefficient, error) VALUES (dcseq.CURRVAL, :z, 'N', :fir_coeff, :fir_error); } } } else { EXEC SQL INSERT INTO Coefficients (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, dc_key, unit_in, unit_out, tf_type, lddate) VALUES (:net, :sta2, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, :Stage, :dic_key, :count_id, :count_id, 'D', SYSDATE); } break; } } factor = (int)(in_sp_rate/out_sp_rate); if (verbose) { printf ("\n\n\n\t\t+------------+"); printf ("\n\t\t| Decimation |"); printf ("\n\t\t+------------+\n"); printf ("\n Stage sequence number:\t\t%d", Stage); printf ("\n Input sample rate:\t\t%10.6E", in_sp_rate); printf ("\n Decimation factor:\t\t%d", factor); printf ("\n Decimation offset:\t\t%d", offset); printf ("\n Estimated delay (seconds):\t%10.6E", delay); printf ("\n Correction applied (seconds):\t%10.6E", correction); } EXEC SQL INSERT INTO Decimation (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, dm_key, lddate) VALUES (:net, :sta2, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, :Stage, dmseq.NEXTVAL, SYSDATE); EXEC SQL INSERT INTO DM (key, name, samprate, factor, offset, delay, correction, lddate) VALUES (dmseq.CURRVAL, NULL, :in_sp_rate, :factor, :offset, :delay, :correction, SYSDATE); gain *= fir_gain; if (verbose) { printf ("\n\n\n\t\t+--------------+"); printf ("\n\t\t| Channel Gain |"); printf ("\n\t\t+--------------+\n"); printf ("\n Stage sequence number:\t\t%d", Stage); printf ("\n Gain:\t\t\t\t%10.6E", gain); printf ("\n Frequency of gain:\t\t%10.6E HZ", frequency); printf ("\n Number of calibrations:\t%d", 0); } ogain *= gain; EXEC SQL INSERT INTO Sensitivity (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, sensitivity, frequency, lddate) VALUES (:net, :sta2, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, :Stage, :gain, :frequency, SYSDATE); Stage++; } /* Retrieving gain information */ gain = 1.; frequency = 0.; EXEC SQL SELECT gain, frequency INTO :gain:ind, :frequency:ind FROM Filter_Sequence WHERE seqfil_id = :seqfil_id; /* GAIN */ /* END */ /* Computing gain */ if (rgain != 0.) gain = rgain; else gain = ogain; /* Digitizer polarity */ if (digi_polarity != 'N') gain *= (-1.); if (Flag_Poly == 1) { EXEC SQL SELECT name, poly_type, lower_bound, upper_bound, max_error, nb_coeff INTO :polyname, :poly_type, :lower_bound, :upper_bound, :max_error, :nb_coeff FROM Response_PN WHERE pn_id = :poid; /* POLY */ strcpy (psunit_out, "COUNTS"); EXEC SQL SELECT id INTO :punit_out FROM D_Unit WHERE name = :psunit_out; if (verbose) { printf ("\n\n\n\t\t+-----------------------+"); printf ("\n\t\t| Response (Polynomial) |"); printf ("\n\t\t+-----------------------+\n"); printf ("\n Polynomial name:\t\t%s", polyname); printf ("\n Transfer function type:\t%c", 'P'); printf ("\n Stage sequence number:\t\t%d", 0); printf ("\n Response in units lookup:\t%.10s", psunit_in); printf ("\n Response out units lookup:\t%.10s", psunit_out); printf ("\n Polynomial approximation type:\t%c", poly_type); printf ("\n Lower bound of approximation:\t%10.6E", lower_bound); printf ("\n Upper bound of approximation:\t%10.6E", upper_bound); printf ("\n Maximum absolute error:\t%10.6E", max_error); printf ("\n Number of coefficients:\t%d", nb_coeff); } EXEC SQL INSERT INTO Polynomial (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, pn_key, unit_in, unit_out, tf_type, lddate) VALUES (:net, :sta2, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, 0, poseq.NEXTVAL, :punit_in, :punit_out, 'P', SYSDATE); EXEC SQL INSERT INTO PN (key, name, poly_type, lower_bound, upper_bound, max_error, lddate) VALUES (poseq.CURRVAL, :polyname, :poly_type, :lower_bound, :upper_bound, :max_error, SYSDATE); if (nb_coeff > 0) { if (verbose) printf ("\n Coefficients:"); if (verbose) printf ("\n\ti\tCoefficient\tError"); for (j=1;j<=nb_coeff;j++) { EXEC SQL SELECT pn_value INTO :pn_value:ind FROM Response_PN_Data WHERE pn_id = :poid AND pn_nb = :j; pn_value /= pow(gain, j-1); if (verbose) printf ("\n\t%d\t%10.6E\t%10.6E", j, pn_value, 0.); EXEC SQL INSERT INTO PN_Data (key, row_key, pn_value) VALUES (poseq.CURRVAL, :j, :pn_value); } } printf ("\n\n\n"); } else { if (verbose) { printf ("\n\n\n\t\t+---------------------+"); printf ("\n\t\t| Channel Sensitivity |"); printf ("\n\t\t+---------------------+\n"); printf ("\n Stage sequence number:\t\t%d", 0); printf ("\n Sensitivity:\t\t\t%10.6E", gain); printf ("\n Frequency of sensitivity:\t%10.6E HZ", rfrequency); printf ("\n Number of calibrations:\t%d\n\n\n", 0); } EXEC SQL INSERT INTO Sensitivity (net, sta, seedchan, channel, channelsrc, location, ondate, offdate, stage_seq, sensitivity, frequency, lddate) VALUES (:net, :sta2, :seedchan, :channel, :channelsrc, :location, :ondate, :enddate, 0, :gain, :rfrequency, SYSDATE); } } EXEC SQL FETCH chan_cursor INTO :sta:ind, :net:ind, :data_nb:ind, :data_pchannel_nb:ind, :lchannel_nb:ind, :seqfil_id:ind2, :seedchan:ind, :channel:ind, :channelsrc:ind, :location:ind, :rgain:ind, :rfrequency:ind, :samprate:ind, :clock_drift:ind, :flags:ind, :data_format:ind, :comp_type:ind, :unit_signal:ind, :unit_calib:ind, :block_size:ind, :remark:indremark, :ondate:ind, :offdate:ind; } EXEC SQL CLOSE chan_cursor; } /************************************************************************/ /* Store_Channel_IR: */ /* Function to store a channel response into a string. */ /************************************************************************/ void Store_Channel_IR ( char psta[7], /* Station code */ char pnet[9], /* Network code */ char pcha[7], /* SEED channel name */ char ploc[3], /* Location code */ char pdate[32], /* Date of interest */ char *cha_ir) /* Response String */ { DCOMPLEX Pole[128]; DCOMPLEX Zero[128]; char *c_tmp; int Flag_Poly = 0; int Flag_Flat = 0; char channel_type; char stmp[255]; /* Response Initialization */ strcpy (cha_ir, ""); /* Location code */ if ((!strcmp (ploc, "-")) || (!strcmp (ploc, "--"))) strcpy (ploc, " "); /* Initializing stage sequence number and overall gain */ Stage = 1; ogain = 1.; /* Retrieving station information */ strcpy (udate, pdate); strcpy (sta2, psta); strcpy (net2, pnet); strcpy (cha, pcha); strcpy (loc, ploc); EXEC SQL DECLARE chan_cursor2 CURSOR FOR SELECT sta, net, data_nb, pchannel_nb, lchannel_nb, seqfil_id, seedchan, channel, channelsrc, location, rgain, rfrequency, samprate, clock_drift, flags, data_format, comp_type, unit_signal, unit_calib, block_size, remark, ondate, offdate FROM Station_Datalogger_LChannel WHERE sta = :sta2 AND net = :net2 AND seedchan = :cha AND location = :loc AND :udate >= ondate AND :udate < offdate ORDER BY pchannel_nb, lchannel_nb; EXEC SQL OPEN chan_cursor2; strcpy (remark, ""); EXEC SQL FETCH chan_cursor2 INTO :sta:ind, :net:ind, :data_nb:ind, :data_pchannel_nb:ind, :lchannel_nb:ind, :seqfil_id:ind2, :seedchan:ind, :channel:ind, :channelsrc:ind, :location:ind, :rgain:ind, :rfrequency:ind, :samprate:ind, :clock_drift:ind, :flags:ind, :data_format:ind, :comp_type:ind, :unit_signal:ind, :unit_calib:ind, :block_size:ind, :remark:indremark, :ondate:ind, :offdate:ind; while (sqlca.sqlcode != NOMOREROWS) { Flag_Poly = 0; Flag_Flat = 0; Remove_Blank (sta); Remove_Blank (net); Remove_Blank (seedchan); Remove_Blank (channel); Remove_Blank (channelsrc); Remove_Blank (flags); if (indremark == (-1)) strcpy (remark, ""); else Remove_Blank (remark); Remove_Blank (location); /* Location */ if (strlen (location) == 0) strcpy (location, " "); /* Retrieving channel type */ EXEC SQL SELECT channel_type INTO :channel_type FROM Station_Datalogger_PChannel WHERE sta = :sta AND net = :net AND data_nb = :data_nb AND pchannel_nb = :data_pchannel_nb AND :udate >= ondate AND :udate < offdate; /* Synthetic channel */ if (channel_type == 'S') { ogain = 1.; /* Converting dates */ strcpy (on_date, Convert_Date (ondate)); strcpy (off_date, Convert_Date (offdate)); sprintf (stmp, "\n%s", sta);strcat (cha_ir, stmp); sprintf (stmp, "\n%s", net);strcat (cha_ir, stmp); sprintf (stmp, "\n%s", seedchan);strcat (cha_ir, stmp); sprintf (stmp, "\n%s", location);strcat (cha_ir, stmp); sprintf (stmp, "\n%d", comp_type);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", lat);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", lon);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", elev);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", edepth);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", azimuth);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", dip);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", clock_drift);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", samprate);strcat (cha_ir, stmp); sprintf (stmp, "\n%s", flags);strcat (cha_ir, stmp); sprintf (stmp, "\n%d", block_size);strcat (cha_ir, stmp); sprintf (stmp, "\n%s", remark);strcat (cha_ir, stmp); /* Inserting poles & zeros information */ r_type = 'D'; Stage = 1; A0 = 1.; EXEC SQL SELECT name INTO :unitsignal FROM D_Unit WHERE id = :unit_signal; sprintf (stmp, "\n%c", r_type);strcat (cha_ir, stmp); sprintf (stmp, "\n%d", Stage);strcat (cha_ir, stmp); sprintf (stmp, "\n%.10s", unitsignal);strcat (cha_ir, stmp); sprintf (stmp, "\n%.10s", unitsignal);strcat (cha_ir, stmp); sprintf (stmp, "\n%8.6f", A0);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", rfrequency);strcat (cha_ir, stmp); sprintf (stmp, "\n%d", 0);strcat (cha_ir, stmp); sprintf (stmp, "\n%d", 0);strcat (cha_ir, stmp); /* Inserting gain information */ gain = 1.; sprintf (stmp, "\n%d", Stage);strcat (cha_ir, stmp); sprintf (stmp, "\n%10.6E", gain);strcat (cha_ir, stmp); sprintf (stmp, "\n%10.6E HZ", rfrequency);strcat (cha_ir, stmp); sprintf (stmp, "\n%d", 0);strcat (cha_ir, stmp); /* Retrieving number of filters */ Stage++; if (ind2 != (-1)) { EXEC SQL SELECT nb_filter INTO :nb_filter FROM Filter_Sequence WHERE seqfil_id = :seqfil_id; } else nb_filter = 0; for (j=1;j<=nb_filter;j++) { EXEC SQL SELECT gain, frequency, in_sp_rate, out_sp_rate, offset, delay, correction, seqresp_id INTO :gain, :frequency, :in_sp_rate, :out_sp_rate, :offset, :delay, :correction, :seqresp_id FROM Filter WHERE filter_id = (SELECT filter_id FROM Filter_Sequence_Data WHERE seqfil_id = :seqfil_id AND filter_nb = :j); fir_gain = 1.; /* Retrieving number of responses */ EXEC SQL SELECT count(*) INTO :nb_resp FROM Response WHERE seqresp_id = :seqresp_id; /* DFILTER */ /* INPUT */ /* DELAY */ /* Generating response lines */ for (i=1;i<=nb_resp;i++) { EXEC SQL SELECT resp_type, resp_id, unit_in, unit_out, r_type INTO :resp_type, :resp_id, :unit_in, :unit_out, :r_type FROM Response WHERE seqresp_id = :seqresp_id AND resp_nb = :i; switch (resp_type) { case 'H': printf ("\n Error: Found HP response in DFILTER.\n"); break; case 'L': printf ("\n Error: Found LP response in DFILTER.\n"); break; case 'Z': printf ("\n Error: Found PZ response in DFILTER.\n"); break; case 'P': printf ("\n Error: Found PN response in DFILTER.\n"); break; case 'F': EXEC SQL SELECT name, symmetry, gain INTO :name, :symmetry, :fir_gain FROM Filter_FIR WHERE fir_id = :resp_id; Remove_Blank (name); /* FIR */ EXEC SQL SELECT count(*) INTO :nb_fir_coeff FROM Filter_FIR_Data WHERE fir_id = :resp_id; sprintf (stmp, "\n%s", name);strcat (cha_ir, stmp); sprintf (stmp, "\n%d", Stage);strcat (cha_ir, stmp); sprintf (stmp, "\n%d", nb_fir_coeff);strcat (cha_ir, stmp); break; } } factor = (int)(in_sp_rate/out_sp_rate); sprintf (stmp, "\n%d", Stage);strcat (cha_ir, stmp); sprintf (stmp, "\n%10.6E", in_sp_rate);strcat (cha_ir, stmp); sprintf (stmp, "\n%d", factor);strcat (cha_ir, stmp); sprintf (stmp, "\n%d", offset);strcat (cha_ir, stmp); sprintf (stmp, "\n%10.6E", delay);strcat (cha_ir, stmp); sprintf (stmp, "\n%10.6E", correction);strcat (cha_ir, stmp); gain *= fir_gain; sprintf (stmp, "\n%d", Stage);strcat (cha_ir, stmp); sprintf (stmp, "\n%10.6E", gain);strcat (cha_ir, stmp); sprintf (stmp, "\n%10.6E HZ", frequency);strcat (cha_ir, stmp); sprintf (stmp, "\n%d", 0);strcat (cha_ir, stmp); ogain *= gain; Stage++; } /* Inserting final stage sensitivity information */ sprintf (stmp, "\n%d", 0);strcat (cha_ir, stmp); sprintf (stmp, "\n%10.6E", ogain);strcat (cha_ir, stmp); sprintf (stmp, "\n%10.6E HZ", rfrequency);strcat (cha_ir, stmp); } else /* Physical channel */ { EXEC SQL SELECT name INTO :unitsignal FROM D_Unit WHERE id = :unit_signal; if (ind2 != (-1)) EXEC SQL SELECT name INTO :seqfil_name FROM filter_sequence WHERE seqfil_id = :seqfil_id; else strcpy (name, ""); /* Retrieving datalogger identifier */ EXEC SQL SELECT data_id INTO :data_id FROM Station_Datalogger WHERE sta = :sta2 AND net = :net2 AND data_nb = :data_nb AND :udate >= ondate AND :udate < offdate; /* Retrieving digitizer links */ EXEC SQL SELECT digi_nb, pchannel_nb, digi_polarity, digi_channel INTO :digi_nb, :digi_pchannel_nb, :digi_polarity, :digi_rchannel_nb FROM Station_Digitizer_PChannel WHERE sta = :sta2 AND net = :net2 AND data_nb = :data_nb AND data_pchannel = :data_pchannel_nb AND :udate >= ondate AND :udate < offdate; /* Retrieving digitizer serial number */ EXEC SQL SELECT serial_nb INTO :digi_serial_nb FROM Station_Digitizer WHERE sta = :sta2 AND net = :net2 AND digi_nb = :digi_nb AND :udate >= ondate AND :udate < offdate; /* Retrieving number of filter-amplifiers */ EXEC SQL SELECT nb_filamp INTO :nb_filamp FROM Station WHERE sta = :sta2 AND net = :net2 AND :udate >= ondate AND :udate < offdate; /* Testing if filter/amplifier is present */ filamp_nb = 0; EXEC SQL SELECT filamp_nb, pchannel_nb INTO :filamp_nb, :filamp_pchannel_nb FROM Station_Filamp_PChannel WHERE sta = :sta2 AND net = :net2 AND next_hard_type = 'D' AND next_hard_nb = :digi_nb AND next_hard_pchannel = :digi_pchannel_nb AND :udate >= ondate AND :udate < offdate; /* Retrieving filter-amplifier and/or sensor information */ if (filamp_nb == 0) { EXEC SQL SELECT sensor_nb, component_nb, azimuth, dip INTO :sensor_nb, :component_nb, :azimuth, :dip FROM Station_Sensor_Component WHERE sta = :sta2 AND net = :net2 AND next_hard_type = 'D' AND next_hard_nb = :digi_nb AND next_hard_pchannel = :digi_pchannel_nb AND :udate >= ondate AND :udate < offdate; } else { EXEC SQL SELECT sensor_nb, component_nb, azimuth, dip INTO :sensor_nb, :component_nb, :azimuth, :dip FROM Station_Sensor_Component WHERE sta = :sta2 AND net = :net2 AND next_hard_type = 'F' AND next_hard_nb = :filamp_nb AND next_hard_pchannel = :filamp_pchannel_nb AND :udate >= ondate AND :udate < offdate; EXEC SQL SELECT filamp_id INTO :filamp_id FROM Station_Filamp WHERE sta = :sta2 AND net = :net2 AND filamp_nb = :filamp_nb AND :udate >= ondate AND :udate < offdate; } EXEC SQL SELECT sensor_id, lat, lon, elev, edepth INTO :sensor_id, :lat, :lon, :elev, :edepth FROM Station_Sensor WHERE sta = :sta2 AND net = :net2 AND sensor_nb = :sensor_nb AND :udate >= ondate AND :udate < offdate; Stage = 1; ogain = 1.; /* Retrieving sensor name */ EXEC SQL SELECT name INTO :sensor_name FROM Sensor WHERE sensor_id = :sensor_id; /* Trim trailing blanks */ Remove_Blank (sta2); Remove_Blank (seedchan); Remove_Blank (net); Remove_Blank (location); Remove_Blank (flags); Remove_Blank (sensor_name); Remove_Blank (unitsignal); Remove_Blank (digi_serial_nb); /* Location */ if (strlen (location) == 0) strcpy (location, " "); /* CHANNEL */ /* Retrieving datalogger type */ EXEC SQL SELECT data_type INTO :data_type FROM Datalogger WHERE data_id = :data_id; /* Retrieving station information */ EXEC SQL SELECT ondate, offdate, staname, lat, lon, elev INTO :ondate, :offdate, :staname, :slat, :slon, :selev FROM Station WHERE sta = :sta2 AND net = :net2 AND :udate >= ondate AND :udate < offdate; /* Trim trailing blanks */ Remove_Blank (data_type); Remove_Blank (data_format); Remove_Blank (ondate); Remove_Blank (offdate); /* Converting dates */ strcpy (on_date, Convert_Date (ondate)); strcpy (off_date, Convert_Date (offdate)); sprintf (stmp, "\n%s", sta2);strcat (cha_ir, stmp); sprintf (stmp, "\n%s", net);strcat (cha_ir, stmp); sprintf (stmp, "\n%s", seedchan);strcat (cha_ir, stmp); sprintf (stmp, "\n%s", location);strcat (cha_ir, stmp); sprintf (stmp, "\n%s", sensor_name);strcat (cha_ir, stmp); sprintf (stmp, "\n%d", comp_type);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", lat);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", lon);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", elev);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", edepth);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", azimuth);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", dip);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", clock_drift);strcat (cha_ir, stmp); sprintf (stmp, "\n%.3f", samprate);strcat (cha_ir, stmp); sprintf (stmp, "\n%s", flags);strcat (cha_ir, stmp); sprintf (stmp, "\n%s", unitsignal);strcat (cha_ir, stmp); sprintf (stmp, "\n%d", block_size);strcat (cha_ir, stmp); sprintf (stmp, "\n%s", remark);strcat (cha_ir, stmp); /* ATTR */ /* Retrieving component information */ EXEC SQL SELECT sensitivity, frequency, seqresp_id INTO :sensitivity, :frequency, :seqresp_id FROM Sensor_Component WHERE sensor_id = :sensor_id AND component_nb = :component_nb; /* Setting up new normalization frequency */ rfrequency = frequency; /* Retrieving number of responses */ EXEC SQL SELECT count(*) INTO :nb_resp FROM Response WHERE seqresp_id = :seqresp_id; /* Retrieving number of response lines */ nb_poles = 0; nb_zero = 0; pz_nb = 0; z_nb = 0; for (i=1;i<=nb_resp;i++) { EXEC SQL SELECT resp_type, resp_id INTO :resp_type, :resp_id FROM Response WHERE seqresp_id = :seqresp_id AND resp_nb = :i; switch (resp_type) { case 'H': EXEC SQL SELECT nb_pole INTO :nb_temp FROM Response_HP WHERE hp_id = :resp_id; nb_poles += nb_temp; nb_zero += nb_temp; break; case 'L': EXEC SQL SELECT nb_pole INTO :nb_temp FROM Response_LP WHERE lp_id = :resp_id; nb_poles += nb_temp; break; case 'Z': EXEC SQL SELECT count(*) INTO :nb_temp FROM Response_PZ WHERE pz_id = :resp_id AND type = 'P'; nb_poles += nb_temp; EXEC SQL SELECT count(*) INTO :nb_temp FROM Response_PZ WHERE pz_id = :resp_id AND type = 'Z'; nb_zero += nb_temp; break; case 'P': break; } } /* INSTR */ /* Generating response lines */ for (i=1;i<=nb_resp;i++) { EXEC SQL SELECT resp_type, resp_id, unit_in, unit_out, r_type INTO :resp_type, :resp_id, :unit_in, :unit_out, :r_type FROM Response WHERE seqresp_id = :seqresp_id AND resp_nb = :i; if (i == 1) { EXEC SQL SELECT Name INTO :sunit_in FROM D_Unit WHERE Id = :unit_in; EXEC SQL SELECT Name INTO :sunit_out FROM D_Unit WHERE Id = :unit_out; } switch (resp_type) { case 'H': EXEC SQL SELECT filter_type, nb_pole, corner_freq, damping_value INTO :filter_type, :nb_pole, :corner_freq, :damping_value FROM Response_HP WHERE hp_id = :resp_id; if (!strcmp (filter_type, "DG")) pz_nb = dg_filter (nb_pole, corner_freq, damping_value, pz_nb, Pole); else if (!strcmp (filter_type, "BW")) pz_nb = bw_filter (nb_pole, corner_freq, pz_nb, Pole); for (z=0;z 0) { for (z=0;z 0) { for (z=0;z 0) { for (z=0;z 0) { for (z=0;z 0) { for (z=0;z 0) { for (z=0;z 0) { for (z=0;z %s\n", tabondate[0], taboffdate[0]); printf ("\n Calling Generate_Sta [%s, %s, %s, %s, %d]\n", sta2, net2, tabondate[0], taboffdate[0], Flag_Ver); } Generate_Sta (sta2, net2, tabondate[0], taboffdate[0], Flag_Ver); } else { /* Retrieving Channel Responses */ for (z=0;z %s] & [%s --> %s] ARE", sta2, net2, tabondate[z], taboffdate[z], tabondate[z+1], taboffdate[z+1]); if (((l = strlen (tabsta[z])) != strlen (tabsta[z+1])) || (strcmp (taboffdate[z], tabondate[z+1]))) { if (Flag_Ver) { printf (" DIFFERENT!\n"); /*printf ("---\n%s---\n%s---\n", tabsta[z], tabsta[z+1]);*/ printf ("\n Populating station for time interval %s --> %s\n", condate, taboffdate[z]); printf ("\n Calling Generate_Sta [%s, %s, %s, %s, %d]\n", sta2, net2, condate, taboffdate[z], Flag_Ver); } Generate_Sta (sta2, net2, condate, taboffdate[z], Flag_Ver); strcpy (condate, tabondate[z+1]); } else { if (memcmp (stabir[z], stabir[z+1], l) != 0) { if (Flag_Ver) { printf (" DIFFERENT!\n"); /*printf ("---\n%s---\n%s---\n", tabsta[z], tabsta[z+1]);*/ printf ("\n Populating station for time interval %s --> %s\n", condate, taboffdate[z]); printf ("\n Calling Generate_IR [%s, %s, %s, %s, %d]\n", sta2, net2, condate, taboffdate[z], Flag_Ver); } Generate_Sta (sta2, net2, condate, taboffdate[z], Flag_Ver); strcpy (condate, tabondate[z+1]); } else { if (Flag_Ver) printf (" IDENTICAL!\n"); } } } /* Populating Last Time Span */ if (Flag_Ver) { printf ("\n Populating station for time interval %s --> %s\n", condate, taboffdate[nbt-1]); printf ("\n Calling Generate_Sta [%s, %s, %s, %s, %d]\n", sta2, net2, condate, taboffdate[nbt-1], Flag_Ver); } Generate_Sta (sta2, net2, condate, taboffdate[nbt-1], Flag_Ver); } /* Retrieving channel codes */ EXEC SQL DECLARE cha_cursor CURSOR FOR SELECT distinct seedchan, location FROM Station_Datalogger_LChannel WHERE sta = :sta2 AND net = :net2; EXEC SQL OPEN cha_cursor; EXEC SQL FETCH cha_cursor INTO :seedchan, :location; while (sqlca.sqlcode != NOMOREROWS) { nbct = 0; Remove_Blank (seedchan); Remove_Blank (location); if (!strcmp (location, "")) strcpy (location, " "); if (nbt > 1) { /* Retrieving Channel Responses */ for (z=0;z 1) { strcpy (condate, ctabondate[0]); for (z=0;z %s] & [%s --> %s] ARE", sta2, net2, seedchan, location, ctabondate[z], ctaboffdate[z], ctabondate[z+1], ctaboffdate[z+1]); if (((l = strlen (ctabir[z])) != strlen (ctabir[z+1])) || (strcmp (ctaboffdate[z], ctabondate[z+1]))) { if (Flag_Ver) { printf (" DIFFERENT!\n"); /*printf ("---\n%s---\n%s---\n", ctabir[z], ctabir[z+1]);*/ printf ("\n Populating response for time interval %s --> %s\n", condate, ctaboffdate[z]); printf ("\n Calling Generate_IR [%s, %s, %s, %s, %s, %s, %d]\n", sta2, net2, cha, loc, condate, ctaboffdate[z], Flag_Ver); } Generate_IR (sta2, net2, seedchan, location, condate, ctaboffdate[z], Flag_Ver); strcpy (condate, ctabondate[z+1]); } else { if (memcmp (ctabir[z], ctabir[z+1], l) != 0) { if (Flag_Ver) { printf (" DIFFERENT!\n"); /*printf ("---\n%s---\n%s---\n", ctabir[z], ctabir[z+1]);*/ printf ("\n Populating response for time interval %s --> %s\n", condate, ctaboffdate[z]); printf ("\n Calling Generate_IR [%s, %s, %s, %s, %s, %s, %d]\n", sta2, net2, cha, loc, condate, ctaboffdate[z], Flag_Ver); } Generate_IR (sta2, net2, seedchan, location, condate, ctaboffdate[z], Flag_Ver); strcpy (condate, ctabondate[z+1]); } else { if (Flag_Ver) printf (" IDENTICAL!\n"); } } } /* Populating Last Time Span */ if (Flag_Ver) { printf ("\n Populating response for time interval %s --> %s\n", condate, ctaboffdate[nbct-1]); printf ("\n Calling Generate_IR [%s, %s, %s, %s, %s, %s, %d]\n", sta2, net2, cha, loc, condate, ctaboffdate[nbct-1], Flag_Ver); } Generate_IR (sta2, net2, seedchan, location, condate, ctaboffdate[nbct-1], Flag_Ver); } else { if (Flag_Ver) { printf ("\n Populating response for time interval %s --> %s\n", ctabondate[0], ctaboffdate[0]); printf ("\n Calling Generate_IR [%s, %s, %s, %s, %s, %s, %d]\n", sta2, net2, cha, loc, ctabondate[0], ctaboffdate[0], Flag_Ver); } Generate_IR (sta2, net2, seedchan, location, ctabondate[0], ctaboffdate[0], Flag_Ver); } } else if (nbt == 1) { if (Flag_Ver) { printf ("\n Populating response for time interval %s --> %s\n", tabondate[0], taboffdate[0]); printf ("\n Calling Generate_IR [%s, %s, %s, %s, %s, %s, %d]\n", sta2, net2, cha, loc, tabondate[0], taboffdate[0], Flag_Ver); } Generate_IR (sta2, net2, seedchan, location, tabondate[0], taboffdate[0], Flag_Ver); } else { printf ("Error: Number of time interval(s) is %d.\n", nbt); exit (0); } EXEC SQL FETCH cha_cursor INTO :seedchan, :location; } EXEC SQL CLOSE cha_cursor; /* Disconnect from the database. */ EXEC SQL COMMIT WORK RELEASE; exit(0); }