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", &
182 enum_c_vals=
s2a(
"on",
"off",
"silent",
"low",
"medium",
"high",
"debug"), &
189 CALL keyword_create(keyword, __location__, name=
"__CONTROL_VAL", &
190 description=
' hidden parameter that controls storage, printing,...'// &
191 ' of the print_key', &
197 description=
"This section specifies how often this property is printed. "// &
198 "Each keyword inside this section is mapping to a specific iteration level and "// &
199 "the value of each of these keywords is matched with the iteration level during "// &
200 "the calculation. How to handle the last iteration is treated "// &
201 "separately in ADD_LAST (this mean that each iteration level (MD, GEO_OPT, etc..), "// &
202 "though equal to 0, might print the last iteration). If an iteration level is specified "// &
203 "that is not present in the flow of the calculation it is just ignored.", &
204 n_keywords=2, n_subsections=0, repeats=.false., &
208 check = (
PRESENT(each_iter_names)) .EQV. (
PRESENT(each_iter_values))
210 ext_each = (
PRESENT(each_iter_names)) .AND. (
PRESENT(each_iter_values))
217 DO i_iter = 1,
SIZE(each_iter_names)
219 my_value = each_iter_values(i_iter)
226 default_i_val=my_value)
234 IF (
PRESENT(add_last))
THEN
235 my_add_last = add_last
238 description=
"If the last iteration should be added, and if it "// &
239 "should be marked symbolically (with lowercase letter l) or with "// &
240 "the iteration number. "// &
241 "Not every iteration level is able to identify the last iteration "// &
242 "early enough to be able to output. When this keyword is activated "// &
243 "all iteration levels are checked for the last iteration step.", &
244 usage=
"ADD_LAST (NO|NUMERIC|SYMBOLIC)", &
245 enum_c_vals=
s2a(
"no",
"numeric",
"symbolic"), &
247 enum_desc=
s2a(
"Do not mark last iteration specifically", &
248 "Mark last iteration with its iteration number", &
249 "Mark last iteration with lowercase letter l"), &
250 default_i_val=my_add_last)
254 my_comm_iter_levels = 0
255 IF (
PRESENT(common_iter_levels)) my_comm_iter_levels = common_iter_levels
256 CALL keyword_create(keyword, __location__, name=
"COMMON_ITERATION_LEVELS", &
257 description=
"How many iterations levels should be written"// &
258 " in the same file (no extra information about the actual"// &
259 " iteration level is written to the file)", &
260 usage=
"COMMON_ITERATION_LEVELS <INTEGER>", &
261 default_i_val=my_comm_iter_levels)
266 IF (
PRESENT(filename)) my_filename = filename
268 description=
"Controls part of the filename for output."//
newline//
newline// &
269 "* Use `__STD_OUT__` (exactly as written here) for the screen or "// &
270 "standard logger (stdout)."//
newline// &
271 "* Use `filename` to obtain `projectname-filename` with "// &
272 "`projectname` defined by &GLOBAL/PROJECT_NAME."//
newline// &
273 "* Use `./filename` to get a filename with a middle name (if present), "// &
274 "iteration numbers and extension always added to the filename."//
newline// &
275 "* Use `=filename` to get `filename` always exactly as typed, but "// &
276 "please note that this can lead to clashes of filenames.", &
277 usage=
"FILENAME ./filename ", &
278 default_lc_val=my_filename)
282 CALL keyword_create(keyword, __location__, name=
"LOG_PRINT_KEY", &
283 description=
"This keywords enables the logger for the print_key (a message is printed on "// &
284 "screen everytime data, controlled by this print_key, are written)", &
285 usage=
"LOG_PRINT_KEY <LOGICAL>", default_l_val=.false., lone_keyword_l_val=.true.)
289 IF (
PRESENT(unit_str))
THEN
291 description=
'Specify the unit of measurement for the quantity in output. '// &
292 "All available CP2K units can be used.", &
293 usage=
"UNIT angstrom", default_c_val=trim(unit_str))
298 IF (my_do_backup)
THEN
299 CALL keyword_create(keyword, __location__, name=
"BACKUP_COPIES", &
300 description=
"Specifies the maximum number of backup copies preserved "// &
301 "when iterations will repeatedly print to the same filename. If set to "// &
302 "N > 0, the files will be automatically rotated by appending a suffix: "// &
303 "the most recent print is `{filename}` (defined by FILENAME keyword), "// &
304 "the last one is moved to `{filename}.bak-1`, the second to last moved "// &
305 "to `{filename}.bak-2`, ..., up to `{filename}.bak-N`. Set to 0 to "// &
306 "disable backup preservation and rewrite always the same `{filename}`.", &
307 usage=
"BACKUP_COPIES {int}", default_i_val=1)
331 print_key_path, used_print_key, first_time) &
335 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: print_key_path
337 POINTER :: used_print_key
338 LOGICAL,
INTENT(OUT),
OPTIONAL :: first_time
341 INTEGER :: end_str, my_control_val, to_path
342 LOGICAL :: flags, is_iter, is_on
346 IF (
PRESENT(first_time)) first_time = .false.
347 cpassert(basis_section%ref_count > 0)
348 IF (
PRESENT(used_print_key))
NULLIFY (used_print_key)
350 IF (
PRESENT(print_key_path))
THEN
351 end_str = len_trim(print_key_path)
352 to_path = index(print_key_path,
"/")
353 IF (to_path < 1)
THEN
354 to_path = end_str + 1
357 IF (to_path > 1)
THEN
359 print_key_path(1:(to_path - 1)))
361 print_key => basis_section
363 cpassert(
ASSOCIATED(print_key))
364 cpassert(print_key%ref_count > 0)
365 IF (to_path + 1 < end_str)
THEN
372 print_key => basis_section
375 IF (
PRESENT(used_print_key)) used_print_key => print_key
377 IF (.NOT. flags)
RETURN
380 i_val=my_control_val)
386 is_iter = cp_printkey_is_iter(iteration_info, print_key, first_time=first_time)
390 ELSE IF (btest(my_control_val,
cp_p_store_if) .AND. is_iter .AND. is_on)
THEN
396 IF (btest(my_control_val,
cp_p_file))
THEN
398 ELSE IF (btest(my_control_val,
cp_p_file_if) .AND. is_iter .AND. is_on)
THEN
400 ELSE IF (btest(my_control_val,
cp_p_file_each) .AND. is_iter)
THEN
403 IF (btest(my_control_val,
cp_p_calc) .OR. res /= 0)
THEN
421 INTEGER :: print_level
423 cpassert(iteration_info%ref_count > 0)
424 IF (.NOT.
ASSOCIATED(print_key))
THEN
427 cpassert(print_key%ref_count > 0)
429 res = iteration_info%print_level >= print_level
444 FUNCTION cp_printkey_is_iter(iteration_info, print_key, first_time) &
448 LOGICAL,
INTENT(OUT),
OPTIONAL :: first_time
451 INTEGER :: add_last, ilevel, iter_nr, ival
452 LOGICAL :: first, level_passed
454 cpassert(iteration_info%ref_count > 0)
455 IF (.NOT.
ASSOCIATED(print_key))
THEN
457 first = all(iteration_info%iteration(1:iteration_info%n_rlevel) == 1)
459 cpassert(print_key%ref_count > 0)
465 DO ilevel = 1, iteration_info%n_rlevel
466 level_passed = .false.
470 iter_nr = iteration_info%iteration(ilevel)
471 IF (iter_nr/ival > 1) first = .false.
472 IF (
modulo(iter_nr, ival) == 0)
THEN
473 level_passed = .true.
477 IF (iteration_info%last_iter(ilevel))
THEN
478 level_passed = .true.
481 IF (.NOT. level_passed) res = .false.
484 first = first .AND. res
485 IF (
PRESENT(first_time)) first_time = first
486 END FUNCTION cp_printkey_is_iter
507 LOGICAL,
INTENT(IN),
OPTIONAL :: for_file
508 CHARACTER(len=default_string_length) :: res
510 INTEGER :: add_last, c_i_level, ilevel, n_rlevel, &
512 LOGICAL :: my_for_file
516 my_for_file = .false.
517 IF (
PRESENT(for_file)) my_for_file = for_file
518 cpassert(
ASSOCIATED(iter_info))
519 cpassert(iter_info%ref_count > 0)
520 NULLIFY (my_print_key)
521 IF (
PRESENT(print_key)) my_print_key => print_key
523 IF (
ASSOCIATED(my_print_key))
THEN
526 n_rlevel = iter_info%n_rlevel
527 IF (my_for_file) n_rlevel = min(n_rlevel, max(0, n_rlevel - c_i_level))
528 DO ilevel = s_level, n_rlevel
529 IF (iter_info%last_iter(ilevel))
THEN
531 WRITE (res(9*ilevel - 8:9*ilevel),
"('l_')")
533 WRITE (res(9*ilevel - 8:9*ilevel),
"(i8,'_')") iter_info%iteration(ilevel)
536 WRITE (res(9*ilevel - 8:9*ilevel),
"(i8,'_')") iter_info%iteration(ilevel)
540 DO ilevel = s_level, iter_info%n_rlevel
541 WRITE (res(9*ilevel - 8:9*ilevel),
"(i8,'_')") iter_info%iteration(ilevel)
545 IF (len_trim(res) > 0)
THEN
546 res(len_trim(res):len_trim(res)) =
" "
561 SUBROUTINE cp_iterate(iteration_info, last, iter_nr, increment, iter_nr_out)
563 LOGICAL,
INTENT(IN),
OPTIONAL :: last
564 INTEGER,
INTENT(IN),
OPTIONAL :: iter_nr, increment
565 INTEGER,
INTENT(OUT),
OPTIONAL :: iter_nr_out
567 INTEGER :: my_increment
572 IF (
PRESENT(last)) my_last = last
573 IF (
PRESENT(increment)) my_increment = increment
574 IF (
PRESENT(iter_nr_out)) iter_nr_out = -1
576 cpassert(
ASSOCIATED(iteration_info))
577 cpassert(iteration_info%ref_count > 0)
578 IF (
PRESENT(iter_nr))
THEN
579 iteration_info%iteration(iteration_info%n_rlevel) = iter_nr
581 iteration_info%iteration(iteration_info%n_rlevel) = &
582 iteration_info%iteration(iteration_info%n_rlevel) + my_increment
585 IF (
PRESENT(iter_nr_out)) iter_nr_out = iteration_info%iteration(iteration_info%n_rlevel)
588 iteration_info%last_iter(iteration_info%n_rlevel) = my_last
600 CHARACTER(LEN=*),
INTENT(IN) :: level_name
603 cpassert(
ASSOCIATED(iteration_info))
604 cpassert(iteration_info%ref_count > 0)
605 DO rlevel = iteration_info%n_rlevel, 1, -1
606 IF (iteration_info%level_name(rlevel) == level_name)
EXIT
622 INTEGER,
INTENT(IN),
OPTIONAL :: rlevel
623 INTEGER,
INTENT(OUT),
OPTIONAL :: iter_nr
624 LOGICAL,
INTENT(OUT),
OPTIONAL :: last_iter
628 cpassert(
ASSOCIATED(iteration_info))
629 cpassert(iteration_info%ref_count > 0)
630 IF (
PRESENT(rlevel))
THEN
631 cpassert(rlevel > 0 .AND. rlevel <= iteration_info%n_rlevel)
634 ilevel = iteration_info%n_rlevel
637 IF (
PRESENT(iter_nr)) iter_nr = iteration_info%iteration(ilevel)
638 IF (
PRESENT(last_iter)) last_iter = iteration_info%last_iter(ilevel)
651 CHARACTER(LEN=*),
INTENT(IN) :: level_name
652 INTEGER,
INTENT(OUT),
OPTIONAL :: n_rlevel_new
658 cpassert(
ASSOCIATED(logger))
659 iteration_info => logger%iter_info
660 cpassert(
ASSOCIATED(iteration_info))
661 cpassert(iteration_info%ref_count > 0)
671 iteration_info%n_rlevel = iteration_info%n_rlevel + 1
672 CALL reallocate(iteration_info%iteration, 1, iteration_info%n_rlevel)
673 CALL reallocate(iteration_info%level_name, 1, iteration_info%n_rlevel)
674 CALL reallocate(iteration_info%last_iter, 1, iteration_info%n_rlevel)
675 iteration_info%iteration(iteration_info%n_rlevel) = 0
676 iteration_info%level_name(iteration_info%n_rlevel) = level_name
677 iteration_info%last_iter(iteration_info%n_rlevel) = .false.
678 IF (
PRESENT(n_rlevel_new)) n_rlevel_new = iteration_info%n_rlevel
679 CALL cp_iter_level_print(logger,
"A")
681 CALL cp_abort(__location__, &
682 "Trying to create an iteration level ("//trim(level_name)//
") not defined. "// &
683 "Please update the module: cp_iter_types.")
698 CHARACTER(LEN=*),
INTENT(IN) :: level_name
699 INTEGER,
INTENT(IN),
OPTIONAL :: n_rlevel_att
704 cpassert(
ASSOCIATED(logger))
705 iteration_info => logger%iter_info
706 cpassert(
ASSOCIATED(iteration_info))
707 cpassert(iteration_info%ref_count > 0)
708 IF (
PRESENT(n_rlevel_att))
THEN
709 cpassert(n_rlevel_att == iteration_info%n_rlevel)
711 CALL cp_iter_level_print(logger,
"R")
715 check = iteration_info%level_name(iteration_info%n_rlevel) == level_name
717 iteration_info%n_rlevel = iteration_info%n_rlevel - 1
718 CALL reallocate(iteration_info%iteration, 1, iteration_info%n_rlevel)
719 CALL reallocate(iteration_info%level_name, 1, iteration_info%n_rlevel)
720 CALL reallocate(iteration_info%last_iter, 1, iteration_info%n_rlevel)
730 SUBROUTINE cp_iter_level_print(logger, direction, local)
732 CHARACTER(LEN=1),
INTENT(IN) :: direction
733 LOGICAL,
INTENT(IN),
OPTIONAL :: local
735 INTEGER,
PARAMETER :: min_iter_level = 2
737 CHARACTER(LEN=:),
ALLOCATABLE :: level_name
738 INTEGER :: iter_nr, rlevel, unit_nr
748 iteration_info => logger%iter_info
750 IF (
PRESENT(local)) my_local = local
751 IF (my_local .OR. logger%para_env%is_source())
THEN
753 rlevel = iteration_info%n_rlevel
755 level_name = trim(adjustl(iteration_info%level_name(rlevel)))
759 IF (unit_nr > 0)
THEN
760 WRITE (unit=unit_nr, fmt=
"()")
762 SELECT CASE (direction)
764 WRITE (unit=unit_nr, fmt=
"(T2,A,T37,I3,T41,A,T73,I8)") &
765 "ITER_LV| >>>>>>>> Entering level +", rlevel,
"[ "//level_name//
" ]", iter_nr
767 WRITE (unit=unit_nr, fmt=
"(T2,A,T37,I3,T41,A,T73,I8)") &
768 "ITER_LV| <<<<<<<< Exiting level -", rlevel,
"[ "//level_name//
" ]", iter_nr
770 CALL cp_abort(__location__, &
771 "Only entering (A) or exiting (R) an iteration level "// &
772 "can have a message printed.")
776 DO WHILE (rlevel > min_iter_level)
778 level_name = trim(adjustl(iteration_info%level_name(rlevel)))
780 WRITE (unit=unit_nr, fmt=
"(T2,A,T37,I3,T41,A,T73,I8)") &
781 "ITER_LV| *", rlevel,
"[ "//level_name//
" ]", iter_nr
784 WRITE (unit=unit_nr, fmt=
"()")
788 CALL cp_warn(__location__, &
789 "An iteration level has been added to or removed from a logger "// &
790 "that does not receive the GLOBAL%ITER_LEVEL_VERBOSITY setting.")
794 END SUBROUTINE cp_iter_level_print
822 my_local)
RESULT(filename)
825 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: middle_name
826 CHARACTER(len=*),
INTENT(IN) :: extension
827 LOGICAL,
INTENT(IN) :: my_local
828 CHARACTER(len=default_path_length) :: filename
830 CHARACTER(len=default_path_length) :: outname, outpath, postfix, root
831 CHARACTER(len=default_string_length) :: my_middle_name
832 INTEGER :: my_ind1, my_ind2
836 IF (outpath(1:1) ==
'=')
THEN
837 cpassert(len(outpath) - 1 <= len(filename))
838 filename = outpath(2:)
841 IF (outpath ==
"__STD_OUT__") outpath =
""
844 my_ind1 = index(outpath,
"/")
845 my_ind2 = len_trim(outpath)
846 IF (my_ind1 /= 0)
THEN
848 DO WHILE (index(outpath(my_ind1 + 1:my_ind2),
"/") /= 0)
849 my_ind1 = index(outpath(my_ind1 + 1:my_ind2),
"/") + my_ind1
851 IF (my_ind1 == my_ind2)
THEN
854 outname = outpath(my_ind1 + 1:my_ind2)
858 IF (
PRESENT(middle_name))
THEN
859 IF (outname /=
"")
THEN
860 my_middle_name =
"-"//trim(outname)//
"-"//middle_name
862 my_middle_name =
"-"//middle_name
865 IF (outname /=
"")
THEN
866 my_middle_name =
"-"//trim(outname)
872 IF (.NOT. has_root)
THEN
873 root = trim(logger%iter_info%project_name)//trim(my_middle_name)
874 ELSE IF (outname ==
"")
THEN
875 root = outpath(1:my_ind1)//trim(logger%iter_info%project_name)//trim(my_middle_name)
877 root = outpath(1:my_ind1)//my_middle_name(2:len_trim(my_middle_name))
881 postfix =
"-"//trim(
cp_iter_string(logger%iter_info, print_key=print_key, for_file=.true.))
882 IF (trim(postfix) ==
"-") postfix =
""
885 postfix = trim(postfix)//extension
888 root=root, postfix=postfix, local=my_local)
920 middle_name, local, log_filename, ignore_should_output, file_form, file_position, &
921 file_action, file_status, do_backup, on_file, is_new_file, mpi_io, &
922 fout, file_access)
RESULT(res)
925 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: print_key_path
926 CHARACTER(len=*),
INTENT(IN) :: extension
927 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: middle_name
928 LOGICAL,
INTENT(IN),
OPTIONAL :: local, log_filename, ignore_should_output
929 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: file_form, file_position, file_action, &
931 LOGICAL,
INTENT(IN),
OPTIONAL :: do_backup, on_file
932 LOGICAL,
INTENT(OUT),
OPTIONAL :: is_new_file
933 LOGICAL,
INTENT(INOUT),
OPTIONAL :: mpi_io
934 CHARACTER(len=default_path_length),
INTENT(OUT), &
936 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: file_access
939 CHARACTER(len=default_path_length) :: filename, filename_bak, filename_bak_1, &
941 CHARACTER(len=default_string_length) :: my_file_action, my_file_form, &
942 my_file_position, my_file_status, &
944 INTEGER :: c_i_level, f_backup_level, i, mpi_amode, &
945 my_backup_level, my_nbak, nbak, &
946 s_backup_level, unit_nr
947 LOGICAL :: do_log, found, my_do_backup, my_local, &
948 my_mpi_io, my_on_file, &
949 my_should_output, replace
955 my_do_backup = .false.
960 my_file_form =
"FORMATTED"
961 my_file_position =
"APPEND"
962 my_file_action =
"WRITE"
963 my_file_status =
"UNKNOWN"
966 IF (
PRESENT(file_form)) my_file_form = file_form
967 IF (
PRESENT(file_position)) my_file_position = file_position
968 IF (
PRESENT(file_action)) my_file_action = file_action
969 IF (
PRESENT(file_status)) my_file_status = file_status
970 IF (
PRESENT(do_backup)) my_do_backup = do_backup
971 IF (
PRESENT(on_file)) my_on_file = on_file
972 IF (
PRESENT(local)) my_local = local
973 IF (
PRESENT(is_new_file)) is_new_file = .false.
974 IF (
PRESENT(mpi_io))
THEN
975#if defined(__parallel)
976 IF (
cp_mpi_io_get() .AND. logger%para_env%num_pe > 1 .AND. mpi_io)
THEN
983 trim(my_file_action), trim(my_file_status), trim(my_file_position))
984 replace = replace .AND. logger%para_env%is_source()
993 cpassert(
ASSOCIATED(logger))
994 cpassert(basis_section%ref_count > 0)
995 cpassert(logger%ref_count > 0)
997 basis_section, print_key_path, used_print_key=print_key),
cp_p_file)
998 IF (
PRESENT(ignore_should_output)) my_should_output = my_should_output .OR. ignore_should_output
999 IF (.NOT. my_should_output)
RETURN
1001 logger%para_env%is_source() .OR. &
1005 IF (outpath ==
'__STD_OUT__' .AND. .NOT. my_on_file)
THEN
1017 IF (
PRESENT(is_new_file))
THEN
1018 INQUIRE (file=filename, exist=found)
1019 is_new_file = .NOT. found
1020 IF (my_file_position ==
"REWIND") is_new_file = .true.
1024 IF (
PRESENT(log_filename))
THEN
1025 do_log = log_filename
1030 IF (my_do_backup)
THEN
1031 INQUIRE (file=filename, exist=found)
1034 iteration_info => logger%iter_info
1036 IF (
ASSOCIATED(print_key%ibackup)) s_backup_level =
SIZE(print_key%ibackup)
1038 my_backup_level = max(1, iteration_info%n_rlevel - c_i_level + 1)
1039 f_backup_level = max(s_backup_level, my_backup_level)
1040 IF (f_backup_level > s_backup_level)
THEN
1041 CALL reallocate(print_key%ibackup, 1, f_backup_level)
1042 DO i = s_backup_level + 1, f_backup_level
1043 print_key%ibackup(i) = 0
1047 print_key%ibackup(my_backup_level) = print_key%ibackup(my_backup_level) + 1
1048 my_nbak = print_key%ibackup(my_backup_level)
1050 DO i = min(nbak, my_nbak), 2, -1
1051 filename_bak_1 = trim(filename)//
".bak-"//adjustl(
cp_to_string(i))
1052 filename_bak_2 = trim(filename)//
".bak-"//adjustl(
cp_to_string(i - 1))
1055 IF (unit_nr > 0)
THEN
1056 WRITE (unit_nr, *)
"Moving file "//trim(filename_bak_2)// &
1057 " into file "//trim(filename_bak_1)//
"."
1060 INQUIRE (file=filename_bak_2, exist=found)
1061 IF (.NOT. found)
THEN
1064 IF (unit_nr > 0)
THEN
1065 WRITE (unit_nr, *)
"File "//trim(filename_bak_2)//
" not existing.."
1071 IF (my_local .OR. logger%para_env%is_source())
THEN
1072 CALL m_mov(trim(filename_bak_2), trim(filename_bak_1))
1077 filename_bak = trim(filename)//
".bak-"//adjustl(
cp_to_string(1))
1080 IF (unit_nr > 0)
THEN
1081 WRITE (unit_nr, *)
"Moving file "//trim(filename)//
" into file "//trim(filename_bak)//
"."
1084 IF (my_local .OR. logger%para_env%is_source())
THEN
1085 CALL m_mov(trim(filename), trim(filename_bak))
1089 print_key%ibackup(my_backup_level) = 0
1094 IF (.NOT. my_mpi_io)
THEN
1095 CALL open_file(file_name=filename, file_status=my_file_status, &
1096 file_form=my_file_form, file_action=my_file_action, &
1097 file_position=my_file_position, file_access=file_access, unit_number=res)
1100 CALL mp_unit%open(groupid=logger%para_env, &
1101 filepath=filename, amode_status=mpi_amode)
1102 IF (
PRESENT(fout)) fout = filename
1103 res = mp_unit%get_handle()
1107 IF (unit_nr > 0)
THEN
1108 WRITE (unit_nr, *)
"Writing "//trim(print_key%section%name)//
" "// &
1142 print_key_path, local, ignore_should_output, on_file, &
1144 INTEGER,
INTENT(INOUT) :: unit_nr
1147 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: print_key_path
1148 LOGICAL,
INTENT(IN),
OPTIONAL :: local, ignore_should_output, on_file, &
1151 CHARACTER(len=default_string_length) :: outpath
1152 LOGICAL :: my_local, my_mpi_io, my_on_file, &
1158 my_on_file = .false.
1161 IF (
PRESENT(local)) my_local = local
1162 IF (
PRESENT(on_file)) my_on_file = on_file
1163 IF (
PRESENT(mpi_io)) my_mpi_io = mpi_io
1164 cpassert(
ASSOCIATED(logger))
1165 cpassert(basis_section%ref_count > 0)
1166 cpassert(logger%ref_count > 0)
1168 print_key_path, used_print_key=print_key),
cp_p_file)
1169 IF (
PRESENT(ignore_should_output)) my_should_output = my_should_output .OR. ignore_should_output
1170 IF (my_should_output .AND. (my_local .OR. &
1171 logger%para_env%is_source() .OR. &
1174 IF (my_on_file .OR. outpath /=
'__STD_OUT__')
THEN
1175 cpassert(unit_nr > 0)
1176 IF (.NOT. my_mpi_io)
THEN
1179 CALL mp_unit%set_handle(unit_nr)
1180 CALL mp_unit%close()
1187 cpassert(unit_nr == -1)
1199 LOGICAL,
INTENT(IN) :: flag
1201 enable_mpi_io = flag
1214 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...