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.
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.
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:
/usr/lib/libI77.a /usr/lib/libF77.a /usr/lib/libm.a
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
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