|
68 | 68 | end do |
69 | 69 |
|
70 | 70 | if (.not. files_loaded) then |
71 | | - ! 1) Discover yRows by reading fileNames(1) until x changes from the first line’s x. |
72 | | - open(newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2) |
73 | | - if (ios2 /= 0 ) then |
74 | | - write(errmsg, '(A,A)') "Error opening file for yRows detection: ", trim(fileNames(1)) |
75 | | - call s_mpi_abort(trim(errmsg)) |
76 | | - end if |
77 | | - |
78 | | - ! Read the very first line to get (x₀, y₀) |
79 | | - read(unit2, *, iostat=ios2) x0, y0, dummy_z |
80 | | - if (ios2 /= 0 ) then |
81 | | - write(errmsg, '(A,A)') "Error reading first line of: ", trim(fileNames(1)) |
82 | | - call s_mpi_abort(trim(errmsg)) |
83 | | - end if |
84 | | - |
85 | | - ycount = 1 |
86 | | - do |
87 | | - read(unit2, *, iostat=ios2) dummy_x, dummy_y, dummy_z |
88 | | - if (ios2 /= 0) exit ! End of File : stop counting |
89 | | - if (dummy_x == x0 .and. dummy_y /= y0) then |
90 | | - ! As soon as x or y changes from the first line’s (x0,y0), |
91 | | - ! we know we have counted all the (x0, y1) rows. |
92 | | - ycount = ycount + 1 |
93 | | - else |
94 | | - exit |
| 71 | + ! 1) Discover yRows by reading fileNames(1) until x changes from the first line’s x. |
| 72 | + open (newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2) |
| 73 | + if (ios2 /= 0) then |
| 74 | + write (errmsg, '(A,A)') "Error opening file for yRows detection: ", trim(fileNames(1)) |
| 75 | + call s_mpi_abort(trim(errmsg)) |
| 76 | + end if |
| 77 | + |
| 78 | + ! Read the very first line to get (x₀, y₀) |
| 79 | + read (unit2, *, iostat=ios2) x0, y0, dummy_z |
| 80 | + if (ios2 /= 0) then |
| 81 | + write (errmsg, '(A,A)') "Error reading first line of: ", trim(fileNames(1)) |
| 82 | + call s_mpi_abort(trim(errmsg)) |
| 83 | + end if |
| 84 | + |
| 85 | + ycount = 1 |
| 86 | + do |
| 87 | + read (unit2, *, iostat=ios2) dummy_x, dummy_y, dummy_z |
| 88 | + if (ios2 /= 0) exit ! End of File : stop counting |
| 89 | + if (dummy_x == x0 .and. dummy_y /= y0) then |
| 90 | + ! As soon as x or y changes from the first line’s (x0,y0), |
| 91 | + ! we know we have counted all the (x0, y1) rows. |
| 92 | + ycount = ycount + 1 |
| 93 | + else |
| 94 | + exit |
| 95 | + end if |
| 96 | + end do |
| 97 | + yRows = ycount |
| 98 | + close (unit2) |
| 99 | + ! 2) Count total rows (nrows) to get xRows |
| 100 | + open (newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2) |
| 101 | + if (ios2 /= 0) then |
| 102 | + write (errmsg, '(A,A)') "Error re‐opening file to count rows: ", trim(fileNames(1)) |
| 103 | + call s_mpi_abort(trim(errmsg)) |
| 104 | + end if |
| 105 | + |
| 106 | + nrows = 0 |
| 107 | + do |
| 108 | + read (unit2, *, iostat=ios2) dummy_x, dummy_y, dummy_z |
| 109 | + if (ios2 /= 0) exit |
| 110 | + nrows = nrows + 1 |
| 111 | + end do |
| 112 | + close (unit2) |
| 113 | + |
| 114 | + if (mod(nrows, yRows) /= 0) then |
| 115 | + write (errmsg, '(A,A,I0,A,I0)') & |
| 116 | + "File ’", trim(fileNames(1)), & |
| 117 | + "’ has total lines=", nrows, & |
| 118 | + " which is not a multiple of yRows=", yRows |
| 119 | + call s_mpi_abort(trim(errmsg)) |
95 | 120 | end if |
96 | | - end do |
97 | | - yRows = ycount |
98 | | - close(unit2) |
99 | | - ! 2) Count total rows (nrows) to get xRows |
100 | | - open(newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2) |
101 | | - if (ios2 /= 0 ) then |
102 | | - write(errmsg, '(A,A)') "Error re‐opening file to count rows: ", trim(fileNames(1)) |
103 | | - call s_mpi_abort(trim(errmsg)) |
104 | | - end if |
105 | | - |
106 | | - nrows = 0 |
107 | | - do |
108 | | - read(unit2, *, iostat=ios2) dummy_x, dummy_y, dummy_z |
109 | | - if (ios2 /= 0) exit |
110 | | - nrows = nrows + 1 |
111 | | - end do |
112 | | - close(unit2) |
113 | | - |
114 | | - if (mod(nrows, yRows) /= 0) then |
115 | | - write(errmsg, '(A,A,I0,A,I0)') & |
116 | | - "File ’", trim(fileNames(1)), & |
117 | | - "’ has total lines=", nrows, & |
118 | | - " which is not a multiple of yRows=", yRows |
119 | | - call s_mpi_abort(trim(errmsg)) |
120 | | - end if |
121 | | - xRows = nrows / yRows |
122 | | - allocate(x_coords(nRows)) |
123 | | - allocate(y_coords(nRows)) |
124 | | - allocate(stored_values(xRows, yRows, sys_size)) |
| 121 | + xRows = nrows/yRows |
| 122 | + allocate (x_coords(nRows)) |
| 123 | + allocate (y_coords(nRows)) |
| 124 | + allocate (stored_values(xRows, yRows, sys_size)) |
125 | 125 | index_x = i |
126 | 126 | index_y = j |
127 | | - |
| 127 | + |
128 | 128 | open (newunit=unit, file=trim(fileNames(1)), status='old', action='read', iostat=ios) |
129 | 129 | if (ios /= 0) then |
130 | 130 | write (errmsg, '(A,A)') "Error opening file: ", trim(fileNames(f)) |
|
165 | 165 | end do |
166 | 166 | end do |
167 | 167 | close (unit) |
168 | | - |
169 | 168 |
|
170 | 169 | domain_xstart = x_coords(1) ! First x value |
171 | 170 | domain_ystart = y_coords(1) ! First y value |
|
0 commit comments