Vérifier si un fichier existe en Fortran

Pour vérifier si un fichier existe en Fortran il existe la fonction fortran INQUIRE. Exemple d'utilisation avec un programme minimaliste en fortran 90 (test.f90):

program test

logical :: file_exists

INQUIRE(FILE="inputs.txt", EXIST=file_exists)

write(6,*) file_exists

end

Après compilation et exécution du code

gfortran test.f90 -o test
test

on obtient

F si le fichier inputs.txt n'existe pas 
T si le fichier inputs.txt existe

Recherches associées