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!
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | IniFile |
Name of ini file to be read in |
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 !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__,& "Ini file does not exist.") 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 ini file.") 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 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. END SUBROUTINE FillStrings