/**************************************************************** * Name: LoadATMS * * Synopsis: Loads an ATMS data set into a Concordance data * * base. The ATMS file has been converted to ASCII * * and downloaded from the mainframe to PC. * * Description: The main menu presents the user with options to * * open a data base, load an ATMS data set, index, * * reindex, browse, and examine the Concordance to * * ATMS field code matches. * * Notes: This program requires that the last three * * characters of the Concordance field names are * * the ATMS/STAIRS field codes. It uses these ID * * codes to match the incoming STAIRS data to the * * proper Concordance field. Aside from the field * * code considerations, the program makes the * * following assumptions about the ATMS data set: * * o It has been converted to ASCII format. * * o Column 0 contains non-alphameric data. * * o Field codes are in columns 1, 2, and 3. * * o All field codes are three characters long. * * o Data starts in column 6. * * o Columns 4 and 5 are ignored. * * Data marked for STAIRS sub-paragraphs, (i.e., * * field 501 below which is stored in STAIRS field * * 500), will be stored in the corresponding field * * "500" in Concordance. This will only work for * * completely numeric field codes. * * * * Sample ATMS Data Set ('X' represents non-alphameric data): * * 1 2 3 4 5 6 * * 0123456789012345678901234567890123456789012345678901234567890 * * XFROM 0000 - Control Operator print80 * * XFROM 0000 - Control Operator print80 * * X * * X0AA DAL000245001 * * X * * X005 13-88-00309-CV * * X * * X010 I-492 * * X * * X500 INA FILE NO 580 L 3480070, PERSONAL INJURY, 3RD * * X PARTY. ROBERT SHERIFF, PO BOX 5700, SAN ANTONIO, TX * * X 524-1700. * * X * * X501 JOHN JONES AND ROBERT SMITH. * * X***END OF DOCUMENT END OF DOCUMENT END OF DOCUMENT * * * ****************************************************************/ main() { int db, finished, next; char string[80]; text MainMenu[8]; text ATMSnames[101]; cls(); cursor(0,0); Status(db); /* Assign the main menu options. */ MainMenu[0] = "ATMS to Concordance Conversion Module"; MainMenu[1] = "Open a Concordance Database"; MainMenu[2] = "Examine Paragraph to Field Code Matches"; MainMenu[3] = "Browse the Database"; MainMenu[4] = "Load ATMS Data Set"; MainMenu[5] = "Index the Database"; MainMenu[6] = "Reindex the Database"; MainMenu[7] = "Concordance Information Retrieval System"; /* ** Initialize the ATMS paragraph code array for ** paragraph code to Concordance field matches. */ if (db.documents >= 0) LoadNames(db,ATMSnames); while(finished == FALSE) switch(next = menu(5, 15, 15, 60, MainMenu, next,"OEBLIRC")) { case 0: cls(); Status(db); /* Open a database. Save the current database's name, */ case 1: /* then close it. If the user cancels the open, then */ /* reopen the same one. */ if (db.documents >= 0) string = db.database+".dcb"; else string = ""; closedb(db); if ((db = OpenDatabase()) < 0) db = opendb(string); LoadNames(db,ATMSnames); Status(db); next = 1; /* Display the STAIRS to Concordance field matches. */ case 2: EditParacodes(db,ATMSnames); next = 2; case 3: query(db,0); browse(db); next = 3; case 4: LoadATMS(db,ATMSnames); next = 4; case 5: index(db); next = 5; case 6: reindex(db); next = 6; case 'M': /* Memory left in the system. */ case 8: string = "Memory available: "+trim(str(memavl(),9,0,',')); puts(0,80-len(string),string,MenuHighlight_); case 7: case -1: finished = TRUE; } } /* main() */ /**************************************************************** * Name: Status * * Synopsis: Displays data base and program name. * ****************************************************************/ Status(int db) { cursoroff(); cursor(0,0); puts(MaxRow_,0,pad("Concordance Information Retrieval System",'L',80),MenuHighlight_); puts(MaxRow_,61,"Dataflight Software",MenuHighlight_); if (db.documents >= 0) puts(0,0,pad(db.database,'L',80),MenuHighlight_); else scroll(0,0,0, 80,0,0,MenuHighlight_); } /* Status() */ /**************************************************************** * Name: LoadATMS * * Synopsis: Loads an ATMS data set into a Concordance data * * base. The ATMS file has been converted to ASCII * * and downloaded from the mainframe to PC. * ****************************************************************/ LoadATMS(int db; text ATMSnames[]) { int key, line, field, i, count, file, start; char string[256]; text screen; file = EOF; /* Check to see if we have an open data base. */ if (db.documents < 0) Message("Please open a database first."); else if (getfile("ATMS Input File","*.*",string) == CR) if ((file = open(string,"r")) == EOF) Message("Error opening input file."); if (file <> EOF) { /* Set up for the processing loop. */ screen = save(12,49,16,69); scroll(12,49,16, 69,0,0,MenuColor_); box(12,49,16,69,'s',MenuColor_); blank(db); puts(13,50,"Line:",MenuColor_); /* ** Here is the entire processing loop. Read ** and process one line at a time until the ** file ends or an error is encountered. */ start = clock(); while((readln(file,string) >= 0) and (key <> 27)) { puts(13,61,str(line = line + 1,8,0,','),MenuColor_); if (string[1]) { if ((field > 1) and ((field = FindField(db, string, ATMSnames, field)) == 1)) key = New(db,count = count + 1); if (len(string) > 6) Store(db,field,string); while(keypress()) if ((key = getkey()) == ESC) key = AreYouSure(); memset(string,0,sizeof(string)); } } /* Last document still needs to be saved. */ if (len(trim(db->1)) and (key <> ESC)) { append(db); puts(14,50,"Documents: "+str(db.documents,8,0,','),MenuColor_); puts(15,50,"Loaded: "+str(count,8,0,','),MenuColor_); } /* Clean up and save statistics to ATMSLOAD.LOG file. */ close(file); start = (clock() - start)/1000; SaveStats("ATMS load time: "+str(start,10,0,',')+" seconds."); restore(12,49,screen); } } /* LoadATMS() */ /**************************************************************** * Name: New * * Synopsis: Appends the document to the data base and shows * * the record count on the screen. Returns ESC if * * an error is encountered storing the record. * ****************************************************************/ New(int db,i) { int error; /* Store the document, clear a new one, display statistics. */ if (append(db) < 0) { error = ESC; Message("The disk is full, cannot continue loading."); } blank(db); puts(14,50,"Documents: "+str(db.documents,8,0,','),MenuColor_); puts(15,50,"Loaded: "+str(i,8,0,','),MenuColor_); return(error); } /* New() */ /**************************************************************** * Name: Store * * Synopsis: Stores the data in the proper field. Date and * * numeric data is converted before being stored. * ****************************************************************/ Store(int db, field; char string[]) { int value; switch(db.type[field]) { case 'P': db->field = db->field+addr(string,7)+" "; case 'T': db->field = trim(addr(string,7)); case 'N': db->field = num(addr(string,7)); case 'D': /* Convert YYYYMMDD format to MM/DD/YY format. */ if ((value = num(addr(string,7))) > 1900) key = value - 1900; value = str(value); db->field = ctod(substr(string,3,2)+"/"+substr(string,5,2)+"/"+substr(string,1,2)); default: ; } } /* Store() */ /**************************************************************** * Name: FindField * * Synopsis: Scans through the list of field ATMS/STAIRS * * field names to find a match for the field name * * in the string just read from file. * ****************************************************************/ FindField(int db; char line[]; text names[]; int field) { int i, code; char string[10]; /* Return the current field number if this line does not */ /* start with a field code number in columns 2 - 4. */ /* Special case for ATMS Operator footer at end of file. */ if (isalnum(i = line[1]) == 0) if (i <> '*') return(field); else return(0); string = upper(substr(line,2,3)); /* Scan through the list and find an exact match for */ /* the STAIRS field code with the Concordance name. */ for(i = field+1; i <= db.fields; i = i + 1) if (string == names[i]) return(i); for(i = 1; i <= field; i = i + 1) if (string == names[i]) return(i); /* No match was made. Scan through the list once more */ /* to see if the field code falls within a range. */ if ((code = num(string)) > 0) { /* This is a subfield, start it on the next line. */ line = substr(line,1,6)+chr(CR)+chr(LF)+chr(CR)+chr(LF)+addr(line,7); for(i = 1; i <= db.fields; i = i + 1) if (num(names[i]) and (code < num(names[i]))) return(i - 1); /* The range check will fail for the last field. */ /* If the field code fell through here, it must go */ /* into the last field, return that field's number. */ return(db.fields); } /* The item isn't a field code. Return a zero to indicate no match. */ return(0); } /* FindField() */ /**************************************************************** * Name: LoadNames * * Synopsis: Loads a text array with the STAIRS field names. * * These names are the last three characters of * * field Concordance data base field names. * ****************************************************************/ LoadNames(int db; text ATMSname[]) { int i, error; /* Initialize the array by clearing out the names. */ for(i = 0; i < sizeof(ATMSname) / sizeof(ATMSname[0]); i = i + 1) ATMSname[i] = ""; if (db.documents < 0) Message("Please open a database first."); else { for(i = 1; i <= db.fields; i = i + 1) if (len(ATMSname[i] = substr(db.name[i],len(db.name[i])-2,3)) < 3) error = ESC; if (error == ESC) Message("This data base doesn't appear to be ATMS-load compatible."); } return(error); } /* LoadNames() */ /**************************************************************** * Name: AreYouSure * * Synopsis: Asks the user if they want to abort loading. * ****************************************************************/ AreYouSure() { int key; key = Message("Abort Loading Y/N?"); if ((key == 'Y') or (key == 'y')) key = ESC; else key = 0; return(key); } /* AreYouSure() */ /**************************************************************** * Name: Message * * Synopsis: Displays error message and waits for key. * ****************************************************************/ Message(text message) { text screen; int key; cursoroff(); screen = save(5,13,8,69); box(5,13,8,69,"DS", MenuColor_); puts(6,14,pad(message,'C',53),MenuColor_); key = getkey(); restore(5,13,screen); return(asc(upper(chr(key)))); } /* Message() */ /**************************************************************** * Name: SaveStats * * Synopsis: Save statistics to file with time & date stamp. * ****************************************************************/ SaveStats(text line) { int file, h, m, s, i; char string[80]; if ((file = open("atmsload.log","a+")) <> EOF) { time(h,m,s); string = str(h,2)+":"+str(m,2)+":"+str(s,2); for(i = 0; string[i]; i = i + 1) if (string[i] == ' ') string[i] = '0'; string = dtoc(today())+" "+string+" "; write(file,string,len(string)); writeln(file,line,len(line)); close(file); } } /* SaveStats() */ /**************************************************************** * Name: OpenDatabase * * Synopsis: Prompts the user for a database and opens it. * ****************************************************************/ OpenDatabase() { int key, db; char string[80]; db = EOF; while((db == EOF) and (key <> ESC)) if ((key = getfile("Open DIRS Database","*.dcb",string)) <> ESC) db = opendb(string); return(db); } /* OpenDatabase() */ /**************************************************************** * Name: EditParacodes * * Synopsis: Displays ATMS to Concordance field correlation. * * Description: The fields are displayed using a Concordance * * menu. The paragraph codes could be edited here * * if the function was modified. Enhancements * * include the ability to save and retrieve field * * name to paragraph code correlation files. This * * function, and this program, currently rely on * * the last three characters of the Concordance * * data base field name being the equivalent ATMS * * STAIRS field name. * ****************************************************************/ EditParacodes(int db; text ATMSnames[]) { text names[db.fields+2], screen; int i, elements; screen = save(8,20,22,66); names[0] = "ATMS/Concordance Field Correlation"; for(i = 1; i < db.fields; i = i + 1) names[i] = ATMSnames[i]+pad(db.name[i],'R',36); i = 1; while(i > 0) i = menu(8, 20, 20, 63, names, i); restore(8,20,screen); } /* EditParacodes() */ /**************************************************************** * Name: initialize * * Synopsis: Set global variables to initial values * * Action: Global variables are set for system calls * ****************************************************************/ int ESC = 27, EOF = -1, CR = 13, LF = 10, FALSE = 0, TRUE = 1;