<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Ok David. in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039346#M112662</link>
    <description>&lt;P&gt;Ok David.&lt;/P&gt;

&lt;P&gt;I'm attaching the codes. 3 Modules in Fortran and 1 class in C#.&lt;/P&gt;

&lt;P&gt;Is it enough?&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Oct 2014 10:56:43 GMT</pubDate>
    <dc:creator>Master_Fortran</dc:creator>
    <dc:date>2014-10-29T10:56:43Z</dc:date>
    <item>
      <title>Exporting Fortran Modules to C# and Returning NaN</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039344#M112660</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;

&lt;P&gt;I have 3 Modules in Fortran. Those modules return 3 variables. Let's call them: Modules A, B and C and variables A, B and C. &amp;nbsp;&lt;/P&gt;

&lt;P&gt;I'm exporting the Modules through a DLL to be showed in three diferent TextBoxes in C#. &amp;nbsp;Module A is independent. Module B calls Module A and Module C calls both Modules A and B.&lt;/P&gt;

&lt;P&gt;When I importing those Modules in C# and display the variables A, B and C, what I get is a correct value for variable A in the fisrt TextBox and NaN for variables B and C! (See the attatched figure)&lt;/P&gt;

&lt;P&gt;I really don't know I to do now. I get all the right results when I run the code in a main program only in Fortran.&lt;/P&gt;

&lt;P&gt;Can somebody help me, please?&lt;/P&gt;

&lt;P&gt;Thanks in advance.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2014 01:30:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039344#M112660</guid>
      <dc:creator>Master_Fortran</dc:creator>
      <dc:date>2014-10-29T01:30:54Z</dc:date>
    </item>
    <item>
      <title>We really need to see your</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039345#M112661</link>
      <description>&lt;P&gt;We really need to see your code to understand what you are doing.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2014 07:47:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039345#M112661</guid>
      <dc:creator>DavidWhite</dc:creator>
      <dc:date>2014-10-29T07:47:29Z</dc:date>
    </item>
    <item>
      <title>Ok David.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039346#M112662</link>
      <description>&lt;P&gt;Ok David.&lt;/P&gt;

&lt;P&gt;I'm attaching the codes. 3 Modules in Fortran and 1 class in C#.&lt;/P&gt;

&lt;P&gt;Is it enough?&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2014 10:56:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039346#M112662</guid>
      <dc:creator>Master_Fortran</dc:creator>
      <dc:date>2014-10-29T10:56:43Z</dc:date>
    </item>
    <item>
      <title>Guys,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039347#M112663</link>
      <description>&lt;P&gt;Guys,&lt;/P&gt;

&lt;P&gt;I discovered that when I fix the value of the variable reyOleo, for example: reyOleo = 4000, it calculates the&amp;nbsp;fatAtrito. However, if reyOleo is calculated, it returns a correct value for reyOleo, but NaN for fatAtrito.&lt;/P&gt;

&lt;P&gt;I'm really don't understanding. It seems that C# is not &amp;nbsp;undestading the follwing peace of code:&lt;/P&gt;

&lt;P&gt;reyOleo &amp;nbsp;= (39370.1/86400.0) * (vazaoOleo * diametroTubo * massaEspecOleo / (viscOleo * areaTubo))&lt;/P&gt;

&lt;P&gt;Any clue?&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2014 18:30:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039347#M112663</guid>
      <dc:creator>Master_Fortran</dc:creator>
      <dc:date>2014-10-29T18:30:24Z</dc:date>
    </item>
    <item>
      <title>Your problem description is</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039348#M112664</link>
      <description>&lt;P&gt;Given a problem description that is imprecise and vague, there may be little that we can do to help you. Try to remember that we are not standing at your shoulder observing all the things that you do. If you are going to do mixed language programming with shared variables, you need a good understanding of the scope of variables, accessibility of variables and the consequences of aliasing.&lt;/P&gt;

&lt;P&gt;Nevertheless, I spot one source of trouble: in the Reynol.f90 file, you have module variables with the same names as the formal (dummy) arguments to a contained subprogram. Read the the Fortran documentation as to the implications of doing this, and ask yourself, "what do I want the compiler to do when it sees a reference or an assignment to one of these variables in the subprogram code? Use/update the formal &amp;nbsp;argument, the module variables, or both? Furthermore, &amp;nbsp;if the caller also uses the module, you could have two seemingly different variables that are tied to the same memory address, and chaos can follow -- the left hand does not know what the right hand is doing.&lt;/P&gt;

&lt;P&gt;Try the following test: add the following lines to reynol.f90, and run the program. You will see that the variable Reyoleo retains the original value of 20000, whereas you might have expected it to have the newly computed value of the actual argument e, which corresponds to the formal argument ReyOleo in the subroutine.&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program bugrey
use Reynolds
double precision a,b,c,d,e

ReyOleo = 20000
a=5; b=0.1; c=800; d=10; e=20
call Reynol(a,b,c,d,e)
write(*,*)ReyOleo,e
end program
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2014 20:18:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039348#M112664</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2014-10-29T20:18:00Z</dc:date>
    </item>
    <item>
      <title>Thank you, mecej4.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039349#M112665</link>
      <description>&lt;P&gt;Thank you, mecej4.&lt;/P&gt;

&lt;P&gt;I think I got it. I did what you suggested. In Reynol.f90 I have no more module variables with the same name of the dummy arguments.&lt;/P&gt;

&lt;P&gt;Now I have different variables in this module with this call:&lt;/P&gt;

&lt;PRE class="brush:fortran;" style="font-size: 13px; line-height: 19.5120010375977px;"&gt;call Reynol(vazaoOleo_, diametroTubo_, massaEspecOleo_, viscOleo_, reyOleo_)&lt;/PRE&gt;

&lt;P&gt;However, it's resulting in fatrito = 1, i.e, when reyOleo is passed to reyOleo_ , for some reason it assumes a zero value or:&lt;SPAN style="font-family: Consolas, 'Lucida Console', Menlo, Monaco, 'DejaVu Sans Mono', monospace, sans-serif; line-height: 19.5120010375977px;"&gt;(reyOleo_ &amp;lt;= 2100d0).&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="line-height: 19.5120010375977px;"&gt;Jesus, it's not so simple...&lt;/SPAN&gt;&lt;SPAN style="font-family: Consolas, 'Lucida Console', Menlo, Monaco, 'DejaVu Sans Mono', monospace, sans-serif; line-height: 19.5120010375977px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="line-height: 19.5120010375977px;"&gt;In FatFan.f90 I did:&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt; module Fatrito

    use Reynolds

    implicit none

    contains
    
    subroutine Fatfan(rugoTubo, fatAtrito)   
    
        !DEC$ ATTRIBUTES DLLEXPORT :: Fatfan
                            
        double precision, intent(in)  :: rugoTubo   
        double precision, intent(out) :: fatAtrito

        double precision :: A1
        double precision :: A2
        
        double precision :: vazaoOleo_, diametroTubo_, massaEspecOleo_, viscOleo_, reyOleo_
        
        call Reynol(vazaoOleo_, diametroTubo_, massaEspecOleo_, viscOleo_, reyOleo_)
        
        if (reyOleo_ &amp;lt;= 2100d0) then
            
            fatAtrito = 1
             
        end if         
        
        if (reyOleo_ &amp;gt;= 4000.d0) then
            
            fatAtrito = 2
            
        end if
            
        if (reyOleo_ &amp;gt;2100d0 .and. reyOleo_ &amp;lt;4000d0) then 
                
            fatAtrito = 3
            
        end if
        
    end subroutine
end module
&lt;/PRE&gt;

&lt;PRE class="brush:;"&gt; module Reynolds
 
    implicit none
    
    contains
 
    subroutine Reynol(vazaoOleo, diametroTubo, massaEspecOleo, viscOleo, reyOleo)
    
        !   ReyOleo = Número de Reynolds do óleo
    
        !DEC$ ATTRIBUTES DLLEXPORT :: Reynol
        
        double precision, intent(in)  :: vazaoOleo, diametroTubo, massaEspecOleo, viscOleo  
        double precision, intent(out) :: reyOleo
    
        double precision :: areaTubo
    
        parameter pi = 3.1415927d0
    
        areaTubo = (pi * diametroTubo **2) / 4
       
        reyOleo  = (39370.1/86400.0) * (vazaoOleo * diametroTubo * massaEspecOleo / (viscOleo * areaTubo))
        
    end subroutine
end module&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Oct 2014 22:35:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039349#M112665</guid>
      <dc:creator>Master_Fortran</dc:creator>
      <dc:date>2014-10-29T22:35:48Z</dc:date>
    </item>
    <item>
      <title>It is not worthwhile to mix</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039350#M112666</link>
      <description>&lt;P&gt;It is not worthwhile to mix code fragments that are scattered in the various posts. Please show a complete example and we can look at the problem.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Oct 2014 23:56:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039350#M112666</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2014-10-29T23:56:17Z</dc:date>
    </item>
    <item>
      <title>mecej4,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039351#M112667</link>
      <description>&lt;P&gt;mecej4,&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;I reproduced this problem in a simpler example of 2 modules. In one I sum two numbers and in the other to get the result of this sum and multiply it for another entry value. For the first module I got the right result, but for the other I had a problem, as you can see below.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;module SumTwoNumbers
    
    implicit none
    
    contains
    
subroutine SumNumbers(a, b, c)	

	!DEC$ ATTRIBUTES DLLEXPORT :: SumNumbers
    
    ! Declaring variables:
    double precision, intent(in) :: a, b
    double precision, intent(out) :: c
        
    ! Summing two numbers:        
	c = a + b   
    
end subroutine 

end module

module MultiplyNumbers
    
    use SumTwoNumbers
    
    implicit none
    
    contains
    
subroutine MultiNumbers(d, e)	

	!DEC$ ATTRIBUTES DLLEXPORT :: MultiNumbers
    
    !Declaring variables:
    double precision, intent(in) :: d
    double precision, intent(out) :: e
    
    double precision :: a_,b_,c_
    
    call SumNumbers(a_,b_,c_)
    
    !Multiplying numbers:        
    e = c_ * d
    
end subroutine 

end module&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2014 10:15:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039351#M112667</guid>
      <dc:creator>Master_Fortran</dc:creator>
      <dc:date>2014-10-30T10:15:29Z</dc:date>
    </item>
    <item>
      <title>Quote:Ewerton C. wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039352#M112668</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Ewerton C. wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;..&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;..
    
subroutine MultiNumbers(d, e)	

	!DEC$ ATTRIBUTES DLLEXPORT :: MultiNumbers
    
    !Declaring variables:
    double precision, intent(in) :: d
    double precision, intent(out) :: e
    
    double precision :: a_,b_,c_
    
    call SumNumbers(a_,b_,c_)
    
    !Multiplying numbers:        
    e = c_ * d
    
end subroutine 

end module&lt;/PRE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;Amongst other things, in your MultiNumbers procedure, think about where and how the variables a_, b_, and c_ get their values.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2014 11:10:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039352#M112668</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2014-10-30T11:10:31Z</dc:date>
    </item>
    <item>
      <title>It WORKED!</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039353#M112669</link>
      <description>&lt;P&gt;It WORKED!&lt;/P&gt;

&lt;P&gt;See what I did in module SumTwoNumbers.&lt;/P&gt;

&lt;P&gt;Variables a_, b_ and c_ &amp;nbsp;receives a, b and c, respectively. And I declared a_, b_ and c_ globally.&lt;/P&gt;

&lt;P&gt;In MultiplyNumbers module,&amp;nbsp;I didn't need to call SumNumbers, just used the USE statement.&amp;nbsp;However, I dont know if it's the only and most appropriate way to pass variables through modules.&lt;/P&gt;

&lt;PRE class="brush:;"&gt;module SumTwoNumbers
    
    implicit none
    
    double precision :: a_,b_,c_
    
    contains
    
subroutine SumNumbers(a, b, c)	

	!DEC$ ATTRIBUTES DLLEXPORT :: SumNumbers
    
    ! Declaring variables:
    double precision, intent(in) :: a, b
    double precision, intent(out) :: c
        
    ! Summing two numbers:        
	c = a + b
    
    a_  = a
    b_  = b
    c_  = c
    
end subroutine 

end module


module MultiplyNumbers
    
    use SumTwoNumbers
    
    implicit none
      
    contains
    
subroutine MultiNumbers(d, e)	

	!DEC$ ATTRIBUTES DLLEXPORT :: MultiNumbers
    
    !Declaring variables:
    double precision, intent(in) :: d
    double precision, intent(out) :: e
    
    !Multiplying numbers:        
    e = c_ * d
    
end subroutine 

end module&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2014 12:00:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Exporting-Fortran-Modules-to-C-and-Returning-NaN/m-p/1039353#M112669</guid>
      <dc:creator>Master_Fortran</dc:creator>
      <dc:date>2014-10-30T12:00:45Z</dc:date>
    </item>
  </channel>
</rss>

