<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Approximatrix Forums — Sharing variables as an argument with Modules]]></title>
	<link rel="self" href="http://forums.approximatrix.com/extern.php?action=feed&amp;tid=630&amp;type=atom" />
	<updated>2017-05-30T05:43:05Z</updated>
	<generator>PunBB</generator>
	<id>http://forums.approximatrix.com/viewtopic.php?id=630</id>
		<entry>
			<title type="html"><![CDATA[Re: Sharing variables as an argument with Modules]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=2899#p2899" />
			<content type="html"><![CDATA[<p>If what you want to achieve is to avoid typing, you can use an INCLUDE file.</p><div class="codebox"><pre><code>! Include file defs.inc
double precision :: a, b, c</code></pre></div><div class="codebox"><pre><code>! Main program
Program Various
Implicit None
include &#039;defs.inc&#039;
call SRTN01()
Print *, a,b,c
End Program Various</code></pre></div><div class="codebox"><pre><code>Subroutine SRTN01()
Implicit None
include &#039;defs.inc&#039;
End Subroutine SRTN01</code></pre></div><p>It doesn&#039;t gain you much in this simple example. If you have so many arguments that you need such tricks to maintain the code, perhaps it is time to restructure it.</p>]]></content>
			<author>
				<name><![CDATA[davidb]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=3463</uri>
			</author>
			<updated>2017-05-30T05:43:05Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=2899#p2899</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Sharing variables as an argument with Modules]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=2898#p2898" />
			<content type="html"><![CDATA[<p>Yes, the error you got is what I was expecting, &quot;ambiguous reference&quot;.&nbsp; This is gfortran&#039;s way of saying, &quot;hey, you have declared a variable as local (dummy argument) with the same name as a imported module variable; an impossible situation!&quot;.&nbsp; The compiler doesn&#039;t know what to make of that situation, as you are trying to use the same name for two different variables.&nbsp; </p><p>If you really want the module variables to be available to the subroutine (same rules for a function), then just USE the module&nbsp; and remove those variables from the argument list.&nbsp; However, if the actual arguments (the ones in the call statement) vary from one call to the next, then remove the USE statement and keep the arguments.&nbsp; </p><p>You&nbsp; might want to do some reading in a Fortran book or online tutorial, as this a feature of Fortran, and has nothing to do with Simply Fortran.</p>]]></content>
			<author>
				<name><![CDATA[baf1]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=3660</uri>
			</author>
			<updated>2017-05-28T22:29:27Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=2898#p2898</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Sharing variables as an argument with Modules]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=2896#p2896" />
			<content type="html"><![CDATA[<p>Thank you Jeff and Baf1 for your response.</p><p>The thing here (and that I forgot to mention) is that the real code where I&#039;m having the problem is much larger and with many variables. I was hoping that there could be a way to declare the variables &quot;a,b,c&quot; globally in a Module and use that as an argument in a subroutine. There are many variables that are used commonly between many subroutines. Otherwise I will have to track down all the variables and declare them locally. If there exist another way would be great.</p><p>Actually the error is:<br />Error: Name &#039;a&#039; at (1) is an ambiguous reference to &#039;a&#039; from current program unit</p><p>Sorry I was thinking that were the same error when I was creating the small example that I posted.</p><p>I&#039;d been trying to solve it with the COMMON statement but wit not success.</p>]]></content>
			<author>
				<name><![CDATA[JManuelR]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=3709</uri>
			</author>
			<updated>2017-05-28T18:32:56Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=2896#p2896</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Sharing variables as an argument with Modules]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=2895#p2895" />
			<content type="html"><![CDATA[<p>More likely what you want to do is leave out the USE statement in the subroutine so that this routine can act on the dummy arguments a, b, and c.</p><p>Subroutine SRTN01(a,b,c)</p><p>Implicit None</p><p>End Subroutine SRTN01</p>]]></content>
			<author>
				<name><![CDATA[baf1]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=3660</uri>
			</author>
			<updated>2017-05-28T17:22:11Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=2895#p2895</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Sharing variables as an argument with Modules]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=2894#p2894" />
			<content type="html"><![CDATA[<p>Your final subroutine is the problem:</p><div class="codebox"><pre><code> Subroutine SRTN01(a,b,c)

Use Datos
Implicit None

End Subroutine SRTN01</code></pre></div><p>The arguments to the subroutine are local variables.&nbsp; The module variables <em>a, b,</em> and <em>c</em> can&#039;t be used as your argument definitions.</p><p>In this case, I&#039;m not sure why you&#039;d pass module variables at all since you&#039;re wanting to access them in the subroutine as well.&nbsp; The code should just be:</p><div class="codebox"><pre><code> Program Various

Use Datos
Implicit None

call SRTN01()

Print *, a,b,c

End Program Various </code></pre></div><p>and</p><div class="codebox"><pre><code> Subroutine SRTN01()

Use Datos
Implicit None

End Subroutine SRTN01 </code></pre></div><p>There&#039;s no reason to pass the variables as arguments.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2017-05-28T14:08:15Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=2894#p2894</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Sharing variables as an argument with Modules]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=2893#p2893" />
			<content type="html"><![CDATA[<p>Hello everyone,</p><p>I have the following problem, my main program calls subroutines that has arguments, those arguments are declared in a module but while compiling the following error appears:</p><p>Error: Symbol &#039;variable&#039; at (1) has no IMPLICIT type</p><p>I dont know what is what I am missing here. I am pretty sure that is something really basic, but I&#039;d been looking around and I cannot find the error.</p><p>I attached an example of the code that I am running. The following is the main program.</p><div class="codebox"><pre><code> Program Various

Use Datos
Implicit None

call SRTN01(a,b,c)

Print *, a,b,c

End Program Various </code></pre></div><p>This is the module.</p><div class="codebox"><pre><code> Module Datos

Implicit None

Double Precision :: a,b,c

End Module Datos </code></pre></div><p>And finally this is the subroutine.</p><div class="codebox"><pre><code> Subroutine SRTN01(a,b,c)

Use Datos
Implicit None

End Subroutine SRTN01 </code></pre></div><p>Every code is stored in a file independently of each other. Any help would be appreciated.</p>]]></content>
			<author>
				<name><![CDATA[JManuelR]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=3709</uri>
			</author>
			<updated>2017-05-28T05:01:20Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=2893#p2893</id>
		</entry>
</feed>
