Friday, March 1, 2019

Delphi Code Example

START
form5.canvas.font.size:=10;
form5.canvas.font.style:=[fsbold];
form5.canvas.font.color:=clblack;
form5.edit1.text:='';
form5.edit2.text:='';
form5.edit3.text:='';
form5.show;

PROCEDURE
label 1;
var
TdewC,T1C,T2C,Ht,LCL,RHd,Tdew,td,T1,T2,densair,m,T,Rh,Rh1,Rh2,P,V,Tsat,Pa,Pv,
Pvd,Psat,omega,tdp,pdp,Va,Vv,Pvs,Pas,omegas,Mv,Ma,Psat1,Psat2,
relh,Tw,LCLC,HTC,LCLT1:extended;
errors1:boolean;
calcstr8,calcstr2,calcstr1,calcstr3,calcstr4,calcstr5,calcstr6,calcstr7:string[30];
begin
errors1:=false;
form5.hide;
form5.show;
Memo1.clear;
Memo1.font.size:=12;
Memo1.font.style:=[fsbold];
Memo1.font.color:=clblack;
try
T1:=strtofloat(form5.edit1.Text);
Rh1:=strtofloat(form5.edit2.Text);
T2:=strtofloat(form5.edit3.Text);
except
errors1:=true;
end;
if (errors1=true) or
(t1<0.01) or (t1>69) or (rh1<0) or (rh1>100) or
(t2<0.1) or (t2>70) or (T2<T1+0.02)
then begin
form5.Memo1.Lines.Add('CHECK ENTRIES.');
goto 1
end;
T1C:=T1;
ht:=1000*(T2-T1)/3.3;
RH1:=RH1/100;
Psat1:=0.61121*exp((18.678-T1/234.5)*T1/(257.14+T1));
Pv:=Psat1*RH1;
Psat2:=0.61121*exp((18.678-T2/234.5)*T2/(257.14+T2));
Rh2:=Pv/Psat2;  {ie partial pressure of water vapour/psat2}
str(rh2*100:9:2,calcstr1);
form5.Memo1.lines.Add('Final relative humidity (at T2) is: '+calcstr1+'%.');
Tdew:=T1;
repeat
Tdew:=Tdew-0.001;
Psat:=0.61121*exp((18.678-Tdew/234.5)*Tdew/(257.14+Tdew));
until (Psat<=Pv);
str(Tdew:12:2,calcstr2);
form5.Memo1.Lines.Add('Dew point is: '+calcstr2+' deg C.');
1: end;

3 comments:

  1. So without a title, what does the above do (for those that cant understand?)
    You should get your ideas into a functionaal specification and then produce an app for android and ios etc

    ReplyDelete
  2. If you tell me what the sections of code are doing e.g. calculate saturation vapour pressure etc and what the constants values represent, I can create a set of functions for you to use. You can build up a library of routines that calculate the DewPoint, Relative Humidity etc

    ReplyDelete
    Replies
    1. The above is a procedure. These procedures are very handy.

      Delete