|
[Sponsors] |
June 20, 2014, 08:22 |
Another scripting Problem
|
#1 |
Member
Vanessa Herwig
Join Date: May 2014
Posts: 36
Rep Power: 12 |
Hi,
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: Code:
# PROCEDURE TO SET UP ALL PARAMETER # ----------------------------------------------- proc PARAMETER {} { # SET THE CONS/DOMS OF THE LAST SECTION 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"] } Code:
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: "PARAMETER" Script: (file "C:\xxxxxxxxxxxx.glf" line 161) Thank you very much for your help |
|
June 22, 2014, 15:18 |
|
#2 |
Senior Member
John Chawner
Join Date: Mar 2009
Location: Fort Worth, Texas, USA
Posts: 275
Rep Power: 18 |
Variable scope is a feature of Tcl, not Glyph. Therefore, you can find many online resources such as this one: https://www.tcl.tk/man/tcl8.5/tutorial/Tcl13.html
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 / jrc@pointwise.com / www.pointwise.com Blog: http://blog.pointwise.com/ on Twitter: @jchawner |
|
June 23, 2014, 12:49 |
|
#3 |
Senior Member
David Garlisch
Join Date: Jan 2013
Location: Fidelity Pointwise, Cadence Design Systems (Fort Worth, Texas Office)
Posts: 307
Rep Power: 14 |
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: Code:
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"] } 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) |
|
Tags |
global, glyph, parameter, script |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF compiling problem | Wouter | Fluent UDF and Scheme Programming | 6 | June 6, 2012 05:43 |
Gambit - meshing over airfoil wrapping (?) problem | JFDC | FLUENT | 1 | July 11, 2011 06:59 |
natural convection problem for a CHT problem | Se-Hee | CFX | 2 | June 10, 2007 07:29 |
Adiabatic and Rotating wall (Convection problem) | ParodDav | CFX | 5 | April 29, 2007 20:13 |
Is this problem well posed? | Thomas P. Abraham | Main CFD Forum | 5 | September 8, 1999 15:52 |