You are here: Surpac Concepts > Macros > TCL > Formatting output
GEOVIA Surpac

Fomrmatting TCL output

These examples show how greater control over the formatting of output can be achieved using the format command.

  • Format coordinate values just like in a string file
    In this example notice how the coordinate values are only reported to 3 decimal places with rounding and redundant zeros where appropriate.
    		set stringnum 1
    		set ypos 100
    		set xpos 235.4567
    		set zpos 99.1
    		set ptdesc "a, value, in, each, desc, field"
    		format "%d, %.3f, %.3f, %.3f, %s" $stringnum $ypos $xpos $zpos $ptdesc
    		
    	

    Output

    		1, 100.000, 235.457, 99.100, a, value, in, each, desc, field
    		
    	
  • Format coordinate values in a fixed field width for a report In this example notice how the coordinate values are only reported to 3 decimal places with rounding and redundant zeros where appropriate and the field width is constant to ensure alignment of columns.

    See how the point description is surrounded by " characters by escaping the " characters with the \ character.

    		set stringnum 1
    		set ypos 100
    		set xpos 235.4567
    		set zpos 99.1
    		set ptdesc "a value, in, each, desc, field"
    		format "%5d %10.3f %10.3f %10.3f    \"%s\"" $stringnum $ypos $xpos $zpos $ptdesc
    		
    	

    Output

    		    1    100.000    235.457     99.100    "a, value, in, each, desc, field"
    		
    	
  • Zero fill numbers in the field width specified by using a leading zero in the format.

    See how the point description is surrounded by " characters by escaping the " characters with the \ character.

    		set stringnum 1
    		set ypos 100
    		set xpos 235.4567
    		set zpos 99.1
    		set ptdesc "a value, in, each, desc, field"
    		format "%05d %010.3f %010.3f %010.3f    \"%s\"" $stringnum $ypos $xpos $zpos $ptdesc
    		
    	

    Output

    		00001 000100.000 000235.457 000099.100    "a, value, in, each, desc, field"
    	scan