is there a way to have the "Get" accept C formed %E numbers like Read does for Real?
- To: mathgroup at smc.vnet.net
- Subject: [mg63441] is there a way to have the "Get" accept C formed %E numbers like Read does for Real?
- From: "Barthelet, Luc" <lucb at ea.com>
- Date: Sat, 31 Dec 2005 06:40:43 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
It would be nice to be able to write fprintf's in C and read the result directly in mathematica without all the juggling around the C format. Is there already a way to do that? ReadList requires advanced knowledge of the structure. Like I would like to have my C code output a text file like this and read it straight in mathematica but doing <<"result.m" result.m looks like this Result={{3.9265E2,3.9265E2,"test"},{3.9265E2,"more test" },{3.9265E2,"Error"},24} Currently the easiest way I found is to encapsulate each number by a function of a string: fprintf[stream, "result={{C2M[%E] ...",double] So my files look like this Result={{C2M["3.9265E2"], C2M["3.9265E2"],"test"},{ C2M["3.9265E2"],"more test" },{ C2M["3.9265E2"],"Error"},24} And have predefined In[1]:= C2M[str_] := Module[{stream = StringToStream[str], result}, result = Read[StringToStream[str], Real]; Close[stream]; result ]; C2M["3.9265E2"] Out[1]= 392.65 But I which there was a nicer way on the C side than adding all those functions and strings. fprintf[stream, "result={{%E,%E,%E},{%E, ...}}",double,double,....] and just do something tricky on the mathematica side. I suppose there is a similar issue with %f. Thanks Luc