unit loadunit; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, CustomDrawnControls, StdCtrls, ExtCtrls, Types,fit; type { TLoadForm } TLoadForm = class(TForm) extentionEdit: TEdit; exitbutton: TCDButton; ListBox: TListBox; Memo: TMemo; SelectLoadDirectory: TSelectDirectoryDialog; selectmeasdirectorybutton: TCDButton; Timer: TTimer; procedure exitbuttonClick(Sender: TObject); procedure extentionEditChange(Sender: TObject); procedure extentionEditKeyPress(Sender: TObject; var Key: char); procedure ListBoxClick(Sender: TObject); procedure ListBoxDrawItem(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState); procedure selectmeasdirectorybuttonClick(Sender: TObject); procedure TimerTimer(Sender: TObject); private public end; var LoadForm: TLoadForm; procedure fillfilelist; procedure loadmemo(s:string); procedure clearindexes; procedure loadfiles; procedure minmax; procedure Savep; procedure setaxislabels; procedure Drawp; implementation {$R *.lfm} uses main,variables,baselineset; var measfile:string; { TLoadForm } procedure TLoadForm.exitbuttonClick(Sender: TObject); begin Loadform.Visible:=false; mainForm.Newbutton.Color:=clAqua; end; procedure TLoadForm.extentionEditChange(Sender: TObject); begin end; procedure TLoadForm.ListBoxDrawItem(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState); var lb: TListBox absolute Control; ts: TTextStyle; begin lb.Canvas.font.Color:=clblack; lb.Canvas.Brush.Color:=clcream; if index=clickindex then lb.Canvas.font.Color :=clred; if measset and (index=measindex) then lb.Canvas.font.Color :=clgreen; if baseset and (index=baseindex) then lb.Canvas.font.Color :=clblue; if measset and baseset and (measindex=baseindex) and (index=measindex) then lb.Canvas.font.Color :=clAqua; lb.Canvas.FillRect(ARect); lb.Canvas.TextOut(ARect.Left, ARect.Top, ListBox.Items[Index]); end; procedure loadmemo(s:string); var f:text; st,sr:string; begin {$I-} LoadForm.Memo.Clear; assign(f,s); reset(f); readln(f,st); readln(f,st); readln(f,st); LoadForm.Memo.Append(st); readln(f,st); LoadForm.Memo.Append(st); readln(f,st); LoadForm.Memo.Append(st); readln(f,st); LoadForm.Memo.Append(st); readln(f,st); LoadForm.Memo.Append(st); readln(f,st); LoadForm.Memo.Append(st); readln(f,st); LoadForm.Memo.Append(st); close(f); {$I+} end; function DSCfile(filename:string):boolean; var f:text; s,st:string; begin {$I-} DSCfile:=false; assign(f,filename); reset(f); readln(f,s); if (s='DTA measure') and measurefiles then DSCfile:=true; if (s='DTA measure, Saved') and drawfiles then DSCfile:=true; end; procedure fillfilelist; var Info : TSearchRec; begin LoadForm.ListBox.visible:=true; LoadForm.ListBox.Items.Clear; fileextention:=Loadform.extentionEdit.text; If FindFirst (loadDirectory+bs+Loadform.extentionEdit.text,faAnyFile,Info)=0 then begin Repeat With Info do begin If (Attr and faDirectory)<>faDirectory then begin if DSCfile(LoadDirectory+bs+Name) then LoadForm.ListBox.Items.Add(Name); end; end; Until FindNext(info)<>0; FindClose(Info); end; end; procedure clearindexes; begin fillfilelist; LoadForm.Memo.Clear; clickindex:=0; measindex:=-1; baseindex:=-1; measset:=false; baseset:=false; if LoadForm.ListBox.Items.Count>0 then loadmemo(LoadDirectory+bs+LoadForm.ListBox.Items[clickindex]); end; procedure TLoadForm.selectmeasdirectorybuttonClick(Sender: TObject); begin LoadForm.SelectLoadDirectory.Initialdir:=loaddirectory; if not SelectloadDirectory.execute then exit; loadDirectory:=LoadForm.SelectLoadDirectory.Filename; clearindexes; end; procedure TLoadForm.TimerTimer(Sender: TObject); var f:string; begin exit; end; procedure newmeasureset; begin if (not measset) and (clickindex=LoadForm.ListBox.ItemIndex) then begin measset:=true; measindex:=LoadForm.ListBox.ItemIndex; filename:=LoadForm.ListBox.Items[clickindex]; filename1:=LoadDirectory+bs+LoadForm.ListBox.Items[clickindex]; measfile:=LoadForm.ListBox.Items[clickindex]; Loadform.Visible:=false; mainForm.Newbutton.Color:=clAqua; loadfiles; exit; end; clickindex:=LoadForm.ListBox.ItemIndex; fillfilelist; loadmemo(LoadDirectory+bs+LoadForm.ListBox.Items[clickindex]); end; procedure drawfileset; begin if (not measset) and (clickindex=LoadForm.ListBox.ItemIndex) then begin measset:=true; measindex:=LoadForm.ListBox.ItemIndex; drawfile:=LoadDirectory+bs+LoadForm.ListBox.Items[clickindex]; measfile:=LoadForm.ListBox.Items[clickindex]; filename:=measfile; Loadform.Visible:=false; mainForm.Drawbutton.Color:=clAqua; resultout('ok'); Drawp; exit; end; clickindex:=LoadForm.ListBox.ItemIndex; fillfilelist; loadmemo(LoadDirectory+bs+LoadForm.ListBox.Items[clickindex]); end; procedure TLoadForm.ListBoxClick(Sender: TObject); begin if LoadForm.ListBox.Items.Count<=0 then exit; if LoadForm.ListBox.ItemIndex<0 then exit; if measurefiles then newmeasureset; if drawfiles then drawfileset; end; procedure TLoadForm.extentionEditKeyPress(Sender: TObject; var Key: char); begin if byte(key)=13 then clearindexes; end; procedure readdata(filename:string;var mass,mtime:double; var iden1,iden2:string;var datanum:longint); var ff:text; s,s1,ss:string; code,i:longint; rate:double; dumi:double; begin {$I-} i:=ioresult; assign(ff,filename); reset(ff); readln(ff,s); readln(ff,s); readln(ff,iden1); iden2:='From '; readln(ff,s);s:=copy(s,pos('=',s)+2,30);s:=copy(s,1,pos('C',s)-2); iden2:=iden2+s+' to '; readln(ff,s);s:=copy(s,pos('=',s)+2,30);s:=copy(s,1,pos('C',s)-2); iden2:=iden2+s+'C '; readln(ff,s); iden2:=iden2+s; s:=copy(s,pos('Rate',s)+7,20); s:=copy(s,1,pos('C/min',s)-2); val(s,rate,code); if code<>0 then rate:=1; readln(ff,s);iden2:=iden2+', '+s; s:=copy(s,pos('=',s)+2,pos('s',s)-3-pos('=',s)); val(s,mtime,code); if code<>0 then mtime:=1; readln(ff,s);iden2:=iden2+', '+s; s:=copy(s,pos('=',s)+2,pos('mg',s)-3-pos('=',s)); val(s,mass,code); if code<>0 then mass:=1; readln(ff,s);{iden2:=iden2+', '+s;} s:=copy(s,pos('=',s)+1,255); val(s,datanum,code); if code<>0 then begin datanum:=0; exit; end; readln(ff,s); for i:=1 to datanum do begin read(ff,t1[i]); read(ff,a1[i]); read(ff,temp1[i]); read(ff,temp2[i]); readln(ff,tempf[i]); end; close(ff); if ioresult<>0 then begin datanum:=0; exit; end; {$I+} end; procedure resetparam; begin baselineb:=false; nobaselineset:=true; bimin:=1; bimax:=datanum1; textsp:=0; markersp:=0; linesp:=0; resultstr:=''; lowerlimitb:=false; upperlimitb:=false; baselineindex1b:=false; baselineindex2b:=false; lineindex:=1; upallowed:=false; integrationindex1b:=false; integrationindex2b:=false; straightbaselineb:=false; curvedbaselineb:=false; baselinesetready:=false; areaprocb:=false; onsetprocb:=false; tmaxprocb:=false; end; procedure minmax; var i:longint; x,y:double; begin if not fileloaded then exit; timemin:=10000000; timemax:=0; qmin:=500; qmax:=-500; tempmin:=1100; tempmax:=0; for i:=bimin to bimax do begin if t1[i]>timemax then timemax:=t1[i]; if t1[i]qmax then qmax:=x; if temp2[i]tempmax then tempmax:=temp2[i]; if temp1[i]>tempmax then tempmax:=temp1[i]; end; for i:=bimin to bimax do begin x:=a2[i]; if xqmax then qmax:=x; end; x:=(qmax-qmin)/2*1.2; if abs(x)<0.01 then x:=0.01; y:=(qmax+qmin)/2; qmin:=y-x; qmax:=y+x; mainform.TimemaxEdit.value:=timemax; mainform.TimeminEdit.value:=timemin; mainform.TempmaxEdit.value:=tempmax; mainform.TempminEdit.value:=tempmin; mainform.qmaxEdit.value:=qmax; mainform.qminEdit.value:=qmin; settimemax; settimemin; settempmax; settempmin; setqmax; setqmin; end; procedure monotontemp; var i,imax:longint; temp2max:double; begin temp2max:=0; imax:=1; monotonb:=true; for i:=1 to datanum1-1 do if temp2[i]>temp2max then begin imax:=i; temp2max:=temp2[i]; end; if imax<(datanum1-1) then monotonb:=false; end; procedure setaxislabels; var yunit:string; begin if baselineb then begin; yunit:='dT/m [°C/mg]' end else begin; yunit:='dT [°C]' end; tempunit:='[°C]'; mainform.Chart1.AxisList[4].Title.Caption:=yunit; mainform.Chart1.AxisList[3].Title.Caption:='T '+tempunit; mainform.Chart1.AxisList[5].Title.Caption:='T '+tempunit; end; procedure loadfiles; var i:longint; begin readdata(filename1,mass1,mtime1,ident11,ident21,datanum1); a2:=a1; resetparam; setaxislabels; mainform.memo.Clear; mainForm.Memo.Append(measfile); mainForm.Memo.Append(ident11); mainForm.Memo.Append(ident21); fileloaded:=true; bimin:=1; bimax:=datanum1; minmax; minmax; monotontemp; redraw; resultout(''); end; procedure Savep; var s:string; ff:text; i,j:longint; ss:string; begin ss:='$'; s:=filename; s:=copy(s,1,length(s)-1); s:=saveDirectory+s+ss; resultout(s); assign(ff,s); {$I-} rewrite(ff); ss:='DTA measure, Saved'; writeln(ff,ss); writeln(ff,ident11); writeln(ff,ident21); writeln(ff); writeln(ff,'Number of data'); writeln(ff,datanum1); writeln(ff); ss:='time [s] dt [C] temp.sample [C] temp.ref [C]'; for i:=1 to datanum1 do begin writeln(ff,t1[i],' ',a1[i],' ',temp1[i],' ',temp2[i]); end; writeln(ff); writeln(ff,'Number of markers'); writeln(ff,markersp); for i:=1 to markersp do writeln(ff,markers[i]); writeln(ff); writeln(ff,'Number of lines'); writeln(ff,linesp); for i:=1 to linesp do begin writeln(ff,lines[i].t0); writeln(ff,lines[i].temp0); writeln(ff,lines[i].a0); writeln(ff,lines[i].t1); writeln(ff,lines[i].temp1); writeln(ff,lines[i].a1); end; writeln(ff); writeln(ff,'Number of texts'); writeln(ff,textsp); for i:=1 to textsp do for j:=1 to 4 do begin writeln(ff,texts[i].head[j]); writeln(ff,texts[i].str[j]); writeln(ff,texts[i].index[j]); writeln(ff,texts[i].y[j]); if texts[i].b[j] then writeln(ff,1) else writeln(ff,0); end; close(ff); i:=ioresult; resultout('File '+s+' saved'); end; procedure Drawp; var s,s0:string; x0,y0,i,j,k:longint; ff:text; begin {$I-} ioresult; resetparam; filename1:=drawfile; resultout(filename1); assign(ff,filename1); reset(ff); readln(ff,s0); readln(ff,ident11); readln(ff,ident21); readln(ff,s); readln(ff,s); readln(ff,datanum1); readln(ff,s); readln(ff,s); for i:=1 to datanum1 do begin read(ff,t1[i]); read(ff,a1[i]); a2[i]:=0; read(ff,temp1[i]); readln(ff,temp2[i]); end; readln(ff,s); readln(ff,s); readln(ff,markersp); for i:=1 to markersp do readln(ff,markers[i]); readln(ff); readln(ff,s); readln(ff,linesp); for i:=1 to linesp do begin readln(ff,lines[i].t0); readln(ff,lines[i].temp0); readln(ff,lines[i].a0); readln(ff,lines[i].t1); readln(ff,lines[i].temp1); readln(ff,lines[i].a1); end; readln(ff,s); readln(ff,s); readln(ff,textsp); for i:=1 to textsp do for j:=1 to 4 do begin readln(ff,texts[i].head[j]); readln(ff,texts[i].str[j]); readln(ff,texts[i].index[j]); readln(ff,texts[i].y[j]); texts[i].b[j]:=false; readln(ff,k); if k=1 then texts[i].b[j]:=true; end; close(ff); ioresult; {$I-} bimin:=1; bimax:=datanum1; baselineb:=true; differenceb:=true; setaxislabels; mainform.memo.Clear; mainForm.Memo.Append(measfile); mainForm.Memo.Append(ident11); mainForm.Memo.Append(ident21); fileloaded:=true; minmax; monotontemp; redraw; end; end.