7 character(len=NEKO_FNAME_LEN) :: in_fname, out_fname, inputchar
8 character(len=80) :: extension
9 real(kind=rp) :: start_time
12 argc = command_argument_count()
14 if ((argc .lt. 3) .or. (argc .gt. 3))
then
21 call get_command_argument(1, inputchar)
22 read(inputchar, *) in_fname
23 call get_command_argument(2, inputchar)
24 read(inputchar, *) start_time
25 call get_command_argument(3, inputchar)
26 read(inputchar, *) out_fname
28 call filename_suffix(in_fname, extension)
29 select case (trim(extension))
36 character(len=LOG_SIZE) :: log_buf
37 write (log_buf, *) trim(extension),
" files not supported!"
38 call neko_warning(log_buf)
49 if (pe_rank .eq. 0)
then
51 write(*,*)
'average_fields_in_time: Computes a weighted average of a '
52 write(*,*)
'set of statistics samples in time.'
55 write(*,*)
'==========================================================='
56 write(*,*)
' ./average_fields_in_time input.fld start_time output.fld'
57 write(*,*)
' ./average_fields_in_time input.csv start_time output.csv'
59 write(*,*)
' start_time is the time at which the first file starts to '
60 write(*,*)
' collect stats.'
62 write(*,*)
'Examples:'
63 write(*,*)
'==========================================================='
64 write(*,*)
' ./average_fields_in_time fluid_stats00.fld 103.2 ' // &
67 write(*,*)
' Computes the average field over the fld files ' // &
69 write(*,*)
' in fluid_stats00.nek5000. The files need to be arranged'
70 write(*,*)
' in chronological order. The average field is then '
71 write(*,*)
' stored in a fld series, i.e. mean0.nek5000 and'
72 write(*,*)
' mean0.f00000'
75 write(*,*)
' ./average_fields_in_time ' // &
76 'stats0.csv 103.2 mean_field_avg.csv'
78 write(*,*)
' Computes the average field over the csv file'
79 write(*,*)
' stats0.csv and writes it in mean_field_avg.csv'
90 character(len=NEKO_FNAME_LEN),
intent(in) :: fld_fname, output_fname
91 real(kind=rp),
intent(in) :: start_time
93 type(file_t) ::
fld_file, output_file
94 type(fld_file_data_t) :: fld_data, fld_data_avg
95 character(len=LOG_SIZE) :: log_buf
101 call fld_data_avg%init()
105 write (log_buf,
'(A, g0)')
"dt: ", fld_data_avg%time - start_time
106 call neko_log%message(log_buf)
108 call fld_data_avg%scale(fld_data_avg%time-start_time)
110 do i = 1, fld_data_avg%meta_nsamples-1
112 call fld_data%scale(fld_data%time-fld_data_avg%time)
113 call fld_data_avg%add(fld_data)
115 write (log_buf,
'(A, g0)')
"dt: ", fld_data%time - fld_data_avg%time
116 call neko_log%message(log_buf)
118 fld_data_avg%time = fld_data%time
120 call fld_data_avg%scale(1.0_rp/(fld_data_avg%time-start_time))
122 call output_file%init(trim(output_fname))
124 call neko_log%message(
'Writing file: ' // trim(output_fname))
125 call output_file%write(fld_data_avg, fld_data_avg%time)
126 call neko_log%message(
'Done')
129 call fld_data_avg%free()
150 character(len=NEKO_FNAME_LEN),
intent(in) :: in_fname, out_fname
151 real(kind=rp),
intent(in) :: start_time
153 type(file_t) :: out_file
154 type(matrix_t) :: data, avg_data
155 character(len=LOG_SIZE) :: log_buf
156 integer :: sample_size, n_samples
158 if (pe_rank .eq. 0)
then
166 if (mod(data%get_nrows(), sample_size) .ne. 0)
then
167 write(log_buf,*)
"# of rows in csv file : ", data%get_nrows()
168 call neko_log%message(log_buf)
169 write(log_buf,*)
"Size of each sample : ", sample_size
170 call neko_log%message(log_buf)
172 call neko_error(
"The # of rows in the file must be a multiple" // &
173 " of the size of each sample.")
176 n_samples = data%get_nrows() / sample_size
177 write (log_buf,
'(A,I0)')
"Size of each sample: ", sample_size
178 call neko_log%message(log_buf)
179 write (log_buf,
'(A,I0)')
"Number of samples : ", n_samples
180 call neko_log%message(log_buf)
183 call avg_data%init(sample_size, data%get_ncols())
187 real(kind=rp) :: dt, ta, tb
192 write (log_buf,
'(A,I0,A,I0,A,g0)')
"Length of sample ", 1,
"/", &
194 call neko_log%message(log_buf)
197 avg_data%x(:,1:) = dt*data%x(1:sample_size, :)
199 do i = 1, n_samples-1
201 ta = data%x(sample_size*(i-1) + 1, 1)
202 tb = data%x(sample_size* i + 1, 1)
205 write (log_buf,
'(A,I0,A,I0,A,g0)')
"Length of sample ", i+1,
"/", &
207 call neko_log%message(log_buf)
209 avg_data%x = avg_data%x + &
210 dt * data%x(sample_size*i + 1:sample_size * (i+1), :)
214 avg_data%x = avg_data%x / (data%x(data%get_nrows(), 1) - start_time)
217 avg_data%x(:,1) = data%x(data%get_nrows(), 1)
220 avg_data%x(:, 2) = data%x(1:sample_size, 2)
225 call out_file%init(trim(out_fname))
226 call out_file%set_overwrite(.true.)
227 call out_file%write(avg_data)
228 call file_free(out_file)
239 type(matrix_t),
intent(in) :: m
243 if (m%get_nrows() .le. 1)
then
250 do while ( abscmp(m%x(n,1), m%x(n+1,1)) )
252 if (n+1 > m%get_nrows()) &
253 call neko_error(
"Out of bounds while searching for sampling size!")
261 character(len=*),
intent(in) :: file_name
262 type(matrix_t),
intent(inout) :: m
265 integer :: unit, i, ierr, num_columns, num_lines, ios
266 character(len=1000) :: line
267 character(len=1) :: delimiter
268 character(len=LOG_SIZE) :: log_buf
274 open(newunit = unit,
file = trim(file_name), status =
'old', &
275 action =
'read', iostat = ios)
277 call neko_error(
"Error opening file " // trim(file_name))
285 read(unit,
'(A)', iostat = ios) line
289 if (num_lines .eq. 0)
then
292 do i = 1, len_trim(line)
293 if (line(i:i) == delimiter)
then
294 num_columns = num_columns + 1
300 num_lines = num_lines + 1
306 write (log_buf,
'(A,A,A,I0,A,I0,A)')
"Size of ", trim(file_name), &
307 " : ", num_lines,
" rows, ", num_columns,
" columns"
308 call neko_log%message(log_buf)
313 call m%init(num_lines, num_columns)
316 call f%init(trim(file_name))
subroutine avg_flds_in_time_fld(fld_fname, output_fname, start_time)
Average fields from a series of fld files.
subroutine populate_matrix(file_name, m)
Read a csv file, determine the # of rows and columns, allocate the matrix accordingly and populate th...
subroutine avg_flds_in_time_csv(in_fname, out_fname, start_time)
Average fields from a series of csv files.
integer function determine_size_of_csv_sample(m)
Finds the size of a statistics sample based on when the time stamp changes.
program average_fields_in_time
Program to sum up averaged fields computed for statistics and mean field Martin Karp 27/01-23.
Module for file I/O operations.