rem *_______________ section 5.1 __________________*
rem *         HISTORICAL STOCK PRICE FILE	   *
rem *         ---------------------------	   *
rem *	UPDATED: February 5, 1983		   *
rem *	BY:	 Edward A. Valenzuela		   *
rem *	VERSION: 1.31				   *
rem *______________________________________________*

rem *--- requires subroutines ---
rem          juldate%.bas
rem          stkprice.bas ... for jump vectors     
rem          scrnin.bas

5500 rem 

if end #8 then 5529
if end #9 then 5539

OPEN "B:STKPRICE.DAT" AS 8
OPEN "B:STKFIL01.DAT" recl 80 AS 9 

GOSUB 320	: rem .. read price file header
  dummy$ = fn.juldate$(newdate$)
  dummy  = val(dummy$)
  nitem%=nstk% + 1

print "current date is "; newdate$ ; " = "; dummy

  FOR I%=1 TO NSTK%
    GOSUB 325	: rem ... read all prices
    GOSUB 310	: rem ... read all names
  NEXT I%
    GOSUB 325	: rem .. S&P 500 price
	
 goto 5517

5529 print "file B:STKPRICE.DAT not found"
 goto 5517
5539 print "file B:STKFIL01.DAT not found"

5517 CLOSE 8,9
 
5508  if end #4 then 5519
  print clear$; fn.down$(2); \
      fn.right$(10); "PRICE HISTORY FILE"
  print down$; fn.right$(15); "option list"; down$
  print fn.right$(4); "0 = RETURN to main menu"
  print fn.right$(4); "1 = STORE prices in DAILY FILE"
  print fn.right$(4); "2 = STORE prices in WEEKLY FILE"
  print fn.right$(4); "3 = STORE prices in MONTHLY FILE"
  print fn.right$(4); "4 = STORE prices in QUARTERLY FILE"
  print fn.right$(4); "5 = STORE prices in ANNUAL FILE"

print down$; fn.line$(17); fn.right$(10); bell$ ;
  input "SELECT option number: "; option%

if option% <= 0 or option% > 5 then goto 900
ON option% goto 5501,5502,5503,5504,5505

5501 filename$ = "B:DAYHST.DAT"
     goto 5507

5502 filename$ = "B:WEEKHST.DAT"
     goto 5507

5503 filename$ = "B:MONTHST.DAT"
     goto 5507

5504 filename$ = "B:QUARTHST.DAT"
     goto 5507

5505 filename$ = "B:YEARHST.DAT"
     goto 5507

5507 OPEN FILENAME$ RECL 8 AS 4    
  GOTO 5511
5519 REM ... no file exists, create one ...
     CREATE FILENAME$ RECL 8 AS 4
5511 if end #4 then 5521

rem ... find size of data file ...
  area% = size( filename$ )
  print "size of "; filename$; " is "; area%; " Kbytes"
 if area% < 1024 then goto 5523
 
rem ... FN.LAST.BLK% FINDS THE NUMBER OF THE FIRST RECORD OF THE LAST
rem ... BLOCK OCCUPIED BY A RELATIVE FILE ...

DEF FN.LAST.BLK%(FILE.NAME$,REC.SIZE%)
    FILE.SIZE% = SIZE(FILE.NAME$)
    FN.LAST.BLK% = ((FILE.SIZE% - 1) * 1024)/ REC.SIZE% + 1
    RETURN
FEND

rem ... find END-OF-FILE by reading all records in last block ...
  read #4, fn.last.blk%(FILENAME$,8); num1%

5523 WHILE -1
  	read #4 ; dum1%
     WEND

5521 rem ... end of file on stock history file found ...
 print "EOF on unit #4 : "; filename$

rem ... print date, number of items ...
print #4 ; dummy
print #4 ; nitem%

rem ... print the prices to file ...

    print #4 ; NEWPRICE(nitem%)	: rem ... S&P 500
  FOR I%=1 TO NSTK%  
    print #4 ; NEWprice(I%)
  NEXT I%

CLOSE 4

REM -------------------- END OF HISTORY FILE----------------
REM                          SUBROUTINE

goto 5508
5509 RETURN
