0

I have a TCL script as the attached below.

The code works perfectly fine; I tested with several inputs before however, i have an issue with an input file Defect.csv. I try remove spaces, lines and convert to unix format using unix2dos however, i get this error -can't use empty string as operand of "*"-

I can see format is still messed up. i believe it does not recognize the "Y" due to the spaces. I tried the following to try to remove the spaces/tabs cat OverlapVGSnets.csv | sed 's/ //g' sed 's/ //g' OverlapVGSnets.csv but, this does not solve this. Any suggestion?

See input

X       ,       Y
5568687 ,       260755
5568687 ,       259891
5568687 ,       259999
5568687 ,       260755

script:

set x1 [lindex $coords 0]
set y1 [lindex $coords 1]
#The coordinates are to be converted into angstroms 
set x2 [expr {int($x1*10)}]
set y2 [expr {int($y1*10)}]
foreach nets [::GetNetsInRegion $x2 $y2 $x2 $y2 vcg temp] 
{puts $outfile $nets foreach masterclose  
[::cadnavapi::layoutAPI::GetMasterCellName $nets]
{puts $outfile $master}}}} $outfile
user5987994
  • 9
  • 1
  • 10
  • Comma is not a list separator in Tcl. If you just remove all spaces, each line will have one single element ([digits],[digits]). Still, you can use that if you split on comma first: lassign [split $line.,] x1 y1 – Peter Lewerin Jul 16 '17 at 04:35
  • Show how you populate the $coords list. – glenn jackman Jul 16 '17 at 11:42
  • I don't think that's exactly your code; `foreach` wants the first brace of its body parameter on the same line as the previous parameter (or at least a backslash in front of the newline(s) that separate(s) them). – Donal Fellows Jul 17 '17 at 14:50
  • I think i found the issue; basically this is in the input file. – user5987994 Jul 19 '17 at 17:55

2 Answers2

1
can't use empty string as operand of "*"

Tcl will raise the above error if the either of the operands used for any expressions is empty.

% set x1 4
4
% set x2 [expr {int($x1*10)}]
40
% set x1 {}
% set x2 [expr {int($x1*10)}]
can't use empty string as operand of "*"
%

In your code, you are getting the variables x1, y1 as follows,

set x1 [lindex $coords 0]
set y1 [lindex $coords 1]

Add a check to ensure it is not empty such as ,

if {$x1 eq {} || $y1 eq {}} {
    puts "Empty records"
    exit 1
}
Dinesh
  • 16,014
  • 23
  • 80
  • 122
  • Could you see my update and the input? i believe i have something that is making the spaces and this is why the y is not getting read. How can i remove the tab/spaces, etc ? i tried stardard sed and cat procedures but, something got messed up from the windows transfer (dos2unix does not do it either). Noemi – user5987994 Jul 16 '17 at 03:50
0

The issue was in the input file; I was creating this from a big data file using this:

awk -F '[(),]' 'BEGIN{OFS="\t"; print "X","Y"} {print $2,$3}' file

The problem is that the TCL was strict and this will fault with the "spaces" so, i change that to this and that works

awk -F '[(),]' 'BEGIN{OFS=","; print "X","Y"} {print $2,$3}'

user5987994
  • 9
  • 1
  • 10