


\starttext

\startluacode

Elemento = {}
x = {}
y ={}
z= {}
carga = {}
i=1
context("\\startMPcode")
context("numeric u; u := 1.5cm;")
for line in io.lines("molecule.xyz") do
local a, b, c, d, e = string.match(line, '(%a+)%s*%s*(%S+)%s*%s*(%S+)%s*%s*(%S+)%s*%s*(%S+)')
Elemento[i]= a
x[i]= tonumber(b)
y[i]= tonumber(c)
z[i]= tonumber(d)
carga[i]= tonumber(e)
context("label(\"%s\", (%0.6f u, %0.6f u));", a, x[i],y[i])
--context("\\par %s \\par %s \\par %s \\par %0.6f \\par %s", a, b, c, z[i], e)
i=i+1 
end
context("\\stopMPcode")
\stopluacode

\startMPcode
vardef Grdln_@#(expr f) =
  save n_, s_; string s_;
  s_ = readfrom f;
  string @#[];
  if s_<>EOF:
    @#1 := loptok s_;
    n_ = if @#1="%": 0 else: 1 fi;
    forever:
      @#[incr n_] := loptok s_;
      exitif @#[n_]="  ";
    endfor
    @#1<>"  "
  else: false
  fi
enddef;

Grdln_$("molecule.xyz");

%  for i=1 upto infinity:
%
%   exitunless Grdln_$("molecule.xyz");
%
%    label("A", (@#2,@#3));
%
%  endfor

\stopMPcode



\stoptext
