<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Calling fortran code from C in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746533#M4353</link>
    <description>You have Fortran WRITE in those subroutines. You will need to include the Fortran run-time libraries in the link, or comment out those WRITEs. Should you hit a case which activates those WRITEs, you have a potential conflict if they use the same output stream as your C code.</description>
    <pubDate>Sun, 16 May 2010 04:36:36 GMT</pubDate>
    <dc:creator>TimP</dc:creator>
    <dc:date>2010-05-16T04:36:36Z</dc:date>
    <item>
      <title>Calling fortran code from C</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746532#M4352</link>
      <description>Hi,&lt;BR /&gt;I need to compute hankel functions with complex argumant in c code. I try to use amos' codes written in fortran. I get some errors. Could you help me please? &lt;BR /&gt;&lt;BR /&gt;&lt;P&gt;$ ifort -r8 -c *.f&lt;/P&gt;&lt;P&gt;$ icc -c testhankel.c&lt;BR /&gt;&lt;BR /&gt;$ icc -o hank testhankel.o zbesh.o zbesj.o d1mach.o i1mach.o zabs_org.o zuoik.o zbknu.o zacon.o zbunk.o zmlt.o zunk1.o zunk2.o zs1s2.o zseri.o zshch.o zsqrt_org.o zdiv.o zuchk.o dgamln.o zlog_org.o zexp_org.o zairy.o zunhj.o zunik.o xerror.o zkscl.o zbinu.o zacai.o zasyi.o zmlri.o zwrsk.o zbuni.o zrati.o zuni1.o zuni2.o -lm&lt;BR /&gt;&lt;BR /&gt;d1mach.o: In function `d1mach_':&lt;BR /&gt;d1mach.f:(.text+0xa2): undefined reference to `for_write_seq_lis'&lt;BR /&gt;d1mach.f:(.text+0xbb): undefined reference to `for_write_seq_lis_xmit'&lt;BR /&gt;d1mach.f:(.text+0xe2): undefined reference to `for_write_seq_lis_xmit'&lt;BR /&gt;d1mach.f:(.text+0xff): undefined reference to `for_stop_core'&lt;BR /&gt;d1mach.f:(.text+0x12a): undefined reference to `for_stop_core'&lt;BR /&gt;i1mach.o: In function `i1mach_':&lt;BR /&gt;i1mach.f:(.text+0x4e): undefined reference to `for_write_seq_fmt'&lt;BR /&gt;i1mach.f:(.text+0x6b): undefined reference to `for_stop_core'&lt;BR /&gt;xerror.o: In function `xerror_':&lt;BR /&gt;xerror.f:(.text+0x72): undefined reference to `for_write_seq_fmt'&lt;BR /&gt;xerror.f:(.text+0xd2): undefined reference to `for_write_seq_lis'&lt;BR /&gt;xerror.f:(.text+0x116): undefined reference to `for_write_seq_fmt'&lt;/P&gt;</description>
      <pubDate>Sun, 16 May 2010 00:55:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746532#M4352</guid>
      <dc:creator>oguren</dc:creator>
      <dc:date>2010-05-16T00:55:07Z</dc:date>
    </item>
    <item>
      <title>Calling fortran code from C</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746533#M4353</link>
      <description>You have Fortran WRITE in those subroutines. You will need to include the Fortran run-time libraries in the link, or comment out those WRITEs. Should you hit a case which activates those WRITEs, you have a potential conflict if they use the same output stream as your C code.</description>
      <pubDate>Sun, 16 May 2010 04:36:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746533#M4353</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2010-05-16T04:36:36Z</dc:date>
    </item>
    <item>
      <title>Calling fortran code from C</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746534#M4354</link>
      <description>&lt;SPAN style="font-size: x-small;"&gt;&lt;P&gt;Thanks for your reply,&lt;/P&gt;&lt;P&gt;I include run-time libraries. It runs but gives wrong result. I'm confusedI write a test program in fortran named test.f and run as&lt;/P&gt;&lt;P&gt;$ifort -r8 -i4 -c test.f zbesh.f zbesj.f d1mach.f i1mach.f zabs_org.f zuoik.f zbknu.f zacon.f zbunk.f zmlt.f zunk1.f zunk2.f zs1s2.f zseri.f zshch.f zsqrt_org.f zdiv.f zuchk.f dgamln.f zlog_org.f zexp_org.f zairy.f zunhj.f zunik.f xerror.f zkscl.f zbinu.f zacai.f zasyi.f zmlri.f zwrsk.f zbuni.f zrati.f zuni1.f zuni2.f &lt;/P&gt;&lt;P&gt;$ifort -o test test.o zbesh.o zbesj.o d1mach.o i1mach.o zabs_org.o zuoik.o zbknu.o zacon.o zbunk.o zmlt.o zunk1.o zunk2.o zs1s2.o zseri.o zshch.o zsqrt_org.o zdiv.o zuchk.o dgamln.o zlog_org.o zexp_org.o zairy.o zunhj.o zunik.o xerror.o zkscl.o zbinu.o zacai.o zasyi.o zmlri.o zwrsk.o zbuni.o zrati.o zuni1.o zuni2.o&lt;/P&gt;&lt;P&gt;$./test&lt;/P&gt;&lt;P&gt;It gives totaly true result as MATLAB besselh function&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But when I call same programs from C routine , it gives &lt;SPAN style="font-family: Times New Roman TUR;"&gt;completely wrong results. my commands like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;$ icc -c testhankel.c &lt;/P&gt;&lt;P&gt;$ ifort -r8 -i4 -c zbesh.f zbesj.f d1mach.f i1mach.f zabs_org.f zuoik.f zbknu.f zacon.f zbunk.f zmlt.f zunk1.f zunk2.f zs1s2.f zseri.f zshch.f zsqrt_org.f zdiv.f zuchk.f dgamln.f zlog_org.f zexp_org.f zairy.f zunhj.f zunik.f xerror.f zkscl.f zbinu.f zacai.f zasyi.f zmlri.f zwrsk.f zbuni.f zrati.f zuni1.f zuni2.f &lt;/P&gt;&lt;P&gt;$ icc -o hank testhankel.o zbesh.o zbesj.o d1mach.o i1mach.o zabs_org.o zuoik.o zbknu.o zacon.o zbunk.o zmlt.o zunk1.o zunk2.o zs1s2.o zseri.o zshch.o zsqrt_org.o zdiv.o zuchk.o dgamln.o zlog_org.o zexp_org.o zairy.o zunhj.o zunik.o xerror.o zkscl.o zbinu.o zacai.o zasyi.o zmlri.o zwrsk.o zbuni.o zrati.o zuni1.o zuni2.o -L/RS/progs/intel/Compiler/11.1/056/lib/intel64 -lifcore -limf&lt;/P&gt;&lt;/SPAN&gt;</description>
      <pubDate>Sun, 16 May 2010 05:24:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746534#M4354</guid>
      <dc:creator>oguren</dc:creator>
      <dc:date>2010-05-16T05:24:02Z</dc:date>
    </item>
    <item>
      <title>Calling fortran code from C</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746535#M4355</link>
      <description>&lt;P&gt;You did not show any of the code in testhankel.c that gave you "wrong" results, so I content myself with giving you a C sample code that gives the same results as Fortran. I downloaded the AMOSLIB sources from Netlib, made the necessary configuration changes to d1mach.f and i1mach.f, and ran the commands&lt;BR /&gt;&lt;BR /&gt;[bash]ifort -w -c *.f &lt;BR /&gt;gcc -c testhankel.c &lt;BR /&gt;ifort -nofor-main *.o &lt;BR /&gt;./a.out [/bash] with testhankel.c containing&lt;BR /&gt;&lt;BR /&gt;[bash]#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;extern void zbesh_(double *,double *,double *,int *,int *, int *,double *,double*,int *,int *); &lt;BR /&gt;int main(int argc,char *argv[]){ &lt;BR /&gt;int i,ierr,nz,m=1,n=3,kode=2; &lt;BR /&gt;double zr=7e-2,zi=5e-2,cyr[3],cyi[3],fnu=0.0; &lt;BR /&gt;zbesh_(&amp;amp;zr,&amp;amp;zi,&amp;amp;fnu,&amp;amp;kode,&amp;amp;m,&amp;amp;n,cyr,cyi,&amp;amp;nz,&amp;amp;ierr); ...&lt;BR /&gt;[/bash] and obtained the results&lt;BR /&gt;&lt;BR /&gt;[bash] 5.0982e-01 -1.7590e+00 &lt;BR /&gt;-4.8843e+00 -6.0601e+00 &lt;BR /&gt;-1.7481e+02 -4.6887e+01 [/bash] which agree with the output &lt;BR /&gt;&lt;BR /&gt;[bash] nZ = 0 IERR = 0 &lt;BR /&gt;0.5098e+00 -0.1759e+01 &lt;BR /&gt;-0.4884e+01 -0.6060e+01 &lt;BR /&gt;-0.1748e+03 -0.4689e+02 [/bash] &lt;BR /&gt;from the equivalent Fortran driver:&lt;BR /&gt;&lt;BR /&gt;[bash] PROGRAM TZBESH &lt;BR /&gt;IMPLICIT NONE &lt;BR /&gt;DOUBLE PRECISION ZR,ZI,FNU,CYR(3),CYI(3) &lt;BR /&gt;integer m,n,nz,ierr,kode,i &lt;BR /&gt;ZR=7d-2 &lt;BR /&gt;ZI=5d-2 &lt;BR /&gt;FNU=0d0 &lt;BR /&gt;M=1 &lt;BR /&gt;N=3 &lt;BR /&gt;KODE=2 &lt;BR /&gt;CALL ZBESH(ZR, ZI, FNU, KODE, M, N, CYR, CYI, NZ, IERR) &lt;BR /&gt;write(*,*)' nZ = ',nz,' IERR = ',ierr &lt;BR /&gt;write(*,'(1x,2E12.4)')(CYR(i),CYI(i),i=1,3) &lt;BR /&gt;stop &lt;BR /&gt;end [/bash]&lt;/P&gt;</description>
      <pubDate>Sun, 16 May 2010 12:17:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746535#M4355</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2010-05-16T12:17:00Z</dc:date>
    </item>
    <item>
      <title>Hello, I need help with</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746536#M4356</link>
      <description>&lt;P&gt;Hello, I need help with hankel function.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I downloaded amoslib from netlib (zbesh.f and dependencies)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;ifort -w -c *.f&lt;BR /&gt;gcc -c -lm wire.c &lt;BR /&gt;ifort -nofor-main *.o&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;then ./a.out&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;gives me very different answer. I am suspecting&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;that the problem is in i1mach fortran routine. I did not customize d1mach because&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;i read that it gets values from i1mach.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;wire.c&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;extern&amp;nbsp; void zbesh_ (double*, double*, double*, int*, int*, int*, double*, dou&lt;BR /&gt;ble*, int*, int*);&lt;BR /&gt;&lt;BR /&gt;void main (void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; double zr = 0.07; &amp;nbsp; double zi = 0.05; &amp;nbsp; double fnu;&lt;BR /&gt;&amp;nbsp; int kode, M, N, nz, ierr, i;&lt;BR /&gt;&amp;nbsp; double cyi[2], cyr[2]; &lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; fnu = 0.0; &amp;nbsp; kode = 1; &amp;nbsp; M = 1; &amp;nbsp; N = 1;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; zbesh_(&amp;amp;zr, &amp;amp;zi, &amp;amp;fnu, &amp;amp;kode, &amp;amp;M, &amp;amp;N, cyr, cyi, &amp;amp;nz, &amp;amp;ierr);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; for (i=0; i&amp;lt;2; i++) &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("real %e\t imag %e \n", cyr&lt;I&gt;, cyi&lt;I&gt;);&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I have 64 bit laptop (cpu is&amp;nbsp; Intel(R) Core(TM) i5 CPU&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; M 450&amp;nbsp; @ 2.40GHz)&lt;/P&gt;
&lt;P&gt;and my custom i1mach.f file below&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH( 1) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH( 2) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH( 3) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH( 4) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH( 5) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH( 6) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH( 7) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH( 8) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 31 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH( 9) / 2147483647 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH(10) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH(11) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH(12) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -126 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH(13) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 127 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH(14) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 53 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH(15) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -1022 /&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA IMACH(16) /&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1023 /&lt;/P&gt;
&lt;P&gt;what am I missing here?&lt;/P&gt;
&lt;P&gt;thanks in advance&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2013 11:37:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746536#M4356</guid>
      <dc:creator>Muhammet_M_</dc:creator>
      <dc:date>2013-05-04T11:37:00Z</dc:date>
    </item>
    <item>
      <title>Quote:Muhammet M. wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746537#M4357</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Muhammet M. wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;gives me very different answer. I am suspecting that the problem is in i1mach fortran routine. I did not customize d1mach because I read that it gets values from i1mach.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;"Different answer" compared to what? For your argument values, zbesh gives&amp;nbsp;H&lt;SUB&gt;ν&lt;/SUB&gt;&lt;SUP&gt;(1)&lt;/SUP&gt;(z) = 0.600799&amp;nbsp;&amp;nbsp; - 1.635214*I, which agrees with the result from Maple.&lt;/P&gt;
&lt;P&gt;You do need to remove comment marks from the lines of d1mach.f that correspond to "IBM PC", since the routine d1mach gets called soon after entry into zbesh, and the version of d1mach provided in the Netlib amos directory does not call i1mach().&lt;/P&gt;
&lt;P&gt;Comments to IDZ forum managers: The inline code in my post of 05/16/2010 above was shown correctly in the old version of the forum. Now that this thread has been reactivated, I see that the new forum software has swallowed C include-file names, removed line endings and, in general, made the code unusable. I have tried to edit and restore the code to the point where it is &lt;I&gt;readable&lt;/I&gt; in the new forum software, but I have not run the inline code through a compiler to verify the edits.&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2013 13:24:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746537#M4357</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2013-05-04T13:24:00Z</dc:date>
    </item>
    <item>
      <title>Thanks mecej4</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746538#M4358</link>
      <description>&lt;P&gt;Thanks mecej4&lt;/P&gt;
&lt;P&gt;It worked after I uncommented the IBM PC constants. &lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2013 22:37:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-fortran-code-from-C/m-p/746538#M4358</guid>
      <dc:creator>Muhammet_M_</dc:creator>
      <dc:date>2013-05-04T22:37:56Z</dc:date>
    </item>
  </channel>
</rss>

