-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_dim.f03
68 lines (44 loc) · 1.78 KB
/
get_dim.f03
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
SUBROUTINE GET_DIM(nx, ny, nz, nparticles, nproc)
! Reads the number of cpus used for the RASMES simulation that produces the particle initialization used in the code,
! then reads each file containing particles to get the total number of particles to allocate enough memory
!
! Expects and info_0000* file containing ncpu, and ncpu files containing the number of particles contained in each file
IMPLICIT NONE
INTEGER :: nproc, pos, index
INTEGER :: nx, ny, nz, nparticles, nparticles_file
INTEGER :: unit_info, unit_part, min_level
CHARACTER(LEN = 128) :: folder, filename
CHARACTER(LEN = 128) :: buffer
CHARACTER(LEN = 128) :: nx_string, pos_string, index_string
unit_info = 1
unit_part = 10
nparticles = 0
write(nx_string, "(I0)") nx
if (nx .eq. 512) then
index = 6
else
index = 3
end if
write(index_string, "(I0)") index
folder = "./output_00003/test" // TRIM(nx_string)
filename = TRIM(folder) // "/info_0000" // TRIM(index_string) // ".txt"
open(unit = unit_info, file = filename, status = 'old', form = 'formatted')
read(unit_info, '(A13, I11)') buffer, nproc
close(unit_info)
do pos = 1, nproc
write(pos_string, "(I0)") pos
if (pos < 10) then
filename = TRIM(folder) // "/part_0000" // TRIM(index_string) // ".out0000" // TRIM(pos_string)
else if (pos < 100) then
filename = TRIM(folder) // "/part_0000" // TRIM(index_string) // ".out000" // TRIM(pos_string)
else
filename = TRIM(folder) // "/part_0000" // TRIM(index_string) // ".out00" // TRIM(pos_string)
end if
open(unit = unit_part, file = filename, status = 'old', form = 'unformatted')
read(unit_part)
read(unit_part)
read(unit_part) nparticles_file
nparticles = nparticles + nparticles_file
close(unit_part)
end do
END SUBROUTINE GET_DIM