Warning, /verification/fizhi-cs-aqualev20/scripts/average_ML.m is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
7ae8fb32b5 Andr*0001 %
0002 %
0003 % Ed Hill
0004 %
0005 % Generate the APE ML01--ML07 and ME01--ME07 fields:
0006 %
0007 % For all facets:
0008 % For all time steps:
0009 % For all variables:
0010 % Create a mask based on THETA == 0.0
0011 % For all variables:
0012 % compute partial sum wrt mask
0013 % compute number contributing wrt mask
0014 % Compute the averages from the partial sums & num contrib
0015 % Write netCDF output for this facet:
0016 %
0017
0018 %======================================================================
0019
0020 ML_files
0021
0022 vars = { ...
0023 {'u','UVEL','masku'} ...
0024 {'v','VVEL','maskv'} ...
0025 {'w','WVEL','mask'} ...
0026 {'phi','PHIHYD','mask'} ...
0027 {'q','SALT','mask'} ...
0028 {'rh','RELHUM','mask'} ...
0029 {'th','THETA','mask'} ...
0030 };
0031
0032 %======================================================================
0033 %
0034 % Interpolate to the reference pressure levels and then compute the
0035 % derived fields and the temporal sums of all fields on the original
0036 % MITgcm grid
0037 %
0038 disp('Computing Sums')
0039
0040 itile = 1;
0041 for itile = 1:6
0042
0043 it0 = 0;
0044 for iv = 1:length(vars)
0045 eval(sprintf('clear %s', vars{iv}{1} ));
0046 end
0047
0048 fi = 1;
0049 for fi = [ 1:length(files) ]
0050
0051 fib = 0;
0052
0053 fname = sprintf(files{fi}{1},itile);
0054 disp([ ' fname = "' fname '"' ]);
0055 nc = netcdf(fname, 'nowrite');
0056 times = nc{'T'}(:);
0057
0058 it = 1;
0059 for it = 1:length(times)
0060
0061 for iv = 1:length(vars)
0062 eval(sprintf('%s = squeeze(nc{ ''%s'' }(it,:,:,:));', ...
0063 vars{iv}{1},vars{iv}{2}));
0064 eval(sprintf('mr = max(abs(%s(:)));', vars{iv}{1}));
0065 if mr > 1e10
0066 % error('values heading out of range!!!');
0067 fib = 1;
0068 end
0069 end
0070
0071 mask = double(th ~= 0.0);
0072 masku = ones(size(th) + [0 0 1]);
0073 masku(:,:,1:(end-1)) = masku(:,:,1:(end-1)) .* mask;
0074 masku(:,:,2:end ) = masku(:,:,2:end ) .* mask;
0075 maskv = ones(size(th) + [0 1 0]);
0076 maskv(:,1:(end-1),:) = maskv(:,1:(end-1),:) .* mask;
0077 maskv(:,2:end, :) = maskv(:,2:end, :) .* mask;
0078
0079 if it0 == 0
0080 it0 = 1;
0081 for iv = 1:length(vars)
0082 eval(sprintf('%s_ave = zeros(size(%s));', ...
0083 vars{iv}{1},vars{iv}{1}));
0084 end
0085 mask_sum = zeros(size(mask));
0086 masku_sum = zeros(size(masku));
0087 maskv_sum = zeros(size(maskv));
0088 end
0089 for iv = 1:length(vars)
0090 eval(sprintf('%s_ave = %s_ave + (%s .* %s);', ...
0091 vars{iv}{1}, vars{iv}{1}, ...
0092 vars{iv}{3}, vars{iv}{1}));
0093 end
0094 mask_sum = mask_sum + mask;
0095 masku_sum = masku_sum + masku;
0096 maskv_sum = maskv_sum + maskv;
0097
0098 end
0099
0100 if fib == 1
0101 disp([ 'BAD :: "' fname '"' ]);
0102 end
0103
0104 nc = close(nc);
0105
0106 end
0107
0108 for iv = 1:length(vars)
0109 eval(sprintf('%s_ave = %s_ave ./ %s_sum;', ...
0110 vars{iv}{1}, vars{iv}{1}, vars{iv}{3} ));
0111 end
0112
0113 nc = netcdf(sprintf('ML_ave_%d.nc',itile), 'clobber');
0114
0115 nc('T') = 0;
0116 nc('Z') = 17;
0117 nc('X') = 32; nc('Xp1') = 33;
0118 nc('Y') = 32; nc('Yp1') = 33;
0119
0120 for iv = 1:length(vars)
0121 switch vars{iv}{3}
0122 case 'mask'
0123 nc{ vars{iv}{2} } = ncdouble( 'T', 'Z', 'Y', 'X' );
0124 case 'masku'
0125 nc{ vars{iv}{2} } = ncdouble( 'T', 'Z', 'Y', 'Xp1' );
0126 case 'maskv'
0127 nc{ vars{iv}{2} } = ncdouble( 'T', 'Z', 'Yp1', 'X' );
0128 end
0129 eval(sprintf('nc{ vars{iv}{2} }(1,:,:,:) = %s_ave;',vars{iv}{1}));
0130 end
0131 nc{ 'mask_sum' } = ncdouble( 'T', 'Z', 'Y', 'X' );
0132 nc{ 'mask_sum' }(1,:,:,:) = mask_sum;
0133 nc{ 'masku_sum' } = ncdouble( 'T', 'Z', 'Y', 'Xp1' );
0134 nc{ 'masku_sum' }(1,:,:,:) = masku_sum;
0135 nc{ 'maskv_sum' } = ncdouble( 'T', 'Z', 'Yp1', 'X' );
0136 nc{ 'maskv_sum' }(1,:,:,:) = maskv_sum;
0137 nc = close(nc);
0138
0139 end
0140