fortran90

Explaining Fortran Write Format

廉价感情. 提交于 2019-12-12 10:28:22
问题 I am a beginner of fortran90. Now I am trying to learn fortran code and I am not clear with the description of the write format write ( *, '(2x,i4,2x,g14.6,2x,14x,2x,g14.6)' ) 0, unew_norm, error Can anybody explain to me what does '(2x,i4,2x,g14.6,2x,14x,2x,g14.6)' stuff mean. It would be very nice to teach me the dummy things. Best 回答1: From this source: nX means that n spaces are added to the line; iw means that an integer (hence the i ) is printed in a field w spaces wide; gw.p is a

reading input file in fortran

放肆的年华 提交于 2019-12-12 05:38:58
问题 I am looking for reading a file, like: NE 32 0 IBZINT 2 NKTAB 936 XC-POT VWN ITER 29 MIX 2.00000000000000E-01 TOL 1.00000000000000E-05 I was thinking it is index intrinsic that I am looking for, and was writing a code accordingly: EDIT The code is updated, Implicit None integer ::i,pos character(50) :: name character(len=16),dimension(100)::key,val key(1)="NE" open(12,file="FeRh/FeRh.pot_new",status="old") do i=1,100 read(12,*)name if (name(1:2)==key(1))then write(*,*)"find NE" write(*,*)name

Reading function from a file in Fortran 90

牧云@^-^@ 提交于 2019-12-12 05:10:18
问题 I have an optimization solver in Fortran 90. So, if I want to change the objective function I have to modified the main file and write the objective function in this way: subroutine fobj(n,x,f) implicit none integer :: n real(8) :: f real(8) :: x(n) intent(in ) :: n,x intent(out) :: f !OBJECTIVE FUNCTION f = x(1)**2-x(2)+2*x(3) end subroutine fobj I have a big objective function, so I want to call this line "f = x(1)**2-x(2)+2*x(3)" from an external file or at least the subrutine. Is that

Segmentation fault in Fortran while constructing graph using adjacency lists

那年仲夏 提交于 2019-12-12 04:35:58
问题 I am creating graph using the adjacency list method. Each node is represented as a node which points to other nodes connected to it. The following is my code program main use graphs implicit none type(node),pointer :: start type(node), dimension(:), pointer :: grp integer :: n, ios=0, a,b, i open(1, file='test6.txt', status='OLD', action='READ') read(1,*,iostat=ios) n allocate(start) allocate(grp(n)) do, i=1,n grp(i)%val=i enddo do while(ios==0) read(1,*, iostat=ios)a,b if(ios.NE.0)then exit

Continuation in gfortran 5.2.0

℡╲_俬逩灬. 提交于 2019-12-12 04:08:50
问题 I need to work on Fortran90 code on my Macbook Pro, which was written on Microsoft Developer Tools years ago. As a free option, I have installed gfortran on my Macbook to be able to compile it. The original code includes & continuation character for the long lines but I am not able to use it. Without & character, everything works fine. What might be the problem? Do I need to activate something to be able to use & character? For example, I think something like this should work: x = 1 y = 2 z =

Converting integer to character in Fortran90

荒凉一梦 提交于 2019-12-12 03:37:06
问题 I am trying to convert an integer to character in my program in Fortran 90. Here is my code: Write(Array(i,j),'(I5)') Myarray(i,j) Array is an integer array and Myarray is a character array, and '(I5)' , I don't know what it is, just worked for me before! Error is: "Unit has neither been opened not preconnected" and sometimes "Format/data mismatch"! 回答1: Alexander Vogt explains the meaning of the (I5) part. That answer also points out some other issues and fixes the main problem. It doesn't

How to read real numbers as characters

懵懂的女人 提交于 2019-12-12 03:08:14
问题 I want to do some arithmetic operation to an array of real number and later I have to read it as an input for character variable. I used read statement still I get the error as UNIT SPECIFICATION MUST BE AN INTEGER OR CHARACTER VARIABLE. I also verified the format descriptor. Here is my piece of code real::la(10), sl integer::i character(len=5)::lat character(len=7)::station sl=11.25 do i=1,10 la = sl+ (i*0.25) read(la(i),'(F5.2)')lat station= lat//'xx' end do 回答1: When you have read(la(i),'

min and max of input array file (.dat) with subroutine

我是研究僧i 提交于 2019-12-11 23:41:51
问题 I try to implement a code that read in a number n, creates a vector to store n double precision numbers, read this number, call a subroutine printminmax() to find min and max. My code work perfect for normal numbers (integer,real etc) but when i have scientific notation (0.3412E+01) stack.Why? I thought with * read all the formats. Thanks implicit none integer, dimension(:), allocatable :: x integer :: n open (unit=77, file='input2.dat', action='read', status='old') read(77,*), n allocate(x(n

Modifying an array in fortran

Deadly 提交于 2019-12-11 21:16:18
问题 I have the following problem. I have a file that I must: divide in cells to create an NxN grid; counts the particles in each cell; write the resulting numbers in a particular way. The problem is the third point: I must write an NxN array each numbers represent the total numbers of particles in each cell, but I don't know how to write the file in an NxN array. program eccen implicit none integer, parameter:: grid=200 integer::i,j,k,n,m real*8,allocatable::f(:,:) real*8::xx(grid),yy(grid),mval

fortran basic help 'd' operator [duplicate]

本秂侑毒 提交于 2019-12-11 20:16:23
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: postfix 'd+0' in Fortran real literal expressions I have this code line in Fortran 90: OVERN2 = 1.d+0/DBLE(FLOAT(NMODE2)) NMODE2 is an integer, OVERN2 is a REAL*8 . Can you please explain to me what this line does? I don't understand the .d+0/ part? if you can also translate that to C or any other easier language. 回答1: 1.d+0 is just a double precision literal in scientific notation, i.e. 1.0e0 or just 1.0. In