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

MATLAB Discussion :

Lire un fichier grib


Sujet :

MATLAB

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 5
    Points : 1
    Points
    1
    Par défaut Lire un fichier grib
    Bonjour,
    J'ai essayé de lire un fichier grib et cela affiche tjr:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    >> readgrib
    Error using readgrib (line 39)
    Not enough input arguments.
    Quelqu'un peut m'aider?
    voici le script
    Nouveau document texte.txt

  2. #2
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 302
    Points : 52 884
    Points
    52 884
    Par défaut
    Je présume qu'il faut donner le nom du fichier en argument d'entrée de la fonction readgrib :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    filename = 'test.grb';
    readgrib(filename)
    Ingénieur indépendant en mécatronique - Conseil, conception et formation
    • Conception mécanique (Autodesk Fusion 360)
    • Impression 3D (Ultimaker)
    • Développement informatique (Python, MATLAB, C)
    • Programmation de microcontrôleur (Microchip PIC, ESP32, Raspberry Pi, Arduino…)

    « J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" » (Saint Huck)

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 5
    Points : 1
    Points
    1
    Par défaut
    Ca marche pas,matlab affiche encore une erreur:
    Unexpected MATLAB expression.

  4. #4
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 302
    Points : 52 884
    Points
    52 884
    Par défaut
    Où as-tu trouvé la fonction readgrib ?

    Montre nous le code que tu utilises et le message d'erreur complet.
    Ingénieur indépendant en mécatronique - Conseil, conception et formation
    • Conception mécanique (Autodesk Fusion 360)
    • Impression 3D (Ultimaker)
    • Développement informatique (Python, MATLAB, C)
    • Programmation de microcontrôleur (Microchip PIC, ESP32, Raspberry Pi, Arduino…)

    « J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" » (Saint Huck)

  5. #5
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 5
    Points : 1
    Points
    1
    Par défaut
    j'ai cherché la fonction sur le net. Voici l'erreur:

    >> readgrib
    Error: File: readgrib.m Line: 36 Column: 58
    Unexpected MATLAB expression.

    La ligne 36 correspond à la première ligne du script, j'ai déja remplacé gribinput par u fichier grib.



    function [lon,lat,time,Uwind,Vwind,SWH,MWD,MWP]=readgrib(gribinput)

    wave=ncgeodataset(gribinput);

    wave.variables;

    lon=wave{'lon'}( : ); %Defining longitude vector
    lengthlon=length(lon); %Defining length of lon vector

    for i=1:lengthlon
    if lon(i)>180
    lon(i)=lon(i)-360;
    end
    end
    lat=wave{'lat'}( : ); %Defining latitude vector
    lengthlat=length(lat);
    time=wave{'time'}( : ); %Defining time vector
    lengthtime=length(time);

    Uwind=wave{'10_metre_U_wind_component_surface'}( :,:,: );
    Vwind=wave{'10_metre_V_wind_component_surface'}( :,:,: );
    SWH=wave{'Significant_wave_height_msl'}( :,:,: );
    MWD=wave{'Mean_wave_direction_msl'} ( :,:,: );
    MWP=wave{'Mean_wave_period_msl'}( :,:,: );

    S=size(MWP);
    end

  6. #6
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 302
    Points : 52 884
    Points
    52 884
    Par défaut
    Citation Envoyé par Hery V Voir le message
    j'ai cherché la fonction sur le net.
    Peux-tu nous donner l'adresse exacte du site où tu as trouvé le code ?

    Et montre nous le contenu exacte de readgrib.m avec les lignes de commentaires en entête
    Ingénieur indépendant en mécatronique - Conseil, conception et formation
    • Conception mécanique (Autodesk Fusion 360)
    • Impression 3D (Ultimaker)
    • Développement informatique (Python, MATLAB, C)
    • Programmation de microcontrôleur (Microchip PIC, ESP32, Raspberry Pi, Arduino…)

    « J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" » (Saint Huck)

  7. #7
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 5
    Points : 1
    Points
    1
    Par défaut
    Je me souvien pas du site mais voici le titra du document PDF que j'ai téléchargé : Development of a Method for Weather
    Routing of Ships
    A noter que j'ai déja nctoolbox installé sur matlab

    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
    % ------------------------------------------------------------
    % readgrib .m
    % Hege Eskild
    % Spring 2014
    %%
    This function reads the GRIB weather file . Gives out
    % vectors with latitude , longitude and time , and matrices
    % with significant wave height , mean wave period , mean wave
    % direction and U- and V- components of wind .
    %%
    If another GRIB files with different variable names is used
    % The name inside the parentheses must be changed .
    %%
    ------------------------------------------------------------
    % Variable name Definition
    % ----------------------Input ---------------------------------
    % GRIBinput Weather file . Can be forecast or
    % hindcast in GRIB format
    % ---------------------Output --------------------------------
    % lon Vector with longitude values from
    % GRIB
    % lat Vector with latitude values from
    % GRIB
    % time Vector with time values from GRIB
    % Uwind Matrix with U component of wind
    % from GRIB
    % Vwind Matrix with V component of wind
    % from GRIB
    % SWH Matrix with Hs from GRIB
    % MWD Matrix with mean wave direction
    % from GRIB
    % MWP Matrix with mean wave period
    % from GRIB
     
    function [lon ,lat ,time ,Uwind ,Vwind ,SWH ,MWD ,MWP ]= readgrib ( GRIBinput )
    % Reading the GRIB file
    wave = ncgeodataset ( GRIBinput );
    % Checking contends
    wave . variables ;
    lon= wave {’lon ’}( : ) ; % Defining longitude vector
    lengthlon = length (lon); % Defining length of lon vector
    %If the lon values are defined as 0 -360 degrees , the values are
    %are change to be between -180 to 180 so that the corresponds
    %to the Matlab values .
    for i=1: lengthlon
    if lon (i) >180
    lon(i)=lon(i) -360;
    end
    end
    lat= wave {’lat ’}( : ) ; % Defining latitude vector
    lengthlat = length (lat);
    time = wave {’time ’}( : ) ; % Defining time vector
    lengthtime = length ( time );
    % Creating matrices of size time *lat* lon including U and V
    % component of wind , significant wave height , mean wave period
    %and mean wave direction
    Uwind = wave {’10 _metre_U_wind_component_surface ’}( : ,: ,: );
    Vwind = wave {’10 _metre_V_wind_component_surface ’}( : ,: ,: );
    SWH= wave {’ Significant_wave_height_msl ’}( : ,: ,: );
    MWD= wave {’ Mean_wave_direction_msl ’}( : ,: ,: );
    MWP= wave {’ Mean_wave_period_msl ’}( : ,: ,: );
    S= size (MWP);
    end

  8. #8
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 302
    Points : 52 884
    Points
    52 884
    Par défaut
    Citation Envoyé par Hery V Voir le message
    Je me souvien pas du site mais voici le titra du document PDF que j'ai téléchargé : Development of a Method for Weather
    Routing of Ships
    => http://www.diva-portal.org/smash/get...FULLTEXT01.pdf

    Pour le reste, c'est un problème de copier/coller depuis le PDF.

    Voici une version corrigée :

    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
    % ------------------------------------------------------------
    % readgrib .m
    % Hege Eskild
    % Spring 2014
    %
    % This function reads the GRIB weather file . Gives out
    % vectors with latitude , longitude and time , and matrices
    % with significant wave height , mean wave period , mean wave
    % direction and U- and V- components of wind .
    %
    % If another GRIB files with different variable names is used
    % The name inside the parentheses must be changed .
    %
    %------------------------------------------------------------
    % Variable name                 Definition
    % ----------------------Input ---------------------------------
    % GRIBinput                     Weather file . Can be forecast or
    %                               hindcast in GRIB format
    % ---------------------Output --------------------------------
    % lon                           Vector with longitude values from
    %                               GRIB
    % lat                           Vector with latitude values from
    %                               GRIB
    % time                          Vector with time values from GRIB
    % Uwind                         Matrix with U component of wind
    %                               from GRIB
    % Vwind                         Matrix with V component of wind
    %                               from GRIB
    % SWH                           Matrix with Hs from GRIB
    % MWD                           Matrix with mean wave direction
    %                               from GRIB
    % MWP                           Matrix with mean wave period
    %                               from GRIB
     
    function [lon, lat, time, Uwind, Vwind, SWH, MWD, MWP] = readgrib(GRIBinput)
     
    % Reading the GRIB file
    wave = ncgeodataset(GRIBinput);
    % Checking contends
    wave.variables;
    lon = wave{'lon'}(:) ;    % Defining longitude vector
    lengthlon = length(lon); % Defining length of lon vector
    %If the lon values are defined as 0 -360 degrees , the values are
    %are change to be between -180 to 180 so that the corresponds
    %to the Matlab values .
    for i = 1:lengthlon
        if lon(i)>180
            lon(i) = lon(i)-360;
        end
    end
    lat = wave{'lat'}(:);     % Defining latitude vector
    lengthlat = length(lat);
    time = wave{'time'}(:);   % Defining time vector
    lengthtime = length(time);
     
    %Creating matrices of size time *lat* lon including U and V
    %component of wind , significant wave height , mean wave period
    %and mean wave direction
    Uwind = wave{'10_metre_U_wind_component_surface'}(:,:,:);
    Vwind = wave{'10_metre_V_wind_component_surface'}(:,:,:);
    SWH = wave{'Significant_wave_height_msl'}(:,:,:);
    MWD = wave{'Mean_wave_direction_msl'}(:,:,:);
    MWP = wave{'Mean_wave_period_msl'}(:,:,:);
    S = size(MWP);
    end
    Ingénieur indépendant en mécatronique - Conseil, conception et formation
    • Conception mécanique (Autodesk Fusion 360)
    • Impression 3D (Ultimaker)
    • Développement informatique (Python, MATLAB, C)
    • Programmation de microcontrôleur (Microchip PIC, ESP32, Raspberry Pi, Arduino…)

    « J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" » (Saint Huck)

  9. #9
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 5
    Points : 1
    Points
    1
    Par défaut
    je ne voie pas trop la différence entre les deux codes

Discussions similaires

  1. lire un fichier GRIB
    Par Flaherty Mc Coillean dans le forum Images
    Réponses: 8
    Dernier message: 16/02/2010, 11h45
  2. lire des fichiers GRIB avec darwin
    Par kreff dans le forum Applications et environnements graphiques
    Réponses: 1
    Dernier message: 13/09/2007, 01h33
  3. Réponses: 5
    Dernier message: 11/01/2004, 20h17
  4. Lire un fichier de 50 gb
    Par Maryves dans le forum MFC
    Réponses: 2
    Dernier message: 08/01/2004, 14h08
  5. Lire le fichier du port série
    Par saibe dans le forum Linux
    Réponses: 7
    Dernier message: 09/04/2003, 09h29

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