Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29273 Discussions

How to call c function from Fortran (CVF)

chstoyer
Beginner
785 Views

Hi,

I am still using CVF as I have still not gotten my new IVF to compile my projects and have not had time to sort it out.

I am trying to call a c routine FLOATTOIBM from Fortran 90. the .c file is part of my project.

CALL FloatToIbm(SR%TRACES(1,I),TRACE,,SR%NSAMP,1)

I have tried various naming conventions including upper and lower case with and without the underline character and I always get the message

Compiling...
IBMFormat.c
Linking...
LINK : warning LNK4075: ignoring /EDITANDCONTINUE due to /INCREMENTAL:NO specification
LINK : warning LNK4098: defaultlib "LIBCD" conflicts with use of other libs; use /NODEFAULTLIB:library
Segyout.obj : error LNK2001: unresolved external symbol _FLOATTOIBM@20
Debug/ixseg2segy.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

ixseg2segy.exe - 2 error(s), 2 warning(s)

What do I need to do to get the system to recognize the c program?

I have looked in the Fortran Help and do not seem to be able to find anything useful.

Thanks, Charles

/* Assumes sizeof(int) == 4 */
extern void __stdcall _FLOATTOIBM(int from[], int to[], int n, int endian)
/**********************************************************************
float_to_ibm - convert between 32 bit IBM and IEEE floating numbers
***********************************************************************
Input:
from input vector
n number of floats in vectors
endian =0 for little endian machine, =1 for big endian machines

Output:
to output vector, can be same as input vector

***********************************************************************
Notes:
Up to 3 bits lost on IEEE -> IBM

IBM -> IEEE may overflow or underflow, taken care of by
substituting large number or zero

Only integer shifting and masking are used.
***********************************************************************
Credits: CWP: Brian Sumner
***********************************************************************/
{
register int fconv, fmant, i, t;

for (i=0;i fconv = from;
if (fconv) {
fmant = (0x007fffff & fconv) | 0x00800000;
t = (int) ((0x7f800000 & fconv) >> 23) - 126;
while (t & 0x3) { ++t; fmant >>= 1; }
fconv = (0x80000000 & fconv) | (((t>>2) + 64) << 24) | fmant;
}
if(endian==0)
fconv = (fconv<<24) | ((fconv>>24)&0xff) |
  ; ((fconv&0xff00)<<8) | ((fconv&0xff0000)>>8);

to = fconv;
}
return;
}

0 Kudos
2 Replies
Steven_L_Intel1
Employee
785 Views
Remove the leading underscore from the routine name in the C code and the extra comma in the argument list in the Fortran code.
0 Kudos
chstoyer
Beginner
785 Views

Thank you! I should have known. I started out without the underscore, and I should have realized that asking for IBMTOIEEE@20 when there were only 4 arguments was a dead giveaway.

Charles

0 Kudos
Reply