libsim Versione 7.2.1

◆ arrayof_integer_append_unique()

integer function, private arrayof_integer_append_unique ( type(arrayof_integer this,
integer, intent(in)  content 
)
private

Quick function to append an element to the array only if it is not present in the array yet.

The return value is the position at which the element has been appended or at which it has been found.

Parametri
thisarray object to extend
[in]contentobject of TYPE INTEGER to append

Definizione alla linea 5610 del file array_utilities.F90.

5611! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
5612! authors:
5613! Davide Cesari <dcesari@arpa.emr.it>
5614! Paolo Patruno <ppatruno@arpa.emr.it>
5615
5616! This program is free software; you can redistribute it and/or
5617! modify it under the terms of the GNU General Public License as
5618! published by the Free Software Foundation; either version 2 of
5619! the License, or (at your option) any later version.
5620
5621! This program is distributed in the hope that it will be useful,
5622! but WITHOUT ANY WARRANTY; without even the implied warranty of
5623! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5624! GNU General Public License for more details.
5625
5626! You should have received a copy of the GNU General Public License
5627! along with this program. If not, see <http://www.gnu.org/licenses/>.
5628
5629
5630
5633#include "config.h"
5634MODULE array_utilities
5635
5636IMPLICIT NONE
5637
5638! la routine per i char non puo' essere sviluppata in macro perche` si deve scrivere diversa
5639!cosi' esiste la function count_distinctc (senza _ ) e la subroutine pack_distinctc qui ivi scritte
5640
5641#undef VOL7D_POLY_TYPE_AUTO
5642
5643#undef VOL7D_POLY_TYPE
5644#undef VOL7D_POLY_TYPES
5645#define VOL7D_POLY_TYPE INTEGER
5646#define VOL7D_POLY_TYPES _i
5647#define ENABLE_SORT
5648#include "array_utilities_pre.F90"
5649#undef ENABLE_SORT
5650
5651#undef VOL7D_POLY_TYPE
5652#undef VOL7D_POLY_TYPES
5653#define VOL7D_POLY_TYPE REAL
5654#define VOL7D_POLY_TYPES _r
5655#define ENABLE_SORT
5656#include "array_utilities_pre.F90"
5657#undef ENABLE_SORT
5658
5659#undef VOL7D_POLY_TYPE
5660#undef VOL7D_POLY_TYPES
5661#define VOL7D_POLY_TYPE DOUBLEPRECISION
5662#define VOL7D_POLY_TYPES _d
5663#define ENABLE_SORT
5664#include "array_utilities_pre.F90"
5665#undef ENABLE_SORT
5666
5667#define VOL7D_NO_PACK
5668#undef VOL7D_POLY_TYPE
5669#undef VOL7D_POLY_TYPES
5670#define VOL7D_POLY_TYPE CHARACTER(len=*)
5671#define VOL7D_POLY_TYPE_AUTO(var) CHARACTER(len=LEN(var))
5672#define VOL7D_POLY_TYPES _c
5673#define ENABLE_SORT
5674#include "array_utilities_pre.F90"
5675#undef VOL7D_POLY_TYPE_AUTO
5676#undef ENABLE_SORT
5677
5678
5679#define ARRAYOF_ORIGEQ 1
5680
5681#define ARRAYOF_ORIGTYPE INTEGER
5682#define ARRAYOF_TYPE arrayof_integer
5683#include "arrayof_pre.F90"
5684
5685#undef ARRAYOF_ORIGTYPE
5686#undef ARRAYOF_TYPE
5687#define ARRAYOF_ORIGTYPE REAL
5688#define ARRAYOF_TYPE arrayof_real
5689#include "arrayof_pre.F90"
5690
5691#undef ARRAYOF_ORIGTYPE
5692#undef ARRAYOF_TYPE
5693#define ARRAYOF_ORIGTYPE DOUBLEPRECISION
5694#define ARRAYOF_TYPE arrayof_doubleprecision
5695#include "arrayof_pre.F90"
5696
5697#undef ARRAYOF_ORIGEQ
5698
5699#undef ARRAYOF_ORIGTYPE
5700#undef ARRAYOF_TYPE
5701#define ARRAYOF_ORIGTYPE LOGICAL
5702#define ARRAYOF_TYPE arrayof_logical
5703#include "arrayof_pre.F90"
5704
5705PRIVATE
5706! from arrayof
5708PUBLIC insert_unique, append_unique
5709
5710PUBLIC sort, index, index_c, &
5711 count_distinct_sorted, pack_distinct_sorted, &
5712 count_distinct, pack_distinct, count_and_pack_distinct, &
5713 map_distinct, map_inv_distinct, &
5714 firsttrue, lasttrue, pack_distinct_c, map
5715
5716CONTAINS
5717
5718
5721FUNCTION firsttrue(v) RESULT(i)
5722LOGICAL,INTENT(in) :: v(:)
5723INTEGER :: i
5724
5725DO i = 1, SIZE(v)
5726 IF (v(i)) RETURN
5727ENDDO
5728i = 0
5729
5730END FUNCTION firsttrue
5731
5732
5735FUNCTION lasttrue(v) RESULT(i)
5736LOGICAL,INTENT(in) :: v(:)
5737INTEGER :: i
5738
5739DO i = SIZE(v), 1, -1
5740 IF (v(i)) RETURN
5741ENDDO
5742
5743END FUNCTION lasttrue
5744
5745
5746! Definisce le funzioni count_distinct(_sorted) e pack_distinct(_sorted)
5747#undef VOL7D_POLY_TYPE_AUTO
5748#undef VOL7D_NO_PACK
5749
5750#undef VOL7D_POLY_TYPE
5751#undef VOL7D_POLY_TYPES
5752#define VOL7D_POLY_TYPE INTEGER
5753#define VOL7D_POLY_TYPES _i
5754#define ENABLE_SORT
5755#include "array_utilities_inc.F90"
5756#undef ENABLE_SORT
5757
5758#undef VOL7D_POLY_TYPE
5759#undef VOL7D_POLY_TYPES
5760#define VOL7D_POLY_TYPE REAL
5761#define VOL7D_POLY_TYPES _r
5762#define ENABLE_SORT
5763#include "array_utilities_inc.F90"
5764#undef ENABLE_SORT
5765
5766#undef VOL7D_POLY_TYPE
5767#undef VOL7D_POLY_TYPES
5768#define VOL7D_POLY_TYPE DOUBLEPRECISION
5769#define VOL7D_POLY_TYPES _d
5770#define ENABLE_SORT
5771#include "array_utilities_inc.F90"
5772#undef ENABLE_SORT
5773
5774#define VOL7D_NO_PACK
5775#undef VOL7D_POLY_TYPE
5776#undef VOL7D_POLY_TYPES
5777#define VOL7D_POLY_TYPE CHARACTER(len=*)
5778#define VOL7D_POLY_TYPE_AUTO(var) CHARACTER(len=LEN(var))
5779#define VOL7D_POLY_TYPES _c
5780#define ENABLE_SORT
5781#include "array_utilities_inc.F90"
5782#undef VOL7D_POLY_TYPE_AUTO
5783#undef ENABLE_SORT
5784
5785SUBROUTINE pack_distinct_c(vect, pack_distinct, mask, back) !RESULT(pack_distinct)
5786CHARACTER(len=*),INTENT(in) :: vect(:)
5787LOGICAL,INTENT(in),OPTIONAL :: mask(:), back
5788CHARACTER(len=LEN(vect)) :: pack_distinct(:)
5789
5790INTEGER :: count_distinct
5791INTEGER :: i, j, dim
5792LOGICAL :: lback
5793
5794dim = SIZE(pack_distinct)
5795IF (PRESENT(back)) THEN
5796 lback = back
5797ELSE
5798 lback = .false.
5799ENDIF
5800count_distinct = 0
5801
5802IF (PRESENT (mask)) THEN
5803 IF (lback) THEN
5804 vectm1: DO i = 1, SIZE(vect)
5805 IF (.NOT.mask(i)) cycle vectm1
5806! DO j = i-1, 1, -1
5807! IF (vect(j) == vect(i)) CYCLE vectm1
5808 DO j = count_distinct, 1, -1
5809 IF (pack_distinct(j) == vect(i)) cycle vectm1
5810 ENDDO
5811 count_distinct = count_distinct + 1
5812 IF (count_distinct > dim) EXIT
5813 pack_distinct(count_distinct) = vect(i)
5814 ENDDO vectm1
5815 ELSE
5816 vectm2: DO i = 1, SIZE(vect)
5817 IF (.NOT.mask(i)) cycle vectm2
5818! DO j = 1, i-1
5819! IF (vect(j) == vect(i)) CYCLE vectm2
5820 DO j = 1, count_distinct
5821 IF (pack_distinct(j) == vect(i)) cycle vectm2
5822 ENDDO
5823 count_distinct = count_distinct + 1
5824 IF (count_distinct > dim) EXIT
5825 pack_distinct(count_distinct) = vect(i)
5826 ENDDO vectm2
5827 ENDIF
5828ELSE
5829 IF (lback) THEN
5830 vect1: DO i = 1, SIZE(vect)
5831! DO j = i-1, 1, -1
5832! IF (vect(j) == vect(i)) CYCLE vect1
5833 DO j = count_distinct, 1, -1
5834 IF (pack_distinct(j) == vect(i)) cycle vect1
5835 ENDDO
5836 count_distinct = count_distinct + 1
5837 IF (count_distinct > dim) EXIT
5838 pack_distinct(count_distinct) = vect(i)
5839 ENDDO vect1
5840 ELSE
5841 vect2: DO i = 1, SIZE(vect)
5842! DO j = 1, i-1
5843! IF (vect(j) == vect(i)) CYCLE vect2
5844 DO j = 1, count_distinct
5845 IF (pack_distinct(j) == vect(i)) cycle vect2
5846 ENDDO
5847 count_distinct = count_distinct + 1
5848 IF (count_distinct > dim) EXIT
5849 pack_distinct(count_distinct) = vect(i)
5850 ENDDO vect2
5851 ENDIF
5852ENDIF
5853
5854END SUBROUTINE pack_distinct_c
5855
5857FUNCTION map(mask) RESULT(mapidx)
5858LOGICAL,INTENT(in) :: mask(:)
5859INTEGER :: mapidx(count(mask))
5860
5861INTEGER :: i,j
5862
5863j = 0
5864DO i=1, SIZE(mask)
5865 j = j + 1
5866 IF (mask(i)) mapidx(j)=i
5867ENDDO
5868
5869END FUNCTION map
5870
5871#define ARRAYOF_ORIGEQ 1
5872
5873#undef ARRAYOF_ORIGTYPE
5874#undef ARRAYOF_TYPE
5875#define ARRAYOF_ORIGTYPE INTEGER
5876#define ARRAYOF_TYPE arrayof_integer
5877#include "arrayof_post.F90"
5878
5879#undef ARRAYOF_ORIGTYPE
5880#undef ARRAYOF_TYPE
5881#define ARRAYOF_ORIGTYPE REAL
5882#define ARRAYOF_TYPE arrayof_real
5883#include "arrayof_post.F90"
5884
5885#undef ARRAYOF_ORIGTYPE
5886#undef ARRAYOF_TYPE
5887#define ARRAYOF_ORIGTYPE DOUBLEPRECISION
5888#define ARRAYOF_TYPE arrayof_doubleprecision
5889#include "arrayof_post.F90"
5890
5891#undef ARRAYOF_ORIGEQ
5892
5893#undef ARRAYOF_ORIGTYPE
5894#undef ARRAYOF_TYPE
5895#define ARRAYOF_ORIGTYPE LOGICAL
5896#define ARRAYOF_TYPE arrayof_logical
5897#include "arrayof_post.F90"
5898
5899END 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.