Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Closing text files before quitting level 1 Fortran Mex function
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
almost_crazy_with_mexing

Posts: 1
From: India
Registered: 1/29/13
Closing text files before quitting level 1 Fortran Mex function
Posted: Jan 29, 2013 5:36 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I open a text file in my level 1 fortran mex function to write the ouput of the my calculations at each instance it is called. However, I am having trouble closing the file after finishing the simulation in simulink.
The sample code is as below

SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS)
! Define all the variables
open(unit=20,file='input.txt')
call main(t,u,y) !Called at each instance of the simulation
return
end

SUBROUTINE MAIN(T,U,Y)
! Perform calculations with t,u,y
write(20,*) T !(say)
return
end

Since I cannot close my input.txt, the next time I run a simulation the simulink crashes saying that it can't open input.txt (unit=20). If I knew where this mexfunction is being called from, I could just put call a terminate function at the end write a simple line saying
close(20)

Can anyone give me advice?

Thanks,



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.