Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Closing text files before quitting level 1 Fortran Mex function
Posted:
Jan 29, 2013 5:36 AM
|
|
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,
|
|
|
|