Search Docs by Keyword
Fortran and Mixed Language Codes on the FASRC cluster
In order to cross-compiled mixed Fortran and C code on the cluster using GNU compilers, let us look at the following simple codes:
$ cat cfortran.f
C Check for NANCPROGRAM checknumIMPLICIT NONEREAL fnumINTEGER isnanINTEGER isinfINTEGER isitfnum=log(0.)isit=isinf(fnum)WRITE (*,*) isitSTOPEND[hptc@iliadaccess02 cfortran]$ cat checknan.c#include #include int isnan_(float *fnum){if (isnan( *fnum) != 0){return 1;}return 0;}int isinf_(float \*fnum){if (isinf(\*fnum) != 0){return 1;}return 0;}Note: The underscores in the C function names are necessary.
Use the following Makefile:
$ cat Makefile
CC=gccF77=g77CFLAGS=-gFFLAGS=-gLIB=-lmRM=/bin/rm -fEXE = cfortranOBJ = cfortran.o checknan.o$(EXE): $(OBJ) Makefile$(F77) $(FFLAGS) -o $(EXE) $(OBJ) $(LIB).f.o:$(F77) $(FFLAGS) -o $*.o -c $*.f.c.o:$(CC) $(CFLAGS) -o $*.o -c $*.cclean:$(RM) $(EXE) $(OBJ) *~This gives:
[hptc@iliadaccess02 cfortran]$ makeg77 -g -o cfortran.o -c cfortran.fgcc -g -o checknan.o -c checknan.cg77 -g -o cfortran cfortran.o checknan.o -lm[hptc@iliadaccess02 cfortran]$ ./cfortran1As log(0) is infinite, the program answers 1.
