I am using a small Python script. Sorry, no time to translate from French. Just know that a âfichierâ is a file and a ârĂ©pertoireâ means a directory. All the .f90
files in the given directory are âtranslatedâ. Only the Fortran instructions listed in the list are put in lower case. A copy .f90~
of each file is made before transformation. The input files must be encoded in UTF-8. A command such as $ recode ISO-8859-15..UTF-8 *.f90
can be useful.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Mettre en minuscule les instructions Fortran de fichiers *.f90
#
# ATTENTION, il faut d'abord convertir les fichiers en UTF-8 pour Ă©viter les problĂšmes de codage :
# recode ISO-8859-15..UTF-8 *.f90
# Ensuite, mettre dans la variable répertoire le chemin à traiter.
#
# vmagnin, 06-10-2016, mis Ă jour le 05-12-2016
import os
import shutil
instructions = ("IMPLICIT NONE", "INTEGER", "DOUBLE PRECISION", "CHARACTER(", "COMPLEX(", "LOGICAL", "PARAMETER", "TYPE(", "TYPE (", "DIMENSION(", "DIMENSION (", "SIZE(", "PROGRAM ", "SUBROUTINE", "FUNCTION", "RETURN", "PURE ", "RESULT(", "NINT(", "INT(", "HUGE(", "USE ", "MODULE", "CONTAINS", "WHILE ", "REAL(", "AIMAG(", "KIND", "CALL ", "ALLOCATE(", "ALLOCATABLE", "SELECT CASE", "CASE(", "CASE (", "CASE DEFAULT", "END SELECT", "IF (", "IF(", "END IF", "ENDIF", "ELSE", " THEN", ".TRUE.", ".FALSE.", ".AND.", ".OR.", ".NOT.", ".EQ.", ".NE.", ".LT.", ".LE.", ".GT.", ".GE.", "OPEN(", "UNIT=", "FILE=", "TITLE=", "WRITE(", "FORMAT(", "CLOSE(", "END DO", "ENDDO", "DO ", "INTENT(IN)", "INTENT(OUT)", "INTENT(INOUT)", "ABS", "DSQRT(", "SQRT(", "MOD(", "MIN(", "MAX(", "DBLE(", "EXP(", "SIN(", "COS(", "SUM(", "LOG(", "DATE_AND_TIME(", "RANDOM_NUMBER(", "RANDOM_SEED(", "STOP", "PRINT", "END ", "LEN=", "SETMESSAGEQQ(", "QWIN$MSG_RUNNING", "QWIN$MSG_TERM", "QWIN$MSG_EXITQ", "ABOUTBOXQQ", "QWIN$MAX", "QWIN$FRAMEWINDOW", "GETACTIVEQQ(", "SETWSIZEQQ(", "SETCOLORRGB", "SETBKCOLORRGB(", "$GCLEARSCREEN", "CLEARSCREEN", "QWIN$SET", "SETACTIVEQQ(", "SAVEIMAGE(", "GETWINDOWCONFIG(", "SETWINDOWCONFIG(", "SETPIXELrgb_w", "MOVETO_W", "LINETO_W", "GETTIM(", )
repertoire = "/home/vmagnin/workingdir/"
fichiers = tuple(os.walk(repertoire))
for fichier in fichiers[0][2]:
if fichier.endswith(".f90"):
print(fichier)
# Sauvegarde du fichier :
shutil.copy2(repertoire+fichier, repertoire+fichier+"~")
# On charge le fichier (attention à l'encodage du fichier de départ...) :
whole_file = open(repertoire+fichier, 'r').read()
# Instructions Fortran en minuscules :
for instruction in instructions:
whole_file2 = whole_file.replace(instruction, instruction.lower())
whole_file = whole_file2
# On Ă©crase le fichier initial :
whole_file3 = open(repertoire+fichier, 'w').write(whole_file)
print("N'oubliez pas d'effacer les fichiers de sauvegarde aprÚs vérification !")