Changeset 2286 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jan 24, 2019, 3:02:17 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `multi_index_mat2DI': Subroutine to provide the indices of the different locations of a value inside a 2D integer matrix
  • `multi_index_mat3DI': Subroutine to provide the indices of the different locations of a value inside a 3D integer matrix
  • `multi_index_mat4DI': Subroutine to provide the indices of the different locations of a value inside a 4D integer matrix
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/module_scientific.f90

    r2282 r2286  
    2828! look_clockwise_borders: Subroutine to look clock-wise for a next point within a collection of borders
    2929!   (limits of a region)
     30! multi_index_mat2DI: Subroutine to provide the indices of the different locations of a value inside a 2D integer matrix
     31! multi_index_mat3DI: Subroutine to provide the indices of the different locations of a value inside a 3D integer matrix
     32! multi_index_mat4DI: Subroutine to provide the indices of the different locations of a value inside a 4D integer matrix
    3033! multi_index_mat2DRK: Subroutine to provide the indices of the different locations of a value inside a 2D RK matrix
    3134! multi_index_mat3DRK: Subroutine to provide the indices of the different locations of a value inside a 3D RK matrix
     
    52115214  END SUBROUTINE spaceweightstats
    52125215
     5216  SUBROUTINE multi_index_mat2DI(d1, d2, d12, mat, value, Nindices, indices)
     5217  ! Subroutine to provide the indices of the different locations of a value inside a 2D integer matrix
     5218
     5219    IMPLICIT NONE
     5220
     5221    INTEGER, INTENT(in)                                  :: d1, d2, d12
     5222    INTEGER, DIMENSION(d1,d2), INTENT(in)                :: mat
     5223    INTEGER,INTENT(in)                                   :: value
     5224    INTEGER, INTENT(out)                                 :: Nindices
     5225    INTEGER, DIMENSION(2,d12), INTENT(out)               :: indices
     5226
     5227! Local
     5228    INTEGER                                              :: i,j
     5229    INTEGER                                              :: Ncounts1D, icount1D
     5230    INTEGER, DIMENSION(d2)                               :: diffmat1D
     5231
     5232    !!!!!!! Variables
     5233    ! d1, d2: shape of the 2D matrix
     5234    ! mat: 2D matrix
     5235    ! value: value to be looking for
     5236    ! Nindices: number of times value found within matrix
     5237    ! indices: indices of the found values
     5238
     5239    fname = 'multi_index_mat2DI'
     5240
     5241    Nindices = 0
     5242    indices = 0
     5243    DO i=1, d1
     5244      diffmat1D = mat(i,:) - value
     5245      IF (ANY(diffmat1D == 0)) THEN
     5246        Ncounts1D = COUNT(diffmat1D == 0)
     5247        icount1D = 0
     5248        DO j=1, d2
     5249          IF (diffmat1D(j) == 0) THEN
     5250            Nindices = Nindices + 1
     5251            indices(1,Nindices) = i
     5252            indices(2,Nindices) = j
     5253            icount1D = icount1D + 1
     5254            IF (icount1D == Ncounts1D) EXIT
     5255          END IF
     5256        END DO
     5257      END IF
     5258    END DO
     5259
     5260  END SUBROUTINE multi_index_mat2DI
     5261
     5262  SUBROUTINE multi_index_mat3DI(d1, d2, d3, d123, mat, value, Nindices, indices)
     5263  ! Subroutine to provide the indices of the different locations of a value inside a 3D integer matrix
     5264
     5265    IMPLICIT NONE
     5266
     5267    INTEGER, INTENT(in)                                  :: d1, d2, d3, d123
     5268    INTEGER, DIMENSION(d1,d2,d3), INTENT(in)             :: mat
     5269    INTEGER, INTENT(in)                                  :: value
     5270    INTEGER, INTENT(out)                                 :: Nindices
     5271    INTEGER, DIMENSION(3,d123), INTENT(out)              :: indices
     5272
     5273! Local
     5274    INTEGER                                              :: i,j,k
     5275    INTEGER                                              :: Ncounts1D, icount1D
     5276    INTEGER                                              :: Ncounts2D, icount2D
     5277    INTEGER, DIMENSION(d2,d3)                            :: diffmat2D
     5278    INTEGER, DIMENSION(d3)                               :: diffmat1D
     5279
     5280    !!!!!!! Variables
     5281    ! d1, d2, d3: shape of the 3D matrix
     5282    ! mat: 3D matrix
     5283    ! value: value to be looking for
     5284    ! Nindices: number of times value found within matrix
     5285    ! indices: indices of the found values
     5286
     5287    fname = 'multi_index_mat3DI'
     5288
     5289    Nindices = 0
     5290    indices = 0
     5291    DO i=1, d1
     5292      diffmat2D = mat(i,:,:) - value
     5293      IF (ANY(diffmat2D == 0)) THEN
     5294        Ncounts2D = COUNT(diffmat2D == 0)
     5295        icount2D = 0
     5296        DO j=1, d2
     5297          diffmat1D = mat(i,j,:) - value
     5298          IF (ANY(diffmat1D == 0)) THEN
     5299            Ncounts1D = COUNT(diffmat1D == 0)
     5300            icount1D = 0
     5301            DO k=1, d3
     5302              IF (diffmat1D(k) == 0) THEN
     5303                Nindices = Nindices + 1
     5304                indices(1,Nindices) = i
     5305                indices(2,Nindices) = j
     5306                indices(3,Nindices) = k
     5307                icount1D = icount1D + 1
     5308                IF (icount1D == Ncounts1D) EXIT
     5309              END IF
     5310            END DO
     5311            icount2D = icount2D + icount1D
     5312            IF (icount2D == Ncounts2D) EXIT
     5313          END IF
     5314        END DO
     5315      END IF
     5316    END DO
     5317
     5318  END SUBROUTINE multi_index_mat3DI
     5319
     5320  SUBROUTINE multi_index_mat4DI(d1, d2, d3, d4, d1234, mat, value, Nindices, indices)
     5321  ! Subroutine to provide the indices of the different locations of a value inside a 4D integer matrix
     5322
     5323    IMPLICIT NONE
     5324
     5325    INTEGER, INTENT(in)                                  :: d1, d2, d3, d4, d1234
     5326    INTEGER, DIMENSION(d1,d2,d3,d4), INTENT(in)          :: mat
     5327    INTEGER, INTENT(in)                                  :: value
     5328    INTEGER, INTENT(out)                                 :: Nindices
     5329    INTEGER, DIMENSION(4,d1234), INTENT(out)             :: indices
     5330
     5331! Local
     5332    INTEGER                                              :: i,j,k,l
     5333    INTEGER                                              :: Ncounts1D, icount1D
     5334    INTEGER                                              :: Ncounts2D, icount2D
     5335    INTEGER                                              :: Ncounts3D, icount3D
     5336    INTEGER, DIMENSION(d2,d3,d4)                         :: diffmat3D
     5337    INTEGER, DIMENSION(d3,d4)                            :: diffmat2D
     5338    INTEGER, DIMENSION(d4)                               :: diffmat1D
     5339
     5340    !!!!!!! Variables
     5341    ! d1, d2, d3, d4: shape of the 4D matrix
     5342    ! mat: 4D matrix
     5343    ! value: value to be looking for
     5344    ! Nindices: number of times value found within matrix
     5345    ! indices: indices of the found values
     5346
     5347    fname = 'multi_index_mat4DI'
     5348
     5349    Nindices = 0
     5350    indices = 0
     5351    DO i=1, d1
     5352      diffmat3D = mat(i,:,:,:) - value
     5353      IF (ANY(diffmat3D == 0)) THEN
     5354        Ncounts3D = COUNT(diffmat3D == 0)
     5355        icount3D = 0
     5356        DO j=1, d2
     5357          diffmat2D = mat(i,j,:,:) - value
     5358          IF (ANY(diffmat2D == 0)) THEN
     5359            Ncounts2D = COUNT(diffmat2D == 0)
     5360            icount2D = 0
     5361            DO k=1, d3
     5362              diffmat1D = mat(i,j,k,:) - value
     5363              IF (ANY(diffmat1D == 0)) THEN
     5364                Ncounts1D = COUNT(diffmat1D == 0)
     5365                icount1D = 0
     5366                DO l=1, d4
     5367                  IF (diffmat1D(l) == 0) THEN
     5368                    Nindices = Nindices + 1
     5369                    indices(1,Nindices) = i
     5370                    indices(2,Nindices) = j
     5371                    indices(3,Nindices) = k
     5372                    indices(4,Nindices) = l
     5373                    icount1D = icount1D + 1
     5374                    IF (icount1D == Ncounts1D) EXIT
     5375                  END IF
     5376                END DO
     5377              icount2D = icount2D + icount1D
     5378              IF (icount2D == Ncounts2D) EXIT
     5379              END IF
     5380            END DO
     5381            icount3D = icount3D + icount1D
     5382            IF (icount3D == Ncounts3D) EXIT
     5383          END IF
     5384        END DO
     5385      END IF
     5386    END DO
     5387
     5388  END SUBROUTINE multi_index_mat4DI
    52135389
    52145390  SUBROUTINE multi_index_mat2DRK(d1, d2, d12, mat, value, Nindices, indices)
Note: See TracChangeset for help on using the changeset viewer.