Mix Fortran77 & C - F77 & C example

Leftblank

C calling Fortran subroutine

C Main

 
#include <string.h>
#ifdef _CRAY
#  include <fortran.h>
#  define nameage      NAMEAGE
#else
#  ifndef _AIX
#    define nameage    nameage_
#  endif
#  define _fcd          char *
#  define _cptofcd(a,b) (a)
#  define _fcdlen(a)    strlen(a)
#endif

void nameage(_fcd name, int *nlen, int *age, float *temp);

int main() {
        char *name = "Knut";
        _fcd fp;
        int nlen,age = 4;
        float temp = 98.6;

        nlen = strlen(name);
        fp = _cptofcd(name, nlen);      /* convert to Fortran string */

        nameage(fp, &nlen, &age, &temp);
        return 0;
}
 

Fortran Subroutine

 
      SUBROUTINE NAMEAGE(NAME, NLEN, AGE, TEMP)
      CHARACTER*(*) NAME
      INTEGER NLEN,AGE
      REAL TEMP
C
      WRITE(6,1000) NAME(1:NLEN),AGE,TEMP
 1000 FORMAT(1X,'Hello ',A,', who is ',I2,
     .      ' years old, has a temperature of ', f4.1)
      RETURN
      END
 

Compilation Steps

To discover which libraries are necessary for Fortran modules, compile a short Fortran test program and add the -V option (or equivalent) to get a verbose execution listing.
Leftblank
Slide 7