Old Code - Need help

Hi there,
i need help for this old code. I know nothing about fortran. Someone here can debug this code or transform it into a modern language?
Thank you.

PROGRAM SE
REAL PI, N0,K0,IL,Z0,W0
COMPLEX J, STH
PI=4.*ATAN(1.)
J=(0.,1.)
C=3.E+08
E0=(1.E-09)/36./PI
N0=120.*PI
    FR=1.E+06
    PRINT *,"Inseration Loss in dB>0 ?"
    READ (*,*) IL
    
    PRINT *,"Separation distance (m) between Magnetic dipoles?"
    READ (*,*) Z0
  
    PRINT *, "Separation distance (m) between Electric dipoles"
    READ (*,*) W0
    SD=2.*(10**(IL/20.)-1.)/N0
    DO 30 I=1,3
    DO 20 II=1,10
    IF(II.EQ.1.AND.I.GT.1) GO TO 20
    FREQ=II*FR
    W=2.*PI*FREQ
    K0=W/C
        STH=J*K0*Z0*N0*SD/6.
        ASEH=20.*ALOG10(CABS(1.+STH))
        STE=N0*SD/K0/W0
        ASEE=20*ALOG10(STE)
        FF=20.*ALOG10(1.+5*N0*SD)
        FM=FREQ/(1.0E+06)
        PRINT 10, FM, ASEH, ASEE, FF
10 FORMAT(1X,4(1X,F8.2)/)
20 CONTINUE
     FR=10.*FR
30 CONTINUE
     END

The program compiles with gfortran, and it runs to completion (in response to all the read statements I entered 1). So what is the bug? Have you installed a compiler and tried to compile the code? ChatGPT-4 is able to translate the code to Python, and the Python program gives the same results as the Fortran one for the inputs of 1. The Python code is

import math
import cmath

# Constants
pi = math.pi
j = complex(0, 1)
c = 3e8
e0 = (1e-9) / (36 * pi)
n0 = 120 * pi
fr = 1e6

# User Input
il = float(input("Insertion Loss in dB > 0 ? "))
z0 = float(input("Separation distance (m) between Magnetic dipoles? "))
w0 = float(input("Separation distance (m) between Electric dipoles? "))

# Calculations
sd = 2 * (10**(il / 20) - 1) / n0

for i in range(1, 4):
    for ii in range(1, 11):
        if ii == 1 and i > 1:
            continue
        freq = ii * fr
        w = 2 * pi * freq
        k0 = w / c
        sth = j * k0 * z0 * n0 * sd / 6
        aseh = 20 * math.log10(abs(1 + sth))
        ste = n0 * sd / (k0 * w0)
        asee = 20 * math.log10(abs(ste))
        ff = 20 * math.log10(1 + 5 * n0 * sd)
        fm = freq / 1e6
        print(f"{fm:8.2f} {aseh:8.2f} {asee:8.2f} {ff:8.2f}")
        
    fr = 10 * fr
1 Like

i try compile online with:

And here the error code…

Inseration Loss in dB>0 ?
At line 11 of file main.f95 (unit = 5, file = ‘stdin’)
Fortran runtime error: End of file

Error termination. Backtrace:
#0 0x7f5d560af960 in ???
#1 0x7f5d560b04d9 in ???
#2 0x7f5d5630417b in ???
#3 0x7f5d562fd684 in ???
#4 0x7f5d562fe2aa in ???
#5 0x556170bc6316 in MAIN__
#6 0x556170bc68b1 in main

[Execution complete with exit code 2]

Well, apart from the use of some old programming constructs, there is nothing non-modern about it :slight_smile:

But what is failing in the run is that the program is trying to read from the keyboard and there is none in an online environment like you seem to be using. You can install a Fortran compiler on your machine, build it locally and then run it.

It runs at Online Fortran Compiler - online editor, since there is a console for input.

Oh, my misunderstanding. But then what was the input?

You need to type in the input before running the code:

image

% transfer by https://chat.baidu.com/
% Define constants
PI = 4.*atan(1.0);
J = complex(0,1);
C = 3.0e8;
E0 = (1.0e-9)/36./PI;
N0 = 120.0*PI;
FR = 1.0e6;

% Inputs
IL = input('Inseration Loss in dB>0 ? ');
Z0 = input('Separation distance (m) between Magnetic dipoles? ');
W0 = input('Separation distance (m) between Electric dipoles? ');

SD = (2.0 * (10 ^ (IL / 20.0)) - 1.0) / N0;

for I = 1:3
    for II = 1:10
        if II == 1 && I > 1
            continue;
        end
        FREQ = II * FR;
        W = 2.0 * PI * FREQ;
        K0 = W / C;
        STH = J * K0 * Z0 * N0 * SD / 6.0;
        ASEH = 20.0 * log10(abs(1 + STH));
        STE = N0 * SD / K0 / W0;
        ASEE = 20.0 * log10(STE);
        FF = 20.0 * log10(1 + 5 * N0 * SD);
        FM = FREQ / (1.0e+06);
        fprintf('%f, %f, %f, %f\n', FM, ASEH, ASEE, FF);
    end
    FR = 10.0 * FR;
end

You are using a 2020s online platform to run 1960s Fortran code, and it would help if you took a tutorial or did some reading of manuals.

I have placed a modern (free format) Fortran version on an instance of your platform, here:

mycompiler.io

The reason that your run failed is that, on the platform, you have to enter the input data to the program into the input pane (right, upper, “eingabe…”) before running the program. If you were running the program on a desktop computer in a command line/terminal window, the input would have been entered after building and running the program.

Okay…Thank you! Kartoffel :wink: