/************************************************************************/ /* 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). /************************************************************************/ #ifndef lint static char sccsid[] = "%W% %G% %U%"; #endif #include #include #include #include #include #include "complex.h" 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 "2.0" #define info stdout char *syntax[] = { "%s version " VERSION " -- Populates the IR schema from the HT schema.", "%s [-S station] [-C channel] [-L location] [-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.", " -C channel Specifies a SEED channel name.", " -L location Specifies a SEED location code.", 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 comptype[81]; /* Compression type identifier */ 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 */ 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 */ 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. */ /* Then recompute A0 at that 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; 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; } 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_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 */ int verbose) /* Verbose mode */ { DCOMPLEX Pole[128]; DCOMPLEX Zero[128]; char *c_tmp; int Flag_Sta = 0; int Flag_Poly = 0; int Flag_Flat = 0; int Flag = 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); /* Connect to the database */ EXEC SQL WHENEVER SQLERROR DO sql_error(); strcpy (user_pwd, CONNECT_STRING); EXEC SQL CONNECT :user_pwd; 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 station at this date (%s -- %s -- %s).\n\n", udate, sta2, net2); 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 :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); /* Testing channel/location */ if ((strlen (cha) == 0) && (strlen (loc) == 0)) Flag = 0; else if ((strlen (cha) != 0) && (strlen (loc) == 0)) { if (strcmp (seedchan, cha)) Flag = 1; else Flag = 0; } else if ((strlen (loc) != 0) && (strlen (cha) == 0)) { if (strcmp (location, loc)) Flag = 1; else Flag = 0; } else { if ((strcmp (seedchan, cha)) || (strcmp (location, loc))) Flag = 1; else Flag = 0; } Remove_Blank (location); /* Location */ if (strlen (location) == 0) strcpy (location, " "); if (Flag == 0) { /* 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)); 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; /* Populating Station_Data table */ if (Flag_Sta == 0) { Flag_Sta = 1; /* Inserting station information */ word_16 = 10; word_32 = 3210; net_id = -1; if (!strcmp (net, "BK")) strcpy (net_tmp, "BDSN"); else strcpy (net_tmp, net); 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 (:net, :sta, :slat, :slon, :selev, :staname, :net_id, :word_32, :word_16, :ondate, :offdate, SYSDATE); } /* 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, :offdate, 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, :offdate, :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, :offdate, :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, :offdate, :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, :offdate, :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, :offdate, :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, :offdate, :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, :offdate, 0, :ogain, :rfrequency, SYSDATE); } else /* Physical channel */ { EXEC SQL SELECT name INTO :unitsignal FROM D_Unit WHERE id = :unit_signal; EXEC SQL SELECT description INTO :comptype FROM D_Abbreviation WHERE id = :comp_type; 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 (comptype); Remove_Blank (ondate); Remove_Blank (offdate); /* Converting dates */ strcpy (on_date, Convert_Date (ondate)); strcpy (off_date, Convert_Date (offdate)); /* 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"); } /* Populating Station_Data table */ if (Flag_Sta == 0) { Flag_Sta = 1; /* Inserting station information */ word_16 = 10; word_32 = 3210; net_id = -1; if (!strcmp (net, "BK")) strcpy (net_tmp, "BDSN"); else strcpy (net_tmp, net); 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 (:net, :sta2, :slat, :slon, :selev, :staname, :net_id, :word_32, :word_16, :ondate, :offdate, SYSDATE); } /* Inserting channel information */ inid = 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, :offdate, 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; /* 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); } } } else { 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, :offdate, :Stage, :poid, :unit_in, :unit_out, :r_type, SYSDATE); } 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, :offdate, :Stage, NULL, :unit_in, :unit_out, 'A', 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, :offdate, :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", rfrequency); 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, :offdate, :Stage, pzseq.NEXTVAL, :r_type, :unit_in, :unit_out, :A0, :rfrequency, 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, :offdate, :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, :offdate, :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, :offdate, :Stage, :gain, :frequency, SYSDATE); Stage++; } /* Retrieving gain information */ EXEC SQL SELECT gain, frequency INTO :gain, :frequency 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 == 0) { 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, :offdate, 0, :gain, :rfrequency, SYSDATE); } } EXEC SQL COMMIT; } 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; EXEC SQL COMMIT WORK RELEASE; } /************************************************************************/ /* sql_error: /* Handle errors. Exit on any error. /************************************************************************/ void sql_error() { char msg[512]; size_t buf_len, msg_len; /*EXEC SQL WHENEVER SQLERROR CONTINUE;*/ buf_len = sizeof(msg); sqlglm (msg, &buf_len, &msg_len); printf ("\nORACLE error detected:"); printf ("\n%.*s \n", msg_len, msg); EXEC SQL ROLLBACK WORK RELEASE; exit(1); } /************************************************************************/ /* Main function /************************************************************************/ main (int argc, char* argv[]) { char sys[255]; /* System command */ int Flag_Sta = 0; int Flag_Net = 0; int Flag_Cha = 0; int Flag_Loc = 0; int Flag_Ver = 0; int nbt = 0; /* Number of time spans */ char tabondate[20][20]; /* Start dates */ char taboffdate[20][20]; /* End dates */ int z; /* Variables needed for getopt. */ extern char *optarg; extern int optind, opterr; int c; char *p; cmdname = ((p = strrchr(*argv,'/')) != NULL) ? ++p : *argv; /* Parse command line options. */ while ( (c = getopt(argc,argv,"hvS:C:N:L:")) != -1) switch (c) { case '?': case 'h': print_syntax(cmdname,syntax,info); exit(0); break; case 'v': Flag_Ver = 1; break; case 'S': Flag_Sta = 1; strcpy (sta2, optarg); break; case 'C': Flag_Cha = 1; strcpy (cha, optarg); break; case 'N': Flag_Net = 1; strcpy (net2, optarg); break; case 'L': Flag_Loc = 1; strcpy (loc, optarg); break; default: fprintf (info, "Unknown option: -%c\n", c); exit(1); } /* Skip over all options and their arguments. */ argv = &(argv[optind]); argc -= optind; /* Station/Channel/Network in upper case */ if (Flag_Sta) for (i=0;i %s\n", tabondate[z], taboffdate[z]); if (Flag_Ver) printf ("\n Calling Generate_IR [%s, %s, %s, %s, %s, %d]\n", sta2, net2, cha, loc, tabondate[z], Flag_Ver); Generate_IR (sta2, net2, cha, loc, tabondate[z], Flag_Ver); } exit(0); }