MDLIB77.OLB a Mr. Dave Software Product January 11, 1981 MDLIB77 is a library of useful subroutines that works with the F77 compiler. This document is a list of routines available and instructions for their use. The routines are accessed at task building time: >TKB TKB>yourprog=yourprog TKB>DL2:[200,6]MDLIB77/LB TKB>// or >TKB yourprog=yourprog,DL2:[200,6]MDLIB77/LB Only those routines needed by yourprog are included in the task image. The programs in MDLIB77 are already in object file format (.OBJ extension). See Dave Thorson for program listings. ============================================================================ AZTO09(VAL,RET,ISIZE) Converts an array of ASCII characters to a real number. VAL is a LOGICAL*1 array of length ISIZE RET returns a real number or is unchanged if VAL contains non-numeric information. Blanks are ignored; if VAL contains only blanks RET is set to 0. Only the rightmost decimal point is used. Any minus sign negates the value to be put in RET. EXAMPLES: CALL AZTO09(VAL,RET,8) ('b' = blank) Call: Return: VAL RET RET 12345bbb 0. 12345. 176E11bb 12345. 12345. -56bbbbb 12345. -56. -32.4-5b 12345. 32.45 -.2-.3.- 32.45 -23. Pbbbbbbb -23. -23. bbbbbbbb -23. 0. ======================================================================== BITINT(I,IBIT) Subroutine converts binary pattern to integer. I is the integer returned; IBIT is LOGICAL*1 array of length 16. Bit pattern is defined as: 15|14 13 12|11 10 9|8 7 6|5 4 3|2 1 0 Example: (Note: IBIT(1)=bit 0, IBIT(2)=bit 1, etc.) LOGICAL*1 IBIT(16) DATA IBIT/0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0/ CALL BITINT(I,IBIT) I is returned with the value of 10, since Binary: 0|0 0 0|0 0 0|0 0 0|0 0 1|0 1 0 or Octal: 0 0 0 0 1 2 = "12 Integer: 1*8 + 2*1 = 10 INTBIT(I,IBIT) Subroutine returns bit pattern of I in IBIT; I is an integer, IBIT is a LOGICAL*1 array of length 16. Bit pattern ia defined as: 15|14 13 12|11 10 9|8 7 6|5 4 3|2 1 0 Example: (Note: IBIT(1)=bit 0, IBIT(2)=bit 1, etc.) LOGICAL*1 IBIT(16) CALL INTBIT(39,IBIT) WRITE(5,1) IBIT 1 FORMAT(16I3) Displays: 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 Bit Pattern is 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 which is octal 0| 0 | 0 | 0 | 4 | 7 = 47; octal 47 = decimal 39. ========================================================================== IGET(IVAR,IDIGIT) Function to return a single digit from an integer number stored in IVAR. The IDIGIT describes which position is desired: 12345. Returns 0 if IDIGIT invalid. Example: IVAR=21367 I=IGET(IVAR,1) J=IGET(IVAR,2) K=IGET(IVAR,3) L=IGET(IVAR,6) Now I=2, J=1, K=3 and L=0. ========================================================================= IPUT(IVAR,IDIGIT,IVAL,IADIF1) Function changes single digits in integer variable IVAR. IDIGIT defines the position (12345). If IADIF1=0, IVAL is stored in position IDIGIT of IVAR. If IADIF1=1, IVAL is added to current value of IGET(IVAR,IDIGIT) (see IGET above) IF IADIF1=-1, IVAL is subtracted from IGET(IVAR,IDIGIT). Note that the sign of IVAR is disregarded, only the magnitude of each digit is considered. If ABS(IVAR) will be greater than 29999, error results. Other values of IADIF1 than 1,0,-1 cause error. "error" means IVAR will be unchanged; value of function will be set to 1. If the intended value of a digit is less than 0 or greater than 9, error also results; IVAR unchanged. IPUT(...)=0 implies success. Example: IVAR=0 N=IPUT(IVAR,2,3,0) IVAR=03000, IPUT=0 N=IPUT(IVAR,3,5,0) IVAR=03500, IPUT=0 N=IPUT(IVAR,3,4,1) IVAR=07500, IPUT=0 N=IPUT(IVAR,3,2,-1) IVAR=07300, IPUT=0 N=IPUT(IVAR,3,5,-1) IVAR=07300, IPUT=1 N=IPUT(IVAR,1,3,0) IVAR=07300, IPUT=1 PROMPT(N,IDS,I,X,A) Subroutine prompts for single integer, real or byte response (similar to READ). If N=1, returns integer in I; N=2 returns real in X; N=3 returns character in A. IDS is status: 1=success; 0=invalid N; -1=end-of-file during read (CNTRL-Z entered). Re-prompts if error encountered. Example: LOGICAL*1 A CALL PROMPT(3,IDS,I,X,A) IF(IDS.LT.0) GOTO 100 IF(A.EQ.'R') GOTO 10 , etc. ======================================================================== RINIT(IS1,IS2) Subroutine initializes random number seeds IS1 and IS2 based on system clock. (RINIT uses starts with 0,0 and calls RAN(IS1,IS2) from 50 to 1000 times, depending on SECNDS(0.0), a system routine) Example: CALL RINIT(IS1,IS2) X=RAN(IS1,IS2) ============================================================================ YESNO(I) Subroutine reads user response from terminal; returns I=1 for yes, I=0 for no, I=-1 for end-of-file during read (CNTRL-Z entered). Must get Y,y,N,n or CNTRL-Z from user before returning; otherwise re-prompts for YES/NO. Example: TYPE *,'DO YOU WISH TO RUN AGAIN ?' CALL YESNO(I) IF(I.EQ.1) GOTO 10 when run, results in: DO YOU WISH TO RUN AGAIN ? why ANSWER YES OR NO: no (also rings bell) ============================================================================ SUBROUTINE TCS(I,J,K,L) Terminal Control Subroutine Routine takes the mess out of several commands which control terminal characteristics, including several escape sequences and QIO commands. A knowledge of QIO commands and escape sequences is helpful but not required. I and J are function selectors, K and L are parameter values. I and J define functions to be performed by their bit patterns as follows: (bits numbered: 16|15 14 13|12 11 10| 9 8 7| 6 5 4| 3 2 1| so octal 13, or 0| 0 | 0 | 0 | 1 | 3 | in binary, 1011: 0| 0 | 0 | 0 | 0 0 1| 0 1 1| would mean bits 4, 2 and 1 are set) a,b, and c refer to the terminal type the commands below refer to; a=VT100, b=VT52, c=ADDS 100. Commands sent to the wrong terminal are ignored, as are unused bits in I and J words. Bit I functions Set (escape sequences to terminal) --- ------------------------------ 1 abc clear screen, leave cursor in upper left corner 2 abc ring bell 3 a reverse video (white background, dark characters) 4 a normal video (dark background, white characters) 5 a set screen to 80 column mode 6 a set screen to 132 column mode 7 abc absolute screen addressing, leaves cursor at row K, column L 8 a set scrolling margins; begin at row K, end at row L 9 a select smooth scrolling 10 a select jump scrolling 11 ab enable alternate keypad 12 ab enable numeric keypad 13 ac set character atttributes K and L, in the order K,L: K or L character attribute 0 all attributes off 1 bold intensity on (c: half intensity) 4 underscore on 5 blink on 7 reverse video on note: for type c terminal, only two attributes may be active at once. The order of K and L makes no difference. Attribute 0 is set first, then the others; (0,4), (4,0), and (4,4) all have the same effect as do (1,7) and (7,1). See code below (statement label 13) and ADDS Regent 100 user's guide for more information. 14 a programmable LED's defined by K and L K or L LED status 0 all LED's off 1 LED 1 on 2 LED 2 on 3 LED 3 on 4 LED 4 on 15 a reset terminal 16 abc clear screen from cursor to end, don't move cursor For details on I word functions, see terminal user's guides. Bit J word functions (QIO/ MCR functions) Set (J word functions work for all terminals) --- ------------------------------------- 1 SET /LOWER=TI: 2 SET /NOLOWER=TI: 3 SET /FDX=TI: 4 SET /NOFDX=TI: 5 SET /SLAVE=TI: 6 SET /NOSLAVE=TI: 7 SET /BUF=TI: (buffer size returned in K) 8 SET /BUF=TI:K (buffer set to decimal size in K) 9 SET /TERM=TI: (terminal type returned in L: 0=unknown, 9=VT52, 13=VT100) 10 SET /TERM=TI:L (set terminal to type sent in L; types defined above) 11 SET /ECHO=TI: enables echo (default) 12 SET /NOECHO=TI: disables echo 13 SET /TYPEAHEAD=TI: set typeahead buffer to 36 characters 14 SET /NOTYPEAHEAD=TI: set buffer to 1 character 15 empty typeahead buffer (characters lost) 16 return no. characters in typeahead buffer in K For details on J word functions, see I/O DRIVERS MANUAL and the MCR OPERATIONS manual. PROGRAMMING EXAMPLE To clear the screen, ring the bell, set terminal to full duplex and leave the cursor at row 10, column 40: bit pattern, I word: 0|000|000|001|000|011 (bits 1,2,7 set) octal value: 0 0 0 1 0 3 = "103 (or decimal 67) bit pattern, J word: 0|000|000|000|000|100 (bit 3 set) octal value: 0 0 0 0 0 4 = "4 CALL TCS("103,"4,10,40) is the subroutine call. Integer values can be used instead of octal values, but this is an extra conversion you don't need to make. The above example could also be: CALL TCS(67,4,10,40). Warning: J word functions 7 and 9 change the value of K Functions are performed in the order listed; I-1 to 16, J-1 to 15. TCS does not require a priviledged account or any other special considerations. ============================================================================ SUBROUTINE SCRADR(IR,IC,AR,AC) SCReen ADRess subroutine for VT100 terminal in ANSI mode. Routine to convert screen coordinates from 1,24 (row) and 1,132 (column) to character format, returned in real variables AR,AC. Useful when using ANSI compatible escape sequences for screen addressing on VT100 or similar terminal: ESC[r;cf or ESC[r;cH where r and c represent the row and column to which the cursor will be moved. Upper left corner of screen is 1,1. AR takes the characters [ijk, AC takes ;ijk where i,j, and k are the hundreds, tens and ones digits of IR and IC. TYPICAL USE: ICOL=K+3 CALL SCRADR(20,ICOL,AROW,ACOL) WRITE(5,300) "33,AROW,ACOL 300 FORMAT(X,A1,2A4,'HTest Results') This example writes "Test Results" starting at row 20, col. K+3. For example, if k+3=45, the write statement is equivalent to: WRITE(5,300) "33 300 FORMAT(X,A1,'[20;45H','Test Results') [if integer numbers are output, they must have leading zeros. Embedded blanks will abort the escape sequence; thus this routine.] SCRADR can also be used for other 2-parameter ANSI escape sequences by changing the character following AC. For example, CALL SCRADR(10,20,AROW,ACOL) WRITE(5,300) "33,AROW,ACOL 300 FORMAT(X,A1,2A4,'r') This sets the scrolling region from row 10 to row 20. CHAR(A,C) Subroutine to place an ASCII value into a CHARACTER substring. Opposite of FORTRAN ICHAR function. Example: LOGICAL*1 A CHARACTER*1 C A="101 ("101 is the ASCII code for 'A'; 65 also works) CALL CHAR(A,C) Now C contains the substring 'A'. Note that C=A is not allowed by FORTRAN. NOTE: All ASCII characters less than space ("40) and the DEL character ("177) will be returned as a ?, with the exception of HT ("11) which returns a tab character. ========================================================================= CONCAT(A,LEN(A),B,LEN(B),C,LEN(C)) Subroutine concatenates B to the end of A and stores the result in C. The end of A is defined as the rightmost character position in A (i.e., NUMBR(A,LA)). Use of LEN(A), etc., instead of an integer value, guarantees that the correct value will be sent. Example: CHARACTER*10 A,B,C A='ABC' B=' FGH' CALL CONCAT(A,LEN(A),B,LEN(B),C,LEN(C)) Now C contains the string 'ABC FGH' ========================================================================== NUMBR(A,LEN(A),N) Subroutine returns the number of characters in A, excluding blanks padded at the right. Example: CHARACTER*20 A A='ABCDE' CALL NUMBR(A,LEN(A),N) N is set to 5 A='A B C D E' CALL NUMBR(A,LEN(A),N) N is set to 9 The value of N returned will be from 0 to LEN(A). ========================================================================== LPAD(A,LEN(A),N) Subroutine pads the LEFT end of string A with N blanks. If N is negative, up to |N| blanks will be removed from the left end of A. Example: CHARACTER*10 A A='ABCD GHI' Contents of A: CALL LPAD(A,LEN(A),3) ' ABCD G' CALL LPAD(A,LEN(A),-1) ' ABCD G ' CALL LPAD(A,LEN(A),-10) 'ABCD G ' CALL LPAD(A,LEN(A),5) ' ABCD ' CALL LPAD(A,LEN(A),-LEN(A)) 'ABCD ' SQUEEZ(A,LEN(A),N) Subroutine squeezes out from A all groups of N or more blanks. N<1 is the same as N=1, N>LEN(A) is the same as N=LEN(A). Example: CHARACTER*20 A A='A C E HI K' CALL SQUEEZ(A,LEN(A),0) A contains 'ACEHIK' A=' B D G KL N Q S' CALL SQUEEZ(A,LEN(A),2) A contains ' B DGKL NQ S' A=' TEST' CALL SQUEEZ(A,LEN(A),INDEX(A,'T')-1) A contains 'TEST' ========================================================================== DAO(NUM,LUNF,LUNT) Subroutine for outputting text from a file to a terminal or another file. The user creates a sequential text file (for example, TEXT.TXT) containing messages the program will output. Subroutine ININDX (see below) is called to transform this sequential file into a direct access file with a .DAX extension (for example, TEXT.DAX). The .DAX file is used by the program; the original file is closed. The importance of this routine is that it allows large amounts of textual information to used in a program very quickly while also greatly reducing the size of the task image. NUM is a reference number (ref#). It must be an integer from 1 to 9999. In the sequential text file it must start in column 1; leading zeroes may be used. When DAO is called with NUM, all text lines between that ref# and either a higher ref# or the end of the file are output. LUNF (Logical Unit Number From) is the lun associated with the .DAX file by the ININDX routine (see below). LUNT (logical Unit Number To) is the lun associated with the terminal, file, or other device to receive output from DAO. The sequential text file must be created with EDI, KED, etc. It has only a few restrictions: -Text lines cannot start with a number or dot in column 1. -Ref#'s must start in column 1, 1') Program will print out: [@ABCDEFGHIJKLMNO....] <1234567890123456> ------------------------------------------------------------------------ MAG(I) Function returns (magnitude of I) + 1, for use in variable format statements. If I is negative, the magnitude returned is increased by one to allow for the minus sign on output. The magnitude is always increased by one to put a space in front of the number on output. I must be integer. Examples: MAG(5)=2, MAG(-3)=3, MAG(123)=4, MAG(0)=2, MAG(-12345)=7 Typical use: I=-27 J=4123 WRITE(5,1) I,J 1 FORMAT(' I =',I' units for J(',I,')') This will print out: I = -27 units for J(4123)