libsim Versione 7.2.0

◆ arrayof_integer_insert()

subroutine arrayof_integer_insert ( type(arrayof_integer this,
integer, intent(in)  content,
integer, intent(in), optional  pos 
)

Method for inserting an element of the array at a desired position.

If necessary, the array is reallocated to accomodate the new element.

Parametri
thisarray object to extend
[in]contentobject of TYPE INTEGER to insert
[in]posposition where to insert, if it is out of range, it is clipped, if it is not provided, the object is appended

Definizione alla linea 5560 del file array_utilities.F90.

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