DataAltiExtrapolation_Valery.R 24.9 KB
Newer Older
Delaigue Olivier's avatar
Delaigue Olivier committed
#*****************************************************************************************************************
#' Function which extrapolates the precipitation and air temperature series for different elevation layers (method from Valery, 2010).
#'
#' Elevation layers of equal surface are created the 101 elevation quantiles (\emph{HypsoData}) 
#' and the number requested elevation layers (\emph{NLayers}). \cr
#' Forcing data (precipitation and air temperature) are extrapolated using gradients from Valery (2010).
#' (e.g. gradP=0.0004 [m-1] for France and gradT=0.434 [degreC/100m] for January, 1st). \cr
#' This function is used by the \emph{CreateInputsModel} function. \cr
#*****************************************************************************************************************
#' @title   Altitudinal extrapolation of precipitation and temperature series
#' @author  Laurent Coron, Pierre Brigode (June 2014)
#' @references
#'   Turcotte, R., L.-G. Fortin, V. Fortin, J.-P. Fortin and J.-P. Villeneuve (2007), 
#'       Operational analysis of the spatial distribution and the temporal evolution of the snowpack water equivalent 
#'       in southern Quebec, Canada, Nordic Hydrology, 38(3), 211, doi:10.2166/nh.2007.009. \cr
#'   Valéry, A. (2010), Modélisation précipitations-débit sous influence nivale ? : Elaboration d'un module neige 
#'       et évaluation sur 380 bassins versants, PhD thesis (in french), AgroParisTech, Paris, France. \cr
#'   USACE (1956), Snow Hydrology, pp. 437, U.S. Army Coprs of Engineers (USACE) North Pacific Division, Portland, Oregon, USA.
#' @seealso \code{\link{CreateInputsModel}}, \code{\link{RunModel_CemaNeigeGR4J}}
#' @encoding UTF-8
#' @export
#_FunctionInputs__________________________________________________________________________________________________
#' @param  DatesR      [POSIXlt] vector of dates
#' @param  Precip      [numeric] time series of daily total precipitation (catchment average) [mm]
#' @param  TempMean    [numeric] time series of daily mean air temperature [degC]
#' @param  TempMin     (optional) [numeric] time series of daily min air temperature [degC]
#' @param  TempMax     (optional) [numeric] time series of daily max air temperature [degC]
#' @param  ZInputs     [numeric] real giving the mean elevation of the Precip and Temp series (before extrapolation) [m]
#' @param  HypsoData   [numeric] vector of 101 reals: min, q01 to q99 and max of catchment elevation distribution [m]
#' @param  NLayers     [numeric] integer giving the number of elevation layers requested [-]
#' @param  quiet       (optional) [boolean] boolean indicating if the function is run in quiet mode or not, default=FALSE
#_FunctionOutputs_________________________________________________________________________________________________
#' @return  list containing the extrapolated series of precip. and air temp. on each elevation layer
#'          \tabular{ll}{                                                                                                      
#'            \emph{$LayerPrecip         }  \tab  [list] list of time series of daily precipitation (layer average) [mm]           \cr
#'            \emph{$LayerTempMean       }  \tab  [list] list of time series of daily mean air temperature (layer average) [degC]  \cr
#'            \emph{$LayerTempMin        }  \tab  [list] list of time series of daily min air temperature (layer average) [degC]   \cr
#'            \emph{$LayerTempMax        }  \tab  [list] list of time series of daily max air temperature (layer average) [degC]   \cr
#'            \emph{$LayerFracSolidPrecip}  \tab  [list] list of time series of daily solid precip. fract. (layer average) [-]     \cr
#'            \emph{$ZLayers             }  \tab  [numeric] vector of median elevation for each layer                              \cr
#'          }                                                                                                                  
#*****************************************************************************************************************
DataAltiExtrapolation_Valery <- function(DatesR,Precip,TempMean,TempMin=NULL,TempMax=NULL,ZInputs,HypsoData,NLayers,quiet=FALSE){
Delaigue Olivier's avatar
Delaigue Olivier committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540


    ##Altitudinal_gradient_functions_______________________________________________________________
      ##unique_gradient_for_precipitation
      GradP_Valery2010 <- function(){ 
        return(0.00041); ### value from Val? PhD thesis page 126
      }
      ##daily_gradients_for_mean_min_and_max_air_temperature
      GradT_Valery2010 <- function(){ 
        RESULT <- matrix(c(
               1,  1, 0.434, 0.366, 0.498,
               2,  1, 0.434, 0.366, 0.500,
               3,  1, 0.435, 0.367, 0.501,
               4,  1, 0.436, 0.367, 0.503,
               5,  1, 0.437, 0.367, 0.504,
               6,  1, 0.439, 0.367, 0.506,
               7,  1, 0.440, 0.367, 0.508,
               8,  1, 0.441, 0.368, 0.510,
               9,  1, 0.442, 0.368, 0.512,
              10,  1, 0.444, 0.368, 0.514,
              11,  1, 0.445, 0.368, 0.517,
              12,  1, 0.446, 0.368, 0.519,
              13,  1, 0.448, 0.369, 0.522,
              14,  1, 0.450, 0.369, 0.525,
              15,  1, 0.451, 0.369, 0.527,
              16,  1, 0.453, 0.370, 0.530,
              17,  1, 0.455, 0.370, 0.533,
              18,  1, 0.456, 0.370, 0.537,
              19,  1, 0.458, 0.371, 0.540,
              20,  1, 0.460, 0.371, 0.543,
              21,  1, 0.462, 0.371, 0.547,
              22,  1, 0.464, 0.372, 0.550,
              23,  1, 0.466, 0.372, 0.554,
              24,  1, 0.468, 0.373, 0.558,
              25,  1, 0.470, 0.373, 0.561,
              26,  1, 0.472, 0.374, 0.565,
              27,  1, 0.474, 0.374, 0.569,
              28,  1, 0.476, 0.375, 0.573,
              29,  1, 0.478, 0.375, 0.577,
              30,  1, 0.480, 0.376, 0.582,
              31,  1, 0.483, 0.376, 0.586,
               1,  2, 0.485, 0.377, 0.590,
               2,  2, 0.487, 0.377, 0.594,
               3,  2, 0.489, 0.378, 0.599,
               4,  2, 0.492, 0.379, 0.603,
               5,  2, 0.494, 0.379, 0.607,
               6,  2, 0.496, 0.380, 0.612,
               7,  2, 0.498, 0.381, 0.616,
               8,  2, 0.501, 0.381, 0.621,
               9,  2, 0.503, 0.382, 0.625,
              10,  2, 0.505, 0.383, 0.630,
              11,  2, 0.508, 0.384, 0.634,
              12,  2, 0.510, 0.384, 0.639,
              13,  2, 0.512, 0.385, 0.643,
              14,  2, 0.515, 0.386, 0.648,
              15,  2, 0.517, 0.387, 0.652,
              16,  2, 0.519, 0.387, 0.657,
              17,  2, 0.522, 0.388, 0.661,
              18,  2, 0.524, 0.389, 0.666,
              19,  2, 0.526, 0.390, 0.670,
              20,  2, 0.528, 0.391, 0.674,
              21,  2, 0.530, 0.392, 0.679,
              22,  2, 0.533, 0.393, 0.683,
              23,  2, 0.535, 0.393, 0.687,
              24,  2, 0.537, 0.394, 0.691,
              25,  2, 0.539, 0.395, 0.695,
              26,  2, 0.541, 0.396, 0.699,
              27,  2, 0.543, 0.397, 0.703,
              28,  2, 0.545, 0.398, 0.707,
              29,  2, 0.546, 0.399, 0.709,
               1,  3, 0.547, 0.399, 0.711,
               2,  3, 0.549, 0.400, 0.715,
               3,  3, 0.551, 0.401, 0.718,
               4,  3, 0.553, 0.402, 0.722,
               5,  3, 0.555, 0.403, 0.726,
               6,  3, 0.557, 0.404, 0.729,
               7,  3, 0.559, 0.405, 0.732,
               8,  3, 0.560, 0.406, 0.736,
               9,  3, 0.562, 0.406, 0.739,
              10,  3, 0.564, 0.407, 0.742,
              11,  3, 0.566, 0.408, 0.745,
              12,  3, 0.567, 0.409, 0.748,
              13,  3, 0.569, 0.410, 0.750,
              14,  3, 0.570, 0.411, 0.753,
              15,  3, 0.572, 0.412, 0.756,
              16,  3, 0.573, 0.413, 0.758,
              17,  3, 0.575, 0.414, 0.761,
              18,  3, 0.576, 0.415, 0.763,
              19,  3, 0.577, 0.416, 0.765,
              20,  3, 0.579, 0.417, 0.767,
              21,  3, 0.580, 0.417, 0.769,
              22,  3, 0.581, 0.418, 0.771,
              23,  3, 0.582, 0.419, 0.773,
              24,  3, 0.583, 0.420, 0.774,
              25,  3, 0.584, 0.421, 0.776,
              26,  3, 0.585, 0.422, 0.777,
              27,  3, 0.586, 0.422, 0.779,
              28,  3, 0.587, 0.423, 0.780,
              29,  3, 0.588, 0.424, 0.781,
              30,  3, 0.589, 0.425, 0.782,
              31,  3, 0.590, 0.425, 0.783,
               1,  4, 0.591, 0.426, 0.784,
               2,  4, 0.591, 0.427, 0.785,
               3,  4, 0.592, 0.427, 0.785,
               4,  4, 0.593, 0.428, 0.786,
               5,  4, 0.593, 0.429, 0.787,
               6,  4, 0.594, 0.429, 0.787,
               7,  4, 0.595, 0.430, 0.787,
               8,  4, 0.595, 0.431, 0.788,
               9,  4, 0.596, 0.431, 0.788,
              10,  4, 0.596, 0.432, 0.788,
              11,  4, 0.597, 0.432, 0.788,
              12,  4, 0.597, 0.433, 0.788,
              13,  4, 0.597, 0.433, 0.788,
              14,  4, 0.598, 0.434, 0.788,
              15,  4, 0.598, 0.434, 0.788,
              16,  4, 0.598, 0.435, 0.787,
              17,  4, 0.599, 0.435, 0.787,
              18,  4, 0.599, 0.436, 0.787,
              19,  4, 0.599, 0.436, 0.786,
              20,  4, 0.599, 0.436, 0.786,
              21,  4, 0.600, 0.437, 0.785,
              22,  4, 0.600, 0.437, 0.785,
              23,  4, 0.600, 0.437, 0.784,
              24,  4, 0.600, 0.438, 0.784,
              25,  4, 0.600, 0.438, 0.783,
              26,  4, 0.601, 0.438, 0.783,
              27,  4, 0.601, 0.438, 0.782,
              28,  4, 0.601, 0.439, 0.781,
              29,  4, 0.601, 0.439, 0.781,
              30,  4, 0.601, 0.439, 0.780,
               1,  5, 0.601, 0.439, 0.779,
               2,  5, 0.601, 0.439, 0.778,
               3,  5, 0.601, 0.439, 0.778,
               4,  5, 0.601, 0.440, 0.777,
               5,  5, 0.601, 0.440, 0.776,
               6,  5, 0.601, 0.440, 0.775,
               7,  5, 0.601, 0.440, 0.775,
               8,  5, 0.601, 0.440, 0.774,
               9,  5, 0.601, 0.440, 0.773,
              10,  5, 0.602, 0.440, 0.772,
              11,  5, 0.602, 0.440, 0.772,
              12,  5, 0.602, 0.440, 0.771,
              13,  5, 0.602, 0.440, 0.770,
              14,  5, 0.602, 0.440, 0.770,
              15,  5, 0.602, 0.440, 0.769,
              16,  5, 0.602, 0.440, 0.768,
              17,  5, 0.602, 0.440, 0.768,
              18,  5, 0.602, 0.440, 0.767,
              19,  5, 0.602, 0.440, 0.767,
              20,  5, 0.602, 0.440, 0.766,
              21,  5, 0.602, 0.440, 0.766,
              22,  5, 0.602, 0.440, 0.765,
              23,  5, 0.602, 0.440, 0.765,
              24,  5, 0.602, 0.440, 0.764,
              25,  5, 0.602, 0.440, 0.764,
              26,  5, 0.602, 0.440, 0.764,
              27,  5, 0.602, 0.439, 0.763,
              28,  5, 0.602, 0.439, 0.763,
              29,  5, 0.602, 0.439, 0.763,
              30,  5, 0.602, 0.439, 0.762,
              31,  5, 0.602, 0.439, 0.762,
               1,  6, 0.602, 0.439, 0.762,
               2,  6, 0.602, 0.439, 0.762,
               3,  6, 0.602, 0.439, 0.762,
               4,  6, 0.602, 0.439, 0.762,
               5,  6, 0.602, 0.439, 0.762,
               6,  6, 0.602, 0.438, 0.761,
               7,  6, 0.602, 0.438, 0.761,
               8,  6, 0.602, 0.438, 0.761,
               9,  6, 0.602, 0.438, 0.761,
              10,  6, 0.602, 0.438, 0.761,
              11,  6, 0.602, 0.438, 0.762,
              12,  6, 0.602, 0.438, 0.762,
              13,  6, 0.602, 0.438, 0.762,
              14,  6, 0.602, 0.438, 0.762,
              15,  6, 0.602, 0.437, 0.762,
              16,  6, 0.602, 0.437, 0.762,
              17,  6, 0.602, 0.437, 0.762,
              18,  6, 0.602, 0.437, 0.762,
              19,  6, 0.602, 0.437, 0.763,
              20,  6, 0.602, 0.437, 0.763,
              21,  6, 0.602, 0.437, 0.763,
              22,  6, 0.602, 0.436, 0.763,
              23,  6, 0.602, 0.436, 0.763,
              24,  6, 0.602, 0.436, 0.764,
              25,  6, 0.602, 0.436, 0.764,
              26,  6, 0.601, 0.436, 0.764,
              27,  6, 0.601, 0.436, 0.764,
              28,  6, 0.601, 0.436, 0.764,
              29,  6, 0.601, 0.435, 0.765,
              30,  6, 0.601, 0.435, 0.765,
               1,  7, 0.601, 0.435, 0.765,
               2,  7, 0.600, 0.435, 0.765,
               3,  7, 0.600, 0.435, 0.765,
               4,  7, 0.600, 0.434, 0.766,
               5,  7, 0.600, 0.434, 0.766,
               6,  7, 0.599, 0.434, 0.766,
               7,  7, 0.599, 0.434, 0.766,
               8,  7, 0.599, 0.434, 0.766,
               9,  7, 0.598, 0.433, 0.766,
              10,  7, 0.598, 0.433, 0.766,
              11,  7, 0.598, 0.433, 0.766,
              12,  7, 0.597, 0.433, 0.766,
              13,  7, 0.597, 0.432, 0.767,
              14,  7, 0.597, 0.432, 0.767,
              15,  7, 0.596, 0.432, 0.767,
              16,  7, 0.596, 0.432, 0.766,
              17,  7, 0.595, 0.431, 0.766,
              18,  7, 0.595, 0.431, 0.766,
              19,  7, 0.594, 0.431, 0.766,
              20,  7, 0.594, 0.430, 0.766,
              21,  7, 0.593, 0.430, 0.766,
              22,  7, 0.593, 0.430, 0.766,
              23,  7, 0.592, 0.429, 0.765,
              24,  7, 0.592, 0.429, 0.765,
              25,  7, 0.591, 0.428, 0.765,
              26,  7, 0.590, 0.428, 0.765,
              27,  7, 0.590, 0.428, 0.764,
              28,  7, 0.589, 0.427, 0.764,
              29,  7, 0.588, 0.427, 0.764,
              30,  7, 0.588, 0.426, 0.763,
              31,  7, 0.587, 0.426, 0.763,
               1,  8, 0.586, 0.425, 0.762,
               2,  8, 0.586, 0.425, 0.762,
               3,  8, 0.585, 0.424, 0.761,
               4,  8, 0.584, 0.424, 0.761,
               5,  8, 0.583, 0.423, 0.760,
               6,  8, 0.583, 0.423, 0.760,
               7,  8, 0.582, 0.422, 0.759,
               8,  8, 0.581, 0.421, 0.758,
               9,  8, 0.580, 0.421, 0.758,
              10,  8, 0.579, 0.420, 0.757,
              11,  8, 0.578, 0.420, 0.756,
              12,  8, 0.578, 0.419, 0.755,
              13,  8, 0.577, 0.418, 0.754,
              14,  8, 0.576, 0.418, 0.754,
              15,  8, 0.575, 0.417, 0.753,
              16,  8, 0.574, 0.416, 0.752,
              17,  8, 0.573, 0.415, 0.751,
              18,  8, 0.572, 0.415, 0.750,
              19,  8, 0.571, 0.414, 0.749,
              20,  8, 0.570, 0.413, 0.748,
              21,  8, 0.569, 0.413, 0.747,
              22,  8, 0.569, 0.412, 0.746,
              23,  8, 0.568, 0.411, 0.745,
              24,  8, 0.567, 0.410, 0.744,
              25,  8, 0.566, 0.409, 0.743,
              26,  8, 0.565, 0.409, 0.742,
              27,  8, 0.564, 0.408, 0.741,
              28,  8, 0.563, 0.407, 0.740,
              29,  8, 0.562, 0.406, 0.738,
              30,  8, 0.561, 0.405, 0.737,
              31,  8, 0.560, 0.405, 0.736,
               1,  9, 0.558, 0.404, 0.735,
               2,  9, 0.557, 0.403, 0.734,
               3,  9, 0.556, 0.402, 0.732,
               4,  9, 0.555, 0.401, 0.731,
               5,  9, 0.554, 0.401, 0.730,
               6,  9, 0.553, 0.400, 0.728,
               7,  9, 0.552, 0.399, 0.727,
               8,  9, 0.551, 0.398, 0.725,
               9,  9, 0.550, 0.397, 0.724,
              10,  9, 0.549, 0.396, 0.723,
              11,  9, 0.548, 0.396, 0.721,
              12,  9, 0.546, 0.395, 0.720,
              13,  9, 0.545, 0.394, 0.718,
              14,  9, 0.544, 0.393, 0.717,
              15,  9, 0.543, 0.392, 0.715,
              16,  9, 0.542, 0.391, 0.713,
              17,  9, 0.541, 0.391, 0.712,
              18,  9, 0.540, 0.390, 0.710,
              19,  9, 0.538, 0.389, 0.709,
              20,  9, 0.537, 0.388, 0.707,
              21,  9, 0.536, 0.388, 0.705,
              22,  9, 0.535, 0.387, 0.703,
              23,  9, 0.533, 0.386, 0.702,
              24,  9, 0.532, 0.385, 0.700,
              25,  9, 0.531, 0.385, 0.698,
              26,  9, 0.530, 0.384, 0.696,
              27,  9, 0.528, 0.383, 0.694,
              28,  9, 0.527, 0.383, 0.692,
              29,  9, 0.526, 0.382, 0.690,
              30,  9, 0.525, 0.381, 0.688,
               1, 10, 0.523, 0.381, 0.686,
               2, 10, 0.522, 0.380, 0.684,
               3, 10, 0.521, 0.379, 0.682,
               4, 10, 0.519, 0.379, 0.680,
               5, 10, 0.518, 0.378, 0.678,
               6, 10, 0.517, 0.377, 0.676,
               7, 10, 0.515, 0.377, 0.674,
               8, 10, 0.514, 0.376, 0.671,
               9, 10, 0.512, 0.376, 0.669,
              10, 10, 0.511, 0.375, 0.667,
              11, 10, 0.510, 0.375, 0.664,
              12, 10, 0.508, 0.374, 0.662,
              13, 10, 0.507, 0.374, 0.659,
              14, 10, 0.505, 0.373, 0.657,
              15, 10, 0.504, 0.373, 0.654,
              16, 10, 0.502, 0.372, 0.652,
              17, 10, 0.501, 0.372, 0.649,
              18, 10, 0.499, 0.372, 0.647,
              19, 10, 0.498, 0.371, 0.644,
              20, 10, 0.496, 0.371, 0.641,
              21, 10, 0.495, 0.371, 0.639,
              22, 10, 0.493, 0.370, 0.636,
              23, 10, 0.492, 0.370, 0.633,
              24, 10, 0.490, 0.370, 0.630,
              25, 10, 0.489, 0.369, 0.628,
              26, 10, 0.487, 0.369, 0.625,
              27, 10, 0.485, 0.369, 0.622,
              28, 10, 0.484, 0.368, 0.619,
              29, 10, 0.482, 0.368, 0.616,
              30, 10, 0.481, 0.368, 0.613,
              31, 10, 0.479, 0.368, 0.610,
               1, 11, 0.478, 0.368, 0.607,
               2, 11, 0.476, 0.367, 0.604,
               3, 11, 0.475, 0.367, 0.601,
               4, 11, 0.473, 0.367, 0.598,
               5, 11, 0.471, 0.367, 0.595,
               6, 11, 0.470, 0.367, 0.592,
               7, 11, 0.468, 0.367, 0.589,
               8, 11, 0.467, 0.366, 0.586,
               9, 11, 0.465, 0.366, 0.583,
              10, 11, 0.464, 0.366, 0.580,
              11, 11, 0.462, 0.366, 0.577,
              12, 11, 0.461, 0.366, 0.574,
              13, 11, 0.459, 0.366, 0.571,
              14, 11, 0.458, 0.366, 0.568,
              15, 11, 0.456, 0.366, 0.565,
              16, 11, 0.455, 0.366, 0.562,
              17, 11, 0.454, 0.366, 0.559,
              18, 11, 0.452, 0.365, 0.556,
              19, 11, 0.451, 0.365, 0.553,
              20, 11, 0.450, 0.365, 0.550,
              21, 11, 0.448, 0.365, 0.547,
              22, 11, 0.447, 0.365, 0.544,
              23, 11, 0.446, 0.365, 0.542,
              24, 11, 0.445, 0.365, 0.539,
              25, 11, 0.443, 0.365, 0.536,
              26, 11, 0.442, 0.365, 0.533,
              27, 11, 0.441, 0.365, 0.531,
              28, 11, 0.440, 0.365, 0.528,
              29, 11, 0.439, 0.365, 0.526,
              30, 11, 0.438, 0.365, 0.523,
               1, 12, 0.437, 0.365, 0.521,
               2, 12, 0.436, 0.365, 0.519,
               3, 12, 0.435, 0.365, 0.517,
               4, 12, 0.434, 0.365, 0.515,
               5, 12, 0.434, 0.365, 0.513,
               6, 12, 0.433, 0.365, 0.511,
               7, 12, 0.432, 0.365, 0.509,
               8, 12, 0.431, 0.365, 0.507,
               9, 12, 0.431, 0.365, 0.505,
              10, 12, 0.430, 0.365, 0.504,
              11, 12, 0.430, 0.365, 0.502,
              12, 12, 0.429, 0.365, 0.501,
              13, 12, 0.429, 0.365, 0.500,
              14, 12, 0.429, 0.365, 0.498,
              15, 12, 0.428, 0.365, 0.497,
              16, 12, 0.428, 0.365, 0.496,
              17, 12, 0.428, 0.365, 0.496,
              18, 12, 0.428, 0.365, 0.495,
              19, 12, 0.428, 0.365, 0.494,
              20, 12, 0.428, 0.365, 0.494,
              21, 12, 0.428, 0.365, 0.494,
              22, 12, 0.428, 0.365, 0.493,
              23, 12, 0.429, 0.365, 0.493,
              24, 12, 0.429, 0.366, 0.493,
              25, 12, 0.429, 0.366, 0.493,
              26, 12, 0.430, 0.366, 0.494,
              27, 12, 0.430, 0.366, 0.494,
              28, 12, 0.431, 0.366, 0.495,
              29, 12, 0.431, 0.366, 0.495,
              30, 12, 0.432, 0.366, 0.496,
              31, 12, 0.433, 0.366, 0.497),ncol=5,byrow=TRUE);
        dimnames(RESULT) <- list(1:366,c("day","month","grad_Tmean","grad_Tmin","grad_Tmax"));
        return(RESULT);
      }



    ##Format_______________________________________________________________________________________
      HypsoData <- as.double(HypsoData);
      ZInputs   <- as.double(ZInputs);


    ##ElevationLayers_Creation_____________________________________________________________________
      ZLayers   <-  as.double(rep(NA,NLayers));
      if(!identical(HypsoData,as.double(rep(NA,101)))){
        nmoy   <- 100 %/% NLayers;
        nreste <- 100 %% NLayers;
        ncont  <- 0;
        for(iLayer in 1:NLayers){
          if(nreste > 0){ nn <- nmoy+1; nreste <- nreste-1; } else { nn <- nmoy; }
          if(nn==1){ ZLayers[iLayer] <- HypsoData[ncont+1]; }
          if(nn==2){ ZLayers[iLayer] <- 0.5 * (HypsoData[ncont+1] + HypsoData[ncont+2]); }
          if(nn>2 ){ ZLayers[iLayer] <- HypsoData[ncont+nn/2]; }
          ncont <- ncont+nn;
        }
      }
  

    ##Precipitation_extrapolation__________________________________________________________________
      ##Initialisation
      LayerPrecip <- list();
      if(identical(ZInputs,HypsoData[51]) & NLayers==1){
        LayerPrecip[[1]] <- as.double(Precip);
      } else {
      ##Elevation_gradients_for_daily_mean_precipitation
        GradP    <- GradP_Valery2010(); ### single value
        TabGradP <- rep(GradP,length(Precip));
      ##Extrapolation
        ##Thresold_of_inputs_median_elevation
        Zthreshold <- 4000;
        ##_On_each_elevation_layer...
        for(iLayer in 1:NLayers){
          ##If_layer_elevation_smaller_than_Zthreshold
          if(ZLayers[iLayer] <= Zthreshold){ 
            LayerPrecip[[iLayer]] <- as.double(Precip*exp(TabGradP*(ZLayers[iLayer]-ZInputs))); 
          ##If_layer_elevation_greater_than_Zthreshold
          } else {
            ##If_inputs_median_elevation_smaller_than_Zthreshold
            if(ZInputs <= Zthreshold){ LayerPrecip[[iLayer]] <- as.double(Precip*exp(TabGradP*(Zthreshold-ZInputs)));
            ##If_inputs_median_elevation_greater_then_Zthreshold
            } else { LayerPrecip[[iLayer]] <- as.double(Precip); }
          }
        }
      }



    ##Temperature_extrapolation____________________________________________________________________
      ##Initialisation
      LayerTempMean <- list(); LayerTempMin <- list(); LayerTempMax <- list();
      if(identical(ZInputs,HypsoData[51]) & NLayers==1){
        LayerTempMean[[1]] <- as.double(TempMean);
        if(!is.null(TempMin) & !is.null(TempMax)){ LayerTempMin[[1]] <- as.double(TempMin); LayerTempMax[[1]] <- as.double(TempMax); }
      } else {
      ##Elevation_gradients_for_daily_mean_min_and_max_temperature
        GradT    <- GradT_Valery2010(); ### Day, Month, GradTmean, GradTmin and GradTmax for iCol=1,2,3,4,5, respectively
        TabGradT <- matrix(NA,nrow=length(Precip),ncol=3);
        for(iday in 1:366){
          ind <- which(as.numeric(format(DatesR,format="%d"))==GradT[iday,1] & as.numeric(format(DatesR,format="%m"))==GradT[iday,2]);
          TabGradT[ind,1:3] <- GradT[iday,3:5];
        }
      ##Extrapolation
        ##On_each_elevation_layer...
        for(iLayer in 1:NLayers){
          LayerTempMean[[iLayer]] <- as.double(TempMean + (ZInputs-ZLayers[iLayer])*abs(TabGradT[,1])/100);
          if(!is.null(TempMin) & !is.null(TempMax)){
          LayerTempMin[[iLayer]]  <- as.double(TempMin  + (ZInputs-ZLayers[iLayer])*abs(TabGradT[,2])/100);
          LayerTempMax[[iLayer]]  <- as.double(TempMax  + (ZInputs-ZLayers[iLayer])*abs(TabGradT[,3])/100);
          }
        }
      }


 
    ##Solid_Fraction_for_each_elevation_layer______________________________________________________
      LayerFracSolidPrecip <- list();
      ##Thresold_of_inputs_median_elevation
      Zthreshold <- 1500;
      ##On_each_elevation_layer...
      for(iLayer in 1:NLayers){
        Option <- "USACE";
        if(!is.na(ZInputs)){ if(ZInputs < Zthreshold & !is.null(TempMin) & !is.null(TempMax)){ Option <- "Hydrotel"; } }
        ##Turcotte_formula_from_Hydrotel
        if(Option=="Hydrotel"){
          TempMin <- LayerTempMin[[iLayer]];
          TempMax <- LayerTempMax[[iLayer]];
          SolidFraction <- 1 - TempMax/(TempMax - TempMin);
          SolidFraction[TempMin >= 0] <- 0;
          SolidFraction[TempMax <= 0] <- 1;
        }
        ##USACE_formula
        if(Option=="USACE"){
          USACE_Tmin <- -1.0;
          USACE_Tmax <-  3.0;
          TempMean <- LayerTempMean[[iLayer]];
          SolidFraction <- 1- (TempMean - USACE_Tmin)/(USACE_Tmax - USACE_Tmin);
          SolidFraction[TempMean > USACE_Tmax] <- 0;
          SolidFraction[TempMean < USACE_Tmin] <- 1;
        }
        LayerFracSolidPrecip[[iLayer]] <- as.double(SolidFraction);
      }




    ##END__________________________________________________________________________________________
    return(list(LayerPrecip=LayerPrecip,LayerTempMean=LayerTempMean,LayerTempMin=LayerTempMin,LayerTempMax=LayerTempMax,
                LayerFracSolidPrecip=LayerFracSolidPrecip,ZLayers=ZLayers));

}