Changeset 1619 in lmdz_wrf


Ignore:
Timestamp:
Sep 7, 2017, 2:50:38 PM (8 years ago)
Author:
lfita
Message:

Adding:

  • `split: Subroutine which provides the values from a string [String] which has been split by a given character [charv] a given number of values [Nvalues] is expected
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/module_generic.f90

    r1615 r1619  
    1010! Index1DArrayR_K: Function to provide the first index of a given value inside a 1D real(r_k) array
    1111! Index2DArrayR: Function to provide the first index of a given value inside a 2D real array
     12! mat2DPosition: Function to provide the i, j indices of a given value inside a 2D matrix
    1213! Nstrings: Function to repeat a number of times a given string
    1314! RangeI: Function to provide a range of d1 values from 'iniv' to 'endv', of integer values in a vector
    1415! RangeR: Function to provide a range of d1 values from 'iniv' to 'endv', of real values in a vector
    1516! RangeR_K: Function to provide a range of d1 from 'iniv' to 'endv', of real(r_k) values in a vector
     17! split: Subroutine which provides the values from a string [String] which has been split by a given
     18!   character [charv] a given number of values [Nvalues] is expected
    1619! vectorR_KS: Function to transform a vector of reals to a string of characters
    1720
     
    283286  END FUNCTION RangeR_K
    284287
     288  SUBROUTINE split(String,charv,Nvalues,values)
     289! Subroutine which provides the values from a string [String] which has been split by a given
     290!   character [charv] a given number of values [Nvalues] is expected
     291
     292    IMPLICIT NONE
     293
     294    CHARACTER(LEN=1000), INTENT(IN)                        :: String
     295    CHARACTER(LEN=1), INTENT(IN)                           :: charv
     296    INTEGER, INTENT(IN)                                    :: Nvalues
     297    CHARACTER(LEN=200), INTENT(OUT), DIMENSION(Nvalues)    :: values
     298
     299! Local
     300    INTEGER                                                :: i, ibeg, iend, Lstring
     301    CHARACTER(LEN=3)                                       :: numS
     302    CHARACTER(LEN=1000)                                    :: newString
     303
     304!!!!!!! Variables
     305! String: String to split
     306! charv: Character to use
     307! Nvalues: number of values
     308! values: vector with the given values (up to 200 characters)
     309
     310    fname = 'split'
     311
     312    newString = String
     313    ibeg = 1
     314    Lstring = LEN_TRIM(String)
     315
     316    DO i=1,Nvalues-1
     317      iend = INDEX(newString(ibeg:Lstring), charv)
     318
     319      IF (iend == 0) THEN
     320        WRITE (numS,"(I3)")Nvalues - 1
     321        msg = "String '" // TRIM(String) // "' does not have " // TRIM(numS) // " '" // charv // "' !!"
     322        CALL ErrMsg(msg, fname, -1)
     323      END IF
     324
     325      values(i) = newString(ibeg:ibeg+iend-2)
     326      ibeg = ibeg+iend
     327    END DO
     328    values(Nvalues) = newString(ibeg:Lstring)
     329
     330  END SUBROUTINE split
    285331
    286332SUBROUTINE ErrMsg(msg, funcn, errN)
Note: See TracChangeset for help on using the changeset viewer.