# doN.r
	# LinePlot, diff areas

pdf(file="out.pdf")

SACONLY = 0		# 0:std  1:saconly data  2:std, but saconly format

InitPar = par(mar=c(2,2,5,0), las=1, xpd=T)

if (SACONLY) {
   par(mfrow=c(1,2), oma=c(2,2,0,1))
 } else
   par(mfrow=c(2,3), oma=c(7,4,3,2))

Plots = c("PRR","cross","crossX2","LIP", "cross","crossX2")
Units = c(  "",  "PRR",   "PRR",   "",    "LIP",  "LIP")
#  Names are hardwired elsewhere - do not change them !!

NEAR.OVERRIDE =  2
YLIM.OVERRIDE = .5			# [1 if EACH.STACK  Mult by cell count
if (!exists("DOUBLE.OVERRIDE"))
   # DIR.OVERRIDE = "GoCue_50:450ms"
   # DIR.OVERRIDE = "GoCue_-500:0ms"
    DIR.OVERRIDE = "GoCue_-800:0ms"		# Pretty good for SACONLY
   # DIR.OVERRIDE = "AllGoCue_-800:0ms"		# Pretty good for SACONLY
   # DIR.OVERRIDE = "All-sacGoCue_-800:0ms"
   # DIR.OVERRIDE = "Target_800:1300ms"
   # DIR.OVERRIDE = "Target_-500:0ms"
   # DIR.OVERRIDE = "AllTarget_-500:0ms"
   # DIR.OVERRIDE = "AllTarget_-500:0ms_NoE"
   # DIR.OVERRIDE = "AllTarget_-400:0ms"
   # DIR.OVERRIDE = "AllTarget_-300:0ms"
   # DIR.OVERRIDE = "AllTarget_-500:1200ms"
   # DIR.OVERRIDE = "AllTarget_800:1300ms"
   # DIR.OVERRIDE = "AllGoCue_-500:0ms"	# Target_{0:1000,300:1300}ms
   # DIR.OVERRIDE = "AllGoCue_-1000:0ms"
					# Comment out that one line for doMany.r

# -300:0 -350:50 -500:0

LOOP = T

for (pl in 1:6) {
     if (SACONLY & (pl != 2 & pl != 5))
       next

    AREA.OVERRIDE = Plots[pl]
    UNIT.OVERRIDE = Units[pl]
    #  CHANGE THIS TO SACONLY>0 if you want tyrol only for both 1 and 2
    MONK.OVERRIDE = ifelse(SACONLY==1, "tyr", "both")	# both, zen, tyr
    source("main.r")
    # print(t(MeanCounts)) # If you want to see the counts!

    # This should move to the individual calls in main.r
    if (PLOT.TYPE == "SignifSync") {
       par(xpd=NA)
       if (par()$mfg[2] == 1) {	# 1st column?
          axis(2, at=YLIM*c(0,.5,1), 
	       labels=paste0(round(YLIM*c(0,.5,1)/CellCount*100,dig=1), "%"))
          save = par(mgp=c(4-4*SACONLY,1,0))
          title(ylab="Coherent pairs (%)")
          par(save)
          } 
       if (par()$mfg[1] == par()$mfrow[1]) {	# bottom row?
          axis(1, at=if (par("xlog")) 2^(2:7) else (0:3)*50, labels=T)
          title(xlab="Frequency (Hz)")
          }
       par(xpd=F)
       }
    }

mtext(paste0(MONK, if (NEAR) paste0("+",NEAR," mm"), "    ",
	     ifelse(exists("MIN_FREQ"), MIN_FREQ, min(BANDS.SEQ)),
	     " to ",
	     ifelse(exists("MAX_FREQ"), MAX_FREQ, max(BANDS.SEQ)),
	     "Hz",
	     "    ", directory,
	     if (SACONLY == 1) ".saconly", 
	     if (SACONLY == 2) " (sac trials only)"),
      side = 3, line = 0-1*SACONLY, outer = T)

LOOP = F
rm(PLOT.TYPE)
if (exists("MIN_FREQ")) rm(MIN_FREQ)
if (exists("MAX_FREQ")) rm(MAX_FREQ)
par(InitPar)

dev.off()
