fortran90

Writing robust and “modern” Fortran code

ぃ、小莉子 提交于 2019-11-29 18:41:43
In some scientific environments, you often cannot go without FORTRAN as most of the developers only know that idiom, and there is lot of legacy code and related experience. And frankly, there are not many other cross-platform options for high performance programming (C++ would do the task, but the syntax, zero-starting arrays, and pointers are not compatible with some people). So, let's assume a new project must use Fortran 90, but I want to build the most modern software architecture out of it, while being compatible with most recent compilers (Intel ifort, but also including the Sun/HP/IBM

Is Fortran unable to do the addition between 865398.78 and -865398.78? Why the answer is -0.03?

痴心易碎 提交于 2019-11-29 17:05:16
In the code below I am adding together 865398.78 and -865398.78. I expect to get 0, but instead I get -0.03. Source Code: program main real(8) :: x open(10,file="test.txt") read(10,*)x print *,"x=",x x=x+865398.78 print *,"x+865398.78=",x end program Result: x= -865398.780000000 x+865398.78= -3.000000002793968E-002 Am I wrong with the usage of "read" codes or something else? The number 865398.78 is represented in single precision in your code. Single precision can handle about 7 significant digits, while your number has 8. You can make it double precision by writing x=x+865398.78_8

Single command to open a file or create it and the append data

放肆的年华 提交于 2019-11-29 16:43:20
问题 I would like to know if in Fortran it is possible to use just a single command (with options/specifiers) to do the following: open a file if it exists and append some data (this can be done with: open(unit=40,file='data.data',Access = 'append',Status='old') but if the file does not exist a runtime error is issued) create the file if it does not exist and write some data. I am currently using inquire to check whether the file exist or not but then I still have to use the open statement to

Dynamic output format setting

房东的猫 提交于 2019-11-29 16:31:12
I tried to make the output format dynamically in the sense that the number of variables to be printed out could be varied dynamically. I had done some experiment with the following two methods (see the context below), but both of them led to a error message like this: forrtl: error (63): output conversion error, unit 1016, file /panfs/roc/Node_ 16.txt The first method uses a string to specify the output format, for example, real a(4) = [1 2 3 4] int size = 4 write(string,'(a,i3,a)') '(a,',size,'(f9.4))' write(*, string) a(:) The second method is what I just learnt from the Internet, which

Include both .f and .F90 file in Fortran main file header

旧时模样 提交于 2019-11-29 16:24:13
I am using some F77 fixed format code with my F90 program. I am trying to include both kinds of code in my main program. Here's how I have arranged my code: Header files: File Name:include.inc include 'module_variables.F90' include 'message.F90' include 'module_common_functions.f90' include 'module_input_gdf.F90' ... Relavant LAPACK files File Name: lapack.inc include 'xerbla.f' include 'strsm.f' include 'slaswp.f' include 'sgetrs.f' include 'sgetrf.f' ... Now my main program looks like: include 'lapack.inc' include 'include.inc' program MDL_HydroD use module_variables use module_write_files

Simple program, that only produce zeros, bug? [duplicate]

心已入冬 提交于 2019-11-29 16:20:50
This question already has an answer here: Why are the elements of an array formatted as zeros when they are multiplied by 1/2 or 1/3? 1 answer Why does this fortran program produce only zeros? When I print it out i get -0.00000 everywhere! What have I done wrong? In matlab it runs perfectly. I dont see any reason why its not working to be honest! It seems like its the fraction that messes it up. if I set x equal to some decimal number it works. program main implicit none integer iMax, jMax double precision, dimension(:,:), allocatable :: T double precision x, dx,f,L2old,L2norm,y integer i, j,n

Usage of Fortran statement functions

时光总嘲笑我的痴心妄想 提交于 2019-11-29 15:54:38
I read about statement functions, such as the example: C(F) = 5.0*(F - 32.0)/9.0 Isn't this the same as: C = 5.0*(F - 32.0)/9.0 i.e. without the function part, or maybe I'm missing something? If they're not the same, when do I need to use a statement function? C = 5.0*(F - 32.0)/9.0 is just assignment to a variable C , it can be anywhere and is evaluated once every time when the program flow reaches it. C(F) = 5.0*(F - 32.0)/9.0 is a statement function, and can be evaluated any time it is in the scope by, e.g., C(100) which returns approximately 37.8 . From some code xx(i) = dx*i f(a) = a*a do

Segfault when calling a function with a constant argument

ぐ巨炮叔叔 提交于 2019-11-29 15:46:54
I have written this very simple code in Fortran: program su implicit none real ran3 write(*,*) ran3(0) end program su real*8 function ran3(iseed) implicit none integer iseed iseed=iseed*153941+1 ran3=float(iseed)*2.328+0.5 end function ran3 I have no problem in compiling it but when I execute the code I get this message: Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0xB76BAC8B #1 0xB76BB2DC #2 0xB77BA3FF #3 0x8048653 in ran3_ #4 0x80486B3 in MAIN__ at der.f90:? Segmentation fault (core dumped) Could you please tell why, and how I

GFortran and CodeBlocks issue with Modules and Multiple Files

蹲街弑〆低调 提交于 2019-11-29 12:45:16
I am working with GFortran and CodeBlocks but I'm having an issue about Modules and Multiple files. i keep getting this error: Fatal Error: Can't open module file 'mesh.mod' for reading at (1): No such file or directory For some reason, GFortran is not building the 'mesh.mod' file. This problem does not occur when I put all the code in a single .f90 file. Bellow is an example of code that this error happens. main.f90 MODULE MESH IMPLICIT NONE INTEGER :: IMAX,JMAX,NMAX REAL(8), ALLOCATABLE :: XD(:),YD(:),FX(:,:),FY(:,:) REAL(8) :: PI,E,DX,DY,H,L,RHO,MU PARAMETER (PI = ACOS(-1.D0)) PARAMETER (E

Fortran 90 how to write very long output lines of different length

折月煮酒 提交于 2019-11-29 11:47:19
I've spent hours scouring the internet for a solution to this problem and can't find anything. I have been trying to write unformatted output to a CSV output file with multiple very long lines of varying length and multiple data types. I'm trying to first write a long header that indicates the variables that will be written below, separated by commas. Then on the lines below that, I am writing the values specified in the header. However, with sequential access, the long output lines are broken into multiple shorter lines, which is not what I was hoping for. I tried controlling the line length