Warning, /verification/fizhi-cs-aqualev20/scripts/assemble_MF.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 MF fields:
0006 %
0007 % Read all variables:
0008 % Convert units as necessary:
0009 % Regrid onto lat-lon:
0010 % Write netCDF output with all attributes:
0011 %
0012
0013
0014 %======================================================================
0015 %
0016 % Define the connections between the APE "ML" variables and the
0017 % MITgcm diagnostics output
0018 %
0019 oname = { 'MF_fields.nc' };
0020 title = 'Averages variance quantities as 3D fields';
0021 nl = 64;
0022 np = 17;
0023
0024
0025 % Get the following from:
0026 % ! (cd ../../ape_data_specs/ ; ./mf_parse_v2.sh)
0027 vars = {};
0028 vars{1} = {'MF01','mf_uu','u2totz','zonal_wind_variance','m2 s-2'};
0029 vars{2} = {'MF02','mf_vv','v2totz','meridional_wind_variance','m2 s-2'};
0030 vars{3} = {'MF03','mf_tt','potempsqz','temperature_variance','K2'};
0031 vars{4} = {'MF04','mf_omom','wvelsqz','omega_variance','Pa2 s-2'};
0032 vars{5} = {'MF05','mf_phiphi','phihydsqz','geopotential_variance','(m2 s-2)2'};
0033 vars{6} = {'MF06','mf_qq','saltsqz','specific_humidity_variance','(kg kg-1)2'};
0034 vars{7} = {'MF07','mf_uv','uvtotz','poleward_zonal_momentum_flux','m2 s-2'};
0035 vars{8} = {'MF08','mf_uom','wuEz','vertical_zonal_momentum_flux','m Pa s-2'};
0036 vars{9} = {'MF09','mf_vom','wvNz','vertical_meridional_momentum_flux','m Pa s-2'};
0037 vars{10} = {'MF10','mf_vt','vNthz','poleward_temperature_flux','m s-1 K'};
0038 vars{11} = {'MF11','mf_omt','wvelthz','vertical_temperature_flux','Pa s-1 K'};
0039 vars{12} = {'MF12','mf_vq','vNsltz','poleward_moisture_flux','m s-1 kg kg-1'};
0040 vars{13} = {'MF13','mf_omq','wvelsltz','vertical_moisture_flux','Pa s-1 kg kg-1'};
0041 vars{14} = {'MF14','mf_vphi','vNphiz','poleward_geopotential_flux','m3 s-3'};
0042 vars{15} = {'MF15','mf_sm_uu','smusq','zonal_wind_variance_stationary_mean','m2 s-2'};
0043 vars{16} = {'MF16','mf_sm_vv','smvsq','meridional_wind_variance_stationary_mean','m2 s-2'};
0044 vars{17} = {'MF17','mf_sm_tt','smtsq','temperature_variance_stationary_mean','K2'};
0045 vars{18} = {'MF18','mf_sm_omom','smwsq','omega_variance_stationary_mean','Pa2 s-2'};
0046 vars{19} = {'MF19','mf_sm_phiphi','smphisq','geopotential_variance_stationary_mean','(m2 s-2)2'};
0047 vars{20} = {'MF20','mf_sm_qq','smqsq','specific_humidity_variance_stationary_mean','(kg kg-1)2'};
0048 vars{21} = {'MF21','mf_sm_uv','smuv','poleward_zonal_momentum_flux_stationary_mean','m2 s-2'};
0049 vars{22} = {'MF22','mf_sm_uom','smuw','vertical_zonal_momentum_flux_stationary_mean','m Pa s-2'};
0050 vars{23} = {'MF23','mf_sm_vom','smvw','vertical_meridional_momentum_flux_stationary_mean','m Pa s-2'};
0051 vars{24} = {'MF24','mf_sm_vt','smvt','poleward_temperature_flux_stationary_mean','m s-1 K'};
0052 vars{25} = {'MF25','mf_sm_omt','smwt','vertical_temperature_flux_stationary_mean','Pa s-1 K'};
0053 vars{26} = {'MF26','mf_sm_vq','smvq','poleward_moisture_flux_stationary_mean','m s-1 kg kg-1'};
0054 vars{27} = {'MF27','mf_sm_omq','smwq','vertical_moisture_flux_stationary_mean','Pa s-1 kg kg-1'};
0055 vars{28} = {'MF28','mf_sm_vphi','smvphi','poleward_geopotential_flux_stationary_mean','m3 s-3'};
0056 vars{29} = {'MF29','mf_se_uu','seusq','zonal_wind_variance_stationary_eddy','m2 s-2'};
0057 vars{30} = {'MF30','mf_se_vv','sevsq','meridional_wind_variance__stationary_eddy','m2 s-2'};
0058 vars{31} = {'MF31','mf_se_tt','setsq','temperature_variance_stationary_eddy','K2'};
0059 vars{32} = {'MF32','mf_se_omom','sewsq','omega_variance_stationary_eddy','Pa2 s-2'};
0060 vars{33} = {'MF33','mf_se_phiphi','sephisq','geopotential_variance_stationary_eddy','(m2 s-2)2'};
0061 vars{34} = {'MF34','mf_se_qq','seqsq','specific_humidity_variance_stationary_eddy','(kg kg-1)2'};
0062 vars{35} = {'MF35','mf_se_uv','seuv','poleward_zonal_momentum_flux_stationary_eddy','m2 s-2'};
0063 vars{36} = {'MF36','mf_se_uom','seuw','vertical_zonal_momentum_flux_stationary_eddy','m Pa s-2'};
0064 vars{37} = {'MF37','mf_se_vom','sevw','vertical_meridional_momentum_flux_stationary_eddy','m Pa s-2'};
0065 vars{38} = {'MF38','mf_se_vt','sevt','poleward_temperature_flux_stationary_eddy','m s-1 K'};
0066 vars{39} = {'MF39','mf_se_omt','sewt','vertical_temperature_flux_stationary_eddy','Pa s-1 K'};
0067 vars{40} = {'MF40','mf_se_vq','sevq','poleward_moisture_flux_stationary_eddy','m s-1 kg kg-1'};
0068 vars{41} = {'MF41','mf_se_omq','sewq','vertical_moisture_flux_stationary_eddy','Pa s-1 kg kg-1'};
0069 vars{42} = {'MF42','mf_se_vphi','sevphi','poleward_geopotential_flux_stationary_eddy','m3 s-3'};
0070 vars{43} = {'MF43','mf_tm_uu','tmusq','zonal_wind_variance_transient_mean_merdional','m2 s-2'};
0071 vars{44} = {'MF44','mf_tm_vv','tmvsq','meridional_wind_variance_transient_mean_merdional','m2 s-2'};
0072 vars{45} = {'MF45','mf_tm_tt','tmtsq','temperature_variance_transient_mean_merdional','K2'};
0073 vars{46} = {'MF46','mf_tm_omom','tmwsq','omega_variance_transient_mean_merdional','Pa2 s-2'};
0074 vars{47} = {'MF47','mf_tm_phiphi','tmphisq','geopotential_variance_transient_mean_merdional','(m2 s-2)2'};
0075 vars{48} = {'MF48','mf_tm_qq','tmqsq','specific_humidity_variance_transient_mean_merdional','(kg kg-1)2'};
0076 vars{49} = {'MF49','mf_tm_uv','tmuv','poleward_zonal_momentum_flux_transient_mean_merdional','m2 s-2'};
0077 vars{50} = {'MF50','mf_tm_uom','tmuw','vertical_zonal_momentum_flux_transient_mean_merdional','m Pa s-2'};
0078 vars{51} = {'MF51','mf_tm_vom','tmvw','vertical_meridional_momentum_flux_transient_mean_merdional','m Pa s-2'};
0079 vars{52} = {'MF52','mf_tm_vt','tmvt','poleward_temperature_flux_transient_mean_merdional','m s-1 K'};
0080 vars{53} = {'MF53','mf_tm_omt','tmwt','vertical_temperature_flux_transient_mean_merdional','Pa s-1 K'};
0081 vars{54} = {'MF54','mf_tm_vq','tmvq','poleward_moisture_flux_transient_mean_merdional','m s-1 kg kg-1'};
0082 vars{55} = {'MF55','mf_tm_omq','tmwq','vertical_moisture_flux_transient_mean_merdional','Pa s-1 kg kg-1'};
0083 vars{56} = {'MF56','mf_tm_vphi','tmvphi','poleward_geopotential_flux_transient_mean_merdional','m3 s-3'};
0084 vars{57} = {'MF57','mf_te_uu','teusq','zonal_wind_variance_transient_eddy','m2 s-2'};
0085 vars{58} = {'MF58','mf_te_vv','tevsq','meridional_wind_variance_transient_eddy','m2 s-2'};
0086 vars{59} = {'MF59','mf_te_tt','tetsq','temperature_variance_transient_eddy','K2'};
0087 vars{60} = {'MF60','mf_te_omom','tewsq','omega_variance_transient_eddy','Pa2 s-2'};
0088 vars{61} = {'MF61','mf_te_phiphi','tephisq','geopotential_variance_transient_eddy','(m2 s-2)2'};
0089 vars{62} = {'MF62','mf_te_qq','teqsq','specific_humidity_variance_transient_eddy','(kg kg-1)2'};
0090 vars{63} = {'MF63','mf_te_uv','teuv','poleward_zonal_momentum_flux_transient_eddy','m2 s-2'};
0091 vars{64} = {'MF64','mf_te_uom','teuw','vertical_zonal_momentum_flux_transient_eddy','m Pa s-2'};
0092 vars{65} = {'MF65','mf_te_vom','tevw','vertical_meridional_momentum_flux_transient_eddy','m Pa s-2'};
0093 vars{66} = {'MF66','mf_te_vt','tevt','poleward_temperature_flux_transient_eddy','m s-1 K'};
0094 vars{67} = {'MF67','mf_te_omt','tewt','vertical_temperature_flux_transient_eddy','Pa s-1 K'};
0095 vars{68} = {'MF68','mf_te_vq','tevq','poleward_moisture_flux_transient_eddy','m s-1 kg kg-1'};
0096 vars{69} = {'MF69','mf_te_omq','tewq','vertical_moisture_flux_transient_eddy','Pa s-1 kg kg-1'};
0097 vars{70} = {'MF70','mf_te_vphi','tevphi','poleward_geopotential_flux_transient_eddy','m3 s-3'};
0098
0099
0100
0101 %======================================================================
0102 %
0103 % Read and save the fields
0104 %
0105 disp('Reading fields')
0106
0107 Pref = [ 1 2 3 5 7 10 15 20 25 30 40 50 60 70 85 92.5 100 ] * 10;
0108 Pref = Pref(length(Pref):-1:1);
0109 pfac = (Pref./1000).^0.286;
0110
0111 ave = struct([]);
0112 i = 1;
0113 for i = 1:length(vars)
0114
0115 if strcmp(vars{i}{3},'--')
0116 continue
0117 end
0118
0119 fid = fopen([ 'data/' vars{i}{3} '.bin' ],'r','ieee-be');
0120 tmp = fread(fid,nl*np,'real*8');
0121 fclose(fid);
0122 ia = length(ave) + 1;
0123 ave(ia).dat = reshape(tmp,[nl np]);
0124 ave(ia).ivar = i;
0125
0126 %=================================
0127 % unit conversions
0128
0129 % theta ==> T
0130 if strcmp(vars{i}{2}((end-1):end),'tt')
0131 disp([' Converting units th^2 ==> T^2 for: "' vars{i}{2} '"'])
0132 for il = 1:nl
0133 ave(ia).dat(il,:) = ave(ia).dat(il,:) .* (pfac.^2);
0134 end
0135 elseif strcmp(vars{i}{2}(end:end),'t')
0136 disp([' Converting units th ==> T for: "' vars{i}{2} '"'])
0137 for il = 1:nl
0138 ave(ia).dat(il,:) = ave(ia).dat(il,:) .* pfac;
0139 end
0140 end
0141
0142 % geopotential
0143 % if length(vars{i}{2}) > 6
0144 % if strcmp(vars{i}{2}((end-5):end),'phiphi')
0145 % disp([' Converting units phiphi/g^2 for: "' vars{i}{2} '"'])
0146 % ave(ia).dat(:,:) = ave(ia).dat(:,:) ./ (9.81^2);
0147 % elseif strcmp(vars{i}{2}((end-2):end),'phi')
0148 % disp([' Converting units phi/g for: "' vars{i}{2} '"'])
0149 % ave(ia).dat(:,:) = ave(ia).dat(:,:) ./ 9.81;
0150 % end
0151 % end
0152
0153 end
0154
0155 %======================================================================
0156 %
0157 % Grid Info
0158 %
0159 % JMC suggested an evenly spaced Lat-Lon at: 128x64
0160 %
0161
0162 og = [];
0163 og.nlat = 64;
0164 og.latcell = 180/og.nlat;
0165 og.lat = linspace(-90+og.latcell/2, 90-og.latcell/2, og.nlat);
0166 og.latbnd(:,1) = og.lat - og.latcell/2.0;
0167 og.latbnd(:,2) = og.lat + og.latcell/2.0;
0168
0169 Pref = [ 1 2 3 5 7 10 15 20 25 30 40 50 60 70 85 92.5 100 ] * 10;
0170 Pref = Pref(length(Pref):-1:1);
0171
0172
0173 %======================================================================
0174 %
0175 % Write netCDF output
0176 %
0177 disp('Writing netCDF output')
0178
0179 nc = netcdf(oname{1}, 'clobber');
0180 nc.title = [ 'Aqua Planet: ' ...
0181 title ];
0182 nc.institution = 'MIT Dept. of EAPS, Cambridge, MA, USA';
0183 nc.source = [ 'MITgcm: ' ];
0184 nc.Conventions = 'CF-1.0';
0185 %nc.history = [ 'Original data produced: ' '2002/08/20' ];
0186
0187 nc('pres') = length(Pref);
0188 nc('lat') = og.nlat;
0189 nc('bnd') = 2;
0190
0191 nc{'pres'} = ncdouble('pres');
0192 nc{'pres'}.standard_name = 'air_pressure';
0193 nc{'pres'}.units = 'Pa';
0194 nc{'pres'}(:) = Pref*100;
0195
0196 nc{'lat'} = ncdouble('lat');
0197 nc{'lat'}.standard_name = 'latitude';
0198 nc{'lat'}.units = 'degrees_north';
0199 nc{'lat'}.bounds = 'lat_bnds';
0200 nc{'lat'}(:) = og.lat;
0201
0202 nc{'lat_bnds'} = ncdouble('lat','bnd');
0203 nc{'lat_bnds'}.ape_name = 'latitude cell bounds';
0204 nc{'lat_bnds'}.units = 'degrees_north';
0205 nc{'lat_bnds'}(:) = og.latbnd;
0206
0207 for ii = 1:length(ave)
0208
0209 iv = ave(ii).ivar;
0210 nc{ vars{iv}{2} } = ncfloat( 'pres', 'lat' );
0211 nc{ vars{iv}{2} }.ape_name = vars{iv}{4};
0212 nc{ vars{iv}{2} }.units = vars{iv}{5};
0213 nc{ vars{iv}{2} }.FillValue_ = 1.0e20;
0214
0215 % handle missing values
0216 indf = find( ave(ii).dat >= 1.0e14 );
0217 ave(ii).dat(indf) = 1.0e20;
0218
0219 nc{ vars{iv}{2} }(:) = ave(ii).dat';
0220
0221 end
0222
0223 nc = close(nc);
0224
0225