Contact us Heritage collections Image license terms
HOME ACL ACD ICF SUS DCS G&A STARLINK Literature
Further reading □ OverviewProgress May 1981 - May 1982PERQ Locations September 1982Recognition of SUS Request December 19821. Support of Perqs and Suns2. PERQ User Notes3. Kent Software Tools4. Guide PNX 5.05. PERQ Software6. Mixing Modules8. User ForumPerq3A
C&A INF CCD CISD Archives Contact us Heritage archives Image license terms

Search

   
ACDSingle User SystemsPERQ PapersInternal
ACDSingle User SystemsPERQ PapersInternal
ACL ACD C&A INF CCD CISD Archives
Further reading

Overview
Progress May 1981 - May 1982
PERQ Locations September 1982
Recognition of SUS Request December 1982
1. Support of Perqs and Suns
2. PERQ User Notes
3. Kent Software Tools
4. Guide PNX 5.0
5. PERQ Software
6. Mixing Modules
8. User Forum
Perq3A

Mixing Modules Compiled by FORT or F77 in Executable Files

Trudy Watson

12 February 1986

Common Base Programme: PERQ User Note 6

1. Introduction.

At present Perq users are in an interim situation with the new Optimising Fortran compiler (FORT) available but the libraries already used (GKS and NAG) being compiled by the F77 Compiler. ICL have given some guidelines about compiling programs using a mixture of FORT and F77 compiled object modules. This note expands on the guidelines and gives examples of calling NAG and GKS from a FORT main program.

2. I/O libraries in FORT and F77.

Each compiler sets up the object module being compiled to do i/o using its own set of routines and data structures. These are unique to each compiler so you cannot freely mix i/o calls in modules compiled by different compilers.

3. ICL's statement.

In the PPSN for FORT ICL have given the following guidelines for mixing FORT compiled modules and F77 compiled modules. They are as follows:

New Object files output by the Optimising Fortran Compiler may be loaded with existing object files output by the f77 compiler, but two constraints should be borne in mind if this is done:

  1. i/o on a file should be restricted to the set of source files compiled by the same compiler.
  2. The loader must be made to search the run time libraries of both compilation systems to ensure that all external references are satisfied. If the main program is compiled with the Optimising Fortran Compiler this could be done by calling fort(l) but including the following libraries in the loaders search list.
    /usr/lib/libI77.a 
    /usr/lib/libF77.a 
    /usr/lib/libm.a
    

4. Notes on the statement.

The statement above needs to be expanded on and in some places it is misleading.

In section a) also note that if preconnected files are being used the modules concerned must be compiled with the same compiler as the main program. Otherwise the program will probably give a run-time error.

Both compilation systems use buffered i/o. This means that output will not necessarily be written to files in the order in is performed by the program. This is not usually critical.

The FORT i/o system does not ensure that all buffers are flushed and files closed when a program terminates abnormally. For example when a NAG routine gives a hard error (and terminates the program) you may find no output is written at all.

Remember that when a file is opened for reading it has to have rewind done on it before anything can be read from it.

Compiling and linking files as suggested in section b) often will not complete. It fails with a multiply defined symbol. Instead it is better and easier to compile and link programs the following way:

fort -c main.f subp1.f 
f77 main.o subp1.o sub2.f your lib. a -lFORT

Do not do what is suggested in b).

f77 -c sub.f 
fort main.f sub.o lib.a -1F77 -1I77 -1m

For example to compile a GKS program and a NAG program (the sources are attached).

fort -c main.f 
f77 main.o -lgks -lFORT
fort -c nag.f 
f77 nag.o yournagl.a -lFORT

5. Examples.

There follows an example program using GKS and an example using NAG.

      program main 
* This program is the main module for the GKS test with mixed Fort and 
* F77 compiled modules.
*
* unit 2 is explicitly opened for reading.
* unit 3 is preconnected.
* unit 4 is explicitly opened for writing.
* unit 8 is used by GKS for error messages.
* unit 0 is used for error messages.
*
*      Data for Ship's Outline 
      INTEGER NSHIP 
      PARAMETER (NSHIP = 18) 
      REAL XSHIP(NSHIP), YSHIP(NSHIP) 
      DATA XSHIP /0.20,0.10,0.40,0.42,0.50,0.52,0.58,0.56,0.64,
     :   0.66,0.72,0.70,0.78,0.78,0.92,0.92,0.90,0.20/ 
     :   YSHIP /0.12,0.22,0.20,0.26,0.26,0.32,0.32,0.26,0.26,
     :   0.32,0.32,0.26,0.26,0.20,0.20,0.14,0.12,0.12/ 
      CHARACTER*5 str 
      open (unit=2,file='fort.2') 
      rewind(2 ) 
      open (unit=4,file='fort.4') 
      read(2,99999) str 
      write(4,*) 'the start' ,str 
      write(3,*) 'the preconnected start' 
      CALL GOPKS(8) 
      CALL GCWKC'gksdisp',ICONID) 
      CALL GOPWK(1,ICONID,501) 
      CALL GACWK(l) 
* End of standard opening sequence
*---------------------------------------------------------------------
CALL GPL (NSHIP , XSHIP , YSHIP)
*---------------------------------------------------------------------
*        Deactivate and close workstation, close GKS. The utility 
*        DISCONNECT WORKSTATION (GDWK) closes the PNX window.
      CALL GDAWK (1) 
* This second GDAWK will cause an error message to be written to fort.8 
      CALL GDAWK(1) 
      CALL GCLWK (1) 
      PAUSE 
      CALL GDWK (ICONID) 
      CALL GCLKS 
99999 FORMAT (A5) 
      END
*
* This program is the example of how to mix NAG routines and FORT compiled 
* main programs.
* input is on units 5 and 7 preconnected 
* output is on units 6 and 8 
* errors are reported on unit 0 
      DOUBLE PRECISION S07AAF, TITLE(7), X, Y, Z 
      INTEGER NIN, NOUT, NIN2, NOUT2, L IFAIL, IFAIL1 
      DATA NIN /5/, NOUT /6/, NIN2 /7/, NOUT2 /8/ 
      READ (NIN,99999) TITLE 
      WRITE (NOUT,99998) (TITLE(I),I=1,6) 
      WRITE (NOUT,99997) 
      READ (NIN2,99999) TITLE 
      WRITE (NOUT2,99998) (TITLE(I),I=1,6) 
      WRITE (NOUT2,99997) 
      Z=1.0D-13 
      X=1.570796326794DO
C 
   20 X=X+Z 
      Y=S07AAF(X,IFAIL)
      WRITE (NOUT,99995) IFAIL1, X, Y,Z, IFAIL 
      WRITE (NOUT2,99995) IFAIL1, X, Y,Z, IFAIL 
      IF (X.GT.1.5707963267947DO) GO TO 30 
      IF (X.LT.1.570796326795DO) GO TO 20 
      GO TO 40 
 30   CLOSE (NOUT2)
      GO TO 20 
 40   STOP 
99999 FORMAT (6A4, lA3) 
99998 FORMAT (4(1X/), lH ,5A4, lA3, 7HRESULTS/lX) 
99997 FORMAT (6H ENTRY, 51X, 4HEXIT/6H IFAIL, 8X, lHX, 33X, lHY, * 27X, 5HIFAIL) 
99996 FORMAT (I5, F20.5) 
99995 FORMAT (4X, 12, 2X, lPD28.20, lX, lPD28.20, lX, lPD28.20, 5X, 12) 
      END
⇑ Top of page
© Chilton Computing and UKRI Science and Technology Facilities Council webmaster@chilton-computing.org.uk
Our thanks to UKRI Science and Technology Facilities Council for hosting this site