8.26 codegen[fortran] problem in Maple6 (17.12.00)

8.26.1 Martin Monnigmann
8.26.2 Carl DeVore (19.12.00)
8.26.3 Dr. Pengfei Shi (19.12.00)

8.26.1 Martin Monnigmann

Unfortunately I cannot resolve the following problem: I create a procedure which contains both a list of equations and an array of equations. If I run codegen[fortran], the list is translated properly, but the array is not.

Instead of the expected fortran code corresponding to the array, I only get "cjac= r", where cjac is the name of the array in the procedure, and r has not been used before anywhere.

Below you will find the complete procedure to be translated, as well as the complete output of codegen[fortran] for reference. "c" is the list of equations which is translated correctly, "cjac" is the array of equations which is turned into "cjac= r" by codegen[fortran].

If you know how I can force codegen[fortran] to translate the array correctly, please let me know.

# 
# procedure confun to be translated 
# 
confun := proc ( 
  mode::integer, 
  ncnln::integer, 
  n::integer, 
  nrowj::integer, 
  needc::integer, 
  x, 
  c, 
  cjac, 
  nstate::integer) 
 
local n_in_confun, ncnln_in_confun; 
 
declare(x = array(1 .. 3,numeric), 
  c = array(1 .. 3,numeric), 
  cjac = array(1 .. 3,1 .. 3,numeric) 
); 
 
if not n_in_confun = n then ERROR(`Error in confun: n differs from 
number of variables`) end if; 
 
if not ncnln_in_confun = ncnln then ERROR(`Error in confun: ncnln 
differs from number of equations`) end if; 
 
c := [-ksi+k0tau*exp(-8000*1/(430+200*theta))*(1-ksi), 
theta0s-kp*(theta-thetas)-kItau*phi+186.580-1.5*theta+k0tau*exp(-8000*1/(430+200*theta))*(1-ksi), 
theta-thetas]; 
 
cjac := array(1 .. 3, 1 .. 3,[(1, 
2)=1600000*k0tau*exp(-8000*1/(430+200*theta))*(1-ksi)/((430+200*theta)^2),(3, 
2)=1,(2, 3)=-kItau,(3, 3)=0,(1, 3)=0,(1, 
1)=-1-k0tau*exp(-8000*1/(430+200*theta)),(3, 1)=0,(2, 
1)=-k0tau*exp(-8000*1/(430+200*theta)),(2, 
2)=-kp-1.5+1600000*k0tau*exp(-8000*1/(430+200*theta))*(1-ksi)/((430+200*theta)^2)]); 
 
RETURN(); 
 
end proc;
 
# 
# output of codegen[fortran] 
# 
> codegen[fortran](confun); 
      subroutine confun(mode,ncnln,n,nrowj,needc,x,c,cjac,nstate) 
      integer mode 
      integer ncnln 
      integer n 
      integer nrowj 
      integer needc 
      real x(3) 
      real c(3) 
      real cjac(3,3) 
      integer nstate 
 
      real n_in_confun 
      real ncnln_in_confun 
 
        if ( .not. n_in_confun .eq. n) then 
          write(6,*) 'Error in confun: n differs from number of variable 
 
     #s' 
          call exit(0) 
        endif 
        if ( .not. ncnln_in_confun .eq. ncnln) then 
          write(6,*) 'Error in confun: ncnln differs from number of equa 
 
     #tions' 
          call exit(0) 
        endif 
        c(1) = -ksi+k0tau*exp(-8000/(430+200*theta))*(1-ksi) 
        c(2) = theta0s-kp*(theta-thetas)-kItau*phi+0.18658E3-0.15E1*thet 
 
     #a+k0tau*exp(-8000/(430+200*theta))*(1-ksi) 
        c(3) = theta-thetas 
        cjac = r 
        return 
      end
 

8.26.2 Carl DeVore (19.12.00)

I am surprised that codegen[fortran] accepts it at all. I get an error message about the array being declared with two indices but used with 1.

I suggest that you convert the array to "listlist" form:

cjac:= 
   array 
      ([ #1st row 
        [-1-k0tau*exp(-8000*1/(430+200*theta)) 
        ,1600000*k0tau*exp(-8000*1/(430+200*theta)) 
            *(1-ksi)/((430+200*theta)^2) 
        ,0 
        ] 
        , #2nd row 
        [-k0tau*exp(-8000*1/(430+200*theta)) 
        ,-kp-1.5+1600000*k0tau*exp(-8000*1/(430+200*theta)) 
            *(1-ksi)/((430+200*theta)^2) 
        ,-kItau 
        ] 
        , #3rd row 
        [0, 1, 0] 
       ]);
 

Look up the help on ?convert,listlist

8.26.3 Dr. Pengfei Shi (19.12.00)

You might want to eliminate the assignments in your square brackets and use the usually way to assign the terms to cjac, or you can assign directly to the entries of cjac.