Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: FortranForm of Integers and Reals

  • To: mathgroup at smc.vnet.net
  • Subject: [mg61039] Re: FortranForm of Integers and Reals
  • From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
  • Date: Sat, 8 Oct 2005 02:48:56 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <di597c$3cr$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

and ToString[FortranForm[num]]

does not help ??

Regards
  Jens

"Robert Schoefbeck" 
<schoefbeck at hep.itp.tuwien.ac.at> schrieb im 
Newsbeitrag news:di597c$3cr$1 at smc.vnet.net...
| Hello all,
|
| I have a stupid problem when I try to export 
Fortran Code from
| Mathematica into some .F file.
|
| For example, I want to achieve that
|
| Format[3xy, FormatType->FortranForm]
|
| gives
|
| 3d0*x*y
|
| and that
|
| Format[3. xy, FormatType->FortranForm]
|
| should give
|
| 3.d0*x*y
|
| That is, I want to have Integers as xdn and 
reals as ydn where n is the
| exponent of 10. First I tried
|
| Unprotect[FortranForm];
| 
FortranForm[int_Integer]:=DisplayForm[SequenceForm[int,d0]]
| FortranForm[r_Real]:=
| 
NumberForm[r,16,ExponentFunction\[Rule]Identity,
|     NumberFormat\[Rule](#1<>"d"<>#3&)]
| Protect[FortranForm];
|
| which gets me
|
| FortranForm[1543254233.]
| 1.543254233d9
|
| FortranForm[1]
| 1d0
|
| which is JUST what I want, except that it doesnt 
work with ToString:
|
| 
ToString[1543254233.,FormatType\[Rule]FortranForm]
| 1.543254233e9
|
| ToString[1,FormatType\[Rule]FortranForm]
| 1
|
| ToString[1.,FormatType\[Rule]FortranForm]
| 1.
|
|
| The reason is that toString does not get the 
actual function FortranForm
| but only the Identifier "FortranForm" and then 
proceeds as usual, i.e.
| not as I want it to.
|
|
| I have not succeded in redefining Format[int_, 
FortranForm] without
| generating infinite recursions.
|
|
| I do think that there should be an easy way out.
| I'd very much appreciate any help.
|
| Robert Schoefbeck
|
|
|
| 



  • Prev by Date: Re: Histogram with more than one dataset
  • Next by Date: Re: Einstein Summation with Utilities`Notation`
  • Previous by thread: FortranForm of Integers and Reals
  • Next by thread: StyleBox["A","MB"],RowBox[{"rrow3D",... inserted into Arrow3D[...]