libsim Versione 7.1.11

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

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