#=============================================================================== # Macro Package: table.mac Version 1.0 #------------------------------------------------------------------------------- print "table.mac Version 1.0" #------------------------------------------------------------------------------- # This package contains macros moving and scanning EPICS table record. # -- Mostly it clones the macros in "slits_xor.mac", however some changes are # made to take the advantages of associative arrays. # # -- It also defines a new _wait_epics function instead of using waitEP. # "_wait_epics" may be relatively generic than "waitEP". # # -- Epics slits record in "slits_xor.mac" can be easily remolded to this style. # # # Written by X. Jiao 06/01/2005 # # # User macros: # # conftables - Defines table to be used interactively # # addtables - A fast way to define a table,supplemental to conftables # # rmtables - To delelte one entry from the table configuration, might # be useful # # showtables - To list all tables configuration, also show current table # position. Can use as "showtables table_mne" too. # # mvtables - Moves table table_parameter to given position # # tablescan - Scans a table in x, y, z, ax, ay, az # # tablelup - Similiar to tablescan, but in lup mode # # # Modification History: # # # # #=============================================================================== global _tbl_part_mv [] global _tbl_part_rb [] _tbl_part_mv["x"] = ".X"; _tbl_part_rb["x"] = ".EX" _tbl_part_mv["y"] = ".Y"; _tbl_part_rb["y"] = ".EY" _tbl_part_mv["z"] = ".Z"; _tbl_part_rb["z"] = ".EZ" _tbl_part_mv["ax"] = ".AX"; _tbl_part_rb["ax"] = ".EAX" _tbl_part_mv["ay"] = ".AY"; _tbl_part_rb["ay"] = ".EAY" _tbl_part_mv["az"] = ".AZ"; _tbl_part_rb["az"] = ".EAZ" global table_pv[] global table_name[] #------------------------------------------------------------------------------- # addtable -> set a new mnemonic table #------------------------------------------------------------------------------- def addtable ' if ( $# != 3 ) { print "Usage: addtable table_mnemonic table_name table_pv_name " print "i.e. addtable tb2 XXX:Table2" exit } table_pv["$1"] = "$3" table_name["$1"] ="$2" ' #------------------------------------------------------------------------------- # rmtable -> remove a menmonic from the table_pv array #------------------------------------------------------------------------------- def rmtable ' if ( $# != 1 ) { print "Usage: rmtable table_mnemonic " exit } delete table_pv["$1"] delete table_name["$1"] ' #------------------------------------------------------------------------------- # showtables -> display all the mnemonic tables (or specified) configuration #------------------------------------------------------------------------------- def showtables '{ local n t[] i _x _y _z _ax _ay _az #if (unset("table_pv")) {global table_pv[] table_name[]} if($# != 0) { n=split("$*",t) for ( i in t) if ( !(table_num(t[i])) ) exit printf("\n\n%8.8s %15.15s %15.15s %8.3s %8.3s %8.3s %8.3s %8.3s %8.3s\n",\ "Mne","Name","EPICS_PV","X","Y","Z","AX","AY","AZ") for( i in t) { _x=epics_get(sprintf("%s%s",table_pv[t[i]],_tbl_part_rb["x"])) _y=epics_get(sprintf("%s%s",table_pv[t[i]],_tbl_part_rb["y"])) _z=epics_get(sprintf("%s%s",table_pv[t[i]],_tbl_part_rb["z"])) _ax=epics_get(sprintf("%s%s",table_pv[t[i]],_tbl_part_rb["ax"])) _ay=epics_get(sprintf("%s%s",table_pv[t[i]],_tbl_part_rb["ay"])) _az=epics_get(sprintf("%s%s",table_pv[t[i]],_tbl_part_rb["az"])) printf("%8.8s %15.15s %15.15s %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n",\ t[i],table_name[t[i]],table_pv[t[i]],_x,_y,_z,_ax,_ay,_az) } } else { if(_aa_length(table_pv) == 0) { print "No table defined. Run conftables or addtable to define." }else { printf("\n\n%8.8s %15.15s %15.15s %8.3s %8.3s %8.3s %8.3s %8.3s %8.3s\n",\ "Mne","Name", "EPICS_PV","X","Y","Z","AX","AY","AZ") for( i in table_pv) { _x=epics_get(sprintf("%s%s",table_pv[i],_tbl_part_rb["x"])) _y=epics_get(sprintf("%s%s",table_pv[i],_tbl_part_rb["y"])) _z=epics_get(sprintf("%s%s",table_pv[i],_tbl_part_rb["z"])) _ax=epics_get(sprintf("%s%s",table_pv[i],_tbl_part_rb["ax"])) _ay=epics_get(sprintf("%s%s",table_pv[i],_tbl_part_rb["ay"])) _az=epics_get(sprintf("%s%s",table_pv[i],_tbl_part_rb["az"])) printf("%8.8s %15.15s %15.15s %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n",\ i,table_name[i],table_pv[i],_x,_y,_z,_ax,_ay,_az) } } } }' #------------------------------------------------------------------------------- # conftables -> set up tables interactively #------------------------------------------------------------------------------- def conftables '{ local foo p "Current Table Setup:" showtables while(yesno("Configure a new table?","1")) { foo=getval("Table nmenonic:","") table_name[foo] = getval("Table Name","") table_pv[foo] = getval("EPICS PV","") } p "New Table Setup:" showtables }' #------------------------------------------------------------------------------- # mvtable -> move table table_parameter to value # umvtable -> like umv, wait for moving done. #------------------------------------------------------------------------------- def mvtable '{ if($# !=3 ) { p "Usage: mvtable table_mne table_param value." exit } local temp_pv1 temp_pv2 if( !(temp_pv1 = table_num("$1"))) exit if( !(temp_pv2 = table_part("$2"))) exit epics_put(sprintf("%s%s",temp_pv1,temp_pv2),$3) }' def umvtable '{ mvtable $* local tmp tmp = table_pv["$1"] ":done" _wait_epics(tmp) tmp = epics_get(sprintf("%s%s",table_pv["$1"],_tbl_part_rb["$2"])) printf("\n%s %s moved to %f\n\n%s \n", "$1","$2",tmp,date()) }' #------------------------------------------------------------------------------- # tablescan -> scan table x,y,z,ax ay az #------------------------------------------------------------------------------- def tablescan '{ if($# != 6) { eprint "Usage: tablescan table_mne table_part start finish intervals time." exit } local tpv1 tpv2 tblmov tblrbv if( !(tpv1 = table_num("$1"))) exit if( !(tpv2 = table_part("$2"))) exit tblmov = tpv1 tpv2 tblrbv = tpv1 _tbl_part_rb["$2"] _s[0] =$3; _f[0]=$4 _n1 = int($5); _ctime = $6 if(_n1 <=0 ) { print "Number of Intervals <=0 " exit } HEADING = sprintf("tablescan %s(%s) %s %g %g %g %g",\ "$1",tpv1,"$2",$3,$4,$5,$6) _d[0] =(_f[0]-_s[0])/_n1++ X_L = sprintf("%s %s",table_name["$1"],"$2") Y_L = cnt_name(DET) _sx = _s[0]; _fx = _f[0] FPRNT = sprintf("%s%s",table_name["$1"],"$2") PPRNT = sprintf("%9.9s ",table_name["$1"]) VPRNT = PPRNT _stype = 1|(1<<8) _cols = 1 _c1 = epics_get(tblrb) cdef("cleanup_once",sprintf("tablescan_cleanup"),"tablescan") tpv2 = table_pv["$1"] ":done" scan_head def _scan_on \' for(;NPTS<_n1;NPTS++) { local pos pos = _s[0] +NPTS*_d[0] epics_put(tblmov,pos) _wait_epics(tpv2) pos = epics_get(tblrbv) FPRNT = sprintf("%g ",pos) PPRNT = sprintf("%9.4f", pos) VPRNT = PPRNT scan_loop scan_data(NPTS,pos) scan_plot } scan_tail \' _scan_on cdef("cleanup_once","","tablescan","delete") tablescan_cleanup tblmov tpv2 }' #------------------------------------------------------------------------------- # tablelup -> lup table in x y z ax ay az #------------------------------------------------------------------------------- def tablelup '{ if($# !=6) { eprint "Usage: tablelup table_mne table_part start finish intervals time." exit } local tpv1 tpv2 tblmov tblrbv if( !(tpv1 = table_num("$1"))) exit if( !(tpv2 = table_part("$2"))) exit tblmov = tpv1 tpv2 tblrbv = tpv1 _tbl_part_rb["$2"] _c1 = epics_get(tblrb) _s[0] =_c1+$3; _f[0]=_c1+$4 _n1 = int($5); _ctime = $6 if(_n1 <=0 ) { print "Number of Intervals <=0 " exit } HEADING = sprintf("tablelup %s(%s) %s %g %g %g %g",\ "$1",tpv1,"$2",$3,$4,$5,$6) _d[0] =(_f[0]-_s[0])/_n1++ X_L = sprintf("%s %s",table_name["$1"],"$2") Y_L = cnt_name(DET) _sx = _s[0]; _fx = _f[0] FPRNT = sprintf("%s%s ",table_name["$1"],"$2") PPRNT = sprintf("%9.9s ",table_name["$1"]) VPRNT = PPRNT _stype = 1|(1<<8) _cols = 1 cdef("cleanup_once",sprintf("tablescan_cleanup"),"tablescan") tpv2 = table_pv["$1"] ":done" scan_head def _scan_on \' for(;NPTS<_n1;NPTS++) { local pos pos = _s[0] +NPTS*_d[0] epics_put(tblmov,pos) _wait_epics(tpv2) pos = epics_get(tblrbv) FPRNT = sprintf("%g ",pos) PPRNT = sprintf("%9.4f", pos) VPRNT = PPRNT scan_loop scan_data(NPTS,pos) scan_plot } scan_tail \' _scan_on cdef("cleanup_once","","tablescan","delete") tablescan_cleanup tblmov tpv2 }' #=============================================================================== # Internal macros/functions #=============================================================================== #------------------------------------------------------------------------------- # _aa_length -> return numberof elements in an associative array #------------------------------------------------------------------------------- def _aa_length(aname) '{ local field n if( !( (whatis("aname")>>16)&0x100 ) ) { print "Not an associative array." exit } for(field in aname) n++ return n }' #------------------------------------------------------------------------------- # table_num -> return the epics_pv of the table mnemonic "mne" #------------------------------------------------------------------------------- def table_num (mne) '{ if(_aa_length(table_pv) == 0) { print "No table defined. Run conftables or addtable to define." return ("") } if ( !(table_pv[mne]) ) { printf("\nInvalid table Mnemonic: %s",mne) print "\nRun showtables to see valid table names." return ("") } return(table_pv[mne]) }' #------------------------------------------------------------------------------- # table_part -> return the epics_pv suffix of the table parameter "tp" #------------------------------------------------------------------------------- def table_part(tp) ' { if( !(_tbl_part_mv[tp]) ) { printf("\nInvalid table parameter:%s",tp) print("\nUse only x,y,z,ax,ay,az.") return ("") } return (_tbl_part_mv[tp]) }' #------------------------------------------------------------------------------- # tablescan_cleanup -> move table back to its original positon before the scan #------------------------------------------------------------------------------- def tablescan_cleanup ' _wait_epics($2) printf("\nReturning %s to %g\n",X_L,_c1) epics_put($1,_c1) _wait_epics($2) ' #------------------------------------------------------------------------------- # _wait_epics -> wait the pv (normally like XXX:table:done) to be 1 #------------------------------------------------------------------------------- def _wait_epics(pv)' { sleep(0.05) while( epics_get(pv,"short")==0) sleep(0.05) }'