IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Fortran Discussion :

Lecture des champs d'un tableau (séparateur tabulation)


Sujet :

Fortran

  1. #1
    Membre à l'essai
    Inscrit en
    Juin 2006
    Messages
    13
    Détails du profil
    Informations personnelles :
    Âge : 49

    Informations forums :
    Inscription : Juin 2006
    Messages : 13
    Points : 12
    Points
    12
    Par défaut Lecture des champs d'un tableau (séparateur tabulation)
    Bonjour Monsieur,
    Voila, j'ai un grand soucie pour lire mon fichier ci-joint, qui contient des séparateurs tabulations dé-fois (t5 ou t2 ) ajouter à cela le nombre de la chaîne de caractère par ligne est variable (180,178....137)

    prière de bien vouloir m'aider à lire ce fichier afin que je puisse contrôler la chronologie du champ date_obs et vérifier les autres champs si les valeurs sont bien dans leurs fourchette de contrôle.

    PRIMARY_KEY DATE_RECORD DATE_OBS INDICE_OBS VPILEMN_H UAIRMN_H UAIRDTMN_H UAIRMX_H UAIRDTMX_H UAIRDRSUP80_H UAIRDRINF40_H UAIR_M UAIRTVE_M RR_H RRDUR_H TAIRMN_H TAIRDTMN_H TAIRMX_H TAIRDTMX_H TAIR_M VDIMX_H VFIMX_H VDTFIMX_H VPASS_H VFMOY10_M VDMOY10_M
    7870 01/01/2009 00:32:41 01/01/2009 00:00:00 0 12.7000 61.0000 50 71.0000 6 0 0 61.0000 0.0000 13.3000 12 14.5000 50 14.5000 160 4 44 7.3000 3.4000 160
    -6839 01/01/2009 01:33:28 01/01/2009 01:00:00 0
    7872 01/01/2009 02:32:52 01/01/2009 02:00:00 0 12.6000 57.0000 48 61.0000 7 0 0 58.0000 0.0000 14.3000 9 14.8000 24 14.8000 180 7 24 12.1000 3.2000 170
    7873 01/01/2009 03:32:34 01/01/2009 03:00:00 0 12.6000 57.0000 31 59.0000 15 0 0 58.0000 0.0000 14.5000 9 14.8000 31 14.7000 190 6 52 10.7000 3.1000 190
    7874 01/01/2009 04:33:24 01/01/2009 04:00:00 0 12.6000 57.0000 26 59.0000 8 0 0 58.0000 0.0000 14.6000 9 15.0000 27 14.7000 190 8 11 14.2000 3.7000 170
    7875 01/01/2009 05:32:36 01/01/2009 05:00:00 0 12.6000 57.0000 43 59.0000 60 0 0 58.0000 0.0000 14.7000 59 15.0000 31 14.9000 210 7 21 11.7000 2.8000 190
    merci d'avance pour votre contribution
    mes salutations[/QUOTE]

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    152
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 152
    Points : 191
    Points
    191
    Par défaut
    Sur ce post tu trouveras une base de travail pour résoudre ton soucis je pense.

    http://www.developpez.net/forums/d12...-dans-fichier/

    Bonne journée,

    Marlan

  3. #3
    Membre à l'essai
    Inscrit en
    Juin 2006
    Messages
    13
    Détails du profil
    Informations personnelles :
    Âge : 49

    Informations forums :
    Inscription : Juin 2006
    Messages : 13
    Points : 12
    Points
    12
    Par défaut Lecture des champs d'un tableau (séparateur tabulation)
    Bonjour,

    J'ai regardé le lien j'ai pas bien compris !

  4. #4
    Membre éclairé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2013
    Messages
    388
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Conseil

    Informations forums :
    Inscription : Janvier 2013
    Messages : 388
    Points : 692
    Points
    692
    Par défaut
    Salut,
    Pour lire des données dont le gabarit varie, j'utilise un module qui découpe une chaine de caractères en sous-chaines en fonction d'un délimiteur.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    module split_string_index
        ! Rem : pb alloc. dyn. des chaines avec version de gfortran (gcc 4.7.3)
        !         character(len=:), allocatable :: value
        !                                               1
        ! Error: Deferred-length character component 'value' at (1) is not yet supported
        implicit none
        integer, parameter :: NBCHAR = 64
     
        type word
            character(len=NBCHAR) :: value
            type(word), pointer   :: p_next => null()
        end type word
     
        type(word), pointer :: p_first => null()
        type(word), pointer :: p_curr => null()
        type(word), pointer, private :: p_prec => null()
        integer :: nb_elt
     
        private :: record
     
    contains
     
        subroutine split (line,delim)
            character(len=*), intent(in) :: line
            character(len=*), intent(in) :: delim
            integer :: idx1         ! position 1er charact. après delim
            integer :: idx2         ! position du delim finissant le mot
            integer :: step         ! nb char de fin du delim au debut nv delim
            integer :: l_delim
            l_delim = len(delim)
            idx1 = 1 ; idx2 = 0 ; nb_elt = 0
            do
                step = index(line(idx1:),delim) - 1
                if (step==-1) exit
                idx2 = idx1 + step
                call record (line(idx1:idx2-1))
                idx1 = idx2 + l_delim
            enddo
            if (idx2>0) then
                idx1 = idx2 + l_delim
                idx2 = len_trim(line)
                call record (line(idx1:idx2))
            else
                call record (trim(line))
            endif
        end subroutine split
     
        subroutine record (a_string)
            character(len=*), intent(in) :: a_string
            if (.not. associated(p_first)) then
                allocate(p_first)
                p_curr => p_first
            else
                allocate(p_curr)
                p_prec%p_next => p_curr
            endif
            p_curr%value = a_string
            p_prec => p_curr
            nb_elt = nb_elt + 1
        end subroutine record
     
        recursive subroutine libere (ptr)
            type(word), pointer :: ptr
            if (associated(ptr%p_next)) call libere(ptr%p_next)
            deallocate(ptr)
        end subroutine libere
     
        function get_item (idx)
            character(len=NBCHAR) :: get_item
            integer, intent(in) :: idx
            integer :: i
            get_item = ""
            if (idx<=0 .or. idx>nb_elt)         goto 101
            if (.not. associated(p_first))      goto 102
            p_curr => p_first
            do i = 1, idx-1
                p_curr => p_curr%p_next
                if (.not. associated(p_curr))   goto 102
            enddo
            get_item = p_curr%value
            return
    101     print '(/,"--- Error : index",x,i3,x,"out of range",/)', idx
            return
    102     print '(/,"--- Error : pointer not associated",/)'
            return
        end function get_item
     
    end module split_string_index
    Qui s'utilise ainsi :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    program test_split_string
        use split_string_index
        implicit none
        character(len=128) :: line
        integer :: idx
     
        line = "-6839 01/01/2009 01:33:28 01/01/2009 01:00:00 0 "
     
        call split (trim(line)," ")
     
        p_curr => p_first ; idx = 0
        do
            if (.not. associated(p_curr)) exit
            idx = idx + 1
            print '(i2,x,"''",a,"''")', idx, trim(p_curr%value)
            p_curr => p_curr%p_next
        enddo
     
        idx = 2
        print '("Item(",i2,") :",x,"''",a,"''")', idx, trim(get_item(idx))
     
        call libere (p_first)
     
    end program test_split_string
    Et donne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     1 '-6839'
     2 '01/01/2009'
     3 '01:33:28'
     4 '01/01/2009'
     5 '01:00:00'
     6 '0'
    Item( 2) : '01/01/2009'
    Il faut ensuite lire la valeur dans la sous-chaine avec le format adéquat.

    Bonne continuation.

  5. #5
    Membre à l'essai
    Inscrit en
    Juin 2006
    Messages
    13
    Détails du profil
    Informations personnelles :
    Âge : 49

    Informations forums :
    Inscription : Juin 2006
    Messages : 13
    Points : 12
    Points
    12
    Par défaut quel version de Fortran ?
    Bonjour Monsieur,

    Tout d'abord, je tien à vous remercie pour le temps que vous m'avez consacré pour résoudre mon problème
    Malheureusement, moi j’utilise « Fortran PowerStation version 4. » , lorsque j’ai compilé le programme, il me sorte 28 Errors (telque : FOR3852, FOR3494, FOR2290…….)
    Quelle version de Fortran utilisez-vous ?

    merci,

  6. #6
    Membre éclairé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2013
    Messages
    388
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Conseil

    Informations forums :
    Inscription : Janvier 2013
    Messages : 388
    Points : 692
    Points
    692
    Par défaut
    Je ne connais pas l'outil. J'utilise le compilateur gfortran. Il fonctionne aussi sur WINDOWS.
    Le compilo doit être récent car le code contient des éléments de FORTRAN 2003.

    Le fichier est au format libre, il a l'extension ".f90".
    Comme c'est un module, il faut commencer par le compiler avant le programme principal. Il y a des exemples sur le forum.

Discussions similaires

  1. contrôle des champ d'un tableau
    Par Chikh001 dans le forum Collection et Stream
    Réponses: 3
    Dernier message: 04/03/2008, 13h45
  2. Comparer des champs dans un tableau
    Par Tomislav dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 14/12/2007, 09h26
  3. [Tableaux] Enlever des champs dans un tableau
    Par djudjublondin dans le forum Langage
    Réponses: 5
    Dernier message: 09/12/2007, 20h44
  4. Réponses: 4
    Dernier message: 03/10/2007, 17h27
  5. Réponses: 2
    Dernier message: 08/08/2007, 08h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo