(********************************************
  Version: 7.0
  Date: 2003/11/25
  This is shareware.
  Copyright (C) Michal Pohanka
  All rights reserved.

  Internet: http://www.volny.cz/profipohanka
 ********************************************)

unit HCArrays;

interface

const
  t0oC=273.15; // [K]

type
  float = double;

  tXY = record
    x, y: float; // values
  end;

  // arrays
  tempArrChar = packed array[0..1000] of char;
  tempArrInt = packed array[0..1000] of integer;
  tempArrFloat = packed array[0..1000] of float;

  // strings
  tMyString = record
    length: integer; // string length
    ch: PChar; // string
  end;

  // int arrays
  tIntArray = record
    i: ^tempArrInt; // array
    n: integer; // array size
    m: integer; // allocated memory
  end;

  tXYIntArray = record
    x, y: ^tempArrInt; // array
    n: integer; // array size
    m: integer; // allocated memory
  end;

  tXYZIntArray = record
    x, y, z: ^tempArrInt; // array
    n: integer; // array size
    m: integer; // allocated memory
  end;

  // float arrays
  tFloatArray = record
    r: ^tempArrFloat; // array
    n: integer; // array size
    m: integer; // allocated memory
  end;

  tXYArray = record
    x, y: ^tempArrFloat; // array
    n: integer; // array size
    m: integer; // allocated memory
  end;

  tXYZArray = record
    x, y, z: ^tempArrFloat; // array
    n: integer; // array size
    m: integer; // allocated memory
  end;

  tABCDArray = record
    a, b, c, d: ^tempArrFloat; // array
    n: integer; // array size
    m: integer; // allocated memory
  end;

///////////////////////////////////////////////////////////////////////////////////////////////////

procedure fHC_Init(var s: tMyString); overload; cdecl; external 'HC.DLL' name '?fHC_Init@@YAXAAUtMyString@@@Z';
procedure fHC_Init(var a: tIntArray); overload; cdecl; external 'HC.DLL' name '?fHC_Init@@YAXAAUtIntArray@@@Z';
procedure fHC_Init(var a: tXYIntArray); overload; cdecl; external 'HC.DLL' name '?fHC_Init@@YAXAAUtXYIntArray@@@Z';
procedure fHC_Init(var a: tXYZIntArray); overload; cdecl; external 'HC.DLL' name '?fHC_Init@@YAXAAUtXYZIntArray@@@Z';
procedure fHC_Init(var a: tFloatArray); overload; cdecl; external 'HC.DLL' name '?fHC_Init@@YAXAAUtRealArray@@@Z';
procedure fHC_Init(var a: tXYArray); overload; cdecl; external 'HC.DLL' name '?fHC_Init@@YAXAAUtXYArray@@@Z';
procedure fHC_Init(var a: tXYZArray); overload; cdecl; external 'HC.DLL' name '?fHC_Init@@YAXAAUtXYZArray@@@Z';
procedure fHC_Init(var a: tABCDArray); overload; cdecl; external 'HC.DLL' name '?fHC_Init@@YAXAAUtABCDArray@@@Z';

procedure fHC_Free(var s: tMyString); overload; cdecl; external 'HC.DLL' name '?fHC_Free@@YAXAAUtMyString@@@Z';
procedure fHC_Free(var a: tIntArray); overload; cdecl; external 'HC.DLL' name '?fHC_Free@@YAXAAUtIntArray@@@Z';
procedure fHC_Free(var a: tXYIntArray); overload; cdecl; external 'HC.DLL' name '?fHC_Free@@YAXAAUtXYIntArray@@@Z';
procedure fHC_Free(var a: tXYZIntArray); overload; cdecl; external 'HC.DLL' name '?fHC_Free@@YAXAAUtXYZIntArray@@@Z';
procedure fHC_Free(var a: tFloatArray); overload; cdecl; external 'HC.DLL' name '?fHC_Free@@YAXAAUtRealArray@@@Z';
procedure fHC_Free(var a: tXYArray); overload; cdecl; external 'HC.DLL' name '?fHC_Free@@YAXAAUtXYArray@@@Z';
procedure fHC_Free(var a: tXYZArray); overload; cdecl; external 'HC.DLL' name '?fHC_Free@@YAXAAUtXYZArray@@@Z';
procedure fHC_Free(var a: tABCDArray); overload; cdecl; external 'HC.DLL' name '?fHC_Free@@YAXAAUtABCDArray@@@Z';

function fHC_GetAllocBlock(): integer; cdecl; external 'HC.DLL' name '?fHC_GetAllocBlock@@YAHXZ'; // get allocating step for Set***Arr
procedure fHC_SetAllocBlock(l: integer); cdecl; external 'HC.DLL' name '?fHC_SetAllocBlock@@YAXH@Z'; // set allocating step for Set***Arr

function fHC_SetLength(var s: tMyString; l: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_SetLength@@YAHAAUtMyString@@H@Z'; // set array size; ch[length]=0; return string length; allocated size = length+1
function fHC_SetLength(var a: tIntArray; l: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_SetLength@@YAHAAUtIntArray@@H@Z'; // set array size; return allocated size
function fHC_SetLength(var a: tXYIntArray; l: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_SetLength@@YAHAAUtXYIntArray@@H@Z'; // set array size; return allocated size
function fHC_SetLength(var a: tXYZIntArray; l: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_SetLength@@YAHAAUtXYZIntArray@@H@Z'; // set array size; return allocated size
function fHC_SetLength(var a: tFloatArray; l: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_SetLength@@YAHAAUtRealArray@@H@Z'; // set array size; return allocated size
function fHC_SetLength(var a: tXYArray; l: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_SetLength@@YAHAAUtXYArray@@H@Z'; // set array size; return allocated size
function fHC_SetLength(var a: tXYZArray; l: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_SetLength@@YAHAAUtXYZArray@@H@Z'; // set array size; return allocated size
function fHC_SetLength(var a: tABCDArray; l: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_SetLength@@YAHAAUtABCDArray@@H@Z'; // set array size; return allocated size

function fHC_Copy(var d: tMyString; s: string): integer; overload; // copy from source to destination
function fHC_Copy(var d: tMyString; var s: tMyString): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Copy@@YAHAAUtMyString@@0@Z'; // copy array from source to destination; return copied size (new dest size)
//function fHC_Copy(var d: tMyString; string var s): integer; cdecl; external 'HC.DLL' name ''; // copy string to tMyString; return copied size (new dest size)
function fHC_Copy(var d: tIntArray; var s: tIntArray): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Copy@@YAHAAUtIntArray@@0@Z'; // copy array from source to destination; return copied size (new dest size)
function fHC_Copy(var d: tXYIntArray; var s: tXYIntArray): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Copy@@YAHAAUtXYIntArray@@0@Z'; // copy array from source to destination; return copied size (new dest size)
function fHC_Copy(var d: tXYZIntArray; var s: tXYZIntArray): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Copy@@YAHAAUtXYZIntArray@@0@Z'; // copy array from source to destination; return copied size (new dest size)
function fHC_Copy(var d: tFloatArray; var s: tFloatArray): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Copy@@YAHAAUtRealArray@@0@Z'; // copy array from source to destination; return copied size (new dest size)
function fHC_Copy(var d: tXYArray; var s: tXYArray): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Copy@@YAHAAUtXYArray@@0@Z'; // copy array from source to destination; return copied size (new dest size)
function fHC_Copy(var d: tXYZArray; var s: tXYZArray): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Copy@@YAHAAUtXYZArray@@0@Z'; // copy array from source to destination; return copied size (new dest size)
function fHC_Copy(var d: tABCDArray; var s: tABCDArray): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Copy@@YAHAAUtABCDArray@@0@Z'; // copy array from source to destination; return copied size (new dest size)

function fHC_InsertEmpty(var a: tIntArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_InsertEmpty@@YAHAAUtIntArray@@HH@Z'; // insert item; return 0=OK
function fHC_InsertEmpty(var a: tXYIntArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_InsertEmpty@@YAHAAUtXYIntArray@@HH@Z'; // insert item; return 0=OK
function fHC_InsertEmpty(var a: tXYZIntArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_InsertEmpty@@YAHAAUtXYZIntArray@@HH@Z'; // insert item; return 0=OK
function fHC_InsertEmpty(var a: tFloatArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_InsertEmpty@@YAHAAUtRealArray@@HH@Z'; // insert item; return 0=OK
function fHC_InsertEmpty(var a: tXYArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_InsertEmpty@@YAHAAUtXYArray@@HH@Z'; // insert item; return 0=OK
function fHC_InsertEmpty(var a: tXYZArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_InsertEmpty@@YAHAAUtXYZArray@@HH@Z'; // insert item; return 0=OK
function fHC_InsertEmpty(var ar: tABCDArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_InsertEmpty@@YAHAAUtABCDArray@@HH@Z'; // insert item; return 0=OK

function fHC_Insert(var a: tIntArray; idx, count: integer; i: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Insert@@YAHAAUtIntArray@@HHH@Z'; // insert item; return 0=OK
function fHC_Insert(var a: tXYIntArray; idx, count: integer; x, y: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Insert@@YAHAAUtXYIntArray@@HHHH@Z'; // insert item; return 0=OK
function fHC_Insert(var a: tXYZIntArray; idx, count: integer; x, y, z: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Insert@@YAHAAUtXYZIntArray@@HHHHH@Z'; // insert item; return 0=OK
function fHC_Insert(var a: tFloatArray; idx, count: integer; r: float): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Insert@@YAHAAUtRealArray@@HHN@Z'; // insert item; return 0=OK
function fHC_Insert(var a: tXYArray; idx, count: integer; x, y: float): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Insert@@YAHAAUtXYArray@@HHNN@Z'; // insert item; return 0=OK
function fHC_Insert(var a: tXYZArray; idx, count: integer; x, y, z: float): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Insert@@YAHAAUtXYZArray@@HHNNN@Z'; // insert item; return 0=OK
function fHC_Insert(var ar: tABCDArray; idx, count: integer; a, b, c, d: float): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Insert@@YAHAAUtABCDArray@@HHNNNN@Z'; // insert item; return 0=OK

function fHC_Delete(var a: tIntArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Delete@@YAHAAUtIntArray@@HH@Z'; // delete items; return 0=OK
function fHC_Delete(var a: tXYIntArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Delete@@YAHAAUtXYIntArray@@HH@Z'; // delete items; return 0=OK
function fHC_Delete(var a: tXYZIntArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Delete@@YAHAAUtXYZIntArray@@HH@Z'; // delete items; return 0=OK
function fHC_Delete(var a: tFloatArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Delete@@YAHAAUtRealArray@@HH@Z'; // delete items; return 0=OK
function fHC_Delete(var a: tXYArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Delete@@YAHAAUtXYArray@@HH@Z'; // delete items; return 0=OK
function fHC_Delete(var a: tXYZArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Delete@@YAHAAUtXYZArray@@HH@Z'; // delete items; return 0=OK
function fHC_Delete(var a: tABCDArray; idx, count: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Delete@@YAHAAUtABCDArray@@HH@Z'; // delete items; return 0=OK

procedure fHC_Sort(var a: tXYIntArray; key: integer); overload; cdecl; external 'HC.DLL' name '?fHC_Sort@@YAXAAUtXYIntArray@@H@Z'; // sort array, +-1=x, +-2=y, ..., positive-ascending, negative-descending
procedure fHC_Sort(var a: tXYZIntArray; key: integer); overload; cdecl; external 'HC.DLL' name '?fHC_Sort@@YAXAAUtXYZIntArray@@H@Z'; // sort array, +-1=x, +-2=y, ..., positive-ascending, negative-descending
procedure fHC_Sort(var a: tXYArray; key: integer); overload; cdecl; external 'HC.DLL' name '?fHC_Sort@@YAXAAUtXYArray@@H@Z'; // sort array, +-1=x, +-2=y, positive-ascending, negative-descending
procedure fHC_Sort(var a: tXYZArray; key: integer); overload; cdecl; external 'HC.DLL' name '?fHC_Sort@@YAXAAUtXYZArray@@H@Z'; // sort array, +-1=x, +-2=y, ..., positive-ascending, negative-descending
procedure fHC_Sort(var a: tABCDArray; key: integer); overload; cdecl; external 'HC.DLL' name '?fHC_Sort@@YAXAAUtABCDArray@@H@Z'; // sort array, +-1=a, +-2=b, ..., positive-ascending, negative-descending

procedure fHC_FindMinMax(var a: tIntArray; var minV: integer; var maxV: integer); overload; cdecl; external 'HC.DLL' name '?fHC_FindMinMax@@YAXAAUtIntArray@@AAH1@Z';
procedure fHC_FindMinMax(var a: tFloatArray; var minV: float; var maxV: float); overload; cdecl; external 'HC.DLL' name '?fHC_FindMinMax@@YAXAAUtRealArray@@AAN1@Z';

function LinearInterp(x0, x1, x2, y0, y2: float): float; // return (y2-y0)/(x2-x0)*(x1-x0)+y0;
implementation

function fHC_Copy(var d: tMyString; s: string): integer; // copy from source to destination
var
  res, l: integer;
begin
  l:=Length(s);
  res:=fHC_SetLength(d, l);
  result:=res;
  if res>0 then Move(s[1], d.ch[0], l);
  if res>=0 then d.ch[d.length]:=#0;
end;

function LinearInterp(x0, x1, x2, y0, y2: float): float; // return (y2-y0)/(x2-x0)*(x1-x0)+y0;
begin
  result:=(y2-y0)/(x2-x0)*(x1-x0)+y0;
end;

end.

