Hi,
I have the following problem, can any one help?
I have 744 simple ascii files. Each of them has the following format: One line header and a column of values. The column has 275648 values (rows).
The target is to create 248 simple ascii files (744/3). Each of the new files has the following format:
The same header as in the old files and the same number of rows (275648). But the first new file contains the average of the old files (file1, file2 and file3). The second new files will contain the average of the three old files (file4, file5, and file6).
How can i do this, below is my trial.
*****************************
program testInternalFiles
implicit none
integer i
integer ios
integer, parameter:: inFileUnit = 8
integer, parameter:: outFileUnit = 9
! Buffers to hold file names
character(80) inputFileName
character(80) outputFileName
character(180) skip
do i=1,248
jj=3*i
j=3*i-2
do k=j,jj
!Use internal files to convert integers to string values
! and embed it in the file names
write (inputFileName, '(a, I0, a)') 'NLDAS.VGRD.',k,'.sa'
write (outputFileName, '(a, I0, a)') 'NLDAS.VGRD.',i,'.dat'
open(inFileUnit, file=inputFileName,status="old", iostat=ios)
if (ios /= 0 ) then
write(*, '("Can''t open file ", a, " for reading.")') &
trim(inputFileName)
stop
endif
write(*, '("Opened file ", a, " for reading.")') &
trim(inputFilename)
!
! It will bail out rather than overwrite an existing file.
!
open(outFileUnit, file=outputFileName,status="new", iostat=ios)
if (ios /= 0) then
write(*, '("Can''t open file ", a, " for writing.")') &
trim(outputFileName)
stop
endif
write(*, '("Opened file ", a, " for writing.")') &
trim(outputFilename)
! Here's where you read stuff from the input file
! and write stuff to the output file.
read(inFileUnit,*) skip
read(inFileUnit,*) x
y=
write(outFileUnit,*) skip
! Close files before next pass through the loop
write(*, '("Closing files.")')
close(inFileUnit)
close(outFileUnit)
write(*,*)
enddo
end program testInternalFiles
*****************************************
thanks
I have the following problem, can any one help?
I have 744 simple ascii files. Each of them has the following format: One line header and a column of values. The column has 275648 values (rows).
The target is to create 248 simple ascii files (744/3). Each of the new files has the following format:
The same header as in the old files and the same number of rows (275648). But the first new file contains the average of the old files (file1, file2 and file3). The second new files will contain the average of the three old files (file4, file5, and file6).
How can i do this, below is my trial.
*****************************
program testInternalFiles
implicit none
integer i
integer ios
integer, parameter:: inFileUnit = 8
integer, parameter:: outFileUnit = 9
! Buffers to hold file names
character(80) inputFileName
character(80) outputFileName
character(180) skip
do i=1,248
jj=3*i
j=3*i-2
do k=j,jj
!Use internal files to convert integers to string values
! and embed it in the file names
write (inputFileName, '(a, I0, a)') 'NLDAS.VGRD.',k,'.sa'
write (outputFileName, '(a, I0, a)') 'NLDAS.VGRD.',i,'.dat'
open(inFileUnit, file=inputFileName,status="old", iostat=ios)
if (ios /= 0 ) then
write(*, '("Can''t open file ", a, " for reading.")') &
trim(inputFileName)
stop
endif
write(*, '("Opened file ", a, " for reading.")') &
trim(inputFilename)
!
! It will bail out rather than overwrite an existing file.
!
open(outFileUnit, file=outputFileName,status="new", iostat=ios)
if (ios /= 0) then
write(*, '("Can''t open file ", a, " for writing.")') &
trim(outputFileName)
stop
endif
write(*, '("Opened file ", a, " for writing.")') &
trim(outputFilename)
! Here's where you read stuff from the input file
! and write stuff to the output file.
read(inFileUnit,*) skip
read(inFileUnit,*) x
y=
write(outFileUnit,*) skip
! Close files before next pass through the loop
write(*, '("Closing files.")')
close(inFileUnit)
close(outFileUnit)
write(*,*)
enddo
end program testInternalFiles
*****************************************
thanks