segmentation error in linux for ansys

前端 未结 1 853
无人及你
无人及你 2021-01-24 17:40

I am writting a usersubroutine using Fortran (Intel Composer (2011.1.107)) for ANSYS14.5.7 I have edited the code to write some data into an external sequential file and read th

相关标签:
1条回答
  • 2021-01-24 18:04

    Low unit numbers are typically reserved for "special units" like STDOUT, STDERR, STDIN. Do not use these (unless you know what you are doing), or something unexpected might happen. I'm mildly aware that there is some upper limit for unit numbers, but I can't find a reference at the moment.

    So the easiest way to solve your problem would be to add an offset to the unit (which again would lead to problems for large arrays), or use newunit= if your compiler supports it. But since you close the files at the end of the loop body, way not use a fixed number like 1234?

    But you have more issues with your code: The line

    write (filename1, '( "Element_", I4)' )  ElementNo
    

    will lead to problems (for most compilers).

    Consider this simple program:

    program test
      write (*, '( "Element_", I4)' )  1
      write (*, '( "Element_", I4)' )  10
      write (*, '( "Element_", I4)' )  100
      write (*, '( "Element_", I4)' )  1000
      write (*, '( "Element_", I4)' )  10000
    end program
    

    The output is:

    Element_   1
    Element_  10
    Element_ 100
    Element_1000
    Element_****
    

    Which leads to a file name that contains spaces. This might lead to an error! What you could do is change the format specifier to use a fixed length by using '( "Element_", I4.4)', which would give you:

    Element_0001
    Element_0010
    Element_0100
    Element_1000
    Element_****
    

    You can see that four digits is still too small to hold the larger elements, but no spaces any more.

    Finally, if you wanted the numbers to start after the slash directly without the leading zeros you could use a combination of adjustl() and trim():

    program test
      character(len=32)  :: filename
    
      write (filename, '(I4)')  1
      filename = "Element_" // adjustl(trim(filename))
      write(*,'(a)') filename
      write (filename, '(I4)')  10
      filename = "Element_" // adjustl(trim(filename))
      write(*,'(a)') filename
      write (filename, '(I4)')  100
      filename = "Element_" // adjustl(trim(filename))
      write(*,'(a)') filename
    end program
    

    results in

    Element_1                       
    Element_10                      
    Element_100  
    
    0 讨论(0)
提交回复
热议问题