Re: a simple question

*To*: mathgroup at smc.vnet.net*Subject*: [mg7135] Re: [mg7077] a simple question*From*: seanross at worldnet.att.net*Date*: Mon, 12 May 1997 01:55:38 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

Alejandro Rozenfeld wrote: > > At 09:27 5/05/97 -0400, you wrote: > >Alex Rozenfeld wrote: > >> > >> Hi. I'm a last year student of Physics in the Universidad > >> Nacional de La Plata (Argentina), and i'm doing a graduating research > >> work. It's very helpful to me to use the Mathematica 2.2. But, in order > >> to improve speed of calculations i wrote some code in "c" language. Now, > >> it is imposible to me to run this code from mathematica 2.2. The purpose > >> of this mail is to find some information about how to do this. If > >> could someone help me, i will be very grateful. > >> Thank you very much. > >> Alex. > > > >There are two ways: > >1) if you have mathematica 2.2.2 or later, you can use mathlink. > >2) you can use the command Run to run a program. Have the c program use > >a data file as input and output its results to a file. Mathematica can > >edit and set up the input file, then read the output when your c program > >is done. > > > > > > Thanks for your answer. > 1) I have mathematica 2.2.1.... :-( > 2) I had already tried that! But i had a problem: > I wrote a very simple "test.c" code: > > #include <stdio.h> > > main() > { > > FILE *arch; > > arch=fopen("f:\wnmath22\work\test.txt","w"); > fprintf(arch,"This is a Test..."); > fclose(arch); > return 0; > > } > > and i generated the test.exe file. > > So, in order to run this simple code from the Mathematica i wrote > the following in a cell: > > Run["test"]; > Read["test.txt",String]; > > The problem is, mathematica do not wait for test.exe to finish! It > inmediately trys to read the file test.txt! but, it does not exist yet!... > So, could you please help me with this trouble???? > > Thank you very much for your attention. > Alex. I don't know what to say. I run some Fortran programs in just the way you describe although I use the OpenRead and OpenWrite commands. The only difference is that my commands are inside a Module construct. Have you tried putting the commands to run and read in separate cells? Sometimes mathematica looks at the entire list of commands and tries to make some sense of it all rather than waiting for the commands to execute first.