libsim Versione 7.1.11

◆ lasttrue()

integer function, public lasttrue ( logical, dimension(:), intent(in)  v)

Return the index ot the last true element of the input logical array v.

If no .TRUE. elements are found, it returns 0.

Parametri
[in]vlogical array to test

Definizione alla linea 937 del file array_utilities.F90.

938! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
939! authors:
940! Davide Cesari <dcesari@arpa.emr.it>
941! Paolo Patruno <ppatruno@arpa.emr.it>
942
943! This program is free software; you can redistribute it and/or
944! modify it under the terms of the GNU General Public License as
945! published by the Free Software Foundation; either version 2 of
946! the License, or (at your option) any later version.
947
948! This program is distributed in the hope that it will be useful,
949! but WITHOUT ANY WARRANTY; without even the implied warranty of
950! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
951! GNU General Public License for more details.
952
953! You should have received a copy of the GNU General Public License
954! along with this program. If not, see <http://www.gnu.org/licenses/>.
955
956
957
960#include "config.h"
961MODULE array_utilities
962
963IMPLICIT NONE
964
965! la routine per i char non puo' essere sviluppata in macro perche` si deve scrivere diversa
966!cosi' esiste la function count_distinctc (senza _ ) e la subroutine pack_distinctc qui ivi scritte
967
968#undef VOL7D_POLY_TYPE_AUTO
969
970#undef VOL7D_POLY_TYPE
971#undef VOL7D_POLY_TYPES
972#define VOL7D_POLY_TYPE INTEGER
973#define VOL7D_POLY_TYPES _i
974#define ENABLE_SORT
975#include "array_utilities_pre.F90"
976#undef ENABLE_SORT
977
978#undef VOL7D_POLY_TYPE
979#undef VOL7D_POLY_TYPES
980#define VOL7D_POLY_TYPE REAL
981#define VOL7D_POLY_TYPES _r
982#define ENABLE_SORT
983#include "array_utilities_pre.F90"
984#undef ENABLE_SORT
985
986#undef VOL7D_POLY_TYPE
987#undef VOL7D_POLY_TYPES
988#define VOL7D_POLY_TYPE DOUBLEPRECISION
989#define VOL7D_POLY_TYPES _d
990#define ENABLE_SORT
991#include "array_utilities_pre.F90"
992#undef ENABLE_SORT
993
994#define VOL7D_NO_PACK
995#undef VOL7D_POLY_TYPE
996#undef VOL7D_POLY_TYPES
997#define VOL7D_POLY_TYPE CHARACTER(len=*)
998#define VOL7D_POLY_TYPE_AUTO(var) CHARACTER(len=LEN(var))
999#define VOL7D_POLY_TYPES _c
1000#define ENABLE_SORT
1001#include "array_utilities_pre.F90"
1002#undef VOL7D_POLY_TYPE_AUTO
1003#undef ENABLE_SORT
1004
1005
1006#define ARRAYOF_ORIGEQ 1
1007
1008#define ARRAYOF_ORIGTYPE INTEGER
1009#define ARRAYOF_TYPE arrayof_integer
1010#include "arrayof_pre.F90"
1011
1012#undef ARRAYOF_ORIGTYPE
1013#undef ARRAYOF_TYPE
1014#define ARRAYOF_ORIGTYPE REAL
1015#define ARRAYOF_TYPE arrayof_real
1016#include "arrayof_pre.F90"
1017
1018#undef ARRAYOF_ORIGTYPE
1019#undef ARRAYOF_TYPE
1020#define ARRAYOF_ORIGTYPE DOUBLEPRECISION
1021#define ARRAYOF_TYPE arrayof_doubleprecision
1022#include "arrayof_pre.F90"
1023
1024#undef ARRAYOF_ORIGEQ
1025
1026#undef ARRAYOF_ORIGTYPE
1027#undef ARRAYOF_TYPE
1028#define ARRAYOF_ORIGTYPE LOGICAL
1029#define ARRAYOF_TYPE arrayof_logical
1030#include "arrayof_pre.F90"
1031
1032PRIVATE
1033! from arrayof
1035PUBLIC insert_unique, append_unique
1036
1037PUBLIC sort, index, index_c, &
1038 count_distinct_sorted, pack_distinct_sorted, &
1039 count_distinct, pack_distinct, count_and_pack_distinct, &
1040 map_distinct, map_inv_distinct, &
1041 firsttrue, lasttrue, pack_distinct_c, map
1042
1043CONTAINS
1044
1045
1048FUNCTION firsttrue(v) RESULT(i)
1049LOGICAL,INTENT(in) :: v(:)
1050INTEGER :: i
1051
1052DO i = 1, SIZE(v)
1053 IF (v(i)) RETURN
1054ENDDO
1055i = 0
1056
1057END FUNCTION firsttrue
1058
1059
1062FUNCTION lasttrue(v) RESULT(i)
1063LOGICAL,INTENT(in) :: v(:)
1064INTEGER :: i
1065
1066DO i = SIZE(v), 1, -1
1067 IF (v(i)) RETURN
1068ENDDO
1069
1070END FUNCTION lasttrue
1071
1072
1073! Definisce le funzioni count_distinct(_sorted) e pack_distinct(_sorted)
1074#undef VOL7D_POLY_TYPE_AUTO
1075#undef VOL7D_NO_PACK
1076
1077#undef VOL7D_POLY_TYPE
1078#undef VOL7D_POLY_TYPES
1079#define VOL7D_POLY_TYPE INTEGER
1080#define VOL7D_POLY_TYPES _i
1081#define ENABLE_SORT
1082#include "array_utilities_inc.F90"
1083#undef ENABLE_SORT
1084
1085#undef VOL7D_POLY_TYPE
1086#undef VOL7D_POLY_TYPES
1087#define VOL7D_POLY_TYPE REAL
1088#define VOL7D_POLY_TYPES _r
1089#define ENABLE_SORT
1090#include "array_utilities_inc.F90"
1091#undef ENABLE_SORT
1092
1093#undef VOL7D_POLY_TYPE
1094#undef VOL7D_POLY_TYPES
1095#define VOL7D_POLY_TYPE DOUBLEPRECISION
1096#define VOL7D_POLY_TYPES _d
1097#define ENABLE_SORT
1098#include "array_utilities_inc.F90"
1099#undef ENABLE_SORT
1100
1101#define VOL7D_NO_PACK
1102#undef VOL7D_POLY_TYPE
1103#undef VOL7D_POLY_TYPES
1104#define VOL7D_POLY_TYPE CHARACTER(len=*)
1105#define VOL7D_POLY_TYPE_AUTO(var) CHARACTER(len=LEN(var))
1106#define VOL7D_POLY_TYPES _c
1107#define ENABLE_SORT
1108#include "array_utilities_inc.F90"
1109#undef VOL7D_POLY_TYPE_AUTO
1110#undef ENABLE_SORT
1111
1112SUBROUTINE pack_distinct_c(vect, pack_distinct, mask, back) !RESULT(pack_distinct)
1113CHARACTER(len=*),INTENT(in) :: vect(:)
1114LOGICAL,INTENT(in),OPTIONAL :: mask(:), back
1115CHARACTER(len=LEN(vect)) :: pack_distinct(:)
1116
1117INTEGER :: count_distinct
1118INTEGER :: i, j, dim
1119LOGICAL :: lback
1120
1121dim = SIZE(pack_distinct)
1122IF (PRESENT(back)) THEN
1123 lback = back
1124ELSE
1125 lback = .false.
1126ENDIF
1127count_distinct = 0
1128
1129IF (PRESENT (mask)) THEN
1130 IF (lback) THEN
1131 vectm1: DO i = 1, SIZE(vect)
1132 IF (.NOT.mask(i)) cycle vectm1
1133! DO j = i-1, 1, -1
1134! IF (vect(j) == vect(i)) CYCLE vectm1
1135 DO j = count_distinct, 1, -1
1136 IF (pack_distinct(j) == vect(i)) cycle vectm1
1137 ENDDO
1138 count_distinct = count_distinct + 1
1139 IF (count_distinct > dim) EXIT
1140 pack_distinct(count_distinct) = vect(i)
1141 ENDDO vectm1
1142 ELSE
1143 vectm2: DO i = 1, SIZE(vect)
1144 IF (.NOT.mask(i)) cycle vectm2
1145! DO j = 1, i-1
1146! IF (vect(j) == vect(i)) CYCLE vectm2
1147 DO j = 1, count_distinct
1148 IF (pack_distinct(j) == vect(i)) cycle vectm2
1149 ENDDO
1150 count_distinct = count_distinct + 1
1151 IF (count_distinct > dim) EXIT
1152 pack_distinct(count_distinct) = vect(i)
1153 ENDDO vectm2
1154 ENDIF
1155ELSE
1156 IF (lback) THEN
1157 vect1: DO i = 1, SIZE(vect)
1158! DO j = i-1, 1, -1
1159! IF (vect(j) == vect(i)) CYCLE vect1
1160 DO j = count_distinct, 1, -1
1161 IF (pack_distinct(j) == vect(i)) cycle vect1
1162 ENDDO
1163 count_distinct = count_distinct + 1
1164 IF (count_distinct > dim) EXIT
1165 pack_distinct(count_distinct) = vect(i)
1166 ENDDO vect1
1167 ELSE
1168 vect2: DO i = 1, SIZE(vect)
1169! DO j = 1, i-1
1170! IF (vect(j) == vect(i)) CYCLE vect2
1171 DO j = 1, count_distinct
1172 IF (pack_distinct(j) == vect(i)) cycle vect2
1173 ENDDO
1174 count_distinct = count_distinct + 1
1175 IF (count_distinct > dim) EXIT
1176 pack_distinct(count_distinct) = vect(i)
1177 ENDDO vect2
1178 ENDIF
1179ENDIF
1180
1181END SUBROUTINE pack_distinct_c
1182
1184FUNCTION map(mask) RESULT(mapidx)
1185LOGICAL,INTENT(in) :: mask(:)
1186INTEGER :: mapidx(count(mask))
1187
1188INTEGER :: i,j
1189
1190j = 0
1191DO i=1, SIZE(mask)
1192 j = j + 1
1193 IF (mask(i)) mapidx(j)=i
1194ENDDO
1195
1196END FUNCTION map
1197
1198#define ARRAYOF_ORIGEQ 1
1199
1200#undef ARRAYOF_ORIGTYPE
1201#undef ARRAYOF_TYPE
1202#define ARRAYOF_ORIGTYPE INTEGER
1203#define ARRAYOF_TYPE arrayof_integer
1204#include "arrayof_post.F90"
1205
1206#undef ARRAYOF_ORIGTYPE
1207#undef ARRAYOF_TYPE
1208#define ARRAYOF_ORIGTYPE REAL
1209#define ARRAYOF_TYPE arrayof_real
1210#include "arrayof_post.F90"
1211
1212#undef ARRAYOF_ORIGTYPE
1213#undef ARRAYOF_TYPE
1214#define ARRAYOF_ORIGTYPE DOUBLEPRECISION
1215#define ARRAYOF_TYPE arrayof_doubleprecision
1216#include "arrayof_post.F90"
1217
1218#undef ARRAYOF_ORIGEQ
1219
1220#undef ARRAYOF_ORIGTYPE
1221#undef ARRAYOF_TYPE
1222#define ARRAYOF_ORIGTYPE LOGICAL
1223#define ARRAYOF_TYPE arrayof_logical
1224#include "arrayof_post.F90"
1225
1226END 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.