fortran90

Ampersand in 5th column and at the end of the line

巧了我就是萌 提交于 2019-12-05 21:33:51
I came across some code today that looks like this: subroutine sub(hello,world,this,routine,takes,a, & & crazy,large,number,of,arguments, & & so,many,that,it,gets,split,across,four, & & lines) It seems that the ampersands in the 5th column are in case the user wants to compile the code with a f77 compiler -- My question is whether this is legitimate (standard conforming) fortran 90 code. I suppose that it probably isn't standard conforming f77 code since the trailing ampersands aren't in column 73 either...but if they were, would this be a standard way to make free-format and fixed-format

Have a function in fortran return a reference that can be placed on the left-hand-side of an assignment

独自空忆成欢 提交于 2019-12-05 20:15:48
As stated in the title, I want to directly modify data that I access through a pointer retrieved from a function. Having a reference returned by a function appearing on the l.h.s. of an assignment(=) is no issue in C++ but the following minimal example in fortran errors out: module test_mod implicit none integer, target :: a=1, b=2, c=3 ! some member variables contains function get(i) integer, pointer :: get integer, intent(in) :: i select case (i) case (1) get => a case (2) get => b case (3) get => c end select end function get end module test_mod program test use test_mod implicit none

Automatic width integer descriptor in fortran 90

◇◆丶佛笑我妖孽 提交于 2019-12-05 18:09:08
I wanted to use automatic integer width descriptor in fortran 90. I referred to Output formatting: too much whitespace in gfortran This question says that I can use I0 and F0,0 for "auto" width. Here is my sample code (complied with GNU Fortran Compiler): PROGRAM MAIN IMPLICIT NONE INTEGER :: i REAL :: j WRITE (*,*) 'Enter integer' READ (*,100) i 100 FORMAT (I0) WRITE (*,*) 'Enter real' READ (*,110) j 110 FORMAT (F0.0) WRITE (*,100) 'Integer = ',i WRITE (*,110) 'Real = ',j END PROGRAM There is runtime error (unit = 5, file = 'stdin') Fortran runtime error: Positive width required in format Am

Open and read data in one row in fortran 90

南笙酒味 提交于 2019-12-05 17:52:00
I did some dummy code to learn to open and read file. Let's say I have the following test.dat which reads 1 2 3 4 5 6 7 8 9 10 I wrote the following code to open and read the data file subroutine readdata implicit none integer :: j double precision :: test open(unit = 100, file = 'test.dat', status = 'old', action = 'read') do j = 1, 10 read(100,*) test print *, 'N1=', test end do end subroutine The output is shown below, as expected gfortran -g -I/usr/include -o main main.o subroutines.o -L/usr/lib64/liblapack -L/usr/lib64/libblas test= 1.0000000000000000 test= 2.0000000000000000 test= 3

Function call stopping/hanging when containing a write-statement, but only when linking with certain libraries during compilation

故事扮演 提交于 2019-12-05 13:54:42
Here is my minimal example: program test implicit none real :: testfunc write(*,*) "Writing from main" write(*,*) testfunc() end program test function testfunc() result(y) real :: y write(*,*) "Write from function g" y=1.0 return end function testfunc When compiling with a simple gfortran test.f90 or when including a library like Slatec gfortran test.f90 -lslatec It works fine. However, when changing the library to -llapack of -lblas, then the program hangs at runtime when calling testfunc(). Note that my example code here does not actually use any of these libraries. The last thing i see is

Using 2d array vs array of derived type in Fortran 90

大憨熊 提交于 2019-12-05 08:20:51
Assuming you want a list of arrays, each having the same size. Is it better performance-wise to use a 2D array : integer, allocatable :: data(:,:) or an array of derived types : type test integer, allocatable :: content(:) end type type(test), allocatable :: data(:) Of course, for arrays of different sizes, we don't have a choice. But how is the memory managed between the 2 cases ? Also, is one of them good code practice ? In general, you want to use the simplest data structure that suits your problem. If a 2d rectangular array meets your needs - and for a huge number of scientific computing

Fortran 90 - “Segmentation fault - invalid memory reference” with scalable 3D array

那年仲夏 提交于 2019-12-05 02:25:41
I have compiled a fortran 90 program with gfortran which builds a scalable 3D array in a way I want. Upon running, I get the following error: Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0x10542ee42 #1 0x10542f60e #2 0x7fff8d7895a9 #3 0x10542575e #4 0x105425975 #5 0x105425d0e Segmentation fault: 11 I believe this is a memory issue with the large 3D array, as it works if I decrease the dimensions, but is there anyway to get around this? Here is my code: PROGRAM phantomtest IMPLICIT NONE INTEGER, PARAMETER:: columns=34, rows=34,

Contains statement

南楼画角 提交于 2019-12-04 21:17:16
问题 I am not understanding the importance of CONTAINS statement in fortran 90 For example PROGRAM BLABLA IMPLICIT NONE INTEGER :: i,j,k i = 1; j = 1;k =1 PRINT *, i,j,k CALL ABC(i,j,k) PRINT *, i,j,k CONTAINS SUBROUTINE ABC(r,s,t) IMPLICIT NONE INTEGER, INTENT(IN) :: r,s INTEGER, INTENT(OUT) :: t t = r + s END SUBROUTINE ABC END PROGRAM BLABLA and one by defining subroutines outside the main program. I understand for functions, one need to specify the type of the function, but for subroutines it

How can I find the cause for a memory leak in Fortran 2003 program?

倖福魔咒の 提交于 2019-12-04 19:45:21
I have a Fortran program I wrote using Fotran 2003 and compiled using Intel(R) Fortran Compiler XE for applications running on IA-32, Version 12.1.2.273 Build 20111128 after running my program for a long run ( it's a physical computation ) I have the out read: Insufficient memory to allocate Fortran RTL message buffer, message I guessed it has to do with memory leak in my program How can I find out where is the leak occurring and how to fix it? As the first answer indicates, your question is very general and not so amendable to a specific answer. Are you using pointers? Pointers are less safe

How could a simple optional argument lead to data corruption?

一世执手 提交于 2019-12-04 19:41:49
I have a FORTRAN code with a routine: SUBROUTINE READ_NC_VALS(NCID, RECID, VARNAME, VARDATA) integer ncid, recid character*(*) varname real*8 vardata dimension vardata(15,45,75) etc. I want to add some flexibility to this code, and I thought I would do it by first adding an optional flag argument: SUBROUTINE READ_NC_VALS(NCID, RECID, VARNAME, VARDATA, how_to_calculate) ! everything the same and then ... logical, optional :: how_to_calculate Now, at this point, I am not even using "how_to_calculate". I am just putting it into the code for testing. So I compile the code without a hitch. Then I