libsim Versione 7.1.11

◆ arrayof_real_append()

integer function arrayof_real_append ( type(arrayof_real this,
real, 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 REAL to append

Definizione alla linea 5860 del file array_utilities.F90.

5861! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
5862! authors:
5863! Davide Cesari <dcesari@arpa.emr.it>
5864! Paolo Patruno <ppatruno@arpa.emr.it>
5865
5866! This program is free software; you can redistribute it and/or
5867! modify it under the terms of the GNU General Public License as
5868! published by the Free Software Foundation; either version 2 of
5869! the License, or (at your option) any later version.
5870
5871! This program is distributed in the hope that it will be useful,
5872! but WITHOUT ANY WARRANTY; without even the implied warranty of
5873! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5874! GNU General Public License for more details.
5875
5876! You should have received a copy of the GNU General Public License
5877! along with this program. If not, see <http://www.gnu.org/licenses/>.
5878
5879
5880
5883#include "config.h"
5884MODULE array_utilities
5885
5886IMPLICIT NONE
5887
5888! la routine per i char non puo' essere sviluppata in macro perche` si deve scrivere diversa
5889!cosi' esiste la function count_distinctc (senza _ ) e la subroutine pack_distinctc qui ivi scritte
5890
5891#undef VOL7D_POLY_TYPE_AUTO
5892
5893#undef VOL7D_POLY_TYPE
5894#undef VOL7D_POLY_TYPES
5895#define VOL7D_POLY_TYPE INTEGER
5896#define VOL7D_POLY_TYPES _i
5897#define ENABLE_SORT
5898#include "array_utilities_pre.F90"
5899#undef ENABLE_SORT
5900
5901#undef VOL7D_POLY_TYPE
5902#undef VOL7D_POLY_TYPES
5903#define VOL7D_POLY_TYPE REAL
5904#define VOL7D_POLY_TYPES _r
5905#define ENABLE_SORT
5906#include "array_utilities_pre.F90"
5907#undef ENABLE_SORT
5908
5909#undef VOL7D_POLY_TYPE
5910#undef VOL7D_POLY_TYPES
5911#define VOL7D_POLY_TYPE DOUBLEPRECISION
5912#define VOL7D_POLY_TYPES _d
5913#define ENABLE_SORT
5914#include "array_utilities_pre.F90"
5915#undef ENABLE_SORT
5916
5917#define VOL7D_NO_PACK
5918#undef VOL7D_POLY_TYPE
5919#undef VOL7D_POLY_TYPES
5920#define VOL7D_POLY_TYPE CHARACTER(len=*)
5921#define VOL7D_POLY_TYPE_AUTO(var) CHARACTER(len=LEN(var))
5922#define VOL7D_POLY_TYPES _c
5923#define ENABLE_SORT
5924#include "array_utilities_pre.F90"
5925#undef VOL7D_POLY_TYPE_AUTO
5926#undef ENABLE_SORT
5927
5928
5929#define ARRAYOF_ORIGEQ 1
5930
5931#define ARRAYOF_ORIGTYPE INTEGER
5932#define ARRAYOF_TYPE arrayof_integer
5933#include "arrayof_pre.F90"
5934
5935#undef ARRAYOF_ORIGTYPE
5936#undef ARRAYOF_TYPE
5937#define ARRAYOF_ORIGTYPE REAL
5938#define ARRAYOF_TYPE arrayof_real
5939#include "arrayof_pre.F90"
5940
5941#undef ARRAYOF_ORIGTYPE
5942#undef ARRAYOF_TYPE
5943#define ARRAYOF_ORIGTYPE DOUBLEPRECISION
5944#define ARRAYOF_TYPE arrayof_doubleprecision
5945#include "arrayof_pre.F90"
5946
5947#undef ARRAYOF_ORIGEQ
5948
5949#undef ARRAYOF_ORIGTYPE
5950#undef ARRAYOF_TYPE
5951#define ARRAYOF_ORIGTYPE LOGICAL
5952#define ARRAYOF_TYPE arrayof_logical
5953#include "arrayof_pre.F90"
5954
5955PRIVATE
5956! from arrayof
5958PUBLIC insert_unique, append_unique
5959
5960PUBLIC sort, index, index_c, &
5961 count_distinct_sorted, pack_distinct_sorted, &
5962 count_distinct, pack_distinct, count_and_pack_distinct, &
5963 map_distinct, map_inv_distinct, &
5964 firsttrue, lasttrue, pack_distinct_c, map
5965
5966CONTAINS
5967
5968
5971FUNCTION firsttrue(v) RESULT(i)
5972LOGICAL,INTENT(in) :: v(:)
5973INTEGER :: i
5974
5975DO i = 1, SIZE(v)
5976 IF (v(i)) RETURN
5977ENDDO
5978i = 0
5979
5980END FUNCTION firsttrue
5981
5982
5985FUNCTION lasttrue(v) RESULT(i)
5986LOGICAL,INTENT(in) :: v(:)
5987INTEGER :: i
5988
5989DO i = SIZE(v), 1, -1
5990 IF (v(i)) RETURN
5991ENDDO
5992
5993END FUNCTION lasttrue
5994
5995
5996! Definisce le funzioni count_distinct(_sorted) e pack_distinct(_sorted)
5997#undef VOL7D_POLY_TYPE_AUTO
5998#undef VOL7D_NO_PACK
5999
6000#undef VOL7D_POLY_TYPE
6001#undef VOL7D_POLY_TYPES
6002#define VOL7D_POLY_TYPE INTEGER
6003#define VOL7D_POLY_TYPES _i
6004#define ENABLE_SORT
6005#include "array_utilities_inc.F90"
6006#undef ENABLE_SORT
6007
6008#undef VOL7D_POLY_TYPE
6009#undef VOL7D_POLY_TYPES
6010#define VOL7D_POLY_TYPE REAL
6011#define VOL7D_POLY_TYPES _r
6012#define ENABLE_SORT
6013#include "array_utilities_inc.F90"
6014#undef ENABLE_SORT
6015
6016#undef VOL7D_POLY_TYPE
6017#undef VOL7D_POLY_TYPES
6018#define VOL7D_POLY_TYPE DOUBLEPRECISION
6019#define VOL7D_POLY_TYPES _d
6020#define ENABLE_SORT
6021#include "array_utilities_inc.F90"
6022#undef ENABLE_SORT
6023
6024#define VOL7D_NO_PACK
6025#undef VOL7D_POLY_TYPE
6026#undef VOL7D_POLY_TYPES
6027#define VOL7D_POLY_TYPE CHARACTER(len=*)
6028#define VOL7D_POLY_TYPE_AUTO(var) CHARACTER(len=LEN(var))
6029#define VOL7D_POLY_TYPES _c
6030#define ENABLE_SORT
6031#include "array_utilities_inc.F90"
6032#undef VOL7D_POLY_TYPE_AUTO
6033#undef ENABLE_SORT
6034
6035SUBROUTINE pack_distinct_c(vect, pack_distinct, mask, back) !RESULT(pack_distinct)
6036CHARACTER(len=*),INTENT(in) :: vect(:)
6037LOGICAL,INTENT(in),OPTIONAL :: mask(:), back
6038CHARACTER(len=LEN(vect)) :: pack_distinct(:)
6039
6040INTEGER :: count_distinct
6041INTEGER :: i, j, dim
6042LOGICAL :: lback
6043
6044dim = SIZE(pack_distinct)
6045IF (PRESENT(back)) THEN
6046 lback = back
6047ELSE
6048 lback = .false.
6049ENDIF
6050count_distinct = 0
6051
6052IF (PRESENT (mask)) THEN
6053 IF (lback) THEN
6054 vectm1: DO i = 1, SIZE(vect)
6055 IF (.NOT.mask(i)) cycle vectm1
6056! DO j = i-1, 1, -1
6057! IF (vect(j) == vect(i)) CYCLE vectm1
6058 DO j = count_distinct, 1, -1
6059 IF (pack_distinct(j) == vect(i)) cycle vectm1
6060 ENDDO
6061 count_distinct = count_distinct + 1
6062 IF (count_distinct > dim) EXIT
6063 pack_distinct(count_distinct) = vect(i)
6064 ENDDO vectm1
6065 ELSE
6066 vectm2: DO i = 1, SIZE(vect)
6067 IF (.NOT.mask(i)) cycle vectm2
6068! DO j = 1, i-1
6069! IF (vect(j) == vect(i)) CYCLE vectm2
6070 DO j = 1, count_distinct
6071 IF (pack_distinct(j) == vect(i)) cycle vectm2
6072 ENDDO
6073 count_distinct = count_distinct + 1
6074 IF (count_distinct > dim) EXIT
6075 pack_distinct(count_distinct) = vect(i)
6076 ENDDO vectm2
6077 ENDIF
6078ELSE
6079 IF (lback) THEN
6080 vect1: DO i = 1, SIZE(vect)
6081! DO j = i-1, 1, -1
6082! IF (vect(j) == vect(i)) CYCLE vect1
6083 DO j = count_distinct, 1, -1
6084 IF (pack_distinct(j) == vect(i)) cycle vect1
6085 ENDDO
6086 count_distinct = count_distinct + 1
6087 IF (count_distinct > dim) EXIT
6088 pack_distinct(count_distinct) = vect(i)
6089 ENDDO vect1
6090 ELSE
6091 vect2: DO i = 1, SIZE(vect)
6092! DO j = 1, i-1
6093! IF (vect(j) == vect(i)) CYCLE vect2
6094 DO j = 1, count_distinct
6095 IF (pack_distinct(j) == vect(i)) cycle vect2
6096 ENDDO
6097 count_distinct = count_distinct + 1
6098 IF (count_distinct > dim) EXIT
6099 pack_distinct(count_distinct) = vect(i)
6100 ENDDO vect2
6101 ENDIF
6102ENDIF
6103
6104END SUBROUTINE pack_distinct_c
6105
6107FUNCTION map(mask) RESULT(mapidx)
6108LOGICAL,INTENT(in) :: mask(:)
6109INTEGER :: mapidx(count(mask))
6110
6111INTEGER :: i,j
6112
6113j = 0
6114DO i=1, SIZE(mask)
6115 j = j + 1
6116 IF (mask(i)) mapidx(j)=i
6117ENDDO
6118
6119END FUNCTION map
6120
6121#define ARRAYOF_ORIGEQ 1
6122
6123#undef ARRAYOF_ORIGTYPE
6124#undef ARRAYOF_TYPE
6125#define ARRAYOF_ORIGTYPE INTEGER
6126#define ARRAYOF_TYPE arrayof_integer
6127#include "arrayof_post.F90"
6128
6129#undef ARRAYOF_ORIGTYPE
6130#undef ARRAYOF_TYPE
6131#define ARRAYOF_ORIGTYPE REAL
6132#define ARRAYOF_TYPE arrayof_real
6133#include "arrayof_post.F90"
6134
6135#undef ARRAYOF_ORIGTYPE
6136#undef ARRAYOF_TYPE
6137#define ARRAYOF_ORIGTYPE DOUBLEPRECISION
6138#define ARRAYOF_TYPE arrayof_doubleprecision
6139#include "arrayof_post.F90"
6140
6141#undef ARRAYOF_ORIGEQ
6142
6143#undef ARRAYOF_ORIGTYPE
6144#undef ARRAYOF_TYPE
6145#define ARRAYOF_ORIGTYPE LOGICAL
6146#define ARRAYOF_TYPE arrayof_logical
6147#include "arrayof_post.F90"
6148
6149END 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.