<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — Modify variable inside a subroutine]]></title>
		<link>https://forums.approximatrix.com/viewtopic.php?id=212</link>
		<atom:link href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=212&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Modify variable inside a subroutine.]]></description>
		<lastBuildDate>Fri, 07 Jun 2013 16:26:12 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Modify variable inside a subroutine]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=821#p821</link>
			<description><![CDATA[<p>I would suggest possibly moving your variables into a module that both the main program and the subroutine &quot;use.&quot;</p><div class="codebox"><pre><code>module myData
    integer::a, b, c
end module myData

module myModule
implicit none
contains
    subroutine mySub()
    use myData
    implicit none
        a=2
        b=5
        c=3
    end subroutine mySub
end module myModule

program main
use myModule
use myData
implicit none
    
    a = 0
    call mySub()
    a = a +1
    
end program main</code></pre></div><p>In the above example, the variables are still compartmentalized via the myData module, but both your subroutine and the main program can modify them.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Fri, 07 Jun 2013 16:26:12 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=821#p821</guid>
		</item>
		<item>
			<title><![CDATA[Modify variable inside a subroutine]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=819#p819</link>
			<description><![CDATA[<p>What I am asking is not safe at all, but I work on an old code, and that seems to be the fastest way to do it.</p><p>So, I have a main program, and a module with subroutine. This module is call by my main program. In my subroutine, a lot of variable are modified, and I want all these modifications to be effective in my main program after calling my subroutine.</p><p>Example :<br />MODULE myModule<br />&nbsp; &nbsp; IMPLICIT NONE<br />&nbsp; &nbsp; CONTAINS<br />&nbsp; &nbsp; &nbsp; &nbsp; subroutine mySub()<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; integer :: a, b, c<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a=2;b=5;c=3<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end subroutine mySub</p><p>program main<br />&nbsp; &nbsp;use myModule<br />&nbsp; &nbsp;integer :: a, b, c<br />&nbsp; &nbsp; &nbsp;a = 0<br />&nbsp; &nbsp; &nbsp;call mySub()<br />&nbsp; &nbsp; a = a +1<br />end program main</p><p>I want my program to give the value 3 to variable &#039;a&#039;, not 1. I know I can do :<br />subroutine mySub(a,b,c)<br />&nbsp; &nbsp; integer, intent(inout) :: a, b, c</p><p>But that&#039;s not what I want, because there are too many variables (like 100). Is there a way to automatically have all my variable in my subroutine act as an intent(out) value without call them in the call of my subroutine?</p><p>In fortran77, when you had a program and a subroutine in the same file, it was possible to modifiy variables in the subroutine, and used the new value in the main program after calling the subroutine. I ask for the same thing.</p><p>Sorry for my bad english...</p>]]></description>
			<author><![CDATA[null@example.com (pierre.peclet-ext)]]></author>
			<pubDate>Fri, 07 Jun 2013 09:18:07 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=819#p819</guid>
		</item>
	</channel>
</rss>
