On 8/13/2015 9:37 PM, John Kitzmiller wrote:
On Aug 9, 2015, at 8:38 AM, Alan BRASLAU <alan.bras...@cea.fr
<mailto:alan.bras...@cea.fr>> wrote:

One needs to think about closing the data file as ConTeXt opens a single
MP instance that is run throughout the entire document AND over its
multiple runs. If the file is left open, a second run will try to read
on from the point where it left off.

THIS IS A SUBTLE POINT THAT SHOULD BE NOTICED BY ALL MPLIB USERS!

Thank you for this insight Alan! Two results immediately helpful are:
1) data can be put at the top of the .tex file
2) autogrids can be rendered and then drawn over

The following may not be the best way, but it works to read data from
the top of the .tex file and then plot on the autogrid.

% 1 0.5 2.5
% 2 1 3.5

\usemodule[graph]
\startMPpage[instance=graph,offset=2mm]
   draw begingraph(3cm,5cm);
   numeric a[];
     gdata("read1.tex", v,
       setrange(0,0,3,4);
     );
     closefrom "read1.tex";

     autogrid(,grid.lft) withcolor .7white;

     gdata("read1.tex",v,
     for j = 1 upto 3:
         a[j] := scantokens v[j];
       endfor;
       path b;
       augment.b(a1,a2);
       augment.b(a1,a3);
       setrange(0,0,3,4);
       gdraw b;
     );
     closefrom "read1.tex";
   endgraph;
\stopMPpage

an apetizer:

\usemodule[graph]

\startluacode
    local d = nil
    function MP.set(data)
        d = data
    end
    function MP.n()
        mp.print(d and #d or 0)
    end
    function MP.get(i,j)
        mp.print(d and d[i] and d[i][j] or 0)
    end
\stopluacode

\startluacode
    MP.set {
        { 1, 0.5, 2.5 },
        { 2, 1.0, 3.5 },
    }
\stopluacode

\startMPpage[instance=graph,offset=2mm]
draw begingraph(3cm,5cm);
    numeric a[];
    for j = 1 upto MP.n() :
        path b;
        augment.b(MP.get(j,1),MP.get(j,2));
        augment.b(MP.get(j,1),MP.get(j,3));
        setrange(0,0,3,4);
        gdraw b;
        endfor ;
endgraph ;
\stopMPpage




-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
    tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to