Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*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 1998

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

Search the Archive

Re: Mathlink problem with lists of reals


  • To: mathgroup@smc.vnet.net
  • Subject: [mg11177] Re: Mathlink problem with lists of reals
  • From: kevinl@wolfram.com (Kevin Leuthold)
  • Date: Wed, 25 Feb 1998 03:31:48 -0500
  • Organization: Wolfram Research, Inc.
  • References: <6ctk8a$lvb@smc.vnet.net>

Dave,

The reason WriteSample is returning is because of what you have in your
:Pattern: field in your template file.  The :Pattern: field specifies
the pattern matching that your Mathematica function will do, and the patterns
here should match the Heads of the expressions your function expects.  So you 
should change your :Pattern: field to:

:Pattern: WriteSample[filename_String, ns_List]

(See the Mathematica Book (Third Edition), section 2.12.4 for an example
of sending a List to a template-based MathLink program).  Also, to see
what patterns are defined for your installed program, you can use the
LinkPatterns function.

Kevin Leuthold
MathLink Group
Wolfram Research


Dave Grosvenor <dag@hplb.hpl.hp.com> writes:

>Briefly
>--------

>Has anyone else had a problem passing a list of Reals from mathematica
>to a c program?

>Or am I making a real simple mistake?

>I would be grateful for examples which  do something similar.

>Thanks 
>  Dave Grosvenor


>In detail
>----------

>I have got mathlink to pass lists of reals from c to mathematica. But
>now I want to   write the reals to a specified file.  This is so simple
>I cannot beleive it is not working.


>I define the following template 


>:Begin:
>:Function: writesample
>:Pattern: WriteSample[filename_String, ns_RealList]
>:Arguments: {filename, ns}
>:ArgumentTypes: {String, RealList}
>:ReturnType: Integer
>:End:


>This is called as follows:-


>WriteSample["test.txt",{1.1,2.2}]

>evaluating to 
>WriteSample["test.txt",{1.1,2.2}]


>The call never reaches my c function code, which is defined as follows:-


>int main(int argc,char* argv[])
>{
>int result;

>result = MLMain(argc,argv);

>return result;
>}


>int writesample(char* filename,double px[],long nx) {
>FILE* outp = fopen(filename,"wb");
>long i;


>for (i=0;i<nx;i++){
> fprintf(outp,"%e\n",px[i]);
>}


>fclose(outp);
>}


>I have put in assert(1!=1) at various points in the writesampletm.c file
>which was generated from the template, and it seems to fail much
>earlier...




  • Prev by Date: Compiling
  • Next by Date: Re: Possible bug in FindRoot[] in Mathematica 3.0
  • Prev by thread: Mathlink problem with lists of reals
  • Next by thread: Re: Mathlink problem with lists of reals