Hi,
I am trying to write a loop to open four main-data-files. At each open of the main-data-file, I want the loop to open another four sub-files and split the data from the mail-data-file according to the creteria and dump into the four files.
When the loop goes to the second main-data-file, it shall generate another 4 sub-files with
different file name. And the process goes on. That means I will have total of 16 sub files for the four main-data-files. Each four files from the 16 files shall have specific name on it.
Based on the code which I given below, I would say when the file at UNIT=100 is opened, 4 new files needed to be opened as well. They are:
maximum_dist_001_064.dat
maximum_dist_065_128.dat
maximum_dist_129_192.dat
maximum_dist_193_256.dat
But at the same time I want this files to be named as
maximum_dist_001_064_100.dat
maximum_dist_065_128_100.dat
maximum_dist_129_192_100.dat
maximum_dist_193_256_100.dat
In the calling of second file, UNIT=101, I want another four files to open and named as below:
maximum_dist_001_064_101.dat
maximum_dist_065_128_101.dat
maximum_dist_129_192_101.dat
maximum_dist_193_256_101.dat
And the process goes on. I have tried to write the code as below but it doesnt seems to work.
Code:
program final
implicit none
!
integer :: i,j, k, m, jj, kk
integer, parameter :: dist_lines=256
real, DIMENSION(dist_lines) :: dist
! main-data-files
open(unit=100,status="old",file="selected_MAXdista nce_only_malto_THERMO_1st.dat")
open(unit=101,status="old",file="selected_MAXdista nce_only_malto_THERMO_2nd.dat")
open(unit=102,status="old",file="selected_MAXdista nce_only_malto_THERMO_3rd.dat")
open(unit=103,status="old",file="selected_MAXdista nce_only_malto_THERMO_4th.dat")
do kk = 100,103
! sub-files
open(unit=(10+kk), file="maximum_dist_001_064.dat")
open(unit=(11+kk), file="maximum_dist_065_128.dat")
open(unit=(12+kk), file="maximum_dist_129_192.dat")
open(unit=(13+kk), file="maximum_dist_193_256.dat")
read(kk,'(F8.3)') (dist(i), i = 1,dist_lines)
do k = 1, 256
if (k < 65 ) then
write ((kk+10),'(F8.3)'), dist(k)
elseif ( k >=65 .and. k < 129 ) then
write( (kk+11),'(F8.3)'), dist(k)
elseif ( k >=129 .and. k < 193 ) then
write ((kk+12),'(F8.3)'), dist(k)
elseif ( k >=193 .and. k < 257 ) then
write ((kk+13),'(F8.3)'), dist(k)
end if
end do
end do
stop
end
Could anyone help me in this matter?
Many thanks in advance.
Regards
Vijay