#!/bin/csh
# Finds typical width & typical spacing of the layers of a job
# Used for impedance specifications
# Input:
#    out_file - file to hold width & spacing results
# Output:
#    foreach signal & mixed layer, the following in the out_file:
#       <layer> <line_width in mils> <spacing in mils>
set temp_file = /tmp/imp.$$.$DISPLAY
 
if ($#argv != 1) then
   echo "Wrong number of parameters"
   exit 1
endif
 
set out_file = $1
 
COM info,args =-t step -e $JOB/$STEP -d CHECKS_LIST,\
    out_file=$temp_file, write_mode=replace
 
source $temp_file
 
set found = 0
foreach i ($gCHECKS_LIST)
   if ($i == "imp") then
      set found = 1
   endif
end
 
COM open_entity,job=$JOB,type=step,name=$STEP
 
if (!($found)) then
   COM chklist_create,chklist=imp
   COM chklist_show,chklist=imp
   COM chklist_single,action=valor_analysis_signal,show=yes
   COM chklist_pclear
   COM chklist_pcopy,chklist=valor_analysis_signal,nact=1
   COM chklist_ppaste,chklist=imp,row=0
   COM chklist_close,chklist=valor_analysis_signal
 
   COM chklist_cupd,chklist=imp,nact=1,\
   params=((pp_layer=.type=signal|mixed & context=board)\
           (pp_spacing=20.0)(pp_tests=Spacing;Size;)),mode=regular
endif
 
COM info,args =-t check -e $JOB/$STEP/imp -d STATUS -o action=1,\
    out_file=$temp_file, write_mode=replace
source $temp_file
 
if ($gSTATUS != "DONE") then
   COM chklist_run,chklist=imp,nact=a,area=global
endif

COM editor_page_close

COM info,args=-t check -e $JOB/$STEP/imp -d CHK_ATTR \
       -o action=1,out_file=$temp_file,write_mode=replace
source $temp_file
cp $temp_file /tmp/gv
\rm $temp_file
 
set n = $#gCHK_ATTRname
set i = 1
while ($i <= $n)
   set name = $gCHK_ATTRname[$i]
   if ($name =~ *_par_space) then
      echo $name $gCHK_ATTRval[$i] >> $temp_file
   else if ($name =~ *?_typ_line) then
      echo $name $gCHK_ATTRval[$i] >> $temp_file
   endif 
   @ i++
end
 
cat $temp_file | sed 's/_typ_/ /' | awk '{   \
   lyr[$1] = 0          \
   t = sprintf("%sx%s", $1, $2) \
   info[t] = $3;  \
} \
END { \
   for (i in lyr) { \
      t1 = sprintf("%sx%s", i, "line"); \
      t2 = sprintf("%sx%s", i, "par_space"); \
      info[t1] += 0 \
      info[t2] += 0 \
      print i" "info[t1]" "info[t2] \
   } \
}' > $out_file
 
# \rm $temp_file
