OS/8 Fortran IV frustration

40 views
Skip to first unread message

Paul R. Bernard

unread,
Sep 28, 2025, 6:40:43 PMSep 28
to pid...@googlegroups.com
I have an array of integers that range from 0 to 999 that I wanted to
print as a continuous stream with leading zeros for values that are less
than three digits long. ie. iarray(1)=4, iarray(2)=10, iarray(3)=123,
iarray(4)=0 would print as:

004010123000

Everything I tried failed miserably. I had to resort to a wasteful
kludge where I mapped the values to characters in a 1000 element array
to be able to print the values with leading zeros:

...

INTEGER I2A(1000)

...

C BUILD THE 0-999 INTEGER TO ASCII LOOKUP TABLE FOR PRINTING

IDX = 1
DO 70 I=0,9
DO 80 J=0,9
DO 90 K=0,9
CALL CPUT( I2A(IDX), 1, 48+I )
CALL CPUT( I2A(IDX), 2, 48+J )
CALL CPUT( I2A(IDX), 3, 48+K )
IDX = IDX + 1
90 CONTINUE
80 CONTINUE
70 CONTINUE

... Printing final integer values

WRITE(4, 1030) (I2A(IGET(PTR(J))+1), J=1, TXTIDX-1)
1030 FORMAT( X1, 30A3 )

(The IGET(PTR(J)) is just gymnastics, think of it as iarray(J)
accesses.)

The whole point of this exercise was only to run the front panel with a
"meaningful" calculation for some definition of "meaningful". (I didn't
want the blinking to be purely random.) So even the horrendous kludge
is fit for purpose, but it really does bug me.

Is it possible in fortran IV on OS/8 to take an array of such integers
and an appropriate FORMAT code to print values less than 100 with
leading zeros?

- paul

Rick Murphy

unread,
Sep 28, 2025, 8:48:01 PMSep 28
to Paul R. Bernard, pid...@googlegroups.com
The FORMAT statement in OS/8 FORTRAN IV has for integers just a width - I3 for an integer 3 characters wide. There's no way to zero-fill.
What I would try in a case like this is a SUBROUTINE to print the number.  
        IF (I .GT. 99) WRITE(4, 10) I
        IF (I .GT. 10) WRITE (4, 20)I
        IF (I .LT. 10) WRITE (4, 20) I
        RETURN
10    FORMAT(1X, I3, $)
20    FORMAT(1X, '0', I2, $)
30    FORMAT(1X, '00', I1, $)

--
You received this message because you are subscribed to the Google Groups "PiDP-8" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pidp-8+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pidp-8/864ismqjz5.fsf%40downspout.ca.


--
Rick Murphy, D. Sc., CISSP-ISSAP, K1MU/4, Annandale VA USA

timr...@gmail.com

unread,
Sep 29, 2025, 11:31:29 AMSep 29
to PiDP-8
Your third write appears to have an error.  Did you not mean WRITE (4,30) for two leading zeros?  Otherwise looks fine to me.  I have not worked in Fortran in years.

Steve Tockey

unread,
Sep 29, 2025, 12:48:17 PMSep 29
to timr...@gmail.com, PiDP-8

Fortran IV does not have a simple way to force printing of leading zeros.  An earlier discussion of a Fortran IV program to print the digits of Pi resulted in the code below. IBUF is the array of integer values between 000 and 999. LBUF is the number of values in the IBUF array to print out. I believe that NGRP and NCNT for line-wrapping. In the original code, NGRP and NCNT are pre-initialized to 10 and 0 respectively. This code has been tested and works fine:

C       ---WRITE THE DECIMALS---
        DO 260 IK=2,LBUF
C       --PAD LEADING ZEROS IF NECESSARY--
        IF ((IBUF(IK) .LT. 100) .AND. (IBUF(IK) .GE. 10)) GOTO 205
        IF (IBUF(IK) .LT. 10) GOTO 210
        GOTO 229
205     WRITE(4,206) IBUF(IK)
206     FORMAT('+0',I2,$)
        GOTO 231
210     WRITE(4,211) IBUF(IK)      
211     FORMAT('+00',I1,$)
        GOTO 231
229     WRITE(4,230) IBUF(IK)
230     FORMAT('+',I3,$)
231     NCNT = NCNT + 1
        IF (NCNT .EQ. NGRP) GOTO 240
        GOTO 260
240     WRITE(4,250)
250     FORMAT(' ')
        NCNT = 0
260     CONTINUE



-- steve


Rick Murphy

unread,
Sep 29, 2025, 6:19:06 PMSep 29
to timr...@gmail.com, PiDP-8
Yup, typo. should be WRITE(4,30).
    -Rick

Reply all
Reply to author
Forward
0 new messages