text:
# this file only needs to be called once to setup the data files needed to run RRTM.jl

# it uses:
# netcdfs/rrtmg_lw.nc
# srtm_kgbs/srtm_kgb$(iband).jl

using PyCall
using JLD
@pyimport xarray as xr

function make_weights(nb,ngc,ngn,ngm,wt)
  mg = 16
  wtsm = zeros(mg)
  rwgt = zeros(nb*mg)

  igcsm = 0
  for ibnd = 1:nb
    iprsm = 0
    if (ngc[ibnd] < mg)
      for igc = 1:ngc[ibnd]
        igcsm += 1
        wtsum = 0.
        for ipr = 1:ngn[igcsm]
          iprsm += 1
          wtsum += wt[iprsm]
        end
        wtsm[igc] = wtsum
      end
      for ig = 1:mg
        ind = (ibnd-1)*mg + ig
        rwgt[ind] = wt[ig]/wtsm[ngm[ind]]
      end
    else
      for ig = 1:mg
        igcsm += 1
        ind = (ibnd-1)*mg + ig
        rwgt[ind] = 1.0
      end
    end
  end

  wtsm,rwgt
end

function fancy_sum(array,ibnd,ngn,rwgt,rwgt_on=true)
  println(size(array))
  mg = 16
  local_ngn = ngn[findfirst(cumsum(ngn),(ibnd-1)*mg)+1:findfirst(cumsum(ngn),ibnd*mg)]
  new_array = zeros(size(array)[1:end-1]...,length(local_ngn))
  dims = length(size(array))
  cumsum_local_ngn = cumsum(local_ngn)
  for i in 1:length(local_ngn)
    ngn_range = (cumsum_local_ngn[i]-local_ngn[i]+1):cumsum_local_ngn[i]
    local_rwgt = rwgt_on ? rwgt[(ibnd-1)*mg + ngn_range] : ones(length(ngn_range))
    input = sum(array[fill(:,dims-1)...,ngn_range].*reshape(local_rwgt,(fill(1,dims-1)...,local_ngn[i])),dims)
    new_array[fill(:,dims-1)...,i] = (dims > 1) ? input : input[1]
  end
  new_array
end

function setup_aerosol_parameters()
  println("Setting up aersol parameters")
  naer=4

  caesc= [ 0.6688e+00, -0.1172e+00, -0.1013e+00,  0.1636e-01,
  -0.3699e-01,  0.1775e-01, -0.9635e-02,  0.1290e-02,
  0.4681e-04, -0.9106e-04,  0.9355e-04, -0.7076e-01,
  -0.1782e-01,  0.1856e-01,  0.1372e-01,  0.8210e-04,
  0.2149e-02,  0.4856e-03,  0.2231e-03,  0.1824e-03,
  0.1960e-05,  0.2057e-01,  0.2703e-01,  0.2424e-01,
  0.9716e-02,  0.1312e-02, -0.8846e-03, -0.3347e-03,
  0.6231e-04,  0.6397e-04, -0.3341e-02, -0.1295e-01,
  -0.4598e-02,  0.3242e-03,  0.8122e-03, -0.2975e-03,
  -0.7757e-04,  0.7793e-04,  0.4455e-02, -0.1584e-01,
  -0.2551e-02,  0.1174e-02,  0.1335e-04,  0.5112e-04,
  0.5605e-04,  0.7412e-04,  0.1857e-02, -0.1917e-03,
  0.4460e-03,  0.1767e-04, -0.5281e-04, -0.5043e-03,
  0.2467e-03, -0.2497e-03, -0.2377e-04, -0.3954e-04,
  0.2666e-03, -0.8186e-03, -0.1441e-03, -0.1904e-04,
  0.3337e-03, -0.1696e-03, -0.2503e-04,  0.1239e-03,
  -0.9983e-04, -0.5283e-04] #< sea aero cosine coeffs

  caess= [-0.3374e-01, -0.3247e-01, -0.1012e-01,  0.6002e-02,
  0.5190e-02,  0.7784e-03, -0.1090e-02,  0.3294e-03,
  0.1719e-03, -0.5866e-05, -0.4124e-03, -0.3742e-01,
  -0.5054e-02,  0.3430e-02,  0.5513e-03, -0.6235e-03,
  0.2892e-03, -0.9730e-04,  0.7078e-04, -0.3300e-01,
  0.5104e-03, -0.2156e-02, -0.3194e-02, -0.5079e-03,
  -0.5517e-03,  0.4632e-04,  0.5369e-04, -0.2731e-01,
  0.5126e-02,  0.2241e-02, -0.5789e-03, -0.3048e-03,
  -0.1774e-03,  0.1946e-05, -0.8247e-02,  0.2338e-02,
  0.1021e-02,  0.1575e-04,  0.2612e-05,  0.1995e-04,
  -0.1319e-02,  0.1384e-02, -0.4159e-03, -0.2337e-03,
  0.5764e-04,  0.1495e-02, -0.3727e-03,  0.6075e-04,
  -0.4642e-04,  0.5368e-03, -0.7619e-04,  0.3774e-04,
  0.1206e-03, -0.4104e-06,  0.2158e-04] #< sea aero sine coeffs

  caelc= [ 0.1542e+00,  0.8245e-01, -0.1879e-03,  0.4864e-02,
  -0.5527e-02, -0.7966e-02, -0.2683e-02, -0.2011e-02,
  -0.8889e-03, -0.1058e-03, -0.1614e-04,  0.4206e-01,
  0.1912e-01, -0.9476e-02, -0.6780e-02,  0.1767e-03,
  -0.5422e-03, -0.7753e-03, -0.2106e-03, -0.9870e-04,
  -0.1721e-04, -0.9536e-02, -0.9580e-02, -0.1050e-01,
  -0.5747e-02, -0.1282e-02,  0.2248e-03,  0.1694e-03,
  -0.4782e-04, -0.2441e-04,  0.5781e-03,  0.6212e-02,
  0.1921e-02, -0.1102e-02, -0.8145e-03,  0.2497e-03,
  0.1539e-03, -0.2538e-04, -0.3993e-02,  0.9777e-02,
  0.4837e-03, -0.1304e-02,  0.2417e-04, -0.1370e-04,
  -0.3731e-05,  0.1922e-02, -0.5167e-03,  0.4295e-03,
  -0.1888e-03,  0.2427e-04,  0.4012e-04,  0.1529e-02,
  -0.2120e-03,  0.8166e-04,  0.2579e-04,  0.3488e-04,
  0.2140e-03,  0.2274e-03, -0.3447e-05, -0.1075e-04,
  -0.1018e-03,  0.2864e-04,  0.3442e-04, -0.1002e-03,
  0.7117e-04,  0.2045e-04] #< land aero cosine coeffs

  caels= [ 0.1637e-01,  0.1935e-01,  0.1080e-01,  0.2784e-02,
  0.1606e-03,  0.1860e-02,  0.1263e-02, -0.2707e-03,
  -0.2290e-03, -0.9761e-05, -0.7317e-02,  0.2465e-01,
  0.6799e-02, -0.1913e-02,  0.1382e-02,  0.6691e-03,
  0.1414e-03,  0.3527e-04, -0.5210e-04,  0.1873e-01,
  0.2977e-02,  0.4650e-02,  0.2509e-02,  0.3680e-03,
  0.1481e-03, -0.6594e-04, -0.5634e-04,  0.1592e-01,
  -0.1875e-02, -0.1093e-02,  0.3022e-03,  0.2625e-03,
  0.3252e-04, -0.3803e-04,  0.4218e-02, -0.1843e-02,
  -0.1351e-02, -0.2952e-03, -0.8171e-05, -0.1473e-04,
  0.9076e-03, -0.1057e-02,  0.2676e-03,  0.1307e-03,
  -0.3628e-04, -0.9158e-03,  0.4335e-03,  0.2927e-04,
  0.6602e-04, -0.3570e-03,  0.5760e-04, -0.3465e-04,
  -0.8535e-04, -0.2011e-04,  0.6612e-06] #< land aero sine coeffs

  caeuc= [ 0.8005e-01,  0.7095e-01,  0.2014e-01, -0.1412e-01,
  -0.2425e-01, -0.1332e-01, -0.2904e-02,  0.5068e-03,
  0.9369e-03,  0.4114e-03,  0.7549e-04,  0.1922e-01,
  0.2534e-01,  0.2088e-01,  0.1064e-01,  0.1063e-02,
  -0.2526e-02, -0.2091e-02, -0.9660e-03, -0.2030e-03,
  0.3865e-04, -0.9900e-02, -0.5964e-02,  0.2223e-02,
  0.4941e-02,  0.3277e-02,  0.1038e-02, -0.1480e-03,
  -0.2844e-03, -0.1208e-03,  0.3999e-02,  0.6282e-02,
  0.2813e-02,  0.1475e-02,  0.4571e-03, -0.1349e-03,
  -0.9011e-04, -0.1936e-04,  0.1994e-02,  0.3540e-02,
  0.8837e-03,  0.1992e-03,  0.3092e-04, -0.7979e-04,
  -0.2664e-04, -0.5006e-04,  0.6447e-03,  0.5550e-03,
  0.1197e-03,  0.6657e-04,  0.1488e-04, -0.9141e-04,
  -0.2896e-03, -0.1561e-03, -0.6524e-04, -0.1559e-04,
  -0.1082e-03, -0.4126e-03, -0.1732e-03, -0.8286e-04,
  -0.1993e-04,  0.3850e-04,  0.2870e-04,  0.4493e-04,
  0.4721e-04,  0.1338e-04] #< urban aero cosine coeffs

  caeus= [ 0.6646e-02,  0.8373e-02,  0.5463e-02,  0.4554e-02,
  0.3301e-02,  0.5725e-03, -0.7482e-03, -0.6222e-03,
  -0.2603e-03, -0.5127e-04, -0.3849e-04,  0.9741e-02,
  0.8190e-02,  0.5712e-02,  0.3039e-02,  0.5290e-03,
  -0.2044e-03, -0.2309e-03, -0.1160e-03,  0.9160e-02,
  0.1286e-01,  0.1170e-01,  0.5491e-02,  0.1393e-02,
  -0.6288e-04, -0.2715e-03, -0.1047e-03,  0.4873e-02,
  0.3545e-02,  0.3069e-02,  0.1819e-02,  0.6947e-03,
  0.1416e-03, -0.1538e-04, -0.4351e-03, -0.1907e-02,
  -0.5774e-03, -0.2247e-03,  0.5345e-04,  0.9052e-04,
  -0.3972e-04, -0.9665e-04,  0.7912e-04, -0.1094e-04,
  -0.6776e-05,  0.2724e-03,  0.1973e-03,  0.6837e-04,
  0.4313e-04, -0.7174e-05,  0.8527e-05, -0.2160e-05,
  -0.7852e-04,  0.3453e-06, -0.2402e-05] #< urban aero sine coeffs

  caedc= [ 0.2840e-01,  0.1775e-01, -0.1069e-01, -0.1553e-01,
  -0.3299e-02,  0.3583e-02,  0.2274e-02,  0.5767e-04,
  -0.3678e-03, -0.1050e-03,  0.2133e-04,  0.2326e-01,
  0.1566e-01, -0.3130e-02, -0.8253e-02, -0.2615e-02,
  0.1247e-02,  0.1059e-02,  0.1196e-03, -0.1303e-03,
  -0.5094e-04,  0.1185e-01,  0.7238e-02, -0.1562e-02,
  -0.3665e-02, -0.1182e-02,  0.4678e-03,  0.4448e-03,
  0.8307e-04, -0.3468e-04,  0.5273e-02,  0.3037e-02,
  -0.4014e-03, -0.1202e-02, -0.4647e-03,  0.5148e-04,
  0.1014e-03,  0.2996e-04,  0.2505e-02,  0.1495e-02,
  0.2438e-03, -0.1223e-03, -0.7669e-04, -0.1638e-04,
  0.1869e-05,  0.1094e-02,  0.6131e-03,  0.1508e-03,
  0.1765e-04,  0.1360e-05, -0.7998e-06,  0.4475e-03,
  0.2737e-03,  0.6430e-04, -0.6759e-05, -0.6761e-05,
  0.1992e-03,  0.1531e-03,  0.4828e-04,  0.5103e-06,
  0.7454e-04,  0.5917e-04,  0.2152e-04,  0.9300e-05,
  0.9790e-05, -0.8853e-05] #< desert aero cosine coeffs

  caeds= [ 0.9815e-02,  0.8436e-02,  0.1087e-02, -0.2717e-02,
  -0.1755e-02, -0.1559e-03,  0.2367e-03,  0.8808e-04,
  0.2001e-05, -0.1244e-05,  0.1041e-01,  0.8039e-02,
  0.1005e-02, -0.1981e-02, -0.1090e-02,  0.1595e-05,
  0.1787e-03,  0.4644e-04, -0.1052e-04,  0.6593e-02,
  0.3983e-02, -0.1527e-03, -0.1235e-02, -0.5078e-03,
  0.3649e-04,  0.1005e-03,  0.3182e-04,  0.3225e-02,
  0.1672e-02, -0.7752e-04, -0.4312e-03, -0.1872e-03,
  -0.1666e-04,  0.1872e-04,  0.1133e-02,  0.5643e-03,
  0.7747e-04, -0.2980e-04, -0.2092e-04, -0.8590e-05,
  0.2988e-03,  0.6714e-04, -0.6249e-05,  0.1052e-04,
  0.8790e-05,  0.1569e-03, -0.1175e-04, -0.3033e-04,
  -0.9777e-06,  0.1101e-03,  0.6827e-05, -0.1023e-04,
  0.4231e-04,  0.4905e-05,  0.6229e-05] #< desert aero sine coeffs

  #> longwave optical depth factor in five LW bands
  caer=reshape([
  0.038520, 0.037196, 0.040532, 0.054934, 0.038520 ,
  0.126130, 0.183130, 0.103570, 0.064106, 0.126130 ,
  0.012579, 0.013649, 0.018652, 0.025181, 0.012579 ,
  0.013792, 0.026810, 0.052203, 0.066338, 0.013792
  ],(5,naer))

  save("jlds/aerosol_parameters.jld","caesc",caesc,"caess",caess,"caelc",caelc,"caels",caels,"caeuc",caeuc,"caeus",caeus,"caedc",caedc,"caeds",caeds,"caer",caer)
  println("Aerosol parameters written to jlds/aerosol_parameters.jld")
end

function setup_LW_parameters()
  println("Setting up LW parameters")

  totplnk = zeros(181,16)
  totplnk[1:50,  1] = [0.14783e-05,0.15006e-05,0.15230e-05,0.15455e-05,0.15681e-05,0.15908e-05,0.16136e-05,0.16365e-05,0.16595e-05,0.16826e-05,0.17059e-05,0.17292e-05,0.17526e-05,0.17762e-05,0.17998e-05,0.18235e-05,0.18473e-05,0.18712e-05,0.18953e-05,0.19194e-05,0.19435e-05,0.19678e-05,0.19922e-05,0.20166e-05,0.20412e-05,0.20658e-05,0.20905e-05,0.21153e-05,0.21402e-05,0.21652e-05,0.21902e-05,0.22154e-05,0.22406e-05,0.22659e-05,0.22912e-05,0.23167e-05,0.23422e-05,0.23678e-05,0.23934e-05,0.24192e-05,0.24450e-05,0.24709e-05,0.24968e-05,0.25229e-05,0.25490e-05,0.25751e-05,0.26014e-05,0.26277e-05,0.26540e-05,0.26805e-05]
  totplnk[51:100,  1] = [0.27070e-05,0.27335e-05,0.27602e-05,0.27869e-05,0.28136e-05,0.28404e-05,0.28673e-05,0.28943e-05,0.29213e-05,0.29483e-05,0.29754e-05,0.30026e-05,0.30298e-05,0.30571e-05,0.30845e-05,0.31119e-05,0.31393e-05,0.31669e-05,0.31944e-05,0.32220e-05,0.32497e-05,0.32774e-05,0.33052e-05,0.33330e-05,0.33609e-05,0.33888e-05,0.34168e-05,0.34448e-05,0.34729e-05,0.35010e-05,0.35292e-05,0.35574e-05,0.35857e-05,0.36140e-05,0.36424e-05,0.36708e-05,0.36992e-05,0.37277e-05,0.37563e-05,0.37848e-05,0.38135e-05,0.38421e-05,0.38708e-05,0.38996e-05,0.39284e-05,0.39572e-05,0.39861e-05,0.40150e-05,0.40440e-05,0.40730e-05]
  totplnk[101:150,  1] = [0.41020e-05,0.41311e-05,0.41602e-05,0.41893e-05,0.42185e-05,0.42477e-05,0.42770e-05,0.43063e-05,0.43356e-05,0.43650e-05,0.43944e-05,0.44238e-05,0.44533e-05,0.44828e-05,0.45124e-05,0.45419e-05,0.45715e-05,0.46012e-05,0.46309e-05,0.46606e-05,0.46903e-05,0.47201e-05,0.47499e-05,0.47797e-05,0.48096e-05,0.48395e-05,0.48695e-05,0.48994e-05,0.49294e-05,0.49594e-05,0.49895e-05,0.50196e-05,0.50497e-05,0.50798e-05,0.51100e-05,0.51402e-05,0.51704e-05,0.52007e-05,0.52309e-05,0.52612e-05,0.52916e-05,0.53219e-05,0.53523e-05,0.53827e-05,0.54132e-05,0.54436e-05,0.54741e-05,0.55047e-05,0.55352e-05,0.55658e-05]
  totplnk[151:181,  1] = [0.55964e-05,0.56270e-05,0.56576e-05,0.56883e-05,0.57190e-05,0.57497e-05,0.57804e-05,0.58112e-05,0.58420e-05,0.58728e-05,0.59036e-05,0.59345e-05,0.59653e-05,0.59962e-05,0.60272e-05,0.60581e-05,0.60891e-05,0.61201e-05,0.61511e-05,0.61821e-05,0.62131e-05,0.62442e-05,0.62753e-05,0.63064e-05,0.63376e-05,0.63687e-05,0.63998e-05,0.64310e-05,0.64622e-05,0.64935e-05,0.65247e-05]
  totplnk[1:50,  2] = [0.20262e-05,0.20757e-05,0.21257e-05,0.21763e-05,0.22276e-05,0.22794e-05,0.23319e-05,0.23849e-05,0.24386e-05,0.24928e-05,0.25477e-05,0.26031e-05,0.26591e-05,0.27157e-05,0.27728e-05,0.28306e-05,0.28889e-05,0.29478e-05,0.30073e-05,0.30673e-05,0.31279e-05,0.31890e-05,0.32507e-05,0.33129e-05,0.33757e-05,0.34391e-05,0.35029e-05,0.35674e-05,0.36323e-05,0.36978e-05,0.37638e-05,0.38304e-05,0.38974e-05,0.39650e-05,0.40331e-05,0.41017e-05,0.41708e-05,0.42405e-05,0.43106e-05,0.43812e-05,0.44524e-05,0.45240e-05,0.45961e-05,0.46687e-05,0.47418e-05,0.48153e-05,0.48894e-05,0.49639e-05,0.50389e-05,0.51143e-05]
  totplnk[51:100,  2] = [0.51902e-05,0.52666e-05,0.53434e-05,0.54207e-05,0.54985e-05,0.55767e-05,0.56553e-05,0.57343e-05,0.58139e-05,0.58938e-05,0.59742e-05,0.60550e-05,0.61362e-05,0.62179e-05,0.63000e-05,0.63825e-05,0.64654e-05,0.65487e-05,0.66324e-05,0.67166e-05,0.68011e-05,0.68860e-05,0.69714e-05,0.70571e-05,0.71432e-05,0.72297e-05,0.73166e-05,0.74039e-05,0.74915e-05,0.75796e-05,0.76680e-05,0.77567e-05,0.78459e-05,0.79354e-05,0.80252e-05,0.81155e-05,0.82061e-05,0.82970e-05,0.83883e-05,0.84799e-05,0.85719e-05,0.86643e-05,0.87569e-05,0.88499e-05,0.89433e-05,0.90370e-05,0.91310e-05,0.92254e-05,0.93200e-05,0.94150e-05]
  totplnk[101:150,  2] = [0.95104e-05,0.96060e-05,0.97020e-05,0.97982e-05,0.98948e-05,0.99917e-05,0.10089e-04,0.10186e-04,0.10284e-04,0.10382e-04,0.10481e-04,0.10580e-04,0.10679e-04,0.10778e-04,0.10877e-04,0.10977e-04,0.11077e-04,0.11178e-04,0.11279e-04,0.11380e-04,0.11481e-04,0.11583e-04,0.11684e-04,0.11786e-04,0.11889e-04,0.11992e-04,0.12094e-04,0.12198e-04,0.12301e-04,0.12405e-04,0.12509e-04,0.12613e-04,0.12717e-04,0.12822e-04,0.12927e-04,0.13032e-04,0.13138e-04,0.13244e-04,0.13349e-04,0.13456e-04,0.13562e-04,0.13669e-04,0.13776e-04,0.13883e-04,0.13990e-04,0.14098e-04,0.14206e-04,0.14314e-04,0.14422e-04,0.14531e-04]
  totplnk[151:181,  2] = [0.14639e-04,0.14748e-04,0.14857e-04,0.14967e-04,0.15076e-04,0.15186e-04,0.15296e-04,0.15407e-04,0.15517e-04,0.15628e-04,0.15739e-04,0.15850e-04,0.15961e-04,0.16072e-04,0.16184e-04,0.16296e-04,0.16408e-04,0.16521e-04,0.16633e-04,0.16746e-04,0.16859e-04,0.16972e-04,0.17085e-04,0.17198e-04,0.17312e-04,0.17426e-04,0.17540e-04,0.17654e-04,0.17769e-04,0.17883e-04,0.17998e-04]
  totplnk[1:50, 3] = [1.34822e-06,1.39134e-06,1.43530e-06,1.48010e-06,1.52574e-06,1.57222e-06,1.61956e-06,1.66774e-06,1.71678e-06,1.76666e-06,1.81741e-06,1.86901e-06,1.92147e-06,1.97479e-06,2.02898e-06,2.08402e-06,2.13993e-06,2.19671e-06,2.25435e-06,2.31285e-06,2.37222e-06,2.43246e-06,2.49356e-06,2.55553e-06,2.61837e-06,2.68207e-06,2.74664e-06,2.81207e-06,2.87837e-06,2.94554e-06,3.01356e-06,3.08245e-06,3.15221e-06,3.22282e-06,3.29429e-06,3.36662e-06,3.43982e-06,3.51386e-06,3.58876e-06,3.66451e-06,3.74112e-06,3.81857e-06,3.89688e-06,3.97602e-06,4.05601e-06,4.13685e-06,4.21852e-06,4.30104e-06,4.38438e-06,4.46857e-06]
  totplnk[51:100, 3] = [4.55358e-06,4.63943e-06,4.72610e-06,4.81359e-06,4.90191e-06,4.99105e-06,5.08100e-06,5.17176e-06,5.26335e-06,5.35573e-06,5.44892e-06,5.54292e-06,5.63772e-06,5.73331e-06,5.82970e-06,5.92688e-06,6.02485e-06,6.12360e-06,6.22314e-06,6.32346e-06,6.42455e-06,6.52641e-06,6.62906e-06,6.73247e-06,6.83664e-06,6.94156e-06,7.04725e-06,7.15370e-06,7.26089e-06,7.36883e-06,7.47752e-06,7.58695e-06,7.69712e-06,7.80801e-06,7.91965e-06,8.03201e-06,8.14510e-06,8.25891e-06,8.37343e-06,8.48867e-06,8.60463e-06,8.72128e-06,8.83865e-06,8.95672e-06,9.07548e-06,9.19495e-06,9.31510e-06,9.43594e-06,9.55745e-06,9.67966e-06]
  totplnk[101:150, 3] = [9.80254e-06,9.92609e-06,1.00503e-05,1.01752e-05,1.03008e-05,1.04270e-05,1.05539e-05,1.06814e-05,1.08096e-05,1.09384e-05,1.10679e-05,1.11980e-05,1.13288e-05,1.14601e-05,1.15922e-05,1.17248e-05,1.18581e-05,1.19920e-05,1.21265e-05,1.22616e-05,1.23973e-05,1.25337e-05,1.26706e-05,1.28081e-05,1.29463e-05,1.30850e-05,1.32243e-05,1.33642e-05,1.35047e-05,1.36458e-05,1.37875e-05,1.39297e-05,1.40725e-05,1.42159e-05,1.43598e-05,1.45044e-05,1.46494e-05,1.47950e-05,1.49412e-05,1.50879e-05,1.52352e-05,1.53830e-05,1.55314e-05,1.56803e-05,1.58297e-05,1.59797e-05,1.61302e-05,1.62812e-05,1.64327e-05,1.65848e-05]
  totplnk[151:181, 3] = [1.67374e-05,1.68904e-05,1.70441e-05,1.71982e-05,1.73528e-05,1.75079e-05,1.76635e-05,1.78197e-05,1.79763e-05,1.81334e-05,1.82910e-05,1.84491e-05,1.86076e-05,1.87667e-05,1.89262e-05,1.90862e-05,1.92467e-05,1.94076e-05,1.95690e-05,1.97309e-05,1.98932e-05,2.00560e-05,2.02193e-05,2.03830e-05,2.05472e-05,2.07118e-05,2.08768e-05,2.10423e-05,2.12083e-05,2.13747e-05,2.15414e-05]
  totplnk[1:50, 4] = [8.90528e-07,9.24222e-07,9.58757e-07,9.94141e-07,1.03038e-06,1.06748e-06,1.10545e-06,1.14430e-06,1.18403e-06,1.22465e-06,1.26618e-06,1.30860e-06,1.35193e-06,1.39619e-06,1.44136e-06,1.48746e-06,1.53449e-06,1.58246e-06,1.63138e-06,1.68124e-06,1.73206e-06,1.78383e-06,1.83657e-06,1.89028e-06,1.94495e-06,2.00060e-06,2.05724e-06,2.11485e-06,2.17344e-06,2.23303e-06,2.29361e-06,2.35519e-06,2.41777e-06,2.48134e-06,2.54592e-06,2.61151e-06,2.67810e-06,2.74571e-06,2.81433e-06,2.88396e-06,2.95461e-06,3.02628e-06,3.09896e-06,3.17267e-06,3.24741e-06,3.32316e-06,3.39994e-06,3.47774e-06,3.55657e-06,3.63642e-06]
  totplnk[51:100, 4] = [3.71731e-06,3.79922e-06,3.88216e-06,3.96612e-06,4.05112e-06,4.13714e-06,4.22419e-06,4.31227e-06,4.40137e-06,4.49151e-06,4.58266e-06,4.67485e-06,4.76806e-06,4.86229e-06,4.95754e-06,5.05383e-06,5.15113e-06,5.24946e-06,5.34879e-06,5.44916e-06,5.55053e-06,5.65292e-06,5.75632e-06,5.86073e-06,5.96616e-06,6.07260e-06,6.18003e-06,6.28848e-06,6.39794e-06,6.50838e-06,6.61983e-06,6.73229e-06,6.84573e-06,6.96016e-06,7.07559e-06,7.19200e-06,7.30940e-06,7.42779e-06,7.54715e-06,7.66749e-06,7.78882e-06,7.91110e-06,8.03436e-06,8.15859e-06,8.28379e-06,8.40994e-06,8.53706e-06,8.66515e-06,8.79418e-06,8.92416e-06]
  totplnk[101:150, 4] = [9.05510e-06,9.18697e-06,9.31979e-06,9.45356e-06,9.58826e-06,9.72389e-06,9.86046e-06,9.99793e-06,1.01364e-05,1.02757e-05,1.04159e-05,1.05571e-05,1.06992e-05,1.08422e-05,1.09861e-05,1.11309e-05,1.12766e-05,1.14232e-05,1.15707e-05,1.17190e-05,1.18683e-05,1.20184e-05,1.21695e-05,1.23214e-05,1.24741e-05,1.26277e-05,1.27822e-05,1.29376e-05,1.30939e-05,1.32509e-05,1.34088e-05,1.35676e-05,1.37273e-05,1.38877e-05,1.40490e-05,1.42112e-05,1.43742e-05,1.45380e-05,1.47026e-05,1.48680e-05,1.50343e-05,1.52014e-05,1.53692e-05,1.55379e-05,1.57074e-05,1.58778e-05,1.60488e-05,1.62207e-05,1.63934e-05,1.65669e-05]
  totplnk[151:181, 4] = [1.67411e-05,1.69162e-05,1.70920e-05,1.72685e-05,1.74459e-05,1.76240e-05,1.78029e-05,1.79825e-05,1.81629e-05,1.83440e-05,1.85259e-05,1.87086e-05,1.88919e-05,1.90760e-05,1.92609e-05,1.94465e-05,1.96327e-05,1.98199e-05,2.00076e-05,2.01961e-05,2.03853e-05,2.05752e-05,2.07658e-05,2.09571e-05,2.11491e-05,2.13418e-05,2.15352e-05,2.17294e-05,2.19241e-05,2.21196e-05,2.23158e-05]
  totplnk[1:50, 5] = [5.70230e-07,5.94788e-07,6.20085e-07,6.46130e-07,6.72936e-07,7.00512e-07,7.28869e-07,7.58019e-07,7.87971e-07,8.18734e-07,8.50320e-07,8.82738e-07,9.15999e-07,9.50110e-07,9.85084e-07,1.02093e-06,1.05765e-06,1.09527e-06,1.13378e-06,1.17320e-06,1.21353e-06,1.25479e-06,1.29698e-06,1.34011e-06,1.38419e-06,1.42923e-06,1.47523e-06,1.52221e-06,1.57016e-06,1.61910e-06,1.66904e-06,1.71997e-06,1.77192e-06,1.82488e-06,1.87886e-06,1.93387e-06,1.98991e-06,2.04699e-06,2.10512e-06,2.16430e-06,2.22454e-06,2.28584e-06,2.34821e-06,2.41166e-06,2.47618e-06,2.54178e-06,2.60847e-06,2.67626e-06,2.74514e-06,2.81512e-06]
  totplnk[51:100, 5] = [2.88621e-06,2.95841e-06,3.03172e-06,3.10615e-06,3.18170e-06,3.25838e-06,3.33618e-06,3.41511e-06,3.49518e-06,3.57639e-06,3.65873e-06,3.74221e-06,3.82684e-06,3.91262e-06,3.99955e-06,4.08763e-06,4.17686e-06,4.26725e-06,4.35880e-06,4.45150e-06,4.54537e-06,4.64039e-06,4.73659e-06,4.83394e-06,4.93246e-06,5.03215e-06,5.13301e-06,5.23504e-06,5.33823e-06,5.44260e-06,5.54814e-06,5.65484e-06,5.76272e-06,5.87177e-06,5.98199e-06,6.09339e-06,6.20596e-06,6.31969e-06,6.43460e-06,6.55068e-06,6.66793e-06,6.78636e-06,6.90595e-06,7.02670e-06,7.14863e-06,7.27173e-06,7.39599e-06,7.52142e-06,7.64802e-06,7.77577e-06]
  totplnk[101:150, 5] = [7.90469e-06,8.03477e-06,8.16601e-06,8.29841e-06,8.43198e-06,8.56669e-06,8.70256e-06,8.83957e-06,8.97775e-06,9.11706e-06,9.25753e-06,9.39915e-06,9.54190e-06,9.68580e-06,9.83085e-06,9.97704e-06,1.01243e-05,1.02728e-05,1.04224e-05,1.05731e-05,1.07249e-05,1.08779e-05,1.10320e-05,1.11872e-05,1.13435e-05,1.15009e-05,1.16595e-05,1.18191e-05,1.19799e-05,1.21418e-05,1.23048e-05,1.24688e-05,1.26340e-05,1.28003e-05,1.29676e-05,1.31361e-05,1.33056e-05,1.34762e-05,1.36479e-05,1.38207e-05,1.39945e-05,1.41694e-05,1.43454e-05,1.45225e-05,1.47006e-05,1.48797e-05,1.50600e-05,1.52413e-05,1.54236e-05,1.56070e-05]
  totplnk[151:181, 5] = [1.57914e-05,1.59768e-05,1.61633e-05,1.63509e-05,1.65394e-05,1.67290e-05,1.69197e-05,1.71113e-05,1.73040e-05,1.74976e-05,1.76923e-05,1.78880e-05,1.80847e-05,1.82824e-05,1.84811e-05,1.86808e-05,1.88814e-05,1.90831e-05,1.92857e-05,1.94894e-05,1.96940e-05,1.98996e-05,2.01061e-05,2.03136e-05,2.05221e-05,2.07316e-05,2.09420e-05,2.11533e-05,2.13657e-05,2.15789e-05,2.17931e-05]
  totplnk[1:50, 6] = [2.73493e-07,2.87408e-07,3.01848e-07,3.16825e-07,3.32352e-07,3.48439e-07,3.65100e-07,3.82346e-07,4.00189e-07,4.18641e-07,4.37715e-07,4.57422e-07,4.77774e-07,4.98784e-07,5.20464e-07,5.42824e-07,5.65879e-07,5.89638e-07,6.14115e-07,6.39320e-07,6.65266e-07,6.91965e-07,7.19427e-07,7.47666e-07,7.76691e-07,8.06516e-07,8.37151e-07,8.68607e-07,9.00896e-07,9.34029e-07,9.68018e-07,1.00287e-06,1.03860e-06,1.07522e-06,1.11274e-06,1.15117e-06,1.19052e-06,1.23079e-06,1.27201e-06,1.31418e-06,1.35731e-06,1.40141e-06,1.44650e-06,1.49257e-06,1.53965e-06,1.58773e-06,1.63684e-06,1.68697e-06,1.73815e-06,1.79037e-06]
  totplnk[51:100, 6] = [1.84365e-06,1.89799e-06,1.95341e-06,2.00991e-06,2.06750e-06,2.12619e-06,2.18599e-06,2.24691e-06,2.30895e-06,2.37212e-06,2.43643e-06,2.50189e-06,2.56851e-06,2.63628e-06,2.70523e-06,2.77536e-06,2.84666e-06,2.91916e-06,2.99286e-06,3.06776e-06,3.14387e-06,3.22120e-06,3.29975e-06,3.37953e-06,3.46054e-06,3.54280e-06,3.62630e-06,3.71105e-06,3.79707e-06,3.88434e-06,3.97288e-06,4.06270e-06,4.15380e-06,4.24617e-06,4.33984e-06,4.43479e-06,4.53104e-06,4.62860e-06,4.72746e-06,4.82763e-06,4.92911e-06,5.03191e-06,5.13603e-06,5.24147e-06,5.34824e-06,5.45634e-06,5.56578e-06,5.67656e-06,5.78867e-06,5.90213e-06]
  totplnk[101:150, 6] = [6.01694e-06,6.13309e-06,6.25060e-06,6.36947e-06,6.48968e-06,6.61126e-06,6.73420e-06,6.85850e-06,6.98417e-06,7.11120e-06,7.23961e-06,7.36938e-06,7.50053e-06,7.63305e-06,7.76694e-06,7.90221e-06,8.03887e-06,8.17690e-06,8.31632e-06,8.45710e-06,8.59928e-06,8.74282e-06,8.88776e-06,9.03409e-06,9.18179e-06,9.33088e-06,9.48136e-06,9.63323e-06,9.78648e-06,9.94111e-06,1.00971e-05,1.02545e-05,1.04133e-05,1.05735e-05,1.07351e-05,1.08980e-05,1.10624e-05,1.12281e-05,1.13952e-05,1.15637e-05,1.17335e-05,1.19048e-05,1.20774e-05,1.22514e-05,1.24268e-05,1.26036e-05,1.27817e-05,1.29612e-05,1.31421e-05,1.33244e-05]
  totplnk[151:181, 6] = [1.35080e-05,1.36930e-05,1.38794e-05,1.40672e-05,1.42563e-05,1.44468e-05,1.46386e-05,1.48318e-05,1.50264e-05,1.52223e-05,1.54196e-05,1.56182e-05,1.58182e-05,1.60196e-05,1.62223e-05,1.64263e-05,1.66317e-05,1.68384e-05,1.70465e-05,1.72559e-05,1.74666e-05,1.76787e-05,1.78921e-05,1.81069e-05,1.83230e-05,1.85404e-05,1.87591e-05,1.89791e-05,1.92005e-05,1.94232e-05,1.96471e-05]
  totplnk[1:50, 7] = [1.25349e-07,1.32735e-07,1.40458e-07,1.48527e-07,1.56954e-07,1.65748e-07,1.74920e-07,1.84481e-07,1.94443e-07,2.04814e-07,2.15608e-07,2.26835e-07,2.38507e-07,2.50634e-07,2.63229e-07,2.76301e-07,2.89864e-07,3.03930e-07,3.18508e-07,3.33612e-07,3.49253e-07,3.65443e-07,3.82195e-07,3.99519e-07,4.17428e-07,4.35934e-07,4.55050e-07,4.74785e-07,4.95155e-07,5.16170e-07,5.37844e-07,5.60186e-07,5.83211e-07,6.06929e-07,6.31355e-07,6.56498e-07,6.82373e-07,7.08990e-07,7.36362e-07,7.64501e-07,7.93420e-07,8.23130e-07,8.53643e-07,8.84971e-07,9.17128e-07,9.50123e-07,9.83969e-07,1.01868e-06,1.05426e-06,1.09073e-06]
  totplnk[51:100, 7] = [1.12810e-06,1.16638e-06,1.20558e-06,1.24572e-06,1.28680e-06,1.32883e-06,1.37183e-06,1.41581e-06,1.46078e-06,1.50675e-06,1.55374e-06,1.60174e-06,1.65078e-06,1.70087e-06,1.75200e-06,1.80421e-06,1.85749e-06,1.91186e-06,1.96732e-06,2.02389e-06,2.08159e-06,2.14040e-06,2.20035e-06,2.26146e-06,2.32372e-06,2.38714e-06,2.45174e-06,2.51753e-06,2.58451e-06,2.65270e-06,2.72210e-06,2.79272e-06,2.86457e-06,2.93767e-06,3.01201e-06,3.08761e-06,3.16448e-06,3.24261e-06,3.32204e-06,3.40275e-06,3.48476e-06,3.56808e-06,3.65271e-06,3.73866e-06,3.82595e-06,3.91456e-06,4.00453e-06,4.09584e-06,4.18851e-06,4.28254e-06]
  totplnk[101:150, 7] = [4.37796e-06,4.47475e-06,4.57293e-06,4.67249e-06,4.77346e-06,4.87583e-06,4.97961e-06,5.08481e-06,5.19143e-06,5.29948e-06,5.40896e-06,5.51989e-06,5.63226e-06,5.74608e-06,5.86136e-06,5.97810e-06,6.09631e-06,6.21597e-06,6.33713e-06,6.45976e-06,6.58388e-06,6.70950e-06,6.83661e-06,6.96521e-06,7.09531e-06,7.22692e-06,7.36005e-06,7.49468e-06,7.63084e-06,7.76851e-06,7.90773e-06,8.04846e-06,8.19072e-06,8.33452e-06,8.47985e-06,8.62674e-06,8.77517e-06,8.92514e-06,9.07666e-06,9.22975e-06,9.38437e-06,9.54057e-06,9.69832e-06,9.85762e-06,1.00185e-05,1.01810e-05,1.03450e-05,1.05106e-05,1.06777e-05,1.08465e-05]
  totplnk[151:181, 7] = [1.10168e-05,1.11887e-05,1.13621e-05,1.15372e-05,1.17138e-05,1.18920e-05,1.20718e-05,1.22532e-05,1.24362e-05,1.26207e-05,1.28069e-05,1.29946e-05,1.31839e-05,1.33749e-05,1.35674e-05,1.37615e-05,1.39572e-05,1.41544e-05,1.43533e-05,1.45538e-05,1.47558e-05,1.49595e-05,1.51647e-05,1.53716e-05,1.55800e-05,1.57900e-05,1.60017e-05,1.62149e-05,1.64296e-05,1.66460e-05,1.68640e-05]
  totplnk[1:50, 8] = [6.74445e-08,7.18176e-08,7.64153e-08,8.12456e-08,8.63170e-08,9.16378e-08,9.72168e-08,1.03063e-07,1.09184e-07,1.15591e-07,1.22292e-07,1.29296e-07,1.36613e-07,1.44253e-07,1.52226e-07,1.60540e-07,1.69207e-07,1.78236e-07,1.87637e-07,1.97421e-07,2.07599e-07,2.18181e-07,2.29177e-07,2.40598e-07,2.52456e-07,2.64761e-07,2.77523e-07,2.90755e-07,3.04468e-07,3.18673e-07,3.33381e-07,3.48603e-07,3.64352e-07,3.80638e-07,3.97474e-07,4.14871e-07,4.32841e-07,4.51395e-07,4.70547e-07,4.90306e-07,5.10687e-07,5.31699e-07,5.53357e-07,5.75670e-07,5.98652e-07,6.22315e-07,6.46672e-07,6.71731e-07,6.97511e-07,7.24018e-07]
  totplnk[51:100, 8] = [7.51266e-07,7.79269e-07,8.08038e-07,8.37584e-07,8.67922e-07,8.99061e-07,9.31016e-07,9.63797e-07,9.97417e-07,1.03189e-06,1.06722e-06,1.10343e-06,1.14053e-06,1.17853e-06,1.21743e-06,1.25726e-06,1.29803e-06,1.33974e-06,1.38241e-06,1.42606e-06,1.47068e-06,1.51630e-06,1.56293e-06,1.61056e-06,1.65924e-06,1.70894e-06,1.75971e-06,1.81153e-06,1.86443e-06,1.91841e-06,1.97350e-06,2.02968e-06,2.08699e-06,2.14543e-06,2.20500e-06,2.26573e-06,2.32762e-06,2.39068e-06,2.45492e-06,2.52036e-06,2.58700e-06,2.65485e-06,2.72393e-06,2.79424e-06,2.86580e-06,2.93861e-06,3.01269e-06,3.08803e-06,3.16467e-06,3.24259e-06]
  totplnk[101:150, 8] = [3.32181e-06,3.40235e-06,3.48420e-06,3.56739e-06,3.65192e-06,3.73779e-06,3.82502e-06,3.91362e-06,4.00359e-06,4.09494e-06,4.18768e-06,4.28182e-06,4.37737e-06,4.47434e-06,4.57273e-06,4.67254e-06,4.77380e-06,4.87651e-06,4.98067e-06,5.08630e-06,5.19339e-06,5.30196e-06,5.41201e-06,5.52356e-06,5.63660e-06,5.75116e-06,5.86722e-06,5.98479e-06,6.10390e-06,6.22453e-06,6.34669e-06,6.47042e-06,6.59569e-06,6.72252e-06,6.85090e-06,6.98085e-06,7.11238e-06,7.24549e-06,7.38019e-06,7.51646e-06,7.65434e-06,7.79382e-06,7.93490e-06,8.07760e-06,8.22192e-06,8.36784e-06,8.51540e-06,8.66459e-06,8.81542e-06,8.96786e-06]
  totplnk[151:181, 8] = [9.12197e-06,9.27772e-06,9.43513e-06,9.59419e-06,9.75490e-06,9.91728e-06,1.00813e-05,1.02471e-05,1.04144e-05,1.05835e-05,1.07543e-05,1.09267e-05,1.11008e-05,1.12766e-05,1.14541e-05,1.16333e-05,1.18142e-05,1.19969e-05,1.21812e-05,1.23672e-05,1.25549e-05,1.27443e-05,1.29355e-05,1.31284e-05,1.33229e-05,1.35193e-05,1.37173e-05,1.39170e-05,1.41185e-05,1.43217e-05,1.45267e-05]
  totplnk[1:50, 9] = [2.61522e-08,2.80613e-08,3.00838e-08,3.22250e-08,3.44899e-08,3.68841e-08,3.94129e-08,4.20820e-08,4.48973e-08,4.78646e-08,5.09901e-08,5.42799e-08,5.77405e-08,6.13784e-08,6.52001e-08,6.92126e-08,7.34227e-08,7.78375e-08,8.24643e-08,8.73103e-08,9.23832e-08,9.76905e-08,1.03240e-07,1.09039e-07,1.15097e-07,1.21421e-07,1.28020e-07,1.34902e-07,1.42075e-07,1.49548e-07,1.57331e-07,1.65432e-07,1.73860e-07,1.82624e-07,1.91734e-07,2.01198e-07,2.11028e-07,2.21231e-07,2.31818e-07,2.42799e-07,2.54184e-07,2.65983e-07,2.78205e-07,2.90862e-07,3.03963e-07,3.17519e-07,3.31541e-07,3.46039e-07,3.61024e-07,3.76507e-07]
  totplnk[51:100, 9] = [3.92498e-07,4.09008e-07,4.26050e-07,4.43633e-07,4.61769e-07,4.80469e-07,4.99744e-07,5.19606e-07,5.40067e-07,5.61136e-07,5.82828e-07,6.05152e-07,6.28120e-07,6.51745e-07,6.76038e-07,7.01010e-07,7.26674e-07,7.53041e-07,7.80124e-07,8.07933e-07,8.36482e-07,8.65781e-07,8.95845e-07,9.26683e-07,9.58308e-07,9.90732e-07,1.02397e-06,1.05803e-06,1.09292e-06,1.12866e-06,1.16526e-06,1.20274e-06,1.24109e-06,1.28034e-06,1.32050e-06,1.36158e-06,1.40359e-06,1.44655e-06,1.49046e-06,1.53534e-06,1.58120e-06,1.62805e-06,1.67591e-06,1.72478e-06,1.77468e-06,1.82561e-06,1.87760e-06,1.93066e-06,1.98479e-06,2.04000e-06]
  totplnk[101:150, 9] = [2.09631e-06,2.15373e-06,2.21228e-06,2.27196e-06,2.33278e-06,2.39475e-06,2.45790e-06,2.52222e-06,2.58773e-06,2.65445e-06,2.72238e-06,2.79152e-06,2.86191e-06,2.93354e-06,3.00643e-06,3.08058e-06,3.15601e-06,3.23273e-06,3.31075e-06,3.39009e-06,3.47074e-06,3.55272e-06,3.63605e-06,3.72072e-06,3.80676e-06,3.89417e-06,3.98297e-06,4.07315e-06,4.16474e-06,4.25774e-06,4.35217e-06,4.44802e-06,4.54532e-06,4.64406e-06,4.74428e-06,4.84595e-06,4.94911e-06,5.05376e-06,5.15990e-06,5.26755e-06,5.37671e-06,5.48741e-06,5.59963e-06,5.71340e-06,5.82871e-06,5.94559e-06,6.06403e-06,6.18404e-06,6.30565e-06,6.42885e-06]
  totplnk[151:181, 9] = [6.55364e-06,6.68004e-06,6.80806e-06,6.93771e-06,7.06898e-06,7.20190e-06,7.33646e-06,7.47267e-06,7.61056e-06,7.75010e-06,7.89133e-06,8.03423e-06,8.17884e-06,8.32514e-06,8.47314e-06,8.62284e-06,8.77427e-06,8.92743e-06,9.08231e-06,9.23893e-06,9.39729e-06,9.55741e-06,9.71927e-06,9.88291e-06,1.00483e-05,1.02155e-05,1.03844e-05,1.05552e-05,1.07277e-05,1.09020e-05,1.10781e-05]
  totplnk[1:50,10] = [8.89300e-09,9.63263e-09,1.04235e-08,1.12685e-08,1.21703e-08,1.31321e-08,1.41570e-08,1.52482e-08,1.64090e-08,1.76428e-08,1.89533e-08,2.03441e-08,2.18190e-08,2.33820e-08,2.50370e-08,2.67884e-08,2.86402e-08,3.05969e-08,3.26632e-08,3.48436e-08,3.71429e-08,3.95660e-08,4.21179e-08,4.48040e-08,4.76294e-08,5.05996e-08,5.37201e-08,5.69966e-08,6.04349e-08,6.40411e-08,6.78211e-08,7.17812e-08,7.59276e-08,8.02670e-08,8.48059e-08,8.95508e-08,9.45090e-08,9.96873e-08,1.05093e-07,1.10733e-07,1.16614e-07,1.22745e-07,1.29133e-07,1.35786e-07,1.42711e-07,1.49916e-07,1.57410e-07,1.65202e-07,1.73298e-07,1.81709e-07]
  totplnk[51:100,10] = [1.90441e-07,1.99505e-07,2.08908e-07,2.18660e-07,2.28770e-07,2.39247e-07,2.50101e-07,2.61340e-07,2.72974e-07,2.85013e-07,2.97467e-07,3.10345e-07,3.23657e-07,3.37413e-07,3.51623e-07,3.66298e-07,3.81448e-07,3.97082e-07,4.13212e-07,4.29848e-07,4.47000e-07,4.64680e-07,4.82898e-07,5.01664e-07,5.20991e-07,5.40888e-07,5.61369e-07,5.82440e-07,6.04118e-07,6.26410e-07,6.49329e-07,6.72887e-07,6.97095e-07,7.21964e-07,7.47506e-07,7.73732e-07,8.00655e-07,8.28287e-07,8.56635e-07,8.85717e-07,9.15542e-07,9.46122e-07,9.77469e-07,1.00960e-06,1.04251e-06,1.07623e-06,1.11077e-06,1.14613e-06,1.18233e-06,1.21939e-06]
  totplnk[101:150,10] = [1.25730e-06,1.29610e-06,1.33578e-06,1.37636e-06,1.41785e-06,1.46027e-06,1.50362e-06,1.54792e-06,1.59319e-06,1.63942e-06,1.68665e-06,1.73487e-06,1.78410e-06,1.83435e-06,1.88564e-06,1.93797e-06,1.99136e-06,2.04582e-06,2.10137e-06,2.15801e-06,2.21576e-06,2.27463e-06,2.33462e-06,2.39577e-06,2.45806e-06,2.52153e-06,2.58617e-06,2.65201e-06,2.71905e-06,2.78730e-06,2.85678e-06,2.92749e-06,2.99946e-06,3.07269e-06,3.14720e-06,3.22299e-06,3.30007e-06,3.37847e-06,3.45818e-06,3.53923e-06,3.62161e-06,3.70535e-06,3.79046e-06,3.87695e-06,3.96481e-06,4.05409e-06,4.14477e-06,4.23687e-06,4.33040e-06,4.42538e-06]
  totplnk[151:181,10] = [4.52180e-06,4.61969e-06,4.71905e-06,4.81991e-06,4.92226e-06,5.02611e-06,5.13148e-06,5.23839e-06,5.34681e-06,5.45681e-06,5.56835e-06,5.68146e-06,5.79614e-06,5.91242e-06,6.03030e-06,6.14978e-06,6.27088e-06,6.39360e-06,6.51798e-06,6.64398e-06,6.77165e-06,6.90099e-06,7.03198e-06,7.16468e-06,7.29906e-06,7.43514e-06,7.57294e-06,7.71244e-06,7.85369e-06,7.99666e-06,8.14138e-06]
  totplnk[1:50,11] = [2.53767e-09,2.77242e-09,3.02564e-09,3.29851e-09,3.59228e-09,3.90825e-09,4.24777e-09,4.61227e-09,5.00322e-09,5.42219e-09,5.87080e-09,6.35072e-09,6.86370e-09,7.41159e-09,7.99628e-09,8.61974e-09,9.28404e-09,9.99130e-09,1.07437e-08,1.15436e-08,1.23933e-08,1.32953e-08,1.42522e-08,1.52665e-08,1.63410e-08,1.74786e-08,1.86820e-08,1.99542e-08,2.12985e-08,2.27179e-08,2.42158e-08,2.57954e-08,2.74604e-08,2.92141e-08,3.10604e-08,3.30029e-08,3.50457e-08,3.71925e-08,3.94476e-08,4.18149e-08,4.42991e-08,4.69043e-08,4.96352e-08,5.24961e-08,5.54921e-08,5.86277e-08,6.19081e-08,6.53381e-08,6.89231e-08,7.26681e-08]
  totplnk[51:100,11] = [7.65788e-08,8.06604e-08,8.49187e-08,8.93591e-08,9.39879e-08,9.88106e-08,1.03834e-07,1.09063e-07,1.14504e-07,1.20165e-07,1.26051e-07,1.32169e-07,1.38525e-07,1.45128e-07,1.51982e-07,1.59096e-07,1.66477e-07,1.74132e-07,1.82068e-07,1.90292e-07,1.98813e-07,2.07638e-07,2.16775e-07,2.26231e-07,2.36015e-07,2.46135e-07,2.56599e-07,2.67415e-07,2.78592e-07,2.90137e-07,3.02061e-07,3.14371e-07,3.27077e-07,3.40186e-07,3.53710e-07,3.67655e-07,3.82031e-07,3.96848e-07,4.12116e-07,4.27842e-07,4.44039e-07,4.60713e-07,4.77876e-07,4.95537e-07,5.13706e-07,5.32392e-07,5.51608e-07,5.71360e-07,5.91662e-07,6.12521e-07]
  totplnk[101:150,11] = [6.33950e-07,6.55958e-07,6.78556e-07,7.01753e-07,7.25562e-07,7.49992e-07,7.75055e-07,8.00760e-07,8.27120e-07,8.54145e-07,8.81845e-07,9.10233e-07,9.39318e-07,9.69113e-07,9.99627e-07,1.03087e-06,1.06286e-06,1.09561e-06,1.12912e-06,1.16340e-06,1.19848e-06,1.23435e-06,1.27104e-06,1.30855e-06,1.34690e-06,1.38609e-06,1.42614e-06,1.46706e-06,1.50886e-06,1.55155e-06,1.59515e-06,1.63967e-06,1.68512e-06,1.73150e-06,1.77884e-06,1.82715e-06,1.87643e-06,1.92670e-06,1.97797e-06,2.03026e-06,2.08356e-06,2.13791e-06,2.19330e-06,2.24975e-06,2.30728e-06,2.36589e-06,2.42560e-06,2.48641e-06,2.54835e-06,2.61142e-06]
  totplnk[151:181,11] = [2.67563e-06,2.74100e-06,2.80754e-06,2.87526e-06,2.94417e-06,3.01429e-06,3.08562e-06,3.15819e-06,3.23199e-06,3.30704e-06,3.38336e-06,3.46096e-06,3.53984e-06,3.62002e-06,3.70151e-06,3.78433e-06,3.86848e-06,3.95399e-06,4.04084e-06,4.12907e-06,4.21868e-06,4.30968e-06,4.40209e-06,4.49592e-06,4.59117e-06,4.68786e-06,4.78600e-06,4.88561e-06,4.98669e-06,5.08926e-06,5.19332e-06]
  totplnk[1:50,12] = [2.73921e-10,3.04500e-10,3.38056e-10,3.74835e-10,4.15099e-10,4.59126e-10,5.07214e-10,5.59679e-10,6.16857e-10,6.79103e-10,7.46796e-10,8.20335e-10,9.00144e-10,9.86671e-10,1.08039e-09,1.18180e-09,1.29142e-09,1.40982e-09,1.53757e-09,1.67529e-09,1.82363e-09,1.98327e-09,2.15492e-09,2.33932e-09,2.53726e-09,2.74957e-09,2.97710e-09,3.22075e-09,3.48145e-09,3.76020e-09,4.05801e-09,4.37595e-09,4.71513e-09,5.07672e-09,5.46193e-09,5.87201e-09,6.30827e-09,6.77205e-09,7.26480e-09,7.78794e-09,8.34304e-09,8.93163e-09,9.55537e-09,1.02159e-08,1.09151e-08,1.16547e-08,1.24365e-08,1.32625e-08,1.41348e-08,1.50554e-08]
  totplnk[51:100,12] = [1.60264e-08,1.70500e-08,1.81285e-08,1.92642e-08,2.04596e-08,2.17171e-08,2.30394e-08,2.44289e-08,2.58885e-08,2.74209e-08,2.90290e-08,3.07157e-08,3.24841e-08,3.43371e-08,3.62782e-08,3.83103e-08,4.04371e-08,4.26617e-08,4.49878e-08,4.74190e-08,4.99589e-08,5.26113e-08,5.53801e-08,5.82692e-08,6.12826e-08,6.44245e-08,6.76991e-08,7.11105e-08,7.46634e-08,7.83621e-08,8.22112e-08,8.62154e-08,9.03795e-08,9.47081e-08,9.92066e-08,1.03879e-07,1.08732e-07,1.13770e-07,1.18998e-07,1.24422e-07,1.30048e-07,1.35880e-07,1.41924e-07,1.48187e-07,1.54675e-07,1.61392e-07,1.68346e-07,1.75543e-07,1.82988e-07,1.90688e-07]
  totplnk[101:150,12] = [1.98650e-07,2.06880e-07,2.15385e-07,2.24172e-07,2.33247e-07,2.42617e-07,2.52289e-07,2.62272e-07,2.72571e-07,2.83193e-07,2.94147e-07,3.05440e-07,3.17080e-07,3.29074e-07,3.41430e-07,3.54155e-07,3.67259e-07,3.80747e-07,3.94631e-07,4.08916e-07,4.23611e-07,4.38725e-07,4.54267e-07,4.70245e-07,4.86666e-07,5.03541e-07,5.20879e-07,5.38687e-07,5.56975e-07,5.75751e-07,5.95026e-07,6.14808e-07,6.35107e-07,6.55932e-07,6.77293e-07,6.99197e-07,7.21656e-07,7.44681e-07,7.68278e-07,7.92460e-07,8.17235e-07,8.42614e-07,8.68606e-07,8.95223e-07,9.22473e-07,9.50366e-07,9.78915e-07,1.00813e-06,1.03802e-06,1.06859e-06]
  totplnk[151:181,12] = [1.09986e-06,1.13184e-06,1.16453e-06,1.19796e-06,1.23212e-06,1.26703e-06,1.30270e-06,1.33915e-06,1.37637e-06,1.41440e-06,1.45322e-06,1.49286e-06,1.53333e-06,1.57464e-06,1.61679e-06,1.65981e-06,1.70370e-06,1.74847e-06,1.79414e-06,1.84071e-06,1.88821e-06,1.93663e-06,1.98599e-06,2.03631e-06,2.08759e-06,2.13985e-06,2.19310e-06,2.24734e-06,2.30260e-06,2.35888e-06,2.41619e-06]
  totplnk[1:50,13] = [4.53634e-11,5.11435e-11,5.75754e-11,6.47222e-11,7.26531e-11,8.14420e-11,9.11690e-11,1.01921e-10,1.13790e-10,1.26877e-10,1.41288e-10,1.57140e-10,1.74555e-10,1.93665e-10,2.14613e-10,2.37548e-10,2.62633e-10,2.90039e-10,3.19948e-10,3.52558e-10,3.88073e-10,4.26716e-10,4.68719e-10,5.14331e-10,5.63815e-10,6.17448e-10,6.75526e-10,7.38358e-10,8.06277e-10,8.79625e-10,9.58770e-10,1.04410e-09,1.13602e-09,1.23495e-09,1.34135e-09,1.45568e-09,1.57845e-09,1.71017e-09,1.85139e-09,2.00268e-09,2.16464e-09,2.33789e-09,2.52309e-09,2.72093e-09,2.93212e-09,3.15740e-09,3.39757e-09,3.65341e-09,3.92579e-09,4.21559e-09]
  totplnk[51:100,13] = [4.52372e-09,4.85115e-09,5.19886e-09,5.56788e-09,5.95928e-09,6.37419e-09,6.81375e-09,7.27917e-09,7.77168e-09,8.29256e-09,8.84317e-09,9.42487e-09,1.00391e-08,1.06873e-08,1.13710e-08,1.20919e-08,1.28515e-08,1.36514e-08,1.44935e-08,1.53796e-08,1.63114e-08,1.72909e-08,1.83201e-08,1.94008e-08,2.05354e-08,2.17258e-08,2.29742e-08,2.42830e-08,2.56545e-08,2.70910e-08,2.85950e-08,3.01689e-08,3.18155e-08,3.35373e-08,3.53372e-08,3.72177e-08,3.91818e-08,4.12325e-08,4.33727e-08,4.56056e-08,4.79342e-08,5.03617e-08,5.28915e-08,5.55270e-08,5.82715e-08,6.11286e-08,6.41019e-08,6.71951e-08,7.04119e-08,7.37560e-08]
  totplnk[101:150,13] = [7.72315e-08,8.08424e-08,8.45927e-08,8.84866e-08,9.25281e-08,9.67218e-08,1.01072e-07,1.05583e-07,1.10260e-07,1.15107e-07,1.20128e-07,1.25330e-07,1.30716e-07,1.36291e-07,1.42061e-07,1.48031e-07,1.54206e-07,1.60592e-07,1.67192e-07,1.74015e-07,1.81064e-07,1.88345e-07,1.95865e-07,2.03628e-07,2.11643e-07,2.19912e-07,2.28443e-07,2.37244e-07,2.46318e-07,2.55673e-07,2.65316e-07,2.75252e-07,2.85489e-07,2.96033e-07,3.06891e-07,3.18070e-07,3.29576e-07,3.41417e-07,3.53600e-07,3.66133e-07,3.79021e-07,3.92274e-07,4.05897e-07,4.19899e-07,4.34288e-07,4.49071e-07,4.64255e-07,4.79850e-07,4.95863e-07,5.12300e-07]
  totplnk[151:181,13] = [5.29172e-07,5.46486e-07,5.64250e-07,5.82473e-07,6.01164e-07,6.20329e-07,6.39979e-07,6.60122e-07,6.80767e-07,7.01922e-07,7.23596e-07,7.45800e-07,7.68539e-07,7.91826e-07,8.15669e-07,8.40076e-07,8.65058e-07,8.90623e-07,9.16783e-07,9.43544e-07,9.70917e-07,9.98912e-07,1.02754e-06,1.05681e-06,1.08673e-06,1.11731e-06,1.14856e-06,1.18050e-06,1.21312e-06,1.24645e-06,1.28049e-06]
  totplnk[1:50,14] = [1.40113e-11,1.59358e-11,1.80960e-11,2.05171e-11,2.32266e-11,2.62546e-11,2.96335e-11,3.33990e-11,3.75896e-11,4.22469e-11,4.74164e-11,5.31466e-11,5.94905e-11,6.65054e-11,7.42522e-11,8.27975e-11,9.22122e-11,1.02573e-10,1.13961e-10,1.26466e-10,1.40181e-10,1.55206e-10,1.71651e-10,1.89630e-10,2.09265e-10,2.30689e-10,2.54040e-10,2.79467e-10,3.07128e-10,3.37190e-10,3.69833e-10,4.05243e-10,4.43623e-10,4.85183e-10,5.30149e-10,5.78755e-10,6.31255e-10,6.87910e-10,7.49002e-10,8.14824e-10,8.85687e-10,9.61914e-10,1.04385e-09,1.13186e-09,1.22631e-09,1.32761e-09,1.43617e-09,1.55243e-09,1.67686e-09,1.80992e-09]
  totplnk[51:100,14] = [1.95212e-09,2.10399e-09,2.26607e-09,2.43895e-09,2.62321e-09,2.81949e-09,3.02844e-09,3.25073e-09,3.48707e-09,3.73820e-09,4.00490e-09,4.28794e-09,4.58819e-09,4.90647e-09,5.24371e-09,5.60081e-09,5.97875e-09,6.37854e-09,6.80120e-09,7.24782e-09,7.71950e-09,8.21740e-09,8.74271e-09,9.29666e-09,9.88054e-09,1.04956e-08,1.11434e-08,1.18251e-08,1.25422e-08,1.32964e-08,1.40890e-08,1.49217e-08,1.57961e-08,1.67140e-08,1.76771e-08,1.86870e-08,1.97458e-08,2.08553e-08,2.20175e-08,2.32342e-08,2.45077e-08,2.58401e-08,2.72334e-08,2.86900e-08,3.02122e-08,3.18021e-08,3.34624e-08,3.51954e-08,3.70037e-08,3.88899e-08]
  totplnk[101:150,14] = [4.08568e-08,4.29068e-08,4.50429e-08,4.72678e-08,4.95847e-08,5.19963e-08,5.45058e-08,5.71161e-08,5.98309e-08,6.26529e-08,6.55857e-08,6.86327e-08,7.17971e-08,7.50829e-08,7.84933e-08,8.20323e-08,8.57035e-08,8.95105e-08,9.34579e-08,9.75488e-08,1.01788e-07,1.06179e-07,1.10727e-07,1.15434e-07,1.20307e-07,1.25350e-07,1.30566e-07,1.35961e-07,1.41539e-07,1.47304e-07,1.53263e-07,1.59419e-07,1.65778e-07,1.72345e-07,1.79124e-07,1.86122e-07,1.93343e-07,2.00792e-07,2.08476e-07,2.16400e-07,2.24568e-07,2.32988e-07,2.41666e-07,2.50605e-07,2.59813e-07,2.69297e-07,2.79060e-07,2.89111e-07,2.99455e-07,3.10099e-07]
  totplnk[151:181,14] = [3.21049e-07,3.32311e-07,3.43893e-07,3.55801e-07,3.68041e-07,3.80621e-07,3.93547e-07,4.06826e-07,4.20465e-07,4.34473e-07,4.48856e-07,4.63620e-07,4.78774e-07,4.94325e-07,5.10280e-07,5.26648e-07,5.43436e-07,5.60652e-07,5.78302e-07,5.96397e-07,6.14943e-07,6.33949e-07,6.53421e-07,6.73370e-07,6.93803e-07,7.14731e-07,7.36157e-07,7.58095e-07,7.80549e-07,8.03533e-07,8.27050e-07]
  totplnk[1:50,15] = [3.90483e-12,4.47999e-12,5.13122e-12,5.86739e-12,6.69829e-12,7.63467e-12,8.68833e-12,9.87221e-12,1.12005e-11,1.26885e-11,1.43534e-11,1.62134e-11,1.82888e-11,2.06012e-11,2.31745e-11,2.60343e-11,2.92087e-11,3.27277e-11,3.66242e-11,4.09334e-11,4.56935e-11,5.09455e-11,5.67338e-11,6.31057e-11,7.01127e-11,7.78096e-11,8.62554e-11,9.55130e-11,1.05651e-10,1.16740e-10,1.28858e-10,1.42089e-10,1.56519e-10,1.72243e-10,1.89361e-10,2.07978e-10,2.28209e-10,2.50173e-10,2.73999e-10,2.99820e-10,3.27782e-10,3.58034e-10,3.90739e-10,4.26067e-10,4.64196e-10,5.05317e-10,5.49631e-10,5.97347e-10,6.48689e-10,7.03891e-10]
  totplnk[51:100,15] = [7.63201e-10,8.26876e-10,8.95192e-10,9.68430e-10,1.04690e-09,1.13091e-09,1.22079e-09,1.31689e-09,1.41957e-09,1.52922e-09,1.64623e-09,1.77101e-09,1.90401e-09,2.04567e-09,2.19647e-09,2.35690e-09,2.52749e-09,2.70875e-09,2.90127e-09,3.10560e-09,3.32238e-09,3.55222e-09,3.79578e-09,4.05375e-09,4.32682e-09,4.61574e-09,4.92128e-09,5.24420e-09,5.58536e-09,5.94558e-09,6.32575e-09,6.72678e-09,7.14964e-09,7.59526e-09,8.06470e-09,8.55897e-09,9.07916e-09,9.62638e-09,1.02018e-08,1.08066e-08,1.14420e-08,1.21092e-08,1.28097e-08,1.35446e-08,1.43155e-08,1.51237e-08,1.59708e-08,1.68581e-08,1.77873e-08,1.87599e-08]
  totplnk[101:150,15] = [1.97777e-08,2.08423e-08,2.19555e-08,2.31190e-08,2.43348e-08,2.56045e-08,2.69302e-08,2.83140e-08,2.97578e-08,3.12636e-08,3.28337e-08,3.44702e-08,3.61755e-08,3.79516e-08,3.98012e-08,4.17265e-08,4.37300e-08,4.58143e-08,4.79819e-08,5.02355e-08,5.25777e-08,5.50114e-08,5.75393e-08,6.01644e-08,6.28896e-08,6.57177e-08,6.86521e-08,7.16959e-08,7.48520e-08,7.81239e-08,8.15148e-08,8.50282e-08,8.86675e-08,9.24362e-08,9.63380e-08,1.00376e-07,1.04555e-07,1.08878e-07,1.13349e-07,1.17972e-07,1.22751e-07,1.27690e-07,1.32793e-07,1.38064e-07,1.43508e-07,1.49129e-07,1.54931e-07,1.60920e-07,1.67099e-07,1.73473e-07]
  totplnk[151:181,15] = [1.80046e-07,1.86825e-07,1.93812e-07,2.01014e-07,2.08436e-07,2.16082e-07,2.23957e-07,2.32067e-07,2.40418e-07,2.49013e-07,2.57860e-07,2.66963e-07,2.76328e-07,2.85961e-07,2.95868e-07,3.06053e-07,3.16524e-07,3.27286e-07,3.38345e-07,3.49707e-07,3.61379e-07,3.73367e-07,3.85676e-07,3.98315e-07,4.11287e-07,4.24602e-07,4.38265e-07,4.52283e-07,4.66662e-07,4.81410e-07,4.96535e-07]
  totplnk[1:50,16] = [0.28639e-12,0.33349e-12,0.38764e-12,0.44977e-12,0.52093e-12,0.60231e-12,0.69522e-12,0.80111e-12,0.92163e-12,0.10586e-11,0.12139e-11,0.13899e-11,0.15890e-11,0.18138e-11,0.20674e-11,0.23531e-11,0.26744e-11,0.30352e-11,0.34401e-11,0.38936e-11,0.44011e-11,0.49681e-11,0.56010e-11,0.63065e-11,0.70919e-11,0.79654e-11,0.89357e-11,0.10012e-10,0.11205e-10,0.12526e-10,0.13986e-10,0.15600e-10,0.17380e-10,0.19342e-10,0.21503e-10,0.23881e-10,0.26494e-10,0.29362e-10,0.32509e-10,0.35958e-10,0.39733e-10,0.43863e-10,0.48376e-10,0.53303e-10,0.58679e-10,0.64539e-10,0.70920e-10,0.77864e-10,0.85413e-10,0.93615e-10]
  totplnk[51:100,16] = [0.10252e-09,0.11217e-09,0.12264e-09,0.13397e-09,0.14624e-09,0.15950e-09,0.17383e-09,0.18930e-09,0.20599e-09,0.22399e-09,0.24339e-09,0.26427e-09,0.28674e-09,0.31090e-09,0.33686e-09,0.36474e-09,0.39466e-09,0.42676e-09,0.46115e-09,0.49800e-09,0.53744e-09,0.57964e-09,0.62476e-09,0.67298e-09,0.72448e-09,0.77945e-09,0.83809e-09,0.90062e-09,0.96725e-09,0.10382e-08,0.11138e-08,0.11941e-08,0.12796e-08,0.13704e-08,0.14669e-08,0.15694e-08,0.16781e-08,0.17934e-08,0.19157e-08,0.20453e-08,0.21825e-08,0.23278e-08,0.24815e-08,0.26442e-08,0.28161e-08,0.29978e-08,0.31898e-08,0.33925e-08,0.36064e-08,0.38321e-08]
  totplnk[101:150,16] = [0.40700e-08,0.43209e-08,0.45852e-08,0.48636e-08,0.51567e-08,0.54652e-08,0.57897e-08,0.61310e-08,0.64897e-08,0.68667e-08,0.72626e-08,0.76784e-08,0.81148e-08,0.85727e-08,0.90530e-08,0.95566e-08,0.10084e-07,0.10638e-07,0.11217e-07,0.11824e-07,0.12458e-07,0.13123e-07,0.13818e-07,0.14545e-07,0.15305e-07,0.16099e-07,0.16928e-07,0.17795e-07,0.18699e-07,0.19643e-07,0.20629e-07,0.21656e-07,0.22728e-07,0.23845e-07,0.25010e-07,0.26223e-07,0.27487e-07,0.28804e-07,0.30174e-07,0.31600e-07,0.33084e-07,0.34628e-07,0.36233e-07,0.37902e-07,0.39637e-07,0.41440e-07,0.43313e-07,0.45259e-07,0.47279e-07,0.49376e-07]
  totplnk[151:181,16] = [0.51552e-07,0.53810e-07,0.56153e-07,0.58583e-07,0.61102e-07,0.63713e-07,0.66420e-07,0.69224e-07,0.72129e-07,0.75138e-07,0.78254e-07,0.81479e-07,0.84818e-07,0.88272e-07,0.91846e-07,0.95543e-07,0.99366e-07,0.10332e-06,0.10740e-06,0.11163e-06,0.11599e-06,0.12050e-06,0.12515e-06,0.12996e-06,0.13493e-06,0.14005e-06,0.14534e-06,0.15080e-06,0.15643e-06,0.16224e-06,0.16823e-06]

  chi_mls = zeros(7,59)
  chi_mls[1,:] = [ 1.8760e-02, 1.2223e-02, 5.8909e-03, 2.7675e-03, 1.4065e-03, 7.5970e-04, 3.8876e-04, 1.6542e-04, 3.7190e-05, 7.4765e-06, 4.3082e-06, 3.3319e-06, 3.2039e-06,  3.1619e-06,  3.2524e-06,  3.4226e-06,  3.6288e-06, 3.9148e-06, 4.1488e-06,  4.3081e-06,  4.4420e-06,  4.5778e-06, 4.7087e-06, 4.7943e-06,  4.8697e-06,  4.9260e-06,  4.9669e-06, 4.9963e-06, 5.0527e-06,  5.1266e-06,  5.2503e-06,  5.3571e-06, 5.4509e-06, 5.4830e-06,  5.5000e-06,  5.5000e-06,  5.4536e-06, 5.4047e-06, 5.3558e-06,  5.2533e-06,  5.1436e-06,  5.0340e-06, 4.8766e-06, 4.6979e-06,  4.5191e-06,  4.3360e-06,  4.1442e-06, 3.9523e-06, 3.7605e-06,  3.5722e-06,  3.3855e-06,  3.1988e-06, 3.0121e-06, 2.8262e-06,  2.6407e-06,  2.4552e-06,  2.2696e-06, 4.3360e-06, 4.1442e-06]
  chi_mls[2,:] = [3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,  3.5500e-04,3.5500e-04,  3.5471e-04,  3.5427e-04,  3.5384e-04,  3.5340e-04,3.5500e-04,  3.5500e-04]
  chi_mls[3,:] = [3.0170e-08,  3.4725e-08,  4.2477e-08,  5.2759e-08,  6.6944e-08,8.7130e-08,  1.1391e-07,  1.5677e-07,  2.1788e-07,  3.2443e-07,4.6594e-07,  5.6806e-07,6.9607e-07,  1.1186e-06,  1.7618e-06,  2.3269e-06,  2.9577e-06,3.6593e-06,  4.5950e-06,  5.3189e-06,  5.9618e-06,  6.5113e-06,7.0635e-06,  7.6917e-06,  8.2577e-06,  8.7082e-06,  8.8325e-06,8.7149e-06,  8.0943e-06,  7.3307e-06,  6.3101e-06,  5.3672e-06,4.4829e-06,  3.8391e-06,  3.2827e-06,  2.8235e-06,  2.4906e-06,2.1645e-06,  1.8385e-06,  1.6618e-06,  1.5052e-06,  1.3485e-06,1.1972e-06,  1.0482e-06,  8.9926e-07,  7.6343e-07,  6.5381e-07,5.4419e-07,  4.3456e-07,  3.6421e-07,  3.1194e-07,  2.5967e-07,2.0740e-07,  1.9146e-07,  1.9364e-07,  1.9582e-07,  1.9800e-07,7.6343e-07,  6.5381e-07]
  chi_mls[4,:] = [ 3.2000e-07,  3.2000e-07,  3.2000e-07,  3.2000e-07,  3.2000e-07, 3.1965e-07,  3.1532e-07,  3.0383e-07,  2.9422e-07,  2.8495e-07, 2.7671e-07,  2.6471e-07, 2.4285e-07,  2.0955e-07,  1.7195e-07,  1.3749e-07,  1.1332e-07, 1.0035e-07,  9.1281e-08,  8.5463e-08,  8.0363e-08,  7.3372e-08, 6.5975e-08,  5.6039e-08,  4.7090e-08,  3.9977e-08,  3.2979e-08, 2.6064e-08,  2.1066e-08,  1.6592e-08,  1.3017e-08,  1.0090e-08, 7.6249e-09,  6.1159e-09,  4.6672e-09,  3.2857e-09,  2.8484e-09, 2.4620e-09,  2.0756e-09,  1.8551e-09,  1.6568e-09,  1.4584e-09, 1.3195e-09,  1.2072e-09,  1.0948e-09,  9.9780e-10,  9.3126e-10, 8.6472e-10,  7.9818e-10,  7.5138e-10,  7.1367e-10,  6.7596e-10, 6.3825e-10,  6.0981e-10,  5.8600e-10,  5.6218e-10,  5.3837e-10, 9.9780e-10,  9.3126e-10]
  chi_mls[5,:] = [ 1.5000e-07,  1.4306e-07,  1.3474e-07,  1.3061e-07,  1.2793e-07, 1.2038e-07,  1.0798e-07,  9.4238e-08,  7.9488e-08,  6.1386e-08, 4.5563e-08,  3.3475e-08,  2.5118e-08,  1.8671e-08,  1.4349e-08,  1.2501e-08,  1.2407e-08, 1.3472e-08,  1.4900e-08,  1.6079e-08,  1.7156e-08,  1.8616e-08, 2.0106e-08,  2.1654e-08,  2.3096e-08,  2.4340e-08,  2.5643e-08, 2.6990e-08,  2.8456e-08,  2.9854e-08,  3.0943e-08,  3.2023e-08, 3.3101e-08,  3.4260e-08,  3.5360e-08,  3.6397e-08,  3.7310e-08, 3.8217e-08,  3.9123e-08,  4.1303e-08,  4.3652e-08,  4.6002e-08, 5.0289e-08,  5.5446e-08,  6.0603e-08,  6.8946e-08,  8.3652e-08, 9.8357e-08,  1.1306e-07,  1.4766e-07,  1.9142e-07,  2.3518e-07, 2.7894e-07,  3.5001e-07,  4.3469e-07,  5.1938e-07,  6.0407e-07, 6.8946e-08,  8.3652e-08]
  chi_mls[6,:] = [1.7000e-06,  1.7000e-06,  1.6999e-06,  1.6904e-06,  1.6671e-06,1.6351e-06,  1.6098e-06,  1.5590e-06,  1.5120e-06,  1.4741e-06,1.4385e-06,  1.4002e-06,1.3573e-06,  1.3130e-06,  1.2512e-06,  1.1668e-06,  1.0553e-06,9.3281e-07,  8.1217e-07,  7.5239e-07,  7.0728e-07,  6.6722e-07,6.2733e-07,  5.8604e-07,  5.4769e-07,  5.1480e-07,  4.8206e-07,4.4943e-07,  4.1702e-07,  3.8460e-07,  3.5200e-07,  3.1926e-07,2.8646e-07,  2.5498e-07,  2.2474e-07,  1.9588e-07,  1.8295e-07,1.7089e-07,  1.5882e-07,  1.5536e-07,  1.5304e-07,  1.5072e-07,1.5000e-07,  1.5000e-07,  1.5000e-07,  1.5000e-07,  1.5000e-07,1.5000e-07,  1.5000e-07,  1.5000e-07,  1.5000e-07,  1.5000e-07,1.5000e-07,  1.5000e-07,  1.5000e-07,  1.5000e-07,  1.5000e-07,1.5000e-07,  1.5000e-07]
  chi_mls[7,:] = [0.2090,  0.2090,  0.2090,  0.2090,  0.2090,0.2090,  0.2090,  0.2090,  0.2090,  0.2090,0.2090,  0.2090,0.2090,  0.2090,  0.2090,  0.2090,  0.2090,0.2090,  0.2090,  0.2090,  0.2090,  0.2090,0.2090,  0.2090,  0.2090,  0.2090,  0.2090,0.2090,  0.2090,  0.2090,  0.2090,  0.2090,0.2090,  0.2090,  0.2090,  0.2090,  0.2090,0.2090,  0.2090,  0.2090,  0.2090,  0.2090,0.2090,  0.2090,  0.2090,  0.2090,  0.2090,0.2090,  0.2090,  0.2090,  0.2090,  0.2090,0.2090,  0.2090,  0.2090,  0.2090,  0.2090,0.2090,  0.2090]

  rrtmg_lw_dset = xr.open_dataset("netcdfs/rrtmg_lw.nc",decode_times=false)
  expeps = 1.e-20
  # Spectral band information
  mg = 16
  nb_lw = 16
  ng = [16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16]
  ngc = [10,12,16,14,16,8,12,8,12,6,8,8,4,2,2,2]
  ngm = [1,2,3,3,4,4,5,5,6,6,7,7,8,8,9,10,           # band 1
       1,2,3,4,5,6,7,8,9,9,10,10,11,11,12,12,      # band 2
       1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,     # band 3
       1,2,3,4,5,6,7,8,9,10,11,12,13,14,14,14,     # band 4
       1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,     # band 5
       1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,            # band 6
       1,1,2,2,3,4,5,6,7,8,9,10,11,11,12,12,       # band 7
       1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,            # band 8
       1,2,3,4,5,6,7,8,9,9,10,10,11,11,12,12,      # band 9
       1,1,2,2,3,3,4,4,5,5,5,5,6,6,6,6,            # band 10
       1,2,3,3,4,4,5,5,6,6,7,7,7,8,8,8,            # band 11
       1,2,3,4,5,5,6,6,7,7,7,7,8,8,8,8,            # band 12
       1,1,1,2,2,2,3,3,3,3,4,4,4,4,4,4,            # band 13
       1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,            # band 14
       1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,            # band 15
       1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2]            # band 16
  ngn = [1,1,2,2,2,2,2,2,1,1,                        # band 1
       1,1,1,1,1,1,1,1,2,2,2,2,                    # band 2
       1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,            # band 3
       1,1,1,1,1,1,1,1,1,1,1,1,1,3,                # band 4
       1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,            # band 5
       2,2,2,2,2,2,2,2,                            # band 6
       2,2,1,1,1,1,1,1,1,1,2,2,                    # band 7
       2,2,2,2,2,2,2,2,                            # band 8
       1,1,1,1,1,1,1,1,2,2,2,2,                    # band 9
       2,2,2,2,4,4,                                # band 10
       1,1,2,2,2,2,3,3,                            # band 11
       1,1,1,1,2,2,4,4,                            # band 12
       3,3,4,6,                                    # band 13
       8,8,                                        # band 14
       8,8,                                        # band 15
       4,12]                                       # band 16
  wt = [ 0.1527534276, 0.1491729617, 0.1420961469,
       0.1316886544, 0.1181945205, 0.1019300893,
       0.0832767040, 0.0626720116, 0.0424925000,
       0.0046269894, 0.0038279891, 0.0030260086,
       0.0022199750, 0.0014140010, 0.0005330000,
       0.0000750000]

  AbsorberNames = ["N2","CCL4","CFC11","CFC12","CFC22","H2O","CO2","O3","N2O","CO","CH4","O2"]
  ntbl = 10000
  tau_tbl = zeros(ntbl+1)
  exp_tbl = zeros(ntbl+1)
  tfn_tbl = zeros(ntbl+1)
  tau_tbl[ntbl+1] = 1.e10
  exp_tbl[ntbl+1] = expeps
  tfn_tbl[ntbl+1] = 1.0
  pade   = 0.278
  bpade = 1.0 / pade

  for itr = 1:(ntbl-1)
    tfn = itr / ntbl
    tau_tbl[itr+1] = bpade * tfn / (1. - tfn)
    exp_tbl[itr+1] = exp(-tau_tbl[itr+1])
    if (exp_tbl[itr+1] <= expeps)
      exp_tbl[itr+1] = expeps
    end
    if (tau_tbl[itr+1] < 0.06)
      tfn_tbl[itr+1] = tau_tbl[itr+1]/6.
    else
      tfn_tbl[itr+1] = 1.-2.*((1./tau_tbl[itr+1])-(exp_tbl[itr+1]/(1.-exp_tbl[itr+1])))
    end
  end

  wtsm, rwgt = make_weights(nb_lw,ngc,ngn,ngm,wt)

  refrat_planck_a_dict = Dict(
    3 => chi_mls[1,9]/chi_mls[2,9],
    4 => chi_mls[1,11]/chi_mls[2,11],
    5 => chi_mls[1,5]/chi_mls[2,5],
    7 => chi_mls[1,3]/chi_mls[3,3],
    9 => chi_mls[1,9]/chi_mls[6,9],
    12 => chi_mls[1,10]/chi_mls[2,10],
    13 => chi_mls[1,5]/chi_mls[4,5],
    15 => chi_mls[4,1]/chi_mls[2,1],
    16 => chi_mls[1,6]/chi_mls[6,6]
  )

  refrat_planck_b_dict = Dict(
    3 => chi_mls[1,13]/chi_mls[2,13],
    4 => chi_mls[3,13]/chi_mls[2,13],
    5 => chi_mls[3,43]/chi_mls[2,43]
  )

  refrat_m_a_dict = Dict(
    3 => chi_mls[1,3]/chi_mls[2,3],
    5 => chi_mls[1,7]/chi_mls[2,7],
    7 => chi_mls[1,3]/chi_mls[3,3],
    9 => chi_mls[1,3]/chi_mls[6,3],
    13 => chi_mls[1,1]/chi_mls[4,1],
    15 => chi_mls[4,1]/chi_mls[2,1]
  )

  refrat_m_b_dict = Dict(
    3 => chi_mls[1,13]/chi_mls[2,13]
  )

  refrat_m_a3_dict = Dict(
    13 => chi_mls[1,3]/chi_mls[4,3]
  )

  lw_params = []
  for iband in 1:nb_lw
    lw_dict = Dict{String,Array}()
    if iband in collect(keys(refrat_planck_a_dict))
      lw_dict["fracrefao"] = rrtmg_lw_dset["PlanckFractionLowerAtmos"][:values][1,iband,:,:]
      lw_dict["kao"] = permutedims(rrtmg_lw_dset["KeySpeciesAbsorptionCoefficientsLowerAtmos"][:values][1,iband,:,:,:,:],(4,3,2,1))
    else
      lw_dict["fracrefao"] = rrtmg_lw_dset["PlanckFractionLowerAtmos"][:values][1,iband,1,:]
      lw_dict["kao"] = permutedims(rrtmg_lw_dset["KeySpeciesAbsorptionCoefficientsLowerAtmos"][:values][1,iband,:,:,:,1],(3,2,1))
    end

    if iband in [1,2,7,8,9,10,11,13,14,16]
      lw_dict["fracrefbo"] = rrtmg_lw_dset["PlanckFractionUpperAtmos"][:values][1,iband,1,:]
      if iband != 13
        lw_dict["kbo"] = permutedims(rrtmg_lw_dset["KeySpeciesAbsorptionCoefficientsUpperAtmos"][:values][1,iband,:,:,:,1],(3,2,1))
      end
    elseif iband in collect(keys(refrat_planck_b_dict))
      lw_dict["fracrefbo"] = rrtmg_lw_dset["PlanckFractionUpperAtmos"][:values][1,iband,:,:]
      lw_dict["kbo"] = permutedims(rrtmg_lw_dset["KeySpeciesAbsorptionCoefficientsUpperAtmos"][:values][1,iband,:,:,:,:],(4,3,2,1))
    end

    if iband in [1]
      lw_dict["kao_mn2"] = rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"N2"),:,:,1]'
      lw_dict["kbo_mn2"] = rrtmg_lw_dset["AbsorptionCoefficientsUpperAtmos"][:values][1,iband,findfirst(AbsorberNames,"N2"),:,:,1]'
    elseif iband in [15]
      lw_dict["kao_mn2"] = permutedims(rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"N2"),:,:,:],(3,2,1))
    end

    if iband in [8]
      lw_dict["kao_mn2o"] = rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"N2O"),:,:,1]'
    elseif iband in [3,9]
      lw_dict["kao_mn2o"] = permutedims(rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"N2O"),:,:,:],(3,2,1))
    end

    if iband in [8,9]
      lw_dict["kbo_mn2o"] = rrtmg_lw_dset["AbsorptionCoefficientsUpperAtmos"][:values][1,iband,findfirst(AbsorberNames,"N2O"),:,:,1]'
    elseif iband in [3]
      lw_dict["kbo_mn2o"] = permutedims(rrtmg_lw_dset["AbsorptionCoefficientsUpperAtmos"][:values][1,iband,findfirst(AbsorberNames,"N2O"),:,:,:],(3,2,1))
    end

    if iband in [8]
      lw_dict["cfc22adjo"] = rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"CFC22"),:,1,1]
      lw_dict["kao_mo3"] = rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"O3"),:,:,1]'
    elseif iband in [5]
      lw_dict["kao_mo3"] = permutedims(rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"O3"),:,:,:],(3,2,1))
      lw_dict["ccl4o"] = rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"CCL4"),:,1,1]

    end

    if iband in [13]
      lw_dict["kao_mco"] = permutedims(rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"CO"),:,:,:],(3,2,1))
      lw_dict["kbo_mo3"] = rrtmg_lw_dset["AbsorptionCoefficientsUpperAtmos"][:values][1,iband,findfirst(AbsorberNames,"O3"),:,:,1]'
    end

    if iband in [6,8]
      lw_dict["cfc12o"] = rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"CFC12"),:,1,1]
      lw_dict["kao_mco2"] = rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"CO2"),:,:,1]'
    elseif iband in [7,13]
      lw_dict["kao_mco2"] = permutedims(rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"CO2"),:,:,:],(3,2,1))
    end

    if iband in [7,8]
      lw_dict["kbo_mco2"] = rrtmg_lw_dset["AbsorptionCoefficientsUpperAtmos"][:values][1,iband,findfirst(AbsorberNames,"CO2"),:,:,1]'
    end

    if iband in [6]
      lw_dict["cfc11adjo"] = rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"CFC11"),:,1,1]
    end

    if iband in [11]
      lw_dict["kao_mo2"] = rrtmg_lw_dset["AbsorptionCoefficientsLowerAtmos"][:values][1,iband,findfirst(AbsorberNames,"O2"),:,:,1]'
      lw_dict["kbo_mo2"] = rrtmg_lw_dset["AbsorptionCoefficientsUpperAtmos"][:values][1,iband,findfirst(AbsorberNames,"O2"),:,:,1]'
    end

    lw_dict["selfrefo"] = rrtmg_lw_dset["H20SelfAbsorptionCoefficients"][:values][1,iband,:,:]'
    lw_dict["forrefo"] = rrtmg_lw_dset["H20ForeignAbsorptionCoefficients"][:values][1,iband,:,:]'

    fixed_keys = copy(collect(keys(lw_dict)))
    for key in fixed_keys
      println("$(iband) $(key)")
      value = lw_dict[key]
      new_key = "cfc12o" == key ? "cfc12" : join([replace(fragment,r"([^2c])o$",s"\1") for fragment in split(key,"_")],"_")
      lw_dict[new_key] = fancy_sum(value,iband,ngn,rwgt,!(new_key in ["fracrefa","fracrefb"]))

      if new_key in ["ka","kb"]
        lw_dict[replace(new_key,"k","abs")] = reshape(lw_dict[new_key],(prod(size(lw_dict[new_key])[1:(end-1)]),size(lw_dict[new_key])[end]))
      end

      delete!(lw_dict,key)
    end

    push!(lw_params,lw_dict)
  end

  ntbl = 10000
  tau_tbl = fill(1.e10,ntbl+1)
  exp_tbl = fill(expeps,ntbl+1)
  tfn_tbl = ones(ntbl+1)

  for itr = 1:(ntbl-1)
    tfn = itr / ntbl
    tau_tbl[itr+1] = bpade * tfn / (1. - tfn)
    exp_tbl[itr+1] = exp(-tau_tbl[itr+1])
    if (exp_tbl[itr+1] <= expeps)
      exp_tbl[itr+1] = expeps
    end
    if (tau_tbl[itr+1] < 0.06)
      tfn_tbl[itr+1] = tau_tbl[itr+1]/6.
    else
      tfn_tbl[itr+1] = 1.-2.*((1./tau_tbl[itr+1])-(exp_tbl[itr+1]/(1.-exp_tbl[itr+1])))
    end
  end

  save("jlds/LW_parameters.jld","lw_params",lw_params,"totplnk",totplnk,"chi_mls",chi_mls,"tau_tbl",tau_tbl,"exp_tbl",exp_tbl,"tfn_tbl",tfn_tbl)
  println("LW parameters written to jlds/LW_parameters.jld")
end

function setup_SW_parameters()
  sw_params = []
  nb_sw = 14
  ngc = [6, 12,  8,  8, 10, 10,  2, 10,  8,  6,  6,  8,  6, 12]
  ngn = [
    2, 2, 2, 2, 4, 4,                              # Band 16
    1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2,            # Band 17
    1, 1, 1, 1, 2, 2, 4, 4,                        # Band 18
    1, 1, 1, 1, 2, 2, 4, 4,                        # Band 19
    1, 1, 1, 1, 1, 1, 1, 1, 2, 6,                  # Band 20
    1, 1, 1, 1, 1, 1, 1, 1, 2, 6,                  # Band 21
    8, 8,                                          # Band 22
    2, 2, 1, 1, 1, 1, 1, 1, 2, 4,                  # Band 23
    2, 2, 2, 2, 2, 2, 2, 2,                        # Band 24
    1, 1, 2, 2, 4, 6,                              # Band 25
    1, 1, 2, 2, 4, 6,                              # Band 26
    1, 1, 1, 1, 1, 1, 4, 6,                        # Band 27
    1, 1, 2, 2, 4, 6,                              # Band 28
    1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1]            # Band 29
  ngm = [
    1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, # Band 16
    1, 2, 3, 4, 5, 6, 6, 7, 8, 8, 9,10,10,11,12,12, # Band 17
    1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, # Band 18
    1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, # Band 19
    1, 2, 3, 4, 5, 6, 7, 8, 9, 9,10,10,10,10,10,10, # Band 20
    1, 2, 3, 4, 5, 6, 7, 8, 9, 9,10,10,10,10,10,10, # Band 21
    1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2 ,2, # Band 22
    1, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 9,10,10,10,10, # Band 23
    1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, # Band 24
    1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, # Band 25
    1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, # Band 26
    1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, # Band 27
    1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, # Band 28
    1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9,10,11,12]  # Band 29

  wt =  [ 0.1527534276, 0.1491729617, 0.1420961469, 0.1316886544, 0.1181945205, 0.1019300893, 0.0832767040, 0.0626720116, 0.0424925000, 0.0046269894, 0.0038279891, 0.0030260086, 0.0022199750, 0.0014140010, 0.0005330000, 0.0000750000]
  mg = 16

  wtsm, rwgt = make_weights(nb_sw,ngc,ngn,ngm,wt)
  println(rwgt)

  for iband in 16:29
    println("preparing band $(iband)")
    include("../srtm_kgbs/srtm_kgb$(iband).jl")

    module_symbol = parse("SrtmKgb$(iband)")
    srtm_module = getfield(Main,module_symbol)
    sw_dict = Dict(string(s)=>getfield(srtm_module,s) for s in names(srtm_module, true) if s !== module_symbol && !startswith(string(s), "#") && !isa(getfield(srtm_module, s), Function))

    # Mike Iacono 20050804
    # -- Perform g-point reduction from 16 per band (224 total points) to
    # -- a band dependent number (112 total points) for all absorption
    # -- coefficient input data and Planck fraction input data.
    # -- Compute relative weighting for new g-point combinations.

    fixed_keys = copy(collect(keys(sw_dict)))
    for key in filter(key -> isa(sw_dict[key],Array),fixed_keys)
      println("$(iband) $(key)")
      value = sw_dict[key]
      sw_dict[key*"c"] = fancy_sum(value,iband-15,ngn,rwgt,key!="sfluxref")
      if key in ["ka","kb"]
        # mo_rrsw_kgs.f90 has a different "equivalence" commented out for band 21 than all ther others...

        if iband == 21
          sw_dict[replace(key,"k","abs")] = reshape(sw_dict[key],(prod(size(sw_dict[key])[1:(end-1)]),size(sw_dict[key])[end]))[:,1:ngc[iband-15]]
        else
          sw_dict[replace(key,"k","abs")] = reshape(sw_dict[key*"c"],(prod(size(sw_dict[key*"c"])[1:(end-1)]),size(sw_dict[key*"c"])[end]))
        end
      end

      delete!(sw_dict,key)
    end

    push!(sw_params,sw_dict)
    println("band $(iband) prepared.")
  end

  save("jlds/SW_parameters.jld","sw_params",sw_params)
end


text:
# ------------------------------------------------------------------
# Licensed under the ISC License. See LICENSE in the project root.
# ------------------------------------------------------------------

"""
    SimpleKriging(γ, μ)
    SimpleKriging(X, z, γ, μ)

Simple Kriging with variogram model `γ` and constant mean `μ`.

Optionally, pass the coordinates `X` and values `z`
to the [`fit`](@ref) function.

### Notes

* Simple Kriging requires stationary variograms
"""
struct SimpleKriging{G<:Variogram,V} <: KrigingEstimator
  # input fields
  γ::G
  μ::V

  function SimpleKriging{G,V}(γ, μ) where {G<:Variogram,V}
    @assert isstationary(γ) "Simple Kriging requires stationary variogram"
    new(γ, μ)
  end
end

SimpleKriging(γ, μ) = SimpleKriging{typeof(γ),typeof(μ)}(γ, μ)

SimpleKriging(X, z, γ, μ) = GeoStatsBase.fit(SimpleKriging(γ, μ), X, z)

nconstraints(estimator::SimpleKriging) = 0

set_constraints_lhs!(estimator::SimpleKriging, LHS::AbstractMatrix, X::AbstractMatrix) = nothing

factorize(estimator::SimpleKriging, LHS::AbstractMatrix) = cholesky(LHS, check=false)

set_constraints_rhs!(estimator::FittedKriging{E,S},
                     xₒ::AbstractVector) where {E<:SimpleKriging,S<:KrigingState} = nothing

function combine(estimator::FittedKriging{E,S},
                 weights::KrigingWeights, z::AbstractVector) where {E<:SimpleKriging,S<:KrigingState}
  γ = estimator.estimator.γ
  μ = estimator.estimator.μ
  b = estimator.state.RHS
  λ = weights.λ
  y = z .- μ

  μ + y⋅λ, sill(γ) - b⋅λ
end

ext: jl


text:
using DataFrames

struct K_KeyTable  <: AbstractDataFrame
    a::Array{K_,1}
    function K_KeyTable(x::K_)
        a = asarray(x)
        t = xt(x)
        if(t != XD)
            throw(ArgumentError("type mismatch: t=$t ≠ $XT"))
        end
        t = xt(xx(x))
        if(t != XT)
            throw(ArgumentError("type mismatch: xx.t=$t ≠ $XT"))
        end
        t = xt(xy(x))
        if(t != XT)
            throw(ArgumentError("type mismatch: xy.t=$t ≠ $XT"))
        end
        new(a)
    end
end

function K_KeyTable(nkeys::Integer; kwargs...)
    x = K_Table(;kwargs[1:nkeys]...)
    y = K_Table(;kwargs[nkeys+1:end]...)
    K_KeyTable(xD(r1(kpointer(x)), r1(kpointer(y))))
end

kpointer(x::K_KeyTable) = K_(pointer(x.a)-16)
keyvalptr(x::K_KeyTable, i) = unsafe_load(Ptr{K_}(xy(xk(x.a[1]))+16), i)
valvalptr(x::K_KeyTable, i) = unsafe_load(Ptr{K_}(xy(xk(x.a[2]))+16), i)
nkey(x::K_KeyTable) = Int(xn(xx(xk(x.a[1]))))
nval(x::K_KeyTable) = Int(xn(xx(xk(x.a[2]))))
colnames(x::K_KeyTable) = [K(r1(xx(xk(x.a[1]))));
                           K(r1(xx(xk(x.a[2]))))]

Base.serialize(io::AbstractSerializer, x::K_KeyTable) =
    _serialize(io, x, typeof(x))

DataFrames.ncol(x::K_KeyTable) = nkey(x) + nval(x)
DataFrames.nrow(x::K_KeyTable) = Int(xn(keyvalptr(x, 1)))
DataFrames.index(x::K_KeyTable) = DataFrames.Index(Array(colnames(x)))

function Base.getindex(x::K_KeyTable, i::Integer)
    k = nkey(x)
    p = i <= k ? keyvalptr(x, i) : valvalptr(x, i - k)
    K(r1(p))
end
Base.getindex(x::K_KeyTable, i::Integer, j::Integer) = x[j][i]
Base.getindex(x::K_KeyTable, i::Symbol) = x[DataFrames.index(x)[i]]


text:
module HistokatControllerImageLoader
export getImageObject, getTile
using PyCall

using DeformableRegistration.ImageProcessing: createImage
@pyimport histokat
# if HistokatController does not load:
# cp -r HistokatController /usr/local/anaconda3/lib/python3.6/site-packages/histokat/backend/lib
# cd /usr/local/anaconda3/lib/python3.6/site-packages/histokat/backend/lib
# install_name_tool -add_rpath "@loader_path/HistokatController/lib" libHistokatController.dylib

    tile_size = [1000, 1000]

    function getImageObject(filename::String)
        return histokat.controller[:open_session](filename)[:get_image]()
    end

    function getVoxelSize(image; level = 0)
        x = image[:get_voxel_size](level)[:x]/1000000
        y = image[:get_voxel_size](level)[:y]/1000000
        return (x,y)
    end
    function getExtent(image; level = 0)
        x = image[:get_extent](level)[:x]/1000000
        y = image[:get_extent](level)[:y]/1000000
        return (x,y)
    end

    function getTile(image, level, x, y, z)
        # get correct level and position
        max_level = image[:get_num_levels]() - 1
        level = max_level - level
        x = tile_size[1] * x
        y = tile_size[2] * y
        region = [[x, y, z], [x + tile_size[2] - 1, y + tile_size[2] - 1, z]]
        # load tile as numpy array
        tile = image[:open_region](level, region)
        # normalize and convert to uint8 image
        tile = tile .* (255.0/image[:get_value_range]()[:max])
        #tile = Image.fromarray(tile.astype(np.uint8))
        tile = sum(Array(tile)[1,:,:,:],3)[:,:,1]/3
        vx = getVoxelSize(image,level=level)
        tileIm = createImage(tile, voxelsize = [vx[1],vx[2]], shift = [tile_size[1] * x * vx[1], tile_size[2] * y * vx[2]])
        return tileIm
    end

end


text:
"""
`nothing` as initial default plotter
"""
default_backend=nothing

"""
$(SIGNATURES)

Return default plotter backend
"""
function default_plotter()
    global default_backend
    default_backend
end

"""
````
   plotter!(Plotter)
````

Set plotter module as the default plotter backend.
"""
function default_plotter!(Plotter)
    global default_backend=Plotter
end

"""
$(SIGNATURES)

Heuristically check if Plotter is VTKView
"""
isvtkview(Plotter)= (typeof(Plotter)==Module)&&isdefined(Plotter,:StaticFrame)

"""
$(SIGNATURES)

Heuristically check if Plotter is PyPlot
"""
ispyplot(Plotter)= (typeof(Plotter)==Module)&&isdefined(Plotter,:Gcf)

"""
$(SIGNATURES)

Heuristically check if  Plotter is Plots
"""
isplots(Plotter)= (typeof(Plotter)==Module) && isdefined(Plotter,:gr)

"""
$(SIGNATURES)

Heuristically check if Plotter is Makie/WGLMakie
"""
ismakie(Plotter)= (typeof(Plotter)==Module)&&isdefined(Plotter,:Makie)

"""
$(SIGNATURES)

Heuristically check if Plotter is MeshCat
"""
ismeshcat(Plotter)= (typeof(Plotter)==Module)&&isdefined(Plotter,:Visualizer)

"""
$(SIGNATURES)

Heuristically check if Plotter is MeshCat
"""
isplutovista(Plotter)= (typeof(Plotter)==Module)&&isdefined(Plotter,:PlutoVistaPlot)

"""
$(TYPEDEF)

Abstract type for dispatching on plotter
"""
abstract type PyPlotType  end

"""
$(TYPEDEF)

Abstract type for dispatching on plotter
"""
abstract type MakieType   end

"""
$(TYPEDEF)

Abstract type for dispatching on plotter
"""
abstract type PlotsType   end

"""
$(TYPEDEF)

Abstract type for dispatching on plotter
"""
abstract type VTKViewType end

"""
$(TYPEDEF)

Abstract type for dispatching on plotter
"""
abstract type MeshCatType end

"""
$(TYPEDEF)

Abstract type for dispatching on plotter
"""
abstract type PlutoVistaType end

"""
$(SIGNATURES)

Heuristically detect type of plotter, returns the corresponding abstract type fro plotting.
"""
function plottertype(Plotter::Union{Module,Nothing})
    if ismakie(Plotter)
        return MakieType
    elseif isplots(Plotter)
        return PlotsType
    elseif ispyplot(Plotter)
        return PyPlotType
    elseif isvtkview(Plotter)
        return VTKViewType
    elseif ismeshcat(Plotter)
        return MeshCatType
    elseif isplutovista(Plotter)
        return PlutoVistaType
    end
    Nothing
end

"""
$(TYPEDEF)

A SubVisualizer is just a dictionary which contains plotting information,
including type of the plotter and its position in the plot.
"""
const SubVisualizer=Union{Dict{Symbol,Any},Nothing}

#
# Update subplot context from dict
#
function _update_context!(ctx::SubVisualizer,kwargs)
    for (k,v) in kwargs
        ctx[Symbol(k)]=v
    end
    ctx
end

"""
$(TYPEDEF)

GridVisualizer struct
"""
struct GridVisualizer
    Plotter::Union{Module,Nothing}
    subplots::Array{SubVisualizer,2}
    context::SubVisualizer
    GridVisualizer(Plotter::Union{Module,Nothing}, layout::Tuple, default::SubVisualizer)=new(Plotter,
                                                                                [copy(default) for I in CartesianIndices(layout)],
                                                                                copy(default))
end

"""
````
    GridVisualizer(; Plotter=default_plotter() , kwargs...)
````

Create a  grid visualizer

Plotter: defaults to `default_plotter()` and can be `PyPlot`, `Plots`, `VTKView`, `Makie`.
This pattern to pass the backend as a module to a plot function allows to circumvent
to create heavy default package dependencies.

Depending on the `layout` keyword argument, a 2D grid of subplots is created.
Further `...plot!` commands then plot into one of these subplots:

```julia
vis=GridVisualizer(Plotter=PyPlot, layout=(2,2)
...plot!(vis[1,2], ...)
```

A `...plot`  command just implicitely creates a plot context:

```julia
gridplot(grid, Plotter=PyPlot)
```

is equivalent to

```julia
vis=GridVisualizer(Plotter=PyPlot, layout=(1,1))
gridplot!(vis,grid)
reveal(vis)
```

Please note that the return values of all plot commands are specific to the Plotter.

An interactive mode switch key   for GLMakie (`,`)  and  VTKView (`*`) allows to
toggle between "gallery view" showing all plots at once and "focused view" showing only one plot.

Keyword arguments: see [`available_kwargs`](@ref)

"""
function GridVisualizer(;Plotter::Union{Module,Nothing}=default_plotter(), kwargs...)
    default_ctx=Dict{Symbol,Any}( k => v[1] for (k,v) in default_plot_kwargs())
    _update_context!(default_ctx,kwargs)
    layout=default_ctx[:layout]
    if isnothing(Plotter)
        default_ctx=nothing
    end
    p=GridVisualizer(Plotter,layout,default_ctx)
    if !isnothing(Plotter)
        p.context[:Plotter]=Plotter
        for I in CartesianIndices(layout)
            ctx=p.subplots[I]
            i=Tuple(I)
            ctx[:subplot]=i
            ctx[:iplot]=layout[2]*(i[1]-1)+i[2]
            ctx[:Plotter]=Plotter
            ctx[:GridVisualizer]=p
        end
        initialize!(p,plottertype(Plotter))
    end
    p
end

"""
$(SIGNATURES)

Return the layout of a GridVisualizer
"""
Base.size(p::GridVisualizer)=size(p.subplots)

"""
$(SIGNATURES)

Return a SubVisualizer
"""
Base.getindex(p::GridVisualizer,i,j)=p.subplots[i,j]

"""
$(SIGNATURES)

Return the type of a plotter.
"""
plottertype(p::GridVisualizer)=plottertype(p.Plotter)

#
# Default context information with help info.
#
default_plot_kwargs()=OrderedDict{Symbol,Pair{Any,String}}(
    :show => Pair(false,"Show plot immediately"),
    :reveal => Pair(false,"Show plot immediately (same as :show)"),
    :clear => Pair(true,"Clear plot before new plot."),
    :layout => Pair((1,1),"Layout of plots in window"),
    :resolution => Pair((500,500),"Plot window resolution"),
    :legend => Pair(:none,"Legend (position): one of [:none, :best, :lt, :ct, :rt, :lc, :rc, :lb, :cb, :rb]"),
    :title => Pair("","Plot title"),
    :xlabel => Pair("","x axis label"),
    :ylabel => Pair("","y axis label"),
    :zlabel => Pair("","z axis label"),
    :xlimits => Pair((1,-1),"x limits"),
    :ylimits => Pair((1,-1),"y limits"),
    :zlimits => Pair((1,-1),"z limits"),
    :flimits => Pair((1,-1),"function limits"),
    :aspect => Pair(1.0,"Aspect ratio modification"),
    :fontsize => Pair(20,"Fontsize of titles. All others are relative to it"),
    :linewidth => Pair(2,"1D plot or isoline linewidth"),
    :linestyle => Pair(:solid,"1D Plot linestyle: one of [:solid, :dash, :dot, :dashdot, :dashdotdot]"),
    :markevery => Pair(5,"1D plot marker stride"),
    :markersize => Pair(5,"1D plot marker size"),
    :markershape => Pair(:none,"1D plot marker shape: one of [:none, :circle, :star5, :diamond, :hexagon, :cross, :xcross, :utriangle, :dtriangle, :rtriangle, :ltriangle, :pentagon, :+, :x]"),
    :color => Pair((0.0,0.0,0.0),"1D plot line color"),
    :cellwise => Pair(false,"1D plots cellwise can be slow)"),
    :label => Pair("","1D plot label"),
    :isolines => Pair(11,"2D contour plot: number of isolines"),
    :elevation => Pair(0.0,"2D plot height factor for elevation"),
    :colorlevels => Pair(51,"2D/3D contour plot: number of color levels"),
    :colormap => Pair(:viridis,"2D/3D contour plot color map (any from [ColorSchemes.jl](https://juliagraphics.github.io/ColorSchemes.jl/stable/basics/#Pre-defined-schemes))"),
    :colorbar => Pair(:vertical,"2D/3D plot colorbar. One of [:none, :vertical, :horizontal]"),
    :alpha => Pair(0.1,"3D outline surface alpha value"),
    :interior => Pair(true,"3D plot interior of grid"),
    :outline => Pair(true,"3D plot outline of domain"),
    :xplane => Pair(prevfloat(Inf),"3D x plane position"),
    :yplane => Pair(prevfloat(Inf),"3D y plane position"),
    :zplane => Pair(prevfloat(Inf),"3D z plane position"),
    :flevel => Pair(prevfloat(Inf),"3D isosurface level"),
    :azim => Pair(-60,"3D azimuth angle  (in degrees)"),
    :elev => Pair(30,"3D elevation angle  (in degrees)"),
    :perspectiveness => Pair(0.25,"3D perspective A number between 0 and 1, where 0 is orthographic, and 1 full perspective"),
    :scene3d  => Pair("Axis3","3D plot type of Makie scene. Alternaitve to `Axis3` is `LScene`"),
    :fignumber => Pair(1,"Figure number (PyPlot)"),
    :framepos => Pair(1,"Subplot position in frame (VTKView)"),
    :subplot => Pair((1,1),"Private: Actual subplot"),
    :backend => Pair(:default,"Backend for PlutoVista plot"),
    :datadim => Pair(1,"Data dimension for PlutoVista plot"),
    :regions => Pair(:all,"List of regions to plot"),
    :species => Pair(1,"Number of species to plot or number of species in regions")
)

#
# Print default dict for interpolation into docstrings
#
function _myprint(dict)
    lines_out=IOBuffer()
    for (k,v) in dict
        println(lines_out,"  - `$(k)`: $(v[2]). Default: `$(v[1])`\n")
    end
    String(take!(lines_out))
end

"""
$(SIGNATURES)

Available kwargs for all methods of this package.

$(_myprint(default_plot_kwargs()))
"""
available_kwargs()=println(_myprint(default_plot_kwargs()))

"""
````
gridplot!(visualizer[i,j], grid, kwargs...)
gridplot!(visualizer, grid, kwargs...)
````

Plot grid into subplot in the visualizer. If `[i,j]` is omitted, `[1,1]` is assumed.

Keyword arguments: see [`available_kwargs`](@ref)
"""
function gridplot!(ctx::SubVisualizer,grid::ExtendableGrid; kwargs...)
    _update_context!(ctx,kwargs)
    gridplot!(ctx,plottertype(ctx[:Plotter]),Val{dim_space(grid)},grid)
end

gridplot!(p::GridVisualizer,grid::ExtendableGrid, kwargs...)= gridplot!(p[1,1],grid; kwargs...)

"""
````
gridplot(grid; Plotter=default_plotter(); kwargs...)
````

Create grid visualizer and plot grid

Keyword arguments: see [`available_kwargs`](@ref)
"""
gridplot(grid::ExtendableGrid; Plotter=default_plotter(), kwargs...)=gridplot!(GridVisualizer(Plotter=Plotter; show=true, kwargs...),grid)

"""
````
scalarplot!(visualizer[i,j], grid, vector; kwargs...)
scalarplot!(visualizer, grid, vector; kwargs...)
scalarplot!(visualizer[i,j], grid, function; kwargs...)
scalarplot!(visualizer[i,j], X, vector; kwargs...)
scalarplot!(visualizer[i,j], X, function; kwargs...)
scalarplot!(visualizer[i,j], X, Y, function; kwargs...)
scalarplot!(visualizer[i,j], X, Y, Z, function; kwargs...)
````

Plot node vector on grid as P1 FEM function on the triangulation into subplot in the visualizer. If `[i,j]` is omitted, `[1,1]` is assumed.

If instead of the node vector,  a function is given, it will be evaluated on the grid.

If instead of the grid, coordinate vectors are given, a temporary grid is created.

Keyword arguments: see [`available_kwargs`](@ref)
"""
function scalarplot!(ctx::SubVisualizer,grid::ExtendableGrid,func; kwargs...)
    _update_context!(ctx,Dict(:clear=>true,:show=>false,:reveal=>false))
    _update_context!(ctx,kwargs)
    scalarplot!(ctx,plottertype(ctx[:Plotter]),Val{dim_space(grid)},grid,func)
end

scalarplot!(p::GridVisualizer,grid::ExtendableGrid, func; kwargs...) = scalarplot!(p[1,1],grid,func; kwargs...)
scalarplot!(ctx::SubVisualizer,grid::ExtendableGrid,func::Function; kwargs...)=scalarplot!(ctx,grid,map(func,grid);kwargs...)
scalarplot!(ctx::SubVisualizer,X::AbstractVector,func; kwargs...)=scalarplot!(ctx,simplexgrid(X),func;kwargs...)
scalarplot!(ctx::GridVisualizer,X::AbstractVector,func; kwargs...)=scalarplot!(ctx,simplexgrid(X),func;kwargs...)
scalarplot!(ctx::GridVisualizer,X::AbstractVector,Y::AbstractVector,func; kwargs...)=scalarplot!(ctx,simplexgrid(X,Y),func;kwargs...)
scalarplot!(ctx::GridVisualizer,X::AbstractVector,Y::AbstractVector,Z::AbstractVector, func; kwargs...)=scalarplot!(ctx,simplexgrid(X,Y,Z),func;kwargs...)

"""
````
scalarplot(grid,vector; Plotter=default_plotter())
scalarplot(grid,function; Plotter=default_plotter())
scalarplot(X,vector; Plotter=default_plotter())
scalarplot(X,function; Plotter=default_plotter())
scalarplot(X,Y,function; Plotter=default_plotter())
scalarplot(X,Y,Z,function; Plotter=default_plotter())

````

Plot node vector on grid as P1 FEM function on the triangulation.

If instead of the node vector,  a function is given, it will be evaluated on the grid.

If instead of the grid,  vectors for coordinates are given, a grid is created automatically.

Keyword arguments: see [`available_kwargs`](@ref)
"""
scalarplot(grid::ExtendableGrid,func ;Plotter=default_plotter(),kwargs...) = scalarplot!(GridVisualizer(Plotter=Plotter; datadim=dim_space(grid),kwargs...),grid,func,show=true)
scalarplot(X::AbstractVector,func ;kwargs...)=scalarplot(simplexgrid(X),func;kwargs...)
scalarplot(X::AbstractVector,Y::AbstractVector,func ;kwargs...)=scalarplot(simplexgrid(X,Y),func;kwargs...)
scalarplot(X::AbstractVector,Y::AbstractVector,Z::AbstractVector, func ;kwargs...)=scalarplot(simplexgrid(X,Y,Z),func;kwargs...)

"""
$(SIGNATURES)

Finish and show plot. Same as setting `:reveal=true` or `:show=true` in last plot statment
for a context.
"""
reveal(visualizer::GridVisualizer)=reveal(visualizer, plottertype(visualizer.Plotter))

"""
$(SIGNATURES)

Save last plotted figure from visualizer to disk.
"""
save(fname::String,visualizer::GridVisualizer)=save(fname,p, plottertype(p.Plotter))

"""
$(SIGNATURES)

Save scene returned from [`reveal`](@ref), [`scalarplot`](@ref) or [`gridplot`](@ref)  to disk.
"""
save(fname::String,scene;Plotter::Union{Module,Nothing}=default_plotter())=save(fname,scene, Plotter, plottertype(Plotter))

#
# Dummy methods to allow Plotter=nothing
#
_update_context!(::Nothing,kwargs)=nothing
Base.copy(::Nothing)=nothing

gridplot!(ctx::Nothing,grid::ExtendableGrid;kwargs...)=nothing
gridplot!(ctx, ::Type{Nothing}, ::Type{Val{1}}, grid)=nothing
gridplot!(ctx, ::Type{Nothing}, ::Type{Val{2}}, grid)=nothing
gridplot!(ctx, ::Type{Nothing}, ::Type{Val{3}}, grid)=nothing

scalarplot!(ctx::Nothing,grid::ExtendableGrid,func;kwargs...)=nothing
scalarplot!(ctx::Nothing,grid::ExtendableGrid,func::Function;kwargs...)=nothing
scalarplot!(ctx, ::Type{Nothing}, ::Type{Val{1}},grid,func)=nothing
scalarplot!(ctx, ::Type{Nothing}, ::Type{Val{2}},grid,func)=nothing
scalarplot!(ctx, ::Type{Nothing}, ::Type{Val{3}},grid,func)=nothing

save(fname,scene,Plotter,::Type{Nothing})=nothing
displayable(ctx,Any)=nothing
reveal(p,::Type{Nothing})=nothing