#!/bin/csh
# To generate a plot for a Light Curve 
# -- Accept Magnitudes or Colors
# -- Accept list of filters, may include combination with '+' or ','
#Required parameters:
###################################################
set plot     = "Velocity curve" # beginning of title (default="Light curve")
# Name and File
if ("$theTab" =~ table*) then
    set theFile = "$theTab"
    if ("$theTab" =~ *6) set Star = "WASP-54"
    if ("$theTab" =~ *7) set Star = "WASP-56"
    if ("$theTab" =~ *8) set Star = "WASP-57"
else
    set Star = "$theTab"
    if ("$theTab" =~ *54) set theFile = "table6"
    if ("$theTab" =~ *56) set theFile = "table7"
    if ("$theTab" =~ *57) set theFile = "table8"
endif
# Instruments
set Flab = "Inst"
set Fcol = "Inst"		# name of column containing a Filter
set Fall = "SOPHIE=red3;CORALIE=blue3;all"
if ($Star =~ *54) then
    set Pdef = 3.69365
else if ($Star =~ *56) then
    set Pdef = 4.6171
    set Fall = "SOPHIE=red3"
else if ($Star =~ *57) then
    set Pdef = 2.83897
endif
######################################################
# Optional parameters:
#######################################################
set JD0      = 2450000		# Origin of JD (default is 2450000)
#set Pdef    = "1.2345678"	# Default value of period
#set Flab     =  "Tr"		# Name of menu with filters, default is "F"
#set Fdef     = # default filter(s) to plot (default="all")
#set Xcol     = # name of column containing the time (default is /JD/)
set Ycol     = "RV"
set has_err  = 1 
#set has_lim  = 1 # must be defined to plot also limits(>) with triangle
#set is_diff  = 1 # must be defined if diff. magnitudes (or relative flux)
#set is_flux  = 1 # must be defined if values are fluxes (not magnitudes)
#set no_xlim  = 1 # must be defined to remove the limits (in case of Phase)
#set theFile  = name of the file(s) for the plot (defaut=$theTab)
#set title    = non-standard title
#set photosys = name of photometric system
#set IDcol    = name of column containing the "identifier"
#set IDval    = value of the "identifier" (default "$stheStar")
set Xlab     = "BJD-2450000"
set Ylab     = "RV [km/s]"
#set graph_color = "`graph_color '$Fall'`"  # Colors for graph
source $Vroot/lib/graph/lc-mag.csh
exit $status

#!/bin/csh
####################################
# theTab = table name
# Argument is P=period
# Vgraph is "gif" "ps" or "txt"
####################################

#################################################################
# Get the Arguments: tab and Period
#################################################################
set Star = "$theTab"

if ("$theTab" =~ table*) then
   set Tab = "$theTab"
     if ("$theTab" =~ table6) then
     set Star = "WASP-54"
     else if ("$theTab" =~ table7) then
     set Star = "WASP-56"
     else
     set Star = "WASP-57"
     endif
else
   set Star = "$theTab"
#    if ("$theTab" =~ *54) then
#    set Tab = "table6"
#    else if ("$theTab" =~ *56) then
#    set Tab = "table7"
#    else
#    set Tab = "table8"
#    endif
endif

# Get Menu
if ("$1" =~ LIST_S=*) then	# The Menu supersedes the default
     set list = "$1"; shift
endif

if ("$1" =~ S=*) then
    set S = `echo "$1" | acut -d= -f2` ; shift
else
    set S = "$Star"
endif

if ("$S" =~ *54) then
     set Tab = "table6"
else if ("$S" =~ *56) then
     set Tab = "table7"
else
     set Tab = "table8"
endif

if ("$1" =~ P=*) then
    set P = `echo "$1" | cut -c3-` ; shift
    if (("$P" == 0) && ("$1" == "-x" )) then	### REMOVE Limits 0/1
	if (("$2" == "0") && ("$3" == "1" )) then 
	    shift; shift; shift
	endif
    endif
else
    set P = ""
endif
if ("$P" == "") set P = 0 


#################################################################
# Vgraph not defined ==> just the plot introduction
#################################################################
if (! $?Vgraph) then
     if (! $?list) then
       set list = "LIST_S=WASP-54;WASP-56;WASP-57"
     endif
    if ($P != 0) then
        set plotx = "-x 0 1"
    else
        set plotx = ""
    endif
    set ploty = "" # "-y - - -"       # Reverse Y axis
    # These values are superseded by what's contained in $argv

    echo1 "\section*{RV of \object{$Star} (P=$P)}"
    cgigraph -img -ps:"Postscript Figure" -txt:"Data as a Table" -form -htx \
	"$list" S="$S" P=$P -graph $plotx $ploty $argv:q
    exit 0
endif

################################################################
# Actual gif or ps plot (Vgraph contains gif or plot)
################################################################

set  plotarg = \
  "-f 0.0325 -h 0.75 -w 0.75 -u 0.125 -r 0.15 --title-font-size 0.05 -m -1 -S 3"

if ($P != 0) then
    set X = "Phase"
else
    set X = "BJD-2455000"
endif
set Y = 'V\sbr\eb [km/s]'

#fcat catalog.dat | gawk -v P=$P "/^$Star /"'{\
asu -data <<====EOQ | gawk -v P=$P 'BEGIN{FS="\t"}{\
    jd = $1; \
    if (P>0) phase = (jd/P) - int(jd/P) ; \
    else phase = jd-2455000; \
    printf("%.4f %s %s\n", phase, $2,$3) \
  }' \
| graph -T $Vgraph -C -I e -L "$S" --pen-colors 1=red3:2=red \
  $plotarg -X $X:q -Y $Y:q $argv:q
-source=$theCat/$Tab
-out=BJD,RV,e_RV
====EOQ
exit 0
