libsim Versione 7.1.11

◆ overalloc

double precision overalloc =2.0D0

overallocation factor, values close to 1 determine more calls to the system alloc function (decreased performances) at the advantage of less memory consumption, the default is 2; the results are not affected by the value of this member

Definizione alla linea 850 del file array_utilities.F90.

850! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
851! authors:
852! Davide Cesari <dcesari@arpa.emr.it>
853! Paolo Patruno <ppatruno@arpa.emr.it>
854
855! This program is free software; you can redistribute it and/or
856! modify it under the terms of the GNU General Public License as
857! published by the Free Software Foundation; either version 2 of
858! the License, or (at your option) any later version.
859
860! This program is distributed in the hope that it will be useful,
861! but WITHOUT ANY WARRANTY; without even the implied warranty of
862! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
863! GNU General Public License for more details.
864
865! You should have received a copy of the GNU General Public License
866! along with this program. If not, see <http://www.gnu.org/licenses/>.
867
868
869
872#include "config.h"
873MODULE array_utilities
874
875IMPLICIT NONE
876
877! la routine per i char non puo' essere sviluppata in macro perche` si deve scrivere diversa
878!cosi' esiste la function count_distinctc (senza _ ) e la subroutine pack_distinctc qui ivi scritte
879
880#undef VOL7D_POLY_TYPE_AUTO
881
882#undef VOL7D_POLY_TYPE
883#undef VOL7D_POLY_TYPES
884#define VOL7D_POLY_TYPE INTEGER
885#define VOL7D_POLY_TYPES _i
886#define ENABLE_SORT
887#include "array_utilities_pre.F90"
888#undef ENABLE_SORT
889
890#undef VOL7D_POLY_TYPE
891#undef VOL7D_POLY_TYPES
892#define VOL7D_POLY_TYPE REAL
893#define VOL7D_POLY_TYPES _r
894#define ENABLE_SORT
895#include "array_utilities_pre.F90"
896#undef ENABLE_SORT
897
898#undef VOL7D_POLY_TYPE
899#undef VOL7D_POLY_TYPES
900#define VOL7D_POLY_TYPE DOUBLEPRECISION
901#define VOL7D_POLY_TYPES _d
902#define ENABLE_SORT
903#include "array_utilities_pre.F90"
904#undef ENABLE_SORT
905
906#define VOL7D_NO_PACK
907#undef VOL7D_POLY_TYPE
908#undef VOL7D_POLY_TYPES
909#define VOL7D_POLY_TYPE CHARACTER(len=*)
910#define VOL7D_POLY_TYPE_AUTO(var) CHARACTER(len=LEN(var))
911#define VOL7D_POLY_TYPES _c
912#define ENABLE_SORT
913#include "array_utilities_pre.F90"
914#undef VOL7D_POLY_TYPE_AUTO
915#undef ENABLE_SORT
916
917
918#define ARRAYOF_ORIGEQ 1
919
920#define ARRAYOF_ORIGTYPE INTEGER
921#define ARRAYOF_TYPE arrayof_integer
922#include "arrayof_pre.F90"
923
924#undef ARRAYOF_ORIGTYPE
925#undef ARRAYOF_TYPE
926#define ARRAYOF_ORIGTYPE REAL
927#define ARRAYOF_TYPE arrayof_real
928#include "arrayof_pre.F90"
929
930#undef ARRAYOF_ORIGTYPE
931#undef ARRAYOF_TYPE
932#define ARRAYOF_ORIGTYPE DOUBLEPRECISION
933#define ARRAYOF_TYPE arrayof_doubleprecision
934#include "arrayof_pre.F90"
935
936#undef ARRAYOF_ORIGEQ
937
938#undef ARRAYOF_ORIGTYPE
939#undef ARRAYOF_TYPE
940#define ARRAYOF_ORIGTYPE LOGICAL
941#define ARRAYOF_TYPE arrayof_logical
942#include "arrayof_pre.F90"
943
944PRIVATE
945! from arrayof
947PUBLIC insert_unique, append_unique
948
949PUBLIC sort, index, index_c, &
950 count_distinct_sorted, pack_distinct_sorted, &
951 count_distinct, pack_distinct, count_and_pack_distinct, &
952 map_distinct, map_inv_distinct, &
953 firsttrue, lasttrue, pack_distinct_c, map
954
955CONTAINS
956
957
960FUNCTION firsttrue(v) RESULT(i)
961LOGICAL,INTENT(in) :: v(:)
962INTEGER :: i
963
964DO i = 1, SIZE(v)
965 IF (v(i)) RETURN
966ENDDO
967i = 0
968
969END FUNCTION firsttrue
970
971
974FUNCTION lasttrue(v) RESULT(i)
975LOGICAL,INTENT(in) :: v(:)
976INTEGER :: i
977
978DO i = SIZE(v), 1, -1
979 IF (v(i)) RETURN
980ENDDO
981
982END FUNCTION lasttrue
983
984
985! Definisce le funzioni count_distinct(_sorted) e pack_distinct(_sorted)
986#undef VOL7D_POLY_TYPE_AUTO
987#undef VOL7D_NO_PACK
988
989#undef VOL7D_POLY_TYPE
990#undef VOL7D_POLY_TYPES
991#define VOL7D_POLY_TYPE INTEGER
992#define VOL7D_POLY_TYPES _i
993#define ENABLE_SORT
994#include "array_utilities_inc.F90"
995#undef ENABLE_SORT
996
997#undef VOL7D_POLY_TYPE
998#undef VOL7D_POLY_TYPES
999#define VOL7D_POLY_TYPE REAL
1000#define VOL7D_POLY_TYPES _r
1001#define ENABLE_SORT
1002#include "array_utilities_inc.F90"
1003#undef ENABLE_SORT
1004
1005#undef VOL7D_POLY_TYPE
1006#undef VOL7D_POLY_TYPES
1007#define VOL7D_POLY_TYPE DOUBLEPRECISION
1008#define VOL7D_POLY_TYPES _d
1009#define ENABLE_SORT
1010#include "array_utilities_inc.F90"
1011#undef ENABLE_SORT
1012
1013#define VOL7D_NO_PACK
1014#undef VOL7D_POLY_TYPE
1015#undef VOL7D_POLY_TYPES
1016#define VOL7D_POLY_TYPE CHARACTER(len=*)
1017#define VOL7D_POLY_TYPE_AUTO(var) CHARACTER(len=LEN(var))
1018#define VOL7D_POLY_TYPES _c
1019#define ENABLE_SORT
1020#include "array_utilities_inc.F90"
1021#undef VOL7D_POLY_TYPE_AUTO
1022#undef ENABLE_SORT
1023
1024SUBROUTINE pack_distinct_c(vect, pack_distinct, mask, back) !RESULT(pack_distinct)
1025CHARACTER(len=*),INTENT(in) :: vect(:)
1026LOGICAL,INTENT(in),OPTIONAL :: mask(:), back
1027CHARACTER(len=LEN(vect)) :: pack_distinct(:)
1028
1029INTEGER :: count_distinct
1030INTEGER :: i, j, dim
1031LOGICAL :: lback
1032
1033dim = SIZE(pack_distinct)
1034IF (PRESENT(back)) THEN
1035 lback = back
1036ELSE
1037 lback = .false.
1038ENDIF
1039count_distinct = 0
1040
1041IF (PRESENT (mask)) THEN
1042 IF (lback) THEN
1043 vectm1: DO i = 1, SIZE(vect)
1044 IF (.NOT.mask(i)) cycle vectm1
1045! DO j = i-1, 1, -1
1046! IF (vect(j) == vect(i)) CYCLE vectm1
1047 DO j = count_distinct, 1, -1
1048 IF (pack_distinct(j) == vect(i)) cycle vectm1
1049 ENDDO
1050 count_distinct = count_distinct + 1
1051 IF (count_distinct > dim) EXIT
1052 pack_distinct(count_distinct) = vect(i)
1053 ENDDO vectm1
1054 ELSE
1055 vectm2: DO i = 1, SIZE(vect)
1056 IF (.NOT.mask(i)) cycle vectm2
1057! DO j = 1, i-1
1058! IF (vect(j) == vect(i)) CYCLE vectm2
1059 DO j = 1, count_distinct
1060 IF (pack_distinct(j) == vect(i)) cycle vectm2
1061 ENDDO
1062 count_distinct = count_distinct + 1
1063 IF (count_distinct > dim) EXIT
1064 pack_distinct(count_distinct) = vect(i)
1065 ENDDO vectm2
1066 ENDIF
1067ELSE
1068 IF (lback) THEN
1069 vect1: DO i = 1, SIZE(vect)
1070! DO j = i-1, 1, -1
1071! IF (vect(j) == vect(i)) CYCLE vect1
1072 DO j = count_distinct, 1, -1
1073 IF (pack_distinct(j) == vect(i)) cycle vect1
1074 ENDDO
1075 count_distinct = count_distinct + 1
1076 IF (count_distinct > dim) EXIT
1077 pack_distinct(count_distinct) = vect(i)
1078 ENDDO vect1
1079 ELSE
1080 vect2: DO i = 1, SIZE(vect)
1081! DO j = 1, i-1
1082! IF (vect(j) == vect(i)) CYCLE vect2
1083 DO j = 1, count_distinct
1084 IF (pack_distinct(j) == vect(i)) cycle vect2
1085 ENDDO
1086 count_distinct = count_distinct + 1
1087 IF (count_distinct > dim) EXIT
1088 pack_distinct(count_distinct) = vect(i)
1089 ENDDO vect2
1090 ENDIF
1091ENDIF
1092
1093END SUBROUTINE pack_distinct_c
1094
1096FUNCTION map(mask) RESULT(mapidx)
1097LOGICAL,INTENT(in) :: mask(:)
1098INTEGER :: mapidx(count(mask))
1099
1100INTEGER :: i,j
1101
1102j = 0
1103DO i=1, SIZE(mask)
1104 j = j + 1
1105 IF (mask(i)) mapidx(j)=i
1106ENDDO
1107
1108END FUNCTION map
1109
1110#define ARRAYOF_ORIGEQ 1
1111
1112#undef ARRAYOF_ORIGTYPE
1113#undef ARRAYOF_TYPE
1114#define ARRAYOF_ORIGTYPE INTEGER
1115#define ARRAYOF_TYPE arrayof_integer
1116#include "arrayof_post.F90"
1117
1118#undef ARRAYOF_ORIGTYPE
1119#undef ARRAYOF_TYPE
1120#define ARRAYOF_ORIGTYPE REAL
1121#define ARRAYOF_TYPE arrayof_real
1122#include "arrayof_post.F90"
1123
1124#undef ARRAYOF_ORIGTYPE
1125#undef ARRAYOF_TYPE
1126#define ARRAYOF_ORIGTYPE DOUBLEPRECISION
1127#define ARRAYOF_TYPE arrayof_doubleprecision
1128#include "arrayof_post.F90"
1129
1130#undef ARRAYOF_ORIGEQ
1131
1132#undef ARRAYOF_ORIGTYPE
1133#undef ARRAYOF_TYPE
1134#define ARRAYOF_ORIGTYPE LOGICAL
1135#define ARRAYOF_TYPE arrayof_logical
1136#include "arrayof_post.F90"
1137
1138END MODULE array_utilities
Quick method to append an element to the array.
Destructor for finalizing an array object.
Method for inserting elements of the array at a desired position.
Method for packing the array object reducing at a minimum the memory occupation, without destroying i...
Method for removing elements of the array at a desired position.
Index method.
This module defines usefull general purpose function and subroutine.

Generated with Doxygen.