61#include "../base/base_uses.f90"
66 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
67 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cp_output_handling'
117 LOGICAL,
PRIVATE,
SAVE :: enable_mpi_io = .false.
144 print_level, each_iter_names, each_iter_values, add_last, filename, &
145 common_iter_levels, citations, unit_str, do_backup)
147 CHARACTER(len=*),
INTENT(IN) :: location, name, description
148 INTEGER,
INTENT(IN),
OPTIONAL :: print_level
149 CHARACTER(LEN=*),
DIMENSION(:),
INTENT(IN), &
150 OPTIONAL :: each_iter_names
151 INTEGER,
DIMENSION(:),
INTENT(IN),
OPTIONAL :: each_iter_values
152 INTEGER,
INTENT(IN),
OPTIONAL :: add_last
153 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: filename
154 INTEGER,
INTENT(IN),
OPTIONAL :: common_iter_levels
155 INTEGER,
DIMENSION(:),
OPTIONAL :: citations
156 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: unit_str
157 LOGICAL,
OPTIONAL :: do_backup
159 CHARACTER(len=default_path_length) :: my_filename
160 INTEGER :: i_each, i_iter, my_add_last, &
161 my_comm_iter_levels, my_print_level, &
163 LOGICAL :: check, ext_each, my_do_backup
167 cpassert(.NOT.
ASSOCIATED(print_key_section))
169 IF (
PRESENT(print_level)) my_print_level = print_level
170 my_do_backup = .false.
171 IF (
PRESENT(do_backup)) my_do_backup = do_backup
173 CALL section_create(print_key_section, location=location, name=name, description=description, &
174 n_keywords=2, n_subsections=0, repeats=.false., &
177 NULLIFY (keyword, subsection)
178 CALL keyword_create(keyword, __location__, name=
"_SECTION_PARAMETERS_", &
179 description=
"Level starting at which this property is printed. "// &
180 "Printing is activated when the GLOBAL/PRINT_LEVEL of a task is "// &
181 "higher than or equal to the level as specified here; to override "// &
182 "this comparison, use ON to always print or OFF to never print. "// &
183 "Explicitly giving the section without a level or ON or OFF is "// &
184 "treated as if SILENT is specified, whereas omitting the section "// &
185 "is treated implicitly using the default value.", &
188 enum_c_vals=
s2a(
"on",
"off",
"silent",
"low",
"medium",
"high",
"debug"), &
195 CALL keyword_create(keyword, __location__, name=
"__CONTROL_VAL", &
196 description=
' hidden parameter that controls storage, printing,...'// &
197 ' of the print_key', &
203 description=
"This section specifies how often this property is printed. "// &
204 "Each keyword inside this section is mapping to a specific iteration level and "// &
205 "the value of each of these keywords is matched with the iteration level during "// &
206 "the calculation. A value of 0 or negative turns off printing for the iteration "// &
207 "level. How to handle the last iteration is treated separately in the ADD_LAST "// &
208 "keyword outside of this section; each iteration level might print the last "// &
209 "iteration even if the corresponding value is set to 0 or negative. "// &
210 "If an iteration level is specified that is not present in the flow of "// &
211 "the calculation, it is just ignored; switch GLOBAL/ITER_LEVEL_VERBOSITY "// &
212 "to NOTICE or STACK to print information about existing iteration levels.", &
213 n_keywords=2, n_subsections=0, repeats=.false., &
217 check = (
PRESENT(each_iter_names)) .EQV. (
PRESENT(each_iter_values))
219 ext_each = (
PRESENT(each_iter_names)) .AND. (
PRESENT(each_iter_values))
226 DO i_iter = 1,
SIZE(each_iter_names)
228 my_value = each_iter_values(i_iter)
235 default_i_val=my_value)
243 IF (
PRESENT(add_last))
THEN
244 my_add_last = add_last
247 description=
"If the last iteration should be added, and if it "// &
248 "should be marked symbolically (with lowercase letter l) or with "// &
249 "the iteration number. "// &
250 "Not every iteration level is able to identify the last iteration "// &
251 "early enough to be able to output. When this keyword is activated "// &
252 "all iteration levels are checked for the last iteration step.", &
253 usage=
"ADD_LAST (NO|NUMERIC|SYMBOLIC)", &
254 enum_c_vals=
s2a(
"no",
"numeric",
"symbolic"), &
256 enum_desc=
s2a(
"Do not mark last iteration specifically", &
257 "Mark last iteration with its iteration number", &
258 "Mark last iteration with lowercase letter l"), &
259 default_i_val=my_add_last)
263 my_comm_iter_levels = 0
264 IF (
PRESENT(common_iter_levels)) my_comm_iter_levels = common_iter_levels
265 CALL keyword_create(keyword, __location__, name=
"COMMON_ITERATION_LEVELS", &
266 description=
"How many iteration levels should be written "// &
267 "in the same file (no extra information about the actual "// &
268 "iteration level is written to the file). Set to 0 to use "// &
269 "the current iteration level, 1 to use the next level, ..., "// &
270 "in the stack of iteration levels (printed by setting the "// &
271 "GLOBAL/ITER_LEVEL_VERBOSITY to STACK).", &
272 usage=
"COMMON_ITERATION_LEVELS <INTEGER>", &
273 default_i_val=my_comm_iter_levels)
278 IF (
PRESENT(filename)) my_filename = filename
280 description=
"Controls part of the filename for output."//
newline//
newline// &
281 "* Use `__STD_OUT__` (exactly as written here) for the screen or "// &
282 "standard logger (stdout)."//
newline// &
283 "* Use `filename` to obtain `projectname-filename` with "// &
284 "`projectname` defined by &GLOBAL/PROJECT_NAME."//
newline// &
285 "* Use `./filename` to get a filename with a middle name (if present), "// &
286 "iteration numbers and extension always added to the filename."//
newline// &
287 "* Use `=filename` to get `filename` always exactly as typed, but "// &
288 "please note that this can lead to clashes of filenames.", &
289 usage=
"FILENAME ./filename ", &
290 default_lc_val=my_filename)
294 CALL keyword_create(keyword, __location__, name=
"LOG_PRINT_KEY", &
295 description=
"This keywords enables the logger for the print_key (a message is printed on "// &
296 "screen everytime data, controlled by this print_key, are written)", &
297 usage=
"LOG_PRINT_KEY <LOGICAL>", default_l_val=.false., lone_keyword_l_val=.true.)
301 IF (
PRESENT(unit_str))
THEN
303 description=
'Specify the unit of measurement for the quantity in output. '// &
304 "All available CP2K units can be used.", &
305 usage=
"UNIT angstrom", default_c_val=trim(unit_str))
310 IF (my_do_backup)
THEN
311 CALL keyword_create(keyword, __location__, name=
"BACKUP_COPIES", &
312 description=
"Specifies the maximum number of backup copies preserved "// &
313 "when iterations will repeatedly print to the same filename. If set to "// &
314 "N > 0, the files will be automatically rotated by appending a suffix: "// &
315 "the most recent print is `{filename}` (defined by FILENAME keyword), "// &
316 "the last one is moved to `{filename}.bak-1`, the second to last moved "// &
317 "to `{filename}.bak-2`, ..., up to `{filename}.bak-N`. Set to 0 to "// &
318 "disable backup preservation and rewrite always the same `{filename}`.", &
319 usage=
"BACKUP_COPIES {int}", default_i_val=1)
343 print_key_path, used_print_key, first_time) &
347 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: print_key_path
349 POINTER :: used_print_key
350 LOGICAL,
INTENT(OUT),
OPTIONAL :: first_time
353 INTEGER :: end_str, my_control_val, to_path
354 LOGICAL :: flags, is_iter, is_on
358 IF (
PRESENT(first_time)) first_time = .false.
359 cpassert(basis_section%ref_count > 0)
360 IF (
PRESENT(used_print_key))
NULLIFY (used_print_key)
362 IF (
PRESENT(print_key_path))
THEN
363 end_str = len_trim(print_key_path)
364 to_path = index(print_key_path,
"/")
365 IF (to_path < 1)
THEN
366 to_path = end_str + 1
369 IF (to_path > 1)
THEN
371 print_key_path(1:(to_path - 1)))
373 print_key => basis_section
375 cpassert(
ASSOCIATED(print_key))
376 cpassert(print_key%ref_count > 0)
377 IF (to_path + 1 < end_str)
THEN
384 print_key => basis_section
387 IF (
PRESENT(used_print_key)) used_print_key => print_key
389 IF (.NOT. flags)
RETURN
392 i_val=my_control_val)
398 is_iter = cp_printkey_is_iter(iteration_info, print_key, first_time=first_time)
402 ELSE IF (btest(my_control_val,
cp_p_store_if) .AND. is_iter .AND. is_on)
THEN
408 IF (btest(my_control_val,
cp_p_file))
THEN
410 ELSE IF (btest(my_control_val,
cp_p_file_if) .AND. is_iter .AND. is_on)
THEN
412 ELSE IF (btest(my_control_val,
cp_p_file_each) .AND. is_iter)
THEN
415 IF (btest(my_control_val,
cp_p_calc) .OR. res /= 0)
THEN
433 INTEGER :: print_level
435 cpassert(iteration_info%ref_count > 0)
436 IF (.NOT.
ASSOCIATED(print_key))
THEN
439 cpassert(print_key%ref_count > 0)
441 res = iteration_info%print_level >= print_level
456 FUNCTION cp_printkey_is_iter(iteration_info, print_key, first_time) &
460 LOGICAL,
INTENT(OUT),
OPTIONAL :: first_time
463 INTEGER :: add_last, ilevel, iter_nr, ival
464 LOGICAL :: first, level_passed
466 cpassert(iteration_info%ref_count > 0)
467 IF (.NOT.
ASSOCIATED(print_key))
THEN
469 first = all(iteration_info%iteration(1:iteration_info%n_rlevel) == 1)
471 cpassert(print_key%ref_count > 0)
477 DO ilevel = 1, iteration_info%n_rlevel
478 level_passed = .false.
482 iter_nr = iteration_info%iteration(ilevel)
483 IF (iter_nr/ival > 1) first = .false.
484 IF (
modulo(iter_nr, ival) == 0)
THEN
485 level_passed = .true.
489 IF (iteration_info%last_iter(ilevel))
THEN
490 level_passed = .true.
493 IF (.NOT. level_passed) res = .false.
496 first = first .AND. res
497 IF (
PRESENT(first_time)) first_time = first
498 END FUNCTION cp_printkey_is_iter
519 LOGICAL,
INTENT(IN),
OPTIONAL :: for_file
520 CHARACTER(len=default_string_length) :: res
522 INTEGER :: add_last, c_i_level, ilevel, n_rlevel, &
524 LOGICAL :: my_for_file
528 my_for_file = .false.
529 IF (
PRESENT(for_file)) my_for_file = for_file
530 cpassert(
ASSOCIATED(iter_info))
531 cpassert(iter_info%ref_count > 0)
532 NULLIFY (my_print_key)
533 IF (
PRESENT(print_key)) my_print_key => print_key
535 IF (
ASSOCIATED(my_print_key))
THEN
538 n_rlevel = iter_info%n_rlevel
539 IF (my_for_file) n_rlevel = min(n_rlevel, max(0, n_rlevel - c_i_level))
540 DO ilevel = s_level, n_rlevel
541 IF (iter_info%last_iter(ilevel))
THEN
543 WRITE (res(9*ilevel - 8:9*ilevel),
"('l_')")
545 WRITE (res(9*ilevel - 8:9*ilevel),
"(i8,'_')") iter_info%iteration(ilevel)
548 WRITE (res(9*ilevel - 8:9*ilevel),
"(i8,'_')") iter_info%iteration(ilevel)
552 DO ilevel = s_level, iter_info%n_rlevel
553 WRITE (res(9*ilevel - 8:9*ilevel),
"(i8,'_')") iter_info%iteration(ilevel)
557 IF (len_trim(res) > 0)
THEN
558 res(len_trim(res):len_trim(res)) =
" "
573 SUBROUTINE cp_iterate(iteration_info, last, iter_nr, increment, iter_nr_out)
575 LOGICAL,
INTENT(IN),
OPTIONAL :: last
576 INTEGER,
INTENT(IN),
OPTIONAL :: iter_nr, increment
577 INTEGER,
INTENT(OUT),
OPTIONAL :: iter_nr_out
579 INTEGER :: my_increment
584 IF (
PRESENT(last)) my_last = last
585 IF (
PRESENT(increment)) my_increment = increment
586 IF (
PRESENT(iter_nr_out)) iter_nr_out = -1
588 cpassert(
ASSOCIATED(iteration_info))
589 cpassert(iteration_info%ref_count > 0)
590 IF (
PRESENT(iter_nr))
THEN
591 iteration_info%iteration(iteration_info%n_rlevel) = iter_nr
593 iteration_info%iteration(iteration_info%n_rlevel) = &
594 iteration_info%iteration(iteration_info%n_rlevel) + my_increment
597 IF (
PRESENT(iter_nr_out)) iter_nr_out = iteration_info%iteration(iteration_info%n_rlevel)
600 iteration_info%last_iter(iteration_info%n_rlevel) = my_last
612 CHARACTER(LEN=*),
INTENT(IN) :: level_name
615 cpassert(
ASSOCIATED(iteration_info))
616 cpassert(iteration_info%ref_count > 0)
617 DO rlevel = iteration_info%n_rlevel, 1, -1
618 IF (iteration_info%level_name(rlevel) == level_name)
EXIT
634 INTEGER,
INTENT(IN),
OPTIONAL :: rlevel
635 INTEGER,
INTENT(OUT),
OPTIONAL :: iter_nr
636 LOGICAL,
INTENT(OUT),
OPTIONAL :: last_iter
640 cpassert(
ASSOCIATED(iteration_info))
641 cpassert(iteration_info%ref_count > 0)
642 IF (
PRESENT(rlevel))
THEN
643 cpassert(rlevel > 0 .AND. rlevel <= iteration_info%n_rlevel)
646 ilevel = iteration_info%n_rlevel
649 IF (
PRESENT(iter_nr)) iter_nr = iteration_info%iteration(ilevel)
650 IF (
PRESENT(last_iter)) last_iter = iteration_info%last_iter(ilevel)
663 CHARACTER(LEN=*),
INTENT(IN) :: level_name
664 INTEGER,
INTENT(OUT),
OPTIONAL :: n_rlevel_new
670 cpassert(
ASSOCIATED(logger))
671 iteration_info => logger%iter_info
672 cpassert(
ASSOCIATED(iteration_info))
673 cpassert(iteration_info%ref_count > 0)
683 iteration_info%n_rlevel = iteration_info%n_rlevel + 1
684 CALL reallocate(iteration_info%iteration, 1, iteration_info%n_rlevel)
685 CALL reallocate(iteration_info%level_name, 1, iteration_info%n_rlevel)
686 CALL reallocate(iteration_info%last_iter, 1, iteration_info%n_rlevel)
687 iteration_info%iteration(iteration_info%n_rlevel) = 0
688 iteration_info%level_name(iteration_info%n_rlevel) = level_name
689 iteration_info%last_iter(iteration_info%n_rlevel) = .false.
690 IF (
PRESENT(n_rlevel_new)) n_rlevel_new = iteration_info%n_rlevel
691 CALL cp_iter_level_print(logger,
"A")
693 CALL cp_abort(__location__, &
694 "Trying to create an iteration level ("//trim(level_name)//
") not defined. "// &
695 "Please update the module: cp_iter_types.")
710 CHARACTER(LEN=*),
INTENT(IN) :: level_name
711 INTEGER,
INTENT(IN),
OPTIONAL :: n_rlevel_att
716 cpassert(
ASSOCIATED(logger))
717 iteration_info => logger%iter_info
718 cpassert(
ASSOCIATED(iteration_info))
719 cpassert(iteration_info%ref_count > 0)
720 IF (
PRESENT(n_rlevel_att))
THEN
721 cpassert(n_rlevel_att == iteration_info%n_rlevel)
723 CALL cp_iter_level_print(logger,
"R")
727 check = iteration_info%level_name(iteration_info%n_rlevel) == level_name
729 iteration_info%n_rlevel = iteration_info%n_rlevel - 1
730 CALL reallocate(iteration_info%iteration, 1, iteration_info%n_rlevel)
731 CALL reallocate(iteration_info%level_name, 1, iteration_info%n_rlevel)
732 CALL reallocate(iteration_info%last_iter, 1, iteration_info%n_rlevel)
742 SUBROUTINE cp_iter_level_print(logger, direction, local)
744 CHARACTER(LEN=1),
INTENT(IN) :: direction
745 LOGICAL,
INTENT(IN),
OPTIONAL :: local
747 INTEGER,
PARAMETER :: min_iter_level = 2
749 CHARACTER(LEN=:),
ALLOCATABLE :: level_name
750 INTEGER :: iter_nr, rlevel, unit_nr
760 iteration_info => logger%iter_info
762 IF (
PRESENT(local)) my_local = local
763 IF (my_local .OR. logger%para_env%is_source())
THEN
765 rlevel = iteration_info%n_rlevel
767 level_name = trim(adjustl(iteration_info%level_name(rlevel)))
771 IF (unit_nr > 0)
THEN
772 WRITE (unit=unit_nr, fmt=
"()")
774 SELECT CASE (direction)
776 WRITE (unit=unit_nr, fmt=
"(T2,A,T37,I3,T41,A,T73,I8)") &
777 "ITER_LV| >>>>>>>> Entering level +", rlevel,
"[ "//level_name//
" ]", iter_nr
779 WRITE (unit=unit_nr, fmt=
"(T2,A,T37,I3,T41,A,T73,I8)") &
780 "ITER_LV| <<<<<<<< Exiting level -", rlevel,
"[ "//level_name//
" ]", iter_nr
782 CALL cp_abort(__location__, &
783 "Only entering (A) or exiting (R) an iteration level "// &
784 "can have a message printed.")
788 DO WHILE (rlevel > min_iter_level)
790 level_name = trim(adjustl(iteration_info%level_name(rlevel)))
792 WRITE (unit=unit_nr, fmt=
"(T2,A,T37,I3,T41,A,T73,I8)") &
793 "ITER_LV| *", rlevel,
"[ "//level_name//
" ]", iter_nr
796 WRITE (unit=unit_nr, fmt=
"()")
800 CALL cp_warn(__location__, &
801 "An iteration level has been added to or removed from a logger "// &
802 "that does not receive the GLOBAL%ITER_LEVEL_VERBOSITY setting.")
806 END SUBROUTINE cp_iter_level_print
834 my_local)
RESULT(filename)
837 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: middle_name
838 CHARACTER(len=*),
INTENT(IN) :: extension
839 LOGICAL,
INTENT(IN) :: my_local
840 CHARACTER(len=default_path_length) :: filename
842 CHARACTER(len=default_path_length) :: outname, outpath, postfix, root
843 CHARACTER(len=default_string_length) :: my_middle_name
844 INTEGER :: my_ind1, my_ind2
848 IF (outpath(1:1) ==
'=')
THEN
849 cpassert(len(outpath) - 1 <= len(filename))
850 filename = outpath(2:)
853 IF (outpath ==
"__STD_OUT__") outpath =
""
856 my_ind1 = index(outpath,
"/")
857 my_ind2 = len_trim(outpath)
858 IF (my_ind1 /= 0)
THEN
860 DO WHILE (index(outpath(my_ind1 + 1:my_ind2),
"/") /= 0)
861 my_ind1 = index(outpath(my_ind1 + 1:my_ind2),
"/") + my_ind1
863 IF (my_ind1 == my_ind2)
THEN
866 outname = outpath(my_ind1 + 1:my_ind2)
870 IF (
PRESENT(middle_name))
THEN
871 IF (outname /=
"")
THEN
872 my_middle_name =
"-"//trim(outname)//
"-"//middle_name
874 my_middle_name =
"-"//middle_name
877 IF (outname /=
"")
THEN
878 my_middle_name =
"-"//trim(outname)
884 IF (.NOT. has_root)
THEN
885 root = trim(logger%iter_info%project_name)//trim(my_middle_name)
886 ELSE IF (outname ==
"")
THEN
887 root = outpath(1:my_ind1)//trim(logger%iter_info%project_name)//trim(my_middle_name)
889 root = outpath(1:my_ind1)//my_middle_name(2:len_trim(my_middle_name))
893 postfix =
"-"//trim(
cp_iter_string(logger%iter_info, print_key=print_key, for_file=.true.))
894 IF (trim(postfix) ==
"-") postfix =
""
897 postfix = trim(postfix)//extension
900 root=root, postfix=postfix, local=my_local)
932 middle_name, local, log_filename, ignore_should_output, file_form, file_position, &
933 file_action, file_status, do_backup, on_file, is_new_file, mpi_io, &
934 fout, file_access)
RESULT(res)
937 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: print_key_path
938 CHARACTER(len=*),
INTENT(IN) :: extension
939 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: middle_name
940 LOGICAL,
INTENT(IN),
OPTIONAL :: local, log_filename, ignore_should_output
941 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: file_form, file_position, file_action, &
943 LOGICAL,
INTENT(IN),
OPTIONAL :: do_backup, on_file
944 LOGICAL,
INTENT(OUT),
OPTIONAL :: is_new_file
945 LOGICAL,
INTENT(INOUT),
OPTIONAL :: mpi_io
946 CHARACTER(len=default_path_length),
INTENT(OUT), &
948 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: file_access
951 CHARACTER(len=default_path_length) :: filename, filename_bak, filename_bak_1, &
953 CHARACTER(len=default_string_length) :: my_file_action, my_file_form, &
954 my_file_position, my_file_status, &
956 INTEGER :: c_i_level, f_backup_level, i, mpi_amode, &
957 my_backup_level, my_nbak, nbak, &
958 s_backup_level, unit_nr
959 LOGICAL :: do_log, found, my_do_backup, my_local, &
960 my_mpi_io, my_on_file, &
961 my_should_output, replace
967 my_do_backup = .false.
972 my_file_form =
"FORMATTED"
973 my_file_position =
"APPEND"
974 my_file_action =
"WRITE"
975 my_file_status =
"UNKNOWN"
978 IF (
PRESENT(file_form)) my_file_form = file_form
979 IF (
PRESENT(file_position)) my_file_position = file_position
980 IF (
PRESENT(file_action)) my_file_action = file_action
981 IF (
PRESENT(file_status)) my_file_status = file_status
982 IF (
PRESENT(do_backup)) my_do_backup = do_backup
983 IF (
PRESENT(on_file)) my_on_file = on_file
984 IF (
PRESENT(local)) my_local = local
985 IF (
PRESENT(is_new_file)) is_new_file = .false.
986 IF (
PRESENT(mpi_io))
THEN
987#if defined(__parallel)
988 IF (
cp_mpi_io_get() .AND. logger%para_env%num_pe > 1 .AND. mpi_io)
THEN
995 trim(my_file_action), trim(my_file_status), trim(my_file_position))
996 replace = replace .AND. logger%para_env%is_source()
1005 cpassert(
ASSOCIATED(logger))
1006 cpassert(basis_section%ref_count > 0)
1007 cpassert(logger%ref_count > 0)
1009 basis_section, print_key_path, used_print_key=print_key),
cp_p_file)
1010 IF (
PRESENT(ignore_should_output)) my_should_output = my_should_output .OR. ignore_should_output
1011 IF (.NOT. my_should_output)
RETURN
1013 logger%para_env%is_source() .OR. &
1017 IF (outpath ==
'__STD_OUT__' .AND. .NOT. my_on_file)
THEN
1029 IF (
PRESENT(is_new_file))
THEN
1030 INQUIRE (file=filename, exist=found)
1031 is_new_file = .NOT. found
1032 IF (my_file_position ==
"REWIND") is_new_file = .true.
1036 IF (
PRESENT(log_filename))
THEN
1037 do_log = log_filename
1042 IF (my_do_backup)
THEN
1043 INQUIRE (file=filename, exist=found)
1046 iteration_info => logger%iter_info
1048 IF (
ASSOCIATED(print_key%ibackup)) s_backup_level =
SIZE(print_key%ibackup)
1050 my_backup_level = max(1, iteration_info%n_rlevel - c_i_level + 1)
1051 f_backup_level = max(s_backup_level, my_backup_level)
1052 IF (f_backup_level > s_backup_level)
THEN
1053 CALL reallocate(print_key%ibackup, 1, f_backup_level)
1054 DO i = s_backup_level + 1, f_backup_level
1055 print_key%ibackup(i) = 0
1059 print_key%ibackup(my_backup_level) = print_key%ibackup(my_backup_level) + 1
1060 my_nbak = print_key%ibackup(my_backup_level)
1062 DO i = min(nbak, my_nbak), 2, -1
1063 filename_bak_1 = trim(filename)//
".bak-"//adjustl(
cp_to_string(i))
1064 filename_bak_2 = trim(filename)//
".bak-"//adjustl(
cp_to_string(i - 1))
1067 IF (unit_nr > 0)
THEN
1068 WRITE (unit_nr, *)
"Moving file "//trim(filename_bak_2)// &
1069 " into file "//trim(filename_bak_1)//
"."
1072 INQUIRE (file=filename_bak_2, exist=found)
1073 IF (.NOT. found)
THEN
1076 IF (unit_nr > 0)
THEN
1077 WRITE (unit_nr, *)
"File "//trim(filename_bak_2)//
" not existing.."
1083 IF (my_local .OR. logger%para_env%is_source())
THEN
1084 CALL m_mov(trim(filename_bak_2), trim(filename_bak_1))
1089 filename_bak = trim(filename)//
".bak-"//adjustl(
cp_to_string(1))
1092 IF (unit_nr > 0)
THEN
1093 WRITE (unit_nr, *)
"Moving file "//trim(filename)//
" into file "//trim(filename_bak)//
"."
1096 IF (my_local .OR. logger%para_env%is_source())
THEN
1097 CALL m_mov(trim(filename), trim(filename_bak))
1101 print_key%ibackup(my_backup_level) = 0
1106 IF (.NOT. my_mpi_io)
THEN
1107 CALL open_file(file_name=filename, file_status=my_file_status, &
1108 file_form=my_file_form, file_action=my_file_action, &
1109 file_position=my_file_position, file_access=file_access, unit_number=res)
1112 CALL mp_unit%open(groupid=logger%para_env, &
1113 filepath=filename, amode_status=mpi_amode)
1114 IF (
PRESENT(fout)) fout = filename
1115 res = mp_unit%get_handle()
1119 IF (unit_nr > 0)
THEN
1120 WRITE (unit_nr, *)
"Writing "//trim(print_key%section%name)//
" "// &
1154 print_key_path, local, ignore_should_output, on_file, &
1156 INTEGER,
INTENT(INOUT) :: unit_nr
1159 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: print_key_path
1160 LOGICAL,
INTENT(IN),
OPTIONAL :: local, ignore_should_output, on_file, &
1163 CHARACTER(len=default_string_length) :: outpath
1164 LOGICAL :: my_local, my_mpi_io, my_on_file, &
1170 my_on_file = .false.
1173 IF (
PRESENT(local)) my_local = local
1174 IF (
PRESENT(on_file)) my_on_file = on_file
1175 IF (
PRESENT(mpi_io)) my_mpi_io = mpi_io
1176 cpassert(
ASSOCIATED(logger))
1177 cpassert(basis_section%ref_count > 0)
1178 cpassert(logger%ref_count > 0)
1180 print_key_path, used_print_key=print_key),
cp_p_file)
1181 IF (
PRESENT(ignore_should_output)) my_should_output = my_should_output .OR. ignore_should_output
1182 IF (my_should_output .AND. (my_local .OR. &
1183 logger%para_env%is_source() .OR. &
1186 IF (my_on_file .OR. outpath /=
'__STD_OUT__')
THEN
1187 cpassert(unit_nr > 0)
1188 IF (.NOT. my_mpi_io)
THEN
1191 CALL mp_unit%set_handle(unit_nr)
1192 CALL mp_unit%close()
1199 cpassert(unit_nr == -1)
1211 LOGICAL,
INTENT(IN) :: flag
1213 enable_mpi_io = flag
1226 flag = enable_mpi_io
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Utility routines to open and close files.
subroutine, public open_file(file_name, unit_number, file_status, file_form, file_action, file_position, file_pad, file_access, debug)
Opens a file and returns its logical unit number.
subroutine, public close_file(unit_number, file_status)
Closes an open file given by its logical unit number.
Collection of routines to handle the iteration info.
integer, parameter, public iter_silent
character(len=default_path_length), dimension(19), parameter, public each_possible_labels
subroutine, public cp_iteration_info_retain(iteration_info)
retains the iteration_info (see doc/ReferenceCounting.html)
subroutine, public cp_iteration_info_release(iteration_info)
releases the iteration_info (see doc/ReferenceCounting.html)
character(len=default_path_length), dimension(19), parameter, public each_desc_labels
integer, parameter, public iter_notice
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
integer function, public cp_logger_get_unit_nr(logger, local)
returns the unit nr for the requested kind of log.
subroutine, public cp_logger_generate_filename(logger, res, root, postfix, local)
generates a unique filename (ie adding eventual suffixes and process ids)
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, parameter, public cp_out_calc
subroutine, public cp_print_key_section_create(print_key_section, location, name, description, print_level, each_iter_names, each_iter_values, add_last, filename, common_iter_levels, citations, unit_str, do_backup)
creates a print_key section
integer, parameter, public cp_out_file_each
integer, parameter, public cp_p_store_each
subroutine, public cp_add_iter_level(logger, level_name, n_rlevel_new)
Adds an iteration level.
character(len=default_string_length) function, public cp_iter_string(iter_info, print_key, for_file)
returns the iteration string, a string that is useful to create unique filenames (once you trim it)
subroutine, public cp_mpi_io_set(flag)
Sets flag which determines whether or not to use MPI I/O for I/O routines that have been parallized w...
integer, parameter, public cp_out_default
integer, parameter, public cp_out_store_if
integer, parameter, public debug_print_level
integer, parameter, public cp_out_store_each
integer, parameter, public cp_p_calc
integer, parameter, public cp_p_store_if
integer, parameter, public cp_out_file_if
integer, parameter, public cp_out_store
integer, parameter, public low_print_level
integer, parameter, public medium_print_level
character(len=default_path_length) function, public cp_print_key_generate_filename(logger, print_key, middle_name, extension, my_local)
Utility function that returns a unit number to write the print key. Might open a file with a unique f...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer, parameter, public cp_out_none
integer, parameter, public high_print_level
logical function, public cp_mpi_io_get()
Gets flag which determines whether or not to use MPI I/O for I/O routines that have been parallized w...
logical function, public cp_printkey_is_on(iteration_info, print_key)
returns true if the printlevel activates this printkey does not look if this iteration it should be p...
subroutine, public cp_iterate(iteration_info, last, iter_nr, increment, iter_nr_out)
adds one to the actual iteration
integer, parameter, public add_last_symbolic
integer, parameter, public cp_p_file_if
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
integer, parameter, public add_last_numeric
integer, parameter, public silent_print_level
subroutine, public cp_rm_iter_level(logger, level_name, n_rlevel_att)
Removes an iteration level.
integer function, public cp_get_iter_level_by_name(iteration_info, level_name)
Return the index of an iteration level by its name.
integer, parameter, public cp_out_file
integer, parameter, public cp_p_file_each
integer, parameter, public cp_p_store
integer, parameter, public add_last_no
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout, file_access)
...
subroutine, public cp_get_iter_nr(iteration_info, rlevel, iter_nr, last_iter)
Return the current iteration number at a given level.
Defines the basic variable types.
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Machine interface based on Fortran 2003 and POSIX.
subroutine, public m_mov(source, target)
...
Utility routines for the memory handling.
Interface to the message passing library MPI.
subroutine, public mp_file_delete(filepath, info)
Deletes a file. Auxiliary routine to emulate 'replace' action for mp_file_open. Only the master proce...
subroutine, public mp_file_get_amode(mpi_io, replace, amode, form, action, status, position)
(parallel) Utility routine to determine MPI file access mode based on variables
Utilities for string manipulations.
subroutine, public compress(string, full)
Eliminate multiple space characters in a string. If full is .TRUE., then all spaces are eliminated.
character(len=1), parameter, public newline
contains the information about the current state of the program to be able to decide if output is nec...
type of a logger, at the moment it contains just a print level starting at which level it should be l...