Re: Splice fails (Mathematica 9; Windows)
- To: mathgroup at smc.vnet.net
- Subject: [mg130367] Re: Splice fails (Mathematica 9; Windows)
- From: Roland Franzius <roland.franzius at uos.de>
- Date: Thu, 4 Apr 2013 22:34:36 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-newout@smc.vnet.net
- Delivered-to: mathgroup-newsend@smc.vnet.net
- References: <kgutm5$nsl$1@smc.vnet.net> <kjgo0g$pub$1@smc.vnet.net>
Am 03.04.2013 10:07, schrieb a.a.almasy at gmail.com:
> I have a similar problem. I am trying to Splice a file but all Mathematica would do is delete the two delimiters <* and *>. The code is:
>
> MyFortranForm[exp_, name_] := Module[{rules, file, out, frm, form},
> rules = {};
> file = name <> ".mf";
> out = OpenWrite[file];
> WriteString[out, name <> " = <* form *> "];
> Close[out];
> form =
> StringJoin @@
> Riffle[With[{splits =
> StringSplit[ToString@FortranForm[exp //. rules], " "]},
> Fold[If[StringLength[Last@#1] + StringLength[#2] > 60,
> Join[#1, {#2}],
> Join[Most[#1], {StringJoin[Last[#1], #2]}]] &, {First@
> splits}, Rest[splits]]], " &\n"] ;
> On[frm];
> Splice[name <> ".mf", PageWidth -> 120];
> FilePrint[name <> ".f"];
> Return[]
> ];
>
> Now when I am using this on an expression:
>
> MyFortranForm[A+B+C, "test"]
>
> it returns:
>
> test = form
>
> Does anyone has any ideas? I cannot find the problem. Internally form has the right form but it won't get sliced into the file.
Your output in StringWrite is the string
name <> " = <* form *> "
You have to replace it by
name <> " = <*"<> form <>" *> "
and evaluate the construction part for <form>
form = StringJoin @@
Riffle[With[{splits = ..... ;
before writing, preferably outside the module as a definition
form[text_,rules_]:= StringJoin @@
Riffle[With[{splits = ..... ;
--
Roland Franzius