Skip to content

Commit

Permalink
Changed rounding algorithm for Kelvin to Celsius
Browse files Browse the repository at this point in the history
  • Loading branch information
gbvalor committed Jan 18, 2016
1 parent e53948f commit fd8cda7
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/libraries/bufr2syn_x12.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ char * kelvin_to_snTTT ( char *target, double T )
{
return NULL;
}
ic = ( int ) ( 100.0 * T + 0.001 ) - 27315;

// tenths of degree (Celsius)
ic = ( int ) ( floor(10.0 * (T - 273.15) + 0.5 ));
if ( ic < 0 )
{
sprintf ( target, "1%03d", ( -ic + 5 ) /10 );
sprintf ( target, "1%03d", -ic );
}
else
{
sprintf ( target, "%04d", ( ic + 4 ) /10 );
sprintf ( target, "0%03d", ic );
}
return target;
}
Expand All @@ -61,8 +63,9 @@ char * kelvin_to_snTT ( char *target, double T )
{
return NULL;
}
ic = ( int ) ( 100.0 * T + 0.001 ) - 27315;
ic /= 100;

// Whole degrees (Celsius)
ic = ( int ) ( floor((T - 273.15) + 0.5 ));
if ( ic < 0 )
{
sprintf ( target, "1%02d", -ic );
Expand All @@ -87,8 +90,9 @@ char * kelvin_to_TT ( char *target, double T )
{
return NULL;
}
ic = ( int ) ( 100.0 * T + 0.001 ) - 27315;
ic /= 100;

// Whole degrees (Celsius)
ic = ( int ) ( floor((T - 273.15) + 0.5 ));
if ( ic < 0 )
{
sprintf ( target, "%02d", 50 - ic );
Expand All @@ -113,8 +117,8 @@ char * kelvin_to_TTTT ( char *target, double T )
{
return NULL;
}

ic = ( int ) ( 100.0 * T + 0.001 ) - 27315;
// hundreth of degrees (Celsius)
ic = ( int ) ( floor(100.0 * (T - 273.15) + 0.5 ));
if ( ic < 0 )
{
ic = 5000 - ic;
Expand Down

0 comments on commit fd8cda7

Please sign in to comment.