# Variable calculations should be done in this file.
# It is read and interpreted by wims for all valid calls to the module.

rightp=)

!if $cmd=reply and $status!=waiting
 error=double_reply
 !exit
!endif

!if $cmd=reply and $status=waiting
 choice=!trim $choice
 chosen=
 !for i in $choice
  row=!line $i of $vecs
  row=!trim $row
  !if $row!=$empty
   chosen=!append line $row to $chosen
  !endif
 !next i
 choicecnt=!linecnt $chosen
 !if $choicecnt<=0
  error=empty_choice
  !exit
 !endif
 chpari=!translate $\
$ to ; in $chosen
 pariout=!exec pari base=Mat([$baspari]);chosen=Mat([$chpari]);print(matrank(chosen));\
  for(x=1,$choicecnt,cc=chosen[x,];r=matrank(concat(base,cc));if(r>$subdim,print(x););)
 !distribute lines $pariout into rank,out
 out=!trim $out
 !if $out!=$empty
  out=!words2items $out  
 !endif
 !if $rank<$choicecnt
  dependent=yes
 !endif
 !if $rank<$subdim
  partial=yes
 !endif

 status=done
 score=1
 !if $out!=$empty
  score=0
 !endif
 !if $dependent=yes
  score=$[$score/2]
 !endif
 !if $partial=yes
  score=$[$score*($rank/$subdim)^2]
 !endif
 module_score=$[rint(10*$score^$severity)]
 wims_module_log=score $module_score/10
!endif

