<?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 Re: Using INQUIRE( SIZE=) in a function leds to immediate termination in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216585#M152199</link>
    <description>&lt;P&gt;Recursive I/O, such as the invocation of a function in an expression in an I/O list, when the function itself perfoms I/O to the same unit, can cause problems. I am not sure if such I/O is still forbidden by the standard, but Intel Fortran did have &lt;A href="https://community.intel.com/t5/Intel-Fortran-Compiler/runtime-I-O-error-in-recursive-function/td-p/745332" target="_self"&gt;Error 40&lt;/A&gt; for such errors. See also this &lt;A href="https://community.intel.com/t5/Intel-Fortran-Compiler/Recursive-I-O-operation-error-inside-error-handler/td-p/1142416" target="_self"&gt;post&lt;/A&gt; by Steve L.&lt;/P&gt;
&lt;P&gt;Intel Fortran on Windows will give you a line number traceback if you compile with the /traceback compiler option.&lt;/P&gt;
&lt;P&gt;You can overcome the problem by breaking up the PRINT statement as&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;sz=local_getsize('test.txt')
print*, "local_getsize('test.txt'): ", sz&lt;/LI-CODE&gt;</description>
    <pubDate>Sun, 11 Oct 2020 12:46:43 GMT</pubDate>
    <dc:creator>mecej4</dc:creator>
    <dc:date>2020-10-11T12:46:43Z</dc:date>
    <item>
      <title>Using INQUIRE( SIZE=) in a function leds to immediate termination</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216566#M152198</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I am trying to implement a function getsize() to return the size of a file (*). When I use gfortran for this, it works fine, but using Intel Fortran 18 on either Windows or Linux the program crashes immediately. On Linux I see this stacktrace:&lt;/P&gt;
&lt;P&gt;~/tmp/fortran&amp;gt; ifort stdlib_test.f90&lt;BR /&gt;~/tmp/fortran&amp;gt; ./a.out&lt;BR /&gt;Start&lt;BR /&gt;Size: -1&lt;BR /&gt;forrtl: severe (174): SIGSEGV, segmentation fault occurred&lt;BR /&gt;Image PC Routine Line Source &lt;BR /&gt;a.out 000000000040456D Unknown Unknown Unknown&lt;BR /&gt;libpthread-2.12.s 00007F6D526AE7E0 Unknown Unknown Unknown&lt;BR /&gt;a.out 0000000000420B01 Unknown Unknown Unknown&lt;BR /&gt;a.out 00000000004036A3 Unknown Unknown Unknown&lt;BR /&gt;a.out 000000000040349E Unknown Unknown Unknown&lt;BR /&gt;libc-2.12.so 00007F6D52329D1D __libc_start_main Unknown Unknown&lt;BR /&gt;a.out 00000000004033A9 Unknown Unknown Unknown&lt;/P&gt;
&lt;P&gt;On Windows this is not shown, but the program simply stops.&lt;/P&gt;
&lt;P&gt;Here is the program:&lt;/P&gt;
&lt;P&gt;program stdlib_test&lt;/P&gt;
&lt;P&gt;!use os_path&lt;/P&gt;
&lt;P&gt;implicit none&lt;BR /&gt;integer :: unit&lt;BR /&gt;logical :: error&lt;/P&gt;
&lt;P&gt;integer :: ierr&lt;BR /&gt;integer :: sz&lt;/P&gt;
&lt;P&gt;character(len=:), allocatable, dimension(:) :: split_str&lt;BR /&gt;character(len=:), allocatable :: startdir&lt;/P&gt;
&lt;P&gt;print*, "Start"&lt;/P&gt;
&lt;P&gt;inquire( file = 'testtxt', size = sz, iostat = ierr )&lt;BR /&gt;print*, "Size: ", sz&lt;/P&gt;
&lt;P&gt;print*, "local_getsize('test.txt'): ", local_getsize('test.txt')&lt;BR /&gt;!print*, "getsize('test.txt'): ", getsize('test.txt')&lt;BR /&gt;print*, "Done"&lt;/P&gt;
&lt;P&gt;contains&lt;BR /&gt;function local_getsize(path)&lt;/P&gt;
&lt;P&gt;!integer(int64) :: getsize&lt;BR /&gt;integer :: local_getsize&lt;BR /&gt;character(len=*), intent(in) :: path&lt;BR /&gt;integer :: ierr&lt;/P&gt;
&lt;P&gt;!write(*,*) '&amp;gt;&amp;gt;', path&lt;BR /&gt;inquire( file = path, size = local_getsize, iostat = ierr )&lt;BR /&gt;if ( ierr /= 0 ) then&lt;BR /&gt;local_getsize = -1&lt;BR /&gt;endif&lt;BR /&gt;!write(*,*) '&amp;gt;&amp;gt;', getsize&lt;/P&gt;
&lt;P&gt;end function local_getsize&lt;BR /&gt;end program stdlib_test&lt;/P&gt;
&lt;P&gt;If I uncomment the write statement in the function, it works fine. Note that the INQUIRE statement in the main program works fine as well.&lt;/P&gt;
&lt;P&gt;Is there any way I can get this to work?&lt;/P&gt;
&lt;P&gt;(*) This is part of an effort to create a "standard library" - see &lt;A href="https://fortran-lang.org/packages/libraries" target="_blank"&gt;https://fortran-lang.org/packages/libraries&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 09:54:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216566#M152198</guid>
      <dc:creator>Arjen_Markus</dc:creator>
      <dc:date>2020-10-11T09:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using INQUIRE( SIZE=) in a function leds to immediate termination</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216585#M152199</link>
      <description>&lt;P&gt;Recursive I/O, such as the invocation of a function in an expression in an I/O list, when the function itself perfoms I/O to the same unit, can cause problems. I am not sure if such I/O is still forbidden by the standard, but Intel Fortran did have &lt;A href="https://community.intel.com/t5/Intel-Fortran-Compiler/runtime-I-O-error-in-recursive-function/td-p/745332" target="_self"&gt;Error 40&lt;/A&gt; for such errors. See also this &lt;A href="https://community.intel.com/t5/Intel-Fortran-Compiler/Recursive-I-O-operation-error-inside-error-handler/td-p/1142416" target="_self"&gt;post&lt;/A&gt; by Steve L.&lt;/P&gt;
&lt;P&gt;Intel Fortran on Windows will give you a line number traceback if you compile with the /traceback compiler option.&lt;/P&gt;
&lt;P&gt;You can overcome the problem by breaking up the PRINT statement as&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;sz=local_getsize('test.txt')
print*, "local_getsize('test.txt'): ", sz&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 11 Oct 2020 12:46:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216585#M152199</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2020-10-11T12:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using INQUIRE( SIZE=) in a function leds to immediate termination</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216587#M152200</link>
      <description>&lt;P&gt;You misunderstand the problem, I am afraid. If I do NOT include the write statement in the function, the program fails. I tried the /traceback option on Windows, but that did not give any useful information - the program simply stops without any output. When I do include the write statement, it works.&lt;/P&gt;
&lt;P&gt;A suggestion I received was to open the file and inquire via the unit number, that does work. Not ideal, but better than the program simply stopping.&lt;/P&gt;
&lt;P&gt;(My apologies for including the program code as plain text instead of code, by the way. I did not think of that possibililty)&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 13:03:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216587#M152200</guid>
      <dc:creator>Arjen_Markus</dc:creator>
      <dc:date>2020-10-11T13:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using INQUIRE( SIZE=) in a function leds to immediate termination</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216593#M152201</link>
      <description>&lt;P&gt;Here is a program that DOES work with the simple implementation:&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;module sizes
    use iso_fortran_env, only: int64
private
public :: getsize
contains
integer(int64) function getsize( filename )
    character(len=*), intent(in) :: filename

    integer :: ierr

    inquire( file = 'testje.f90', size = getsize, iostat = ierr )
end function getsize
end module sizes

program chksize
    use sizes
    implicit none

    write(*,*) getsize('testje.f90')


end program chksize
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have no idea what makes this program behave so differently from the previous one. Mind you: I have tried a number of variants, with the implementation of getsize() in a separate module and in the same source file as the main program etc.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 14:09:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216593#M152201</guid>
      <dc:creator>Arjen_Markus</dc:creator>
      <dc:date>2020-10-11T14:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using INQUIRE( SIZE=) in a function leds to immediate termination</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216602#M152202</link>
      <description>&lt;P&gt;When I assign result of function local_getsize(path) to a variable and call the print with variable, it works fine. What would be fortran print function evaluation rules(or not)?&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 18:12:08 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216602#M152202</guid>
      <dc:creator>MWind2</dc:creator>
      <dc:date>2020-10-11T18:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using INQUIRE( SIZE=) in a function leds to immediate termination</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216604#M152203</link>
      <description>&lt;P&gt;This is clearly a bug in the run-time library. The access violation appears within the call in the main program to transmit the function result value. (I did have to fix up "testtxt" in the initial INQUIRE and create the test.txt file). There's nothing wrong with doing the INQUIRE in the function. Please submit a bug report to Intel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 18:22:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216604#M152203</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2020-10-11T18:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using INQUIRE( SIZE=) in a function leds to immediate termination</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216611#M152204</link>
      <description>&lt;P&gt;If I can assign to a variable&amp;nbsp;sz=local_getsize('test.txt'), and&amp;nbsp;print*, "local_getsize('test.txt'): ", sz, but cannot&amp;nbsp;print*, "getsize('test.txt'): ", getsize('test.txt'), then would it not seem to be a problem with print statement implementation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;sz=local_getsize('test.txt')
print*, "local_getsize('test.txt'): ", sz !works
print*, "local_getsize('test.txt'): ", local_getsize('test.txt')! crashes&lt;/LI-CODE&gt;
&lt;P&gt;but then the following works&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;program testprint
    
    implicit none
    ! Variables
     integer :: ix
    ! Body of testprint
    ix = iresult(37)
    print *, ix
    print *, iresult(37)
    print *,'Done'
contains
    function iresult (iin)
    integer, intent(in)::iin
    integer :: iresult
      iresult = iin*2+iin/3
    end function iresult
    

    end program testprint&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 21:59:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216611#M152204</guid>
      <dc:creator>MWind2</dc:creator>
      <dc:date>2020-10-11T21:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using INQUIRE( SIZE=) in a function leds to immediate termination</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216646#M152205</link>
      <description>&lt;P&gt;You have a test case - send it to Intel and let them figure out what went wrong. My guess (much of my career was working on Fortran I/O libraries) is that some internal state is not being set or restored correctly when the INQUIRE happens in the middle of another I/O statement.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 00:17:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216646#M152205</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2020-10-12T00:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using INQUIRE( SIZE=) in a function leds to immediate termination</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216862#M152214</link>
      <description>&lt;P&gt;I may be completely overlooking it, but I cannot find the right webpage to report this - I do feel a bit awkward about that. Can you point in the right direction?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 14:19:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216862#M152214</guid>
      <dc:creator>Arjen_Markus</dc:creator>
      <dc:date>2020-10-12T14:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using INQUIRE( SIZE=) in a function leds to immediate termination</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216875#M152215</link>
      <description>&lt;P&gt;&lt;A href="https://supporttickets.intel.com/" target="_blank"&gt;https://supporttickets.intel.com/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 15:16:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216875#M152215</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2020-10-12T15:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using INQUIRE( SIZE=) in a function leds to immediate termination</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216881#M152217</link>
      <description>&lt;P&gt;Thank you - I have submitted the problem report, support case &lt;SPAN&gt;&lt;A class="support-request-id" style="cursor: pointer;" target="_blank"&gt;04834525&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 15:32:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-INQUIRE-SIZE-in-a-function-leds-to-immediate-termination/m-p/1216881#M152217</guid>
      <dc:creator>Arjen_Markus</dc:creator>
      <dc:date>2020-10-12T15:32:09Z</dc:date>
    </item>
  </channel>
</rss>

