24#include "../base/base_uses.f90"
28 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
29 CHARACTER(len=*),
PRIVATE,
PARAMETER :: moduleN =
'cp_array_utils'
100 REAL(kind=
dp),
dimension(:),
pointer :: array => null()
110 REAL(kind=
dp),
dimension(:, :),
pointer :: array => null()
120 REAL(kind=
dp),
dimension(:, :, :),
pointer :: array => null()
130 REAL(kind=
dp),
dimension(:),
contiguous,
pointer :: array => null()
140 REAL(kind=
dp),
dimension(:, :),
contiguous,
pointer :: array => null()
150 REAL(kind=
dp),
dimension(:, :, :),
contiguous,
pointer :: array => null()
161 COMPLEX(KIND=dp),
dimension(:),
pointer :: array => null()
171 COMPLEX(KIND=dp),
dimension(:, :),
pointer :: array => null()
181 COMPLEX(KIND=dp),
dimension(:, :, :),
pointer :: array => null()
191 COMPLEX(KIND=dp),
dimension(:),
contiguous,
pointer :: array => null()
201 COMPLEX(KIND=dp),
dimension(:, :),
contiguous,
pointer :: array => null()
211 COMPLEX(KIND=dp),
dimension(:, :, :),
contiguous,
pointer :: array => null()
222 INTEGER(kind=int_4),
dimension(:),
pointer :: array => null()
232 INTEGER(kind=int_4),
dimension(:, :),
pointer :: array => null()
242 INTEGER(kind=int_4),
dimension(:, :, :),
pointer :: array => null()
252 INTEGER(kind=int_4),
dimension(:),
contiguous,
pointer :: array => null()
262 INTEGER(kind=int_4),
dimension(:, :),
contiguous,
pointer :: array => null()
272 INTEGER(kind=int_4),
dimension(:, :, :),
contiguous,
pointer :: array => null()
283 logical,
dimension(:),
pointer :: array => null()
293 logical,
dimension(:, :),
pointer :: array => null()
303 logical,
dimension(:, :, :),
pointer :: array => null()
313 logical,
dimension(:),
contiguous,
pointer :: array => null()
323 logical,
dimension(:, :),
contiguous,
pointer :: array => null()
333 logical,
dimension(:, :, :),
contiguous,
pointer :: array => null()
351 REAL(kind=
dp),
INTENT(in) :: array(:)
352 INTEGER,
INTENT(in) :: unit_nr
353 CHARACTER(len=*),
INTENT(in),
OPTIONAL :: el_format
356 CHARACTER(len=*),
PARAMETER :: defaultformat =
"(es14.6)"
358 WRITE (unit=unit_nr, fmt=
"('( ')", advance=
"no", iostat=iostat)
359 cpassert(iostat == 0)
360 IF (
PRESENT(el_format))
THEN
361 DO i = 1,
SIZE(array) - 1
362 WRITE (unit=unit_nr, fmt=el_format, advance=
"no") array(i)
363 IF (mod(i, 5) == 0)
THEN
364 WRITE (unit=unit_nr, fmt=
"(',')")
366 WRITE (unit=unit_nr, fmt=
"(',')", advance=
"no")
369 IF (
SIZE(array) > 0)
THEN
370 WRITE (unit=unit_nr, fmt=el_format, advance=
"no") array(
SIZE(array))
373 DO i = 1,
SIZE(array) - 1
374 WRITE (unit=unit_nr, fmt=defaultformat, advance=
"no") array(i)
375 IF (mod(i, 5) == 0)
THEN
376 WRITE (unit=unit_nr, fmt=
"(',')")
378 WRITE (unit=unit_nr, fmt=
"(',')", advance=
"no")
381 IF (
SIZE(array) > 0)
THEN
382 WRITE (unit=unit_nr, fmt=defaultformat, advance=
"no") array(
SIZE(array))
385 WRITE (unit=unit_nr, fmt=
"(' )')")
402 REAL(kind=
dp),
INTENT(in) :: array(:, :)
403 INTEGER,
INTENT(in) :: unit_nr
404 CHARACTER(len=*),
INTENT(in),
OPTIONAL :: el_format
407 CHARACTER(len=*),
PARAMETER :: defaultformat =
"(es14.6)"
408 CHARACTER(len=200) :: fmtstr
409 CHARACTER(len=25) :: nriga
412 DO i = 1,
SIZE(array, 1)
413 IF (
PRESENT(el_format))
THEN
414 fmtstr =
'(" ",'//nriga//el_format//
')'
415 WRITE (unit=unit_nr, fmt=fmtstr, iostat=iostat) array(i, :)
417 fmtstr =
'(" ",'//nriga//defaultformat//
')'
418 WRITE (unit=unit_nr, fmt=fmtstr, iostat=iostat) array(i, :)
420 cpassert(iostat == 0)
443 REAL(kind=
dp),
POINTER :: array(:)
444 INTEGER,
INTENT(in) :: n
447 IF (
ASSOCIATED(array))
THEN
448 IF (
SIZE(array) /= n)
THEN
449 cpwarn(
'size has changed')
453 IF (.NOT.
ASSOCIATED(array))
THEN
476 REAL(kind=
dp),
POINTER :: array(:, :)
477 INTEGER,
INTENT(in) :: n_rows, n_cols
479 cpassert(n_cols >= 0)
480 cpassert(n_rows >= 0)
481 IF (
ASSOCIATED(array))
THEN
482 IF (
SIZE(array, 1) /= n_rows .OR.
SIZE(array, 2) /= n_cols)
THEN
483 cpwarn(
'size has changed')
487 IF (.NOT.
ASSOCIATED(array))
THEN
488 ALLOCATE (array(n_rows, n_cols))
509 REAL(kind=
dp),
intent(in) :: array(:)
510 REAL(kind=
dp),
intent(in) :: el
511 INTEGER,
INTENT(in),
OPTIONAL :: l_index, u_index
514 INTEGER :: lindex, uindex, aindex
518 if (
present(l_index)) lindex = l_index
519 if (
present(u_index)) uindex = u_index
520 DO WHILE (lindex <= uindex)
521 aindex = (lindex + uindex)/2
522 IF ( array(aindex) < el)
THEN
542 COMPLEX(KIND=dp),
INTENT(in) :: array(:)
543 INTEGER,
INTENT(in) :: unit_nr
544 CHARACTER(len=*),
INTENT(in),
OPTIONAL :: el_format
547 CHARACTER(len=*),
PARAMETER :: defaultformat =
"(es14.6)"
549 WRITE (unit=unit_nr, fmt=
"('( ')", advance=
"no", iostat=iostat)
550 cpassert(iostat == 0)
551 IF (
PRESENT(el_format))
THEN
552 DO i = 1,
SIZE(array) - 1
553 WRITE (unit=unit_nr, fmt=el_format, advance=
"no") array(i)
554 IF (mod(i, 5) == 0)
THEN
555 WRITE (unit=unit_nr, fmt=
"(',')")
557 WRITE (unit=unit_nr, fmt=
"(',')", advance=
"no")
560 IF (
SIZE(array) > 0)
THEN
561 WRITE (unit=unit_nr, fmt=el_format, advance=
"no") array(
SIZE(array))
564 DO i = 1,
SIZE(array) - 1
565 WRITE (unit=unit_nr, fmt=defaultformat, advance=
"no") array(i)
566 IF (mod(i, 5) == 0)
THEN
567 WRITE (unit=unit_nr, fmt=
"(',')")
569 WRITE (unit=unit_nr, fmt=
"(',')", advance=
"no")
572 IF (
SIZE(array) > 0)
THEN
573 WRITE (unit=unit_nr, fmt=defaultformat, advance=
"no") array(
SIZE(array))
576 WRITE (unit=unit_nr, fmt=
"(' )')")
593 COMPLEX(KIND=dp),
INTENT(in) :: array(:, :)
594 INTEGER,
INTENT(in) :: unit_nr
595 CHARACTER(len=*),
INTENT(in),
OPTIONAL :: el_format
598 CHARACTER(len=*),
PARAMETER :: defaultformat =
"(es14.6)"
599 CHARACTER(len=200) :: fmtstr
600 CHARACTER(len=25) :: nriga
603 DO i = 1,
SIZE(array, 1)
604 IF (
PRESENT(el_format))
THEN
605 fmtstr =
'(" ",'//nriga//el_format//
')'
606 WRITE (unit=unit_nr, fmt=fmtstr, iostat=iostat) array(i, :)
608 fmtstr =
'(" ",'//nriga//defaultformat//
')'
609 WRITE (unit=unit_nr, fmt=fmtstr, iostat=iostat) array(i, :)
611 cpassert(iostat == 0)
634 COMPLEX(KIND=dp),
POINTER :: array(:)
635 INTEGER,
INTENT(in) :: n
638 IF (
ASSOCIATED(array))
THEN
639 IF (
SIZE(array) /= n)
THEN
640 cpwarn(
'size has changed')
644 IF (.NOT.
ASSOCIATED(array))
THEN
667 COMPLEX(KIND=dp),
POINTER :: array(:, :)
668 INTEGER,
INTENT(in) :: n_rows, n_cols
670 cpassert(n_cols >= 0)
671 cpassert(n_rows >= 0)
672 IF (
ASSOCIATED(array))
THEN
673 IF (
SIZE(array, 1) /= n_rows .OR.
SIZE(array, 2) /= n_cols)
THEN
674 cpwarn(
'size has changed')
678 IF (.NOT.
ASSOCIATED(array))
THEN
679 ALLOCATE (array(n_rows, n_cols))
700 COMPLEX(KIND=dp),
intent(in) :: array(:)
701 COMPLEX(KIND=dp),
intent(in) :: el
702 INTEGER,
INTENT(in),
OPTIONAL :: l_index, u_index
705 INTEGER :: lindex, uindex, aindex
709 if (
present(l_index)) lindex = l_index
710 if (
present(u_index)) uindex = u_index
711 DO WHILE (lindex <= uindex)
712 aindex = (lindex + uindex)/2
713 IF (real(array(aindex)) < real(el) .OR. (abs(real(array(aindex))-real(el)) < epsilon(max(abs(real(array(aindex))),&
714 & abs(real(el)))) .and. aimag(array(aindex)) < aimag(el)))
THEN
734 INTEGER(kind=int_4),
INTENT(in) :: array(:)
735 INTEGER,
INTENT(in) :: unit_nr
736 CHARACTER(len=*),
INTENT(in),
OPTIONAL :: el_format
739 CHARACTER(len=*),
PARAMETER :: defaultformat =
"(i6)"
741 WRITE (unit=unit_nr, fmt=
"('( ')", advance=
"no", iostat=iostat)
742 cpassert(iostat == 0)
743 IF (
PRESENT(el_format))
THEN
744 DO i = 1,
SIZE(array) - 1
745 WRITE (unit=unit_nr, fmt=el_format, advance=
"no") array(i)
746 IF (mod(i, 5) == 0)
THEN
747 WRITE (unit=unit_nr, fmt=
"(',')")
749 WRITE (unit=unit_nr, fmt=
"(',')", advance=
"no")
752 IF (
SIZE(array) > 0)
THEN
753 WRITE (unit=unit_nr, fmt=el_format, advance=
"no") array(
SIZE(array))
756 DO i = 1,
SIZE(array) - 1
757 WRITE (unit=unit_nr, fmt=defaultformat, advance=
"no") array(i)
758 IF (mod(i, 5) == 0)
THEN
759 WRITE (unit=unit_nr, fmt=
"(',')")
761 WRITE (unit=unit_nr, fmt=
"(',')", advance=
"no")
764 IF (
SIZE(array) > 0)
THEN
765 WRITE (unit=unit_nr, fmt=defaultformat, advance=
"no") array(
SIZE(array))
768 WRITE (unit=unit_nr, fmt=
"(' )')")
785 INTEGER(kind=int_4),
INTENT(in) :: array(:, :)
786 INTEGER,
INTENT(in) :: unit_nr
787 CHARACTER(len=*),
INTENT(in),
OPTIONAL :: el_format
790 CHARACTER(len=*),
PARAMETER :: defaultformat =
"(i6)"
791 CHARACTER(len=200) :: fmtstr
792 CHARACTER(len=25) :: nriga
795 DO i = 1,
SIZE(array, 1)
796 IF (
PRESENT(el_format))
THEN
797 fmtstr =
'(" ",'//nriga//el_format//
')'
798 WRITE (unit=unit_nr, fmt=fmtstr, iostat=iostat) array(i, :)
800 fmtstr =
'(" ",'//nriga//defaultformat//
')'
801 WRITE (unit=unit_nr, fmt=fmtstr, iostat=iostat) array(i, :)
803 cpassert(iostat == 0)
826 INTEGER(kind=int_4),
POINTER :: array(:)
827 INTEGER,
INTENT(in) :: n
830 IF (
ASSOCIATED(array))
THEN
831 IF (
SIZE(array) /= n)
THEN
832 cpwarn(
'size has changed')
836 IF (.NOT.
ASSOCIATED(array))
THEN
859 INTEGER(kind=int_4),
POINTER :: array(:, :)
860 INTEGER,
INTENT(in) :: n_rows, n_cols
862 cpassert(n_cols >= 0)
863 cpassert(n_rows >= 0)
864 IF (
ASSOCIATED(array))
THEN
865 IF (
SIZE(array, 1) /= n_rows .OR.
SIZE(array, 2) /= n_cols)
THEN
866 cpwarn(
'size has changed')
870 IF (.NOT.
ASSOCIATED(array))
THEN
871 ALLOCATE (array(n_rows, n_cols))
892 INTEGER(kind=int_4),
intent(in) :: array(:)
893 INTEGER(kind=int_4),
intent(in) :: el
894 INTEGER,
INTENT(in),
OPTIONAL :: l_index, u_index
897 INTEGER :: lindex, uindex, aindex
901 if (
present(l_index)) lindex = l_index
902 if (
present(u_index)) uindex = u_index
903 DO WHILE (lindex <= uindex)
904 aindex = (lindex + uindex)/2
905 IF ( array(aindex) < el)
THEN
925 logical,
INTENT(in) :: array(:)
926 INTEGER,
INTENT(in) :: unit_nr
927 CHARACTER(len=*),
INTENT(in),
OPTIONAL :: el_format
930 CHARACTER(len=*),
PARAMETER :: defaultformat =
"(l1)"
932 WRITE (unit=unit_nr, fmt=
"('( ')", advance=
"no", iostat=iostat)
933 cpassert(iostat == 0)
934 IF (
PRESENT(el_format))
THEN
935 DO i = 1,
SIZE(array) - 1
936 WRITE (unit=unit_nr, fmt=el_format, advance=
"no") array(i)
937 IF (mod(i, 5) == 0)
THEN
938 WRITE (unit=unit_nr, fmt=
"(',')")
940 WRITE (unit=unit_nr, fmt=
"(',')", advance=
"no")
943 IF (
SIZE(array) > 0)
THEN
944 WRITE (unit=unit_nr, fmt=el_format, advance=
"no") array(
SIZE(array))
947 DO i = 1,
SIZE(array) - 1
948 WRITE (unit=unit_nr, fmt=defaultformat, advance=
"no") array(i)
949 IF (mod(i, 5) == 0)
THEN
950 WRITE (unit=unit_nr, fmt=
"(',')")
952 WRITE (unit=unit_nr, fmt=
"(',')", advance=
"no")
955 IF (
SIZE(array) > 0)
THEN
956 WRITE (unit=unit_nr, fmt=defaultformat, advance=
"no") array(
SIZE(array))
959 WRITE (unit=unit_nr, fmt=
"(' )')")
976 logical,
INTENT(in) :: array(:, :)
977 INTEGER,
INTENT(in) :: unit_nr
978 CHARACTER(len=*),
INTENT(in),
OPTIONAL :: el_format
981 CHARACTER(len=*),
PARAMETER :: defaultformat =
"(l1)"
982 CHARACTER(len=200) :: fmtstr
983 CHARACTER(len=25) :: nriga
986 DO i = 1,
SIZE(array, 1)
987 IF (
PRESENT(el_format))
THEN
988 fmtstr =
'(" ",'//nriga//el_format//
')'
989 WRITE (unit=unit_nr, fmt=fmtstr, iostat=iostat) array(i, :)
991 fmtstr =
'(" ",'//nriga//defaultformat//
')'
992 WRITE (unit=unit_nr, fmt=fmtstr, iostat=iostat) array(i, :)
994 cpassert(iostat == 0)
1017 logical,
POINTER :: array(:)
1018 INTEGER,
INTENT(in) :: n
1021 IF (
ASSOCIATED(array))
THEN
1022 IF (
SIZE(array) /= n)
THEN
1023 cpwarn(
'size has changed')
1027 IF (.NOT.
ASSOCIATED(array))
THEN
1050 logical,
POINTER :: array(:, :)
1051 INTEGER,
INTENT(in) :: n_rows, n_cols
1053 cpassert(n_cols >= 0)
1054 cpassert(n_rows >= 0)
1055 IF (
ASSOCIATED(array))
THEN
1056 IF (
SIZE(array, 1) /= n_rows .OR.
SIZE(array, 2) /= n_cols)
THEN
1057 cpwarn(
'size has changed')
1061 IF (.NOT.
ASSOCIATED(array))
THEN
1062 ALLOCATE (array(n_rows, n_cols))
1083 logical,
intent(in) :: array(:)
1084 logical,
intent(in) :: el
1085 INTEGER,
INTENT(in),
OPTIONAL :: l_index, u_index
1088 INTEGER :: lindex, uindex, aindex
1091 uindex =
size(array)
1092 if (
present(l_index)) lindex = l_index
1093 if (
present(u_index)) uindex = u_index
1094 DO WHILE (lindex <= uindex)
1095 aindex = (lindex + uindex)/2
1096 IF ( (.not. array(aindex)) .and. el)
THEN
various utilities that regard array of different kinds: output, allocation,... maybe it is not a good...
subroutine, public cp_2d_c_guarantee_size(array, n_rows, n_cols)
If the size of the array is changes reallocate it. Issues a warning when the size changes (but not on...
subroutine, public cp_1d_i_guarantee_size(array, n)
If the size of the array is changes reallocate it. Issues a warning when the size changes (but not on...
subroutine, public cp_2d_r_guarantee_size(array, n_rows, n_cols)
If the size of the array is changes reallocate it. Issues a warning when the size changes (but not on...
integer function, public cp_1d_logical_bsearch(array, el, l_index, u_index)
returns the index at which the element el should be inserted in the array to keep it ordered (array(i...
integer function, public cp_1d_c_bsearch(array, el, l_index, u_index)
returns the index at which the element el should be inserted in the array to keep it ordered (array(i...
subroutine, public cp_1d_i_write(array, unit_nr, el_format)
writes an array to the given unit
subroutine, public cp_1d_logical_write(array, unit_nr, el_format)
writes an array to the given unit
integer function, public cp_1d_i_bsearch(array, el, l_index, u_index)
returns the index at which the element el should be inserted in the array to keep it ordered (array(i...
subroutine, public cp_2d_i_guarantee_size(array, n_rows, n_cols)
If the size of the array is changes reallocate it. Issues a warning when the size changes (but not on...
subroutine, public cp_2d_c_write(array, unit_nr, el_format)
writes an array to the given unit
subroutine, public cp_1d_r_write(array, unit_nr, el_format)
writes an array to the given unit
subroutine, public cp_1d_logical_guarantee_size(array, n)
If the size of the array is changes reallocate it. Issues a warning when the size changes (but not on...
integer function, public cp_1d_r_bsearch(array, el, l_index, u_index)
returns the index at which the element el should be inserted in the array to keep it ordered (array(i...
subroutine, public cp_1d_c_guarantee_size(array, n)
If the size of the array is changes reallocate it. Issues a warning when the size changes (but not on...
subroutine, public cp_2d_logical_write(array, unit_nr, el_format)
writes an array to the given unit
subroutine, public cp_2d_logical_guarantee_size(array, n_rows, n_cols)
If the size of the array is changes reallocate it. Issues a warning when the size changes (but not on...
subroutine, public cp_1d_c_write(array, unit_nr, el_format)
writes an array to the given unit
subroutine, public cp_2d_r_write(array, unit_nr, el_format)
writes an array to the given unit
subroutine, public cp_1d_r_guarantee_size(array, n)
If the size of the array is changes reallocate it. Issues a warning when the size changes (but not on...
subroutine, public cp_2d_i_write(array, unit_nr, el_format)
writes an array to the given unit
various routines to log and control the output. The idea is that decisions about where to log should ...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public int_4
Machine interface based on Fortran 2003 and POSIX.
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
represent a pointer to a contiguous 1d array
represent a pointer to a 1d array
represent a pointer to a contiguous 1d array
represent a pointer to a 1d array
represent a pointer to a contiguous 1d array
represent a pointer to a 1d array
represent a pointer to a contiguous 1d array
represent a pointer to a 1d array
represent a pointer to a contiguous 2d array
represent a pointer to a 2d array
represent a pointer to a contiguous 2d array
represent a pointer to a 2d array
represent a pointer to a contiguous 2d array
represent a pointer to a 2d array
represent a pointer to a contiguous 2d array
represent a pointer to a 2d array
represent a pointer to a contiguous 3d array
represent a pointer to a 3d array
represent a pointer to a contiguous 3d array
represent a pointer to a 3d array
represent a pointer to a contiguous 3d array
represent a pointer to a 3d array
represent a pointer to a contiguous 3d array
represent a pointer to a 3d array