{--------------------------------------------------------------------------- (c) Copyright Aleksandrov O.E., 1999 Molecular Physics department, USTU, Ekaterinsburg, K-2, 620002, RUSSIA phone 75-47-15 E-mail: aleks@dpt.ustu.ru (c) Copyright Александров О.Е., 1999 620002, Екатеринбург, К-2, УГТУ, Кафедра молекулярной физики тел. 75-47-15 E-mail: aleks@dpt.ustu.ru ----------------------------------------------------------------------------} Unit uMiscFun; INTERFACE { Проверяет существует ли файл } {$IfNDef Delphi} function FileExists(const FileName:string):boolean; {$EndIf NDef Delphi} { Возвращает размер файла } function SizeOfFile(const FileName:string):longint; {$IfDef Delphi} function Ansi2Dos(const s:string):string; procedure DosWriteln(Strings:array of string); {$EndIf Def Delphi} type tTimerTiks={$IfNDef Delphi}longint{$Else}cardinal{$EndIf}; tTimerDecimalTiks=record mSec,mAfterDotSec,mScale:tTimerTiks end; tSize={$IfNDef Delphi}longint{$Else}cardinal{$EndIf}; {$IfNDef Delphi} function GetTickCount:tTimerTiks; {$EndIf NDef Delphi} function WaitNextTickCount:tTimerTiks; procedure GetTickSpent(t0:tTimerTiks; Count:word; var mSec:tTimerDecimalTiks ); function GetBytesPerSeconds(Size:tSize; mSec:tTimerDecimalTiks):tSize; IMPLEMENTATION Uses xStrings {$IfDef Delphi}, Windows, MMSystem{$EndIf}; {$IfDef Delphi} function Ansi2Dos(const s:string):string; begin SetLength(Result,Length(s)); CharToOEMBuff(@s[1],@Result[1],Length(s)); end; procedure DosWriteln(Strings:array of string); var i:cardinal; begin for i:=0 to Pred(Length(Strings)) do begin write(Ansi2Dos(Strings[i])); end; writeln; end; {$EndIf Def Delphi} function GetBytesPerSeconds(Size:tSize; mSec:tTimerDecimalTiks):tSize; begin if (Size<(High(Size) div 1000)) then GetBytesPerSeconds:=(Size*1000+(mSec.mSec div 2)) div mSec.mSec else if (Size<(High(Size) div 100)) then GetBytesPerSeconds:=((Size*100+(mSec.mSec div 2)) div mSec.mSec)*10 else if (Size<(High(Size) div 10)) then GetBytesPerSeconds:=((Size*10+(mSec.mSec div 2)) div mSec.mSec)*100 else GetBytesPerSeconds:=((Size+(mSec.mSec div 2)) div mSec.mSec)*1000; end; procedure GetTickSpent(t0:tTimerTiks; Count:word; var mSec:tTimerDecimalTiks ); var dt,scale,ads,ads1,adsx:tTimerTiks; i:byte; const cMaxScale=10000; cMaxCount=4; begin dt:=(GetTickCount-t0+(Count div 2)); scale:=cMaxScale; i:=cMaxCount; while (010) and (ads>10) then begin repeat adsx:=ads div 10; ads1:=adsx*10; if (ads1=ads) and (ads1<>0) then begin ads:=adsx; scale:=scale div 10; end; until (scale<10) or (adsx<>ads); end; mSec.mAfterDotSec:=ads; mSec.mScale:=scale; end; {$IfOpt I+} {$Define IisOn} {$I-} {$EndIf} {$IfNDef Delphi} function FileExists; var OldFileMode:byte; fl:file; begin Assign(fl,FileName); OldFileMode:=System.FileMode; System.FileMode:=0; Reset(fl); System.FileMode:=OldFileMode; if (IOResult=0) then begin FileExists:=FileSize(fl)>0; Close(fl); end else begin FileExists:=FALSE; end; end; {$EndIf NDef Delphi} function SizeOfFile; var OldFileMode:byte; fl:file; begin Assign(fl,FileName); OldFileMode:=System.FileMode; System.FileMode:=0; Reset(fl,1); System.FileMode:=OldFileMode; if (IOResult=0) then begin SizeOfFile:=FileSize(fl); Close(fl); end else begin SizeOfFile:=-1; end; end; {$IfDef IisOn} {$UnDef IisOn} {$I+} {$EndIf} {$IfNDef Delphi} function GetTickCount:longint; assembler; asm mov es,Seg0040; mov bx,06Ch mov ax,es:[bx] mov cx,es:[bx][2] mov bx,55 mul bx xchg cx,ax; mov si,dx mul bx mov dx,si; add dx,ax mov ax,cx end; function WaitNextTickCount:tTimerTiks; assembler; asm mov es,Seg0040; mov bx,06Ch mov al,es:[bx] @loop: cmp al,es:[bx] je @loop jmp GetTickCount end; {$Else} function WaitNextTickCount:tTimerTiks; var t0:tTimerTiks; begin t0:=timeGetTime; Result:=timeGetTime; while t0=Result do Result:=timeGetTime; end; {$EndIf NDef Delphi} END.