Simh/i1401 with FortranII on docker

[Run Fortran From Cards](http://ibm-1401.info/RunFortranFromCards.html)にカードデッキからFORTRANのプログラムを実行する方法が書かれています。
これを使ってDocker上のSimhエミュレータで試してみます。
マニュアルは「Fortran Specifications and Operating Procedures IBM 1401」([C24-1455-2](http://ibm-1401.info/pictures/1401FortranSpecOP-C24-1455-2.pdf))です。
[v3m4-part1.o](http://ibm-1401.info/pictures/Fortran/v3m4-part1.o)、[v3m4-part2.o](http://ibm-1401.info/pictures/Fortran/v3m4-part2.o)と[Example_Program_2.f](http://ibm-1401.info/pictures/Fortran/Example_Program_2.f)をダウンロードします。

```
/simh # mkdir fortran
/simh # cd fortran
/simh/fortran # wget http://ibm-1401.info/pictures/Fortran/v3m4-part1.o
Connecting to ibm-1401.info (45.40.183.1:80)
v3m4-part1.o         100% |****************************************************************|  7857  0:00:00 ETA
/simh/fortran # wget http://ibm-1401.info/pictures/Fortran/v3m4-part2.o
Connecting to ibm-1401.info (45.40.183.1:80)
v3m4-part2.o         100% |****************************************************************|  169k  0:00:00 ETA
/simh/fortran # wget http://ibm-1401.info/pictures/Fortran/Example_Program_2.f
Connecting to ibm-1401.info (45.40.183.1:80)
Example_Program_2.f  100% |****************************************************************|   860  0:00:00 ETA
/simh/fortran #
```
Fortranのプログラムを実行するには、コンパイラのカードデッキの間にFortranのプログラムを挟みます。以下の例では適宜空白行を削除しています。

```
/simh/fortran # cat v3m4-part1.o Example_Program_2.f v3m4-part2.o > fort.cd
```
カードデッキができたので、これを実行します。

```
/simh/fortran # i1401

IBM 1401 simulator V4.0-0 Current        git commit id: 9e719822
SET LPT FORTRAN
at cdr fort.cd
at lpt -n printer.txt
sim> sim> sim> LPT: creating new file: printer.txt
b cdr
sim>
HALT instruction, IS: 280 (H 280)
!cat printer.txt
sim> START OF FORTRAN COMPILATION

MACHINE SIZE SPECIFIED IS 08000
ACTUAL MACHINE SIZE IS 16000
                                                                                         PAGE    1
SEQ   STMNT      FORTRAN STATEMENT

      C          APPENDIX E   SAMPLE PROBLEM 2   PAGE 50 OF C24-1455-2
      C          EXERCISE LIBRARY FUNCTIONS AND PUNCH OBJECT DECK
  1              PRINT 8
  2   8           FORMAT(48H1A=2I(SQRT(1-COS(X)**2)COS(X)SIN(X)/ABS(SIN(X))))
  3              PRINT 1
  4   1          FORMAT(97H0 I   DEGREES            A         EXPONENTIAL(A)=B
              1  LOGARITHM(B)=C        I SIN(2X)=D     C-D//)
  5              FI=1.0
  6              DEGREE=7.5
  7              DELTA=1.57079632679489661923/12.0
  8              ARG=DELTA
  9   3          A=(FI+FI)*SQRTF(1.0-COSF(ARG)**2)*COSF(ARG)
 10              IF(FI-24.)7,7,6
 11   6          A=-A
 12   7          B=EXPF(A)
 13              C=LOGF(B)
 14              D=FI*SINF(ARG+ARG)
 15              DIFF=C-D
 16              PRINT 2,FI,DEGREE,A,B,C,D,DIFF
 17   2          FORMAT(1X,F3.0,F9.1,F19.10,E19.10,2F19.10,E12.1)
 18              FI=FI+1.0
 19              DEGREE=DEGREE+7.5
 20              ARG=ARG+DELTA
 21              IF(FI-49.0)3,4,5
 22   4          PRINT 9
 23   9          FORMAT(1H1)
 24              STOP 111
 25   5          STOP 777
 26              END

  653 INPUT CHARACTERS

MODULUS IS  5
MANTISSA IS 20
  STORAGE ASSIGNMENT-ARRAYS + EQUATED VARIABLES
NO ARRAYS

STORAGE ASSIGNMENT - SIMPLE VARIABLES

ARG            4301     30/
DEGREE         4323     32T
FI             4345     34V
DIFF           4367     36X
D              4389     38Z
C              4411     41/
B              4433     43T
A              4455     45V
DELTA          4477     47X

CONSTANTS LOCATED FROM 07924 TO 07999   I2U-I9Z

             STARTING ADDRESS OF STATEMENTS

     SEQ                  STARTING ADDRESS       DISPLAY

     001                52W             4526         53|
     003                53X             4537         54/
     005                54Y             4548         55S
     006                56|             4560         56U
     007                57S             4572         57W
     008                58Y             4588         59S
     009                60|             4600         60U
     010                66|             4660         66U
     011                68Y             4688         69S
     012                70/             4701         70V
     013                71U             4714         71Y
     014                72X             4727         73/
     015                74Y             4748         75S
     016                76U             4764         76Y
     018                77V             4775         77Z
     019                79/             4791         79V
     020                80X             4807         81/
     021                82T             4823         82X
     022                85Z             4859         86T
     024                87|             4870         87U
     025                87Z             4879         88T
     027                88Y             4888         89S

END OF COMPILATION

PRESS START TO GO

g
sim>
HALT instruction, IS: 4875 (B 4870)
(省略)
END OF COMPILATION

PRESS START TO GO

A=2I(SQRT(1-COS(X)**2)COS(X)SIN(X)/ABS(SIN(X)))

 I   DEGREES            A         EXPONENTIAL(A)=B     LOGARITHM(B)=C        I SIN(2X)=D     C-D

 1.      7.5       0.2588190451   0.1295399375E 01       0.2588190451       0.2588190451     0.4E-19
 2.     15.0       1.9937934244   0.7343337389E 01       1.9937934244       1.9937934244     0.0E 00
 3.     22.5       2.1500504667   0.8585291657E 01       2.1500504667       2.1500504667     0.0E 00
 4.     30.0       3.8930534390   0.4906046117E 02       3.8930534390       3.8930534390     0.0E 00
 5.     37.5       4.8663167987   0.1298418016E 03       4.8663167987       4.8663167987     0.0E 00
 6.     45.0       5.8395801585   0.3436350381E 03       5.8395801585       5.8395801585     0.0E 00
 7.     52.5       6.8128435182   0.9094531804E 03       6.8128435182       6.8128435182     0.0E 00
 8.     60.0       7.7861068780   0.2406928851E 04       7.7861068780       7.7861068780     0.0E 00
 9.     67.5       8.7593702377   0.6370098667E 04       8.7593702377       8.7593702377     0.0E 00
10.     75.0       9.7326335974   0.1685889345E 05       9.7326335974       9.7326335974     0.0E 00
11.     82.5      10.7058969572   0.4461819244E 05      10.7058969572      10.7058969572     0.0E 00
12.     90.0      11.6791603169   0.1180850394E 06      11.6791603169      11.6791603169     0.0E 00
13.     97.5      12.6524236767   0.3125199783E 06      12.6524236767      12.6524236767     0.0E 00
14.    105.0      13.6256870364   0.8271050873E 06      13.6256870364      13.6256870364     0.0E 00
15.    112.5      14.5989503962   0.2188989098E 07      14.5989503962      14.5989503962     0.0E 00
16.    120.0      15.5722137559   0.5793306492E 07      15.5722137559      15.5722137559     0.0E 00
17.    127.5      16.5454771156   0.1533237426E 08      16.5454771156      16.5454771156    -0.1E-17
18.    135.0      17.5187404754   0.4057815702E 08      17.5187404754      17.5187404754     0.0E 00
19.    142.5      18.4920038351   0.1073928147E 09      18.4920038351      18.4920038351     0.0E 00
20.    150.0      19.4652671949   0.2842222882E 09      19.4652671949      19.4652671949     0.0E 00
21.    157.5      20.4385305546   0.7522133521E 09      20.4385305546      20.4385305546     0.0E 00
22.    165.0      21.4117939144   0.1990783097E 10      21.4117939144      21.4117939144     0.0E 00
23.    172.5      22.3850572741   0.5268741014E 10      22.3850572741      22.3850572741     0.0E 00
24.    180.0      23.3583206339   0.1394407653E 11      23.3583206339      23.3583206339     0.0E 00
25.    187.5     -24.3315839936   0.2709738212E-10     -24.3315839936      24.3315839936    -0.5E 02
26.    195.0     -25.3048473533   0.1023869083E-10     -25.3048473533      25.3048473533    -0.5E 02
27.    202.5     -26.2781107131   0.3868668546E-11     -26.2781107131      26.2781107131    -0.5E 02
28.    210.0     -27.2513740728   0.1461768557E-11     -27.2513740728      27.2513740728    -0.5E 02
29.    217.5     -28.2246374326   0.5523262821E-12     -28.2246374326      28.2246374326    -0.6E 02
30.    225.0     -29.1979007923   0.2086953645E-12     -29.1979007923      29.1979007923    -0.6E 02
31.    232.5     -30.1711641521   0.7885511985E-13     -30.1711641521      30.1711641521    -0.6E 02
32.    240.0     -31.1444275118   0.2979524697E-13     -31.1444275118      31.1444275118    -0.6E 02
33.    247.5     -32.1176908715   0.1125807359E-13     -32.1176908715      32.1176908715    -0.6E 02
34.    255.0     -33.0909542313   0.4253840252E-14     -33.0909542313      33.0909542313    -0.7E 02
35.    262.5     -34.0642175910   0.1607304904E-14     -34.0642175910      34.0642175910    -0.7E 02
36.    270.0     -35.0374809508   0.6073168954E-15     -35.0374809508      35.0374809508    -0.7E 02
37.    277.5     -36.0107443105   0.2294734562E-15     -36.0107443105      36.0107443105    -0.7E 02
38.    285.0     -36.9840076703   0.8670607960E-16     -36.9840076703      36.9840076703    -0.7E 02
39.    292.5     -37.9572710300   0.3276171617E-16     -37.9572710300      37.9572710300    -0.8E 02
40.    300.0     -38.9305343898   0.1237894795E-16     -38.9305343898      38.9305343898    -0.8E 02
41.    307.5     -39.9037977495   0.4677360356E-17     -39.9037977495      39.9037977495    -0.8E 02
42.    315.0     -40.8770611092   0.1767331116E-17     -40.8770611092      40.8770611092    -0.8E 02
43.    322.5     -41.8503244690   0.6677824747E-18     -41.8503244690      41.8503244690    -0.8E 02
44.    330.0     -42.8235878287   0.2523202526E-18     -42.8235878287      42.8235878287    -0.9E 02
45.    337.5     -43.7968511885   0.9533869524E-19     -43.7968511885      43.7968511885    -0.9E 02
46.    345.0     -44.7701145482   0.3602353247E-19     -44.7701145482      44.7701145482    -0.9E 02
47.    352.5     -45.7433779080   0.1361141862E-19     -45.7433779080      45.7433779080    -0.9E 02
48.    360.0     -46.7166412677   0.5143046896E-20     -46.7166412677      46.7166412677    -0.9E 02
```
カードデッキからではなく、テープからコンパイル&実行するには[1401 FORTRAN & SIMH](http://ibm-1401.info/1401-FORTRAN-SIMH.html)に書かれている[v3m4.simh.mt1](http://ibm-1401.info/v3m4.simh.mt1)を使います。
今回は、iniファイルを用いてみます。まずは作成ですね。

```
/simh/fortran # cat > fortran.ini
at mt1 v3m4.simh.mt1
at cdr Example_Program_2.f
set lpt fortran
at -n lpt Listing
b mt1
c
q
/simh/fortran #
```
できたら、起動します。実行結果はListingに出力されます。

```
/simh/fortran # i1401 fortran.ini

IBM 1401 simulator V4.0-0 Current        git commit id: 9e719822
/simh/fortran/fortran.ini-1> at mt1 v3m4.simh.mt1
Tape Image 'v3m4.simh.mt1' scanned as SIMH format.
contains 92030 bytes of tape data (319 records, 2 tapemarks)
A potentially unreasonable number of record sizes(69) vs tape marks (2) have been found
The tape format (SIMH) might not be correct for the 'v3m4.simh.mt1' tape image
/simh/fortran/fortran.ini-4> at -n lpt Listing
LPT: creating new file: Listing

HALT instruction, IS: 280 (H 280)

HALT instruction, IS: 4875 (B 4870)
Goodbye
/simh/fortran # cat Listing
START OF FORTRAN COMPILATION

MACHINE SIZE SPECIFIED IS 08000
ACTUAL MACHINE SIZE IS 16000

                                                                                          PAGE    1
SEQ   STMNT      FORTRAN STATEMENT

      C          APPENDIX E   SAMPLE PROBLEM 2   PAGE 50 OF C24-1455-2
      C          EXERCISE LIBRARY FUNCTIONS AND PUNCH OBJECT DECK
  1              PRINT 8
(省略)
47.    352.5     -12.1644951198   0.5212269879E-05     -12.1644951198     -12.1644951198     0.0E 00
48.    360.0       0.0000000000   0.1000000000E 01       0.0000000000       0.0000000000    -0.1E-15
/simh/fortran #
```
比べてみたことなかったが、カードデッキとテープからの起動で実行結果が違うんですが、、