Skip to content

Commit 9b64b69

Browse files
committed
fix a bug in FUN_nc_OpenDAP_with_limit: some useless codes introduced in an early version create a nan matrix with same size of the data to be downloaded. This may lead to an out-of-memory error.
1 parent c090594 commit 9b64b69

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

FUN_nc_OpenDAP_with_limit.m

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ function FUN_nc_OpenDAP_with_limit( filename0, filename1, dim_limit_name, dim_li
6161
%
6262
% % Another example for 2D lon/lat cases is attached to the end.
6363

64+
% By L. Chi, V1.62 2022-07-27: fix a bug: Some old codes will create a large nan matrix before downloading a large dataset no matter whether
65+
% "divided_dim_str" is set or not. The nan matrix is may lead to an out-of-memory error and it is useless.
66+
% Related codes have been commented and will be removed in a later version.
6467
% By L. Chi, V1.61 2021-08-16: correct a typo ("compressiion_level" -> "compression_level")
6568
% By L. Chi, V1.60 2021-07-28: Put all operations to source files in try-catch blocks to survive from internet/server errors.
6669
%
@@ -421,22 +424,22 @@ function FUN_nc_OpenDAP_with_limit( filename0, filename1, dim_limit_name, dim_li
421424
% The data will be donwloaded peice by piece by piece according to the last dim.
422425

423426
disp([datestr(now) ' downloading ' info0.Variables(iv).Name ])
424-
if all( size(count) == 1 ) % in case of count = 5 instead of [5 6 7 8]
425-
var_value = nan(count,1);
426-
else
427-
var_value = nan(count);
428-
end
427+
%if all( size(count) == 1 ) % in case of count = 5 instead of [5 6 7 8]
428+
% var_value = nan(count,1);
429+
%else
430+
% var_value = nan(count);
431+
%end
429432
divided_dim = FUN_struct_find_field_ind( VarDim_now, 'Name', divided_dim_str );
430433

431434
% make the divided_dim as the last dim.
432-
[var_value, tem_ind_reverse] = FUN_dim_move_to_end(var_value, divided_dim );
433-
tem_size = size( var_value );
434-
% check
435-
if count(divided_dim) == tem_size(end)
436-
else
437-
error('dimension error')
438-
end
439-
var_value = reshape( var_value, [], count(divided_dim) );
435+
% [var_value, tem_ind_reverse] = FUN_dim_move_to_end(var_value, divided_dim );
436+
%tem_size = size( var_value );
437+
% % check
438+
% if count(divided_dim) == tem_size(end)
439+
% else
440+
% error('dimension error')
441+
% end
442+
% var_value = reshape( var_value, [], count(divided_dim) );
440443

441444

442445
% prepare for loading the index by groups

FUN_nc_varget_enhanced_from_multifiles.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
is_1D = length(var_size1) == 2 && any( var_size1 == 1 );
6565
var_size2 = var_size1;
6666

67-
if dim_ind == length( var_size1 ) || is_1D;
67+
if dim_ind == length( var_size1 ) || is_1D
6868
% ok
6969
else
7070
error('The merged dim must be the last dimension. Other conditions are not supported yet')
@@ -81,7 +81,7 @@
8181
out_sourcefile_ind = nan( 1, MV.N );
8282

8383
%% load/write variable
84-
for ii = 1:length( filelist );
84+
for ii = 1:length( filelist )
8585
disp(['Loading from ' fullfile( input_dir, filelist(ii).name ) ])
8686
out_var(:, MV.ind_start(ii): MV.ind_end(ii)) = reshape( FUN_nc_varget_enhanced( fullfile( input_dir, filelist(ii).name ), var_name ), NX, [] );
8787
out_sourcefile_ind( MV.ind_start(ii): MV.ind_end(ii) ) = ii;

private/FUN_codetool_retry.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@
6565
count_err = count_err + 1;
6666

6767
fprintf(' \n' );
68-
disp(['Err, retry count: ' num2str( count_err )] );
68+
warning(['Err, retry count: ' num2str( count_err )] );
6969

7070
fprintf('Wait for %.2f seconds ... \n', pause_seconds );
7171
pause(pause_seconds) %retry after 30 seconds
7272

7373
fprintf('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n' );
7474

7575
if count_err == N_max_retry
76-
fprintf('>>>>>> Reach N_max_retry(=%i), stop <<<<<< \n', N_max_retry)
76+
warning('>>>>>> Reach N_max_retry(=%i), stop <<<<<< \n', N_max_retry)
7777
% This will return an error message by default
7878
[varargout{1:nargout}] = else_fun();
7979
end

0 commit comments

Comments
 (0)