dc. DO DB c. Simple data base program ,c. c. This program permits the definition and processing of a data c. base structure. The user is prompted for a file that contains Xc. his data. The default type of the file is .DB. The structure of c. the file is given by an associated file with the same name, but c. with the type .DS. Once these two files are active the user can c. process this file. The commands are identified by entering a ? for c. help. More documentation will be available later. Lc. c. -end.of.infi- c. x program db c. @c. == Simple data base edit c.  include 'dbinc.for' lc===  call initdb( isw ) 4c. 200 continue  call incmd('db',inp) ` call jjupp(inp) c. ( if( isadd(inp) ) goto 200 if( ischa(inp) ) goto 200 if( isdel(inp) ) goto 200 T if( isexi(inp) ) goto 9000 if( isfin(inp) ) goto 200  if( islis(inp) ) goto 200 if( isund(inp) ) goto 200 if( ismov(inp) ) goto 200 H if( isset(inp) ) goto 200 c. 850 continue t ieof = 1  if( inp.eq.'?' ) then < write(6,*)' ] .. To repeat a command line'  else  write(6,*)'Enter: ? .. to get a command list' h endif  goto 200 0c. 9000 continue  end dc====== function incmd( prompt, cmd ) ,c. c... Input a command c. X character*(*) prompt, cmd  include 'dbinc.for'  data inp/ ' ' /  data ipos/1/ c=== L200 continue  call jjwrd( inp, ipos, cmd )  if( cmd.eq.' ' ) then x210 continue  type 91,'$[' @ inp = ' '  cmd = '^Z'  read(5,91,end=9000)inp l ipos = 1  ieof = -1 4 cmd = inp  if( cmd.ne.' ' ) goto 200  endif ` if( cmd.eq.',' ) cmd = ' ' if( cmd.eq.']' ) then ( if( ieof.eq.1 ) goto 210 ipos = 1 if( inp(1:1).ge.'0' .and. inp(1:1).le.'9' ) then T call jjwrd(inp,ipos,cmd) endif  goto 200 endif c. H 9000 continue return  end dc====== function initdb( idb ) ,c. c... Initalize data base format c. X include 'dbinc.for'  character*80 nmdbs c===  call stopctc(1) c. L idb = -1  type 91,'$File<.db>? '  read(5,91,end=9000) fnam x call jjupp( fnam )  inx = index(fnam,'.')-1 @ if(inx.lt.0) then  inx = jjlen(fnam)  fnam = fnam(1:inx)//'.db' l endif  nmdbs = fnam(1:inx)//'.ds' 4 if( index( fnam,'.DS' ).ne.0 ) goto 550 c.  open(unit=1,type='old',name=nmdbs,err=500) ` c. c... Old db format ( c. 200 continue idb = 1 T ii = ii+1 read( 1,91,end=290 ) dbfmt(ii)  goto 200 c. 290 continue H close( unit=1 ) goto 1000 c. tc... New db dbs c. <500 continue  idb = 2  write(6,*) 'New DB format ',nmdbs(1:jjlen(nmdbs)) hc. ..........12345678901234567890 550 continue 0 dbfmt(1)='Fld Name a10'  dbfmt(2)='Fld fmt a5'  fnam = nmdbs \c. 1000 continue $ ii = 1  ipos = 1 c. P1010 continue  do 1090 ii=1,100  if(dbfmt(ii).lt.' ') goto 1095 | inp = dbfmt(ii)(11:)  len = index(inp,' ')-1 D inx = index(inp(1:len),'.')  if(inx.ne.0) len = inx-1  decode( len-1,1020,inp(2:5))isize p1020 format(i)  ifst(ii)=ipos 8 ilst(ii)=ipos+isize-1  ipos = ipos+isize 1090 continue d1095 continue c. ,c... open files c.  open(unit=1,name=fnam,type='old',err=2100) X goto 2190 2100 continue  write(6,*) 'New DB file ',fnam(1:jjlen(fnam)) c. 2190 continue L open(unit=2,name='DB.SCI',type='new',carriagecontrol='list')  call movdat(0) c. x9000 continue  initdb = idb @ return  end dc====== function isadd( cmd ) ,c. c... add a record c. X character*(*) cmd  include 'dbinc.for' c.  isadd = .false.  if( cmd.eq.'?' ) then L write(6,*)' ADd .. Adds a record to the file'  else if( cmd(1:2).eq.'AD' ) then  isadd = .true. x iodata = ' '  do 290 ii=1,100 @ if( dbfmt(ii).le.' ' ) goto 295  write(6,91)'$', dbfmt(ii)(1:8),'? '  read(5,91,end=9000) iodata(ifst(ii):ilst(ii)) l goto 290 290 continue 4c. 295 continue  write(6,*)'..Added..' ` call movdat(-1 ) endif ( c. 9000 continue return T end dc====== function ischa( cmd ) ,c. c... change a record c. X character*(*) cmd  include 'dbinc.for'  character*80 infld c===  ischa = .false. L if( cmd.eq.'?' ) then  write(6,*)' CHange .. Changes the current record' c. x else if( cmd(1:2).eq.'CH' ) then  nrec = movdat( -4 ) @200 continue  ii = lofld( cmd )  if( ii.eq.-1 ) then l goto 1090 c. 4 else if( ii.gt.0 ) then  write(6,91)' ',dbfmt(ii)(1:8),': '  1 , iodata(ifst(ii):ilst(ii)) ` write(6,91)'$ new? ' read(5,91,err=200)iodata(ifst(ii):ilst(ii)) ( goto 200 c. else T write(6,*) '..Changed..' call movdat( -2 )  call movdat( -1 ) endif c. H 1090 continue ischa = .true.  endif tc.  return < end dc====== function isdel( cmd ) ,c. c... Delete a record c. X character*(*) cmd  include 'dbinc.for' c.  isdel = .false.  if( cmd.eq.'?' ) then L write(6,*)' DElete .. Deletes the current record'  else if( cmd(1:2).eq.'DE' ) then  isdel = .true. x call movdat( -2 )  write(6,*)'..Deleted..' @ endif  return  end dc====== function isexi( cmd ) ,c. c... Exit from the program c. X character*(*) cmd  include 'dbinc.for' c.  isexi = .false.  if( cmd.eq.'?' ) then L write(6,*)' EXit .. Exit from the DB program'  write(6,*)' ^Z .. Also exit' c. x else if( cmd(1:2).eq.'EX' .or. cmd(1:3).eq.'^Z' ) then  if(iadd.eq.0 .and. idel.eq.0 ) goto 500 @ write(6,210) iadd,idel 210 format( i5,' Add ',i5,' Del ')  type 91,'$Update ? ' l read(5,91,end=300)inp  call jjupp(inp) 4c.  if( inp(1:1).eq.' '.or. inp(1:1).eq.'Y' ) then  open(unit=3,name=fnam,type='new',carriagecontrol='list') ` 300 continue nwrite = 0 ( do 390 ii=1,10000 nrec = movdat( ii ) if( abs(nrec).ne.ii ) goto 395 T if( nrec.lt.0 ) goto 390 write(3,91)iodata(1:jjlen(iodata))  nwrite = nwrite+1 390 continue 395 continue H write(6,410)nwrite, fnam(1:jjlen(fnam)) 410 format( i5, ' records in ', a )  close(unit=2,disp='delete') tc.  else <500 continue  write(6,*)' No change ', fnam(1:jjlen(fnam))  if( iadd.eq.0 ) close(unit=2,disp='delete') h close(unit=3,disp='delete')  endif 0 isexi = .true.  endif c. \9000 continue  return $ end dc====== function isfin( cmd ) ,c. c... Set up search condition c. X character*(*) cmd  include 'dbinc.for'  character*80 sval, temp  character*2 cond(6)  data cond/'EQ','NE','GT','GE','LT','LE'/ Lc.  isfin = .false.  if( cmd.eq.'?' ) then x write(6,*)' FInd .. FInd a record'  write(6,*)' = .. To set up find condition' @ else if( cmd(1:2).eq.'FI' ) then  isfin = .true.  irec = movdat( -4 ) l250 continue  ir = abs(irec)+1 4 irec = movdat( ir )  if( ir .ne. abs(irec) ) then  write(6,310) irec,'~EOF~' ` goto 9000 endif ( if( (imod.and.2).eq.0 .and.irec.lt.0) goto 250 if( iis.ne.0 ) then temp = iodata(ifst(iis):ilst(iis)) T call jjupp(temp) if(icon.eq.1.and.sval.ne.temp(1:jjlen(sval)))goto 250  if(icon.eq.2.and.sval.eq.temp(1:jjlen(sval)))goto 250 if(icon.eq.3.and.sval.ge.temp(1:jjlen(sval)))goto 250 if(icon.eq.4.and.sval.gt.temp(1:jjlen(sval)))goto 250 H if(icon.eq.5.and.sval.le.temp(1:jjlen(sval)))goto 250 if(icon.eq.6.and.sval.lt.temp(1:jjlen(sval)))goto 250  endif t if( (imod.and.1).ne.0 ) then  call islis('LIST') < else if( irec.gt.0 ) then  write(6,310) irec,': ',iodata(1:65) 310 format(i9,10a) h else  write(6,310) irec,'- ',iodata(1:65) 0 endif c.  else if( cmd(1:2).eq.'= ' ) then \ isfin = .true.  ii = lofld( cmd ) $ if( ii.eq.0 ) then  iis = 0  else if( ii.gt.0 ) then P iis = ii 500 continue  type 91,'$',dbfmt(iis)(1:8),'? ' | read(5,91)inp  call jjupp(inp) D do 510 icon=1,6  if(inp.eq.cond(icon)) goto 515 510 continue p write(6,*)'**Illegal condition**'  write(6,*) cond 8 goto 500 c. 515 continue d type 91,'$Fld ',cond(icon),' ? '  read(5,91)sval , call jjupp(sval) c.  endif X endif 9000 continue  return  end dc====== function islis(cmd) ,c. c... Show the current record c. X character*(*) cmd  include 'dbinc.for'  character rtype*2 c.  islis = .false. L if( cmd.eq.'?' ) then  write(6,*)' LIst .. Shows the current record'  else if( cmd(1:2).eq.'LI' ) then x irec = movdat( -4 )  rtype = ':' @ if( irec.le.0 ) rtype = '-'  write(6,210) irec, rtype 210 format( i9,10a ) l do 290 ii=1,100  if( dbfmt(ii).le.' ' ) goto 295 4 write(6,91)' ', dbfmt(ii)(1:8),rtype  1 ,iodata(ifst(ii):ilst(ii)) 290 continue ` c. 295 continue ( islis = .true. endif return T end dc====== function ismov( cmd ) ,c. c... Move, and list to the n-th record c. X character*(*) cmd  include 'dbinc.for' c===  ismov = .false.  if( cmd.eq.'?' ) then L write(6,*)' nnn .. Move to record nnn'  write(6,*)' +nn .. Move + nn records'  write(6,*)' -nn .. Move - nn records' x else  decode( jjlen(cmd),210,cmd,err=9000 ) irec @210 format( i )  ismov = .true.  if( cmd(1:1).eq.'+' .or.cmd(1:1).eq.'-' ) then l jrec = irec+abs(nrec)  if( jrec.le.0 ) jrec=1 4 else  jrec = irec  endif ` if( jrec.lt.0 .or. cmd.eq.' ' ) jrec = 1+abs(nrec) nrec = movdat( jrec ) ( if( jrec.ne.abs(nrec) ) then write(6,310) nrec,'~EOF~' 310 format( i9,10a ) T endif endif  c. 9000 continue return H end dc====== function isset( cmd ) ,c. c... Set the move 'list' mode c. X character*(*) cmd  include 'dbinc.for' c.  isset = .false.  if( cmd.eq.'?' ) then L write(6,*)' /Active .. Find only active records (def)'  write(6,*)' /Delete .. Find all, inc. deleted, records'  write(6,*)' /Full .. Full record list on find' x write(6,*)' /Short .. Short record list on find (def)'  else if( cmd(1:2).eq.'/A' ) then @ imod = imod .and.-1-2  isset = .true.  else if( cmd(1:2).eq.'/D' ) then l imod = imod .or. 2  isset = .true. 4 else if( cmd(1:2).eq.'/F' ) then  imod = imod .or. 1  isset = .true. ` else if( cmd(1:2).eq.'/S' ) then imod = imod .and. -2 ( isset = .true. endif c. T return end dc====== function isund( cmd ) ,c. c... Undelete a record c. X character*(*) cmd  include 'dbinc.for' c.  isund = .false.  if( cmd.eq.'?' ) then L write(6,*) ' UNdel .. Un-Delete a record'  else if( cmd(1:2).eq.'UN' ) then  isund = .true. x call movdat( -3 )  endif @ return  end dc====== function lofld( cmd ) ,c. c... Locate a field c. Xc.out. lofld: ^Z=-1, Blank=0, Field=+N c.  character*(*) cmd  include 'dbinc.for'  character*80 inp2 Lc=== 200 continue  lofld = -1 x type 91,'$Fld Name? '  read(5,91,end=9000) inp2 @ call jjupp(inp2)  if( inp2.eq.'^Z' ) goto 9000  if( inp2.eq.' ' .or. inp2.eq.',' ) then l lofld = 0  goto 9000 4 else if( inp2.eq.'?' ) then  call islis('LIST')  goto 200 ` else do 210 ii=1,100 ( if( dbfmt(ii).le.' ' ) goto 215 inp = dbfmt(ii)(1:8) call jjupp(inp) T if( inp2.eq.inp(1:jjlen(inp2)) ) then lofld = ii  goto 9000 endif 210 continue H 215 continue type *,'**No such field**'  goto 200 tc. ....  endif <c. 9000 continue  return h end dc====== function movdat( jrec ) ,c. c.inp. jrec: Add=-1, Delete=-2, Undel=-3, Re-read=-4, c. Read = +N Xc.out. movdat: +n for not deleted, -n for deleted, +last at EOF c.  include 'dbinc.for'  character*1 trash  integer ixdel(1000) L data mxrec/10000/ c.  if( jrec.eq.-1 ) then !!Add x100 continue  read(2,91,err=110)trash @ goto 100 c. 110 continue l iadd = iadd+1  call update 4 write(2,91)iodata(1:jjlen(iodata))  nrec = 999  movdat = 999 ` c. else if( jrec.eq.-2 ) then !!Del ( idel = idel+1 ndel = ndel+1 ixdel(ndel)=nrec T movdat = -nrec c.  else if(jrec.eq.-4 ) then !!Re-Read goto 1500 c. H else if(jrec.ge.0) then !!Read if(jrec.lt.nrec) then  rewind 1 t rewind 2  nrec = 0 < if( jrec.eq.0 ) then  iodata = ' '  do 590 ii=1,100 h if( dbfmt(ii).le.' ' ) goto 595  iodata(ifst(ii):ilst(ii))=dbfmt(ii)(11:) 0590 continue 595 continue  goto 1500 \ endif  endif $c. 1110 continue  if( jrec.eq.nrec ) goto 1500 P read(1,91,err=1200)iodata  nrec = nrec+1  if(jrec.gt.nrec) goto 1110 | goto 1500 c. D1200 continue 1210 continue  read(2,91,err=1400)iodata p nrec = nrec+1  if(jrec.gt.nrec) goto 1210 8 goto 1500 c. 1400 continue d ieof = 1 c. ,1500 continue  movdat = nrec  do 1590 ii=1,ndel X if( nrec.eq.ixdel(ii) ) then  movdat = -nrec  goto 1595  endif 1590 continue L1595 continue c.  else x write(6,*)'illegal',jrec  ieof = 1 @ endif  return  end dc====== subroutine stopctc(iflag) ,c.  include 'dbinc.for' c. X call stopit  ieof = 1  return  end c====== L subroutine stopit c.  external io$_setmode,io$m_ctrlcast,stopctc xc.  ioset = %loc(io$_setmode).or.%loc(io$m_ctrlcast) @ call jjmess( sys$assign( 'TT:', ichan, , ) )  call jjmess( sys$qio( , %val(ichan), %val(ioset) , , ,  1 , stopctc, 1, , , , , ) ) l return  end 4c======  subroutine update c. ` include 'dbinc.for' character vaxtime*12, dbtime*20 ( character*3 month(12) data month/'JAN','FEB','MAR','APR','MAY','JUN' 1 ,'JUL','AUG','SEP','OCT','NOV','DEC' / T character*2 moinx(12) data moinx/'01','02','03','04','05','06'  1 ,'07','08','09','10','11','12'/ c. do 210 ii=1,100 H if( dbfmt(ii)(11:11).eq.'U' ) goto 215 210 continue  return tc. 215 continue < call date( vaxtime )  dbtime = vaxtime(8:)  do 220 jj=1,11 h if( vaxtime(4:6).eq.month(jj) ) goto 250 220 continue 0c. 250 continue  dbtime(3:4)=moinx(jj) \ dbtime(5:) =vaxtime(1:2)  if(dbtime(5:5).eq.' ')dbtime(5:5)='0' $c.  iodata(ifst(ii):ilst(ii)) = dbtime  do 310 ii=1,100 P if( dbfmt(ii)(11:11).eq.'C' ) goto 325 310 continue  return |c. 325 continue D if( iodata(ifst(ii):ilst(ii)).eq.' ' )  1 iodata(ifst(ii):ilst(ii)) = dbtime c. p return  end