Fortran 77 : Recherche d'un emplacement de fichier

Fermé
Frost - 24 mai 2017 à 17:53
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 - 1 juin 2017 à 08:42
Bonjour à tous,

Voici ma question :

Comment peut on avoir accès en fortran au chemin d'accès du fichier que l'on est en train de coder. La problématique est la suivante :

Je code régulièrement en fortran et je crée des sorties textes dans le même emplacement fichier que mon code source. Mais il m'arrive régulièrement de changer de poste de travail et mes codes deviennent obsolètes car l'emplacement du fichier txt n'est plus le même.

Or i lest très simple avec excel par exemple de connaitre l'emplacement fichier cellule("adresse",A1). Est il possible de faire pareil en fortran pour ensuite créer un string qui sera le nom d'emplacement fichier désiré?

Merci pour vos réponses

Nicolas
A voir également:

2 réponses

f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701
24 mai 2017 à 19:54
Bonjour,
Une façon de faire :
Créez un fichier txt avec le paramétrage du chemin du poste que vous utilisez. Ensuite, lisez ce fichier à chaque que vous lancez vos exe. Évidemment, pensez à modifier ce fichier au moment du changement de poste
0
Bonjour F894009,

Tout d'abord merci de ta réponse.

Ceci est une solution qui ne règle pas mon problème car je veux automatiser pour que cela marche malgré un changement de poste.

As tu d'autres idées ?

Je pensais aller chercher le chemin avec un excel mais comment ouvrir le texte d'un fichier excel ?

Cordialement,
0
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701
30 mai 2017 à 14:24
Bonjour,
Ecrivez un fichier txt avec le vba excel, vu que vous allez cherchez le chemin par le fichier excel
0
Du coup j'ai créer une fonction VBA qui me permet de changer le texte d'un fichier. LE code marche très bien sauf si je l'applique à un fichier fortran. Dans ce cas j'e n'arrive pas à modifier la ligne.

En cherchant je crois que j'ai un problème d'encodage mais je n'arrive pas à trouver de fonction encoder decoder pour le fortran/VBA.

Quelqu'un peut m'aider??
Sub extraction()

Dim TXT As String
Dim TextLine As String

Filename = Worksheets("feuil1").Range("C8") & "\TF_actor.f"
Filename2 = Worksheets("feuil1").Range("C9")


Open Filename For Input As #1 'Ouverture du fichier en lecture.

Do While Not EOF(1)

Line Input #1, TextLine 'Lecture de la ligne

Encode_UTF8 (TextLine)

If InStr(TextLine, "Chemin =") <> 0 Then
TXT = TXT & AjouterText() & vbCrLf 'Si le test est concluant j'ajoute mes valeurs
GoTo 10
End If


TXT = TXT & TextLine & vbCrLf 'Je concatène mon texte

Decode_UTF8 (TXT)

10: Loop

Close #1

Open Filename2 For Output As #1 'Ouverture du fichier en écriture.
Print #1, TXT 'Je stock dans mon fichier la variable TXT
Close #1

End Sub


Function AjouterText() As String

AjouterText = AjouterText & "Chemin = " & Worksheets("feuil1").Range("C9")

End Function

Public Function isUTF8(astr)
Dim c0, c1, c2, c3
Dim n

isUTF8 = True
n = 1
Do While n <= Len(astr)
c0 = Asc(Mid(astr, n, 1))
If n <= Len(astr) - 1 Then
c1 = Asc(Mid(astr, n + 1, 1))
Else
c1 = 0
End If
If n <= Len(astr) - 2 Then
c2 = Asc(Mid(astr, n + 2, 1))
Else
c2 = 0
End If
If n <= Len(astr) - 3 Then
c3 = Asc(Mid(astr, n + 3, 1))
Else
c3 = 0
End If

If (c0 And 240) = 240 Then
If (c1 And 128) = 128 And (c2 And 128) = 128 And (c3 And 128) = 128 Then
n = n + 4
Else
isUTF8 = False
Exit Function
End If
ElseIf (c0 And 224) = 224 Then
If (c1 And 128) = 128 And (c2 And 128) = 128 Then
n = n + 3
Else
isUTF8 = False
Exit Function
End If
ElseIf (c0 And 192) = 192 Then
If (c1 And 128) = 128 Then
n = n + 2
Else
isUTF8 = False
Exit Function
End If
ElseIf (c0 And 128) = 0 Then
n = n + 1
Else
isUTF8 = False
Exit Function
End If
Loop
End Function


Public Function Encode_UTF8(astr)
Dim c
Dim n
Dim utftext

utftext = ""
n = 1
Do While n <= Len(astr)
c = AscW(Mid(astr, n, 1))
If c < 128 Then
utftext = utftext + Chr(c)
ElseIf ((c >= 128) And (c < 2048)) Then
utftext = utftext + Chr(((c \ 64) Or 192))
utftext = utftext + Chr(((c And 63) Or 128))
ElseIf ((c >= 2048) And (c < 65536)) Then
utftext = utftext + Chr(((c \ 4096) Or 224))
utftext = utftext + Chr((((c \ 64) And 63) Or 128))
utftext = utftext + Chr(((c And 63) Or 128))
Else ' c >= 65536
utftext = utftext + Chr(((c \ 262144) Or 240))
utftext = utftext + Chr(((((c \ 4096) And 63)) Or 128))
utftext = utftext + Chr((((c \ 64) And 63) Or 128))
utftext = utftext + Chr(((c And 63) Or 128))
End If
n = n + 1
Loop
Encode_UTF8 = utftext
End Function


Public Function Decode_UTF8(astr)
Dim c0, c1, c2, c3
Dim n
Dim unitext

If isUTF8(astr) = False Then
Decode_UTF8 = astr
Exit Function
End If

unitext = ""
n = 1
Do While n <= Len(astr)
c0 = Asc(Mid(astr, n, 1))
If n <= Len(astr) - 1 Then
c1 = Asc(Mid(astr, n + 1, 1))
Else
c1 = 0
End If
If n <= Len(astr) - 2 Then
c2 = Asc(Mid(astr, n + 2, 1))
Else
c2 = 0
End If
If n <= Len(astr) - 3 Then
c3 = Asc(Mid(astr, n + 3, 1))
Else
c3 = 0
End If

If (c0 And 240) = 240 And (c1 And 128) = 128 And (c2 And 128) = 128 And (c3 And 128) = 128 Then
unitext = unitext + ChrW((c0 - 240) * 65536 + (c1 - 128) * 4096) + (c2 - 128) * 64 + (c3 - 128)
n = n + 4
ElseIf (c0 And 224) = 224 And (c1 And 128) = 128 And (c2 And 128) = 128 Then
unitext = unitext + ChrW((c0 - 224) * 4096 + (c1 - 128) * 64 + (c2 - 128))
n = n + 3
ElseIf (c0 And 192) = 192 And (c1 And 128) = 128 Then
unitext = unitext + ChrW((c0 - 192) * 64 + (c1 - 128))
n = n + 2
ElseIf (c0 And 128) = 128 Then
unitext = unitext + ChrW(c0 And 127)
n = n + 1
Else ' c0 < 128
unitext = unitext + ChrW(c0)
n = n + 1
End If
Loop

Decode_UTF8 = unitext
End Function



Voici mon code qui ne marche pas. J'ai essayé de décoder en UTF8 mais sans résultats...

Merci
0
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701 > Frost
31 mai 2017 à 11:58
Bonjour,

si je l'applique à un fichier fortran
Que voulez-vous dire par la, un fichier txt lambda doit aller...!
0
Frost > f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024
31 mai 2017 à 13:29
f894009

Mon fichier fortran est écrit en .f que j'utilise pour compiler et faire un exécutable avec.
0
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701 > Frost
31 mai 2017 à 14:40
Re,

Pige pas votre facon de faire. Que cherchez vous exactement et pourquoi, je ne vois ce que vient faire le .f dans cette affaire
0