{"id":1341,"date":"2022-01-05T01:35:24","date_gmt":"2022-01-05T09:35:24","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1341"},"modified":"2022-01-05T01:35:24","modified_gmt":"2022-01-05T09:35:24","slug":"133-create-vectors-and-planes-using-tcl-in-hypermesh-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2022\/01\/133-create-vectors-and-planes-using-tcl-in-hypermesh-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2\/","title":{"rendered":"#251 Global variable using global keyword in tcl"},"content":{"rendered":"<p>The global variable can be declared with the global keyword.<\/p>\n<p>Example:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nset globalvar 100.2\r\nproc test1 {} {\r\n    global globalvar\r\n    puts &quot;test1: $globalvar&quot;\r\n}\r\nproc test2 {} {\r\n    global globalvar\r\n    puts &quot;test2: $globalvar&quot;\r\n}\r\ntest1\r\ntest2\r\n<\/pre>\n<p>Result:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ntest1: 100.2\r\ntest2: 100.2\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The global variable can be declared with the global keyword. Example: set globalvar 100.2 proc test1 {} { global globalvar puts &quot;test1: $globalvar&quot; } proc test2 {} { global globalvar puts &quot;test2: $globalvar&quot; } test1 test2 Result: test1: 100.2 test2: 100.2<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[27],"tags":[],"class_list":["post-1341","post","type-post","status-publish","format-standard","hentry","category-tcl"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-lD","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1339,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/01\/133-create-vectors-and-planes-using-tcl-in-hypermesh-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":1341,"position":0},"title":"#250 Global variable using :: prefix in tcl","author":"gantovnik","date":"2022-01-05","format":false,"excerpt":"Qualifying a global variable is done by prefixing the variable name with the :: character sequence. This is a special case of namespace qualification where the :: prefix indicates that the variable resides in the global namespace. Example: [code language=\"python\"] set globalvar 100.2 proc test1 {} { puts \"test1: $::globalvar\"\u2026","rel":"","context":"In &quot;tcl&quot;","block_context":{"text":"tcl","link":"https:\/\/gantovnik.com\/bio-tips\/category\/tcl\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":781,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/11\/134-global-variable-in-tcl\/","url_meta":{"origin":1341,"position":1},"title":"#134 Global variable in tcl","author":"gantovnik","date":"2020-11-12","format":false,"excerpt":"#134 Global variable in tcl [code language=\"python\"] set f \"This is a global variable\"; #This procedure cannot access the global variable f. proc testproc1 { } { catch {puts $f} val; puts $val; } #This procedure can access the global variable f using the global command. proc testproc2 { }\u2026","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":783,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/11\/135-global-namespace-in-tcl\/","url_meta":{"origin":1341,"position":2},"title":"#135 Global namespace in tcl","author":"gantovnik","date":"2020-11-12","format":false,"excerpt":"#135 Global namespace in tcl It is possible to reference global variables inside procedures using global namespace indicator: [code language=\"python\"] set ::element_list \"1 2 3 4 5\"; proc ::element_info {} { puts $::element_list; set ::node_list \"10 20 30 40\"; puts $::node_list; } element_info; 1 2 3 4 5 10 20\u2026","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1331,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/01\/133-create-vectors-and-planes-using-tcl-in-hypermesh-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":1341,"position":3},"title":"#246 Create a procedure with variable number of arguments in tcl","author":"gantovnik","date":"2022-01-04","format":false,"excerpt":"An example of a procedure with variable number of arguments is [code language=\"python\"] proc avg {numbers} { set sum 0 foreach number $numbers { set sum [expr $sum + $number] } set average [expr $sum\/[llength $numbers]] return $average } puts [avg {50 50 50 60}] puts [avg {50 50 50}]\u2026","rel":"","context":"In &quot;tcl&quot;","block_context":{"text":"tcl","link":"https:\/\/gantovnik.com\/bio-tips\/category\/tcl\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":833,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/147-count-the-total-number-of-fields-in-a-file-using-awk\/","url_meta":{"origin":1341,"position":4},"title":"#147 Count the total number of fields in a file using awk","author":"gantovnik","date":"2021-01-14","format":false,"excerpt":"#147 Count the total number of fields in a file using awk Assume we have \"test1.txt\" file with data in columns: [code language=\"python\"] a b c d e f g h i j k l 1 2 3 4 [\/code] Save the following awk script in the file \"ex147.awk\" [code\u2026","rel":"","context":"In &quot;awk&quot;","block_context":{"text":"awk","link":"https:\/\/gantovnik.com\/bio-tips\/category\/awk\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1337,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/01\/133-create-vectors-and-planes-using-tcl-in-hypermesh-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":1341,"position":5},"title":"#249 Creating namespace in tcl","author":"gantovnik","date":"2022-01-05","format":false,"excerpt":"Namespace is a container for a set of identifiers that are used to group variables and procedures. Example: [code language=\"python\"] namespace eval MyMath { # Create a variable inside the namespace variable myResult } # Create procedures inside the namespace proc MyMath::Add {a b } { set ::MyMath::myResult [expr $a\u2026","rel":"","context":"In &quot;tcl&quot;","block_context":{"text":"tcl","link":"https:\/\/gantovnik.com\/bio-tips\/category\/tcl\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=1341"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1341\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}