LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-04-2014, 02:56 AM   #1
Jykke
Member
 
Registered: Sep 2005
Posts: 201

Rep: Reputation: 19
TCL array problem


I am fairly bad at tcl, but I am trying to write my own procedures for a commercial software that has tcl API.

I have following procedure:
proc crs_rot { axis value } {
set actvie [GNS_get_system_var ACTVIEWID]
array set csecdef [GNS_get_cross_section $actvie 0 0]
# foreach {key value} [array get csecdef] {
# puts $key
# puts $value
# }
}

at this stage the API command GNS_get_cross_section is of importance.
puts [GNS_get_cross_section $actvie 0 0] will return following stuff:
STATE off TYPE Euler GEO show LINE on WIDTH 1 STYLE con RGBA {1 0 0 1} PIDCOLOR off INNERSOL off TAIL {1329 -739.4 514.4} DIRECTION {0 1 0}

at this moment I am interested in the DIRECTION vector {0 1 0}

the foreach loop works ok - I can print out the keys STATE TYPE GEO etc.
or values.

The important question is, how can I get only the specific entry DIRECTION without looping through
the whole array? And while we are at it, how can I get the vector {0 1 0} separated into components x, y and z?
 
Old 12-05-2014, 03:59 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
I don't really know much TCL either, but here are my guesses...

Quote:
The important question is, how can I get only the specific entry DIRECTION without looping through
the whole array?
According to http://wiki.tcl.tk/1032

Code:
$csecdef(DIRECTION)
Quote:
And while we are at it, how can I get the vector {0 1 0} separated into components x, y and z?
I think lindex should work:
Code:
set x [lindex $csecdef(DIRECTION) 0]
set y [lindex $csecdef(DIRECTION) 1]
set z [lindex $csecdef(DIRECTION) 2]
 
Old 12-08-2014, 05:58 AM   #3
Jykke
Member
 
Registered: Sep 2005
Posts: 201

Original Poster
Rep: Reputation: 19
This way it works:

Code:
	set secvec $csecdef([array names csecdef DIRECTION])
	set dx [lindex $secvec 0]
	set dy [lindex $secvec 1]
	set dz [lindex $secvec 2]
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH-Adding array element: Naming issue using array[${#array[*]}]=5 calvarado777 Programming 8 07-26-2013 09:48 PM
Little error (not harmful) exists in tcl.SlackBuild (source slackbuilds for Tcl) blancamolinos Slackware 3 01-14-2013 05:46 AM
tcl problem khodeir Programming 17 03-16-2009 06:49 AM
Cannot find Tcl dll ( Perl's Tcl bridge ) Xyem Linux - Software 2 08-08-2006 09:45 AM
tcl newbie: can't count length of array jimieee Programming 12 06-03-2006 12:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration