---
title: "Fortran and Mixed Language Codes on the FASRC cluster"
id: "5369"
type: "epkb_post_type_1"
slug: "fortran-and-mixed-language-codes-on-odyssey"
published_at: "2010-01-05T19:57:59+00:00"
modified_at: "2024-04-29T15:31:33+00:00"
url: "https://docs.rc.fas.harvard.edu/kb/fortran-and-mixed-language-codes-on-odyssey/"
markdown_url: "https://docs.rc.fas.harvard.edu/kb/fortran-and-mixed-language-codes-on-odyssey.md"
excerpt: "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 NAN C PROGRAM checknum IMPLICIT NONE REAL fnum INTEGER isnan INTEGER..."
taxonomy_epkb_post_type_1_category:
  - "Languages"
---

# 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 NAN`  
`C`  
`PROGRAM checknum`  
`IMPLICIT NONE`  
`REAL fnum`  
`INTEGER isnan`  
`INTEGER isinf`  
`INTEGER isit`  
`fnum=log(0.)`  
`isit=isinf(fnum)`  
`WRITE (*,*) isit`  
`STOP`  
`END`  
`[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=gcc`  
`F77=g77`  
`CFLAGS=-g`  
`FFLAGS=-g`  
`LIB=-lm`  
`RM=/bin/rm -f`  
`EXE = cfortran`  
`OBJ = 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 $*.c`  
`clean:`  
`$(RM) $(EXE) $(OBJ) *~`

`This gives:`

`[hptc@iliadaccess02 cfortran]$ make`  
`g77 -g -o cfortran.o -c cfortran.f`  
`gcc -g -o checknan.o -c checknan.c`  
`g77 -g -o cfortran cfortran.o checknan.o -lm`  
`[hptc@iliadaccess02 cfortran]$ ./cfortran`  
`1`

As *log(0)* is infinite, the program answers 1.

Last UpdatedApril 29, 2024
