#include #include #include #include #include EXEC SQL INCLUDE sqlca.h; typedef char asciz[20]; typedef char vc2_arr[11]; EXEC SQL BEGIN DECLARE SECTION; /* User-defined type for null-terminated strings */ EXEC SQL TYPE asciz IS STRING(20) REFERENCE; /* User-defined type for a VARCHAR array element. */ EXEC SQL TYPE vc2_arr IS VARCHAR2(11) REFERENCE; asciz username; asciz password; char user_pwd[80]; int i; int j; int k; char sta[16]; /* Station code */ char sta2[16]; /* Station code */ char net[9]; /* Network code */ float lat; /* Latitude */ float lon; /* Longitude */ float elev; /* Elevation */ char staname[51]; /* Station name */ int nb_sensor; /* Number of sensors */ int nb_filamp; /* Number of filter-amplifiers */ int nb_digi; /* Number of digitizers */ int nb_data; /* Number of dataloggers */ char date[32]; /* Date */ char ondate[32]; /* Start date */ char offdate[32]; /* Off date */ char lddate[32]; /* Load date */ int sensor_id; /* Sensor identifier */ float edepth; /* Sensor depth */ int nb_component; /* Number of components */ int nb_component2; /* Number of components */ char name[81]; /* Name */ char serial_nb[81]; /* Serial number */ char channel_comp[3];/* Channel */ char component_type; /* Component type */ float sensitivity; /* Sensitivity */ float frequency; /* Frequency */ int seqresp_id; /* Sequence of responses identifier */ int resp_nb; /* Response number */ char resp_type; /* Response type */ int resp_id; /* Response identifier */ int unit_in; /* Input units */ int unit_out; /* Output units */ char unitin[81]; /* Input units */ char unitout[81]; /* Output units */ char r_type; /* Response type */ char filter_type[3]; /* Filter type */ int nb_pole; /* Number of poles */ float corner_freq; /* Corner frequency */ float damping_value; /* Damping value */ char type; float r_value; /* Real value */ float i_value; /* Imaginary value */ char poly_type; /* Type of polynomial approximation */ float lower_bound; /* Lower bound */ float upper_bound; /* Upper bound */ float max_error; /* Maximum error */ int nb_coeff; /* Number of coefficients */ int pn_nb; /* Coefficient number */ float pn_value; /* Coefficient value */ char next_hard_type; /* Next hardware type */ int next_hard_nb; /* Next hardware number */ int next_hard_pchannel; /* Next hardware channel */ float azimuth; /* Azimuth */ float dip; /* Dip */ int filamp_id; /* Filter-Amplifier identifier */ int nb_pchannel; /* Number of physical channels */ int nb_pchannel2; /* Number of physical channels */ float gain; /* Gain */ short ind; /* Indicator */ int nb_pri_pchannel; /* Number of primary channels */ int nb_aux_pchannel; /* Number of auxiliary channels */ char digi_type[4]; /* Digitizer type */ char digi_polarity; /* Digitizer polarity */ int data_nb; /* Datalogger number */ int data_pchannel; /* Datalogger physical channel */ int data_id; /* Datalogger identifier */ char seed_io[3]; /* SEED instrument and orientation */ int nb_lchannel; /* Number of logical channels */ int seqfil_id; /* Sequence of filters identifier */ char seedchan[4]; /* SEED channel name */ char channel[4]; /* Channel name */ char channelsrc[9]; /* Channel source */ float rgain; /* Gain */ float rfrequency; /* Frequency */ float samprate; /* Sampling rate */ float 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 */ char comptype[81]; /* Compression type identifier */ char unitsignal[81]; /* Unit of signal responses identifier */ char unitcalib[81]; /* Unit of calibration identifier */ char data_type[81]; /* Datalogger type */ char serial_nb[81]; /* Serial number */ char firmware_nb[81];/* Firmware number */ char software[81]; /* Software */ char software_nb[81];/* Software version number */ int nb_board; /* Number of boards */ int nb_module; /* Number of modules */ int word_32; /* 32 bit word order */ int word_16; /* 16 bit word order */ EXEC SQL END DECLARE SECTION; long SQLCODE; void sql_error(); /* Handles unrecoverable errors */ /**************************************/ /* Trim trailing blanks from a string */ /**************************************/ char* Remove_Blank (s) char *s; { char *p = s + strlen (s); while (--p >= s) if (*p == ' ') *p = '\0'; else break; return (s); } /*****************/ /* Main function */ /*****************/ main (argc, argv) int argc; char* argv[]; { /* Test of parameters */ if ((argc < 2) || (argc > 3)) { printf ("\n\n stinfo []\n\n"); exit (0); } strcpy (sta2, argv[1]); for (i=0;i Not used.", j); else printf ("\n\t\t Channel %d --> Type: %c Nb: %d Channel: %d -- Azimuth: %5.2f Dip: %5.2f", j, next_hard_type, next_hard_nb, next_hard_pchannel, azimuth, dip); } printf ("\n"); EXEC SQL SELECT name, serial_nb, nb_component INTO :name, :serial_nb, :nb_component2 FROM sensor WHERE sensor_id = :sensor_id; printf ("\n\t %.26s %.26s -- Nb. component: %d", name, serial_nb, nb_component2); for (j=1;j<=nb_component2;j++) { EXEC SQL SELECT channel_comp, component_type, sensitivity, frequency, seqresp_id INTO :channel_comp, :component_type, :sensitivity, :frequency, :seqresp_id FROM sensor_component WHERE sensor_id = :sensor_id AND component_nb = :j; printf ("\n\t\t Channel: %s -- Type: %c -- Sens: %5.2f -- Freq: %5.2f Hz", channel_comp, component_type, sensitivity, frequency); EXEC SQL DECLARE resp_cursor CURSOR FOR SELECT resp_nb, resp_type, resp_id, unit_in, unit_out, r_type FROM response WHERE seqresp_id = :seqresp_id ORDER BY resp_nb; EXEC SQL OPEN resp_cursor; EXEC SQL FETCH resp_cursor INTO :resp_nb, :resp_type, :resp_id, :unit_in, :unit_out, :r_type; while (sqlca.sqlcode != 1403) { EXEC SQL SELECT name INTO :unitin FROM D_Unit WHERE id = :unit_in; EXEC SQL SELECT name INTO :unitout FROM D_Unit WHERE id = :unit_out; printf ("\n\t\t\t Type: %c -- In: %.12s Out: %.12s", r_type, unitin, unitout); 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; printf ("\n\t\t\t High-Pass filter: Type: %s -- Nb. Pole: %d -- Corner Freq: %5.2f -- Damping: %5.2f", filter_type, nb_pole, corner_freq, damping_value); break; case 'L': EXEC SQL SELECT filter_type, nb_pole, corner_freq, damping_value INTO :filter_type, :nb_pole, :corner_freq, :damping_value FROM response_lp WHERE lp_id = :resp_id; printf ("\n\t\t\t Low-Pass filter: Type: %s -- Nb. Pole: %d -- Corner Freq: %5.2f -- Damping: %5.2f", filter_type, nb_pole, corner_freq, damping_value); break; case 'Z': EXEC SQL DECLARE pz_cursor CURSOR FOR SELECT type, r_value, i_value FROM response_pz WHERE pz_id = :resp_id ORDER BY pz_nb; EXEC SQL OPEN pz_cursor; EXEC SQL FETCH pz_cursor INTO :type, :r_value, :i_value; while (sqlca.sqlcode != 1403) { printf ("\n\t\t\t Type: %c -- Real: %5.2f -- Imag: %5.2f", type, r_value, i_value); EXEC SQL FETCH pz_cursor INTO :type, :r_value, :i_value; } EXEC SQL CLOSE pz_cursor; break; case 'P': EXEC SQL SELECT poly_type, lower_bound, upper_bound, max_error, nb_coeff INTO :poly_type, :lower_bound, :upper_bound, :max_error, :nb_coeff FROM response_pn WHERE pn_id = :resp_id; printf ("\n\t\t\t Polynomial: Type: %c -- Lower: %5.2f -- Upper: %5.2f -- Max. Error: %5.2f -- Nb Coeff: %d", poly_type, lower_bound, upper_bound, max_error, nb_coeff); EXEC SQL DECLARE pn_cursor CURSOR FOR SELECT pn_nb, pn_value FROM response_pn_data WHERE pn_id = :resp_id ORDER BY pn_nb; EXEC SQL OPEN pn_cursor; EXEC SQL FETCH pn_cursor INTO :pn_nb, :pn_value; while (sqlca.sqlcode != 1403) { printf ("\n\t\t\t Coeff: %d -- Value: %5.2f", pn_nb, pn_value); EXEC SQL FETCH pn_cursor INTO :pn_nb, :pn_value; } EXEC SQL CLOSE pn_cursor; break; } EXEC SQL FETCH resp_cursor INTO :resp_nb, :resp_type, :resp_id, :unit_in, :unit_out, :r_type; } EXEC SQL CLOSE resp_cursor; } } /* Retrieving filamp information */ printf ("\n\n\n Filter-Amplifier information:"); printf ("\n -----------------------------"); for (i=1;i<=nb_filamp;i++) { printf ("\n\n\t Filter-Amplifier %d:", i); printf ("\n\t -------------------\n"); EXEC SQL SELECT filamp_id, nb_pchannel INTO :filamp_id, :nb_pchannel FROM station_filamp WHERE sta = :sta2 AND filamp_nb = :i AND :date BETWEEN ondate AND offdate; printf ("\n\t Nb Channel: %d", nb_pchannel); EXEC SQL SELECT nb_pchannel INTO :nb_pchannel2 FROM filamp WHERE filamp_id = :filamp_id; for (j=1;j<=nb_pchannel2;j++) { next_hard_type = ' '; EXEC SQL SELECT next_hard_type, next_hard_nb, next_hard_pchannel INTO :next_hard_type, :next_hard_nb, :next_hard_pchannel FROM station_filamp_pchannel WHERE sta = :sta2 AND filamp_nb = :i AND pchannel_nb = :j AND :date BETWEEN ondate AND offdate; if (next_hard_type == ' ') printf ("\n\t\t Channel %d --> Not used.", j); else printf ("\n\t\t Channel %d --> Type: %c Nb: %d Channel: %d", j, next_hard_type, next_hard_nb, next_hard_pchannel); } printf ("\n"); EXEC SQL SELECT name, serial_nb, nb_pchannel INTO :name, :serial_nb, :nb_pchannel2 FROM filamp WHERE filamp_id = :filamp_id; printf ("\n\t %.26s %.26s -- Nb. channel: %d", name, serial_nb, nb_pchannel2); for (j=1;j<=nb_pchannel2;j++) { EXEC SQL SELECT gain, frequency, seqresp_id INTO :gain, :frequency, :seqresp_id:ind FROM filamp_pchannel WHERE filamp_id = :filamp_id AND pchannel_nb = :j; printf ("\n\t\t Gain: %5.2f -- Freq: %5.2f Hz", gain, frequency); if (ind == (-1)) printf ("\n\t\t\t No response"); else { EXEC SQL DECLARE resp_cursor2 CURSOR FOR SELECT resp_nb, resp_type, resp_id, unit_in, unit_out, r_type FROM response WHERE seqresp_id = :seqresp_id ORDER BY resp_nb; EXEC SQL OPEN resp_cursor2; EXEC SQL FETCH resp_cursor2 INTO :resp_nb, :resp_type, :resp_id, :unit_in, :unit_out, :r_type; while (sqlca.sqlcode != 1403) { EXEC SQL SELECT name INTO :unitin FROM D_Unit WHERE id = :unit_in; EXEC SQL SELECT name INTO :unitout FROM D_Unit WHERE id = :unit_out; printf ("\n\t\t\t Type: %c -- In: %.12s Out: %.12s", r_type, unitin, unitout); 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; printf ("\n\t\t\t High-Pass filter: Type: %s -- Nb. Pole: %d -- Corner Freq: %5.2f -- Damping: %5.2f", filter_type, nb_pole, corner_freq, damping_value); break; case 'L': EXEC SQL SELECT filter_type, nb_pole, corner_freq, damping_value INTO :filter_type, :nb_pole, :corner_freq, :damping_value FROM response_lp WHERE lp_id = :resp_id; printf ("\n\t\t\t Low-Pass filter: Type: %s -- Nb. Pole: %d -- Corner Freq: %5.2f -- Damping: %5.2f", filter_type, nb_pole, corner_freq, damping_value); break; case 'Z': EXEC SQL DECLARE pz_cursor2 CURSOR FOR SELECT type, r_value, i_value FROM response_pz WHERE pz_id = :resp_id ORDER BY pz_nb; EXEC SQL OPEN pz_cursor2; while (sqlca.sqlcode != 1403) { EXEC SQL FETCH pz_cursor2 INTO :type, :r_value, :i_value; printf ("\n\t\t\t Type: %c -- Real: %5.2f -- Imag: %5.2f", type, r_value, i_value); } EXEC SQL CLOSE pz_cursor2; break; case 'P': EXEC SQL SELECT poly_type, lower_bound, upper_bound, max_error, nb_coeff INTO :poly_type, :lower_bound, :upper_bound, :max_error, :nb_coeff FROM response_pn WHERE pn_id = :resp_id; printf ("\n\t\t\t Polynomial: Type: %c -- Lower: %5.2f -- Upper: %5.2f -- Max. Error: %5.2f -- Nb Coeff: %d", poly_type, lower_bound, upper_bound, max_error, nb_coeff); EXEC SQL DECLARE pn_cursor2 CURSOR FOR SELECT pn_nb, pn_value FROM response_pn_data WHERE pn_id = :resp_id ORDER BY pn_nb; EXEC SQL OPEN pn_cursor2; while (sqlca.sqlcode != 1403) { EXEC SQL FETCH pn_cursor2 INTO :pn_nb, :pn_value; printf ("\n\t\t\t Coeff: %d -- Value: %5.2f", pn_nb, pn_value); } EXEC SQL CLOSE pn_cursor2; break; } EXEC SQL FETCH resp_cursor2 INTO :resp_nb, :resp_type, :resp_id, :unit_in, :unit_out, :r_type; } EXEC SQL CLOSE resp_cursor2; } } } /* Retrieving digitizer information */ printf ("\n\n\n Digitizer information:"); printf ("\n ----------------------"); for (i=1;i<=nb_digi;i++) { printf ("\n\n\t Digitizer %d:", i); printf ("\n\t -----------\n"); EXEC SQL SELECT serial_nb, nb_pri_pchannel, nb_aux_pchannel INTO :serial_nb, :nb_pri_pchannel, :nb_aux_pchannel FROM station_digitizer WHERE sta = :sta2 AND digi_nb = :i AND :date BETWEEN ondate AND offdate; strcpy (serial_nb, Remove_Blank (serial_nb)); printf ("\n\t Serial Nb: %s -- Nb Primary Channel: %d -- Nb Auxiliary Channel: %d", serial_nb, nb_pri_pchannel, nb_aux_pchannel); EXEC SQL SELECT nb_module INTO :nb_module FROM datalogger_board WHERE serial_nb = :serial_nb AND data_id IN (SELECT data_id FROM Datalogger WHERE :date BETWEEN ondate AND offdate); for (j=1;j<=nb_module;j++) { strcpy (digi_type, ""); EXEC SQL SELECT data_nb, data_pchannel, digi_type, digi_polarity INTO :data_nb, :data_pchannel, :digi_type, :digi_polarity FROM station_digitizer_pchannel WHERE sta = :sta2 AND digi_nb = :i AND pchannel_nb = :j AND :date BETWEEN ondate AND offdate; if (strlen (digi_type) == 0) printf ("\n\t\t Channel %d --> Not used.", j); else printf ("\n\t\t Channel %d --> Datalogger Nb: %d Channel: %d -- Type: %s -- Polarity: %c", j, data_nb, data_pchannel, digi_type, digi_polarity); } } /* Retrieving datalogger information */ printf ("\n\n\n Datalogger information:"); printf ("\n -----------------------"); for (i=1;i<=nb_data;i++) { printf ("\n\n\t Datalogger %d:", i); printf ("\n\t ------------\n"); EXEC SQL SELECT data_id, nb_pchannel INTO :data_id, :nb_pchannel FROM station_datalogger WHERE sta = :sta2 AND data_nb = :i AND :date BETWEEN ondate AND offdate; printf ("\n\t Nb Physical Channel: %d", nb_pchannel); for (j=1;j<=nb_pchannel;j++) { EXEC SQL SELECT seed_io, nb_lchannel INTO :seed_io, :nb_lchannel FROM station_datalogger_pchannel WHERE sta = :sta2 AND data_nb = :i AND pchannel_nb = :j AND :date BETWEEN ondate AND offdate; printf ("\n\t\t SEED: %s -- Nb Logical Channel: %d", seed_io, nb_lchannel); for (k=1;k<=nb_lchannel;k++) { EXEC SQL SELECT seqfil_id, seedchan, channel, channelsrc, rgain, rfrequency, samprate, clock_drift, flags, data_format, comp_type, unit_signal, unit_calib, block_size INTO :seqfil_id, :seedchan, :channel, :channelsrc, :rgain:ind, :rfrequency, :samprate, :clock_drift, :flags, :data_format, :comp_type, :unit_signal, :unit_calib, :block_size FROM station_datalogger_lchannel WHERE sta = :sta2 AND data_nb = :i AND pchannel_nb = :j AND lchannel_nb = :k AND :date BETWEEN ondate AND offdate; EXEC SQL SELECT name INTO :unitsignal FROM D_Unit WHERE id = :unit_signal; EXEC SQL SELECT name INTO :unitcalib FROM D_Unit WHERE id = :unit_calib; EXEC SQL SELECT description INTO :comptype FROM D_Abbreviation WHERE id = :comp_type; EXEC SQL SELECT name INTO :name FROM filter_sequence WHERE seqfil_id = :seqfil_id; printf ("\n\t\t\t %.12s -- %s %s %.5s -- Gain: %5.2f Freq: %5.2f -- Samp. rate: %5.2f Hz\n\t\t\t Clock: %5.2f -- %.4s Format: %.12s -- Comp. Type: %.12s Signal: %.12s\n\t\t\t Calib: %.12s -- Block Size: %d", name, seedchan, channel, channelsrc, rgain, rfrequency, samprate, clock_drift, flags, data_format, comptype, unitsignal, unitcalib, block_size); } } printf ("\n"); EXEC SQL SELECT data_type, serial_nb, firmware_nb, software, software_nb, nb_board, word_32, word_16 INTO :data_type:ind, :serial_nb:ind, :firmware_nb:ind, :software:ind, :software_nb:ind, :nb_board:ind, :word_32:ind, :word_16:ind FROM datalogger WHERE data_id = :data_id; printf ("\n\t Type: %.12s -- Serial: %.12s Firmware: %.12s Soft: %.12s Version: %.12s\n\t Nb Board: %d -- Word 32: %d Word 16: %d", data_type, serial_nb, firmware_nb, software, software_nb, nb_board, word_32, word_16); for (j=1;j<=nb_board;j++) { strcpy (serial_nb, ""); EXEC SQL SELECT serial_nb, nb_module INTO :serial_nb:ind, :nb_module FROM datalogger_board WHERE data_id = :data_id AND board_nb = :j; printf ("\n\t\t Serial: %.12s -- Nb Module: %d", serial_nb, nb_module); for (k=1;k<=nb_module;k++) { strcpy (serial_nb, ""); EXEC SQL SELECT serial_nb, sensitivity INTO :serial_nb:ind, :sensitivity FROM datalogger_module WHERE data_id = :data_id AND board_nb = :j AND module_nb = :k; printf ("\n\t\t\t Serial: %.12s -- Sensitivity: %f", serial_nb, sensitivity); } } } printf ("\n\n"); /* Disconnect from the database. */ printf ("\n Disconnecting from ORACLE ...\n\n"); EXEC SQL COMMIT WORK RELEASE; exit(0); } /* 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); }