fortran90

When does a module go out of scope in Fortran 90/95?

巧了我就是萌 提交于 2019-12-29 01:43:51
问题 My intended use is program main use mod external sub call sub end program main subroutine sub ! code here calls subroutines in mod end subroutine sub Specifically, will module mod be in scope in subroutine sub ? Also, I'd be interested to know more generally when a module is in/out of scope. I'm using gfortran 4.6.1, if it matters. 回答1: It is not in scope of subroutine sub, as sub cannot call routines or use variables from mod, because sub is not part of the program main . They have nothing

Can Fortran read bytes directly from a binary file?

本秂侑毒 提交于 2019-12-28 15:54:34
问题 I have a binary file that I would like to read with Fortran. The problem is that it was not written by Fortran, so it doesn't have the record length indicators. So the usual unformatted Fortran read won't work. I had a thought that I could be sneaky and read the file as a formatted file, byte-by-byte (or 4 bytes by 4 bytes, really) into a character array and then convert the contents of the characters into integers and floats via the transfer function or the dreaded equivalence statement. But

Can Fortran read bytes directly from a binary file?

為{幸葍}努か 提交于 2019-12-28 15:51:27
问题 I have a binary file that I would like to read with Fortran. The problem is that it was not written by Fortran, so it doesn't have the record length indicators. So the usual unformatted Fortran read won't work. I had a thought that I could be sneaky and read the file as a formatted file, byte-by-byte (or 4 bytes by 4 bytes, really) into a character array and then convert the contents of the characters into integers and floats via the transfer function or the dreaded equivalence statement. But

Can Fortran read bytes directly from a binary file?

杀马特。学长 韩版系。学妹 提交于 2019-12-28 15:51:21
问题 I have a binary file that I would like to read with Fortran. The problem is that it was not written by Fortran, so it doesn't have the record length indicators. So the usual unformatted Fortran read won't work. I had a thought that I could be sneaky and read the file as a formatted file, byte-by-byte (or 4 bytes by 4 bytes, really) into a character array and then convert the contents of the characters into integers and floats via the transfer function or the dreaded equivalence statement. But

Best way to write a large array to file in fortran? Text vs Other

纵然是瞬间 提交于 2019-12-28 05:30:46
问题 I wanted to know what the best way to write a large fortran array ( 5000 x 5000 real single precision numbers) to a file. I am trying to save the results of a numerical calculation for later use so they do not need to be repeated. From calculation 5000 x 5000 x 4bytes per number number is 100 Mb, is it possible to save this in a form that is only 100Mb? Is there a way to save fortran arrays as a binary file and read it back in for later use? I've noticed that saving numbers to a text file

Fortran subroutine returning wrong values

此生再无相见时 提交于 2019-12-28 03:12:15
问题 Hey I'm working on a fortran program and have ran across an odd problem. When I try to output some values of an array directly before calling a specific subroutine I get the correct values. I then try to output some values of the same array right as I start the subroutine, and they are 0. I finally output the values of the array after the subroutine and the values are back to the expected values. Could anyone help me understand why? My code is below: First, the calling of the subroutine in

gfortran REAL not accurate to 8 decimal places [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-12-25 20:00:31
问题 This question already exists : gfortran represents REAL incorrectly [duplicate] Closed 5 years ago . This question has not been previously answered. I am trying to represent a real or any number for that matter in Fortran correctly. What gfortran is doing for me is way off. For example when I declare the variable REAL pi=3.14159 fortran prints pi = 3.14159012 rather than say 3.14159000. See below: PROGRAM Test IMPLICIT NONE REAL:: pi = 3.14159 PRINT *, "PI = ",pi END PROGRAM Test This prints:

f90 read .txt file return NaN

末鹿安然 提交于 2019-12-25 18:22:29
问题 I am trying to read a .txt file with multiple arrays with a fortran program. It looks like the program is finding the file but it only returns NaN value... ! INTEGER :: T, RH, i, j, ierror ! REAL, DIMENSION(3,3) :: AFILE ! LOGICAL :: dir_e inquire(file='PSR_FAB.txt', exist=dir_e) if ( dir_e ) then print*, "dir exists!" else print*, 'nope' end if OPEN (UNIT = 1234 , FILE = 'PSR_FAB.txt', STATUS = 'OLD', ACTION = 'READ') DO i=1,3 READ(1234,*, IOSTAT=ierror) (AFILE(i,j),j=1,3) print*, (AFILE(i,j

Remove repeated elements in a 2D array in Fortran

怎甘沉沦 提交于 2019-12-25 08:47:16
问题 I would like to know whether it is possible to have a function that erases all of the 2D repeated nodes from an array, i.e.: A(xy,1:2) A(xy,1) = /1,2,4, 5 ,5,9,6,8,2, 5 ,4/ A(xy,2) = /5,2,5, 6 ,7,6,6,3,7, 6 ,6/ After A(xy,1) = /1,2,4, 5 ,5,9,6,8,2,4/ A(xy,2) = /5,2,5, 6 ,7,6,6,3,7,6/ When I try to execute @HighPerformanceMark's code in a blank program, there are several compiling errors that I do not get: repeating.f90:24.20: mask(ix) = NOT(ANY(arraya(1,:ix-1)==arraya(1,ix).AND.& 1 Error: 'i'

Undefined reference to a function in a module

北城余情 提交于 2019-12-25 08:03:00
问题 I was going through all the other threads about undefined reference and I was unable to figure out why this piece of codes is not working. I am basically trying to run a function from a module into a subroutine in the main program. But I keep getting an error Main: program main use m1 implicit none integer, dimension(:,:), allocatable :: A,AFun integer :: n,i,j print *, "enter value for n" read *, n do i=1,n do j=1,n A(i,j)=i**2-j**3 end do end do print *, "Matrix A: " call prMat(A,n) call