-
Paolo Veglio authoredPaolo Veglio authored
get_ti_weights_geos.c 1.99 KiB
/*******************************************************************************
Description:
Integer function get_ti_weights_geos.c
Calculates time-interpolation weights from L1b start time and the two GEOS
file times.
Computed weight is for the later of two GEOS grids. The weight of the earlier
one is simply (1.0 - weight).
Called from get_GEOS.c
Input arguments:
targhr decimal start time of input L1b data
gdashr1 integer hour of earlier GEOS file
gdashr2 integer hour of later GEOS file
Output arguments:
wt time-interpolation weight for later GEOS time
Function output:
int return_code successful completion is zero, otherwise non-zero
Revision History:
10/2012 R. Frey Original version
06/2021 R. Frey Modified to use GMAO GEOS files.
Calls:
none
*******************************************************************************/
// Includes
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/******************************************************************************/
int get_ti_weights(float targhr, int geoshr1, int geoshr2, float *wt)
{
/******************************************************************************/
// Declarations and initializations.
int return_code = 0;
/******************************************************************************/
// Calculate time-interpolation weight.
if(geoshr2 > geoshr1) *(wt) = (targhr-(float)geoshr1) / ((float)geoshr2-(float)geoshr1);
if(geoshr2 == geoshr1) *(wt) = 0.0;
if(geoshr2 < geoshr1) {
geoshr2 += 24;
*(wt) = (targhr-(float)geoshr1) / ((float)geoshr2-(float)geoshr1);
if( *(wt) < 0.0) {
printf("GEOS times are incorrect! T-I weight: %f %d %d %f\n", targhr, geoshr1, geoshr2, *(wt));
return_code = -1;
}
}
/******************************************************************************/
return (return_code);
/******************************************************************************/
}