esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% THC.MAC
#%NAME%
#  Macros to read and display thermocouples
#%DESCRIPTION%
#  This macro set is mainly used to do calorimet. measurements
#  (temperature against time) or simply display the temperatures of some   
#  beamline elements in a window.  
#%EXAMPLE%
#%DL%
#%DT%  thcsetup "ID11/thermo/1" 1 2 4 %DD%
#    The thermocouples 1, 2, and 4 will be used on device ID11/thermo/1     
#%DT%  thcread 20 .5 mono_calor %DD%
#    For 20 seconds the temperature on all configured thermocouples (1, 2,
#    and 4) will be read every 2 seconds (0.5 times per second). The
#    results will be plotted and appended to a file named mono_calor.
#  
#%DT%  thcdsetup_first "ID11/thermo/1" "ID11/thermo/2" %DD%
#    The thermocouple display will be used for two devices named 
#    "ID11/thermo/1" and "ID11/thermo/2".
#%DT%  thcdsetup_one 0 3 "Primary slit blades" %DD%
#    Thermocouple 3 on device "ID11/thermo/1" will be displayed first
#    with "Primary slit blades" as a comment. 
#%DT%  thcdsetup_one 1 2 "Primary slit blades" %DD%
#    Thermocouple 2 on device "ID11/thermo/2" will be displayed next
#    with "Secondary slit blades" as a comment. 
#%DT%  thcdsetup_last %DD%
#    The setup for the thermocouple display is done
#%DT%  thcd %DD%
#    Now display our values and refresh the screen every 3 seconds.
#%XDL%

#%UU%  [n-time] [x-updates per second] [filename] 
#%MDESC%

# This macros reads
#    the thermocoupler x times per second for n seconds, do a plot
#    on the screen and writes the data to the file [filename]
#    (The spec timer is used as a timebase. If the software realizes
#    that the time is always 0 (failure of the timer hardware or wrong
#    setup) it will try to get the time from the unix workstation)
def thcread '
#usage thcread [time] [updatetime] [filename]
{
global THC_TIME
global THC_UPDATE
global THC_FILENAME
local _i

if (THC_TIME == 0) THC_TIME=10
if (THC_UPDATE == 0) THC_UPDATE=2
if (THC_FILENAME == "") THC_FILENAME="/dev/null"

if ($# < 1) {
  THC_TIME = getval("Measure the temperature for how many seconds ",THC_TIME)
  }
else {
  THC_TIME=$1
  }

if ($# < 2) {
  THC_UPDATE = getval("Measure the temperature how many times per second ",THC_UPDATE)
  }
else {
  THC_UPDATE=$2
  }

if ($# < 3) {
  THC_FILENAME = getval("Write the results to which file ",THC_FILENAME)
  }
else {
  THC_FILENAME="$3"
  }

_thcread
}
'
#%UU%  [device] [channel1] [channel2] .. 
#%MDESC%

# Use this macro to tell
#    spec which thermocouplers ou want to read. Just type thcsetup
#    and you will be asked some questions  
def thcsetup '
#usage thcsetup [device] [channel1] [channel2] [...]
{
global THC_DATA THC_INDEX THC_NOTOTAL
global THC_DEV THC_NODEV
global THC_CHANNEL THC_NOCHANNEL
global THC_MAX THC_MIN
local _i

THC_DATA =254

if ($#) {
   THC_NODEV=1
   THC_NOCHANNEL[0] = $# - 1
   THC_DEV[0]="$1"
   THC_CHANNEL["0,0"]=$2
   THC_CHANNEL["0,1"]=$3
   THC_CHANNEL["0,2"]=$4
   THC_CHANNEL["0,3"]=$5
   THC_CHANNEL["0,4"]=$6
   THC_CHANNEL["0,5"]=$7
   THC_CHANNEL["0,6"]=$8
   THC_CHANNEL["0,7"]=$9
   } else {
  THC_NODEV = getval("How many thermocouple devices do you have",THC_NODEV)
  for (ii=0;ii<THC_NODEV;ii++) {
    THC_DEV[ii] = getval(sprintf("How is your %d thermocoupler device called ",\
 	ii+1),THC_DEV[ii])
    THC_NOCHANNEL[ii] = getval("No of thermocouples on this device",THC_NOCHANNEL[ii])
    for (_i=0;_i<THC_NOCHANNEL[ii];_i++) {
      THC_CHANNEL[sprintf("%d,%d",ii,_i)]=getval(sprintf("Thermocoupler %d is on which channel",_i+1),THC_CHANNEL[sprintf("%d,%d",ii,_i)])
      }
    }
  }

for (ii=0,jj=0;ii<THC_NODEV;ii++) {
  THC_MAX[ii] = THC_CHANNEL[sprintf("%d,%d",ii,0)]
  THC_MIN[ii] = THC_CHANNEL[sprintf("%d,%d",ii,0)]
  for (_i=0;_i<THC_NOCHANNEL[ii];_i++) {
    THC_INDEX[jj++]= sprintf("%d,%d",ii,_i)
    if (THC_MAX[ii] < THC_CHANNEL[sprintf("%d,%d",ii,_i)]) \
	THC_MAX[ii] = THC_CHANNEL[sprintf("%d,%d",ii,_i)]
    if (THC_MIN[ii] > THC_CHANNEL[sprintf("%d,%d",ii,_i)]) \
	THC_MIN[ii] = THC_CHANNEL[sprintf("%d,%d",ii,_i)]
    }
  }	
THC_NOTOTAL=jj 
}
'

def sim_thcgettemp '
{
  local no _i
  local ARGIN ARGOUT 
  global THC xxx
  ARGIN[0]=THC_MIN[0]
  ARGIN[1]=THC_MAX[0]
  for (_i=0;_i<THC_NOCHANNEL[0];_i++) {
    THC[_i] = _i*xxx + xxx*3 - 34 + xxx*xxx
    xxx+=.1 
    }
} '

def org_thcgettemp '
{
  local no _i
  local ARGIN ARGOUT 
  global THC
  for (ii=0,jj=0;ii<THC_NODEV;ii++) {
    ARGIN[0]=THC_MIN[ii]
    ARGIN[1]=THC_MAX[ii]
    no=esrf_io(THC_DEV[ii],"DevReadValues",ARGIN,ARGOUT)
    for (_i=0;_i<THC_NOCHANNEL[ii];_i++) {
      THC[jj++] = ARGOUT[THC_CHANNEL[sprintf("%d,%d",ii,_i)]-THC_MIN[ii]]
      }
    }
} '

def _thcgettemp 'org_thcgettemp'

def _thchead '
global THC_START
global THC_SCAN 
plot_cntl("filter2")
if (set_sim(-1)) {
  print "***** SIMULATION MODE ******"
  rdef _thcgettemp "sim_thcgettemp"
  }
else {
  rdef _thcgettemp "org_thcgettemp"
  }
offd
if (THC_FILENAME != "/dev/null") on(THC_FILENAME)
printf ("#  Thermo couple report %d \n",THC_SCAN++)
printf ("#  Started %s by %s\n",date(),USER)
Fheader
printf ("#  No      Time")
waitcount
tcount(THC_TIME)
THC_START=time()
for (_i=0;_i<THC_NOTOTAL;_i++) {
  printf("  ThC No%2d",_i+1)
  }
printf ("\n")
data_grp(THC_DATA,4096,THC_NOTOTAL+1)
'

def _thcprinttemp '
{
local _i tt
getcounts
if (S[0] != 0) {
  tt=S[0]
  }
else
  {
  tt=int(time()-THC_START+.5)
  }
data_put(THC_DATA,thc_r,0,tt)
printf("%5d%10.3f",thc_r,tt)
for (_i=0;_i<THC_NOTOTAL;_i++) {
  data_put(THC_DATA,thc_r,_i+1,THC[_i])
  printf("%10.3f",THC[_i])
  }
printf("\n")
}
'
def _thcread '
global thc_r 
rdef cleanup "_thctail"
_thchead
for (thc_r=0;thc_r<THC_TIME*THC_UPDATE;thc_r++) {
  _thcgettemp
  _thcprinttemp
  if (S[0] > THC_TIME) break;
  _thcrplot thc_r 0 THC_TIME*THC_UPDATE
  _thcwait
 }
_thctail
'

def _thcrplot '
	if (PLOT_MODE&128) {
		plot_cntl(sprintf("colors=%s",rplot_col))
		plot_cntl("open")
	}
	if ($1 == 0) {
		plot_cntl("erase")
		plot_range("auto","auto","auto","auto")
		plot_move(0,1,"Temp in Deg.")
	}
	plot_cntl("addpoint")
	data_plot(THC_DATA,0,0,"all")
'

def _thcsplot '

{
if (PLOT_MODE&128) {
	plot_cntl(sprintf("colors=%s",splot_col))
	plot_cntl("open")
}
plot_cntl("erase")
plot_range("auto","auto","auto","auto")
plot_move(0,1,"Temp in Deg.")
data_plot(THC_DATA,0,0,"all")

for (i=0;i<THC_NOTOTAL;i++) {
  if (THC_NOTOTAL<7) {
    if (pos != -60) { 
      pos=-60
      line++
      }
    else {
      pos = -30
      }
     
    plot_move(pos,line,sprintf("Thermocoupler %d Channel %d",i+1,THC_CHANNEL[THC_INDEX[i]]))
    }
  else {
    printf("Thermocoupler %d Channel %d\n",i+1,THC_CHANNEL[THC_INDEX[i]])
    }
  }
}
'
def _thctail '
{
local tt
if (THC_FILENAME != "/dev/null") on(THC_FILENAME)
getcounts
if (S[0] != 0) {
  tt=S[0]
  }
else
  {
  tt=int(time()-THC_START+.5)
  printf("# WARNING Software timer used. Is Timer not working?\n")
  }
printf("# Total time %f seconds\n# Done\n",tt)
if (THC_FILENAME != "/dev/null") close(THC_FILENAME)
_thcsplot
plot_cntl("filter1")

undef cleanup
}
'
def _thcwait '
if (THC_UPDATE) {
  local sltime
  sltime = 1/THC_UPDATE-.14
  if (sltime > 0) sleep (sltime)
  } '


#%UU%  

#%MDESC%
#    display the values on the screen
def thcd '
{
local argin argout
argout[0]=0
for (;;) {
  u clear
  for (ii=0;ii<THCD_NODEV;ii++) {
    argin[0]=THCD_MIN[ii]; argin[1]=THCD_MAX[ii]
    esrf_io(THCD_DEV[ii],"DevReadValues",argin,argout)
    for (i=0;i<THCD_NOCHANNEL[ii];i++) {
      printf("%3d %5d %20s : %6.2f\n",ii,THCD_CHANNEL[sprintf("%d,%d",ii,i)],\
	THCD_NAME[sprintf("%d,%d",ii,i)] ,\
	argout[THCD_CHANNEL[THCD_INDEX[i]]-THCD_MIN[ii]])
      }
    }
  sleep(3)
  }
}
'

#%UU%  

#%MDESC%
#    setup is finished
def thcdsetup_last '
{
global THCD_MIN THCD_MAX THCD_NODEV THCD_NOCHANNEL THCD_INDEX
global THCD_NAME THCD_DEV
for (ii=0,jj=0;ii<THCD_NODEV;ii++) {
  THCD_MAX[ii] = THCD_CHANNEL[sprintf("%d,%d",ii,0)]
  THCD_MIN[ii] = THCD_CHANNEL[sprintf("%d,%d",ii,0)]
  for (_i=0;_i<THCD_NOCHANNEL[ii];_i++) {
    THCD_INDEX[jj++]= sprintf("%d,%d",ii,_i)
    if (THCD_MAX[ii] < THCD_CHANNEL[sprintf("%d,%d",ii,_i)]) \
	THCD_MAX[ii] = THCD_CHANNEL[sprintf("%d,%d",ii,_i)]
    if (THCD_MIN[ii] > THCD_CHANNEL[sprintf("%d,%d",ii,_i)]) \
	THCD_MIN[ii] = THCD_CHANNEL[sprintf("%d,%d",ii,_i)]
    }
  }	
THCD_NOTOTAL=jj 
}
'

#%UU%  <device> <device> 
#%MDESC%

#    set the devices for the thermo couple device server
def thcdsetup_first '
{
global THCD_MIN THCD_MAX THCD_NODEV THCD_NOCHANNEL THCD_INDEX
global THCD_NAME THCD_NOTOTAL THCD_DEV THCD_CHANNEL
THCD_NODEV=$#
THCD_DEV[0]="$1" ; THCD_DEV[1]="$2" ; THCD_DEV[2]="$3" ;THCD_DEV[3]="$4"
THCD_DEV[4]="$5" ; THCD_DEV[5]="$6"
for (ii=0;ii<THCD_NODEV;ii++) {
  THCD_NOCHANNEL[ii]=0
  }
}
'

#%UU%  <device_no> <channel> <text>
#%MDESC%

def thcdsetup_one '
{
global THCD_MIN THCD_MAX THCD_NODEV THCD_NOCHANNEL THCD_INDEX
global THCD_NAME THCD_NOTOTAL
THCD_CHANNEL[sprintf("%d,%d",$1,THCD_NOCHANNEL[$1])]=$2
THCD_NAME[sprintf("%d,%d",$1,THCD_NOCHANNEL[$1])]="$3"
THCD_NOCHANNEL[$1]++
}
'
#%MACROS%
#%IMACROS%
#%ATTENTION%
#%UL%
#%LI% The display will be sorted by device. The individual order will be
#    taken from the input order of thcdsetup_one.
#%LI% Each device will be read via multiple triggered read.
#%XUL%
#%DEPENDENCIES%
# The file thc.mac has to be read in         !done by: startup script
#%AUTHOR%
#  THC.MAC JK 1.93 
#%TOC%