FillStrings Subroutine

public subroutine FillStrings(IniFile)

Uses

  • proc~~fillstrings~~UsesGraph proc~fillstrings FillStrings module~modgvec_mpi MODgvec_MPI proc~fillstrings->module~modgvec_mpi

Read ini file and put each line in a string object. All string objects are connected to a list of string objects starting with "firstString". MUST BE CALLED IN THE VERY BEGINNING OF THE PROGRAM!

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: IniFile

Name of ini file to be read in


Calls

proc~~fillstrings~~CallsGraph proc~fillstrings FillStrings interface~deletestring DeleteString proc~fillstrings->interface~deletestring interface~enter_subregion enter_subregion proc~fillstrings->interface~enter_subregion interface~exit_subregion exit_subregion proc~fillstrings->interface~exit_subregion interface~getnewstring GetNewString proc~fillstrings->interface~getnewstring interface~lowcase LowCase proc~fillstrings->interface~lowcase interface~par_bcast par_Bcast proc~fillstrings->interface~par_bcast proc~remove_blanks remove_blanks proc~fillstrings->proc~remove_blanks proc~replace replace proc~fillstrings->proc~replace proc~split split proc~fillstrings->proc~split interface~deletestring->interface~deletestring interface~enter_subregion->interface~enter_subregion interface~exit_subregion->interface~exit_subregion interface~getnewstring->interface~getnewstring interface~lowcase->interface~lowcase proc~par_bcast_array1d par_Bcast_array1D interface~par_bcast->proc~par_bcast_array1d proc~par_bcast_array1d_int par_Bcast_array1D_int interface~par_bcast->proc~par_bcast_array1d_int proc~par_bcast_array1d_str par_Bcast_array1D_str interface~par_bcast->proc~par_bcast_array1d_str proc~par_bcast_array2d par_Bcast_array2D interface~par_bcast->proc~par_bcast_array2d proc~par_bcast_scalar par_Bcast_scalar interface~par_bcast->proc~par_bcast_scalar proc~par_bcast_scalar_int par_Bcast_scalar_int interface~par_bcast->proc~par_bcast_scalar_int proc~par_bcast_scalar_str par_Bcast_scalar_str interface~par_bcast->proc~par_bcast_scalar_str

Source Code

SUBROUTINE FillStrings(IniFile)
! MODULES
USE MODgvec_MPI, ONLY: par_BCast
IMPLICIT NONE
!-----------------------------------------------------------------------------------------------------------------------------------
! INPUT/OUTPUT VARIABLES
CHARACTER(LEN=*),INTENT(IN)            :: IniFile                    !! Name of ini file to be read in
!-----------------------------------------------------------------------------------------------------------------------------------
! OUTPUT VARIABLES
!-----------------------------------------------------------------------------------------------------------------------------------
! LOCAL VARIABLES
TYPE(tString),POINTER          :: Str1=>NULL(),Str2=>NULL()
CHARACTER(LEN=MAXLEN)          :: HelpStr,Str
CHARACTER(LEN=300)             :: Filename
INTEGER                        :: stat,iniUnit,nLines,i !<<<<
LOGICAL                        :: file_exists !<<<<
CHARACTER(LEN=MAXLEN),ALLOCATABLE :: FileContent(:) !<<<<
CHARACTER(LEN=1)               :: tmpChar='' !<<<<
!===================================================================================================================================
! do nothing if FillStrings was already called
IF (ReadInDone) RETURN
CALL enter_subregion("read-parameterfile")
!READ FROM FILE ONLY ON MPIroot
IF(MPIroot)THEN !<<<<
  FileName = TRIM(IniFile)
  ! Get name of ini file
  WRITE(UNIT_StdOut,*)'| Reading from file "',TRIM(filename),'":'
  INQUIRE(FILE=TRIM(filename), EXIST=file_exists)
  IF (.NOT.file_exists) THEN
    CALL Abort(__STAMP__,&
        "parameter file '"//TRIM(filename)//"' file does not exist.",TypeInfo="FileNotFoundError")
  END IF

  OPEN(NEWUNIT= iniUnit,        &
       FILE   = TRIM(filename), &
       STATUS = 'OLD',          &
       ACTION = 'READ',         &
       ACCESS = 'SEQUENTIAL',   &
       IOSTAT = stat)
  IF(stat.NE.0)THEN
    CALL abort(__STAMP__,&
      "Could not open parameter file '"//TRIM(filename)//"'.")
  END IF

  ! parallel IO: ROOT reads file and sends it to all other procs
  nLines=0
  stat=0
  DO
    READ(iniunit,"(A)",IOSTAT=stat)tmpChar
    IF(stat.NE.0)EXIT
    nLines=nLines+1
  END DO
END IF !MPIroot !<<<<

!broadcast number of lines, read and broadcast file content
CALL par_BCast(nLines,0)
ALLOCATE(FileContent(nLines))

IF(MPIroot)THEN !<<<<
  !read file
  REWIND(iniUnit)
  READ(iniUnit,'(A)') FileContent
  CLOSE(iniUnit)
END IF !MPIroot !<<<<
!BROADCAST FileContent
CALL par_BCast(FileContent,0)
!#if MPI
!CALL MPI_BCAST(FileContent,LEN(FileContent)*nLines,MPI_CHARACTER,0,worldComm,iError) !<<<<
!#endif

NULLIFY(Str1,Str2)
DO i=1,nLines !<<<<
  IF(.NOT.ASSOCIATED(Str1)) CALL GetNewString(Str1)
  ! Read line from file
  Str=FileContent(i)
  ! Remove comments with "!"
  CALL Split(Str,Str,"!")
  ! Remove comments with "#"
  CALL Split(Str,Str,"#")
  Str=remove_blanks(Str)
  Str=Replace(Str,"(/","")
  Str=Replace(Str,"/)","")
  ! Replace brackets
  ! DO NOT Replace commas, used for array dimensions!
  !Str1%Str=Replace(Str1%Str,","," ")
  ! Lower case
  CALL LowCase(TRIM(Str),HelpStr)
  ! If we have a remainder (no comment only)
  IF(LEN_TRIM(HelpStr).GT.2) THEN
    Str1%Str=TRIM(HelpStr)
    IF(.NOT.ASSOCIATED(Str2)) THEN
      FirstString=>Str1
    ELSE
      Str2%NextStr=>Str1
      Str1%PrevStr=>Str2
    END IF
    Str2=>Str1
    CALL GetNewString(Str1)
  END IF
END DO
DEALLOCATE(FileContent)

!find line continuation "&" and merge strings (can be multiple lines)
Str1=>FirstString
DO WHILE (ASSOCIATED(Str1))
  IF(INDEX((Str1%str),'&').NE.0)THEN !found "&"
    CALL Split(Str1%Str,HelpStr,"&") !take part in front of "&"
    Str2=>Str1%nextStr
#if(!defined(NVHPC))
    DEALLOCATE(Str1%Str)
#endif /* ONLY NVHPC COMPILER DOES NOT SEEM TO WORK WITH ALLOCATABLE CHARACTERS (SIGSEV!) */
    Str1%Str=TRIM(HelpStr)//TRIM(Str2%Str)
    CALL deleteString(Str2)
    !do not go to next  string as long as there are "&" in the string
  ELSE
    Str1=>Str1%NextStr !nothing to be done
  END IF
END DO
!check len_trim<MAXLEN
Str1=>FirstString
DO WHILE (ASSOCIATED(Str1))
  IF(LEN_TRIM(Str1%Str).EQ.MAXLEN)THEN
    CALL abort(__STAMP__,&
      "parameter file readin: Line of input file might be longer than MAXLEN.",Intinfo=MAXLEN)
  END IF
  Str1=>Str1%NextStr !nothing to be done
END DO

ReadInDone = .TRUE.
CALL exit_subregion("read-parameterfile")
END SUBROUTINE FillStrings