
diagnostics=good
Eq=
eqlist=
!for i=1 to $objdim+1
 e_=!trim $(eq$i)
 e_=!declosing $e_
 !if $e_=$empty
  error=empty_data
  !exit
 !endif
 e_=!char 1 to $eqlim of $e_
 e_=!translate ; to , in $e_
 n_=!itemcnt $e_
 !if $n_!=$spacedim
  error=bad_dim
  !exit
 !endif
 eq$i=$e_
 eqlist=!append line $e_ to $eqlist
 e_=!translate , to + in $e_
 e_=!rawmath $e_
 Eq=$Eq+($e_)
!next i

test=$[$Eq]
!if NaN isin $test or Inf isin $test
 error=bad_data
 !exit
!endif

!if $integer=1
 !if . isin $Eq or , isin $Eq or / isin $Eq or ^ isin $Eq or\
	+ isin $eqlist or * isin $Eq
  error=not_integer
  !exit
 !endif
!endif
v_=!varlist $Eq
!if $v_!=$empty
  error=illegal_var
  !exit
!endif

eqlist=!translate $\
$ to ; in $eqlist
mat=!translate $\
$ to ; in $mat1
pari_header=eqlist=bestappr([$eqlist],10^10); pmat=eqlist; mat1=[$mat];\
	origin=[$origin]; for(i=1,$objdim+1,pmat[i,]=pmat[i,]-origin);\
	for(i=1,$objdim+1,eqlist[i,]=eqlist[i,]-eqlist[$objdim+1,]);\
	rank1=matrank(eqlist); rank2=matrank(concat(pmat~,mat1));

lintest=!exec pari print(rank1)\
	print(rank2)\
	for(n=1,$objdim+1,print(matrank(concat(mat1,pmat[n,]~)),", "))
	
!distribute lines $lintest into rank1, rank2, ranks

!if rank isin $rank1$rank2 or $rank1=$empty or $rank2=$empty
 error=bad_data
 !exit
!endif

!if $rank2>$objdim
 !for p=1 to $objdim+1
  l_=!item $p of $ranks
  !if $l_>$rank1
   diagnostics=bad $p
   !exit
  !endif
 !next p
!endif

!if $rank1<$objdim
 diagnostics=nospan
 !exit
!endif

