Back to home page

MITgcm

 
 

    


Warning, /verification/fizhi-cs-aqualev20/scripts/average1_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 files = { ...
                0021 { 'mnc_out_144000/MLfields.0000136800.t%03d.nc' }; ...
                0022 { 'mnc_out_151200/MLfields.0000144000.t%03d.nc' }; ...
                0023 { 'mnc_out_158400/MLfields.0000151200.t%03d.nc' }; ...
                0024 { 'mnc_out_165600/MLfields.0000158400.t%03d.nc' }; ...
                0025 { 'mnc_out_172800/MLfields.0000165600.t%03d.nc' }; ...
                0026 { 'mnc_out_180000/MLfields.0000172800.t%03d.nc' }; ...
                0027 { 'mnc_out_187200/MLfields.0000180000.t%03d.nc' }; ...
                0028 { 'mnc_out_194400/MLfields.0000187200.t%03d.nc' }; ...
                0029 { 'mnc_out_201600/MLfields.0000194400.t%03d.nc' }; ...
                0030 { 'mnc_out_208800/MLfields.0000201600.t%03d.nc' }; ...
                0031 { 'mnc_out_216000/MLfields.0000208800.t%03d.nc' }; ...
                0032 { 'mnc_out_223200/MLfields.0000216000.t%03d.nc' }; ...
                0033 { 'mnc_out_230400/MLfields.0000223200.t%03d.nc' }; ...
                0034 { 'mnc_out_237600/MLfields.0000230400.t%03d.nc' }; ...
                0035 { 'mnc_out_244800/MLfields.0000237600.t%03d.nc' }; ...
                0036 { 'mnc_out_252000/MLfields.0000244800.t%03d.nc' }; ...
                0037 { 'mnc_out_259200/MLfields.0000252000.t%03d.nc' }; ...
                0038 { 'mnc_out_266400/MLfields.0000259200.t%03d.nc' }; ...
                0039 { 'mnc_out_273600/MLfields.0000266400.t%03d.nc' }; ...
                0040 { 'mnc_out_280800/MLfields.0000273600.t%03d.nc' }; ...
                0041 { 'mnc_out_288000/MLfields.0000280800.t%03d.nc' }; ...
                0042 { 'mnc_out_295200/MLfields.0000288000.t%03d.nc' }; ...
                0043 { 'mnc_out_302400/MLfields.0000295200.t%03d.nc' }; ...
                0044 { 'mnc_out_309600/MLfields.0000302400.t%03d.nc' }; ...
                0045 { 'mnc_out_316800/MLfields.0000309600.t%03d.nc' }; ...
                0046 { 'mnc_out_324000/MLfields.0000316800.t%03d.nc' }; ...
                0047 { 'mnc_out_331200/MLfields.0000324000.t%03d.nc' }; ...
                0048 { 'mnc_out_338400/MLfields.0000331200.t%03d.nc' }; ...
                0049 { 'mnc_out_345600/MLfields.0000338400.t%03d.nc' }; ...
                0050 { 'mnc_out_352800/MLfields.0000345600.t%03d.nc' }; ...
                0051 { 'mnc_out_360000/MLfields.0000352800.t%03d.nc' }; ...
                0052 { 'mnc_out_367200/MLfields.0000360000.t%03d.nc' }; ...
                0053 { 'mnc_out_374400/MLfields.0000367200.t%03d.nc' }; ...
                0054 { 'mnc_out_381600/MLfields.0000374400.t%03d.nc' }; ...
                0055 { 'mnc_out_388800/MLfields.0000381600.t%03d.nc' }; ...
                0056 { 'mnc_out_396000/MLfields.0000388800.t%03d.nc' }; ...
                0057 { 'mnc_out_403200/MLfields.0000396000.t%03d.nc' }; ...
                0058 { 'mnc_out_410400/MLfields.0000403200.t%03d.nc' }; ...
                0059 { 'mnc_out_417600/MLfields.0000410400.t%03d.nc' }; ...
                0060 { 'mnc_out_424800/MLfields.0000417600.t%03d.nc' }; ...
                0061 { 'mnc_out_432000/MLfields.0000424800.t%03d.nc' }; ...
                0062 { 'mnc_out_439200/MLfields.0000432000.t%03d.nc' }; ...
                0063 { 'mnc_out_446400/MLfields.0000439200.t%03d.nc' }; ...
                0064 { 'mnc_out_453600/MLfields.0000446400.t%03d.nc' }; ...
                0065 { 'mnc_out_460800/MLfields.0000453600.t%03d.nc' }; ...
                0066 { 'mnc_out_468000/MLfields.0000460800.t%03d.nc' }; ...
                0067 { 'mnc_out_475200/MLfields.0000468000.t%03d.nc' }; ...
                0068 { 'mnc_out_482400/MLfields.0000475200.t%03d.nc' }; ...
                0069 { 'mnc_out_489600/MLfields.0000482400.t%03d.nc' }; ...
                0070 { 'mnc_out_496800/MLfields.0000489600.t%03d.nc' }; ...
                0071 { 'mnc_out_504000/MLfields.0000496800.t%03d.nc' }; ...
                0072 { 'mnc_out_511200/MLfields.0000504000.t%03d.nc' }; ...
                0073 { 'mnc_out_518400/MLfields.0000511200.t%03d.nc' }; ...
                0074 { 'mnc_out_525600/MLfields.0000518400.t%03d.nc' }; ...
                0075 { 'mnc_out_532800/MLfields.0000525600.t%03d.nc' }; ...
                0076 { 'mnc_out_540000/MLfields.0000532800.t%03d.nc' }; ...
                0077 { 'mnc_out_547200/MLfields.0000540000.t%03d.nc' }; ...
                0078 { 'mnc_out_554400/MLfields.0000547200.t%03d.nc' }; ...
                0079 { 'mnc_out_561600/MLfields.0000554400.t%03d.nc' }; ...
                0080 { 'mnc_out_568800/MLfields.0000561600.t%03d.nc' }; ...
                0081 { 'mnc_out_576000/MLfields.0000568800.t%03d.nc' }; ...
                0082 { 'mnc_out_583200/MLfields.0000576000.t%03d.nc' }; ...
                0083 { 'mnc_out_590400/MLfields.0000583200.t%03d.nc' }; ...
                0084 { 'mnc_out_597600/MLfields.0000590400.t%03d.nc' }; ...
                0085 { 'mnc_out_604800/MLfields.0000597600.t%03d.nc' }; ...
                0086 { 'mnc_out_612000/MLfields.0000604800.t%03d.nc' }; ...
                0087 { 'mnc_out_619200/MLfields.0000612000.t%03d.nc' }; ...
                0088 { 'mnc_out_626400/MLfields.0000619200.t%03d.nc' }; ...
                0089 { 'mnc_out_633600/MLfields.0000626400.t%03d.nc' }; ...
                0090 { 'mnc_out_640800/MLfields.0000633600.t%03d.nc' }; ...
                0091 { 'mnc_out_648000/MLfields.0000640800.t%03d.nc' }; ...
                0092 { 'mnc_out_655200/MLfields.0000648000.t%03d.nc' }; ...
                0093 { 'mnc_out_662400/MLfields.0000655200.t%03d.nc' }; ...
                0094 { 'mnc_out_669600/MLfields.0000662400.t%03d.nc' }; ...
                0095 { 'mnc_out_676800/MLfields.0000669600.t%03d.nc' }; ...
                0096 { 'mnc_out_684000/MLfields.0000676800.t%03d.nc' }; ...
                0097 { 'mnc_out_691200/MLfields.0000684000.t%03d.nc' }; ...
                0098 { 'mnc_out_698400/MLfields.0000691200.t%03d.nc' }; ...
                0099 { 'mnc_out_705600/MLfields.0000698400.t%03d.nc' }; ...
                0100 { 'mnc_out_712800/MLfields.0000705600.t%03d.nc' }; ...
                0101 { 'mnc_out_720000/MLfields.0000712800.t%03d.nc' }; ...
                0102 { 'mnc_out_727200/MLfields.0000720000.t%03d.nc' }; ...
                0103 { 'mnc_out_734400/MLfields.0000727200.t%03d.nc' }; ...
                0104 { 'mnc_out_741600/MLfields.0000734400.t%03d.nc' }; ...
                0105 { 'mnc_out_748800/MLfields.0000741600.t%03d.nc' }; ...
                0106 { 'mnc_out_756000/MLfields.0000748800.t%03d.nc' }; ...
                0107 { 'mnc_out_763200/MLfields.0000756000.t%03d.nc' }; ...
                0108 { 'mnc_out_770400/MLfields.0000763200.t%03d.nc' }; ...
                0109 { 'mnc_out_777600/MLfields.0000770400.t%03d.nc' }; ...
                0110 { 'mnc_out_784800/MLfields.0000777600.t%03d.nc' }; ...
                0111 { 'mnc_out_792000/MLfields.0000784800.t%03d.nc' }; ...
                0112 { 'mnc_out_799200/MLfields.0000792000.t%03d.nc' }; ...
                0113 { 'mnc_out_806400/MLfields.0000799200.t%03d.nc' }; ...
                0114 { 'mnc_out_813600/MLfields.0000806400.t%03d.nc' }; ...
                0115 { 'mnc_out_820800/MLfields.0000813600.t%03d.nc' }; ...
                0116 { 'mnc_out_828000/MLfields.0000820800.t%03d.nc' }; ...
                0117 { 'mnc_out_835200/MLfields.0000828000.t%03d.nc' }; ...
                0118 { 'mnc_out_842400/MLfields.0000835200.t%03d.nc' }; ...
                0119 { 'mnc_out_849600/MLfields.0000842400.t%03d.nc' }; ...
                0120 { 'mnc_out_856800/MLfields.0000849600.t%03d.nc' }; ...
                0121 { 'mnc_out_864000/MLfields.0000856800.t%03d.nc' }; ...
                0122 { 'mnc_out_871200/MLfields.0000864000.t%03d.nc' }; ...
                0123 { 'mnc_out_878400/MLfields.0000871200.t%03d.nc' }; ...
                0124 { 'mnc_out_885600/MLfields.0000878400.t%03d.nc' }; ...
                0125 { 'mnc_out_892800/MLfields.0000885600.t%03d.nc' }; ...
                0126 { 'mnc_out_900000/MLfields.0000892800.t%03d.nc' }; ...
                0127 { 'mnc_out_907200/MLfields.0000900000.t%03d.nc' }; ...
                0128 };
                0129 
                0130 vars = { ...
                0131     {'u','UVEL','masku'} ...
                0132     {'v','VVEL','maskv'} ...
                0133     {'w','WVEL','mask'} ...
                0134     {'phi','PHIHYD','mask'} ...
                0135     {'q','SALT','mask'} ...
                0136     {'rh','RELHUM','mask'} ...
                0137     {'th','THETA','mask'} ...
                0138        };
                0139 
                0140 %======================================================================
                0141 %
                0142 %  Interpolate to the reference pressure levels and then compute the
                0143 %  derived fields and the temporal sums of all fields on the original
                0144 %  MITgcm grid
                0145 %
                0146 disp('Computing Sums')
                0147 
                0148 itile = 1;
                0149 for itile = 1:3
                0150   
                0151   it0 = 0;
                0152   for iv = 1:length(vars)
                0153     eval(sprintf('clear %s', vars{iv}{1} ));
                0154   end
                0155   
                0156   fi = 1;
                0157   for fi = [ 1:length(files) ]
                0158 
                0159     fib = 0;
                0160   
                0161     fname = sprintf(files{fi}{1},itile);
                0162     disp([ '  fname = "' fname '"' ]);
                0163     nc = netcdf(fname, 'nowrite');
                0164     times = nc{'T'}(:);
                0165 
                0166     it = 1;
                0167     for it = 1:length(times)
                0168       
                0169       for iv = 1:length(vars)
                0170         eval(sprintf('%s = squeeze(nc{ ''%s'' }(it,:,:,:));', ...
                0171                      vars{iv}{1},vars{iv}{2}));
                0172         eval(sprintf('mr = max(abs(%s(:)));', vars{iv}{1}));
                0173         if mr > 1e10
                0174           %  error('values heading out of range!!!');
                0175           fib = 1;
                0176         end
                0177       end
                0178 
                0179       mask = double(th ~= 0.0);
                0180       masku = ones(size(th) + [0 0 1]);
                0181       masku(:,:,1:(end-1)) = masku(:,:,1:(end-1)) .* mask;
                0182       masku(:,:,2:end    ) = masku(:,:,2:end    ) .* mask;
                0183       maskv = ones(size(th) + [0 1 0]);
                0184       maskv(:,1:(end-1),:) = maskv(:,1:(end-1),:) .* mask;
                0185       maskv(:,2:end,    :) = maskv(:,2:end,    :) .* mask;
                0186       
                0187       if it0 == 0
                0188         it0 = 1;
                0189         for iv = 1:length(vars)
                0190           eval(sprintf('%s_ave = zeros(size(%s));', ...
                0191                        vars{iv}{1},vars{iv}{1}));
                0192         end
                0193         mask_sum = zeros(size(mask));
                0194         masku_sum = zeros(size(masku));
                0195         maskv_sum = zeros(size(maskv));
                0196       end
                0197       for iv = 1:length(vars)
                0198         eval(sprintf('%s_ave = %s_ave + (%s .* %s);', ...
                0199                      vars{iv}{1}, vars{iv}{1}, ...
                0200                      vars{iv}{3}, vars{iv}{1}));
                0201       end
                0202       mask_sum = mask_sum + mask;
                0203       masku_sum = masku_sum + masku;
                0204       maskv_sum = maskv_sum + maskv;
                0205       
                0206     end
                0207     
                0208     if fib == 1
                0209       disp([ 'BAD ::  "' fname '"' ]);
                0210     end
                0211     
                0212     nc = close(nc);
                0213     
                0214   end
                0215 
                0216   for iv = 1:length(vars)
                0217     eval(sprintf('%s_ave = %s_ave ./ %s_sum;', ...
                0218                  vars{iv}{1}, vars{iv}{1}, vars{iv}{3} ));
                0219   end
                0220   
                0221   nc = netcdf(sprintf('mnc_out_processed/ML_ave_%d.nc',itile), 'clobber');
                0222   
                0223   nc('T') = 0;
                0224   nc('Z') = 17;
                0225   nc('X') = 32;   nc('Xp1') = 33;
                0226   nc('Y') = 32;   nc('Yp1') = 33;
                0227   
                0228   for iv = 1:length(vars)
                0229     switch vars{iv}{3}
                0230      case 'mask'
                0231       nc{ vars{iv}{2} } = ncdouble( 'T', 'Z', 'Y', 'X' );
                0232      case 'masku'
                0233       nc{ vars{iv}{2} } = ncdouble( 'T', 'Z', 'Y', 'Xp1' );
                0234      case 'maskv'
                0235       nc{ vars{iv}{2} } = ncdouble( 'T', 'Z', 'Yp1', 'X' );
                0236     end
                0237     eval(sprintf('nc{ vars{iv}{2} }(1,:,:,:) = %s_ave;',vars{iv}{1}));
                0238   end
                0239   nc{ 'mask_sum' } = ncdouble( 'T', 'Z', 'Y', 'X' );
                0240   nc{ 'mask_sum' }(1,:,:,:) = mask_sum;
                0241   nc{ 'masku_sum' } = ncdouble( 'T', 'Z', 'Y', 'Xp1' );
                0242   nc{ 'masku_sum' }(1,:,:,:) = masku_sum;
                0243   nc{ 'maskv_sum' } = ncdouble( 'T', 'Z', 'Yp1', 'X' );
                0244   nc{ 'maskv_sum' }(1,:,:,:) = maskv_sum;
                0245   nc = close(nc);
                0246 
                0247 end
                0248