Hello,
The subroutine below receives an array of derived type data and uses the data within to run logical tests. I've been successful in writing the results to a text file, but am unable to store them in an array within the subroutine and print it to the terminal.
***Derived Type Definition***
[...]
*********
The input 'array' below contains some 40k+ lines of data of type 'temps'. The lines added since I've been having problems are in bold.
And here's the problem output:
[...]
Histogram of Tmax above/below Tnorm
32 42
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
[...]
Obviously not what I want. I think this is a problem of my understanding of either if loops or subroutines.
The entire script is attached, in case it is needed. The successfully written text file (the data within which I want to store to an array instead) is attached also.
Thanks for any input,
Dave
The subroutine below receives an array of derived type data and uses the data within to run logical tests. I've been successful in writing the results to a text file, but am unable to store them in an array within the subroutine and print it to the terminal.
***Derived Type Definition***
Code:
module my_temps
type temps
integer :: dates, hi, lo, av
real :: hinorms, lonorms
end type temps
contains
*********
The input 'array' below contains some 40k+ lines of data of type 'temps'. The lines added since I've been having problems are in bold.
Code:
subroutine high_norm_runs(array)
implicit none
type(temps), allocatable :: array(:)
integer :: i, n, upcount, downcount, maxuprun, maxdownrun
integer :: upbins(0:50) = (0), downbins(0:50) = 0
integer, allocatable :: allups(:), alldowns(:), [b]allruns(:,:)[/b]
n = size(array)
allocate(allups(n))
allocate(alldowns(n))
[b]allocate(allruns(n,3))[/b]
upcount = 0
downcount = 0
maxuprun = 0
maxdownrun = 0
do i = 1, n
if(array(i)%hinorms /= 99.99) then
if(array(i)%hi > array(i)%hinorms) then
if(downcount > maxdownrun) then
maxdownrun = downcount
endif
downbins(downcount) = downbins(downcount) + 1
upcount = upcount + 1
if(downcount /= 0) then
alldowns(i) = downcount
[b]allruns(i,1) = array(i)%dates
allruns(i,2) = 0
allruns(i,3) = downcount[/b]
!write(3,*) array(i)%dates, '-',downcount
end if
downcount = 0
else
if (upcount > maxuprun) then
maxuprun = upcount
end if
upbins(upcount) = upbins(upcount) + 1
downcount = downcount + 1
if(upcount /= 0) then
allups(i) = upcount
[b]allruns(i,1) = array(i)%dates
allruns(i,2) = 1
allruns(i,3) = upcount[/b]
!write(3,*) array(i)%dates, ' ',upcount
end if
upcount = 0
end if
end if
end do
!do i = 1, 50
! write(*,*) '[',i,']:', upbins(i), downbins(i)
! write(2,*) upbins(i), downbins(i)
!end do
write (*,*) maxuprun, maxdownrun
!write (2,*) maxuprun, maxdownrun
!write (2,*)
[b]do i = 1, 100
write(*,*) allruns(i,1), allruns(i,2), allruns(i,3)
end do[/b]
end subroutine high_norm_runs
And here's the problem output:
[...]
Histogram of Tmax above/below Tnorm
32 42
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
[...]
Obviously not what I want. I think this is a problem of my understanding of either if loops or subroutines.
The entire script is attached, in case it is needed. The successfully written text file (the data within which I want to store to an array instead) is attached also.
Thanks for any input,
Dave