/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ /* Populate_Poly.pc */ /* Load to the NCEDC database the polynomial info. */ /* Errors can be found in Error.log */ /* */ /* Zuzlewski Stephane @1999 */ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ #include #include #include #define CONNECT_STRING "user/passwd@db" 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 polyname[81]; /* Polynomial name */ char ptype[32]; /* Polynomial type */ double lower; /* Polynomial lower bound */ double upper; /* Polynomial upper bound */ double maxerror; /* Maximum error of polynomial approximation */ int nb_coeff; /* Number of coefficients */ double pncoeff; /* Polynomial coefficients */ EXEC SQL END DECLARE SECTION; long SQLCODE; FILE* f_err; /* Error File descriptor */ void sql_error(); /* handles unrecoverable errors */ /*-*-*-*-*-*-*-*-*/ /* Main function */ /*-*-*-*-*-*-*-*-*/ main (int argc, char* argv[]) { FILE* f_poly; /* Polynomial file descriptor */ char line[1025]; /* Line information */ char header[7]; /* Header */ double pn_coeff[21]; /* Polynomial coefficients */ if (argc != 2) { printf ("\n %s \n\n", argv[0]); exit (0); } /* Opening the poly file */ if ((f_poly = fopen (argv[1], "rt")) == NULL) { printf ("\n Error [File (%s) could not be opened].\n\n", argv[1]); exit (0); } /* Opening the error file */ if ((f_err = fopen ("Error.log", "w+t")) == NULL) { printf ("\n Error [File (Error.log) could not be opened].\n\n"); exit (0); } /* Connect to ORACLE. */ EXEC SQL WHENEVER SQLERROR DO sql_error(); strcpy (user_pwd, CONNECT_STRING); EXEC SQL CONNECT :user_pwd; printf ("\n Connected to ORACLE as user: %s\n", username); /* Parsing poly file */ fgets (line, 1024, f_poly); while (!feof (f_poly)) { strcpy (header, ""); sscanf (line, "%s", header); if (!strcmp (header, "POLY")) { /* Reading polynomial information */ sscanf (line, "%*s %s %s %lf %lf %lf %d", polyname, ptype, &lower, &upper, &maxerror, &nb_coeff); EXEC SQL INSERT INTO Response_PN (pn_id, name, poly_type, lower_bound, upper_bound, max_error, nb_coeff, lddate) VALUES (pnseq.NEXTVAL, :polyname, :ptype, :lower, :upper, :maxerror, :nb_coeff, SYSDATE); printf ("\n POLY : %s\t%s\t%lf\t%lf\t%lf\t%d", polyname, ptype, lower, upper, maxerror, nb_coeff); /* Reading polynomial coefficients */ sscanf (line, "%*s %*s %*s %*s %*s %*s %*s %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &pn_coeff[0], &pn_coeff[1], &pn_coeff[2], &pn_coeff[3], &pn_coeff[4], &pn_coeff[5], &pn_coeff[6], &pn_coeff[7], &pn_coeff[8], &pn_coeff[9], &pn_coeff[10], &pn_coeff[11], &pn_coeff[12], &pn_coeff[13], &pn_coeff[14], &pn_coeff[15], &pn_coeff[16], &pn_coeff[17], &pn_coeff[18], &pn_coeff[19]); printf ("\n\t\t\t Coefficients : "); for (k=0;k