Hello All,
I am new to using Fortan and doing research work with hourly observation data and computing 24 hour times periods down to daily averaged vaule. I have did a search online and found a Fortran script similar to what my needs are for data computation. The script runs as far as line 101 then crashes. Not sure what the issues is with the script. Does anyone have any suggustions? Also how would I output the two columns of date and data to a new file say one named datatest.txt? I have file format and the script being used to below.....
Thank you
20101002 15:00 0.4
20101002 16:00 0.4
20101002 17:00 0.4
20101002 18:00 0.7
20101002 19:00 0.8
20101002 20:00 0.8
20101002 21:00 0.6
20101002 22:00 0.4
program control_break
! Single-Level Control Break Processing
implicit none
integer :: stat, nr_records
real :: dummy
! global variables
integer :: date, date_save, col02, nr_col03, tnr_col03
real :: col03, sum_col03, tsum_col03
common date, date_save, col02, col03, &
nr_col03, sum_col03, &
tnr_col03, tsum_col03
! open file
open (1, file="C:\\Users\\Jason\\Desktop\\GEOS-CHEM-Data\\County005-CO-0133.txt", status='old', iostat=stat)
if (stat .ne. 0) then
write(*,*) 'File cannot be opened !'
go to 99
end if
write(*, '(80A)') '*******************************************************'
! process file
nr_records = 0
date_save = 0
do while (.true.)
! read record
read(1, *, end=99) dummy, col02, col03
nr_records = nr_records + 1
call process_record
call save_keys
enddo
99 continue
! at end print totals
call print_daily_summary
call print_total_summary
write(*, 10) nr_records
write(*, '(80A)') '*******************************************************'
! close file
close(1)
10 format('Processing of',1X, I0, 1X, 'lines finished.')
end program control_break
subroutine process_record
implicit none
! global variables
integer :: date, date_save, col02, nr_col03, tnr_col03
real :: col03, sum_col03, tsum_col03
common date, date_save, col02, col03, &
nr_col03, sum_col03, &
tnr_col03, tsum_col03
! compute date
date = col02
! if not on first record
if (date_save .ne. 0) then
! process control break
call process_control_break
end if
! print line
write(*, 10) col02, col03
! compute sum of col03
if (col03 .ne. -999.0) then
nr_col03 = nr_col03 + 1
sum_col03 = sum_col03 + col03
tnr_col03 = tnr_col03 + 1
tsum_col03 = tsum_col03 + col03
end if
10 format(5X, I10, 1X, f8.2, 1X, f8.2)
end subroutine process_record
subroutine process_control_break
implicit none
! global variables
integer :: date, date_save, col02, nr_col03, tnr_col03
real :: col03, col07, sum_col03, tsum_col03
common date, date_save, col02, col03, &
nr_col03, sum_col03, &
tnr_col03, tsum_col03
if (date .ne. date_save) then
call print_daily_summary
end if
end subroutine process_control_break
subroutine print_daily_summary
implicit none
! global variables
integer :: date, date_save, col02, nr_col03, tnr_col03
real :: col03, sum_col03, tsum_col03
common date, date_save, col02, col03 &
nr_col03, sum_col03, &
tnr_col03, tsum_col03
write(*, *)
write(*, 10) date_save
write(*, 20) sum_col03
write(*, 30) nr_col03
write(*, 40) sum_col03/nr_col03
write(*, *)
10 format('* Summary for date',1x,I8,':')
20 format('* sum:',9x, f8.2, 1x, f8.2)
30 format('* count:',7x,I8,1x,I8)
40 format('* average:',5x, f8.2, 1x, f8.2)
! initialize gloabal variables
sum_col03 = 0
nr_col03 = 0
end subroutine print_daily_summary
subroutine print_total_summary
implicit none
! global variables
integer :: date, date_save, col02, nr_col03, tnr_col03
real :: col03, sum_col03, tsum_col03
common date, date_save, col02, col03, &
nr_col03, sum_col03, &
tnr_col03, tsum_col03
write(*, 10)
write(*, 20) tsum_col03
write(*, 30) tnr_col03
write(*, 40) tsum_col03/tnr_col03
10 format('** Summary for all dates:')
20 format('** sum:',9x, f8.2, 1x, f8.2)
30 format('** count:',7x,I8,1x,I8)
40 format('** average:',5x, f8.2, 1x, f8.2)
end subroutine print_total_summary
subroutine save_keys
implicit none
! global variables
integer :: date, date_save, col02, nr_col03, tnr_col03
real :: col03, sum_col03, tsum_col03
common date, date_save, col02, col03, &
nr_col03, sum_col03, &
tnr_col03, tsum_col03
date_save = date
end subroutine save_keys
I am new to using Fortan and doing research work with hourly observation data and computing 24 hour times periods down to daily averaged vaule. I have did a search online and found a Fortran script similar to what my needs are for data computation. The script runs as far as line 101 then crashes. Not sure what the issues is with the script. Does anyone have any suggustions? Also how would I output the two columns of date and data to a new file say one named datatest.txt? I have file format and the script being used to below.....
Thank you
20101002 15:00 0.4
20101002 16:00 0.4
20101002 17:00 0.4
20101002 18:00 0.7
20101002 19:00 0.8
20101002 20:00 0.8
20101002 21:00 0.6
20101002 22:00 0.4
program control_break
! Single-Level Control Break Processing
implicit none
integer :: stat, nr_records
real :: dummy
! global variables
integer :: date, date_save, col02, nr_col03, tnr_col03
real :: col03, sum_col03, tsum_col03
common date, date_save, col02, col03, &
nr_col03, sum_col03, &
tnr_col03, tsum_col03
! open file
open (1, file="C:\\Users\\Jason\\Desktop\\GEOS-CHEM-Data\\County005-CO-0133.txt", status='old', iostat=stat)
if (stat .ne. 0) then
write(*,*) 'File cannot be opened !'
go to 99
end if
write(*, '(80A)') '*******************************************************'
! process file
nr_records = 0
date_save = 0
do while (.true.)
! read record
read(1, *, end=99) dummy, col02, col03
nr_records = nr_records + 1
call process_record
call save_keys
enddo
99 continue
! at end print totals
call print_daily_summary
call print_total_summary
write(*, 10) nr_records
write(*, '(80A)') '*******************************************************'
! close file
close(1)
10 format('Processing of',1X, I0, 1X, 'lines finished.')
end program control_break
subroutine process_record
implicit none
! global variables
integer :: date, date_save, col02, nr_col03, tnr_col03
real :: col03, sum_col03, tsum_col03
common date, date_save, col02, col03, &
nr_col03, sum_col03, &
tnr_col03, tsum_col03
! compute date
date = col02
! if not on first record
if (date_save .ne. 0) then
! process control break
call process_control_break
end if
! print line
write(*, 10) col02, col03
! compute sum of col03
if (col03 .ne. -999.0) then
nr_col03 = nr_col03 + 1
sum_col03 = sum_col03 + col03
tnr_col03 = tnr_col03 + 1
tsum_col03 = tsum_col03 + col03
end if
10 format(5X, I10, 1X, f8.2, 1X, f8.2)
end subroutine process_record
subroutine process_control_break
implicit none
! global variables
integer :: date, date_save, col02, nr_col03, tnr_col03
real :: col03, col07, sum_col03, tsum_col03
common date, date_save, col02, col03, &
nr_col03, sum_col03, &
tnr_col03, tsum_col03
if (date .ne. date_save) then
call print_daily_summary
end if
end subroutine process_control_break
subroutine print_daily_summary
implicit none
! global variables
integer :: date, date_save, col02, nr_col03, tnr_col03
real :: col03, sum_col03, tsum_col03
common date, date_save, col02, col03 &
nr_col03, sum_col03, &
tnr_col03, tsum_col03
write(*, *)
write(*, 10) date_save
write(*, 20) sum_col03
write(*, 30) nr_col03
write(*, 40) sum_col03/nr_col03
write(*, *)
10 format('* Summary for date',1x,I8,':')
20 format('* sum:',9x, f8.2, 1x, f8.2)
30 format('* count:',7x,I8,1x,I8)
40 format('* average:',5x, f8.2, 1x, f8.2)
! initialize gloabal variables
sum_col03 = 0
nr_col03 = 0
end subroutine print_daily_summary
subroutine print_total_summary
implicit none
! global variables
integer :: date, date_save, col02, nr_col03, tnr_col03
real :: col03, sum_col03, tsum_col03
common date, date_save, col02, col03, &
nr_col03, sum_col03, &
tnr_col03, tsum_col03
write(*, 10)
write(*, 20) tsum_col03
write(*, 30) tnr_col03
write(*, 40) tsum_col03/tnr_col03
10 format('** Summary for all dates:')
20 format('** sum:',9x, f8.2, 1x, f8.2)
30 format('** count:',7x,I8,1x,I8)
40 format('** average:',5x, f8.2, 1x, f8.2)
end subroutine print_total_summary
subroutine save_keys
implicit none
! global variables
integer :: date, date_save, col02, nr_col03, tnr_col03
real :: col03, sum_col03, tsum_col03
common date, date_save, col02, col03, &
nr_col03, sum_col03, &
tnr_col03, tsum_col03
date_save = date
end subroutine save_keys