WB to Temp and Tint

Hi.
I know, this question was asked more than once, but I still have not been able to find a solution.
I want to translate the white balance coefficients into Temperature and Tint, as for example, this is done in FastRawViewer.
For this, I used dng_temperature from the DNG SDK (about the error with the typing I know).
I receive rgb_cam from cam_xyz with cam_xyz_coeff for my camera. The rgb_cam now stores the matrix from the camera to sRGB.
To get XYZ, I multiply rgb_cam by xyz_rgb. And multiply the resulting matrix by the RGB value. I hope I understood the dcraw code correctly.
Now the question arises, what exactly to use as RGB. I suggested that I need to divide the pre_mul by a white balance factor. As a result, I get values ​​that are approximately similar to Temp / Tint, but there is no accuracy that is found in FastRawViewer.
I need help, I seem to be mistaken somewhere.
If it's easier to look at the code, here's the my test:

 
	double out_cam[3][4];
	double pre_mul[4] = {0,0,0,0};
	double cam_xyz[4][3] = { {0.6722,-0.0635,-0.0963},{-0.4287,1.2460,0.2028},{-0.0908,0.2162,0.5668} }; // 5D Mark III
	double black = 0;
	double maximum = 0x3c80;
	double rgb_cam[3][4] = {0};
	int i, j, k;
	int colors = 3;
 
	cam_xyz_coeff (rgb_cam, cam_xyz, pre_mul);
 
	double dblRGGB[4] = 
		//{1986.0, 1024.0, 1024.0, 1628.0 }; // RGGB 5200
		//{1438.0, 1024.0, 1024.0, 2399.0 }; // RGGB 3200
		{2275.0, 1024.0, 1024.0, 1393.0 }; // RGGB 7000
	double dblWB[3] = {0, 0, 0};
	double dblRGB[3] = {0, 0, 0};
	double dblXYZ[3] = {0, 0, 0};
	GetWBcoef(dblRGGB, dblWB);
	for (i=0; i < 3; i++) dblWB[i] = pre_mul[i] / dblWB[i];
	double dblWBmax = MAX(dblWB[0],MAX(dblWB[1],dblWB[2]));
	for (i=0; i < 3; i++) dblRGB[i] = dblWB[i] / dblWBmax;
 
	for (i=0; i < 3; i++)
      for (j=0; j < colors; j++)
	for (out_cam[i][j] = double(k=0); k < 3; k++)
	  out_cam[i][j] += xyz_rgb[i][k] * rgb_cam[k][j];
	dblXYZ[0] = dblXYZ[1] = dblXYZ[2] = 0;
	for (i=0; i < colors; i++) {
	  dblXYZ[0] += out_cam[0][i] * dblRGB[i];
	  dblXYZ[1] += out_cam[1][i] * dblRGB[i];
	  dblXYZ[2] += out_cam[2][i] * dblRGB[i];
	}
 
	dng_temperature t;
	dng_vector_3 coord(dblXYZ[0],dblXYZ[1],dblXYZ[2]);
	dng_xy_coord xy = XYZtoXY (coord);
	t.Set_xy_coord(xy);
	double Temp = t.Temperature();
	double Tint = t.Tint();

Forums: 

not solved

In the previous post there was nonsense written. Another piece of code is:

inline void mul2temp_xyz_cam(double *cam_mul, double (*xyz_cam)[3], double &temp, double &tint, int colors = 3)
{
	double xyz[3] = {0,0,0};
	for (int i=0; i < 3; i++)
		for (int j=0; j < colors; j++)
			xyz[i] += xyz_cam[i][j] * 0.5/cam_mul[j];
	xyz2temp(xyz, temp, tint);
}
 
void mul2temp_cam_xyz(double *cam_mul, double (*cam_xyz)[3], double &temp, double &tint, int colors = 3)
{
	double inverse[4][3];
	double xyz_cam[3][3];
	pseudoinverse (cam_xyz, inverse, colors);
	for (int i=0; i < 3; i++)
		for (int j=0; j < colors; j++)
			xyz_cam[i][j] = inverse[j][i];
	mul2temp_xyz_cam(cam_mul, xyz_cam, temp, tint);
}
 
	int i, j, k;
	double xyz_cam[3][3];
	const double xyz_rgb[3][3] = {			// sRGB to XYZD65
		{ 0.412453, 0.357580, 0.180423 },
		{ 0.212671, 0.715160, 0.072169 },
		{ 0.019334, 0.119193, 0.950227 } };
	for (i=0; i < 3; i++)
		for (j=0; j < colors; j++)
			for (xyz_cam[i][j] = k=0; k < 3; k++)
				xyz_cam[i][j] += xyz_rgb[i][k] * rgb_cam[k][j]*pre_mul[j];
 
	mul2temp_xyz_cam(cam_mul, xyz_cam, temp, tint);

doesn't work too. Nevertheless it is not clear how to convert factors into Temp/Tint.