/************************************************************************* * Name..................: notch.sc * Author................: Jeff Y YUAN * Creation.Date.........: Feb-09-2000 * Purpose...............: Load wafer notch info into database * Data.Source...........: Electroglas file from EWS tester *------------------------------------------------------------------------- * Include.Files.........: QAC505.H : Global Definitions and Macros * Dbase.Objects.........: Table: EWS_NOTCH * Calls.................: notch.exe db_name datafile_name * Called.From...........: system *------------------------------------------------------------------------- * Modifications.........: Jeff Y Yuan March-9-2000 Load certain Lot_id into EWS_NO_LOAD table *************************************************************************/ /************************************************************************ * Includes & Macros *************************************************************************/ #include #include #include #include #include EXEC SQL INCLUDE SQLCA; #include "qac505.h" #define NO_ERROR 99 EXEC SQL BEGIN DECLARE SECTION; char C_err_msg[200]; /* Ingres error message */ int C_err_no; /* Ingres error code */ int C_rows; /* Ingres row count */ char C_dbname[10]; char C_lot[12], C_reader[19], C_date[11], C_time[9], C_operator[16], C_setup_file[16], C_test_sys[16], C_probecard[21], C_prober[16], C_test_data[16]; int C_wafer_no; float C_xstep, C_ystep, C_flat, C_xref, C_yref, C_xfrst, C_yfrst, C_xdelta, C_ydelta, C_prquad, C_coquad, C_diam; int flag; EXEC SQL END DECLARE SECTION; /*********************************************************************** * Prototypes ************************************************************************/ int Open_db ( ); void Close_db ( ); void Commit ( ); void Err_ingres ( ); /************************************************************************ * Global Variables Declarations *************************************************************************/ int I_insert = 0, /* Number of lows inserted */ I_error = FALSE, /* True if an fatal error appeared */ I_modif = 0; /* number of lows updated */ FILE *flog; /************************************************************************ * Main Function *************************************************************************/ main (argc,argv) int argc; char *argv[]; { int i, nl; char *line; char pname[25][21], cdum[21], dum[19]; FILE *fpin; if(argc != 3) { printf("Usage:\n"); printf("executable.exe db_name data_file\n"); exit(0); } strcpy(C_dbname, argv[1]); printf("LOT: %s %s\n",argv[1],argv[2]); fpin = fopen(argv[2], "r"); if(fpin == NULL) { printf("file %s does not exist\n",argv[2]); exit(1); } flog = fopen("loading.log", "w"); if(flog == NULL) { printf("Can not open a log file. \n"); exit(1); } /* prepare necessary memory */ nl = 200; line = (char *)malloc((nl+1)*sizeof(char)); if(line==NULL) { printf("something wrong with allocate 1\n"); exit(1); } /* reading in data */ fgets(line,nl-1,fpin); /* skip first four lines */ fgets(line,nl-1,fpin); fgets(line,nl-1,fpin); fgets(line,nl-1,fpin); for(i=0;i<25;i++) /* the cursor points to the fifth line */ { fgets(line,nl-1,fpin); if(strncmp(line, "PRODUCT",7)==0 || strncmp(line, "DEVICE",6)==0) { strncpy(pname[i], "NODATA", 6); } else { if(strncmp(line,"TEST",4)==0 || strncmp(line,"SETUP",5)==0 ) { sscanf(line,"%s %s %s", cdum, cdum, pname[i]); } else sscanf(line,"%s %s", cdum, pname[i]); } /* fprintf(flog, "%s | \n", pname[i]); */ } strcpy(dum, pname[4]); /* get the lot id from READER field */ for (i=0; dum[i]!='-'; i++) C_lot[i]=dum[i]; C_lot[i]='\0'; /* strcpy(C_lot, pname[0]); */ sscanf(pname[1], "%d", &C_wafer_no); strcpy(C_reader, pname[4]); sscanf(pname[5], "%f", &C_xstep); sscanf(pname[6], "%f", &C_ystep); sscanf(pname[7], "%f", &C_flat); sscanf(pname[8], "%f", &C_xref); sscanf(pname[9], "%f", &C_yref); sscanf(pname[10], "%f", &C_yfrst); sscanf(pname[11], "%f", &C_xfrst); sscanf(pname[12], "%f", &C_xdelta); sscanf(pname[13], "%f", &C_ydelta); sscanf(pname[14], "%f", &C_prquad); sscanf(pname[15], "%f", &C_coquad); sscanf(pname[16], "%f", &C_diam); strcpy(C_date, pname[17]); strcpy(C_time, pname[18]); strcpy(C_operator, pname[19]); strcpy(C_setup_file, pname[20]); strcpy(C_test_sys, pname[21]); strcpy(C_test_data, pname[22]); strcpy(C_probecard, pname[23]); strcpy(C_prober, pname[24]); /* printf("%s \n", C_lot); */ /* printf("%d \n", C_wafer_no); */ fprintf(flog,"%s | ", C_lot); fprintf(flog, "%d \n", C_wafer_no); /* printf("%s \n", pname[2]);*/ /* open the database */ if (!Open_db ()) exit (FALSE); /* DB loading */ EXEC SQL INSERT INTO ews_notch VALUES ( :C_lot, :C_wafer_no, :C_reader, :C_xstep, :C_ystep, :C_flat, :C_xref, :C_yref, :C_yfrst, :C_xfrst, :C_xdelta, :C_ydelta, :C_prquad, :C_coquad, :C_diam, :C_date, :C_time, :C_operator, :C_setup_file, :C_test_sys, :C_test_data, :C_probecard, :C_prober ); if (C_ERROR) { Err_ingres ("Error in loading EWS_NOTCH - "); } Row_count (ews_notch); Commit (); EXEC SQL REPEATED SELECT COUNT(ews_notch.lot) INTO :flag FROM ews_load_list a, ews_notch WHERE uppercase(a.lot) = ews_notch.lot AND a.wafer_no = ews_notch.wafer_no AND ews_notch.lot = :C_lot ; if (C_ERROR) { Err_ingres ("Error in counting"); return (FALSE); } Commit (); if(flag == 0) /* then, load the lot id to another table */ { EXEC SQL INSERT INTO ews_no_load VALUES ( :C_lot, :C_wafer_no, DATE('today') ); if (C_ERROR) { Err_ingres ("Error in loading EWS_NO_LOAD"); return (90); } Commit (); fprintf(flog, "The STDF file has not been transferred for loading.\n"); printf("The STDF file has not been tranferred for loading.\n"); fclose(fpin); fclose(flog); Close_db ( ); exit (90); } else { printf("The STDF was tranferred to IDEA/EWS server. Flag: %d\n", flag); fprintf(flog, "The STDF file was transferred to IDEA/EWS server. Flag: %d\n", flag); fclose(fpin); fclose(flog); Close_db ( ); exit (NO_ERROR); } } /************************************************************************* * Function..............: Open_db ************************************************************************** * Purpose...............: Connect to idwsphx Database * Returns...............: FALSE if the connection failed * Dbase.Objects.Modified: *************************************************************************/ int Open_db ( ) { EXEC SQL CONNECT :C_dbname; if (C_ERROR) { Err_ingres("idwsphx Connection failed"); return (FALSE); } /* Do not lock the table */ EXEC SQL SET LOCKMODE SESSION WHERE READLOCK = NOLOCK; if (C_ERROR) { Err_ingres("Error: set lockmode session"); return (FALSE); } return (C_SUCCES); } /************************************************************************ * Function..............: Close_db ************************************************************************* * Purpose...............: Close Database * Returns...............: * Dbase.Objects.Modified: *************************************************************************/ void Close_db () { EXEC SQL ROLLBACK WORK; EXEC SQL DISCONNECT; } /*********************************************************************** * Function..............: Commit ************************************************************************ * Purpose...............: Commit the current transition * Returns...............: * Dbase.Objects.Modified: ************************************************************************/ void Commit () { EXEC SQL COMMIT; if (C_ERROR) Err_ingres ("Commit Failed..."); } /*********************************************************************** * Function..............: Err_ingres ************************************************************************ * Purpose...............: Print a ingres error message, rollback * Returns...............: * Input.................: message to print * Output................: * Dbase.Objects.Modified: ************************************************************************/ void Err_ingres (message) char *message; { fprintf (flog, "\nError INGRES, Rollback :\n"); fprintf (flog, "%.70s\n", message); /* Retrieve error or message information from db */ EXEC SQL INQUIRE_SQL (:C_err_msg = errortext, :C_err_no=errorno); fprintf (flog, "%Ingres Message \n-%s-\n", C_err_msg); fprintf (flog, "%d\n", C_err_no); printf ("%Ingres Error Message \n-%s-\n", C_err_msg); printf ("%d\n", C_err_no); EXEC SQL ROLLBACK WORK; I_error = TRUE; } /************************************************************************ * Function..............: Row_count ************************************************************************* * Purpose...............: Print the number of rows affected by the query * Returns...............: * Input.................: message to print * Output................: * Dbase.Objects.Modified: *************************************************************************/ void Row_count (tabname) char *tabname; { EXEC SQL INQUIRE_SQL (:C_rows = rowcount); fprintf (flog, "\nAffected rows in table "); fprintf (flog, "%.70s", tabname); fprintf (flog, " %d", C_rows); printf ("\nAffected rows in table "); printf ("%.70s\n", tabname); printf (" %d", C_rows); }