Error "Dot name reference on non-scalar structure" with loop

151 views
Skip to first unread message

Pascal App

unread,
Jun 16, 2014, 1:14:38 PM6/16/14
to ncto...@googlegroups.com
Hi everyboby,

I Use nctoolbox to read grib data from fnmoc server.
Unfortunately, when I use looping with iteration, after 3 loop, the running fails and I receive a bug message java "Dot name reference on non-scalar structure"....
I looked for solution, without  success.

Before this, I put a javaclasspath in prefdir with
 "<before>
C:\Users\AB\Desktop\Matlab\protobuf-java-2.4.1.jar"
and
"setup_nctoolbox" before all runs.

The only method I can use now (without bug) is to put "clear java protobuf-java-2.4.1.jar" just before the end of the loop, but this method clear all my data....

This is my scrip below, with "clear java" desactived....

If someone have a solution, this will be fine...

Best regards.
Pascal


clear all;      %clear variables
close all;       %close figures
clc;             %clear command
dbstop if error; %debug

setup_nctoolbox

% disp('Suppression des derniers fichiers .mat...')
ext = '*.mat';
chemin = fullfile(pwd,ext);
list = dir(chemin);
delete(chemin)


for m = 1:9
   
   
    % calcul sur date
    jd=now_utc; % gets the current time in UTC
    g=datevec(jd-6/24); % go for forecast 6 hours before
    d=datestr(g,'yyyymmdd'); % date du jour
    y = datestr(now, 10) ; % année en cours
    h=floor(g(4)/6)*6; % obtention du run en cours
    h1=06;
   
   
    z(1)=00;
    %         z(2)=06;
    %         z(3)=12;
    %         z(4)=18;
   
    %     fieldArray = cell(1,NB_FILE);
    fieldArray{1} = 'sig_wav_ht';
    fieldArray{2} = 'swl_wav_ht';
    fieldArray{3} = 'wnd_wav_ht';
    fieldArray{4} = 'peak_wav_dir';
    fieldArray{5} = 'swl_wav_dir';
    fieldArray{6} = 'wnd_wav_dir';
    fieldArray{7} = 'peak_wav_per';
    fieldArray{8} = 'swl_wav_per';
    fieldArray{9} = 'wnd_wav_per';
   
   
    % Reading grib1 file from FNMOC
    url=sprintf('http://www.usgodae.org/pub/outgoing/fnmoc/models/ww3_regional/med/%s/%s00/US058GOCN-GR1mdl.0111_0179_0%2.2d00F0RL%s00_0001_000000-000000%s',y,d,z(1),d,fieldArray{m})
    disp(['Opening dataset ' url '...'])
   
    %         field = cell(1,NB_FIELDS);
    field{1} = 'sig_wav_ht_surface';
    field{2} = 'swl_wav_ht_surface';
    field{3} = 'wnd_wav_ht_surface';
    field{4} = 'peak_wav_dir_surface';
    field{5} = 'swl_wav_dir_surface';
    field{6} = 'wnd_wav_dir_surface';
    field{7} = 'peak_wav_per_surface';
    field{8} = 'swl_wav_per_surface';
    field{9} = 'wnd_wav_per_surface';
   
    lon_range=[-6 -4];
    s.lon=lon_range;
   
    lat_range=[47 49];
    s.lat=lat_range;
   
    % download grib1 file
    local_file='test.grb';
    urlwrite(url,local_file);
    nc=ncgeodataset(local_file);
   
    %list variables
    nc.variables
    info = nc.metadata
   
    % create ncvariable
    uvar = nc.geovariable(field{m});
    us=uvar.geosubset(s);
   
    %         Suppression NaN
    us.data(isnan(us.data))=0;
   
    Position(1,:) = us.data(1,6,5);
    Position(2,:)= us.data(1,7,6);
    Position(3,:) = us.data(1,7,7);
   
   
    savefile = strcat('A',num2str(m),'.mat');
    save(savefile,'Position')
   
%     clear java protobuf-java-2.4.1.jar

end
   



Brian Schlining

unread,
Jun 16, 2014, 2:07:07 PM6/16/14
to ncto...@googlegroups.com, Pascal App

Hi Pascal,

I tried your code. The short answer is that you’re attempting to read a variable using the wrong variable name. You can wrap the offending section of code in a try/catch like this:

% create ncvariable
try  
    uvar = nc.geovariable(field{m});

    us=uvar.geosubset(s);

    %         Suppression NaN
    us.data(isnan(us.data))=0;

    Position(1,:) = us.data(1,6,5);
    Position(2,:)= us.data(1,7,6);
    Position(3,:) = us.data(1,7,7);


    savefile = strcat('A',num2str(m),'.mat');
    save(savefile,'Position')
catch
   fprintf(1, 'Unable to read %s\n', field{m});  
end

Now when you run your script, it will display the variables you are trying to read that don’t exist in the grib files. That should get you back on track.

--
You received this message because you are subscribed to the Google Groups "nctoolbox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nctoolbox+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
-- 
Brian Schlining

Reply all
Reply to author
Forward
0 new messages