CodeGen : How generate compliant f95 fortran code (currently not the case : F77 style)

54 views
Skip to first unread message

Flo Bidou65

unread,
Jul 10, 2017, 12:04:31 PM7/10/17
to sympy
Hi,

I'm new to sympy and i'm trying to generate fully compliant f95 fortran code. But for instance, the declaration of datatypes (real, int, etc) is not compliant with the f95 --std.

Is there a way to automatically generate codes with for instance : real (kind=8) :: toto instead of REAL*8 :: toto ?

Instead of rewriting the source code, is someone using codegen for standard fortran generation codes purposes ?

Thanks in advance

Best regards.

Florent

Aaron Meurer

unread,
Jul 11, 2017, 10:17:29 AM7/11/17
to sy...@googlegroups.com
From what I've read (please correct me if I am wrong), REAL*8 is still
valid in Fortran 95. However, we really ought to allow specifying
multiple standards to the function, so that the newer standards can
output more idiomatic code.

I believe it should be possible to change what codegen() is outputting
from changing the DataType that is used. I'm not quite clear how to
pass it in to the codegen() function. In SymPy 1.1 you can pass in a
custom CodeGen subclass, so it should be doable, however it's
complicated because currently types are handled by the classes in the
codegen module rather than the code printers.

Maybe someone more well versed in the module can give a better answer,
but monkeypatching should work

import sympy.utilities.codegen as codegen_mod

codegen_mod.default_datatypes.update({
"int": codegen_mod.DataType("int", "INTEGER(kind=4)", "int", "", "", "i32"),
"float": codegen_mod.DataType("double", "REAL(kind=8)", "float",
"", "", "f64"),
})

(see https://github.com/sympy/sympy/blob/b2b4bfbbbe85e4b19fbc68fb4f72bdaccb476e79/sympy/utilities/codegen.py#L240)

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/dcd1bd81-3be1-45fa-a828-62aec52d398a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages