<?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 I see! Then I fix my code to in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Some-Problems-about-using-ODRPACK95/m-p/1124310#M132452</link>
    <description>&lt;P&gt;I see! Then I fix my code to pass 3D array. It works! Thanks for teaching!&lt;/P&gt;</description>
    <pubDate>Tue, 03 Jan 2017 12:36:15 GMT</pubDate>
    <dc:creator>yan__san-chi</dc:creator>
    <dc:date>2017-01-03T12:36:15Z</dc:date>
    <item>
      <title>Some Problems about using ODRPACK95</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Some-Problems-about-using-ODRPACK95/m-p/1124306#M132448</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;

&lt;P&gt;I have some questions about passing arguments from C to Fortran with ISO_C_BINDING.&lt;/P&gt;

&lt;P&gt;1. In ODRPACK, there are arguments need to pass 3D array, for example in wrapper code &lt;SPAN style="font-size: 13.008px;"&gt;with ISO_C_BINDING&lt;/SPAN&gt;&amp;nbsp;for ODRPACK95 :&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;!!!!!Optional variable
    !!!!!!!!Unfinished
    
    integer(c_int), optional :: IFIXB(1:NP),IFIXX(:,:),JOB,NDIGIT,MAXIT&amp;amp;
    ,IPRINT,LUNERR,LUNRPT,INFO
    
    real(c_double),  optional :: WE(1:N,1:NQ,1:NQ),WD(1:N,1:M,1:M),&amp;amp;
        TAUFAC,SSTOL,PARTOL,STPB(1:NP),STPD(:,:),&amp;amp;
        SCLB(1:NP),SCLD(:,:),LOWER(1:NP),UPPER(1:NP)
    
     integer(c_int), optional,pointer :: IWORK(:)
    real(c_double), optional :: DELTA(1:N,1:M),WORK(:)
    &lt;/PRE&gt;

&lt;P&gt;In C, how to pass WD to Fortran? My C code shown below&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;extern "C" {

    void wrapper_ODR(void(*f)(int *N, int *M, int *NP, int *NQ, int *LDN, int *LDM, int *LDNP, \
        double BETA[2], double XPLUSD[4][1], int IFIXB[2], int IFIXX[1][4], int *LDIFX, \
        int *IDEVAL, double F[1][4], double FJACB[1][2][4], double FJACD[1][1][4], int*ISTOP), \

        int N,int M,int NP,int NQ,double BETA[],double Y[][4],double X[][4],\
        double DELTA[][4],double WE[],double WD[1][1][4],int IFIXB[],int IFIXX[],\
        int *JOB,int *NDIGIT,double *TAUFAC,double *SSTOL, double *PARTOL,\
        int *MAXIT, int *IPRINT, int *LUNERR, int *LUNRPT,double STPB[],\
        double STPD[], double SCLB[], double SCLD[], double WORK[], double IWORK[],\
        int *INFO, double LOWER[2], double UPPER[]);

}


int main(){

	int NP = 2, N = 4, M = 1, NQ = 1;
	double BETA[2] = { 2.0, 0 };
	double X[1][4] = { 0.0, 1.0, 2.0, 3.0 };
	double Y[1][4] = { 2.0, 5.0, 8.0, 11.0 };
	double UPPER[2] = { 2.5, 1 };
	double WD[1][1][4];

	for (int i = 0; i &amp;lt; 4; i++){
		if (i == 0){
			WD[1][1]&lt;I&gt; = 0.05;
		}
		else {

			WD[1][1]&lt;I&gt; = 1;
		}
	}

	wrapper_ODR(&amp;amp;FCN, N, M, NP, NQ, BETA, Y, X, NULL, NULL, WD, NULL, NULL, NULL, NULL, NULL, \
		NULL, NULL,NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, NULL, NULL, NULL, \
		NULL, UPPER);&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;In extern "C" function prototype, WD is declared 3D array with size, and in "int main",&lt;/P&gt;

&lt;P&gt;I set value for WD then call wrapper_ODR. But results(as attached file) show&amp;nbsp;&lt;SPAN style="font-size: 1em;"&gt;it's not correct I expected.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;It looks like I have wrong code for 3D array, well actually I don't know how to pass 3D array to Fortran.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;2. &amp;nbsp; Data type of a&lt;SPAN style="font-size: 13.008px;"&gt;rgument "DELTA" &lt;/SPAN&gt;is array with pointer in ODRPACK, how to use it in C?&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2016 08:48:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Some-Problems-about-using-ODRPACK95/m-p/1124306#M132448</guid>
      <dc:creator>yan__san-chi</dc:creator>
      <dc:date>2016-12-31T08:48:33Z</dc:date>
    </item>
    <item>
      <title>Unlike the older ODRPACK, the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Some-Problems-about-using-ODRPACK95/m-p/1124307#M132449</link>
      <description>&lt;P&gt;Unlike the older ODRPACK, the main ODRPACK-95 subroutine takes quite a few arguments that are arrays of assumed shape. To call ODRPACK-95 from C, you would need to pass not just the base address of the array and leading dimension(s), but descriptors.&lt;/P&gt;

&lt;P&gt;This can certainly be done if necessary, but doing so correctly needs that you know the structure of these descriptors, use the header file ISO_Fortran_binding.h containing declarations of the descriptor structures, and assign correct values to all the components of all the descriptors. This is considerably more complicated than to call ODRPACK-95 from Fortran or to call ODRPACK-77 from C.&lt;/P&gt;

&lt;P&gt;The function argument, FCN, however, is more straightforward to write in C, since it does not have any assumed-shape arguments. Here, for example, is the C version of FCN for the DRIVE1.F example in the ODRPACK-95 distribution.&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;math.h&amp;gt;

void FCN(int *pn, int *pm, int *pnp, int *pnq, int *pldn, int *pldm, int *pldnp,
         double *pbeta, double *pxplusd,
         int *pifixb, int *pifixx, int *pldifx,
         int *pideval, double *pf, double *pfjacb,double *pfjacd,
         int *istop){
int i, l, nq=*pnq, n=*pn, ldn=*pldn, ldm=*pldm, ldnp=*pldnp, ideval=*pideval;
double *beta=pbeta-1;
if(beta[1] &amp;lt; 0.0){
        *istop = 1; return;
        }
else istop = 0;
if(ideval % 10)
        for(l=0; l&amp;lt;nq; l++)for(i=0; i&amp;lt;n; i++){
           double xp = exp(beta[3]*pxplusd&lt;I&gt;) - 1.0;
           pf[i+l*ldn] = beta[1] + beta[2]*xp*xp;
           }
if((ideval/10) % 10)
        for(l=0; l&amp;lt;nq; l++)for(i=0; i&amp;lt;n; i++){
           double xp = exp(beta[3]*pxplusd&lt;I&gt;);
           pfjacb[i+l*ldn*ldnp] = 1.0;
           pfjacb[i+ldn+l*ldn*ldnp] = (xp-1.0)*(xp-1.0);
           pfjacb[i+2*ldn+l*ldn*ldnp] = 2*beta[2]*(xp-1.0)*xp*pxplusd&lt;I&gt;;
           }
if((ideval/100) % 10)
        for(l=0; l&amp;lt;nq; l++)for(i=0; i&amp;lt;n; i++){
           double xp = exp(beta[3]*pxplusd&lt;I&gt;);
           pfjacd[i+l*ldn*ldm] = 2*beta[2]*(xp-1.0)*xp*beta[3];
           }
return;
}&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2016 17:11:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Some-Problems-about-using-ODRPACK95/m-p/1124307#M132449</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2016-12-31T17:11:00Z</dc:date>
    </item>
    <item>
      <title>Hi! </title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Some-Problems-about-using-ODRPACK95/m-p/1124308#M132450</link>
      <description>&lt;P&gt;Hi!&amp;nbsp;&lt;/P&gt;

&lt;P&gt;2D array like X,Y I can pass C array to Fortran, but in the same way for passing 3D array WD to Fortran above,&amp;nbsp;&lt;SPAN style="font-size: 1em;"&gt;I got unusual(as attached file) value. I don't know why?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jan 2017 10:33:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Some-Problems-about-using-ODRPACK95/m-p/1124308#M132450</guid>
      <dc:creator>yan__san-chi</dc:creator>
      <dc:date>2017-01-01T10:33:23Z</dc:date>
    </item>
    <item>
      <title>Quote:yan, san-chi wrote: 2D</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Some-Problems-about-using-ODRPACK95/m-p/1124309#M132451</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;yan, san-chi wrote:&lt;BR /&gt;&amp;nbsp;&lt;SPAN style="font-size: 1em;"&gt;2D array like X,Y I can pass C array to Fortran, but in the same way for passing 3D array WD to Fortran above,&amp;nbsp;I got unusual(as attached file) value. I don't know why?&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em;"&gt;&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;I already stated in #2 why this will not work. The main file odr.f of ODRPACK-95 applies the intrinsic function SIZE to several assumed shape array arguments in many places. Since your C program passes only the base address of the array, instead of a descriptor as the Fortran subroutine expects, the latter will pull a wrong value for the size of the array and compute garbage results after that.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jan 2017 17:47:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Some-Problems-about-using-ODRPACK95/m-p/1124309#M132451</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2017-01-01T17:47:13Z</dc:date>
    </item>
    <item>
      <title>I see! Then I fix my code to</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Some-Problems-about-using-ODRPACK95/m-p/1124310#M132452</link>
      <description>&lt;P&gt;I see! Then I fix my code to pass 3D array. It works! Thanks for teaching!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2017 12:36:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Some-Problems-about-using-ODRPACK95/m-p/1124310#M132452</guid>
      <dc:creator>yan__san-chi</dc:creator>
      <dc:date>2017-01-03T12:36:15Z</dc:date>
    </item>
  </channel>
</rss>

