//Resistance thermometer

function R=PT100_Platinum(t)
  //name: Resistance thermometer PT100 Platinum
  //type: 404
  //temperature units: °C
  //emf units: Ohm
  //range: -200.0 to 0.0°C
  A1=3.9083E-3
  B1=-5.775E-7
  C1=-4.183E-12
  //range: 0.0 to 850.0°C
  A2=3.9083E-3
  B2=-5.775E-7
  //Resistance at 0°C
  R0=100

  if t>=-200.0 & t<=0.0 then
    R=R0*(1+A1*t+B1*t^2+C1*(t-100)*t^3)
  elseif t>0.0 & t<=850.0 then
    R=R0*(1+A2*t+B2*t^2)
  else disp("Out of range")
  end
endfunction

function t=Inv_PT100_Platinum(R)
  //Inverse coefficients for PT100 Platinum
  //Temperature range: -200.0 to 0.0°C
  //Ohm range: 18.52 to 100Ohm
  A2=-5.67E-6
  B2=2.498437E-3
  C2=2.22764
  D2=-242.078
  //Temperature range: 0.0 to 850°C
  //Ohm range: 100 to 390.48Ohm
  A1=3.9083E-3
  B1=-5.775E-7
//Resistance at 0°C
  R0=100
//Error range: Class AA
  tgAA=0.1+0.0017*t
  tgA=0.15+0.002*t
  tgB=0.30+0.005*t
  tgC=0.6+0.01*t

  if R>=-18.49 & R<=100.0 then
    t=A2*R^3+B2*R^2+C2*R+D2
  elseif R>100.0 & R<=390.26 then
    t=(-A1*R0+sqrt((A1*R0)^2-4*B1*R0*(R0-R)))/(2*B1*R0)
  else disp("Out of range")
  end
endfunction

function Table_PT100_Platinum()

//Temperatur T[°C]
t=[-200:1:850]

//Resistance R[Ohm];
R=[18.52,18.95,19.38,19.82,20.25,20.68,21.11,21.54,21.97,22.4,...
22.83,23.25,23.68,24.11,24.54,24.97,25.39,25.82,26.24,26.67,...
27.1,27.52,27.95,28.37,28.8,29.22,29.64,30.07,30.49,30.91,...
31.34,31.76,32.18,32.6,33.02,33.44,33.86,34.28,34.7,35.12,...
35.54,35.96,36.38,36.8,37.22,37.64,38.05,38.47,38.89,39.31,...
39.72,40.14,40.56,40.97,41.39,41.8,42.22,42.63,43.05,43.46,...
43.88,44.29,44.7,45.12,45.53,45.94,46.36,46.77,47.18,47.59,...
48,48.42,48.83,49.24,49.65,50.06,50.47,50.88,51.29,51.7,...
52.11,52.52,52.93,53.34,53.75,54.15,54.56,54.97,55.38,55.79,...
56.19,56.6,57.01,57.41,57.82,58.23,58.63,59.04,59.44,59.85,...
60.26,60.66,61.07,61.47,61.88,62.28,62.68,63.09,63.49,63.9,...
64.3,64.7,65.11,65.51,65.91,66.31,66.72,67.12,67.52,67.92,...
68.33,68.73,69.13,69.53,69.93,70.33,70.73,71.13,71.53,71.93,...
72.33,72.73,73.13,73.53,73.93,74.33,74.73,75.13,75.53,75.93,...
76.33,76.73,77.12,77.52,77.92,78.32,78.72,79.11,79.51,79.91,...
80.31,80.7,81.1,81.5,81.89,82.29,82.69,83.08,83.48,83.87,...
84.27,84.67,85.06,85.46,85.85,86.25,86.64,87.04,87.43,87.83,...
88.22,88.62,89.01,89.4,89.8,90.19,90.59,90.98,91.37,91.77,...
92.16,92.55,92.95,93.34,93.73,94.12,94.52,94.91,95.3,95.69,...
96.09,96.48,96.87,97.26,97.65,98.04,98.44,98.83,99.22,99.61,...
100,100.39,100.78,101.17,101.56,101.95,102.34,102.73,103.12,103.51,...
103.9,104.29,104.68,105.07,105.46,105.85,106.24,106.63,107.02,107.4,...
107.79,108.18,108.57,108.96,109.35,109.73,110.12,110.51,110.9,111.29,...
111.67,112.06,112.45,112.83,113.22,113.61,114,114.38,114.77,115.15,...
115.54,115.93,116.31,116.7,117.08,117.47,117.86,118.24,118.63,119.01,...
119.4,119.78,120.17,120.55,120.94,121.32,121.71,122.09,122.47,122.86,...
123.24,123.63,124.01,124.39,124.78,125.16,125.54,125.93,126.31,126.69,...
127.08,127.46,127.84,128.22,128.61,128.99,129.37,129.75,130.13,130.52,...
130.9,131.28,131.66,132.04,132.42,132.8,133.18,133.57,133.95,134.33,...
134.71,135.09,135.47,135.85,136.23,136.61,136.99,137.37,137.75,138.13,...
138.51,138.88,139.26,139.64,140.02,140.4,140.78,141.16,141.54,141.91,...
142.29,142.67,143.05,143.43,143.8,144.18,144.56,144.94,145.31,145.69,...
146.07,146.44,146.82,147.2,147.57,147.95,148.33,148.7,149.08,149.46,...
149.83,150.21,150.58,150.96,151.33,151.71,152.08,152.46,152.83,153.21,...
153.58,153.96,154.33,154.71,155.08,155.46,155.83,156.2,156.58,156.95,...
157.33,157.7,158.07,158.45,158.82,159.19,159.56,159.94,160.31,160.68,...
161.05,161.43,161.8,162.17,162.54,162.91,163.29,163.66,164.03,164.4,...
164.77,165.14,165.51,165.89,166.26,166.63,167,167.37,167.74,168.11,...
168.48,168.85,169.22,169.59,169.96,170.33,170.7,171.07,171.43,171.8,...
172.17,172.54,172.91,173.28,173.65,174.02,174.38,174.75,175.12,175.49,...
175.86,176.22,176.59,176.96,177.33,177.69,178.06,178.43,178.79,179.16,...
179.53,179.89,180.26,180.63,180.99,181.36,181.72,182.09,182.46,182.82,...
183.19,183.55,183.92,184.28,184.65,185.01,185.38,185.74,186.11,186.47,...
186.84,187.2,187.56,187.93,188.29,188.66,189.02,189.38,189.75,190.11,...
190.47,190.84,191.2,191.56,191.92,192.29,192.65,193.01,193.37,193.74,...
194.1,194.46,194.82,195.18,195.55,195.91,196.27,196.63,196.99,197.35,...
197.71,198.07,198.43,198.79,199.15,199.51,199.87,200.23,200.59,200.95,...
201.31,201.67,202.03,202.39,202.75,203.11,203.47,203.83,204.19,204.55,...
204.9,205.26,205.62,205.98,206.34,206.7,207.05,207.41,207.77,208.13,...
208.48,208.84,209.2,209.56,209.91,210.27,210.63,210.98,211.34,211.7,...
212.05,212.41,212.76,213.12,213.48,213.83,214.19,214.54,214.9,215.25,...
215.61,215.96,216.32,216.67,217.03,217.38,217.74,218.09,218.44,218.8,...
219.15,219.51,219.86,220.21,220.57,220.92,221.27,221.63,221.98,222.33,...
222.68,223.04,223.39,223.74,224.09,224.45,224.8,225.15,225.5,225.85,...
226.21,226.56,226.91,227.26,227.61,227.96,228.31,228.66,229.02,229.37,...
229.72,230.07,230.42,230.77,231.12,231.47,231.82,232.17,232.52,232.87,...
233.21,233.56,233.91,234.26,234.61,234.96,235.31,235.66,236,236.35,...
236.7,237.05,237.4,237.74,238.09,238.44,238.79,239.13,239.48,239.83,...
240.18,240.52,240.87,241.22,241.56,241.91,242.26,242.6,242.95,243.29,...
243.64,243.99,244.33,244.68,245.02,245.37,245.71,246.06,246.4,246.75,...
247.09,247.44,247.78,248.13,248.47,248.81,249.16,249.5,249.85,250.19,...
250.53,250.88,251.22,251.56,251.91,252.25,252.59,252.93,253.28,253.62,...
253.96,254.3,254.65,254.99,255.33,255.67,256.01,256.35,256.7,257.04,...
257.38,257.72,258.06,258.4,258.74,259.08,259.42,259.76,260.1,260.44,...
260.78,261.12,261.46,261.8,262.14,262.48,262.82,263.16,263.5,263.84,...
264.18,264.52,264.86,265.2,265.53,265.87,266.21,266.55,266.89,267.22,...
267.56,267.9,268.24,268.57,268.91,269.25,269.59,269.92,270.26,270.6,...
270.93,271.27,271.61,271.94,272.28,272.61,272.95,273.29,273.62,273.96,...
274.29,274.63,274.96,275.3,275.63,275.97,276.3,276.64,276.97,277.31,...
277.64,277.98,278.31,278.64,278.98,279.31,279.64,279.98,280.31,280.64,...
280.98,281.31,281.64,281.98,282.31,282.64,282.97,283.31,283.64,283.97,...
284.3,284.63,284.97,285.3,285.63,285.96,286.29,286.62,286.95,287.29,...
287.62,287.95,288.28,288.61,288.94,289.27,289.6,289.93,290.26,290.59,...
290.92,291.25,291.58,291.91,292.24,292.56,292.89,293.22,293.55,293.88,...
294.21,294.54,294.86,295.19,295.52,295.85,296.18,296.5,296.83,297.16,...
297.49,297.81,298.14,298.47,298.8,299.12,299.45,299.78,300.1,300.43,...
300.75,301.08,301.41,301.73,302.06,302.38,302.71,303.03,303.36,303.69,...
304.01,304.34,304.66,304.98,305.31,305.63,305.96,306.28,306.61,306.93,...
307.25,307.58,307.9,308.23,308.55,308.87,309.2,309.52,309.84,310.16,...
310.49,310.81,311.13,311.45,311.78,312.1,312.42,312.74,313.06,313.39,...
313.71,314.03,314.35,314.67,314.99,315.31,315.64,315.96,316.28,316.6,...
316.92,317.24,317.56,317.88,318.2,318.52,318.84,319.16,319.48,319.8,...
320.12,320.43,320.75,321.07,321.39,321.71,322.03,322.35,322.67,322.98,...
323.3,323.62,323.94,324.26,324.57,324.89,325.21,325.53,325.84,326.16,...
326.48,326.79,327.11,327.43,327.74,328.06,328.38,328.69,329.01,329.32,...
329.64,329.96,330.27,330.59,330.9,331.22,331.53,331.85,332.16,332.48,...
332.79,333.11,333.42,333.74,334.05,334.36,334.68,334.99,335.31,335.62,...
335.93,336.25,336.56,336.87,337.18,337.5,337.81,338.12,338.44,338.75,...
339.06,339.37,339.69,340,340.31,340.62,340.93,341.24,341.56,341.87,...
342.18,342.49,342.8,343.11,343.42,343.73,344.04,344.35,344.66,344.97,...
345.28,345.59,345.9,346.21,346.52,346.83,347.14,347.45,347.76,348.07,...
348.38,348.69,348.99,349.3,349.61,349.92,350.23,350.54,350.84,351.15,...
351.46,351.77,352.08,352.38,352.69,353,353.3,353.61,353.92,354.22,...
354.53,354.84,355.14,355.45,355.76,356.06,356.37,356.67,356.98,357.28,...
357.59,357.9,358.2,358.51,358.81,359.12,359.42,359.72,360.03,360.33,...
360.64,360.94,361.25,361.55,361.85,362.16,362.46,362.76,363.07,363.37,...
363.67,363.98,364.28,364.58,364.89,365.19,365.49,365.79,366.1,366.4,...
366.7,367,367.3,367.6,367.91,368.21,368.51,368.81,369.11,369.41,...
369.71,370.01,370.31,370.61,370.91,371.21,371.51,371.81,372.11,372.41,...
372.71,373.01,373.31,373.61,373.91,374.21,374.51,374.81,375.11,375.41,...
375.7,376,376.3,376.6,376.9,377.19,377.49,377.79,378.09,378.39,...
378.68,378.98,379.28,379.57,379.87,380.17,380.46,380.76,381.06,381.35,...
381.65,381.95,382.24,382.54,382.83,383.13,383.42,383.72,384.01,384.31,...
384.6,384.9,385.19,385.49,385.78,386.08,386.37,386.67,386.96,387.25,...
387.55,387.84,388.14,388.43,388.72,389.02,389.31,389.6,389.9,390.19,...
390.48]

//Darstellung
figure("figure_name",gettext("RTD PT100 Platinum"),"Position",[50,50,500,500],"BackgroundColor",[1.0,1.0,1.0])
title('$RTD\ Table\ for\ PT100\ Platinum\ type\ 404$','color','black','fontsize',5)
plot2d(t,[R],[5])
xgrid()
xlabel('Temperature t [°C]')
ylabel('Resistance R [Ohm]')
endfunction

//create the *.bin files in libdir
libdir = TMPDIR;
save(libdir + '/PT100_Platinum.bin','PT100_Platinum');
save(libdir + '/Inv_PT100_Platinum.bin','Inv_PT100_Platinum');
save(libdir + '/Table_PT100_Platinum','Table_PT100_Platinum');


mputl(['PT100_Platinum';'Inv_PT100_Platinum';'Table_PT100_Platinum'],libdir+'/names');

//build the library
mylibfoo = lib(libdir+'/');

// check the library
mylibfoo
[n,p] = libraryinfo('mylibfoo')
