; build a form which controls the plot
;
; create a file (postscript or HPGL) and send it to the 
; current plotter
; many parameters availlable
;
; no arg means : build the formbox, args means do the plot
;
; see also : plot? PLOT

if (!$arg) then
; compute default values
set pl = $config_plot
if ($pl s= "HP-GL") then
  set of7x = (-($cx/2))
  set of7y = (-($cy/2))
else
  set of7x = 1
  set of7y = 1
endif
set cray = 1
set xax = 0.5
set yax = 0.5
set plax = "(F12) Plot Both Axes"
set gd = "off"
set ct = ("File : ";$name)
set txt = "Gifa_Temp.Plot"
set pg = "Draw & Print"
formbox "Print Parameters ..." \
     "easyplot $cpl $crot $ccx $ccy $cof7x $cof7y $cpn $clev $clog $ccray $cpcol $cbw $cxshow $cyshow $cunit $cxax $cyax $cplax $cgd $titre $ctxt $cpg" \
     "Plotter Type   " enum "postscript,HP-GL" cpl $pl \
     "Rotate is . . ." enum "on,off" crot "off" \
     "Size (cm) in the X-axis " real ccx $cx \
     "Size (cm) in the Y-axis " real ccy $cy \
     "OffSet <X> " real cof7x $of7x  \
     "OffSet <Y> " real cof7y $of7y  \
     separator \
     "Display part " enum "positive,negative,both" cpn $sign  \
     "Number of levels: " int clev $level \
     "Level Algo: " real clog $loga \
     "Pen number . . . (Line Style for a PostScript Print)" enum "1,2,3,4,5,6,7,8" ccray $cray \
     "Color type . . . (Not used for a HP-GL Print)" enum "black,red,yellow,green,cian,blue,purple,white" cpcol "black" \
     "Plot type " enum "Monochrome,MultiColor" cbw "Monochrome" \ 
     "Show on X axis (2D)" enum "none,proj,diag" cxshow "none" \
     "Show on Y axis (2D)" enum "none,proj,diag" cyshow "none" \
     separator \
     "Unit along Axes" enum "ppm,hz,index" cunit "ppm" \
     "Separation along X Axis" real cxax $xax  \
     "Separation along Y Axis" real cyax $yax  \
     "Axis direction " enum "No Axes,(F1) Plot Y Axis,(F2) Plot X Axis,(F12) Plot Both Axes" cplax $plax \
     "Grid " enum "solid,dashed,off" cgd $gd  \
     separator \
     "Title to print... " string titre $ct \
     "Output File :  " string ctxt $txt \
     "page command " enum "Draw & Print,Draw Only,Print Only" cpg $pg \
     *
else
 set cpl = $_
 set crot = $_
 set ccx = $_ 
 set ccy = $_
 set cof7x = $_
 set cof7y = $_
 set cpn = $_
 set clev = $_
 set clog = $_
 set ccray = $_
 set cpcol = $_
 set cbw = $_
 set cxshow = $_
 set cyshow = $_
 set cunit = $_
 set cxax = $_
 set cyax = $_
 set cplax = $_
 set cgd = $_
 set titre = $_
 set ctxt = $_
 set cpg = $_
; garde l'echelle en entree
 set inscale = $scale
; nom de l'auteur du formulaire
 print "Gifa easyplot Form. :  Ch. PRUVOST 1995"
; 
; Calcul de la hauteur de l'eventuel plot du spectre 1D ($tcy)
; (10% de la taille du plot en y et au minimum 2cm)
; le separateur ($sep) est fixe a 0.1cm 
; 
 set sep = 0.1 
 set tcy = (0.1 * $ccy) 
 if ($tcy < 2) set tcy = 2
;
; restitution de la couleur
;
 if ($cpcol s= "black") set cpcol = 1
 if ($cpcol s= "red") set cpcol = 2
 if ($cpcol s= "yellow") set cpcol = 3
 if ($cpcol s= "green") set cpcol = 4
 if ($cpcol s= "cian") set cpcol = 5
 if ($cpcol s= "blue") set cpcol = 6
 if ($cpcol s= "purple") set cpcol = 7
 if ($cpcol s= "white") set cpcol = 8

;Choix du plotter
plotter $cpl
if (!($cpg s= "Print Only")) then
   print "Opening File..."
   if ($crot s= "on") then
     rotate 1
   else 
     rotate 0
   endif
   ;choix de CX et CY
   if ($ccx > 0 ) then
      cx $ccx
   else
      error "cx should be >0"
   endif
   if ($ccy > 0 ) then
      cy $ccy
   else
      error "cy should be >0"
   endif

;Choix des coordonnees de l'origine (calcule pour HPGL ou Postscript) 
;[varie suivant la presence ou non des projections latterales]
;
   plotoffset $cof7x $cof7y ;reinitialise plotoffset pour le cas ou la
                            ; macro serait lancee plusieurs fois sinon
                            ; on observe un decalage du a plotoffset % ...
  if ($dim == 2) then                         
   if (($cxshow s= "none") & ($cyshow s= "none")) then
      plotoffset $cof7x $cof7y 
   else  ; un peu mal ecrit mais ca marche
      if (!($cyshow s= "none")) then 
         if ($cpl s= "postscript") plotoffset (%+$sep+$tcy) % 
         if ($cpl s= "HP-GL") plotoffset % % ; pas de modif. car rotate indisponible 
      endif 
      if (!($cxshow s= "none")) then 
         if ($cpl s= "postscript") plotoffset % %   ; juste pour info. 
         if ($cpl s= "HP-GL") plotoffset % (%-$sep-$tcy) ; pas de modif. (car rotate...) 
      endif  
   endif
  endif
  
;Choix du display +, - out +&-
;
   if ($cpn s= "positive") then
     sign 1
   elsif ($cpn s= "negative") then
        sign -1
      else  
        sign 0
   endif
   if ($clev != $level) then
      if ($clev < 1 | $clev > 64) error "Wrong number of levels"
      level $clev
   endif
   if ($clog != $loga) then
      if ($clog < 1) error "Loga should be >= 1"
      loga $clog
   endif
;
; initialise
;
   if ($cpl s= "postscript") then
      pcolor 1 $ctxt
   endif
   pen 1 $ctxt
;
;Print axis
;
   if (!($cplax s="No Axes")) then
      plotaxis? $cunit $cxax $cyax
      if ($cplax s= "(F1) Plot Y Axis") plotaxis F1 $ctxt
      if ($cplax s= "(F2) Plot X Axis") plotaxis F2 $ctxt
      if ($cplax s= "(F12) Plot Both Axes") plotaxis F12 $ctxt
   endif
;
;Print grid
;
   if ($cgd s="solid") then
      if ($dim == 1) grid F2 $ctxt
      if ($dim == 2) grid F12 $ctxt
   elsif ($cgd s="dashed") then
      pen 4 $ctxt
      if ($dim == 1) grid F2 $ctxt
      if ($dim == 2) grid F12 $ctxt
      pen 1 $ctxt
   endif
   
;
;print map in b&w or color
;
   pen $ccray $ctxt
   if ($cpl s= "postscript") then
      if ($cbw s= "Monochrome") then
         pcolor $cpcol $ctxt
         plot $ctxt
      else
         plotcolordisp $ctxt
      endif
   else
      if ($cbw s= "Monochrome") then
        plot $ctxt
      else
        plotcolordisp $ctxt
      endif
   endif

;Print title
   if (!($cxshow s= "none")) then 
      set oldcy = $cy
      cy ($cy+$sep+$tcy)
      title $titre $ctxt
      cy $oldcy
   else
      title $titre $ctxt
   endif
 if ($dim == 2) then ; otherwise projection not print
;
; print side spectra
;
;
   set orx = $PLOTOFFSET[1] ;recupere l'origine du contour plot en x
   set ory = $PLOTOFFSET[2] ;recupere l'origine du contour plot en y
   
; recupere dans tous les cas la taille de l'eventuel zoom 2D
    set rap = ($SI2_2D/$SI1_2D)
    set za = ($zoom_2d[1]*$rap) ; utile pour bien positionner
    set zb = $zoom_2d[2]        ;
    set zc = ($zoom_2d[3]*$rap) ; la fenetre de zoom en 1D
    set zd = $zoom_2d[4]        ;
;
; Projection selon F1
;
   if (!($cxshow s= "none")) then 
       dim 2
       if ($cxshow s= "proj") then 
          proj F1 S
       endif 
       if ($cxshow s= "diag") then
          diag
       endif
       dim 1 scale 1 cx $ccx cy $tcy
       zoom 1 $zb $zd
       if ($cpl s= "postscript") plotoffset $orx ($ory+$ccy+$sep)
       if ($cpl s= "HP-GL") plotoffset $orx ($cof7y+$ccy+$sep-($tcy/2))
       plot $ctxt
       dim 2 cx $ccx cy $ccy scale $inscale
   endif 
;
; Projection selon F2
;
  if (!($cpl s= "HP-GL")) then ; pas cette projection en HP-GL
   if (!($cyshow s= "none")) then
       dim 2
       if ($cyshow s= "proj") then 
          proj F2 S
       endif 
       if ($cyshow s= "diag") then
          diag
       endif
       if ($crot s= "off") then
          dim 1 scale -2.6 cx $ccy cy $tcy ; ?? taille scale -1 # taille de scale 1 ??
          vheight (1-%) ;permet de remonter le graphe dans la fenetre 1D
          if ($cpl s= "postscript") plotoffset (20.285-$ory-$ccy) ($orx-$sep-$tcy)
          reverse 
          if ($cyshow s= "diag") zoom 1 ($SI1_1D - $zc) ($SI1_1D - $za)
          if ($cyshow s= "proj") zoom 1 ($SI1_1D - ($zc/$rap)) ($SI1_1D - ($za/$rap))
          rotate 1
          plot $ctxt
          rotate 0
       else
          dim 1 scale 1 cx $ccy cy $tcy ; 
          if ($cpl s= "postscript") plotoffset (20.285-$orx-$ccx) ($ory+$ccy+$sep)
          zoom 1 ($za/$rap) ($zc/$rap)
          rotate 0
          plot $ctxt
          rotate 1
       endif
       reverse vheight (1-%) ;permet de recuperer le zoom de depart en 1D
       dim 2 cx $ccx cy $ccy scale $inscale
   endif 
  else
    if (!($cyshow s= "none")) print "Show on Y axis NOT AVAILABLE with HP-GL"
  endif
 else
  if ((!($cyshow s= "none")) | (!($cxshow s= "none"))) \
               print "Side Projection Not Available with 1D plot"
 endif
endif 
;End of Drawing

; Write EOF and send it to the printer if Print is on!     Printing...
if (!($cpg s= "Draw Only")) page $ctxt

;EOmacro 
endif


