libsim Versione 7.2.6

◆ arrayof_integer_append()

integer function arrayof_integer_append ( type(arrayof_integer) this,
integer, intent(in) content )

Quick method to append an element to the array.

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

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

Definizione alla linea 5573 del file array_utilities.F90.

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