CFD Online Logo CFD Online URL
Home > Forums > Mesh Generation & Pre-Processing Software > Pointwise & Gridgen

Another scripting Problem

Register Blogs Members List Search Today's Posts Mark Forums Read

LinkBack Thread Tools Search this Thread Display Modes
Old   June 20, 2014, 07:22
Post Another scripting Problem
Vanessa Herwig
Join Date: May 2014
Posts: 36
Rep Power: 12
v_herw is on a distinguished road

i need a bit of help. I scripted a mesh and now i wanted to divide the script into procedures to have a nicer overview over the script. the problem now is that i need in several procedures different Cons/Doms. I wanted to create a procedure where i define all of these parameters to get them later in the procedures.

My script:
# -----------------------------------------------
proc PARAMETER {} {
	global CN(1)
	set CN(1) [pw::GridEntity getByName "TopUpperCon"]
	global CN(2)
	set CN(2) [pw::GridEntity getByName "TopLowerCon"]
	global CN(3)
	set CN(3) [pw::GridEntity getByName "TopTeCon"]	
	global DM(2)
	set DM(2) [pw::GridEntity getByName "TopBlLowerDom"]
	global DM(3)
	set DM(3) [pw::GridEntity getByName "TopBlUpperDom"]
	global DM(4)
	set DM(4) [pw::GridEntity getByName "BottomBlUpperDom"]
	global DM(5)
	set DM(5) [pw::GridEntity getByName "UpperBlDom"]

But this won't work - i get the following fault:

Script: ----- TCL TRACE -----
Script: bad variable name "CN(1)": upvar won't create a scalar variable that looks like an array element
Script:     while executing
Script: "global CN(1)"
Script:     (procedure "PARAMETER" line 22)
Script:     invoked from within
Script:     (file "C:\xxxxxxxxxxxx.glf" line 161)
is there any opportunity to make the parameters "global"??

Thank you very much for your help
v_herw is offline   Reply With Quote

Old   June 22, 2014, 14:18
Senior Member
John Chawner
Join Date: Mar 2009
Location: Fort Worth, Texas, USA
Posts: 275
Rep Power: 18
jchawner is on a distinguished road
Variable scope is a feature of Tcl, not Glyph. Therefore, you can find many online resources such as this one:

This page includes the ability to make variables global in scope. However, in general, global variables are bad practice. I would recommend passing variables to a proc via its parameter list instead.

I hope this helps.
John Chawner / /
on Twitter: @jchawner
jchawner is offline   Reply With Quote

Old   June 23, 2014, 11:49
Senior Member
David Garlisch
Join Date: Jan 2013
Location: Fidelity Pointwise, Cadence Design Systems (Fort Worth, Texas Office)
Posts: 307
Rep Power: 14
dgarlisch is on a distinguished road
To answer your question directly, the error is caused by using the array subscript in the global statement.

I did not test this, but your proc should look like:

proc PARAMETER {} {
  global CN
  set CN(1) [pw::GridEntity getByName "TopUpperCon"]
  set CN(2) [pw::GridEntity getByName "TopLowerCon"]
  set CN(3) [pw::GridEntity getByName "TopTeCon"]	
  set DM(2) [pw::GridEntity getByName "TopBlLowerDom"]
  set DM(3) [pw::GridEntity getByName "TopBlUpperDom"]
  set DM(4) [pw::GridEntity getByName "BottomBlUpperDom"]
  set DM(5) [pw::GridEntity getByName "UpperBlDom"]
HOWEVER, I agree wholeheartedly with John.

Using global variables is a bad* programming practice in general. However, for "quick and dirty" scripts that will be used once and then thrown away, globals may be the easiest way to get things done quickly.

* There are always exceptions to the rules! (bad != NEVER)
dgarlisch is offline   Reply With Quote


global, glyph, parameter, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF compiling problem Wouter Fluent UDF and Scheme Programming 6 June 6, 2012 04:43
Gambit - meshing over airfoil wrapping (?) problem JFDC FLUENT 1 July 11, 2011 05:59
natural convection problem for a CHT problem Se-Hee CFX 2 June 10, 2007 06:29
Adiabatic and Rotating wall (Convection problem) ParodDav CFX 5 April 29, 2007 19:13
Is this problem well posed? Thomas P. Abraham Main CFD Forum 5 September 8, 1999 14:52

All times are GMT -4. The time now is 21:37.