1
$\begingroup$

Before updating to Mathematica 9.0, I have successfully generated beautiful Fortran code using Mark Sofroniou's Format.m package, which is posted on MathSource.

However, after updating to the latest Mathematica, version 9.0, the program can't work; the following error displayed when running the code:

Clear["Global`*"];
<< format`Format`
(* -> Get::noopen: Cannot open format`Format`. >> *)

Could anyone tell me how to set up Format.m in Mathematica 9.0?

$\endgroup$
6
  • $\begingroup$ Looks like you simply haven't placed the file in the correct location or are loading it using an incorrect path. $\endgroup$ Commented Feb 9, 2014 at 1:14
  • $\begingroup$ Hi OleKsandr, thanks for your kindly reply. Where should I put the file? I have put it to the same path of the program I running. $\endgroup$
    – Tang Laoya
    Commented Feb 9, 2014 at 1:22
  • $\begingroup$ The documentation describes how packages should ordinarily be set up. If you don't do it that way, you do at least have to put it in one of the directories on $Path, and load it as Format.m, not just Format`. Alternatively, just load the file using the front end and click the "Run Package" button. $\endgroup$ Commented Feb 9, 2014 at 1:32
  • $\begingroup$ Thanks for your kindly reply. I tried your last option: just load the file and click the 'Run Package' button, however, the following errors displayed: Get::noopen: Cannot open UtilitiesFilterOptions. >> Needs::nocont: Context UtilitiesFilterOptions was not created when Needs was evaluated. >> $\endgroup$
    – Tang Laoya
    Commented Feb 9, 2014 at 1:54
  • $\begingroup$ reference.wolfram.com/mathematica/Compatibility/tutorial/… $\endgroup$ Commented Feb 9, 2014 at 2:36

1 Answer 1

0
$\begingroup$

The problem was solved after I used this file: https://github.com/Expander/FlexibleSUSY/blob/master/meta/Format.m

and put it to here: C:\Users\tang\AppData\Roaming\Mathematica\Applications\format

Thanks

Update:

there is another problem:

v = Det[{{1, 1, 1, 1}, {x1, x2, x3, x4}, {y1, y2, y3, y4}, {z1, z2, 
     z3, z4}}]/6;
b1 = -Det[{{1, 1, 1}, {y2, y3, y4}, {z2, z3, z4}}];
c1 = Det[{{1, 1, 1}, {x2, x3, x4}, {z2, z3, z4}}];
d1 = -Det[{{1, 1, 1}, {x2, x3, x4}, {y2, y3, y4}}];
b2 = Det[{{1, 1, 1}, {y1, y3, y4}, {z1, z3, z4}}];
c2 = -Det[{{1, 1, 1}, {x1, x3, x4}, {z1, z3, z4}}];
d2 = Det[{{1, 1, 1}, {x1, x3, x4}, {y1, y3, y4}}];
b3 = -Det[{{1, 1, 1}, {y1, y2, y4}, {z1, z2, z4}}];
c3 = Det[{{1, 1, 1}, {x1, x2, x4}, {z1, z2, z4}}];
d3 = -Det[{{1, 1, 1}, {x1, x2, x4}, {y1, y2, y4}}];
b4 = Det[{{1, 1, 1}, {y1, y2, y3}, {z1, z2, z3}}];
c4 = -Det[{{1, 1, 1}, {x1, x2, x3}, {z1, z2, z3}}];
d4 = Det[{{1, 1, 1}, {x1, x2, x3}, {y1, y2, y3}}];
bcdv = {b1, c1, d1, b2, c2, d2, b3, c3, d3, b4, c4, d4, v};
FortranAssign[bcdv, bcdv, OptimizationSymbol -> tmp]

It will give the following express:

    tmp90=-z3
    tmp93=-z1
    tmp100=-z4
    tmp87=-z2
    bcdv(1)=y3*z2-y4*z2-y2*z3+y4*z3+y2*z4-y3*z4
    bcdv(2)=-(x3*z2)+x4*z2+x2*z3-x4*z3-x2*z4+x3*z4
    bcdv(3)=x3*y2-x4*y2-x2*y3+x4*y3+x2*y4-x3*y4
    bcdv(4)=-(y3*z1)+y4*z1+y1*z3-y4*z3-y1*z4+y3*z4
    bcdv(5)=x3*z1-x4*z1-x1*z3+x4*z3+x1*z4-x3*z4
    bcdv(6)=-(x3*y1)+x4*y1+x1*y3-x4*y3-x1*y4+x3*y4
    bcdv(7)=y2*z1-y4*z1-y1*z2+y4*z2+y1*z4-y2*z4
    bcdv(8)=-(x2*z1)+x4*z1+x1*z2-x4*z2-x1*z4+x2*z4
    bcdv(9)=x2*y1-x4*y1-x1*y2+x4*y2+x1*y4-x2*y4
    bcdv(10)=-(y2*z1)+y3*z1+y1*z2-y3*z2-y1*z3+y2*z3
    bcdv(11)=x2*z1-x3*z1-x1*z2+x3*z2+x1*z3-x2*z3
    bcdv(12)=-(x2*y1)+x3*y1+x1*y2-x3*y2-x1*y3+x2*y3
    bcdv(13)=x4*(y3*(tmp87+z1)+y1*(tmp90+z2)+y2*(tmp93+z3))+x3*(y2*(
 &  tmp100+z1)+y4*(tmp93+z2)+y1*(tmp87+z4))+x1*(y3*(tmp100+z2)+y4*(t
 &  mp87+z3)+y2*(tmp90+z4))+x2*(y4*(tmp90+z1)+y1*(tmp100+z3)+y3*(tmp
 &  93+z4))

However, that's not most efficient, the most efficient code is like the following:

x1=x(2)-x(1)
y1=y(2)-y(1)
z1=z(2)-z(1)
x2=x(3)-x(2)
y2=y(3)-y(2)
z2=z(3)-z(2)
x3=x(4)-x(3)
y3=y(4)-y(3)
z3=z(4)-z(3)
x4=x(1)-x(4)
y4=y(1)-y(4)
z4=z(1)-z(4)
B1=Y3*Z2-Y2*Z3
B2=Y3*Z4-Y4*Z3
B3=Y1*Z4-Y4*Z1
B4=Y1*Z2-Y2*Z1
C1=X2*Z3-X3*Z2
C2=X4*Z3-X3*Z4
C3=X4*Z1-X1*Z4
C4=X2*Z1-X1*Z2
D1=X3*Y2-X2*Y3
D2=X3*Y4-X4*Y3
D3=X1*Y4-X4*Y1
D4=X1*Y2-X2*Y1
V=(x(1)*b1+x(2)*b2+x(3)*b3+x(4)*b4)/6.0d0

So my question is: how to let mathematica generate most efficient Fortran code?

Thanks, Tang Laoya

$\endgroup$
2
  • $\begingroup$ Hello Tang Laoya, I've marked this question as a "simple mistake", since it was mainly about placing it in the correct path (and a minor fix for FilterOptions). Regarding the new question you raise in your answer, I think this answer: How can I get Mathematica to produce better Fortran code? to your previous question is what you're looking for. If I'm mistaken, then please post this as a new question, perhaps also explaining why Simon's answer there doesn't apply here. $\endgroup$
    – rm -rf
    Commented Feb 9, 2014 at 7:07
  • $\begingroup$ Hi rm, thanks for your process. The old problem is solved by used an updated Format.m and placed it to the correct location. But I have some new problems as I described. I think that they are the same kind of problems so I placed it here. Thanks. $\endgroup$
    – Tang Laoya
    Commented Feb 9, 2014 at 8:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.