Not long ago I wrote this little program to generate the NIST table for the k type thermocouple. It may be useful for somebody...
/* This program generates a table similar to the one at http://srdata.nist.gov/its90/download/type_k.tab */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// if( t < 0ÂșC)
// E = coeff[0][0]+coeff[1][0]*t+coeff[2][0]*t^2+...+coeff[10][0]*t^10
// else
// E = coeff[0][0]+coeff[1][0]*t+coeff[2][0]*t^2+...+coeff[9][0]*t^9+a0*exp(a1*(t - a2)*(t - a2)).
//
// coefficients for E=f(t), E is in mV and t is in oC.
const float coeff[11][2] =
{
{ 0.000000000000E+00, -0.176004136860E-01 },
{ 0.394501280250E-01, 0.389212049750E-01 },
{ 0.236223735980E-04, 0.185587700320E-04 },
{ -0.328589067840E-06, -0.994575928740E-07 },
{ -0.499048287770E-08, 0.318409457190E-09 },
{ -0.675090591730E-10, -0.560728448890E-12 },
{ -0.574103274280E-12, 0.560750590590E-15 },
{ -0.310888728940E-14, -0.320207200030E-18 },
{ -0.104516093650E-16, 0.971511471520E-22 },
{ -0.198892668780E-19, -0.121047212750E-25 },
{ -0.163226974860E-22, 0.000000000000E+00 }
};
// Coefficients for exponential portion of equation above
const float a[] = { 0.1185976E+00, -0.1183432E-03, 0.1269686E+03 };
// Ranges for coefficients above
const float range[] = { -270.000 , 0.000, 1372.00 };
float C_to_mv (float t)
{
int k;
float mv=0.0;
if(t<range[1])
{
for(k=10; k>0; k--) mv=(mv+coeff[k][0])*t;
// mv+=coeff[0][0]; // Not needed because coeff[0][0]=0.0
}
else
{
for(k=9; k>0; k--) mv=(mv+coeff[k][1])*t;
mv+=coeff[0][1]+a[0]*exp(a[1]*(t-a[2])*(t-a[2]));
}
return mv;
}
void Create_Table (void)
{
float t;
char i;
printf("\n oC 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10\n");
printf("\n%4.0f %6.3f", range[0], C_to_mv(range[0]));
for(t=range[0]+10.0; t<=range[1]; t+=10.0)
{
printf("\n%4.0f", t);
for(i=0; i>=-10; i--)
{
printf(" %6.3f", C_to_mv(t+i));
}
}
printf("\n");
printf("\n oC 0 1 2 3 4 5 6 7 8 9 10\n");
for(t=range[1]; t<=range[2]; t+=10.0)
{
printf("\n%4.0f", t);
for(i=0; i<=10; i++)
{
if((t+i)<(range[2]+0.1))
printf(" %6.3f", C_to_mv(t+i));
else
return;
}
}
}
void main (void)
{
Create_Table();
}