fortran90

Array-valued function

柔情痞子 提交于 2019-12-02 01:31:10
I'm new in the area of Fortran programming and after testing a few programs I already got a feeling of how to write programs. Now I was trying me on a bit harder program and I run into a problem I couldn't solve by myself. I already googled about the problem but I couldn't find an adequate answer ... So I thought maybe there are one or two Fortran programmers which can give me a hand in solving this problem. The program is very simple it just multiplies two matrices with each other. I was trying to write a function which performs the task and returns the result matrix back to the invoker. To

Calling a subroutine in Fortran (Segmentation fault)

故事扮演 提交于 2019-12-02 01:24:14
The following code gives segmentation error when compiled with pgf90 on the Linux system, while is run successfully when I used the Intel Visual FORTRAN on Windows. program main implicit none integer:: a(3), b(3) ,c(3) a=[3, 4, 5] b=[1, 2, 3] call sub(a,b,c) write(*,*)'a+b = ',c end program main subroutine sub(a,b,c) implicit none integer, intent(in)::a(:),b(:) integer, intent(out)::c(:) c=a+b end subroutine sub Any explanation for this ? When you call a subroutine which has assumed shape dummy arguments (as is the case in this program), an explicit interface is required. The easiest way to

passing pointer arguments in fortran

懵懂的女人 提交于 2019-12-02 01:00:57
I am wondering what is the proper way to write the following code? PROGRAM foo INTEGER :: x REAL(KIND=8), TARGET, DIMENSION(0: 10) :: array REAL(KIND=8), POINTER, DIMENSION(:) :: ptr ptr => array CALL bar(ptr) END PROGRAM foo SUBROUTINE bar (ptr) REAL(KIND=8), POINTER, DIMENSION(:) :: ptr INTEGER x DO x =0, 10 ptr(x) = 2 // seg faults ENDDO END SUBROUTINE bar It works if I declare ptr in bar as REAL(KIND=8), DIMENSION(0:10) . But in general I might not know the size of the passed-in array, so is there a way to declare ptr to be a pointer to some array? I am compiling this with gfortran If a

pointer as a dummy argument

拈花ヽ惹草 提交于 2019-12-01 23:59:04
I am somewhat puzzled by the following program module test implicit none type TestType integer :: i end type contains subroutine foo(test) type (TestType), intent(out) :: test test%i = 5 end subroutine subroutine bar(test) type (TestType), intent(out) :: test test%i = 6 end subroutine end module program hello use test type(TestType) :: t call foo(t) print *, t%i call bar(t) print *, t%i end program hello and its derivatives. More on those later. As we know, Fortran transfers routine arguments as a pass-by-reference, meaning that the entity emerging at the dummy argument test for both foo and

How to get the name of a file acting as stdin/stdout?

假如想象 提交于 2019-12-01 21:11:16
I'm having the following problem. I want to write a program in Fortran90 which I want to be able to call like this: ./program.x < main.in > main.out Additionally to "main.out" (whose name I can set when calling the program), secondary outputs have to be written and I wanted them to have a similar name to either "main.in" or "main.out" (they are not actually called "main"); however, when I use: INQUIRE(UNIT=5,NAME=sInputName) The content of sInputName becomes "Stdin" instead of the name of the file. Is there some way to obtain the name of files that are linked to stdin/stdout when the program

Scope of variables in case of modules used by modules in Fortran

余生长醉 提交于 2019-12-01 21:06:48
I've noticed that variables in a (child) module, which are used by a parent modules are accessible in a main program through just the parent module. This is one concept which clearly distinguishes use statement in Fortran from include statement in C/C++. The following programs clearly illustrate this concept. a.f90 module a_mod use b_mod implicit none integer :: a end module b.f90 module b_mod use c_mod implicit none integer :: b end module c.f90 module c_mod implicit none integer :: c = 10 contains subroutine inc_c c = c + 10 end subroutine inc_c end module test.f90 program test use a_mod

keeping array limits in fortran during subroutine call

雨燕双飞 提交于 2019-12-01 17:51:39
I have the following program module test contains subroutine foo() integer, allocatable :: a(:) allocate(a(-5:5)) call bar(a) print *, a end subroutine subroutine bar(a) integer, intent(out) :: a(:) a = 0 a(-4) = 3 ! here a(2) = 3 end subroutine end module program x use test call foo() end program In the line marked with "here" I am doing something wrong. The fact is that when I receive the array a (in the caller allocated from -5 to +5), the callee uses conventional numbering (1 to n), meaning that assigning -4 I am doing an out of boundary assignment. How can I instruct the compiler that,

Fortran 90 difference between compaq visual fortran and gfortran

喜欢而已 提交于 2019-12-01 14:07:17
This may be a specific question, but I think it pertains to how memory is handled with these two compilers (Compaq visual Fortran Optimizing Compiler Version 6.5 and minGW). I am trying to get an idea of best practices with using pointers in Fortran 90 (which I must use). Here is an example code, which should work "out of the box" with one warning from a gfortran compiler: "POINTER valued function appears on RHS of assignment", and no warnings from the other compiler. module vectorField_mod implicit none type vecField1D private real(8),dimension(:),pointer :: x logical :: TFx = .false. end

Converting data stored in Fortran 90 binaries to human readable format

我们两清 提交于 2019-12-01 11:54:22
In your experience, in Fortran 90, what is the best way to store large arrays in output files? Previously, I had been trying to write large arrays to ASCII text files. For example, I would do something like this (thanks to the recommendation at the bottom of the page In Fortran 90, what is a good way to write an array to a text file, row-wise? ): PROGRAM testing1 IMPLICIT NONE INTEGER :: i, j, k INTEGER, DIMENSION(4,10) :: a k=1 DO i=1,4 DO j=1,10 a(i,j)=k k=k+1 END DO END DO OPEN(UNIT=12, FILE="output.txt", ACTION="WRITE", STATUS="REPLACE") DO i=1,4 DO j=1,10 WRITE(12, "(i2,x)", ADVANCE="NO")

Opening multiple files in Fortran 90

别等时光非礼了梦想. 提交于 2019-12-01 09:10:19
I would like to open 10,000 files with file names starting from abc25000 until abc35000 and copy some information into each file. The code I have written is as below: PROGRAM puppy IMPLICIT NONE integer :: i CHARACTER(len=3) :: n1 CHARACTER(len=5) :: cnum CHARACTER(len=8) :: n2 loop1: do i = 25000 ,35000 !in one frame n1='abc' write(cnum,'(i5)') i n2=n1//cnum print*, n2 open(unit=i ,file=n2) enddo loop1 end This code is supposed to generate files starting from abc24000 until abc35000 but it stops about half way saying that At line 17 of file test-openFile.f90 (unit = 26021, file = '') Fortran