Changeset 12 for readTracFiles_mod.f90


Ignore:
Timestamp:
Feb 4, 2022, 3:39:33 PM (3 years ago)
Author:
dcugnet
Message:
  • Fix in sortTracers
  • New version of the addPhase routine taking the phase index as a second argument instead of the phase itself.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • readTracFiles_mod.f90

    r11 r12  
    3333  INTERFACE idxAncestor;   MODULE PROCEDURE idxAncestor_1, idxAncestor_m; END INTERFACE idxAncestor
    3434  INTERFACE    ancestor;   MODULE PROCEDURE    ancestor_1,    ancestor_m; END INTERFACE    ancestor
    35   INTERFACE    addPhase;   MODULE PROCEDURE    addPhase_1,    addPhase_m; END INTERFACE    addPhase
     35  INTERFACE    addPhase;   MODULE PROCEDURE   addPhase_s1,   addPhase_sm,   addPhase_i1,   addPhase_im; END INTERFACE addPhase
    3636!------------------------------------------------------------------------------------------------------------------------------
    3737
     
    152152      CLOSE(90)
    153153      DO ip = 1, nphases                                             !--- Deal with old water names
    154         oldH2O = 'H2O'//old_phases(ip:ip)
    155         newH2O = 'H2O'//phases_sep//known_phases(ip:ip)
     154        oldH2O = addPhase('H2O', ip, '')
     155        newH2O = addPhase('H2O', ip)
    156156        ix = strIdx(tracs(:)%name, oldH2O)
    157157        IF(ix == 0) CYCLE
     
    565565        trn=TRIM(tr(iq)%name); nam=trn                               !--- Tracer name (regular case)
    566566        IF(lTg) nam = TRIM(tr(iq)%parent)                            !--- Parent name (tagging case)
    567         IF(lEx) nam = TRIM(nam)//phases_sep//pha(ip:ip)              !--- Phase extension needed
     567        IF(lEx) nam = addPhase(nam, ip)                              !--- Phase extension needed
    568568        IF(lTg) nam = TRIM(nam)//'_'//TRIM(trn)                      !--- <parent>_<name> for tags
    569569        ttr(it) = tr(iq)                                             !--- Same <key>=<val> pairs
     
    572572        ttr(it)%phase = pha(ip:ip)                                   !--- Single phase entry
    573573        IF(lEx.AND.tr(iq)%iGeneration>1) THEN
    574           ttr(it)%parent   = TRIM(ttr(it)%parent)//phases_sep//pha(ip:ip)
    575           ttr(it)%gen0Name = TRIM(ttr(it)%gen0Name)//phases_sep//pha(ip:ip)
     574          ttr(it)%parent   = addPhase(ttr(it)%parent,   ip)          !--- Modify parent name
     575          ttr(it)%gen0Name = addPhase(ttr(it)%gen0Name, ip)          !--- Modify generation 0 ancestor name
    576576        END IF
    577577        it=it+1
     
    602602  iy = [(k, k=1, nq)]
    603603  DO ip = nphases, 1, -1
    604     iq = strIdx(tracers(:)%name, 'H2O'//phases_sep//known_phases(ip:ip))
    605     IF(iq/=0) iy = [iq, iy(1:iq-1), iy(iq:nq)]
     604    iq = strIdx(tr(:)%name, addPhase('H2O', ip))
     605    IF(iq/=0) iy = [iq, iy(1:iq-1), iy(iq+1:nq)]
    606606  END DO
    607607  tr = tr(iy)                                                        !--- Water displaces at first positions
     
    724724      tnam = TRIM(t1(iq)%name)                                       !--- Original name
    725725      IF(COUNT(t1%name == tnam) == 1) CYCLE                          !--- Current tracer is not duplicated: finished
    726       tnam_new = TRIM(tnam)//phases_sep//TRIM(sections(is)%name)     !--- Same with section extension
     726      tnam_new = TRIM(tnam)//'_'//TRIM(sections(is)%name)            !--- Same with section extension
    727727      nq = SUM(nt(1:is-1))                                           !--- Number of tracers in previous sections
    728728      ns = nt(is)                                                    !--- Number of tracers in the current section
     
    11541154  lerr = .FALSE.
    11551155  IF(PRESENT(ky)) THEN
    1156     val = getKeyByName_prv(keyn, tname , ky);    IF(val /= '') RETURN          !--- "ky" and "tnam"
     1156    val = getKeyByName_prv(keyn, tname, ky);              IF(val /= '') RETURN !--- "ky" and "tnam"
    11571157    val = getKeyByName_prv(keyn, delPhase(strHead(tname,'_')), ky)             !--- "ky" and "tnam" without phase
    11581158  ELSE
     
    11861186  CHARACTER(LEN=*), TARGET, OPTIONAL, INTENT(IN)  :: tnam(:)
    11871187  TYPE(keys_type),  TARGET, OPTIONAL, INTENT(IN)  ::   ky(:)
    1188   CHARACTER(LEN=maxlen),    POINTER :: n(:)
     1188  TYPE(keys_type),       POINTER :: k(:)
     1189  CHARACTER(LEN=maxlen), POINTER :: n(:)
    11891190  INTEGER :: iq
    1190   n => tracers(:)%keys%name; IF(PRESENT(tnam)) n => tnam(:)
     1191  k => tracers(:)%keys; IF(PRESENT(ky  )) k => ky
     1192  n => k(:)%name;       IF(PRESENT(tnam)) n => tnam
    11911193  ALLOCATE(val(SIZE(n)))
    1192   IF(     PRESENT(ky)) lerr = ANY([(getKeyByName_s1(keyn, val(iq), n(iq), ky), iq=1, SIZE(n))])
    1193   IF(.NOT.PRESENT(ky)) lerr = ANY([(getKeyByName_s1(keyn, val(iq), n(iq)),     iq=1, SIZE(n))])
     1194  lerr = ANY([(getKeyByName_s1(keyn, val(iq), n(iq), k), iq=1, SIZE(n))])
    11941195END FUNCTION getKeyByName_sm
    11951196!==============================================================================================================================
     
    12131214  CHARACTER(LEN=*), TARGET, OPTIONAL, INTENT(IN)  :: tnam(:)
    12141215  TYPE(keys_type),  TARGET, OPTIONAL, INTENT(IN)  ::   ky(:)
     1216  TYPE(keys_type),       POINTER :: k(:)
    12151217  CHARACTER(LEN=maxlen), POINTER :: n(:)
    12161218  INTEGER :: iq
    1217   n => tracers(:)%name; IF(PRESENT(tnam)) n => tnam(:)
     1219  k => tracers(:)%keys; IF(PRESENT(ky  )) k => ky
     1220  n => k(:)%name;       IF(PRESENT(tnam)) n => tnam
    12181221  ALLOCATE(val(SIZE(n)))
    1219   IF(     PRESENT(ky)) lerr = ANY([(getKeyByName_i1(keyn, val(iq), n(iq), ky), iq=1, SIZE(n))])
    1220   IF(.NOT.PRESENT(ky)) lerr = ANY([(getKeyByName_i1(keyn, val(iq), n(iq)),     iq=1, SIZE(n))])
     1222  lerr = ANY([(getKeyByName_i1(keyn, val(iq), n(iq), k), iq=1, SIZE(n))])
    12211223END FUNCTION getKeyByName_im
    12221224!==============================================================================================================================
     
    12401242  CHARACTER(LEN=*), TARGET, OPTIONAL, INTENT(IN)  :: tnam(:)
    12411243  TYPE(keys_type),  TARGET, OPTIONAL, INTENT(IN)  ::   ky(:)
     1244  TYPE(keys_type),       POINTER :: k(:)
    12421245  CHARACTER(LEN=maxlen), POINTER :: n(:)
    12431246  INTEGER :: iq
    1244   n => tracers(:)%name;  IF(PRESENT(tnam)) n => tnam(:)
     1247  k => tracers(:)%keys; IF(PRESENT(ky  )) k => ky
     1248  n => k(:)%name;       IF(PRESENT(tnam)) n => tnam
    12451249  ALLOCATE(val(SIZE(n)))
    1246   IF(     PRESENT(ky)) lerr = ANY([(getKeyByName_r1(keyn, val(iq), n(iq), ky), iq=1, SIZE(n))])
    1247   IF(.NOT.PRESENT(ky)) lerr = ANY([(getKeyByName_r1(keyn, val(iq), n(iq)),     iq=1, SIZE(n))])
     1250  lerr = ANY([(getKeyByName_r1(keyn, val(iq), n(iq), k), iq=1, SIZE(n))])
    12481251END FUNCTION getKeyByName_rm
    12491252!==============================================================================================================================
     
    12761279END FUNCTION delPhase
    12771280!------------------------------------------------------------------------------------------------------------------------------
    1278 CHARACTER(LEN=maxlen) FUNCTION addPhase_1(s,pha,ph_sep) RESULT(out)
     1281CHARACTER(LEN=maxlen) FUNCTION addPhase_s1(s,pha,ph_sep) RESULT(out)
    12791282  CHARACTER(LEN=*),           INTENT(IN) :: s
    12801283  CHARACTER(LEN=1),           INTENT(IN) :: pha
     
    12891292  IF(i == 0) out =  TRIM(s)//TRIM(psep)//pha                                   !--- <var>       => return <var><sep><pha>
    12901293  IF(i /= 0) out = s(1:i-1)//TRIM(psep)//pha//'_'//s(i+1:l)                    !--- <var>_<tag> => return <var><sep><pha>_<tag>
    1291 END FUNCTION addPhase_1
    1292 !------------------------------------------------------------------------------------------------------------------------------
    1293 FUNCTION addPhase_m(s,pha,ph_sep) RESULT(out)
     1294END FUNCTION addPhase_s1
     1295!------------------------------------------------------------------------------------------------------------------------------
     1296FUNCTION addPhase_sm(s,pha,ph_sep) RESULT(out)
    12941297  CHARACTER(LEN=*),           INTENT(IN) :: s(:)
    12951298  CHARACTER(LEN=1),           INTENT(IN) :: pha
     
    12991302  INTEGER :: k
    13001303  psep = phases_sep; IF(PRESENT(ph_sep)) psep = ph_sep
    1301   out = [( addPhase_1(s(k), pha, psep), k=1, SIZE(s) )]
    1302 END FUNCTION addPhase_m
     1304  out = [( addPhase_s1(s(k), pha, psep), k=1, SIZE(s) )]
     1305END FUNCTION addPhase_sm
     1306!------------------------------------------------------------------------------------------------------------------------------
     1307CHARACTER(LEN=maxlen) FUNCTION addPhase_i1(s,ipha,ph_sep) RESULT(out)
     1308  CHARACTER(LEN=*),           INTENT(IN) :: s
     1309  INTEGER,                    INTENT(IN) :: ipha
     1310  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: ph_sep
     1311  CHARACTER(LEN=1) :: psep
     1312  out = s
     1313  IF(s == '') RETURN                                                           !--- Empty string: nothing to do
     1314  psep = phases_sep; IF(PRESENT(ph_sep)) psep = ph_sep
     1315  IF(psep == '') out = addPhase_s1(s,   old_phases(ipha:ipha), psep)
     1316  IF(psep /= '') out = addPhase_s1(s, known_phases(ipha:ipha), psep)
     1317END FUNCTION addPhase_i1
     1318!------------------------------------------------------------------------------------------------------------------------------
     1319FUNCTION addPhase_im(s,ipha,ph_sep) RESULT(out)
     1320  CHARACTER(LEN=*),           INTENT(IN) :: s(:)
     1321  INTEGER,                    INTENT(IN) :: ipha
     1322  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: ph_sep
     1323  CHARACTER(LEN=maxlen),     ALLOCATABLE :: out(:)
     1324  CHARACTER(LEN=1) :: psep
     1325  INTEGER :: k
     1326  psep = phases_sep; IF(PRESENT(ph_sep)) psep = ph_sep
     1327  out = [( addPhase_i1(s(k), ipha, psep), k=1, SIZE(s) )]
     1328END FUNCTION addPhase_im
    13031329!------------------------------------------------------------------------------------------------------------------------------
    13041330
     
    13721398
    13731399END MODULE readTracFiles_mod
    1374 
Note: See TracChangeset for help on using the changeset viewer.