how to write the minimum hourly value in fortran? - fortran

This script reads 5 day forecasts from a weather model, and averages a few variables monthly hourly.
Now, I need to get the minimum temperature value.
Example, each day I have 5 days of forecast.
I need an output like this:
January
minimum value of 0h, 1h, 2h, 3h, 4h, etc. It doesn't matter what day it is in January, just the monthly hourly minimum value.
program medias
implicit none
INTEGER,PARAMETER :: NVARS=5
INTEGER :: IM, JM, YEAR2, MONTH2, DAY2, YEAR, MONTH, DAY, LASTYEAR, &
LASTMONTH, LASTDAY, H1, H2, H3, H7, H8, A, B, V, X, Y, TDEF=0
REAL :: LAT, LON, RESX=0.0466611, RESY=0.0448676
INTEGER, DIMENSION(12) :: CALENDAR
CHARACTER(LEN=3), DIMENSION(12) :: MONTHS = (/ 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec' /)
CHARACTER(LEN=5), DIMENSION(NVARS) :: VARNAMES = (/ 'PRECI','T2MJU','TD2MJ','U10MJ','V10MJ' /)
REAL, DIMENSION(:,:), ALLOCATABLE :: SURVAR
REAL, DIMENSION(:,:,:,:), ALLOCATABLE :: HOURLY2D, HOURLY2DF, MONTHLY2D, MONTHLY2DF
CHARACTER :: DATE*8, DIROUT*200, DIRRUN*200, FILENAME*200, DYEAR*4, DMONTH*2, DDAY*2, DHOUR*2
! DADOS DE ENTRADA
DIRRUN = '/media/milena/Backup/'
!DIRRUN = '/home/oper/prevtempo/dataout/GrADS_BRAMS-6.5.2/'
DIROUT = '/media/milena/Backup/'
IM = 259
JM = 269
CALENDAR = (/ 31,28,31,30,31,30,31,31,30,31,30,31 /)
H8 = 24
ALLOCATE(SURVAR(IM,JM))
ALLOCATE(HOURLY2DF(IM,JM,H8,5))
ALLOCATE(MONTHLY2DF(IM,JM,12,5))
! Iniciando o armazenamento de dados
TDEF = 0
YEAR = 2022
MONTH = 10
LASTMONTH = 10
LASTYEAR = 2022
H7 = 0
YEAR2 = YEAR
MONTH2 = MONTH
2 H7 = H7+1
H2 = 0
DO WHILE (H2 .LE. 23)
YEAR = YEAR2
MONTH = MONTH2
PRINT*, MONTH
PRINT*, YEAR
H1 = ((LASTYEAR-YEAR)+1)*31*5
ALLOCATE(HOURLY2D(IM,JM,H1,5))
H1 = 0
WRITE (DHOUR,'(BZ,I2.2)') H2
TDEF = TDEF+1
DO WHILE (YEAR .LE. LASTYEAR)
IF (MOD(YEAR,4) .EQ. 0) CALENDAR(2) = 29
LASTDAY = CALENDAR(MONTH)
! IF (MONTH .EQ. LASTMONTH) LASTDAY = 12
DAY = 1
DO WHILE (DAY .LE. LASTDAY)
DAY2 = DAY
A = 8
WRITE (DATE,'(BZ,I4.4,3I2.2)') YEAR,MONTH,DAY
WRITE (DYEAR,'(BZ,I4.4)') YEAR
WRITE (DMONTH,'(BZ,I2.2)') MONTH
IF (H2 .EQ. 0) THEN
DAY2 = DAY2+1
IF ( DAY2 .GT. LASTDAY ) THEN
GO TO 22
END IF
END IF
WRITE (DDAY,'(BZ,I2.2)') DAY2
8 FILENAME = TRIM(DIRRUN)//DATE//'00/Go05km-A-'//DYEAR//'-'//DMONTH//'-'//DDAY//'-'//DHOUR//'0000-g1.gra'
OPEN(8,FILE=TRIM(FILENAME),ACCESS="direct",ACTION="read",STATUS="old",RECL=IM*JM*4)
H1 = H1+1
GO TO 21
9 FILENAME = TRIM(DIRRUN)//DATE//'00/Go05km-A-'//DYEAR//'-'//DMONTH//'-'//DDAY//'-'//DHOUR//'0000-g1.gra'
OPEN(9,FILE=TRIM(FILENAME),ACCESS="direct",ACTION="read",STATUS="old",RECL=IM*JM*4)
H1 = H1+1
GO TO 21
10 FILENAME = TRIM(DIRRUN)//DATE//'00/Go05km-A-'//DYEAR//'-'//DMONTH//'-'//DDAY//'-'//DHOUR//'0000-g1.gra'
OPEN(10,FILE=TRIM(FILENAME),ACCESS="direct",ACTION="read",STATUS="old",RECL=IM*JM*4)
H1 = H1+1
GO TO 21
11 FILENAME = TRIM(DIRRUN)//DATE//'00/Go05km-A-'//DYEAR//'-'//DMONTH//'-'//DDAY//'-'//DHOUR//'0000-g1.gra'
OPEN(11,FILE=TRIM(FILENAME),ACCESS="direct",ACTION="read",STATUS="old",RECL=IM*JM*4)
H1 = H1+1
GO TO 21
12 FILENAME = TRIM(DIRRUN)//DATE//'00/Go05km-A-'//DYEAR//'-'//DMONTH//'-'//DDAY//'-'//DHOUR//'0000-g1.gra'
OPEN(12,FILE=TRIM(FILENAME),ACCESS="direct",ACTION="read",STATUS="old",RECL=IM*JM*4)
H1 = H1+1
GO TO 21
13 GO TO 22
21 B = 0
DO V =1,175
READ (A,REC=V) SURVAR(:,:)
! Leitura Precipitacao
IF ( V .EQ. 162 ) THEN
B = B+1
HOURLY2D(:,:,H1,B) = SURVAR(:,:)
END IF
! Leitura Tp2m
IF ( V .EQ. 166 ) THEN
B = B+1
HOURLY2D(:,:,H1,B) = SURVAR(:,:)
END IF
! Leitura Td2m
IF ( V .EQ. 167 ) THEN
B = B+1
HOURLY2D(:,:,H1,B) = SURVAR(:,:)
END IF
! Leitura U10m
IF ( V .EQ. 168 ) THEN
B = B+1
HOURLY2D(:,:,H1,B) = SURVAR(:,:)
END IF
! Leitura V10m
IF ( V .EQ. 169 ) THEN
B = B+1
HOURLY2D(:,:,H1,B) = SURVAR(:,:)
END IF
END DO
CLOSE(A)
A = A+1
DAY2 = DAY2+1
WRITE (DDAY,'(BZ,I2.2)') DAY2
IF ( DAY2 .GT. LASTDAY ) THEN
GO TO 22
END IF
GO TO (9,10,11,12,13),A-8
22 DAY = DAY+1
END DO
YEAR = YEAR+1
IF (MONTH .GT. LASTMONTH) THEN
GO TO 23
END IF
END DO
23 DO B=1,5
DO Y=1,JM
DO X=1,IM
HOURLY2DF(X,Y,H2,B) = SUM(HOURLY2D(X,Y,1:H1,B))/H1
END DO
END DO
END DO
PRINT*,H2
PRINT*, HOURLY2DF(130,107,H2,1)
PRINT*, HOURLY2DF(130,107,H2,2)
PRINT*, HOURLY2DF(130,107,H2,3)
PRINT*, HOURLY2DF(130,107,H2,4)
PRINT*, HOURLY2DF(130,107,H2,5)
DEALLOCATE(HOURLY2D)
H2 = H2+1
END DO
40 FILENAME = TRIM(DIROUT)//'MEDIA_HORARIA_'//DMONTH//'.bin'
PRINT*, FILENAME
OPEN(40,FILE=TRIM(FILENAME),ACCESS="direct",ACTION="write",STATUS="new",RECL=IM*JM*4)
H3=1
H2=H2-1
DO H2=0,H2
DO B=1,5
WRITE(40,rec=H3) HOURLY2DF(:,:,H2,B)
H3=H3+1
END DO
END DO
CLOSE(40)
DO B=1,5
DO Y=1,JM
DO X=1,IM
MONTHLY2DF(X,Y,H7,B) = SUM(HOURLY2DF(X,Y,0:H2,B))/(H2+1)
END DO
END DO
END DO
PRINT*,'MEDIA MENSAL DO MES ',DMONTH
PRINT*, MONTHLY2DF(153,117,H7,1)
PRINT*, MONTHLY2DF(153,117,H7,2)
PRINT*, MONTHLY2DF(153,117,H7,3)
PRINT*, MONTHLY2DF(153,117,H7,4)
PRINT*, MONTHLY2DF(153,117,H7,5)
MONTH2 = MONTH2+1
IF (MONTH2 .GT. 12) THEN
MONTH2 = 1
YEAR2 = YEAR2+1
END IF
IF (MONTH2 .LE. LASTMONTH) THEN
IF (H7 .LE. 12) THEN
GO TO 2
END IF
END IF
50 FILENAME = TRIM(DIROUT)//'MEDIA_MENSAL_01.bin'
OPEN(50,FILE=TRIM(FILENAME),ACCESS="direct",ACTION="write",STATUS="new",RECL=IM*JM*4)
H3=1
DO H7=1,H7
DO B=1,5
WRITE(50,rec=H3) MONTHLY2DF(:,:,H7,B)
H3=H3+1
END DO
END DO
CLOSE(50)
END PROGRAM medias

Related

How to handle blank in formatted integer input

I have a file like this
1980 01 23
1982 04 30
1983 05 22
1984
1985 02 11
I tried to read data using format "(3I4)"
implicit none
integer, parameter :: FUnitIn = 10
character(len=255) :: FNameIn = "./test.txt"
integer :: FStatOpen, FStatRead
integer :: yyyy, mm, dd
open ( unit = FUnitIn, &
file = trim(FNameIn), &
access = "sequential", &
form = "formatted", &
status = "old", &
iostat = FStatOpen)
if (FStatOpen /= 0) then ! ERROR
stop
end if
do
read (FUnitIn, "(3I4)", iostat=FStatRead) yyyy, mm, dd
if (FStatRead /= 0) then
exit
else
write (6, "(3I4)") yyyy, mm, dd
end if
end do
I got three zeros for the blank line.
Are there any options to handle blank input?
You can read each line in a character variable, and check its adjusted-trimmed length if your sole goal is to skip the empty line, something like the following code (see variable record). Going beyond this simple implementation requires some extra information from you as to what behavior exactly you want to get.
implicit none
integer, parameter :: FUnitIn = 10
character(len=255) :: FNameIn = "./test.txt"
integer :: FStatOpen, FStatRead
integer :: yyyy, mm, dd
character(len=1023) :: record
open ( unit = FUnitIn, &
file = trim(FNameIn), &
access = "sequential", &
form = "formatted", &
status = "old", &
iostat = FStatOpen)
if (FStatOpen /= 0) then ! ERROR
stop
end if
do
read (FUnitIn, "(3I4)", iostat=FStatRead) record
if (FStatRead /= 0) then
exit
elseif ( len_trim(adjustl(record)) > 0 ) then
read (record, *) yyyy, mm, dd
write (6, "(3I4)") yyyy, mm, dd
end if
end do

Increase Steps in 2D Self Avoiding Random Walk

I am trying to increase the number of possible steps in the following Fortran self avoiding random walk program.
Increasing the number of steps would result in more accuracy regarding the square mean distance
I would appropriate your solutions and suggestions.
PROGRAM Two_dimensional_Self_Avoiding__Random_Walks
implicit none
integer, dimension(:,:), allocatable :: lattice
integer, dimension(1:46):: na
integer :: i,x,y,xt,yt,id,step,xx, ns,n,ii,III,choice
real :: r,dis,dis2,square,d,d2
Logical :: terminate,newsite
CALL RANDOM_SEED()
! intial values for end to end distance
read(*,*) choice
if (choice == 1) then
print*, ' Enter ns and n '
read(*,*) ns
na = (/(III, III=5, 50, 1)/)
do ii= 1, 46
dis = 0.0; dis2 = 0.0
n = na(ii)
allocate(lattice(-n:n,-n:n))
CALL walks() ! self avoiding walks
IF (ALLOCATED (lattice)) DEALLOCATE (lattice)
enddo
elseif (choice == 2) then
print*, ' Enter ns and n '
read(*,*) ns , n
dis = 0.0; dis2 = 0.0
allocate(lattice(-n:n,-n:n))
CALL walks()
endif
CONTAINS
SUBROUTINE walks
DO i = 1,ns
lattice = 0; x = 0; y = 0
step = 0; terminate = .FALSE.
DO WHILE ((.NOT. terminate) .AND. (step <= n))
xt = x; yt = y
xx = lattice(x+1,y)+lattice(x-1,y) &
+lattice(x,y+1)+lattice(x,y-1)
IF (xx == 4) THEN
terminate = .TRUE.
ELSE
newsite = .FALSE.
DO WHILE (.NOT. newsite)
CALL RANDOM_NUMBER(r)
id = INT(r*4.0)
IF (id == 0) THEN
x = xt + 1; y = yt
ELSEIF (id == 1) THEN
x = xt - 1; y = yt
ELSEIF (id == 2) THEN
x = xt; y = yt + 1
ELSEIF (id == 3) THEN
x = xt; y = yt - 1
ENDIF
IF (lattice(x,y) == 0) newsite = .TRUE.
ENDDO
step = step + 1; lattice(x,y) = 1
ENDIF
write(7,*) x,y
ENDDO
write(10,*),step
square = float(x**2+y**2)
dis = dis + sqrt(square); dis2 = dis2 + square
d = dis/ns; d2=dis2/ns
ENDDO
write(11,*), ns,n, d, d2
print*, ns,n, d, d2
END SUBROUTINE walks
END PROGRAM Two_dimensional_Self_Avoiding__Random_Walks

How take more than one input and run the program for each one

The following is a program for self avoiding random walk. The program works fine but I need to make a minor modification but I do not know how.
Currently the program receives n and ns as inputs and then calculates a distance (dis). I want the program to receive more than one n and calculate the distance for each n.
Example of current output
n = 100 ns = 100 dis = 10.8
I want the program to output
n = 100 ns = 100 dis = 10.8
n = 200 ns = 100 dis = 11.6
and go on for all input vales of n.
This can be done by running the program every time with different n but I need to do it with one run.
PROGRAM Two_dimensional_Self_Avoiding__Random_Walks
implicit none
integer, dimension(:,:), allocatable :: lattice
integer :: i,x,y,xt,yt,id,step,xx, ns,n
real :: r,dis,dis2,square,d,d2
Logical :: terminate,newsite
print*, ' Enter ns and n '
read(*,*) ns,n
allocate(lattice(-n:n,-n:n))
CALL RANDOM_SEED()
dis = 0.0; dis2 = 0.0 ! intial values for end to end distance
CALL walks() ! self avoiding walks
dis = dis/float(ns); dis2 = dis2/float(ns)
print*,ns,n,dis,dis2
CONTAINS
SUBROUTINE walks
DO i = 1,ns
lattice = 0; x = 0; y = 0
step = 0; terminate = .FALSE.
!do ii = 1, n
DO WHILE ((.NOT. terminate) .AND. (step <= n))
xt = x; yt = y
xx = lattice(x+1,y)+lattice(x-1,y) &
+lattice(x,y+1)+lattice(x,y-1)
IF (xx == 4) THEN
terminate = .TRUE.
ELSE
newsite = .FALSE.
DO WHILE (.NOT. newsite)
CALL RANDOM_NUMBER(r)
id = INT(r*4.0)
IF (id == 0) THEN
x = xt + 1; y = yt
ELSEIF (id == 1) THEN
x = xt - 1; y = yt
ELSEIF (id == 2) THEN
x = xt; y = yt + 1
ELSEIF (id == 3) THEN
x = xt; y = yt - 1
ENDIF
IF (lattice(x,y) == 0) newsite = .TRUE.
ENDDO
step = step + 1; lattice(x,y) = 1
ENDIF
write(10,*),step
!print*, x,y
write(7,*) x,y
ENDDO
square = float(x**2+y**2)
dis = dis + sqrt(square); dis2 = dis2 + square
d = dis/ns; d2=dis2/ns
write(8,*) step, d, d2
!enddo
ENDDO
END SUBROUTINE walks
END PROGRAM Two_dimensional_Self_Avoiding__Random_Walks

Using OpenACC in a fortran77 project ,but has no effect and not output kernel information

I have a fortran77 reservoir simulation project ,and want to use openacc directive to accelerate implementation,the compiler is PGI visual fortran ,a subroutine as follow:
SUBROUTINE jbild(a, b, impl,
[ ia, ja, neqa, kvst, ka, ibkmax, nja, ndima, nbmxc,
[ isymm)
USE parameter_data
USE connect_data
USE contrl
IMPLICIT REAL*8(A-H,O-Z)
include 'eleme.com'
COMMON/G9/NEXG(MNOGN)
COMMON/shiftf/SFTMIN(mxcom)
COMMON/gm_nm/gamman(njamax)
common/jocab2/uf(3,ibnd+maxlay),flw(3),fsav(3,ibnd+maxlay)
[ ,fsum(3),fsums(3), fdsum(3), fdp(3), fdiag(3)
COMMON/well_1/iwell(mnel)
COMMON/well_2/pwell(mnogn),vol_w(mnogn)
COMMON/source/qm_bc(mxcom)
integer ndima, nbmxc, ibkmax, nja, impl(ibkmax),
[ ia(ibkmax+1), ja(nja), neqa(ibkmax), kvst(ibkmax+1),
[ ka( nja+1), isymm(nja)
double precision a(ndima), b(nbmxc)
double precision fdsav(mxcom),eps
parameter (eps=1.0d-300)
COMMON/scndv2/densn(maxnn,mxphs+1),accn(maxnn,mxcom),acck(mxcom),acck_All
double precision Epsilon1(mxphs), Epsilon2(mxphs)
IDiagonal_dominace = 1 !--- =1: JACOBI
do 1 i=1, ka( nja+1 ) ! ndima
a(i) = 0.0d0
1 continue
do 3 i = 1, kvst( ibkmax + 1) ! nbmxc
b(i) = 0.0d0
3 continue
EpsilonMax1 = 0.0
EpsilonMax2 = 0.0
NEpsilonMax1 = 1
NEpsilonMax2 = 1
do 1000 i=1, ibkmax
inode=i
imat=matx(i)
do iphas=1, nph
fsum(iphas) = 0.0d0
fsums(iphas) = 0.0d0
fdsum( iphas ) = 0.0d0
fdsav(iphas) = 0.0d0
do index=1, ia(i+1)-1 - ( ia(i) )
fsav(iphas, index) = 0.0d0
enddo
enddo
if(iwell(inode).eq.0) then
do iphas=1,mnph
qm_bc(iphas)=0.0d0
enddo
elseif(iwell(inode).eq.1) then
call bc_ev(INODE)
elseif(iwell(inode).eq.2) then
call bc_well(inode,ishift,ia, ja,nja)
endif
call eqnsa(INODE,IMAT,ishift)
jconet=0
do 12 index = ia(i)+1, ia(i+1)-1
id = ja( index )
jconet=jconet+1
if(dabs(gamman(index)).le.eps) goto 12
call eqnsf(INODE,id,imat,ishift,index,jconet,impl(i))
do 14 iphas = 1, mxphs
if( impl(i) .eq. 0 )then
a( ka(isymm(index)) + iphas ) = fdp( iphas )
else
fsav(iphas, jconet) = flw(iphas)
endif
14 continue
if( (impl(i) .eq. 0) .AND. (IDiagonal_dominace .eq. 1) )then !---
a( ka(isymm(index)) + 1 ) = fdp( 3 )
a( ka(isymm(index)) + 3 ) = fdp( 1 )
endif
12 continue
do 15 iphas = 1, mxphs
b( kvst(i) + iphas ) = -fsum( iphas )
if(EPSN1.GT.0.0.AND.EPSN2.GT.0.0) then !-- -----------------
Epsilon1(iphas) = abs(b( kvst(i) + iphas )/(acck_All+1.0D-20)) !---
Epsilon2(iphas) = abs(b( kvst(i) + iphas )) !---
if(EpsilonMax1(iphas).LT.Epsilon1(iphas)) then
EpsilonMax1(iphas) = Epsilon1(iphas)
NEpsilonMax1(iphas) = i
endif
if(EpsilonMax2(iphas).LT.Epsilon2(iphas)) then
EpsilonMax2(iphas) = Epsilon2(iphas)
NEpsilonMax2(iphas) = i
endif
endif !--------------------------
if( impl(i) .eq. 0) then
fdsav( iphas ) = fdiag( iphas)
else
fsums(iphas) = fsum(iphas)
fdsav(iphas) = fdiag(iphas)
endif
15 continue
if(IDiagonal_dominace.EQ.1)then !---
b( kvst(i) + 1 ) = -fsum( 3 )
b( kvst(i) + 3 ) = -fsum( 1 )
endif
do 2000 icol=1, nph
isave=1
ishift=1
call save_v(INODE,ISAVE,ICOL)
call shif(INODE,ICOL,stemp)
if( impl(i) .eq. 0)then
kupdat = 0
else
kupdat = 1
endif
if(MOP(10).NE.0) kupdat=0 !--- add by Diyuan, 2014-6-6
call eosms(inode,kupdat,b,kvst)
if(iwell(inode).eq.0) then
!$acc loop
do iphas=1,mnph
qm_bc(iphas)=0.0d0
enddo
elseif(iwell(inode).eq.1) then
call bc_ev(INODE)
elseif(iwell(inode).eq.2) then
call bc_well(inode,ishift,ia, ja,nja)
endif
call eqnsa(inode,IMAT,ishift)
if( impl(i) .eq. 0 ) go to 100
if( impl(i) .eq. 0 .and. icol .gt. 1) go to 100
jconet=0
do 150 index =ia(i)+1, ia(i+1)-1
id = ja( index )
jconet=jconet+1
if(dabs(gamman(index)).le.eps) goto 150
call save_tauf_C(idcon(index),1,ICOL)
call EOSMS_Connection(idcon(index),kupdat) !-- add by Diyuan, 2012-6-22
call eqnsf(INODE,id,imat,ishift,index,jconet,impl(i))
call save_tauf_C(idcon(index),2,ICOL)
do 101 irow=1,mxphs
if( impl(i) .eq. 1)then
a(ka(isymm(index))+(irow-1)*mxphs+icol) = +(flw(irow)-fsav(irow,jconet))/stemp
else
a(ka(isymm(index))+irow) = (flw(irow)-fsav(irow,jconet))/stemp
endif
101 continue
if(IDiagonal_dominace.EQ.1)then !---
a_temp = a(ka(isymm(index))+(1-1)*mxphs+icol)
a(ka(isymm(index))+(1-1)*mxphs+icol) = a(ka(isymm(index))+(3-1)*mxphs+icol)
a(ka(isymm(index))+(3-1)*mxphs+icol) = a_temp
endif
150 continue
100 continue
do 120 irow=1, mxphs
itemp = ka( ia(i) ) + (irow-1)* mxphs
if( impl(i) .eq. 0 ) then
a(itemp + icol) = ( fdiag(irow) - fdsav(irow) ) / stemp
if( icol .eq. 1)then
a( itemp + icol ) = a( itemp + icol ) + fdsum(irow)
endif
else
a(itemp+icol) = + (fsum(irow) - fsums(irow ))/ stemp
endif
120 continue
if(IDiagonal_dominace.EQ.1)then !---
itemp1 = ka( ia(i) ) + (1-1)* mxphs
itemp3 = ka( ia(i) ) + (3-1)* mxphs
a_temp = a(itemp1 + icol)
a(itemp1 + icol) = a(itemp3 + icol)
a(itemp3 + icol) = a_temp
endif
isave=2
call save_v(INODE,ISAVE,ICOL)
2000 continue
1000 continue
ishift=0
RETURN
END
But when I add the openacc directive ,I can’t see the output information and data replication information ,in console there isn’t also outputing kernel execution time information. I have set up the environment variables and command-line parameters to ensure that the information output. :
!$acc parallel loop
do iphas=1, nph
fsum(iphas) = 0.0d0
fsums(iphas) = 0.0d0
fdsum( iphas ) = 0.0d0
fdsav(iphas) = 0.0d0
do index=1, ia(i+1)-1 - ( ia(i) )
fsav(iphas, index) = 0.0d0
enddo
enddo
!$acc end parallel
The array store in .com file . I don’t know why the openacc has no effort ,and what impact the goto-statement have , would I like to delete goto-statement the program to modify the program for using openacc

Not reading Input file to run stress autocorrelation function

I am trying to run a stress autocorrelation function code to calculate the stress autocorrelation function,then from there I would like to calculate viscosity using Green -Kubo equation. Now the Fortran code I have does not read out my stress data in order to calculate stress auot-correlarion function. Anyone can please help me with this. I have attached my code and data I want to correlate. Hope to here from you soon.
Here is the error
./a.out
**** Program Stress_autocorrelation ****
Calculation of time Correlation Functions
Enter data file name
DFILE
Enter results file name
RFILE
0.00000000
0.00000000
0.00000000
0.00000000
0.00000000
0.00000000
0.00000000
0.00000000
At line 106 of file main.f95 (unit = 10, file = 'DFILE')
Fortran runtime error: Bad value during floating point read
Code and below is Input data:
! Program to claculate pressure autocorrelation function
program stress_autocorrelation
implicit none
common / block1 / STORA, STORB, STORC, STORD,STORE,STORF,STORG, STORH, STORI
common / block2 / PA, PB, PC, PD, PE, PF, PG, PH , PI
common / block3 / PACF, ANORM
! *******************************************************************
! ............ PRINCIPAL VARIABLES............
!
! ** integer N Number of atoms
! ** integer NSTEP Number of steps on the tape
! ** integer IOR Interval for time origins
! ** integer NT Correlation length, Including T=0
! ** integer NTIMOR Number of time origin
! ** integer NLABEL Label for step (1,2,3.....Nstep)
!
!
! ** real PACF(NT) The pressure correlation function
! ** NSTEP and NT should be multiples of IOR.
! ** PA,PB,PC = Pxx,Pxy,Pxz
! ** PD,PE,PF = Pyx,Pyy,Pyz
! ** PG,PH,PI = Pzx,Pzy,Pzz
!
!
! ...............ROUTINES REFERENCED..........................
!
! ....Subroutine Store (J1)..........
!Routine to store the data for correlation
! .....Subroutine Corr (J1,J2,IT).........
!Routine to correlate the stored time origin
!
!
! .....................USAGE..............................
!
! Data in file DFILE on fortrran UNIT DUNIT
! Results in File RFILE on fortran UNIT RUNIT
! *******************************************************************
integer N, NSTEP, IOR, NT, NDIM, DUNIT, RUNIT, NTIMOR
integer FULLUP
parameter ( N = 78, NSTEP = 10, IOR = 4, NT = 8 )
parameter ( DUNIT = 10, RUNIT = 11 )
parameter ( NDIM = NT / IOR + 1, NTIMOR = NSTEP / IOR )
parameter ( FULLUP = NDIM - 1 )
real PA(N), PB(N), PC(N), PD(N), PE(N), PF(N), PG(N), PH(N), PI(N)
real STORA(NDIM,N), STORB(NDIM,N), STORC(NDIM,N),STORD(NDIM,N), STORE(NDIM,N),STORF(NDIM,N),STORG(NDIM,N),STORH(NDIM,N)
real STORI(NDIM,N)
REAL PACF(NT), ANORM(NT)
integer S(NTIMOR), TM(NTIMOR)
integer TS, TSS, L, NINCOR, K, R, JA, IB, IN, IA, JO, I
integer NLABEL
character DUMMY * 5
character DFILE * 115
character RFILE * 115
! *******************************************************************
write(*,'('' **** Program Stress_autocorrelation **** '')')
write(*,'('' Calculation of time Correlation Functions '')')
!.....READ IN FILE NAMES.........
write(*,'('' Enter data file name'')')
read (*,'(A)') DFILE
write (*,'('' Enter results file name'')')
read (*,'(A)') RFILE
!......INITIALIZE COUNTERS.......
NINCOR = FULLUP
JA = 1
IA = 1
IB = 1
!........ZERO ARRAYS.............
do 5 I = 1, NT
PACF(I) = 0.0
ANORM(I) = 0.0
write(*,*) PACF(I)
5 continue
!..........OPEN DATA FILE AND RESULTS FILE...........
open ( UNIT = DUNIT, FILE = DFILE, STATUS = 'OLD', FORM = 'FORMATTED')
open ( UNIT = RUNIT, FILE = RFILE, STATUS = 'NEW' )
!.........CALCULATION BEGINS............
do 40 L = 1, NTIMOR
JA = JA + 1
S(L) = JA - 1
read ( DUNIT, '(A5,I4)') DUMMY, NLABEL
do 7 R = 1, N
read (DUNIT,'(F9.6,8(9X,F9.6))')PA(R),PB(R),PC(R),PD(R),PE(R),PF(R),PG(R),PH(R),PI(R)
7 continue
TM(L) = NLABEL
write(*,*) TM(L)
!.......STORE STEP AS A TIME ORIGIN......
call STOREE ( JA )
!........CORRELATE THE ORIGINS IN STORE......
do 10 IN = IA, L
TSS = TM(L) - TM(IN)
TS = TSS + 1
JO = S(IN) + 1
call CORR ( JO, JA, TS )
10 continue
!Read IN data between time origins. This can
!Be conveniently stored IN element 1 of the
!Array storx etc. and can then ben correlated
!With the time origins
do 30 K = 1, IOR - 1
read ( DUNIT, '(A5,I4)') DUMMY, NLABEL
do 15 R = 1, N
read ( DUNIT,'(F17.14,8(13X,F17.14))')PA(R),PB(R),PC(R),PD(R),PE(R),PF(R),PG(R),PH(R),PI(R)
15 continue
call STOREE ( 1 )
do 20 IN = IA, L
TSS = NLABEL - TM(IN)
TS = TSS + 1
JO = S(IN) + 1
call CORR ( JO, 1, TS )
20 continue
30 continue
if ( L .GE. FULLUP ) then
if ( L .EQ. NINCOR ) then
NINCOR = NINCOR + FULLUP
JA = 1
endif
IA = IA + 1
endif
40 continue
close ( DUNIT )
!.....NORMALISE CORRELATION FUNCTIONS.......
PACF(1) = PACF(1) / ANORM(1) / REAL ( N )
do 50 I = 2, NT
PACF(I) = PACF(I) / ANORM(I) / REAL ( N ) / PACF(1)
50 continue
write ( RUNIT, '('' Pressure ACF '')')
write ( RUNIT, '(I6,E15.6)') ( I, PACF(I), I = 1, NT )
close ( RUNIT )
stop
end
subroutine STOREE ( J1 )
common / BLOCK1 / STORA, STORB, STORC, STORD,STORE,STORF,STORG,STORH,STORI
common/ BLOCK2 / PA, PB, PC, PD, PE, PF, PG, PH, PI
! *******************************************************************
!.........SUBROUTINE TO STORE TIME ORIGINS..............
! *******************************************************************
integer J1
integer N, NT, IOR, NDIM
parameter ( N = 78, NT = 8, IOR =4 )
parameter ( NDIM = NT / IOR + 1 )
real STORA(NDIM,N), STORB(NDIM,N), STORC(NDIM,N),STORD(NDIM,N)
real STORE(NDIM,N),STORF(NDIM,N),STORG(NDIM,N),STORH(NDIM,N),STORI(NDIM,N)
real PA(N), PB(N), PC(N), PD(N), PE(N), PF(N),PG(N), PH(N), PI(N)
integer I
do 10 I = 1, N
STORA(J1,I) = PA(I)
STORB(J1,I) = PB(I)
STORC(J1,I) = PC(I)
STORD(J1,I) = PD(I)
STORE(J1,I) = PE(I)
STORF(J1,I) = PF(I)
STORG(J1,I) = PG(I)
STORH(J1,I) = PH(I)
STORI(J1,I) = PI(I)
10 continue
return
end
subroutine CORR ( J1, J2, IT )
common / block1 / STORA, STORB, STORC, STORD,STORE,STORF,STORG,STORH,STORI
common/ block3 / PACF, ANORM
! *******************************************************************
!......SUBROUTINE TO CORRELATE TIME ORIGINS....
! *******************************************************************
integer J1, J2, IT
integer N, NT, IOR, NDIM
parameter ( N = 78, NT = 8, IOR = 4 )
parameter ( NDIM = NT / IOR + 1 )
real STORA(NDIM,N), STORB(NDIM,N), STORC(NDIM,N),STORD(NDIM,N)
real STORE(NDIM,N),STORF(NDIM,N),STORG(NDIM,N),STORH(NDIM,N),STORI(NDIM,N)
real PACF(NT), ANORM(NT)
integer I
!********************************************************************
do 10 I = 1, N
PACF(IT) = PACF(IT) + STORA(J1,I) * STORA(J2,I) &
+ STORB(J1,I) * STORB(J2,I) &
+ STORC(J1,I) * STORC(J2,I) &
+ STORD(J1,I) * STORD(J2,I) &
+ STORE(J1,I) * STORE(J2,I) &
+ STORF(J1,I) * STORF(J2,I) &
+ STORG(J1,I) * STORG(J2,I) &
+ STORH(J1,I) * STORH(J2,I) &
+ STORI(J1,I) * STORI(J2,I)
10 continue
ANORM(IT) = ANORM(IT) + 1.0
return
end
Data: has 9 columns
-9.568336E+00 -1.615161E+00 1.042644E+00 -1.615161E+00 -1.131916E+01 -6.979813E-01 1.042644E+00 -6.979813E-01 -1.182917E+01
-4.765572E-01 9.005122E-01 -2.282920E+00 9.005122E-01 -3.827857E+00 -3.206736E+00 -2.282920E+00 -3.206736E+00 -6.252462E+00
-1.012710E+01 4.672368E-01 8.791873E-02 4.672368E-01 -4.680832E+00 -5.271814E-01 8.791873E-02 -5.271814E-01 -1.898345E-01
-7.699012E+00 -9.906154E-01 7.450304E-01 -9.906154E-01 -1.061230E+00 -3.546956E+00 7.450304E-01 -3.546956E+00 -6.843898E+00
-3.544260E+00 4.254020E+00 -1.963602E+00 4.254020E+00 3.740858E+00 -4.587760E+00 -1.963602E+00 -4.587760E+00 -6.776258E+00
1.755595E-01 -9.625855E-01 -2.395960E+00 -9.625855E-01 -1.701399E+00 -8.483695E-01 -2.395960E+00 -8.483695E-01 -4.165223E+00
-3.244186E+00 5.540608E+00 -4.951768E-01 5.540608E+00 3.068601E+00 -1.613010E-01 -4.951768E-01 -1.613010E-01 -5.641277E+00
-8.985849E+00 1.870244E+00 -2.295795E-01 1.870244E+00 -4.635924E+00 -4.787461E+00 -2.295795E-01 -4.787461E+00 -3.014272E+00
-1.651073E-01 -6.326584E-01 -3.028051E+00 -6.326584E-01 -2.621833E+00 -2.640439E+00 -3.028051E+00 -2.640439E+00 1.668877E+00
1.250349E+00 3.054784E+00 -2.898975E+00 3.054784E+00 8.419503E-01 9.620184E-01 -2.898975E+00 9.620184E-01 1.479256E+00
-7.796195E-01 1.942983E+00 -2.736569E+00 1.942983E+00 6.073043E+00 -2.520281E+00 -2.736569E+00 -2.520281E+00 -9.600832E-01
4.697066E-01 3.138124E+00 -1.092573E+00 3.138124E+00 -2.099285E+00 -1.581031E+00 -1.092573E+00 -1.581031E+00 -6.285002E-01
3.017532E-01 -9.701574E-02 1.611936E+00 -9.701574E-02 -1.762075E+00 -3.401961E+00 1.611936E+00 -3.401961E+00 -6.889746E-01
1.177410E-01 5.090611E-01 1.452691E-01 5.090611E-01 5.695570E+00 -3.573245E+00 1.452691E-01 -3.573245E+00 -1.099615E+00
-5.180126E+00 -1.876409E-01 -2.067182E+00 -1.876409E-01 1.611177E+00 5.458450E-01 -2.067182E+00 5.458450E-01 1.026071E+00
1.477567E+00 1.598949E+00 -1.577546E+00 1.598949E+00 3.933810E+00 -2.698132E+00 -1.577546E+00 -2.698132E+00 3.485029E+00
-2.533324E+00 1.753033E+00 1.425241E-01 1.753033E+00 2.406501E+00 -1.147217E+00 1.425241E-01 -1.147217E+00 3.065603E-01
-2.360274E+00 1.312721E+00 -3.711419E-01 1.312721E+00 2.556935E+00 3.152605E-01 -3.711419E-01 3.152605E-01 3.378170E+00
-1.698217E+00 1.105760E+00 3.780822E-01 1.105760E+00 2.736574E+00 7.920578E-01 3.780822E-01 7.920578E-01 -6.596856E-01
-5.099544E+00 1.647542E-01 -1.036544E+00 1.647542E-01 3.845429E+00 -1.034068E+00 -1.036544E+00 -1.034068E+00 -3.152053E+00
-2.686567E+00 1.335786E+00 -1.889911E-01 1.335786E+00 9.755267E-01 9.322043E-01 -1.889911E-01 9.322043E-01 3.229615E-01
1.542994E-01 3.104663E+00 -1.634353E-01 3.104663E+00 4.090105E+00 -1.128244E+00 -1.634353E-01 -1.128244E+00 -2.909383E-01
-4.235419E-01 1.554157E+00 3.475430E+00 1.554157E+00 4.701173E+00 -1.789414E+00 3.475430E+00 -1.789414E+00 1.517218E+00
-8.054924E-01 -1.167935E+00 -1.123460E+00 -1.167935E+00 1.169303E+00 -2.171076E+00 -1.123460E+00 -2.171076E+00 -5.636150E+00