/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ /* Populate_Poly.pc */ /* Load to the NCEDC database the polynomial info. */ /* Errors can be found on Error.log */ /* */ /* Zuzlewski Stephane @1999 */ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ #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 pname[81]; /* Polynomial name */ char ptype[32]; /* Polynomial type */ float lower; /* Polynomial lower bound */ float upper; /* Polynomial upper bound */ float maxerror; /* Maximum error of polynomial approximation */ int nb_coeff; /* Number of coefficients */ float 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 (argc, argv) int argc; char* argv[]; { FILE* f_poly; /* Polynomial file descriptor */ char line[1025]; /* Line information */ char header[7]; /* Header */ float pn_coeff[21]; /* Polynomial coefficients */ /* 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); } /* Opening the poly file */ if ((f_poly = fopen ("poly.tbl", "rt")) == NULL) { printf ("\n Error [File (poly.tbl) could not be opened].\n\n"); exit (0); } /* Connect to ORACLE. */ EXEC SQL WHENEVER SQLERROR DO sql_error(); strcpy (username, "ncedcdba"); strcpy (password, "passwd"); strcpy (user_pwd, "ncedcdba/passwd@ncedc"); 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 %f %f %f %d", pname, 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, :pname, :ptype, :lower, :upper, :maxerror, :nb_coeff, SYSDATE); printf ("\n POLY : %s\t%s\t%f\t%f\t%f\t%d", pname, ptype, lower, upper, maxerror, nb_coeff); /* Reading polynomial coefficients */ sscanf (line, "%*s %*s %*s %*s %*s %*s %*s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", &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