Index: /branches/sj_ippTests_branch_20080929/ippTests/compIPPphoto.py
===================================================================
--- /branches/sj_ippTests_branch_20080929/ippTests/compIPPphoto.py	(revision 20527)
+++ /branches/sj_ippTests_branch_20080929/ippTests/compIPPphoto.py	(revision 20528)
@@ -67,4 +67,5 @@
 # (and that's probably quite enough anyway).
 
+# Look at extended flag in PS1 vs. SDSS!!!
 
 plotcol_1frame_tlist = [
@@ -75,5 +76,5 @@
     ,(['sky_ps1'],['d_mag'],'scatter')
     ,(['d_sky'],['d_mag'],'scatter')
-    ,(['x_psf'],['objc_colc'],'histogram')
+    ,(['d_x'],['d_y'],'histogram')
     ,(['m_rr_cc_psf'],['d_mag'],'scatter')
     ,(['sky_sdss'],['sky_ps1'],'scatter')
@@ -100,5 +101,5 @@
     outroot = re.sub('(\.[sc]mf|\.fits?)$','',summaryTable)
     for filt in filtlist:
-        rootstr = "nup_match_%s"%(filt)
+        rootstr = "win_match_%s"%(filt)
         globstr = "%s_*.eps"%(rootstr)
         filelist = glob(globstr)
@@ -203,5 +204,6 @@
     return outname
     
-def plotStatsOnefile(values_hash,goodrow_hash,matchtable,plotcol_tlist,bandindex,format='eps',bandid=''):
+def plotStatsOnefile(values_hash,goodrow_hash,matchtable,plotcol_tlist,bandindex,\
+                         format='epsport',bandid='',expand=0.8):
     """Make diagnostic plots for a single table, based on values in
     values_hash"""
@@ -218,6 +220,17 @@
     ptype_l = [ 41, 41, 40, 40, 30,30]
     outname_l = []
-    nplots = 0
+    nplots = len(plotcol_tlist)
+    all_outname = "win_" + re.sub('(\.[sc]mf|\.fits?)$','',matchtable) +".eps"
+    smOpenPlot(all_outname,format=format)
+    # all the explict sm. and smLib. calls should be wrapped into
+    # functions that can be called for other plotting packages
+    sm.window(1,1,1,1)
+    sm.frelocate(0.5,1.05)
+    sm.putlabel(5,re.sub('(\.[sc]mf|\.fits?)$','',re.sub('_','\_',matchtable)))
+    i=0
     for troika in plotcol_tlist:
+        i+=1
+        Nx,Ny,winx,winy = setWindow(i,nplots)
+        smLib.window(Nx,Ny,winx,winy)
         col1name_l = troika[0]
         col2name_l = troika[1]
@@ -225,7 +238,5 @@
         outname = getOutnameStatsOnefile(matchtable,plottype,col1name_l,col2name_l,format=format,bandid=bandid)
         outname_l.append(outname)
-        smOpenPlot(outname,format=format)
         firstplot = True
-        i = 0
         for col1name,col2name in zip(col1name_l,col2name_l):
             values1 = values_hash[col1name.lower()]
@@ -255,10 +266,11 @@
                         smScatterPlot(values1,values2,logical=goodrows,xlab=col1name,ylab=col2name,\
                                           # xrange=(xmin,xmax),yrange=(ymin,ymax))
-                                      xrange=None,yrange=None)
+                                      xrange=None,yrange=None,expand=expand)
                     else:
                         smScatterPlot(values1,values2,logical=goodrows,xlab=col1name,ylab=col2name)
                 else:
                     angle(angle_l[i%len(angle_l)])
-                    smScatterPlot(values1,values2,ptype=ptype_l[i%len(ptype_l)],logical=goodrows,append=True)
+                    smScatterPlot(values1,values2,ptype=ptype_l[i%len(ptype_l)],\
+                                      logical=goodrows,append=True,expand=expand)
                     angle(0)
             if plottype == 'histogram':
@@ -273,23 +285,22 @@
                     minbin=None
                     maxbin=None
-                smHistoPlot(values2,ltype=0,nbins=Nbins,minbin=minbin,maxbin=maxbin,xlab=col2name,ylab="N")
+                smHistoPlot(values2,ltype=0,nbins=Nbins,minbin=minbin,maxbin=maxbin,\
+                                xlab=col2name,ylab="N",expand=expand)
                 smHistoPlot(values1,append=True,minbin=minbin,maxbin=maxbin,nbins=Nbins,\
-                            ltype=2)
+                            ltype=2,expand=expand)
             firstplot = False
-            i+=1
-        smClosePlot()
-        nplots += 1
+    smClosePlot()
     all_outname = "nup_" + re.sub('(\.[sc]mf|\.fits?)$','',matchtable) +".eps"
     tmp_outname = "tmp_" + re.sub('(\.[sc]mf|\.fits?)$','',matchtable) +".eps"
-    print "creating ", all_outname
-    mergecmd = "gs -dNOPAUSE -sDEVICE=pswrite -sOutputFile=%s %s -c quit" %(tmp_outname,' '.join(outname_l))
-    call(mergecmd,shell=True)
-    psnupcmd = "psnup -pletter -%i %s %s"%(nplots,tmp_outname,all_outname)
-    print "calling ", psnupcmd
-    call(psnupcmd,shell=True)
-    os.remove(tmp_outname)
+    # print "creating ", all_outname
+    # mergecmd = "gs -dNOPAUSE -sDEVICE=pswrite -sOutputFile=%s %s -c quit" %(tmp_outname,' '.join(outname_l))
+    # call(mergecmd,shell=True)
+    # psnupcmd = "psnup -pletter -%i %s %s"%(nplots,tmp_outname,all_outname)
+    # print "calling ", psnupcmd
+    # call(psnupcmd,shell=True)
+    # os.remove(tmp_outname)
     return all_outname
 
-def setWindow(i,Nplots):
+def setWindow(i,Nplots,portrait=True):
     """Set sm window for plotting the i-th out of Nplots. The logic is
     that N_x * N_y >= Nplots and N_y-N_x is 0 or 1. So Ny is the sqrt
@@ -318,4 +329,11 @@
     if int(i/Nx) == i/float(Nx):
         winy -= 1
+    if not portrait:
+        tmp = Nx
+        Nx = Ny
+        Ny = tmp
+        tmp = winx
+        winx = winy
+        winy = tmp
     return Nx,Ny,winx,winy
 
@@ -697,4 +715,6 @@
     """Issue sm device command for file of given format:
     eps -> postfile
+    epsland -> postlandfile
+    epsport -> postportfile
     else just use given format as 'device'"""
     from sm import device, erase
@@ -703,4 +723,8 @@
     elif format == 'eps':
         device('postfile '+filename)
+    elif format == 'epsland':
+        device('postlandfile '+filename)
+    elif format == 'epsport':
+        device('postportfile '+filename)
     else:
         device(format +' '+filename)    
@@ -717,5 +741,5 @@
                     xlab=None,ylab=None,xrange=None,yrange=None,\
                     box1=None,box2=None,box3=None,box4=None,\
-                    ltype=0,append=False):
+                    ltype=0,append=False,expand=1.8):
     """Plot a histogram, intelligently deriving bins from the given
     parameters if they are given intelligently.  Otherwise, silently
@@ -735,4 +759,5 @@
     bincenters = leftbinedges + 0.5*(leftbinedges[1]-leftbinedges[0])
 
+    sm.expand(expand)
     sm.ltype(ltype)
     if not append:
@@ -764,9 +789,9 @@
 def smScatterPlot(x,y,logical=None,ptype=41,xlab=None,ylab=None,xrange=None,yrange=None,\
                     box1=None,box2=None,box3=None,box4=None,\
-                    append=False):
+                    append=False,expand=1.8):
     """Make an sm scatter plot on current device. If append=True,
     overplot with current limits. Otherwise, draw box box1 box2 box3 box4"""
     import sm
-    sm.expand(1.8)
+    sm.expand(expand)
     sm.lweight(5)
     # Silently ignore any problems with plot generation
@@ -779,4 +804,5 @@
         pass
 
+# May need to add erase option here which defaults to True
 def smSetup(x,y,logical,xrange,yrange,xlab,ylab,box1,box2,box3,box4):
     import sm,re
