📄 run_one_test.m
字号:
end elseif isnumeric(av) & isnumeric(att_val{jj}) if size(av) == size(att_val{jj}) switch test_type case 'netcdf' dd = abs(av - att_val{jj}) + ... abs(isnan(av) - isnan(att_val{jj})); if max(dd(:)) > 0 error(['!! attnc failed: 2: attribute ' num2str(jj) ' of ' ... var{ii} ' wrong']) end case 'opendap' % allow for possible rounding error. dd1 = abs(isnan(av) - isnan(att_val{jj})); if max(dd1(:)) > 0 error(['!! attnc failed: 2a: attribute ' num2str(jj) ' of ' ... var{ii} ' wrong (NaNs don''t match']) end % Check for a large relative error. This is necessary because of % loss of precision in when using opendap. dd2 = abs(av - att_val{jj}); if max(dd2(:)) > 0 vv = att_val{jj}; ff = find(abs(vv) > 0); dd2(ff) = dd2(ff)./vv(ff); if max(dd2(:)) > 1e-5 error(['!! attnc failed: 2b: attribute ' num2str(jj) ' of ' ... var{ii} ' wrong']) end end end else error(['!! attnc failed: 3: attribute ' num2str(jj) ' of ' ... var{ii} ' wrong']) end else error(['!! attnc failed: 4: attribute ' num2str(jj) ' of ' ... var{ii} ' wrong']) end endelseif (test_no >= 34) & (test_no <= 47) % Now step through each of the variables. When the arrays are found replace % appropriate values by NaNs. (Values which match the missing_value or % _FillValue or lie outside the valid_range, valid_min or valid_max.) ii = test_no - 33; cmd = ['val = ' var{ii} '_nan;']; eval(cmd) % Get the entire array, with missing values replaced by NaNs, and test it. The % array is retrieved in different ways including sending a structure as an % argument to getnc. switch mod(ii, 3) case 0 xx = getnc(file, var{ii}); case 1 clear struc struc.varid = var{ii}; xx = getnc(file, struc); case 2 clear struc struc.file = file; struc.varid = var{ii}; xx = getnc(struc); end compare_mats_getnc(val, xx, var{ii}, 'nan')elseif (test_no >= 48) & (test_no <= 61) % Now step through each of the variables. When the arrays are found do not % replace any values by NaNs. ii = test_no - 47; cmd = ['val = ' var{ii} '_nonan;']; eval(cmd) % Get the entire array, without any NaNs, and test it. The array is retrieved % in different ways including sending a structure as an argument to getnc. switch mod(ii, 4) case 0 xx = getnc(file, var{ii}, -1, -1, -1, -1, 1); case 1 clear struc struc.varid = var{ii}; struc.change_miss = 1; xx = getnc(file, struc); case 2 clear struc struc.change_miss = 1; xx = getnc(file, var{ii}, struc); case 3 clear struc struc.file = file; struc.varid = var{ii}; struc.change_miss = 1; xx = getnc(struc); end compare_mats_getnc(val, xx, var{ii}, 'nonan')elseif (test_no >= 62) & (test_no <= 75) % Now step through each of the variables. When the arrays are found replace % appropriate values by 64. (Values which match the missing_value or % _FillValue or lie outside the valid_range, valid_min or valid_max.) ii = test_no - 61; cmd = ['val = ' var{ii} '_mi;']; eval(cmd) % Get the entire array, with missing values replaced by 64 and test it. switch mod(ii, 4) case 0 xx = getnc(file, var{ii}, -1, -1, -1, -1, 3, 64); case 1 clear struc struc.varid = var{ii}; struc.new_miss = 64; xx = getnc(file, var{ii}, -1, -1, -1, -1, 3, struc); case 2 clear struc struc.varid = var{ii}; struc.change_miss = 3; struc.new_miss = 64; xx = getnc(file, var{ii}, -1, -1, -1, -1, 3, struc); case 3 clear struc struc.file = file; struc.varid = var{ii}; struc.change_miss = 3; struc.new_miss = 64; xx = getnc(struc); end compare_mats_getnc(val, xx, var{ii}, 'mi')elseif (test_no >= 76) & (test_no <= 89) % Now get a subset of the data. ii = test_no - 75; cmd = ['val = ' var{ii} '_nonan;']; eval(cmd) % Specify a subset of the array. Note the need to fiddle the case of array % being a vector. Note also that we slip in -1 a few times just to show % that it can be done. si_full = size(val); ref_array = zeros(si_full); if ndims(val) == 2 if si_full(1) == 1 si_full = si_full(2); elseif si_full(2) == 1 si_full = si_full(1); end end corner = max(floor(si_full.*0.3), 1); end_point = ceil(si_full.*0.5); stride = ceil(si_full.*0.2); switch length(si_full) case 1 val_sub = val(corner(1):stride(1):end_point(1)); case 2 val_sub = val(corner(1):stride(1):end_point(1), ... corner(2):stride(2):end_point(2)); case 3 val_sub = val(corner(1):stride(1):end_point(1), ... corner(2):end_point(2), ... corner(3):stride(3):end_point(3)); stride(2) = -1; case 4 val_sub = val(corner(1):stride(1):end_point(1), ... corner(2):stride(2):end, ... corner(3):stride(3):end_point(3), ... corner(4):stride(4):end_point(4)); end_point(2) = -1; case 5 val_sub = val(1:1:end, ... corner(2):stride(2):end_point(2), ... corner(3):stride(3):end_point(3), ... corner(4):stride(4):end_point(4), ... corner(5):stride(5):end_point(5)); corner(1) = -1; end_point(1) = -1; end % Now get the subset of the array, without NaNs, and test it. switch mod(ii, 3) case 0 xx = getnc(file, var{ii}, corner, end_point, stride, -1, 1); case 1 clear struc struc.stride = stride; struc.change_miss = 1; xx = getnc(file, var{ii}, corner, end_point, struc); case 2 clear struc struc.file = file; struc.varid = var{ii}; struc.bl_corner = corner; struc.tr_corner = end_point; struc.stride = stride; struc.change_miss = 1; xx = getnc(struc); end compare_mats_getnc(val_sub, xx, var{ii}, 'sub') elseif (test_no >= 90) & (test_no <= 103) % Now step through each of the variables. When the arrays are found do not % replace any values by NaNs. Permute the arrays using the order_array % cell. For opendap access only test those occasions for which the order is a % scalar since this is the only version supported. ii = test_no - 89; order = order_array{ii}; if strcmp(test_type, 'netcdf') | ... (strcmp(test_type, 'opendap') & (length(order) == 1)) % disp(['Doing ' var{ii}]) cmd = ['val = ' var{ii} '_nonan;']; eval(cmd) if length(order) == 1 if (order == -2) si = size(val); nd = length(si); if (nd > 2) | ((si(1) > 1) & (si(2) > 1)) val = permute(val, length(size(val)):-1:1); end end else val = permute(val, order); end % First get the entire array, without any NaNs, and test it. switch mod(ii, 3) case 0 xx = getnc(file, var{ii}, -1, -1, -1, order, 1); case 1 clear struc struc.stride = stride; struc.change_miss = 1; xx = getnc(file, var{ii}, -1, -1, [], order, struc); case 2 clear struc struc.file = file; struc.varid = var{ii}; struc.order = order; struc.change_miss = 1; xx = getnc(struc); end compare_mats_getnc(val, xx, var{ii}, 'order') endelseif (test_no >= 104) & (test_no <= 117) % Now get a subset of the data. This is the same as the 76 to 89 case % except that we use different factors for the corner, end_point and % stride. ii = test_no - 103; cmd = ['val = ' var{ii} '_nonan;']; eval(cmd) % Specify a subset of the array. Note the need to fiddle the case of array % being a vector. Note also that we slip in -1 a few times just to show % that it can be done. si_full = size(val); ref_array = zeros(si_full); if ndims(val) == 2 if si_full(1) == 1 si_full = si_full(2); elseif si_full(2) == 1 si_full = si_full(1); end end corner = max(floor(si_full.*0.3), 1); end_point = ceil(si_full.*0.9); stride = ceil(si_full.*0.3); switch length(si_full) case 1 val_sub = val(corner(1):stride(1):end_point(1)); case 2 val_sub = val(corner(1):stride(1):end_point(1), ... corner(2):stride(2):end_point(2)); case 3 val_sub = val(corner(1):stride(1):end_point(1), ... corner(2):end_point(2), ... corner(3):stride(3):end_point(3)); stride(2) = -1; case 4 val_sub = val(corner(1):stride(1):end_point(1), ... corner(2):stride(2):end, ... corner(3):stride(3):end_point(3), ... corner(4):stride(4):end_point(4)); end_point(2) = -1; case 5 val_sub = val(1:1:end, ... corner(2):stride(2):end_point(2), ... corner(3):stride(3):end_point(3), ... corner(4):stride(4):end_point(4), ... corner(5):stride(5):end_point(5)); corner(1) = -1; end_point(1) = -1; end % Allow for the possibility that val_sub is a row vector when our standard % specifies that only column vectors are to be returned. si_val_sub = size(val_sub); if length(si_val_sub) == 2 if si_val_sub(1) == 1 val_sub = val_sub(:); end end % Now get the subset of the array, without NaNs, and test it. switch mod(ii, 3) case 0 xx = getnc(file, var{ii}, corner, end_point, stride, -1, 1); case 1 clear struc struc.stride = stride; struc.change_miss = 1; xx = getnc(file, var{ii}, corner, end_point, struc); case 2 clear struc struc.file = file; struc.varid = var{ii}; struc.bl_corner = corner; struc.tr_corner = end_point; struc.stride = stride; struc.change_miss = 1; xx = getnc(struc); end compare_mats_getnc(val_sub, xx, var{ii}, 'sub') end % end of giant if statement
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -