libsim Versione 7.1.11

◆ 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 5579 del file array_utilities.F90.

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