Boucle fichiers

Bonjour,
j’ai un programme avec une boucle, et je voudrais enregistrer plusieurs fichiers (data.txt ) à chaque passage créer un fichier dont le nom dépend de l’indice

merci pour votre aide .

program ex4
open(10,file=‘data.txt’)
do x=0,5,0.5
f=fct_data(x)
write(10,) x,f
write(
,’(2f7.2)’)x ,f
enddo
end

function fct_data(x)
fct_data=2*x**2 +1
return
end

Welcome Said, I will reply both in French and English (is there an official language on Fortran-lang?)
Bienvenue Said, je répondrai à la fois en français et en anglais (y a-t-il une langue officielle sur Fortran-lang ?)

You can use that kind of code to create your filenames:
Tu peux utiliser ce genre de code pour créer tes noms de fichiers:

WRITE(nom,*) x
nom = TRIM('data'//ADJUSTL(nom))//'.txt'
OPEN (UNIT=1O, FILE=nom)

In my case, x was an integer. Perhaps you will have adapt the code.
Dans mon cas, x était un entier. Peut-être que tu devras adapter le code.

Sorry, for the others, I’ll reply only in French.

Bonjour Said et bienvenue.

Pour compléter la réponse précédente. L’indice d’une boucle en fortran doit être un entier (la possibilité d’utiliser un réel a été supprimée).
Probablement, vous devriez vous documenter sur le language fortran. Par exemple en français :

http://www.idris.fr/media/formations/fortran/idris_fortran_base_cours.pdf

Il y a aussi une discussion sur ce forum à propos de livres et documentations (en anglais) :

https://fortran-lang.discourse.group/t/books-for-the-learn-page/

1 Like

Please let’s only use English on this Forum, so that others can participate.

If there is interest, we can setup a Forum in other languages also, but I don’t speak French, so I wouldn’t be able to monitor it.

Sure, sorry about that.

No problem at all, thank you for participating!

Following the ongoing discussion on the use of other (human) languages, as a demonstration, this is the raw automatic translations of @said 's question and @gardhor 's answer, from French to English, obtained with https://www.deepl.com/home


Hello,
I have a program with a loop, and I would like to save several files (data.txt ): at each run create a file whose name depends on the index

thank you for your help.

program ex4
open(10,file=‘data.txt’)


Hello Said and welcome.

To complete the previous answer. The index of a loop in fortran must be an integer (the possibility to use a real has been removed).
Probably, you should read up on the fortran language. For example in French :

http://www.idris.fr/media/formations/fortran/idris_fortran_base_cours.pdf 2

There is also a discussion on this forum about books and documentations:

https://fortran-lang.discourse.group/t/books-for-the-learn-page/

Translated with www.DeepL.com/Translator (free version)


Note the “2” character at the end of the first link, which is the number of times the initial link was clicked. I kept it on purpose, but we should of course remove it to avoid confusion.
In Said’s question, I have just added a “:” after (data.txt ) in the French text to improve clarity.

2 Likes

I’ve planed to do it as well, thanks.
I’m impressed by the quality of the translation.

1 Like