i have 2 tables contain 2 columns (id, value). tables have same number of rows (id). so, want sum columns value
tables each id.
can me how can fortran? please find below part of code wrote in line 19, not estimate summation.
integer :: id,idmax,nf,files,write_id real, allocatable, dimension(:) :: val,vct_val,sum_files idmax=5 nfiles=2 allocate (vct_val(idmax)) allocate(val(nfiles)) allocate (sum_files(idmax)) nf=0 !nf number of file nf = 1,nfiles open(10,file=fname_daily) id=1, idmax read(10,'(i6,1x,f16.2)') write_id,val(nf) vct_val(id)=val(nf) print *, 'read file ', write_id, vct_val(id), val(nf) end !for rows(id) enddo !for nfiles id=1, idmax print *, 'file1 sum', write_id, val(1) print *, 'file2 sum', write_id, val(2) sum_files(id)=val(1)+val(2) end !for rows(id) write(20,'(i6,a,f20.2)') (write_id, tab, sum_files(write_id), write_id=1, idmax)
in following can find example of file 1 , file 2 want sum columns "value" each id.
file1
"id" "value"
1 51000.00 2 1612000.00 3 1520000.00 4 1520000.00 5 1134000.00
file2
"id" "value"
1 35740000.00 2 24460000.00 3 21800000.00 4 54280000.00 5 42530000.00
the first print(line 14) gives following correct values:
read file 1 51000.0000 51000.0000 read file 2 1612000.00 1612000.00 read file 3 1520000.00 1520000.00 read file 4 1520000.00 1520000.00 read file 5 1134000.00 1134000.00 read file 1 35740000.0 35740000.0 read file 2 24460000.0 24460000.0 read file 3 21800000.0 21800000.0 read file 4 54280000.0 54280000.0 read file 5 42530000.0 42530000.0
however, second print (line 18) gives values id 5:
file1 sum 5 1134000.00 file2 sum 5 42530000.0 file1 sum 5 1134000.00 file2 sum 5 42530000.0 file1 sum 5 1134000.00 file2 sum 5 42530000.0 file1 sum 5 1134000.00 file2 sum 5 42530000.0 file1 sum 5 1134000.00 file2 sum 5 42530000.0 file1 sum 5 1134000.00 file2 sum 5 42530000.0
Comments
Post a Comment