So far, all my FTN95 programs have been single units, that is, a main program with no other units. That single unit is in a file.
I’d like to extend to using additional units but have run into procedural issues. In particular, I want the main program to be in one file and an external function to be in another file. All my efforts to compile and run have been unsuccessful. I’ve only been able to get this to work if I merge the two units into a single file, perhaps using an INCLUDE statement. Can I do it with two separate files?
Here is the code in the two separate files:
(C:\Kalish_data\FORTRAN source\95\Fortran 95 Counihan\ch07p109\ch07p109_ex_003_Main.f95) WINAPP !for CLEARWIN PROGRAM Main ! ! Fortran 95, Martin Counihan ! Chapter 7, Introducing external procedures, page 109 ! Section 7.1, Functions page 109 ! ! The text provides a FUNCTION Cot(x) which determines the Cotangent ! of x, an angle given in radians. This is the main program which ! obtains an angle in degrees and uses the FUNCTION Cot to determine ! the Cotangent of an angle in degrees. ! IMPLICIT NONE REAL:: Cot, AngDeg, AngRad, CoTangent, Pi = 3.14159265358979 ! WRITE(,) 'Please enter an angle in degrees. We will & &determine its Cotangent. ...' READ(,) AngDeg AngRad = AngDegpi/180. WRITE(,) 'The angle = ', AngRad, ' in radians.' CoTangent = Cot(AngRad) WRITE(,*) 'The cotangent = ', CoTangent ! END PROGRAM Main
(C:\Kalish_data\FORTRAN source\95\Fortran 95 Counihan\ch07p109\ch07p109_ex_003_Function.f95) WINAPP !for CLEARWIN FUNCTION Cot(x) ! ! Fortran 95, Martin Counihan ! Chapter 7, Introducing external procedures, page 109 ! Section 7.1, Functions page 109 ! ! The text provides a FUNCTION Cot(x) which determines the Cotangent ! of x, an angle given in radians. This is that FUNCTION. ! IMPLICIT NONE REAL:: Cot, eps, s, c REAL, INTENT(IN):: x !Can use x but can't modify it. ! eps = EPSILON(x) Singularity: IF ((-eps.LE.x).AND.(x.LE.eps)) THEN WRITE(,) 'Error: cotangent function called with a zero argument' Cot = Huge(x) ELSE Singularity s = SIN(x) c = COS(x) Cot = c/s END IF Singularity ! END FUNCTION Cot
If I compile the FUNCTION in Plato, it says, “*** No main, WinMain or LibMain function *** Compilation” If I compile the Main program in Plato, it is successful.
I’m not able to get anywhere with project in Plato.
If I compile the Main program in Command Prompt with FTN95.exe, I get
WARNING the following symbols are missing: COT c:\Kalish_data\FORTRAN source\95\Fortran 95 Counihan\ch07p109\lgotemp@.obj (C:\KALISH_DATA\FORTRAN SOURCE\95\FORTRAN 95 COUNIHAN\CH07P109\CH07P109_EX_003_MAIN.F95) Creating executable: .EXE.exe Creating Linker map file: .MAP.map
If I compile the Function in Command Prompt with FTN95.exe, I get
*** No main, WinMain or LibMain function *** Compilation abandoned
Also, I haven’t been able to compile the two units so as to obtain .OBJ files for use with SLINK.exe.
There must be some way to do this.
Thanks, Dan
