******************************************************************************
*** PLA based on IMaude
******************************************************************************
mod PLA-IMPORT is
  inc RFE .
  inc PLA-AUX .
  inc STATUS-AUX .
  
  inc PARSE-PANTHER .


******************************************************************************
*** Variables
******************************************************************************
var ctl : Control .
var wait4s : Wait4Set .
var reqQ reqQ' reqQ0 reqQ1 reqQ2 : RequestQ .
vars es es' : ESet .
var ee : Entry .
var ee? : Entry? .
var log : Log .

var b : Bool .
var n nodeId : Nat .
vars  mname g2dname g2dvname kbname modname modname' : Qid .
vars type tkbFname occsFname graphFname nid flag qid tmp : Qid .
vars fname gname pname newgname newpname pathpname dname format : Qid .
vars outQ toks toks' rids srctoks : QidList .
var ?graph : Graph .
vars pntlT pntlT' pnetT occsT ioccsT ioccsT' uoccsT roccsT nT occT : Term .
vars goccsT aoccsT ridsT ugoccsT : Term .
var tl occsTL : TermList .
vars dnotes gnotes pnotes notes : Notes .
vars res0?? res1?? res?? res2?? res3?? : [ResultPair?] .
vars id ?string status str gstr astr rstr title subtitle : String .
vars ctr  ctr1 ctr2 netStr taskStr : String .
vars ndl ndl' nds nodes pndl : NodeList .
var edl : EdgeList .
 
******************************************************************************
*** Import CD pathway
**** 
******************************************************************************

  eq isReq('cd2plkb) = true .
  eq enabled(wait4s,req('cd2plkb,ql(tmp  modname kbname toks),reqQ)) = true .

**** assumes dgraph has been made and stored as petri-graph under gname
  crl[cd2plkb]:
   [nil,
    st(processing(req('cd2plkb,ql(tmp  modname kbname toks),reqQ')), 
       wait4s,reqQ,es,log), 
    outQ]
     =>
   [nil,  
    st(ready, wait4s, (reqQ reqQ0), es', log),
   outQ ] 
  if {b,es'} :=  cd2plkb(es,tmp,modname,kbname) 
  /\ reqQ0 := (if b then reqQ' else req('logreq,ql('cd2plkb 'failed),nil) fi) .

****
  op cd2plkb : ESet Qid Qid Qid -> BoolESet .
  ceq cd2plkb(es,tmp,modname,kbname) = {b,es'}
  if ql(toks') := getVal(es,'qval,tmp,ql(nil))
**** toks' ~ 'content fname toks
  /\ toks := getPost(2,toks')
  /\ tm(modname',pntlT) := parsePathway(modname,toks) 
  /\ pnotes := (("source" := ql('CD modname)))
  /\ b := toks =/= nil 
  /\ es' := (if b  
             then addEntry(es, 'tval,'tkb kbname,pnotes,tm(modname',pntlT))
             else es fi) .

***(seq (fileread fname tmp) 
        (cd2plkb tmp modname kbname)
        (initKBgraph kbname)
        (graph2file gfname )
    )




endm


