>>create table mustread (; >> driver c(50),; >> path c(50),; >> short c(12)) >>index on driver tag driver >>sele 0 >>use datadirs order 2 exclu >>pack >>dtest="" >> >>do toread2 && prog >> >>sele tempread >>use >>set defa to (opdir) >>sele 0 >>use infmread >>copy stru to thisread cdx >>use >>sele 0 >>use thisread exclu >>if !file('badmods.dbf') >> copy stru to badmods cdx >>endif >>if reccount()>0 >> ?? chr(7) >> do choose with 'Recovering from previous crashed run. Press space' >> goto bott >> scatter memvar >> sele 0 >> use badmods >> append blank >> gather memvar >> use >>endif >> >>sele thisread >>set order to 1 >>zap >> >>sele 0 >>use infmread >>set order to 1 >> >>sele mustread >>pack >> >>pcount=reccount() >>@ 10,20 say "Files to read "+str(pcount,6,0) >>if pcount=0 >> ?? chr(7) >> do choose with "No data to read. Press space" >> close data >> erase mustread.dbf >> return >>endif >>goto top >>do prompt with "Browse. <escape> to exit" >>defi wind view from 3,2 to 20,78 color sche 10 >>brow fields short :H='Module',path noapp noedit nodele wind view ; >> title "To read" >> >>do while .T. >> do choose with "(C)ontinue to read (A)bandon" >> if cs$"CA" >> exit >> endif >>enddo >>if cs="A" >> close data >> erase mustread.dbf >> set defa to (opdir) >> return >>endif >> >>close data >> >>xbytes=o_tickbyte >>cc=0 >>xop=1 >>empty=0 >>xdriver='' >>xbus=0 >>xduty=0 >> >>if !file('dumpfile.dbf') >> sele 0 >> use waymcl >> copy stru to dumpfile >> use >>endif >> >>sele 25 >>use dumpfile >> >>sele 24 >>use infmread order 1 >> >>sele 22 >>use thisread order 1 >> >>sele 21 >>use badmods order 1 >> >>sele 23 >>use mustread alias willread >>goto top >> >>do while !eof() && willread >> sele 7 >> use transid order 1 >> >> sele 6 >> use waymcl && file storing extracted data >> copy stru to mcltemp && temp file >> copy stru to wayfare && holds all extracted records >> use mcltemp && hold selected records >> >> sele 5 >> use emptymod order 1 && do not empty >> >> do heading with "Read and convert ETM data" >> >> sele 2 >> use wayfare excl && hold extracted records >> zap >> >> sele 1 >> use dec2hex order 1 >> >> sele willread >> goto top >> >> ff=0 >> @ 14,0 clear to 20,79 >> set esca on >> isesca=.F. >> on escape isesca=.T. >> @ 7,10 say "Once processing is under way press <Esc> to pause / abandon" >> @ 8,10 say "after the modules detailed below" >> do choose with "Note message above. Press space to start processing" >> if lastkey()=27 >> close data >> set esca off >> return >> endif >> >> do while !eof() && willread >> >> ff=ff+1 >> @ 11,20 say " Files read "+str(ff,6,0) >> >> tshort=alltrim(short) >> tlong=alltrim(driver) >> tpath=alltrim(path) >> >> tfile=tpath+tshort >> tread=padr(tlong,50) >> >> do prompt with "Reading "+tread >> >> if isesca >> acti wind alert >> @ 4,7 say " Process interrupted" >> @ 5,7 say "Read action options below" >> acti scree >> ?? chr(7) >> do while .t. >> do choose with "Process interrupted. (R)esume (A)bandon " >> if cs$"RA" >> exit >> endif >> enddo >> deac wind alert >> if cs="A" >> set esca off >> exit >> endif >> endif >> isesca=.F. >> >> store fopen(tfile) to f_handle && file num >> store fseek(f_handle,0,2) to eofile && eof >> store fseek(f_handle,0) to bofile && bof >> >> >> if eofile<=0 && file is empty >> * wait wind tfile+" is empty" nowait >> empty=empty+1 >> sele emptymod >> seek tread >> if !found() >> append blank >> repla file with tread,event with "EM" >> endif >> =fclose(f_handle) >> >> sele infmread >> seek tread+dtos(nuldate) >> if !found() >> append blank >> repla driver with tread >> endif >> sele willread >> skip >> >> loop >> endif >> >> xdriver='' >> for xx=7 to 9 >> =fseek(f_handle,xx,0) >> a=asc(fread(f_handle,1)) >> sele dec2hex >> seek a >> b=hex >> xdriver=xdriver+b >> endfor >> xdate="" >> for xx=10 to 12 >> =fseek(f_handle,xx,0) >> a=asc(fread(f_handle,1)) >> sele dec2hex >> seek a >> b=hex >> xdate=xdate+b >> endfor >> yy=right(xdate,2) >> if val(yy)<90 >> yy="20"+yy >> else >> yy="19"+yy >> endif >> tickdate=ctod(left(xdate,2)+"/"+substr(xdate,3,2)+"/"+yy) >> xontime='' >> for xx=13 to 14 >> =fseek(f_handle,xx,0) >> a=asc(fread(f_handle,1)) >> sele dec2hex >> seek a >> b=hex >> xontime=xontime+b >> endfor >> xofftime='' >> for xx=19 to 20 >> =fseek(f_handle,xx,0) >> a=asc(fread(f_handle,1)) >> sele dec2hex >> seek a >> b=hex >> xofftime=xofftime+b >> endfor >> if !between(tickdate,xfrom,xto) >> =fclose(f_handle) >> sele willread >> skip >> >> loop >> endif >> sele badmods >> seek tread+dtos(tickdate) >> if found() >> =fclose(f_handle) >> sele willread >> skip >> >> loop >> endif >> sele infmread >> seek xdriver+dtos(tickdate)+xontime+xofftime >> if found() >> =fclose(f_handle) >> sele willread >> skip >> >> loop >> endif >> sele thisread >> seek xdriver+dtos(tickdate)+xontime+xofftime >> if found() >> =fclose(f_handle) >> sele willread >> skip >> loop >> else >> append blank >> repla driver with xdriver,; >> ondate with tickdate,; >> ontime with xontime,; >> offtime with xofftime >> endif >> xcash="" >> for xx=64 to 67 >> =fseek(f_handle,xx,0) >> a=asc(fread(f_handle,1)) >> sele dec2hex >> seek a >> b=hex >> xcash=xcash+b >> endfor >> totfare=totfare+val(xcash) >> xtickets="" >> for xx=76 to 79 >> =fseek(f_handle,xx,0) >> a=asc(fread(f_handle,1)) >> sele dec2hex >> seek a >> b=hex >> xtickets=xtickets+b >> endfor >> tottick=tottick+val(xtickets) >> xpasses="" >> for xx=80 to 83 >> =fseek(f_handle,xx,0) >> a=asc(fread(f_handle,1)) >> sele dec2hex >> seek a >> b=hex >> xpasses=xpasses+b >> endfor >> tottick=tottick+val(xpasses) >> =fseek(f_handle,256,0) >> do while !feof(f_handle) >> if !is02() >> exit >> endif >> do lentrans >> sele transid >> seek xtrans >> isticket=iif(found('transid'),.t.,.f.) >> do case >> case xtrans$'0002,001F,0030' && start of duty >> * get date,driver no,bus no,dutyno >> do getduty with xtrans >> case xtrans$'0020,0003,0025' && start of route >> * route no,journey no,start time >> do getroute with xtrans >> case xtrans$'0021,0004,0071' && stage record >> * get ostage >> do getstage with xtrans >> case xtrans$'0008,0023' && stop time >> do getstop with xtrans >> case xtrans$'0073,0039,003B,' && annul ticket >> isannul=.t. >> case isticket >> do maketick >> if isannul >> xfare=xfare*-1 >> endif >> * add a record to the database - split up bytes >> do addtick >> otherwise >> * skip over len of record minus read up to the trans. >> =fseek(f_handle,xlen-3,1) >> endcase >> >> if feof(f_handle) >> exit >> endif >> >> enddo && !eof() >> =fclose(f_handle) >> sele willread >> skip >>enddo && willread >> sele wayfare >> rcount=reccount() >> ecount=empty >> if o_opanal="Y" >> * see if file op_fare exists >> do prompt with "Please wait ..saving analysis files." >> opfile=o_analdir+"opanal.dbf" >> if file((opfile)) >> sele 0 >> use (opfile) >> append from wayfare >> use >> else >> sele wayfare >> copy to (opfile) >> endif >> endif >>* select and close 1 - 10 >> erase &cfile >> erase &dfile >> do stxweed && prog - extract required records to mcltemp and >> * build up stats1 file with adult fares >> * appweed calls upvalue.prg to insert values >> if isesca >> close data >> exit >> endif >> sele willread >> if !eof() >> skip >> endif >>enddo && will read loop >>close data >>* update infmread >>sele 0 >>use thisread exclu >>sele 0 >>use infmread >>append from thisread >>sele thisread >>zap >>close data >> >>@ 3,0 clear to 20,79 >>@ 12,20 say alltrim(str(rcount,6,0))+" records have been read" >>@ 13,10 say alltrim(str(ecount,6,0)); >> +" files were empty. See control files for details" >>do choose with "Press space to continue" >>return >>