Interp.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #include "common.h"
  2. #include "Interp.h"
  3. void interp (const int iaer, const int idatmp,
  4. const float wl, const float taer55,
  5. const float taer55p, const float xmud,
  6. InterpStruct& is)
  7. {
  8. /* that for the atmosphere :
  9. the reflectances
  10. rayleigh = rorayl
  11. aerosols = roaero
  12. mixing = romix
  13. the downward transmittances
  14. rayleigh = dtotr
  15. aerosols = dtota
  16. total = dtott
  17. the upward transmittances
  18. rayleigh = utotr
  19. aerosols = utota
  20. total = utott
  21. the spherical albedos
  22. rayleigh = asray
  23. aerosols = asaer
  24. total = astot
  25. the optical thickness of total atmosphere
  26. rayleigh = tray
  27. aerosols = taer
  28. the optical thickness of the atmosphere above the plane
  29. rayleigh = is.trayp
  30. aerosols = taerp
  31. the tsca of the aerosols (god dammed it)
  32. total atmosphere = tsca */
  33. int linf = 0;
  34. for(int i = 0; i < 9; i++) if(wl > sixs_disc.wldis[i] && wl <= sixs_disc.wldis[i+1]) linf = i;
  35. if(wl > sixs_disc.wldis[9]) linf = 8;
  36. int lsup = linf + 1;
  37. /* interpolation in function of wavelength for scattering
  38. atmospheric functions from discrete values at sixs_disc.wldis */
  39. float alphaa = 0;
  40. float betaa = 0;
  41. float alphar = 0;
  42. float betar = 0;
  43. float alphac = 0;
  44. float betac = 0;
  45. is.phaa = 0;
  46. is.roaero = 0;
  47. is.dtota = 1;
  48. is.utota = 1;
  49. is.asaer = 0;
  50. is.taer = 0;
  51. is.taerp = 0;
  52. float coef = (float)log(sixs_disc.wldis[lsup] / sixs_disc.wldis[linf]);
  53. float wlinf = sixs_disc.wldis[linf];
  54. if(iaer != 0)
  55. {
  56. alphaa = (float)(log(sixs_aer.phase[lsup] / sixs_aer.phase[linf]) / coef);
  57. betaa = (float)(sixs_aer.phase[linf] / pow(wlinf,alphaa));
  58. is.phaa = (float)(betaa * pow(wl,alphaa));
  59. }
  60. float d2 = 2 + delta;
  61. is.phar = (2 * (1 - delta) / d2) * .75f * (1 + xmud * xmud) + 3 * delta / d2;
  62. if(idatmp == 0)
  63. {
  64. betar = 0;
  65. betaa = 0;
  66. betac = 0;
  67. }
  68. else
  69. {
  70. if(sixs_disc.roatm[0][linf] < 0.001)
  71. {
  72. is.rorayl = sixs_disc.roatm[0][linf] + (sixs_disc.roatm[0][lsup] - sixs_disc.roatm[0][linf])
  73. * (wl - sixs_disc.wldis[linf]) / (sixs_disc.wldis[lsup] - sixs_disc.wldis[linf]);
  74. }
  75. else
  76. {
  77. alphar = (float)(log(sixs_disc.roatm[0][lsup] / sixs_disc.roatm[0][linf]) / coef);
  78. betar = (float)(sixs_disc.roatm[0][linf] / pow(wlinf,alphar));
  79. is.rorayl = (float)(betar * pow(wl,alphar));
  80. }
  81. if(sixs_disc.roatm[1][linf] < 0.001)
  82. {
  83. is.romix = sixs_disc.roatm[1][linf] + (sixs_disc.roatm[1][lsup] - sixs_disc.roatm[1][linf])
  84. * (wl - sixs_disc.wldis[linf]) / (sixs_disc.wldis[lsup] - sixs_disc.wldis[linf]);
  85. }
  86. else
  87. {
  88. alphac = (float)(log(sixs_disc.roatm[1][lsup] / sixs_disc.roatm[1][linf]) / coef);
  89. betac = (float)(sixs_disc.roatm[1][linf] / pow(wlinf,alphac));
  90. is.romix = (float)(betac * pow(wl,alphac));
  91. }
  92. if(iaer != 0)
  93. {
  94. if(sixs_disc.roatm[2][linf] < 0.001)
  95. {
  96. is.roaero = sixs_disc.roatm[2][linf]+(sixs_disc.roatm[2][lsup] - sixs_disc.roatm[2][linf])
  97. * (wl - sixs_disc.wldis[linf]) / (sixs_disc.wldis[lsup] - sixs_disc.wldis[linf]);
  98. }
  99. else
  100. {
  101. alphaa = (float)(log(sixs_disc.roatm[2][lsup] / sixs_disc.roatm[2][linf]) / coef);
  102. betaa = (float)(sixs_disc.roatm[2][linf] / pow(wlinf,alphaa));
  103. is.roaero = (float)(betaa * pow(wl,alphaa));
  104. }
  105. }
  106. }
  107. alphar = (float)(log(sixs_disc.trayl[lsup] / sixs_disc.trayl[linf]) / coef);
  108. betar = (float)(sixs_disc.trayl[linf] / pow(wlinf,alphar));
  109. is.tray = (float)(betar * pow(wl,alphar));
  110. if (idatmp != 0)
  111. {
  112. alphar = (float)(log(sixs_disc.traypl[lsup] / sixs_disc.traypl[linf]) / coef);
  113. betar = (float)(sixs_disc.traypl[linf] / pow(wlinf,alphar));
  114. is.trayp = (float)(betar * pow(wl,alphar));
  115. }
  116. else is.trayp = 0;
  117. if(iaer != 0)
  118. {
  119. alphaa = (float)(log(sixs_aer.ext[lsup] * sixs_aer.ome[lsup] / (sixs_aer.ext[linf] * sixs_aer.ome[linf])) / coef);
  120. betaa = (float)(sixs_aer.ext[linf] * sixs_aer.ome[linf] / pow(wlinf,alphaa));
  121. is.tsca = (float)(taer55 * betaa * pow(wl,alphaa) / sixs_aer.ext[3]);
  122. alphaa = (float)(log(sixs_aer.ext[lsup] / sixs_aer.ext[linf]) / coef);
  123. betaa = (float)(sixs_aer.ext[linf] / pow(wlinf,alphaa));
  124. is.taerp = (float)(taer55p * betaa * pow(wl,alphaa) / sixs_aer.ext[3]);
  125. is.taer = (float)(taer55 * betaa * pow(wl,alphaa) / sixs_aer.ext[3]);
  126. }
  127. float drinf = sixs_disc.dtdif[0][linf] + sixs_disc.dtdir[0][linf];
  128. float drsup = sixs_disc.dtdif[0][lsup] + sixs_disc.dtdir[0][lsup];
  129. alphar = (float)(log(drsup / drinf) / coef);
  130. betar = (float)(drinf / pow(wlinf,alphar));
  131. is.dtotr = (float)(betar * pow(wl,alphar));
  132. float dtinf = sixs_disc.dtdif[1][linf] + sixs_disc.dtdir[1][linf];
  133. float dtsup = sixs_disc.dtdif[1][lsup] + sixs_disc.dtdir[1][lsup];
  134. alphac = (float)(log((dtsup * drinf) / (dtinf * drsup)) / coef);
  135. betac = (float)((dtinf / drinf) / pow(wlinf,alphac));
  136. float dtotc = (float)(betac * pow(wl,alphac));
  137. float dainf = sixs_disc.dtdif[2][linf] + sixs_disc.dtdir[2][linf];
  138. float dasup = sixs_disc.dtdif[2][lsup] + sixs_disc.dtdir[2][lsup];
  139. if(iaer != 0)
  140. {
  141. alphaa = (float)(log(dasup / dainf) / coef);
  142. betaa = (float)(dainf / pow(wlinf,alphaa));
  143. is.dtota = (float)(betaa * pow(wl,alphaa));
  144. }
  145. is.dtott = dtotc * is.dtotr;
  146. float urinf = sixs_disc.utdif[0][linf] + sixs_disc.utdir[0][linf];
  147. float ursup = sixs_disc.utdif[0][lsup] + sixs_disc.utdir[0][lsup];
  148. alphar = (float)(log(ursup / urinf) / coef);
  149. betar = (float)(urinf / pow(wlinf,alphar));
  150. is.utotr = (float)(betar * pow(wl,alphar));
  151. float utinf = sixs_disc.utdif[1][linf] + sixs_disc.utdir[1][linf];
  152. float utsup = sixs_disc.utdif[1][lsup] + sixs_disc.utdir[1][lsup];
  153. alphac = (float)(log((utsup * urinf) / (utinf * ursup)) / coef);
  154. betac = (float)((utinf / urinf) / pow(wlinf,alphac));
  155. float utotc = (float)(betac * pow(wl,alphac));
  156. float uainf = sixs_disc.utdif[2][linf] + sixs_disc.utdir[2][linf];
  157. float uasup = sixs_disc.utdif[2][lsup] + sixs_disc.utdir[2][lsup];
  158. is.utott = utotc * is.utotr;
  159. if(iaer != 0)
  160. {
  161. alphaa = (float)(log(uasup / uainf) / coef);
  162. betaa = (float)(uainf / pow(wlinf,alphaa));
  163. is.utota = (float)(betaa * pow(wl,alphaa));
  164. }
  165. float arinf = sixs_disc.sphal[0][linf];
  166. float arsup = sixs_disc.sphal[0][lsup];
  167. alphar = (float)(log(arsup / arinf) / coef);
  168. betar = (float)(arinf / pow(wlinf,alphar));
  169. is.asray = (float)(betar * pow(wl,alphar));
  170. float atinf = sixs_disc.sphal[1][linf];
  171. float atsup = sixs_disc.sphal[1][lsup];
  172. alphac = (float)(log(atsup / atinf) / coef);
  173. betac = (float)(atinf / pow(wlinf,alphac));
  174. is.astot = (float)(betac * pow(wl,alphac));
  175. float aainf = sixs_disc.sphal[2][linf];
  176. float aasup = sixs_disc.sphal[2][lsup];
  177. if(iaer != 0)
  178. {
  179. alphaa = (float)(log(aasup / aainf) / coef);
  180. betaa = (float)(aainf / pow(wlinf,alphaa));
  181. is.asaer = (float)(betaa * pow(wl,alphaa));
  182. }
  183. }