fortran90

How to use Fortran 77 subroutines in Fortran 90/95?

99封情书 提交于 2019-11-28 08:56:15
问题 I'm writing a code with Fortran 90 and now I need to use the special functions in the*amos Fotran 77 library(http://www.netlib.org/amos/). Now I found a module interface for those routines(https://github.com/certik/fortran-utils/blob/master/src/amos.f90). My question is: how can I combine them and use them in my Fortran 90 program and how to compile them correctly? I have been struggling for this for one whole day and still could not figure it out. The following is my test code: PROGRAM TEST

how to stop a fortran program abnormally

守給你的承諾、 提交于 2019-11-28 08:34:16
问题 When an exception occurs I would like to terminate abnormally my program. Right now, when an exception happens a write statement with an explanatory sentence is called, and then a stop statement is called. I am debugging the program with idb (intel debugger), when the exception happens I get the write statement, but idb treats the program as terminated normally. I would like that when the exception happens the program is terminated abnormally and so that I can look to the memory with

f2py: Specifying real precision in fortran when interfacing with python?

烈酒焚心 提交于 2019-11-28 07:46:57
I am playing around with f2py. I'm a bit confused about numpy intrinsic types vs. fortran 90 types. It seems like I can only use single precision reals in fortran 90, when interacting with python. Let me illustrate with an example: Say I have this fortran 90 module, test.f90, to be compiled with f2py and imported in python: module test implicit none integer, parameter :: sp = selected_real_kind(6,37) ! single precision integer, parameter :: dp = selected_real_kind(15,307) ! double precision real(sp) :: r_sp = 1.0 real(dp) :: r_dp = 1.0_dp end module and I compile like this: f2py -c -m test

Segmentation fault during MPI_FINALIZE() in Fortran

若如初见. 提交于 2019-11-28 06:47:55
问题 I am getting a segmentation fault during a call to MPI_FINALIZE() in a Fortran 90 program. While the code is quite extensive, I will post the pseudocode and see if it raises any flags. I have a hunch (but have not yet tried this) that it could possibly be caused by not deallocating arrays? I'm not sure however - can failure to deallocate arrays in Fortran 90 cause segmentation faults during a call to MPI_FINALIZE ? if(<rank 0>) then do iat = 1,natoms do il = 0, LMAX do im = -il,il <mpi_recv

How can gfortran tell if I am compiling f90 or f95 code?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 06:35:27
I understand gfortran can compile f90 or f95? How does it know which one it is compiling? Also can it compile f77 code? Does ubuntu already have a fortran compiler or do I need to download gfortran? Jonathan Dursi gfortran can guess certain things from the file extension; if the file has an extension of .f, .f90, f95, .f03, or .f08 it will assume fixed (.f) or free format with the appropriate standards. But you can force it to compile (say) fortran2003 code with the option -std=f2003. Eg, from the documentation , -std=std Specify the standard to which the program is expected to conform, which

Broadcast array multiplication in Fortran 90/95

痞子三分冷 提交于 2019-11-28 04:30:34
问题 I was wondering that would there be a better (succinct) way to code this in Fortran? I am trying to multiply each column of a(3, 3) by each value in b(3) . I know in Python there is np.multiply , and not sure about Fortran. !!! test.f90 program test implicit none integer, parameter :: dp=kind(0.d0) real(dp) :: a(3, 3)=reshape([1, 2, 3, 4, 5, 6, 7, 8, 9], [3, 3]),& b(3)=[1, 2, 3] integer :: i do i = 1, 3 a(:, i) = a(:, i) * b(i) end do write(*, *) a end program test Thanks in advance! 回答1: The

Skip a line from text file in Fortran90

给你一囗甜甜゛ 提交于 2019-11-28 03:38:57
问题 I'm writing in fortran (90). My program must read file1, do something with every line of it and write result to file2. But the problem - file1 has some unneeded information in first line. How can I skip a line from input file using Fortran? The code: open (18, file='m3dv.dat') open (19, file='m3dv2.dat') do read(18,*) x tmp = sqrt(x**2 + 1) write(19, *) tmp end do First line is a combination of text and numbers. 回答1: You already found the solution but I just wanted to add that you don't even

What flags do you set for your GFORTRAN debugger/compiler to catch faulty code?

独自空忆成欢 提交于 2019-11-28 03:09:01
I think I won't find that in any textbook, because answering this takes experience. I am currently in the stage of testing/validating my code / hunting bugs to get it into production state and any errors would lead to many people suffering e.g. the dark side. What kind of flags do you set when you compile your program for Fortran for debugging purposes? What kind of flags do you set for the production system? What do you do before you deploy? The production version uses ifort as a compiler, yet I do my testing with gfortran . Am I doing it wrong? Bare minimum -Og / -O0 -O0 basically tells the

Proper use of the PURE keyword Fortran

一笑奈何 提交于 2019-11-28 02:36:31
问题 I'm currently delving into Fortran and I've come across the pure keyword specifying functions/subroutines that have no side effects. I have a book, Fortran 90/95 by S Chapman which introduces the pure keyword but strangely provides no "good coding practice" uses. I'm wondering how liberally one should use this keyword in their procedures. Just by looking around it's obvious to me that most procedures without side effects don't find it necessary to include the pure keyword. So where is it best

Wrong result when using a global variable in Fortran

怎甘沉沦 提交于 2019-11-28 02:28:08
I'm learning the basics of Fortran. I created a simple subroutine initializing a matrix: program test integer, parameter :: n = 1024 real :: a(n, n) call init(a) write (*, *) a(1, 1) end program subroutine init(a) real :: a(n, n) a(:, :) = 3.0 end subroutine Then the output is 0.0 instead of expected 3.0 . Apart from that, valgrind says that: ==7006== Conditional jump or move depends on uninitialised value(s) ==7006== at 0x400754: init_ (in /home/marcin/proj/mimuw/fortran/test) ==7006== by 0x4007A4: MAIN__ (in /home/marcin/proj/mimuw/fortran/test) ==7006== by 0x40083B: main (in /home/marcin