How Wait for Matlab subprocess in opensees(Tcl programming)

Forum for OpenSees users to post questions, comments, etc. on the use of the OpenSees interpreter, OpenSees.exe

Moderators: silvia, selimgunay, Moderators

Post Reply
alima2065
Posts: 13
Joined: Wed Feb 09, 2011 9:15 am
Location: nar

How Wait for Matlab subprocess in opensees(Tcl programming)

Post by alima2065 »

Hi everybody

I Want to Run Matlab in my Opensees script and wait for Matlab results and then continue my code. I have used this script for invoking Matlab but after runing of this script program runs the rest of Tcl code. At this time Matlab is running still. I wonder if you could help me. Thanks
It is my script :

set stat 1
proc getA {stat} {

# invoke matlab
if {[catch {exec matlab -nosplash -nodesktop -r "Node; quit"}]} {
puts "Ignore this $msg"
}

# read matlab result
set fileIN [open filename.txt r]
set fileData [read $fileIN]
close $fileIN

#cleanup

file delete filename.txt

# return result
set lines [split $fileData "\n"]
set A [lindex $lines 0]
}

set A [getA $stat]
canim_ken
Posts: 10
Joined: Tue Feb 24, 2009 8:50 am
Location: Sharif University of Technology

Re: How Wait for Matlab subprocess in opensees(Tcl programmi

Post by canim_ken »

Why don't you write your script in MatLab and run OpenSEES from your MatLab script?
Hadi Kenarangi
miguelnp
Posts: 3
Joined: Wed Oct 31, 2012 2:52 pm

Re: How Wait for Matlab subprocess in opensees(Tcl programmi

Post by miguelnp »

Hello, I hope someone on the forum can help me with this:
I have a script on tcl, where I do a step by step analysis, I need to call Matlab after every single step, do some processes in this Matlab routine, store the results of it on a .txt file, close everything and then go back to OpenSees, run the next step analysis and so on.
I have the same problem mentioned by alima2065, all the subroutines work fine individually, but OpenSees is not waiting for Matlab, it calls it, but continues running, so tcl script finishes and Matlab is still opening windows and obviously everything is incorrect.
So, my question is, is there any command to instruct OpenSees to wait for Matlab until it finishes and closes everything and then continue??, by the way I can't operate OpenSees from Matlab, not in this case, I definitely have to do it this way, thanks a lot!
Panos
Posts: 23
Joined: Fri Jul 20, 2012 10:28 am
Location: National Technical University of Athens

Re: How Wait for Matlab subprocess in opensees(Tcl programmi

Post by Panos »

I am currently facing similar problems, if anyone has found a solution, it'd be very helpful if he posted it!
aghaf
Posts: 6
Joined: Tue Jan 19, 2016 6:54 pm

Re: How Wait for Matlab subprocess in opensees(Tcl programmi

Post by aghaf »

Has anyone figured this out?
yekose
Posts: 50
Joined: Thu May 15, 2008 5:46 am
Location: Turkey

Re: How Wait for Matlab subprocess in opensees(Tcl programmi

Post by yekose »

that wont be an elegant solution but what i would do is, at the end of your matlab text put something --end of file or something mark-- and in your tcl file make a while and like every 10 sec. read your file if it finds your mark that means your process has finished then exit the while and continue to your tcl script :)
fmk
Site Admin
Posts: 5884
Joined: Fri Jun 11, 2004 2:33 pm
Location: UC Berkeley
Contact:

Re: How Wait for Matlab subprocess in opensees(Tcl programmi

Post by fmk »

this is a tcl related question for which there are other resources, e.g. google returns a bunch, e.g.:

http://stackoverflow.com/questions/2504 ... xt-command
aghaf
Posts: 6
Joined: Tue Jan 19, 2016 6:54 pm

Re: How Wait for Matlab subprocess in opensees(Tcl programmi

Post by aghaf »

Many thanks for the answers,
I used the "after 30000" command in Tcl, right after invoking the Matlab code. this way, execution of the rest of the code was delayed for 30 seconds (30000 m seconds) that was enough for the Matlab code to be run.
Post Reply