gfortran

How to convert 2D array to 1D array in Fortran code?

北城以北 提交于 2019-12-10 19:07:51
问题 How do I convert r(i,j) to a 1D array so that I can sort the number easily? program sort implicit none character CN*8,O*7 integer j,iconf,nconf integer i,nbins,t integer n,nmax,ind,num,b parameter (n=216) double precision xbox,rq parameter (nmax=3091,nconf=1) double precision atom(nmax),id(nmax),ox(nmax),oy(nmax),oz(nmax) double precision xij,yij,zij,rij double precision r(n,n),A(n) open(unit=10,status='unknown',file='1000.gro') do iconf= 1,nconf write(*,*)iconf read(10,*) read(10,*) do i=1,n

How does automatic typecasting (type conversion) work in Fortran?

倖福魔咒の 提交于 2019-12-10 18:35:05
问题 I am using gfortran compiler. Also tell me if gfortran uses something other than the Fortran standard while performing automatic typecasting (type conversion). 回答1: Assignment is defined by Fortran 2008 Section 7.2. Of note is Cl. 7.2.1.3 paragraph 8: For an intrinsic assignment statement where the variable is of numeric type, the expr may have a different numeric type or kind type parameter, in which case the value of expr is converted to the type and kind type parameter of the variable

Accessing files in sub directory of main program

夙愿已清 提交于 2019-12-10 18:32:44
问题 The folder containing my main executable is very cluttered with input, output and source files. I would like to move some of these files into a different directory to my executable but still be able to access them. It would be fantastic if I could make a directory, for example ./main/outfile , that holds all the output files from my program. Is it possible to include a path when accessing these files in Fortran 77/90? If compilers are of any importance, I use gfortran which is running on

Loading derived types with a subroutine within a module in modern Fortran

微笑、不失礼 提交于 2019-12-10 18:04:20
问题 Goal: use the subroutine load_things to load a library of structures of type su2 . Running gfortran simple.f90 produces Undefined symbols for architecture x86_64: "_load_things_", referenced from: _MAIN__ in cc7DuxGQ.o (maybe you meant: ___myclass_MOD_load_things_sub) ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status The main program follows: program simple use myClass implicit none integer :: nThings type ( su2 ) :: reflections call load_things (

gfortran multiple definition of main

一世执手 提交于 2019-12-10 17:54:23
问题 I'm having trouble with compiling a piece of code I have been given for my research. It consists of one component written in C++ and the other in FORTRAN. I think the problem is to do with my gcc version. The first file for example is a C++ file (foo.ccp) #include <iostream> using namespace std; extern "C" { extern int MAIN__(); } int main(){ cout << "main in C++\n"; return MAIN__(); } The second is bar.f90: program test implicit none print*, 'MAIN in FORTRAN' end program test I'm trying to

SIGFPE: Floating-point exception backtrace for this error: 0x7F70C71AF7D7

泄露秘密 提交于 2019-12-10 17:21:46
问题 I use a Fortran 90 model under Ubuntu 14.04. The gfortran 95 compiler (gfortran 4:4.8.2-1ubuntu6) and the gcc 4:4.8.2-1ubuntu6 are installed by Ubuntu Software Center. After I ran the model I get the following error message: Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation. Backtrace for this error: #0 0x7F70C71AF7D7 #1 0x7F70C71AFDDE #2 0x7F70C68EAD3F #3 0x7F70C6EB6913 Could someone explain me what these backtrace codes mean? How can I handle these

“d” label in the first column, Fortran 77

余生颓废 提交于 2019-12-10 17:13:44
问题 I am modifying a code from a model written in Fortran 77, but I have come across an odd thing to me. In some files, there is a label "d" in the first column of a line, like the example below: d real*8 co2rootfix,co2rootloss,co2shootfix d character komma*1 d open(unit=87,file='crop_CO2.csv',status='unknown') d write(87,*) 'date,co2rootfix,co2rootloss,co2shootfix' d open(unit=88,file='crop_dm.csv',status='unknown') d write(88,*) 'date,wrtpot,wrt,wstpot,wst,rdpot,rd,laipot,lai, d &gwrt,gwst,drrt

gfortran: how to control output directory for .mod files

孤者浪人 提交于 2019-12-10 15:16:10
问题 Is there is a way to put .mod files, generated by gfortran (GCC), into a separate output directory? I know how to place object files or other output with the -o flag as in: gfortran -c test.f03 -o /path/to/output/dir/test.o But the .mod files (which are generated by the above call) are not affected by the -o flag and placed in the current directory. Some commercial compilers have a flag like -qmoddir, but I cannot find something similar for gfortran. If there's no such flag, is it possible to

Segmentation fault for array, but only if a component of a derived type

主宰稳场 提交于 2019-12-10 14:58:10
问题 Pretty simple setup, using gfortran 4.8.5 on linux (red hat): I get a segfault if my array of reals (inside a derived type) has size > 2,000,000. This seems to be a standard stack/heap issue as my stack size is 8mb if I check with ulimit . There is no problem if the array is NOT inside a derived type Note that as @francescalus guesses, removing the initial value = 0.0 eliminates the problem Edit to add: Note that I have posted a followup question Segmentation fault related to component of

Fortran 90 Differences in declaring allocatable array

喜欢而已 提交于 2019-12-10 14:47:44
问题 Is there a difference between integer, intent(in) :: n integer, dimension(:), allocatable :: a allocate(a(n)) and integer, intent(in) :: n integer, dimension(n) :: a In which situation would we use the first version? Perhaps I misunderstood allocatable array, is the second version even an allocatable array? 回答1: The second case indeed doesn't have a allocatable. It is, however, an automatic object. Ignoring the practical differences in memory use at the implementation level, there is a big