if (name_declared("pkgversions") != 4 ) {  execute("strdef pkgversions") }
sprint(pkgversions,"%sTreePlot = $Revision: 1.5 $, ",pkgversions)

load_file("TreePlot.hoc")
load_file("RPlot.hoc")

begintemplate TreePlotArray
public glist, cellref
public rprintfile, rp

objref vb
objref hblist
objref glist
objref rp

// TreePlotArray(double rows, double cols)
proc init() { local i, j
    rows = $1
    cols = $2
    vb = new VBox()
    hblist = new List()
    glist = new List()
    vb.intercept(1)
    for i=0,rows-1 {
        hblist.append(new HBox())
        hblist.object(i).intercept(1)
        for j = 0,cols-1 {
            glist.append(new TreePlot())
        }
        hblist.object(i).intercept(0)
        hblist.object(i).map
    }
    vb.intercept(0)
    vb.map
    rp = new RPlot()
}

proc cellref() {
    $o1 = glist.object($2*cols + $3)
}

// rprintfile(String epsfilename, Double SaveFile)
proc rprintfile() { local i, j
    if (numarg() == 1) { rp.create_rfile() }
    if (numarg() == 2) {
        if ($2 != 0) { rp.create_rfile($s1) }
    }
    rp.start_plot($s1)
    rp.set_mfrow(rows,cols)
    for i=0,rows-1 {
        for j = 0,cols-1 {
            rp.add_graph(glist.object(i*cols+j))
        }
    }
    rp.end_plot()
    rp.run()
}

endtemplate TreePlotArray