Howdy, Stranger!




FORTRAN 90 Tracking cumulative emissions read in from txt file

I am attempting to modify an original set of code which uses a spline interpolator to plot a curve representing cumulative emissions (and its derivative annual emissions). The goal is to read in the historical emissions (from histem.txt) and then track the cumulative emissions (read integral of annual emissions) which I will tack onto the cumulative emissions spit out by the spline interpolator in cumemC.txt.

program sat_profile

! interpolated values at other time intervals by changing the loop that
! generates tval and calculates yval.

implicit none

integer i, j

real year(257), emissions(257), HIST, TIM, sum, cem(257)


t(3) = 2500. ! year of zero emissions
! calculate the spline derivatives

call exit(1)

call exit(1)

if ( then
call exit(1)

if ( then
call exit(1)

open(unit=15, file='histem.txt')

258 open (10, file='cumemC.txt')
! evaluate the spline at points tval


do i=1,257
do j=1,i
sum = sum + emissions(j)
write (*, '(2f12.4)')
cem(i) = sum

do i=iyr,fyr
tval = float(i)

! if not doing stabilization, get rid of this line:


AEMIT(i) = yval
TIME(i) = tval
end do
close (10)

open(10, file='anemC.txt')
EMIT(iyr) = initg

do i=iyr+1,fyr

end do

close (10)


also see combined.txt and histem.txt

The way I am currently reading in year and emissions via:


is storing these each as a 1-column vector. Since I need to be tracking a running sum of emissions, what I really need to be doing is storing these as 257 scalar values instead (or so I believe?). However, I am uncertain of how to do this. I have attempted using a do loop in earlier versions of the code, but was unsuccessful.

I am using a do loop for purposes of a running sum of emissions:

do i=1,257
do j=1,i
abc = abc + emissions(j)
write (*, '(2f12.4)')
cem(i) = abc

here abc represents the variable I use to keep track of the running sum, emissions are the annual emissions in GtC, and cem(i) represents the integral of emissions.

Unfortunately, because of the way this file is being read, cem(i) and year(i) do not get stored properly, and the resulting text file is erroneous.

I have attached the histem.txt file and the code (combined.txt)
Sign In or Register to comment.