Fortran Stack output concept

I am new FORTRAN user. I want to write the output in stack way without deleting the previous one. Suppose we have three outputs A,B,C for one one one "ELECTRON1". When we run the code for another "ELECTRON2" then all previous outputs are over written. So I want to write in a stack way with one blank line. Please suggest me how I can do it....... I am very greatful to you... Regards

Fortran Efficient convergence check

I have a grid with thousands of double precision reals. It's iterating through, and I need it to stop when it's reached convergence to 3 decimal places. The target is to have it run as fast as possible, but needs to give the same result every (to 3 dp) every time. At the minute I'm doing something like this REAL(KIND=DP) :: TOL = 0.001_DP DO WHILE(.NOT. CONVERGED) CONVERGED = .TRUE. DO I = 1, NUM_POINTS NEW POTENTIAL = !blah blah blah IF (CONVERGED) THEN

How do I compile this legacy FORTRAN 77 code with *.h files?

I have a collection of .F and .H files that makeup a FORTRAN code. I'm running into trouble tyring to compile the .H files. The .H files contain a bunch of common blocks. An example of one of the .H files is: *AC HEAD c HEAD 1 common/blah/ x(25), y, z(25), p(25,mnv), HEAD 2 1 t(25,mx), d(25,mnv) HEAD 3 c

FORTRAN 77 Simple input/out

I am new to FORTRAN, and must write a FORTRAN 77 program to read the following format from a file redirection or standard input: [CHARACTER] [REAL] [REAL] [REAL] ... (can have any number of these) D [INTEGER] (only one of these) [REAL] [REAL] [REAL] ... (can have any number of these) example input could be: T 1.0 2.0 3.0 S 1.0 2.0 4.0 Y 3.0 4.0 5.0 D 2 3.0 5.0 6.0 4.5 4.6 5.6 My native language is C++, so I'm new to this whole idea of a read statement going to the next line automatically.

FORTRAN ZGEEV, all 0 eigenvalues

I am trying to get the ZGEEV routine in Lapack to work for a test problem and having some difficulties. I just started coding in FORTRAN a week ago, so I think it is probably something very trivial that I am missing. I have to diagonalize rather large complex symmetric matrices. To get started, using Matlab I created a 200 by 200 matrix, which I have verified is diagonalizable. When I run the code, it brings up no errors and the INFO = 0, suggesting a success. However, all the eigenvalues are (

Sending 2D arrays in Fortran with MPI_Gather

I want to send 2d chunks of data using MPI_GATHER. For example: I have 2x3 arrays on each node and I want 8x3 array on root, if I have 4 nodes. For 1d arrays, MPI_GATHER sorts data according to MPI ranks, but for 2d data it creates a mess! What is the clean way to put chunks in order? I expected the output of this code: program testmpi use mpi implicit none integer :: send (2,3) integer :: rec (4,3) integer :: ierror,my_rank,i,j call MPI_Init(ierror) MPI_DATA_TYPE type_col !

Writing on the same line in FORTRAN

In Fortran, each time one uses WRITE a new line is produced. In order to control the working of a program that is being executed, I would like to write on screen the current value of a variable, but always on the same line (erasing the previous value and starting at the beginning of the line). That is, something like 1 CONTINUE "update the value of a" WRITE(*,*) a BACKSPACE "screen" GOTO 1 Something like WRITE(*,*,ADVANCE='NO') (incorrect anyway) is not quite what

Questions about intel fortran compiler options

I am currently running a fortran code both on serial (single core)/parallel (48 cores),and there are values such as "infinity" or "NaN" in the output (which shouldn't have) without any other information. I would like to use the compiler options to help me locate the source of the infinity/NaN. I tried the combination of "-O0 -g -traceback -fpe3", then during run-time, the infinity appears earlier in such case than the normal case (without debug options). But still, there is no information about

Do these 2 lines of Fortran represent a Fortran macro?

I am converting some Fortran code to C and I don't understand what is going on here. This code came from TOMS, Transactions on Mathematical Software, so I don't believe this is an errant line of code. ZCOS and A have no other definitions in the file other than what I am showing here. Is this a Fortran technique for defining ZCOS as COS, and if so, what does it accomplish? REAL ZCOS ZCOS(A) = COS(A) C(I) = ONE / (TWO * ZCOS ( C(I) * PI / DBLE(N+N) ))

Fortran estimate the size of a binary file

I am very confused about this. I dump out a 3D array of size 16000*4*2, all elements of which are DOUBLE PRECISION, and I thought I should have gotten a file of size: 16000*4*2*8 bytes/dp = 1,024,000 bytes. But I keep getting 2,048,000 bytes. And I tested with a simple test program: PROGRAM testprog IMPLICIT NONE DOUBLE PRECISION :: x=0.0D0 INTEGER :: i OPEN(UNIT=128,FILE='try.out',FORM='UNFORMATTED',ACCESS='SEQUENTIAL') DO i=1,16000*4*2 WRITE(128) x ENDDO CLOSE(128) ENDP

Fortran Unclassifiable statement at 1 , Non-numeric character in statement label at 1

i'm totally new to Fortran, and i want to write a test program using a real*8 function called NeQuick, so i've written the following program : program test implicit real*8 (a-h,o-z) aNe=NeQuick(400.0D0,45.0D0,15.0D0,10,1.929D2,15.0D0) write(6,'(A,E12.5,A)') & ' NeQuick electron density =',aNE,' m^-3' call sleep(10) end program At the end when i compile it I have the following errors in each line of the little program : -Non-numeric character in statement label at 1 or

Eliminating hidden copies in Fortran

I wanted to ask some Fortran gurus about this issues I have with an up to date version of the Cray Compiler. I have several warnings that although they do not affect correctness, they will probably do for performance. The warning is: This argument produces a copy in to a temporary variable. Here is one of the situations where I get this warning. Within the same file (fem.f90) and module: call fem( array_local( i, : ), pcor, arcol, inder, & ^ ft

Fortran Resize array generated by the loop

Let's have an array A(:,:) Real, Allocatable:: A(:,:), B(:) Integer, Allocatable:: rowin(:) Integer:: m,j,k, nl Allocate(A(max1,max2)) defined by several loops over m,j,k nl = 0 A(rowin(m)+j,k) = ... and now I want to select subset of A(:,:) such that their values are negative and store them into array B(:) unknown length yet, i.e. if(A(rowin(m)+j,k).lt.0.d0) then nl = nl + 1 B(nl) = A(rowin(m)+j,k) end if Since max1 and max2 are very large numbers, I don't wan

Fortran Partition a 3D array AND use allgather

I now want to use the allgather to rebuild a 3D array. 16 cups are claimed and the data of the Y-Z plane are partitioned into 4*4 parts. Also a new type (newtype) is created for convenience. Are the errors related to this new type, Thanks! !================================================================================================================================== !****** [ Program main ] ***************************************************************************************************

Fortran Print Statements Performance Effects

I just inherited some old Fortran code that has print statements everywhere (when it runs, the matrix streams by). I know these print statements are useless because I cannot tell what the program is printing as it is going by so fast. But is there a significant performance impact to having a lot of print statements in a Fortran program (i.e. does an overly verbose program take longer to execute)? It seems like it would as it is another line to execute, but I don't know if it is significant.

how to use subroutine written in FORTRAN90 to main program written in FORTRAN77

My question is about FORTRAN 77 and FORTRAN 90. The main program (program.f77) is written in FORTRAN 77. One subroutine is written in FORTRAN 90. Say the name of the file is sub.f90 which has the subroutine. Now I want to use this subroutine to my main program. So I have used 'include sub.f90' to my main program but it did not work. My question is is there any way I can use sub.f90 to my main program (program.f77)? Any help will be appreciated.

Fortran Interpreting gdb output where FPE is occurring

I am using the same instructions as provided in this URL - Debug fortran code with gdb and I am getting these messages - Breakpoint 1, psiappsor (omega=1.80999994, pv=<error reading variable: value requires 31250000 bytes, which is more than max-value-size>, psi=<error reading variable: value requires 31250000 bytes, which is more than max-value-size>, nsq=..., rhoref=..., thetatop=<error reading variable: value requires 250000 bytes, which is more than max-value-size>, t

Filling an array with unknown size in fortran90

I want to fill an array with unknown size in fortran90. This is the equivalent code in MATLAB : for i=1:10 A[i] = i end I know that i can pass the size, but How can i do this in fortran90 without passing the size of the array. I read that we can use pointers, but i really dont know how to deal with pointers

Fortran How to pass a private variant value into declaration when overide new functions

For instance, I have a definition of type A in moduleA: Module moduleA implicit none type A private integer::N contains ... procedure,pass::f=>f1 endtype private::f1 contains real function f1(self,x) real::x(self%n) end function ... end Module Then I found I meet a trouble when I override function f in other modules since I can not get the value of N. Even though I can have a method to get that, it seems that somethin

Neglecting NaN terms in a summation in Fortran

Is there a way to combine NaN and ordinary numbers in a different way then usually done in Fortran? I have several summations which contains 'safe' terms, which cannot be NaN, and some other terms which can be NaN. I would like the evaluation of the expression to neglect the addends in case they are NaN. I cannot just get rid of them multiplying them times a null factor when they are NaN as NaN x 0 gives NaN anyway. Ideas? Thanks

Fortran unresolved symbol vec_add_

First, my source programs are shown as follows: call_fun.f90 program call_fun use omp_lib implicit none integer, parameter :: N = 100 integer a(N), b(N), c(N) integer i do i = 1, N a(i) = i b(i) = i+1 end do !$omp target !$omp parallel do do i = 1, N call vec_add(a(i), b(i), c(i)) end do !$omp end target write(*,10) N, c(N) 10 format('c[', I4, ']=', I6) end program vec_add.f90 subroutine vec_add(a, b, c) implicit none integer a, b, c c = a + b end Obviously, this tw

Fortran Operator to check file existence

I want to create an operator .f. that checks whether a file exists so that I can write if (.f. filename) Then ... I have already written a function to do this, now have to create the interface. What would the constraints on e function arguments for having the mentioned functionality?

Can Fortran PURE functions use global parameters?

It seems to me the what is called a pure function in Fortran is not considered pure enough for those who use functional programming. So here is my question. Suppose I have the following code: MODULE basics IMPLICIT NONE INTEGER, PARAMETER :: dp = kind(1.0d0) REAL(dp), PARAMETER :: PI=3.1415926535897932_dp REAL(dp), PARAMETER :: earthEquatorialRadius=6378.137_dp END MODULE basics MODULE myFunctions USE basics IMPLICIT NONE PURE REAL(dp) FUNCTION sphericalArc(angleInR

Fortran Printing a matrix in to a file

I need to print DFGRD1, a matrix, in a file. I have written these lines open(105,file='C:\temp17\FM.mtx') WRITE(105,*) DFGRD1 close(105) c To check in .dat file DO i=1,3 WRITE (7,*) (DFGRD1(i,j),j=1,3) END DO However, the answers are not the same. They are the transpose of each other. Since I cannot access the real value of DFGRD1, I do not know which one is correct. I would really appreciate if someone could help me with it.

Multiply the row of two matrix to obtain a scalar with Fortran

After a few years of not using Fortran I'm having some troubles with matmul. Suppose I have two matrix: A_{N,K} and B_{J,K} . I want to create a subroutine that takes a row of A and a row of B, multiplies that and creates the scalar C. This is what I wrote: subroutine test_matmul(A, B, N, K, J, row_a, row_b, C) integer, intent(in) :: N, K, J, row_a, row_b double precision, dimension(N,K), intent(in) :: A double precision, dimension(J,K), intent(i

Fortran do loop not calculating the entered variable

When I run the code for Celsius only I am getting the result below the code: program temperature ! F C temperature conversion implicit none real :: celcius=0.0, fahrenheit=0.0 integer:: t,n print *,'enter the number of lines' read*, n do n=1,n print*,'enter the value of t: one per line',n read*, t celcius=5/9*(t-32) enddo do n=1,n print*, t, celcius enddo end program result enter the number of lines 3 enter the value of t: one per line 1 50 enter the value of t: one

How to send and receive arrays using an MPI struct in Fortran 90

I'm attempting to package 1D and 2D double precision arrays in an MPI struct in Fortran 90. I've successfully done this in C++ in a very similar problem and the procedure seems to be almost exactly the same, but I can't seem to figure out where I'm going wrong here, despite the extremely helpful MPI error codes... My best guess is that the problem is in the block length or displacement calculations. The code compiles and runs when the call to MPI_RECV() is commented out, but results in an error

Fortran Maxval for derived type's variable in array

I have the following array of derived type in Fortran 90: type tpo_line integer :: price = -1 integer :: count = -1 end type type(tpo_line),dimension(10000) :: myarray Given a populated myarray, is there a more straightforward way to get the tpo_line item of the array which has the largest count than iterating over the whole array? (I have seen that for simple arrays you can use maxval)

How to break to new line in Fortran when printing?

It is very simple query but I'm not able to find the exact solution. How to break to new line when printing in Fortran? for example print*,'This is first line' print*,'This is second line' I want following output This is first line This is Second line That is add space between two lines. In java we use \n and in html using <br> does the job..but how to achieve same in Fortran?

DEXP or EXP for exponential function in fortran?

I have two very short questions: 1 - I just read that DEXP() is the archaic form of EXP(). Does it mean that it should not be used anymore? I always thought that DEXP() was the double precision equivalent to EXP(). 2 - What is the range of the exponential function? Is it compiler dependent? Thanks in advance for your help! Best, Remek

fortran undefined reference to popcnt_

i am trying to compile a fortran 90 program which has a call to POPCNT as follows: ... print *, popcnt(127) ... by compiling it as follows: gfortran prog.f90 it gives me the following: ...: undefined reference to `popcnt_' plz can anyone suggest the correct way of compiling? thanks.

Fortran Do I need an explicit interface to allocate a component of a derived type in a subroutine?

I have a derived type: module foo type bar integer, allocatable, dimension(:) :: data end type bar end module foo Now I would like to allocate bar's data within a subroutine without an explicit interface: program main use foo type(bar) :: mybar call alloc_my_bar(10,mybar) print*, mybar end program subroutine alloc_my_bar(n,mybar) use foo type(bar) :: mybar integer :: n allocate(mybar%data(n)) mybar%data = 42 end subroutine alloc_my_bar This seems to work just f

Cost of using functions in fortran (or any other language)

Let say I have a array which is very big verybigvariable And I have defined a function that does some operations like this function myfunc(var) result(res) real:: var(:,:,:),res ... ... ... end function myfunc My question is that when I call this function like this myvar=myfunc(verybigvariable) what happens? does it duplicate my variable so it holds 2X space in the ram during the execution of the function? If so how can I prevent this? (In a simple program, I know, I can define the func

g95 vs gfortran : Dummy procedure 'f' of PURE procedure at (1) must also be PURE

I get this error message with g95: G95 (GCC 4.0.3 (g95 0.94!) Jan 17 2013) In file src/integrators.f95:34 pure function rk4_step(u,f,dt) result(un) 1 Error: Dummy procedure 'f' of PURE procedure at (1) must also be PURE Makefile:28: recipe for target 'test_rk4' failed I don't get it with gfortran: GNU Fortran (GCC) 4.8.2 20140206 (prerelease) and the program compiles without further problems

Fortran Capture Aliasing in Subroutine

Is there a way to check whether aliasing occurs in a Fortran subroutine, or at least to tell the compiler to issue a warning? Consider this (rather simplistic) example: module alias contains subroutine myAdd(a, b, c) integer,intent(in) :: a, b integer,intent(inout) :: c c = 0 c = a + b end subroutine end module program test use alias integer :: a, b a = 1 ; b = 2 call myAdd(a, b, b) print *, b, 'is not 3' end program Here, the result is set to zero in th

fortran "Error: Two main PROGRAMs at (1) and (2)"

I am learning fortran and encountered a problem with a program I am writing. The program is below: PROGRAM mymain IMPLICIT NONE INTEGER :: a, g1 EXTERNAL f PRINT *, "value of a" READ *, a g1 = f(a) PRINT *, a, g1 END PROGRAM mymain CONTAINS INTEGER FUNCTION f(x) IMPLICIT NONE INTEGER, INTENT(IN) :: x f = x*x RETURN END FUNCTION f When I tried to run the program, I got the following error: xfunc.f90:2.14: PROGRAM mymain 1 exfunc.

Fortran: parameters/variables in external file

I have several programs that use the same block of code at the begining, but do different stuff. Is it possible to declare this block of code in an external file (fortran file or text file) so if I want to change one part of this code (in the block I'm talking about) I don't have to change it in every program? Example: Two programs MAIN1 and MAIN2 that do different operations with the vector X generated in an external file. PROGRAM MAIN1 IMPLICIT NONE ! External block here REAL, PARAMETE

Fortran program made to calculate cos using taylor series prints wrong results,possible error with my factorial

I've been trying to create a program that can calculate the cos of a radiant using Taylor series. I contemplate the error, for example: cos(45)=1.4 must be this : s=(((-1.)**n/(fact*2.*n))*x**(2.*n))*sign. The code: program project2_ex6 implicit none !Reference to variables !------------------------------------------------------- integer(kind=3)::degrees,i,sign !sign=a random name in order to use it to change the 's' sign consecutively integer::n double precision::x,err_limit,s_old,s,fact !x

Fortran "Cannot assign to named constant" (reassigning a variable)

I'm using a flag f for some error checking. Fortran (or maybe gfortran) won't let me reassign its value when I want to perform another check. integer, dimension(:,:), allocatable :: A integer :: f, n write (*, *) "Give an integer n > 0. n = " read (*, IOSTAT=f) n do while(f /= 0) print *, "Error with input. Please try again." read (*, IOSTAT=f) n end do write (*, "(a, i5)") "You have entered n = ", n allocate(A(n), STAT=f) if (f /= 0) print *

Gfortran does not have module Funits while ifort does

Once O tried to compile Fortran code that relies on funits. while it is not available in gfortran 4.9.3. use FUNITS 1 Fatal Error: Can't open module file 'funits.mod' for reading at (1): No such file or directory here is gfortran information gfortran -v Using built-in specs. COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3/gfortran COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /var/tmp/portage/sys-devel/gc

Fortran Error: Expected a right parenthesis in expression at (1)

its showing Expected a right parenthesis in expression, although i have checked it many times do i= 0, m-1 do j= 0, n-1 k1(i,j)=-0.001*(((y(i,j)/dx)*((0.02651995*pho(i+3,j))-(0.18941314*pho(i+2,j))+(0.79926643*pho(i+1,j))-(0.79926643*pho(i-1,j))+(0.18941314*pho(i-2,j))-(0.02651995*pho(i-3,j))))+((x(i,j)/dy)*((0.02651995*pho(i+3,j))-(0.18941314*pho(i+2,j))+(0.79926643*pho(i+1,j))-(0.79926643*pho(i-1,j))+(0.18941314*pho(i-2,j))-(0.02651995*pho(i-3, j))))) enddo enddo

Fortran Multiple communicators in MPI

The background of this question is in some computational areas such as Computational Fluid Dynamics (CFD). We often need finer mesh/grid in some critical regions while the background mesh can be coarser. For example the adaptive refine mesh to track shock waves and nesting domains in meteorology. The Cartesian topology is used and domain decomposition is shown in the following sketch. In this case, 4*2=8 processors are used. The single number means the processor's rank and (x,y) means its topo

How to compute the first eigenvalue and eigenvector in Fortran

I tried to use ARPACK using some examples (here), but I could not even figure out how to input my matrix. From this question, It seems that the implementations in Python and Matlab are the only solution to avoid the complexity of ARPACK. Is there some (Fortran-based) way to do this, also avoiding to calculate all the eigenvalues/eigenvectors?

Fortran infinity check shows infinity though the values is not

I'm sharing a part of my code, where I'm trying to check if the value of a varible (PF) becomes infinity of not. It turns out the test find it to be infinite although, in reality, it is much smaller than the highest floating number that can be stored in Fortan. PF=0.d0 PF_before=PF do i=0,Nstates-1 PF=PF+exp(-beta*E(i)) end do flag_reduce=0 print*,'PF-1,PF=',PF-1,PF !if (PF-1==PF) then ! True if PF is infinity if (IEEE_IS_FINITE(PF)) then ! True if

How to set the default value of an mpi_comm optional variable in Fortran?

I want to create a wrapper procedure for MPI_Size in Fortran. I wrote the function wmpi_size which returns an mpi size given a communicator. I would like the communicator to be an optional input, so if it is not present I set it to mpi_comm_world. The code compiles either way, but when I call wmpi_size without input the code crashes at runtime. One way to fix this is to pass mpi_comm_world to mpi_comm_size directly if the communicator is not present, as shown in the commented function definition

Fortran derived types coarrays with opencoarray compiler

I am having some trouble using coarrays of a derived type with opencoarrays. My minimal working example is ("main.f90"): module mod_parallel implicit none type :: array_type real, allocatable :: d(:) end type contains subroutine init_arr(arr) type(array_type), intent(inout) :: arr allocate(arr%d(5)) end subroutine init_arr end module mod_parallel program main use mod_parallel implicit none type(array_type) :: array[*] call init_arr(array) array%d = 1.5*this

sum(sum(A.*B)) (matlab notation) in modern fortran

May you suggest me an efficient way to implement sum(sum(C)) where C=A.*B Here I'm using matlab notation, that means that fo A and B square matrices, A.*B is a matrix of the same dimension where its element i-j is the multiplication of the element i-j of A and the element i-j of b, that is Cij = Aij*Bij Then, sum(sum(C)) means the sum of all element of the matrix C. Of course, It is easy to do a DO-loop calculating this, but this operation is inside another loop cycle, so I must to do it sever

  1    2   3   4   5   6  ... 下一页 最后一页 共 19 页