You are on page 1of 255

unit GeoUtils;

interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, {Controls, }Forms, Dialogs,math,extctrls,Grids,JPEG,printers; CONST TAB=#9 ; maxlayer=20; type realpoint=record x,y:double; end; realarray=array[1..500] of realpoint; str100=String[100]; str200=string[200]; TTicksStyle=(TSinner,TSouter,TSBoth); Trealarray=array[1..1000] of double; TGaxisType=(ATnorm,ATlog); tlinerec=record x1,x2,y1,y2:double; end; TGaxis=class private FTransparent: boolean; FShowLabels: boolean;

FShowMinorgrid: boolean; FShowTitle: boolean; FShowMajorgrid: boolean; FMinimum: double; FMaximum: double; FMinors: double; FMajors: double; FTitle: str100; FFontColor: tcolor; FBkColor: tcolor; FPenColor: tcolor; FMinorsColor: tcolor; FMajorscolor: tcolor; FAxrect: trect; FTicksStyle: TticksStyle; FAxisType: TGAxisType; FCanvas: tcanvas; FLabelsformat: str100; FchartRect: Trect; FREverse: boolean; Fdrawaxisline: boolean; procedure SetAxrect(const Value: trect); procedure SetBkColor(const Value: tcolor); procedure SetFontColor(const Value: tcolor); procedure SetMajors(const Value: double);

procedure SetMajorscolor(const Value: tcolor); procedure SetMaximum(const Value: double); procedure SetMinimum(const Value: double); procedure SetMinors(const Value: double); procedure SetMinorsColor(const Value: tcolor); procedure SetPenColor(const Value: tcolor); procedure SetShowLabels(const Value: boolean); procedure SetShowMajorgrid(const Value: boolean); procedure SetShowMinorgrid(const Value: boolean); procedure SetShowTitle(const Value: boolean); procedure SetTicksStyle(const Value: tTicksStyle); procedure SetTitle(const Value: str100); procedure SetTransparent(const Value: boolean); procedure SetAxisType(const Value: TGAxisType); procedure SetCanvas(const Value: tcanvas); procedure SetLabelsformat(const Value: str100); procedure SetchartRect(const Value: Trect); procedure SetREverse(const Value: boolean); procedure Setdrawaxisline(const Value: boolean); public constructor create; procedure Assign(ax:tgaxis); property PenColor:tcolor read FPenColor write SetPenColor; property FontColor:tcolor read FFontColor write SetFontColor; property BkColor:tcolor read FBkColor write SetBkColor;

property Axrect:trect read FAxrect write SetAxrect; property Majorscolor:tcolor read FMajorscolor write SetMajorscolor; property MinorsColor:tcolor read FMinorsColor write SetMinorsColor; property Minimum:double read FMinimum write SetMinimum; property Maximum:double read FMaximum write SetMaximum; property Majors:double read FMajors write SetMajors; property Minors:double read FMinors write SetMinors; property ShowMajorgrid:boolean read FShowMajorgrid write SetShowMajorgrid; property ShowMinorgrid:boolean read FShowMinorgrid write SetShowMinorgrid; property TicksStyle:TTicksStyle read FTicksStyle write SetTicksStyle; property ShowLabels:boolean read FShowLabels write SetShowLabels; property Title:str100 read FTitle write SetTitle; property ShowTitle:boolean read FShowTitle write SetShowTitle; property Transparent:boolean read FTransparent write SetTransparent; property AxisType:TGaxisType read FAxisType write SetAxisType; Property Canvas:tcanvas read FCanvas write SetCanvas; property Labelsformat:str100 read FLabelsformat write SetLabelsformat; property chartRect:Trect read FchartRect write SetchartRect; property Reverse:boolean read FREverse write SetREverse; property drawaxisline:boolean read Fdrawaxisline write Setdrawaxisline; end;

TGBottomAxis=class(TGaxis) private public

constructor create; procedure draw; procedure PrintAx(aleft,atop,abottom,aright:double); Function Topix(value:double):integer; function Toval(pix:integer):double; end; TGTopAxis=class(TGaxis) private public constructor create; procedure draw; procedure PrintAx(aleft,atop,abottom,aright:double); Function Topix(value:double):integer; function Toval(pix:integer):double; end;

TGleftAxis=class(tgaxis) private public constructor create; procedure draw; procedure PrintAx(aleft,atop,abottom,aright:double); Function Topix(value:double):integer; function Toval(pix:integer):double; end;

TGRightAxis=class(tgaxis) private public constructor create; procedure draw; procedure PrintAx(aleft,atop,abottom,aright:double); Function Topix(value:double):integer; function Toval(pix:integer):double; end; TlabelPos=(Slpup,slpdown,slpleft,slpright); Tsymbol=class private Fx: integer; Fbitmapid: integer; Fsize: integer; Fy: integer; Fcolor: tcolor; Fsrect: trect; Fbitmap: tbitmap; Fselected: boolean; FID: integer; FName: str100; Fshowname: boolean; FTransparentText: boolean; Fspacing: integer;

FLabelPos: TlabelPos; Flabelbkcolor: tcolor; procedure Setcolor(const Value: tcolor); procedure Setid(const Value: integer); procedure Setbitmapid(const Value: integer); procedure Setsize(const Value: integer); procedure Setsrect(const Value: trect); procedure Setx(const Value: integer); procedure Sety(const Value: integer); procedure Setbitmap(const Value: tbitmap); procedure Setselected(const Value: boolean); procedure SetName(const Value: str100); procedure Setshowname(const Value: boolean); procedure SetTransparentText(const Value: boolean); procedure Setspacing(const Value: integer); procedure SetLabelPos(const Value: TlabelPos); procedure Setlabelbkcolor(const Value: tcolor); public constructor create; procedure erase(canvas:tcanvas); procedure draw(canvas:tcanvas); procedure drawselect(canvas:tcanvas;clr:tcolor); Function pointin(x,y:integer):boolean; property color:tcolor read Fcolor write Setcolor; property size:integer read Fsize write Setsize;

property x:integer read Fx write Setx; property y:integer read Fy write Sety; property bitmapid:integer read Fbitmapid write Setbitmapid; property srect:trect read Fsrect write Setsrect; property bitmap:tbitmap read Fbitmap write Setbitmap; property selected:boolean read Fselected write Setselected; property ID:integer read FID write SetID; property Name:str100 read FName write SetName; property showname:boolean read Fshowname write Setshowname; property TransparentText:boolean read FTransparentText write SetTransparentText; property spacing:integer read Fspacing write Setspacing; property LabelPos:TlabelPos read FLabelPos write SetLabelPos; property labelbkcolor:tcolor read Flabelbkcolor write Setlabelbkcolor; end; THorizaxis=(hatop,habottom); tvertaxis=(valeft,varight); TgeoChart = class private Fshowrightaxis: boolean; FShowleftaxis: boolean; Fshowtopaxis: boolean; Fshowbottomaxis: boolean; Fleftmargin: integer; Frightmargin: integer; Fbottommargin: integer;

Ftopmargin: integer; FTitle: str100; Fbordercolor: tcolor; Fbkcolor: tcolor; Fpanelcolor: tcolor; Fchartrect: trect; FBitmap: tbitmap; Fhorizaxis: thorizaxis; Fvertaxis: tvertaxis; Fheight: integer; Fwidth: integer; Fshowbkbitmap: boolean; Fbkbitmap: tbitmap; Ftransparent: boolean; FProportionalXY: boolean; FDrawBorder: boolean; procedure Setbkcolor(const Value: tcolor); procedure Setbordercolor(const Value: tcolor); procedure Setbottommargin(const Value: integer); procedure Setleftmargin(const Value: integer); procedure Setpanelcolor(const Value: tcolor); procedure Setrightmargin(const Value: integer); procedure Setshowbottomaxis(const Value: boolean); procedure SetShowleftaxis(const Value: boolean); procedure Setshowrightaxis(const Value: boolean);

procedure Setshowtopaxis(const Value: boolean); procedure SetTitle(const Value: str100); procedure Settopmargin(const Value: integer); procedure SetBitmap(const Value: tbitmap); procedure Sethorizaxis(const Value: thorizaxis); procedure Setvertaxis(const Value: tvertaxis); procedure Setheight(const Value: integer); procedure Setwidth(const Value: integer); procedure Setbkbitmap(const Value: tbitmap); procedure Setshowbkbitmap(const Value: boolean); procedure setchartrect(arect:trect); procedure Settransparent(const Value: boolean); procedure SetProportionalXY(const Value: boolean); procedure SetDrawBorder(const Value: boolean); { Private declarations } protected { Protected declarations } public { Public declarations } leftaxis:tgleftaxis; rightaxis:tgrightaxis; bottomaxis:tgbottomaxis; topaxis:tgtopaxis; Constructor create; destructor destroy;override;

procedure Draw; procedure printit(aleft,atop,aright,abottom:double); procedure drawtoimage(image:timage); function xtopix(xv:double):integer; function ytopix(yv:double):integer; function pixtox(xp:integer):double; function pixtoy(yp:integer):double; Function XrangeperYrange:double; Function WperH:double; procedure assign(achart:tgeochart); procedure setaxistype(horizaxis,vertaxis:tgaxistype); procedure setallticks(major,minor:integer); procedure setallcolors(borderclr,panelclr,bkclr,fontclr,majorclr,minorclr:tcolor); procedure setminmax(minx,maxx,miny,maxy:double); procedure DrawPoint(canvas:tcanvas;x,y:double); procedure Drawline(canvas:tcanvas;x1,y1,x2,y2:double); procedure DrawSymbol(canvas:tcanvas;x,y:double;var sym:tsymbol); procedure Drawcurve(canvas:tcanvas;N:integer; F: realarray;color:tcolor); procedure loadbkfromfile(fn:str200); property leftmargin:integer read Fleftmargin write Setleftmargin; property topmargin:integer read Ftopmargin write Settopmargin; property bottommargin:integer read Fbottommargin write Setbottommargin; property rightmargin:integer read Frightmargin write Setrightmargin; property chartrect:trect read Fchartrect write setchartrect; property Showleftaxis:boolean read FShowleftaxis write SetShowleftaxis;

property showrightaxis:boolean read Fshowrightaxis write Setshowrightaxis; property showtopaxis:boolean read Fshowtopaxis write Setshowtopaxis; property showbottomaxis:boolean read Fshowbottomaxis write Setshowbottomaxis; property panelcolor:tcolor read Fpanelcolor write Setpanelcolor; property bkcolor:tcolor read Fbkcolor write Setbkcolor; property bordercolor:tcolor read Fbordercolor write Setbordercolor; property Title:str100 read FTitle write SetTitle; property Bitmap:tbitmap read FBitmap write SetBitmap; property vertaxis:tvertaxis read Fvertaxis write Setvertaxis; property horizaxis:thorizaxis read Fhorizaxis write Sethorizaxis; property width:integer read Fwidth write Setwidth; property height:integer read Fheight write Setheight; property bkbitmap:tbitmap read Fbkbitmap write Setbkbitmap; property showbkbitmap:boolean read Fshowbkbitmap write Setshowbkbitmap; property transparent:boolean read Ftransparent write Settransparent; property ProportionalXY:boolean read FProportionalXY write SetProportionalXY; property DrawBorder:boolean read FDrawBorder write SetDrawBorder; end;

TGline=class private Fwidth: byte; Fy1: integer; Fx2: integer; Fx1: integer;

Fstyle: tpenstyle; Fy2: integer; Fcolor: tcolor; Fselected: boolean;

procedure Setstyle(const Value: tpenstyle); procedure Setwidth(const Value: byte); procedure Setx1(const Value: integer); procedure Setx2(const Value: integer); procedure Sety1(const Value: integer); procedure Setcolor(const Value: tcolor); procedure Sety2(const Value: integer); procedure Setselected(const Value: boolean); public

constructor create; procedure Draw(canvas:tcanvas;penmode:tpenmode); function pointin(x,y:integer):boolean; property x1:integer read Fx1 write Setx1; property x2:integer read Fx2 write Setx2; property y1:integer read Fy1 write Sety1; property y2:integer read Fy2 write Sety2; property color:tcolor read Fcolor write Setcolor; property width:byte read Fwidth write Setwidth; property style:tpenstyle read Fstyle write Setstyle;

property selected:boolean read Fselected write Setselected; end; Tglinearray=array[1..2000] of tgline; Tgpoly = class private FID: str100; Fvisible: boolean; fnumV:integer; Fmodefied: boolean;

procedure SetID(const Value: str100); procedure Setvisible(const Value: boolean); procedure SetNumV(const Value: integer); procedure Setmodefied(const Value: boolean); public vertex:tglinearray;

constructor create; destructor destroy; override; procedure Setcolors(color:tcolor); procedure setwidths(W:byte); procedure setpenstyle(penstyle:tpenstyle); procedure Drawline(canvas:tcanvas); procedure Drawarea(canvas:tcanvas); procedure add(vrtx:tgline);

function pointin(x,y:integer;var idx:integer):boolean; property ID:str100 read FID write SetID; property visible:boolean read Fvisible write Setvisible; property numV:integer read fnumv write setnumv; property modefied:boolean read Fmodefied write Setmodefied; end;

Tgpolyarray=array[1..100] of tgpoly;

TgrealLine=class private Fselected: boolean; Fwidth: byte; Fy2: double; Fy1: double; Fx1: double; Fx2: double; Fcolor: tcolor; Fstyle: tpenstyle; Fchart: tgeochart; procedure Setcolor(const Value: tcolor); procedure Setselected(const Value: boolean); procedure Setstyle(const Value: tpenstyle); procedure Setwidth(const Value: byte); procedure Setx1(const Value: double);

procedure Setx2(const Value: double); procedure Sety1(const Value: double); procedure Sety2(const Value: double); procedure Setchart(const Value: tgeochart);

public

constructor create; procedure Draw(canvas:tcanvas;penmode:tpenmode); function mousein(x,y:integer):boolean; function inside:boolean; property x1:double read Fx1 write Setx1; property x2:double read Fx2 write Setx2; property y1:double read Fy1 write Sety1; property y2:double read Fy2 write Sety2; property color:tcolor read Fcolor write Setcolor; property width:byte read Fwidth write Setwidth; property style:tpenstyle read Fstyle write Setstyle; property selected:boolean read Fselected write Setselected; property chart:tgeochart read Fchart write Setchart; end;

tgReallinearray=array[1..500] of tgrealline;

Tgrealpoly = class

private Fvisible: boolean; Fmodefied: boolean; FnumV: integer; FID: str100; Fchart: tgeochart; procedure SetID(const Value: str100); procedure Setmodefied(const Value: boolean); procedure SetnumV(const Value: integer); procedure Setvisible(const Value: boolean); procedure Setchart(const Value: tgeochart); public vertex:tgReallinearray; constructor create; destructor destroy; override; procedure Setcolors(color:tcolor); procedure setwidths(W:byte); procedure setpenstyle(penstyle:tpenstyle); procedure Drawline(canvas:tcanvas); procedure Drawarea(canvas:tcanvas); procedure Drawlineat(acanvas:tcanvas;grf:tgeochart); procedure Drawareaat(acanvas:tcanvas;grf:tgeochart); procedure add(vrtx:tgrealline); function mousein(x,y:integer;var idx:integer):boolean; property ID:str100 read FID write SetID;

property visible:boolean read Fvisible write Setvisible; property numV:integer read FnumV write SetnumV; property modefied:boolean read Fmodefied write Setmodefied; property chart:tgeochart read Fchart write Setchart; end;

Tgrealpolyarray=array[1..200] of tgrealpoly; tarraytype=(schlumberger,wenner,Dipole); TVespoint=record ab2,rho:double; end; TVespoints=array[1..100] of tvespoint; TRmodel=record n:integer; H,rho:array[1..maxlayer] of double; end; Tves=class private FX: double; Fz: double; Fy: double; FDirection: integer; FStation_No: str100; FNumpoints: integer; Flocation: str100;

Fproject: str100; Foperator: str100; Fequip: str100; FArraytype: tarraytype; FDipolelength: double; FRemarks: str200; FMDate: str100; FVisible: boolean; Fchart: tgeochart; Fshowmodel: boolean; Fshowpoints: boolean; Fmodellinewidth: byte; Fmodellineclr: tcolor; procedure SetArraytype(const Value: tarraytype); procedure SetmDate(const Value: str100); procedure SetDirection(const Value: integer); procedure Setequip(const Value: str100); procedure Setlocation(const Value: str100); procedure SetNumpoints(const Value: integer); procedure Setoperator(const Value: str100); procedure Setproject(const Value: str100); procedure SetStation_No(const Value: str100); procedure SetX(const Value: double); procedure Sety(const Value: double); procedure Setz(const Value: double);

procedure SetDipolelength(const Value: double); procedure SetRemarks(const Value: str200); procedure SetVisible(const Value: boolean); procedure Setchart(const Value: tgeochart); procedure Setshowpoints(const Value: boolean); procedure Setshowmodel(const Value: boolean); procedure Setmodellineclr(const Value: tcolor); procedure Setmodellinewidth(const Value: byte);

public points:tvespoints; Symbol,Sympoint:tsymbol; Model:TRmodel; constructor create; destructor destroy;override; procedure resetVES; procedure loadfromfile(fn:str200); procedure savetofile(fn:str200); procedure assign(vs:tves); procedure printit(aLeft, atop, aright, abottom: double;addmodel:boolean); procedure autoab(np:integer); procedure draw(canvas:tcanvas); procedure drawmodel(image:timage); function mouseonH(x,y:integer;var idx:integer):boolean; function mouseonR(x,y:integer;var idx:integer):boolean;

function getDepth(idx:integer):double; function mouseonpoint(x,y:integer;var idx:integer):boolean; property Arraytype:tarraytype read FArraytype write SetArraytype; property Station_No:str100 read FStation_No write SetStation_No; property Direction:integer read FDirection write SetDirection; property project:str100 read Fproject write Setproject; property location:str100 read Flocation write Setlocation; property operator:str100 read Foperator write Setoperator; property equip:str100 read Fequip write Setequip; property MDate:str100 read FMDate write SetMDate; property Remarks:str200 read FRemarks write SetRemarks; property X:double read FX write SetX; property y:double read Fy write Sety; property z:double read Fz write Setz; property Numpoints:integer read FNumpoints write SetNumpoints; property Dipolelength:double read FDipolelength write SetDipolelength; property Visible:boolean read FVisible write SetVisible; property chart:tgeochart read Fchart write Setchart; property showmodel:boolean read Fshowmodel write Setshowmodel; property showpoints:boolean read Fshowpoints write Setshowpoints; property modellineclr:tcolor read Fmodellineclr write Setmodellineclr; property modellinewidth:byte read Fmodellinewidth write Setmodellinewidth; end;

TvesArray=array[1..2000]of tves;

tindexarray=array[0..2000] of integer;

Tvesproject=class private Fnumves: integer; Fprofileselected: boolean; Fpronumves: integer; Fdrawprofileline: boolean; FNumprofiles: integer; Fchart: tgeochart; FshowDir: boolean; Fshowlabels: boolean; Flineclr: tcolor; FSelectedID: integer; procedure Setnumves(const Value: integer); procedure Setprofileselected(const Value: boolean); procedure Setpronumves(const Value: integer); procedure Setdrawprofileline(const Value: boolean); procedure SetNumprofiles(const Value: integer); procedure Setchart(const Value: tgeochart); procedure SetshowDir(const Value: boolean); procedure Setlineclr(const Value: tcolor); procedure Setshowlabels(const Value: boolean); procedure SetSelectedID(const Value: integer); public

VES:tvesarray; map,prochart:tgeochart; proindexes:tindexarray; profiles:tgrealpolyarray; constructor create; destructor destroy;override; procedure loadfromlist(files:tstrings); procedure printmap(aleft,atop,aright,abottom:double); procedure printprofile(aleft,atop,aright,abottom:double); procedure savetofile(fn:str200); procedure loadfromfile(fn:str200); procedure DeleteVes(id:integer); procedure insertVES(id:integer;vs:tves); procedure crossSection(fn:str200;topo:boolean); procedure GeoSect(fn:str200;topo:boolean) ; procedure Sectioninfo(fn:str200;topo:boolean); procedure vesloc(fn:str200;topo:boolean); procedure inhomo(fn:str200;topo:boolean); procedure blnkingfile(fn:str200;topo:boolean); procedure Draw(var image:timage); procedure Drawprofiles(var image:timage); procedure initprofiles; procedure autominmaxX; procedure autominmaxY; property numves:integer read Fnumves write Setnumves;

property profileselected:boolean read Fprofileselected write Setprofileselected; property drawprofileline:boolean read Fdrawprofileline write Setdrawprofileline; property pronumves:integer read Fpronumves write Setpronumves; property Numprofiles:integer read FNumprofiles write SetNumprofiles; property chart:tgeochart read Fchart write Setchart; property showDir:boolean read FshowDir write SetshowDir; property lineclr:tcolor read Flineclr write Setlineclr; property showlabels:boolean read Fshowlabels write Setshowlabels; property SelectedID:integer read FSelectedID write SetSelectedID; end; Tlayer=record depth:double; spacing:integer; showname:boolean; end; Tlayers=array[1..20] of Tlayer; Tvesinfo=record id:integer; name:string[50]; x,z1,z2:double; nlayer:integer; layers:tlayers; showname:boolean; end; Tvesinfoarray=array[1..10] of tvesinfo;

Tinhomo=record x,z,rho:double; visible:boolean; end; Tinhomos=array[1..500] of tinhomo; TVesSection =class private Fdrawdepthline: boolean; Fdrawlayers: boolean; Fdrawinhomos: boolean; FDrawvesline: boolean; Fnves: integer; Fnuminhomos: integer; Fhloaded: boolean; Finfoloaded: boolean; Fshowx: boolean; procedure Setdrawdepthline(const Value: boolean); procedure Setdrawinhomos(const Value: boolean); procedure Setdrawlayers(const Value: boolean); procedure SetDrawvesline(const Value: boolean); procedure Setnuminhomos(const Value: integer); procedure Setnves(const Value: integer); procedure Sethloaded(const Value: boolean); procedure Setinfoloaded(const Value: boolean); procedure Setshowx(const Value: boolean);

public vesproject:tvesproject; chart:tgeochart; vesinfo:tvesinfoarray; inhomos:tinhomos; vsym,isym,lsym:tsymbol; constructor create; destructor destroy;override; procedure loadinfo(infofile:str200); procedure loadinhomo(homofile:str200); procedure Draw(image:timage); procedure printit(aleft,atop,aright,abottom:double); function layerselected(x,y:integer;var Vidx:integer; var lidx:integer):boolean; function VesSelected(x,y:integer;var Vidx:integer):boolean; function inhomoselected(x,y:integer;var Vidx:integer):boolean; property nves:integer read Fnves write Setnves; property numinhomos:integer read Fnuminhomos write Setnuminhomos; property drawdepthline:boolean read Fdrawdepthline write Setdrawdepthline; property Drawvesline:boolean read FDrawvesline write SetDrawvesline; property drawinhomos:boolean read Fdrawinhomos write Setdrawinhomos; property drawlayers:boolean read Fdrawlayers write Setdrawlayers; property hloaded:boolean read Fhloaded write Sethloaded; property infoloaded:boolean read Finfoloaded write Setinfoloaded; property showx:boolean read Fshowx write Setshowx; end;

TStringGridHack = class(TStringGrid) protected public procedure DeleteRow(ARow: Longint); reintroduce; procedure InsertRow(ARow: Longint); end;

// tptinterop TprinterOp=class private Fscalingy: double; FscalingX: double;

function GetPixelsPerInchY: Integer; function GetPixelsPerInchX: Integer; function GetPageOffsetBottom: Integer; function GetPageOffsetTop: Integer; function GetPageOffsetRight: Integer; function GetPageOffsetLeft: Integer; function GetPageHeight: Integer; function GetPageWidth: Integer; procedure SetscalingX(const Value: double); procedure Setscalingy(const Value: double);

public chart:tgeochart; constructor create; function CmtopixelsX(cm:double):integer; function CmtopixelsY(cm:double):integer; function IntopixelsX(inches:double):integer; function IntopixelsY(inches:double):integer; function PixelstocmX(px:integer):double; function PixelstocmY(py:integer):double; function pixelstoInX(px:integer):double; function pixelstoInY(py:integer):double; property PixelsPerInchY: Integer read GetPixelsPerInchY; property PixelsPerInchX: Integer read GetPixelsPerInchX; property PageOffsetBottom: Integer read GetPageOffsetBottom; property PageOffsetTop: Integer read GetPageOffsetTop; property PageOffsetRight: Integer read GetPageOffsetRight; property PageOffsetLeft: Integer read GetPageOffsetLeft; property PageHeight: Integer read GetPageHeight; property PageWidth: Integer read GetPageWidth; property scalingX:double read FscalingX write SetscalingX; property scalingy:double read Fscalingy write Setscalingy; end; function V2P(v,min,max:double;minp,maxp:integer;rev:boolean):integer; function P2V(p:integer;min,max:double;minp,maxp:integer;rev:boolean):double; procedure textoutan(Canvas: TCanvas; X, Y, Angle: Integer; Text: string);

function logV2P(v,min,max:double;minp,maxp:integer;rev:boolean):integer; function logP2V(p:integer;min,max:double;minp,maxp:integer;rev:boolean):double; function intersect(l1,l2:tlinerec;var x:double;var y:double):boolean; Function Jpeg2Bitmap(JPEGFile : String) : TBitmap; Function distance(x1,y1,x2,y2:double):double; function interpol(n:integer;xv:double;P:realarray;order:integer ):double; function CursorOnLine(X, Y, x1, y1, x2, y2, d: Integer): Boolean; function mtop(millimeter: integer) : integer; procedure DeleteRow(yourStringGrid: TStringGrid; ARow: Integer); procedure DeleteCel(yourStringGrid: TStringGrid;acol, ARow: Integer); Function ScreenCmtop(cm:double):integer; Function Screenintop(inches:double):integer; function screenPtocm(px:integer):double; function screenPtoin(px:integer):double; implementation

function ScreenCmtop(cm: double): integer; begin result:=round(cm*screen.PixelsPerInch/2.54); end;

function Screenintop(inches: double): integer; begin

result:=round(inches*screen.PixelsPerInch); end;

function screenPtocm(px: integer): double; begin result:=(px*2.54)/screen.PixelsPerInch; end;

function screenPtoin(px: integer): double; begin result:=px/screen.PixelsPerInch; end;

procedure DeleteRow(yourStringGrid: TStringGrid; ARow: Integer); var i, j: Integer; begin with yourStringGrid do begin for i := ARow to RowCount-2 do for j := 1 to ColCount-1 do Cells[j, i] := Cells[j, i+1]; RowCount := RowCount - 1 end; end; procedure DeleteCel(yourStringGrid: TStringGrid;acol, ARow: Integer);

var i: Integer; begin with yourStringGrid do begin for i := ARow to RowCount-2 do Cells[acol, i] := Cells[acol, i+1];

end; end;

//============================================================ function mtop(millimeter: integer) : integer; function GetLogPixelsX : integer; var i1 : integer; begin i1:=CreateCompatibleDC(0); result:=GetDeviceCaps(i1,LogPixelsX); DeleteDC(i1); end; begin result:=round(GetLogPixelsX*millimeter/254); end;

//============================================================

function CursorOnLine(X, Y, x1, y1, x2, y2, d: Integer): Boolean; var sine, cosinus: Double; dx, dy, len: Integer; begin if d = 0 then d := 1; asm fild(y2) fisub(y1) // Y-Difference fild(x2) fisub(x1) // X-Difference fpatan // Angle of the line in st(0) fsincos // Cosinus in st(0), Sinus in st(1) fstp cosinus fstp sine end; dx := Round(cosinus * (x - x1) + sine * (y - y1)); dy := Round(cosinus * (y - y1) - sine * (x - x1)); len := Round(cosinus * (x2 - x1) + sine * (y2 - y1)); // length of line if (dy > -d) and (dy < d) and (dx > -d) and (dx < len + d) then Result := True else Result := False; end;

//============================================================ function interpol(n:integer;xv:double;P:realarray;order:integer ):double; var i,j,k:integer;

s,e:integer; sum,pp:double; begin

if inrange(xv,p[1].x,p[n].x) then begin k:=1; for i:=2 to n do if inrange(xv,p[i-1].x,p[i].x) then begin k:=i; continue; end;

if order>n div 2 then begin s:=1; e:=n; end else

begin if k<=order then begin s:=1; e:=2*k-1; if e<order then e:=order; end else if k >n-order then begin s:= k-(n-k); if s> n-order then s:=n-order; e:=n; end else begin s:=k-order; e:=k+order; end;

end; sum:=0; for i:=s to e do begin pp:=1; for j:=s to e do if j<>i then

pp:=pp*(xv-p[j].x)/(p[i].x-p[j].x); sum:=sum+pp*p[i].y; end; result:=sum; end else begin raise exception.Create('point outside the range of x'); end; end; //============================================================ Function distance(x1,y1,x2,y2:double):double; var xx:double; begin xx:=sqrt(Sqr(x2 -x1)+sqr( y2 - y1)); result:=xx; end; //============================================================

Function Jpeg2Bitmap(JPEGFile : String) : TBitmap; var oJPEG : TJPEGImage; aFormat : Word; aData : THandle;

aPalette : HPALETTE; begin oJPEG := TJPEGImage.Create ; oJPEG.LoadFromFile(JPEGFile); oJPEG.SaveToClipboardFormat(aFormat,aData,aPalette); oJPEG.Free;

Result := TBitmap.Create; Result.LoadFromClipboardFormat(aFormat,aData,aPalette); end;

//============================================================ function intersect(l1,l2:tlinerec;var x:double;var y:double):boolean; var a1,a2,b1,b2:double; xm,ym:double; inrange:boolean; begin

a1:=(l1.y2-l1.y1)/(l1.x2-l1.x1); b1:=l1.y1-a1*l1.x1;

a2:=(l2.y2-l2.y1)/(l2.x2-l2.x1); b2:=l2.y1-a2*l2.x1;

if a1=a2 then begin result:=false; exit; end; xm:=(b2-b1)/(a1-a2); ym:=a1*xm+b1; x:=xm;y:=ym; if (xm>=l1.x1) and(xm<=l1.x2) and (xm>=l2.x1) and(xm<=l2.x2) then inrange:=true else inrange:=false; result:=inrange; end;

//============================================================ function logV2P(v,min,max:double;minp,maxp:integer;rev:boolean):integer; var a,b,c:double; px:integer; begin a:=log10(v/min); b:=maxp-minp; c:=log10(max/min); px:=round((a*b)/c); if rev then

px:=maxp-px else px:=minp+px; result:=px; end; //============================================================== function logP2V(p:integer;min,max:double;minp,maxp:integer;rev:boolean):double; var a,b,c:double; begin c:=log10(min); if rev then a:=maxp-p else a:=p-minp; a:=a*log10(max/min); b:=maxp-minp; c:=c+a/b; result:=power(10,c); end;

//============================================================

procedure TStringGridHack.DeleteRow(ARow: Longint);

var GemRow: Integer; begin GemRow := aRow; if RowCount > FixedRows + 1 then inherited DeleteRow(ARow) else Rows[ARow].Clear; if GemRow < RowCount then Row := GemRow; end; procedure TStringGridHack.InsertRow(ARow: Longint); var GemRow: Integer; begin GemRow := Row; while ARow < FixedRows do Inc(ARow); RowCount := RowCount + 1; MoveRow(RowCount - 1, ARow); Row := GemRow; Rows[Row].Clear; end;

{procedure TForm1.Button1Click(Sender: TObject); begin // Insert Row, Zeile hinzufgen

TStringGridHack(StringGrid1).InsertRow(1); // Remove Row, Zeile entfernen TStringGridHack(StringGrid1).DeleteRow(2); end; end.}

function CreateAngledFont(Font: HFont; Angle: Longint; Quality: byte = PROOF_QUALITY): HFont;

var FontInfo: TLogFontA; // Font information structure begin // Get the information of the font passed as parameter if GetObject(Font, SizeOf(FontInfo), @FontInfo) = 0 then begin Result := 0; exit; end; // Set the angle FontInfo.lfEscapement := Angle*10; FontInfo.lfOrientation := Angle*10; // Set the quality FontInfo.lfQuality := Quality;

// Create a new font with the modified information // The new font must be released calling DeleteObject Result := CreateFontIndirect(FontInfo); end; {========================================================================} procedure textoutan(Canvas: TCanvas; X, Y, Angle: Integer; Text: string); var OriginalFont, AngledFont: HFont; begin // Create an angled font from the current font canvas.Font.Name:='arial'; AngledFont := CreateAngledFont(Canvas.Font.Handle, Angle); if AngledFont <> 0 then begin // Set it temporarily as the current font OriginalFont := SelectObject(Canvas.Handle, AngledFont); if OriginalFont <> 0 then begin

Canvas.TextOut(X, Y, Text); // Write the text

if SelectObject(Canvas.Handle, OriginalFont)=0 then //Restore the orig. font begin Canvas.Font.Handle := AngledFont; raise Exception.Create('Couldn''t restore font'); exit;

end; end; // Release the angled font DeleteObject(AngledFont) end; end; {=======================value to pixel===================================}

function V2P(v,min,max:double;minp,maxp:integer;rev:boolean):integer; var prange,pxl:integer; vrange,vp:double; begin prange:= maxp-minp; vrange:=max-min; if vrange=0 then vrange:=1; if rev then vp:=max-v else vp:=v-min; pxl:=round(minp+vp*(prange/vrange)); result:=pxl; end; {====================pixel to value======================================} function P2V(p:integer;min,max:double;minp,maxp:integer;rev:boolean):double; var prange,pxl:integer;

vrange,vp:double; begin prange:= maxp-minp; if prange=0 then prange:=1; vrange:=max-min; if rev then pxl:=maxp-p else pxl:=p-minp; vp:=round(min+pxl*(vrange/prange)); result:=vp; end;

procedure TGaxis.Assign(ax: tgaxis); begin fdrawaxisline := ax.drawaxisline; FTransparent := ax.Transparent; FShowLabels := ax.ShowLabels; FShowMinorgrid:= ax.ShowMinorgrid; FShowTitle := ax.ShowTitle; FShowMajorgrid:= ax.ShowMajorgrid; FMinimum FMaximum FMinors FMajors FTitle := ax.Minimum ; := ax.Maximum ; := ax.Minors; := ax.Majors; := ax.Title ;

FFontColor := ax.FontColor;

FBkColor FPenColor

:= ax.BkColor ; := ax.PenColor;

FMinorsColor := ax.MinorsColor; FMajorscolor := ax.Majorscolor; FAxrect := ax.Axrect;

FTicksStyle := ax.TicksStyle; FAxisType := ax.AxisType;

fcanvas:=ax.Canvas; end;

constructor TGaxis.create; begin inherited create; fdrawaxisline:=true; FTransparent:= False; FShowLabels:= True; FShowMinorgrid:= True; FShowTitle:= true; FShowMajorgrid:= True; FMinimum:= 0; FMaximum:= 100; FMinors:= 5; FMajors:= 10; FTitle:= 'Axis'; FFontColor:= Clblue;

FBkColor:= Clwhite; FPenColor:= CLblack; FMinorsColor:= Clgreen; FMajorscolor:= Clblue; FAxrect:= Rect(0,0,50,50); FTicksStyle:= TSBoth; FAxisType:=atnorm; Flabelsformat:='0.###'; end;

procedure TGaxis.SetAxisType(const Value: TGaxisType); begin FAxisType := Value; end;

procedure TGaxis.SetAxrect(const Value: trect); begin FAxrect := Value; end;

procedure TGaxis.SetBkColor(const Value: tcolor); begin FBkColor := Value;

end;

procedure TGaxis.SetCanvas(const Value: tcanvas); begin FCanvas := Value; end;

procedure TGaxis.SetchartRect(const Value: Trect); begin FchartRect := Value; end;

procedure TGaxis.Setdrawaxisline(const Value: boolean); begin Fdrawaxisline := Value; end;

procedure TGaxis.SetFontColor(const Value: tcolor); begin FFontColor := Value; end;

procedure TGaxis.SetLabelsformat(const Value: str100); begin FLabelsformat := Value;

end;

procedure TGaxis.SetMajors(const Value: double); begin FMajors := Value; end;

procedure TGaxis.SetMajorscolor(const Value: tcolor); begin FMajorscolor := Value; end;

procedure TGaxis.SetMaximum(const Value: double); begin FMaximum := Value; end;

procedure TGaxis.SetMinimum(const Value: double); begin FMinimum := Value; end;

procedure TGaxis.SetMinors(const Value: double); begin FMinors := Value;

end;

procedure TGaxis.SetMinorsColor(const Value: tcolor); begin FMinorsColor := Value; end;

procedure TGaxis.SetPenColor(const Value: tcolor); begin FPenColor := Value; end;

procedure TGaxis.SetREverse(const Value: boolean); begin FREverse := Value; end;

procedure TGaxis.SetShowLabels(const Value: boolean); begin FShowLabels := Value; end;

procedure TGaxis.SetShowMajorgrid(const Value: boolean); begin FShowMajorgrid := Value;

end;

procedure TGaxis.SetShowMinorgrid(const Value: boolean); begin FShowMinorgrid := Value; end;

procedure TGaxis.SetShowTitle(const Value: boolean); begin FShowTitle := Value; end;

procedure TGaxis.SetTicksStyle(const Value: tTicksStyle); begin FTicksStyle := Value; end;

procedure TGaxis.SetTitle(const Value: str100); begin FTitle := Value; end;

procedure TGaxis.SetTransparent(const Value: boolean);

begin FTransparent := Value; end;

{ TGhorizAxis }

constructor TGBottomAxis.create; begin inherited create; end;

procedure TGBottomAxis.draw; var tx,ty:integer; labels:string[100]; p:integer; dd:double; exp1,exp2,node,delta,i,x,xx,j:integer; minorsarray:array[2..9]of integer; x1,x2,y1,y2,tickslength:integer; begin fcanvas.brush.color:=bkcolor; fcanvas.pen.Color:=fpencolor; fcanvas.Font.Color:=fFontcolor; //tickslength:=(faxrect.bottom-faxrect.Top) div 2;

tickslength:=fcanvas.TextHeight('0'); x1:=Faxrect.left; x2:=Faxrect.Right; y1:=(faxrect.bottom+faxrect.Top) div 2; y2:=y1+tickslength+fcanvas.TextHeight('0')+3; if fdrawaxisline then begin fcanvas. moveto(x1,y1); fcanvas.lineto(x2,y1); end; // responsing to axis type logarithmic or normal axis if faxistype= atlog then begin fcanvas.brush.Style:=bsclear; if fminimum=0 then fminimum:=0.1; exp1:=round(log10(fminimum)); exp2:=round(log10(fmaximum)); fminimum:=power(10,exp1); fmaximum:=power(10,exp2);

node:=exp2-exp1; delta:=round((x2-x1)/node); for i:=2 to 9 do minorsarray[i]:=round(log10(i)*delta); for i:=1 to node do

begin if freverse then x:=x2-(i-1)*delta else x:=x1+(i-1)*delta; if i>1 then begin fcanvas.Pen.Color:=fmajorscolor; case ticksStyle of TSinner:begin fcanvas.MoveTo(x,y1); fcanvas.LineTo(x ,y1-tickslength); end; tsouter:begin fcanvas.MoveTo(x,y1); fcanvas.LineTo(x,y1+tickslength); end; Tsboth:begin fcanvas.MoveTo(x,y1); fcanvas.LineTo(x,y1-tickslength); fcanvas.MoveTo(x,y1); fcanvas.LineTo(x,y1+tickslength); end; end;

if Fshowmajorgrid then begin

Fcanvas.Pen.Style:=psSolid; fcanvas.MoveTo(x,fchartrect.top); fcanvas.LineTo(x,fchartrect.bottom); Fcanvas.Pen.Style:=psSolid; end; if fshowlabels then begin labels:=formatfloat(flabelsformat,fminimum*power(10,i-1)); ty:=y1+tickslength+2 ; tx:=x-canvas.Textwidth(labels) div 2; fcanvas.TextOut(tx,ty,labels); end; end; //--------------------fcanvas.Pen.Color:=fminorscolor; if fminors =1 then begin if freverse then xx:=x-minorsarray[5] else xx:=x+minorsarray[5]; case ticksStyle of TSinner:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1- tickslength div 2) end;

tsouter:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1+ tickslength div 2); end; Tsboth:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1+ tickslength div 2); fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1- tickslength div 2) end; end;//case if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot; fcanvas.MoveTo(xx,fchartrect.top); fcanvas.LineTo(xx,fchartrect.bottom); Fcanvas.Pen.Style:=psSolid; end;// grid end else if fminors= 4 then begin for j:=1 to 4 do begin if freverse then xx:=x-minorsarray[j*2] else xx:=x+minorsarray[j*2];

case ticksStyle of TSinner:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1- tickslength div 2) end; tsouter:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1+ tickslength div 2); end; Tsboth:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1+ tickslength div 2); fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1- tickslength div 2) end; end;//case if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot; fcanvas.MoveTo(xx,fchartrect.top); fcanvas.LineTo(xx,fchartrect.bottom); Fcanvas.Pen.Style:=psSolid; end;// grid end; end else begin

for j:=2 to 9 do begin if freverse then xx:=x-minorsarray[j] else xx:=x+minorsarray[j]; case ticksStyle of TSinner:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1- tickslength div 2) end; tsouter:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1+ tickslength div 2); end; Tsboth:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1+ tickslength div 2); fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1- tickslength div 2) end; end; if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot; fcanvas.MoveTo(xx,fchartrect.top);

fcanvas.LineTo(xx,fchartrect.bottom); Fcanvas.Pen.Style:=psSolid; end;// grid

end; // for end; // case else

end;// for i //=============== fcanvas.Brush.Style:=bsclear; if Fshowtitle then begin ty:=y1+fcanvas.textheight('0')+tickslength+2; tx:=((x2+x1) div 2)- fcanvas.textwidth(ftitle)div 2 ; fcanvas.TextOut(tx,ty,ftitle); end;

end else begin // ------ minor ticks ----fcanvas.Pen.Color:=fminorscolor; dd:=round(fminimum / fminors); dd:=fminors*dd; fcanvas.brush.Style:=bsclear; if dd < fminimum then dd:=dd+fminors;

while dd < fmaximum do begin p:=v2p(dd,fminimum,fmaximum,x1,x2,freverse); if (dd>fminimum) and (dd < maximum) then case ticksStyle of TSinner:begin fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1- tickslength div 2); end; tsouter:begin fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1+ tickslength div 2); end; Tsboth:begin fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1+ tickslength div 2); fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1- tickslength div 2); end; end; if FShowminorgrid then begin Fcanvas.Pen.Style:=psDot; fcanvas.Brush.Style:=bsclear; fcanvas.MoveTo(p,fchartrect.top); fcanvas.LineTo(p,fchartrect.bottom);

Fcanvas.Pen.Style:=psSolid; end; dd:=dd+fminors; end;

fcanvas.brush.Style:=bsclear; if fshowtitle then begin tx:=((x2+x1) div 2)- (fcanvas.textwidth(ftitle)div 2); ty:=y2+2; fcanvas.TextOut(tx,ty,ftitle); end; // ----- major ticks ----dd:=round(fminimum / fmajors); dd:=fmajors*dd; fcanvas.Pen.Color:=fmajorscolor; if dd < fminimum then dd:=dd+fmajors; ty:=y1+ tickslength+2; while dd < fmaximum do begin p:=v2p(dd,fminimum,fmaximum,x1,x2,freverse); if (dd>fminimum) and (dd < maximum) then case ticksStyle of TSinner:begin fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1- tickslength);

end; tsouter:begin fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1+ tickslength); end; Tsboth:begin fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1+ tickslength); fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1- tickslength); end; end;

if FShowmajorgrid then begin Fcanvas.Pen.Style:=psSolid; fcanvas.Brush.Style:=bsclear; fcanvas.MoveTo(p,fchartrect.top); fcanvas.LineTo(p,fchartrect.bottom); Fcanvas.Pen.Style:=psSolid; end; if fshowlabels then begin labels:= formatfloat( labelsformat,dd); tx:=p-fcanvas.TextWidth(labels) div 2; if (dd>fminimum) and (dd < maximum) then fcanvas.TextOut(tx,ty,labels);

end; dd:=dd+fmajors; end; end;// if axis type end;

procedure TGBottomAxis.PrintAx(aleft,atop,abottom,aright:double); var oldR:trect; po:tprinterop; oldcanvas:tcanvas; begin oldR:=Faxrect; oldcanvas:=fcanvas; po:=tprinterop.create; try faxrect.Left:=po.CmtopixelsX(aLeft); faxrect.Right:=po.CmtopixelsX(aRight); faxrect.Top:=po.CmtopixelsY(aTop)+ 2*printer.Canvas.TextHeight('0') ; faxrect.bottom:=po.CmtopixelsY(aBottom); fcanvas:=printer.Canvas; draw; fcanvas.Rectangle(faxrect); finally Faxrect:=oldR;

fcanvas:=oldcanvas; freeandnil(po); end;

end;

function TGBottomAxis.Topix(value: double): integer; begin if faxistype= atlog then result:=logv2p(value,fminimum,fmaximum,fchartrect.left,fchartrect.right,freverse) else result:=v2p(value,fminimum,fmaximum,fchartrect.left,fchartrect.right,freverse); end;

function TGBottomAxis.Toval(pix: integer): double; begin if faxistype= atlog then result:=logp2v(pix,fminimum,fmaximum,fchartrect.left,fchartrect.right,freverse) else result:=p2v(pix,fminimum,fmaximum,fchartrect.left,fchartrect.right,freverse); end;

{ TGTopAxis }

constructor TGTopAxis.create;

begin inherited create; end;

procedure TGTopAxis.draw; var tx,ty:integer; labels:string[100]; p:integer; dd:double; x1,x2,y1,tickslength:integer; exp1,exp2,node,delta,i,x,xx,j:integer; minorsarray:array[2..9]of integer; begin fcanvas.brush.color:=bkcolor; fcanvas.pen.Color:=fpencolor; fcanvas.Font.Color:=fFontcolor; //tickslength:=(faxrect.bottom-faxrect.Top) div 2; tickslength:=fcanvas.TextHeight('0'); x1:=Faxrect.left; x2:=Faxrect.Right; y1:=(faxrect.bottom+faxrect.Top) div 2; //y2:=y1+tickslength+fcanvas.TextHeight('0')+3; if fdrawaxisline then begin fcanvas. moveto(x1,y1);

fcanvas.lineto(x2,y1); end; if faxistype = atlog then begin

//=================== fcanvas.brush.Style:=bsclear; if fminimum=0 then fminimum:=0.1; exp1:=round(log10(fminimum)); exp2:=round(log10(fmaximum)); fminimum:=power(10,exp1); fmaximum:=power(10,exp2);

node:=exp2-exp1; delta:=round((x2-x1)/node); for i:=2 to 9 do minorsarray[i]:=round(log10(i)*delta); for i:=1 to node do begin if freverse then x:=x2-(i-1)*delta else x:=x1+(i-1)*delta; if i>1 then begin

fcanvas.Pen.Color:=fmajorscolor; case ticksStyle of TSinner:begin fcanvas.MoveTo(x,y1); fcanvas.LineTo(x ,y1-tickslength); end; tsouter:begin fcanvas.MoveTo(x,y1); fcanvas.LineTo(x,y1+tickslength); end; Tsboth:begin fcanvas.MoveTo(x,y1); fcanvas.LineTo(x,y1-tickslength); fcanvas.MoveTo(x,y1); fcanvas.LineTo(x,y1+tickslength); end; end;

if Fshowmajorgrid then begin Fcanvas.Pen.Style:=psSolid; fcanvas.MoveTo(x,fchartrect.top); fcanvas.LineTo(x,fchartrect.bottom); Fcanvas.Pen.Style:=psSolid; end; if fshowlabels then begin

labels:=formatfloat(flabelsformat,fminimum*power(10,i-1)); ty:=y1-tickslength-2-fcanvas.TextHeight('0') ; tx:=x-fcanvas.Textwidth(labels) div 2; fcanvas.TextOut(tx,ty,labels); end; end; //--------------------fcanvas.Pen.Color:=fminorscolor; if fminors =1 then begin if freverse then xx:=x-minorsarray[5] else xx:=x+minorsarray[5]; case ticksStyle of TSinner:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1+ tickslength div 2); end; tsouter:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1- tickslength div 2) end; Tsboth:begin fcanvas.MoveTo(xx,y1);

fcanvas.LineTo(xx,y1+ tickslength div 2); fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1- tickslength div 2) end; end;//case if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot; fcanvas.MoveTo(xx,fchartrect.top); fcanvas.LineTo(xx,fchartrect.bottom); Fcanvas.Pen.Style:=psSolid; end;// grid end else if fminors =4 then begin for j:=1 to 4 do begin

if freverse then xx:=x-minorsarray[j*2] else xx:=x+minorsarray[j*2]; case ticksStyle of TSinner:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1+ tickslength div 2); end;

tsouter:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1- tickslength div 2) end; Tsboth:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1+ tickslength div 2); fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1- tickslength div 2) end; end;//case if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot; fcanvas.MoveTo(xx,fchartrect.top); fcanvas.LineTo(xx,fchartrect.bottom); Fcanvas.Pen.Style:=psSolid; end;// grid end; end else begin for j:=2 to 9 do begin if freverse then xx:=x-minorsarray[j] else

xx:=x+minorsarray[j]; case ticksStyle of TSinner:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1+ tickslength div 2); end; tsouter:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1- tickslength div 2) end; Tsboth:begin fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1+ tickslength div 2); fcanvas.MoveTo(xx,y1); fcanvas.LineTo(xx,y1- tickslength div 2) end; end;//case if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot; fcanvas.MoveTo(xx,fchartrect.top); fcanvas.LineTo(xx,fchartrect.bottom); Fcanvas.Pen.Style:=psSolid; end;// grid

end; // for

end; // case else

end;// for i //=============== fcanvas.Brush.Style:=bsclear; if Fshowtitle then begin ty:=y1-fcanvas.textheight('0')*2-tickslength-2; tx:=((x2+x1) div 2)- fcanvas.textwidth(ftitle)div 2 ; fcanvas.TextOut(tx,ty,ftitle); end; end else begin

// ------ minor ticks ----fcanvas.Pen.Color:=fminorscolor; dd:=round(fminimum / fminors); dd:=fminors*dd; if dd < fminimum then dd:=dd+fminors; while dd < fmaximum do begin p:=v2p(dd,fminimum,fmaximum,x1,x2,freverse); if (dd>fminimum) and (dd < maximum) then case ticksStyle of TSinner:begin fcanvas.MoveTo(p,y1);

fcanvas.LineTo(p,y1+ tickslength div 2); end; tsouter:begin fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1- tickslength div 2); end; Tsboth:begin fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1+ tickslength div 2); fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1- tickslength div 2); end; end; if FShowminorgrid then begin Fcanvas.Pen.Style:=psDot; fcanvas.Brush.Style:=bsclear; fcanvas.MoveTo(p,fchartrect.top); fcanvas.LineTo(p,fchartrect.bottom); Fcanvas.Pen.Style:=psSolid; end; dd:=dd+fminors; end;

fcanvas.brush.Style:=bsclear;

if fshowtitle then begin tx:=((x2+x1) div 2)- (fcanvas.textwidth(ftitle)div 2); ty:=faxrect.Top-fcanvas.TextHeight('0')*2-3; fcanvas.TextOut(tx,ty,ftitle); end; // ----- major ticks ----dd:=round(fminimum / fmajors); dd:=fmajors*dd; fcanvas.Pen.Color:=fmajorscolor; if dd < fminimum then dd:=dd+fmajors; ty:=faxrect.Top-fcanvas.TextHeight('0')*2-3+fcanvas.TextHeight('0')+2; while dd < fmaximum do begin p:=v2p(dd,fminimum,fmaximum,x1,x2,freverse); if (dd>fminimum) and (dd < maximum) then case ticksStyle of TSinner:begin fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1+ tickslength); end; tsouter:begin fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1- tickslength); end; Tsboth:begin fcanvas.MoveTo(p,y1);

fcanvas.LineTo(p,y1+ tickslength); fcanvas.MoveTo(p,y1); fcanvas.LineTo(p,y1- tickslength); end; end;

if FShowmajorgrid then begin Fcanvas.Pen.Style:=psSolid; fcanvas.Brush.Style:=bsclear; fcanvas.MoveTo(p,fchartrect.top); fcanvas.LineTo(p,fchartrect.bottom); Fcanvas.Pen.Style:=psSolid; end; if fshowlabels then begin labels:= formatfloat( labelsformat,dd); tx:=p-fcanvas.TextWidth(labels) div 2; if (dd>fminimum) and (dd < maximum) then fcanvas.TextOut(tx,ty,labels); end; dd:=dd+fmajors; end; end; end;

procedure TGTopAxis.PrintAx(aleft,atop,abottom,aright:double);

var oldR:trect; po:tprinterop; oldcanvas:tcanvas; begin oldR:=Faxrect; oldcanvas:=fcanvas; po:=tprinterop.create; try faxrect.Left:=po.CmtopixelsX(aLeft); faxrect.Right:=po.CmtopixelsX(aRight); faxrect.Top:=po.CmtopixelsY(aTop) ; faxrect.bottom:=po.CmtopixelsY(aBottom)-2*printer.Canvas.TextHeight('0'); fcanvas:=printer.Canvas; draw; fcanvas.Rectangle(faxrect); finally Faxrect:=oldR; fcanvas:=oldcanvas; freeandnil(po); end; end; function TGTopAxis.Topix(value: double): integer; begin if faxistype= atlog then

result:=logv2p(value,fminimum,fmaximum,fchartrect.left,fchartrect.right,freverse) else result:=v2p(value,fminimum,fmaximum,fchartrect.left,fchartrect.right,freverse); end;

function TGTopAxis.Toval(pix: integer): double; begin if faxistype= atlog then result:=logp2v(pix,fminimum,fmaximum,fchartrect.left,fchartrect.right,freverse) else result:=p2v(pix,fminimum,fmaximum,fchartrect.left,fchartrect.right,freverse); end;

{ TGleftAxis }

constructor TGleftAxis.create; begin inherited create; end;

procedure TGleftAxis.draw; var p:integer; dd:double;

x1,y1,y2:integer; tx,ty,tickslength:integer; labels:string[100]; exp1,exp2,node,delta,i,y,yy,j:integer; minorsarray:array[2..9]of integer; begin fcanvas.brush.Style:=bssolid; fcanvas.brush.color:=fbkcolor; fcanvas.pen.Color:=fpencolor; fcanvas.Font.Color:=ffontcolor; x1:=(faxrect.left+faxrect.Right) div 2; y1:=faxrect.Top; y2:=faxrect.Bottom; //tickslength:=(faxrect.right-faxrect.left) div 2; tickslength:=fcanvas.TextHeight('0'); if fdrawaxisline then begin fcanvas.moveto(x1,y1); fcanvas.lineto(x1,y2); end;

// ------ minor ticks ----if faxistype=atlog then begin fcanvas.brush.Style:=bsclear; if fminimum=0 then

fminimum:=0.1; exp1:=round(log10(fminimum)); exp2:=round(log10(fmaximum));

fminimum:=power(10,exp1); fmaximum:=power(10,exp2);

node:=exp2-exp1; delta:=round((y2-y1)/node); for i:=2 to 9 do minorsarray[i]:=round(log10(i)*delta); for i:=1 to node do begin if freverse then y:=y1+(i-1)*delta else y:=y2-(i-1)*delta; if i>1 then begin fcanvas.Pen.Color:=fmajorscolor; case ticksStyle of TSinner:begin fcanvas.MoveTo(x1,y); fcanvas.LineTo(x1+ tickslength,y); end; tsouter:begin

fcanvas.MoveTo(x1,y); fcanvas.LineTo(x1- tickslength,y); end; Tsboth:begin fcanvas.MoveTo(x1,y); fcanvas.LineTo(x1+tickslength,y); fcanvas.MoveTo(x1,y); fcanvas.LineTo(x1- tickslength,y); end; end;

if Fshowmajorgrid then begin Fcanvas.Pen.Style:=psSolid; fcanvas.MoveTo(fchartrect.Left,y); fcanvas.LineTo(fchartrect.Right,y); Fcanvas.Pen.Style:=psSolid; end; if fshowlabels then begin labels:=formatfloat(flabelsformat,fminimum*power(10,i-1)); tx:=x1-tickslength-2-fcanvas.TextHeight(labels) ; ty:=y+canvas.Textwidth(labels) div 2; textoutan(fcanvas,tx,ty,90,labels); end; end; //---------------------

fcanvas.Pen.Color:=fminorscolor; if fminors = 1 then begin if freverse then yy:=y+minorsarray[5] else yy:=y-minorsarray[5]; case ticksStyle of TSinner:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1+ tickslength div 2,yy); end; tsouter:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1- tickslength div 2,yy) end; Tsboth:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1+ tickslength div 2,yy); fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1- tickslength div 2,yy) end; end;//case if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot;

fcanvas.MoveTo(fchartrect.Left,yy); fcanvas.LineTo(fchartrect.Right,yy); Fcanvas.Pen.Style:=psSolid; end;// grid end else if fminors = 4 then begin for j:=1 to 4 do begin if freverse then yy:=y+minorsarray[j*2] else yy:=y-minorsarray[j*2];

case ticksStyle of TSinner:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1+ tickslength div 2,yy); end; tsouter:begin fcanvas.MoveTo(x1,y1); fcanvas.LineTo(x1- tickslength div 2,y1) end; Tsboth:begin fcanvas.MoveTo(x1,yy);

fcanvas.LineTo(x1+ tickslength div 2,yy); fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1- tickslength div 2,yy) end; end; if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot; fcanvas.MoveTo(fchartrect.Left,yy); fcanvas.LineTo(fchartrect.Right,yy); Fcanvas.Pen.Style:=psSolid; end; end; end else begin for j:=2 to 9 do begin if freverse then yy:=y+minorsarray[j] else yy:=y-minorsarray[j];

case ticksStyle of TSinner:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1+ tickslength div 2,yy);

end; tsouter:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1- tickslength div 2,yy) end; Tsboth:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1+ tickslength div 2,yy); fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1- tickslength div 2,yy) end; end; if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot; fcanvas.MoveTo(fchartrect.Left,yy); fcanvas.LineTo(fchartrect.Right,yy); Fcanvas.Pen.Style:=psSolid; end; end; // for end; // case else

end;// for i //=============== fcanvas.Brush.Style:=bsclear; if Fshowtitle then begin

tx:=x1-fcanvas.textheight('0')*2-tickslength-2; ty:=((y2+y1) div 2)+ fcanvas.textwidth(ftitle)div 2 ; textoutan(fcanvas,tx,ty,90,ftitle); end; end // axis log else begin fcanvas.Pen.Color:=fminorscolor; dd:=round(fminimum / fminors); dd:=fminors*dd; fcanvas.brush.Style:=bsclear; if dd < fminimum then dd:=dd+fminors; while dd < maximum do begin p:=v2p(dd,fminimum,fmaximum,y1,y2, not freverse); if (dd>fminimum) and (dd < maximum) then case ticksStyle of TSinner:begin fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1+ tickslength div 2,p); end; tsouter:begin fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1- tickslength div 2,p) end; Tsboth:begin fcanvas.MoveTo(x1,p);

fcanvas.LineTo(x1+ tickslength div 2,p); fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1- tickslength div 2,p) end; end; dd:=dd+fminors;

if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot; fcanvas.MoveTo(fchartrect.Left,p); fcanvas.LineTo(fchartrect.Right,p); Fcanvas.Pen.Style:=psSolid; end; end;

fcanvas.Brush.Style:=bsclear; if Fshowtitle then begin tx:=x1-fcanvas.textheight('0')*2-tickslength-2; ty:=((y2+y1) div 2)+ fcanvas.textwidth(ftitle)div 2 ; textoutan(fcanvas,tx,ty,90,ftitle); end;

// ----- major ticks ----fcanvas.Pen.Color:=fmajorscolor;

dd:=round(fminimum / fmajors); dd:=fmajors*dd; labels:=formatfloat( flabelsformat,fmaximum);

if dd < fminimum then dd:=dd+fmajors;

while dd < fmaximum do begin p:=v2p(dd,minimum,fmaximum,y1,y2,not freverse); if (dd>fminimum) and (dd < maximum) then case ticksStyle of TSinner:begin fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1+ tickslength,p); end; tsouter:begin fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1- tickslength,p); end; Tsboth:begin fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1+tickslength,p); fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1- tickslength,p); end; end;

if Fshowmajorgrid then begin Fcanvas.Pen.Style:=psSolid; fcanvas.MoveTo(fchartrect.Left,p); fcanvas.LineTo(fchartrect.Right,p); Fcanvas.Pen.Style:=psSolid; end; if fshowlabels then begin labels:=formatfloat( flabelsformat,dd); ty:=p+fcanvas.Textwidth(labels) div 2; tx:=x1-tickslength-fcanvas.TextHeight('0')-2; if (dd>fminimum) and (dd < maximum) then textoutan(fcanvas,tx,ty,90,labels); end; dd:=dd+majors; end;

end;// axis norm end;

procedure TGleftAxis.PrintAx(aleft,atop,abottom,aright:double); var oldR:trect; po:tprinterop; oldcanvas:tcanvas;

begin oldR:=Faxrect; oldcanvas:=fcanvas; po:=tprinterop.create; try faxrect.Left:=po.CmtopixelsX(aLeft)+2*printer.Canvas.TextHeight('0'); faxrect.Right:=po.CmtopixelsX(aRight); faxrect.Top:=po.CmtopixelsY(aTop); faxrect.bottom:=po.CmtopixelsY(aBottom); fcanvas:=printer.Canvas; draw; fcanvas.Rectangle(faxrect); finally Faxrect:=oldR; fcanvas:=oldcanvas; freeandnil(po); end; end;

function TGleftAxis.Topix(value: double): integer; begin if faxistype = atlog then result:=logv2p(value,fminimum,fmaximum,fchartrect.Top,fchartrect.Bottom,not freverse) else result:=v2p(value,fminimum,fmaximum,fchartrect.Top,fchartrect.Bottom,not freverse);

end;

function TGleftAxis.Toval(pix: integer): double; begin if faxistype = atlog then result:=logp2v(pix,fminimum,fmaximum,fchartrect.Top,fchartrect.Bottom,not freverse) else result:=p2v(pix,fminimum,fmaximum,fchartrect.Top,fchartrect.Bottom,not freverse); end;

{ TGRightAxis }

constructor TGRightAxis.create; begin inherited create; end;

procedure TGRightAxis.draw; var p:integer; dd:double; x1,y1,y2:integer; tx,ty,tickslength:integer; labels:string[100]; exp1,exp2,node,delta,i,y,yy,j:integer;

minorsarray:array[2..9]of integer; begin fcanvas.brush.color:=fbkcolor; fcanvas.pen.Color:=fpencolor; fcanvas.Font.Color:=ffontcolor; x1:=(faxrect.left+faxrect.Right) div 2;

y1:=faxrect.Top; y2:=faxrect.Bottom; //tickslength:=(faxrect.right-faxrect.left) div 2; tickslength:=fcanvas.TextHeight('0'); if fdrawaxisline then begin fcanvas.moveto(x1,y1); fcanvas.lineto(x1,y2); end; if faxistype= atlog then begin //=================== fcanvas.brush.Style:=bsclear; if fminimum=0 then fminimum:=0.1; exp1:=round(log10(fminimum)); exp2:=round(log10(fmaximum)); fminimum:=power(10,exp1); fmaximum:=power(10,exp2);

node:=exp2-exp1; delta:=round((y2-y1)/node); for i:=2 to 9 do minorsarray[i]:=round(log10(i)*delta); for i:=1 to node do begin if freverse then y:=y1+(i-1)*delta else y:=y2-(i-1)*delta; if i>1 then begin fcanvas.Pen.Color:=fmajorscolor; case ticksStyle of TSinner:begin fcanvas.MoveTo(x1,y); fcanvas.LineTo(x1+ tickslength,y); end; tsouter:begin fcanvas.MoveTo(x1,y); fcanvas.LineTo(x1- tickslength,y); end; Tsboth:begin fcanvas.MoveTo(x1,y); fcanvas.LineTo(x1+tickslength,y);

fcanvas.MoveTo(x1,y); fcanvas.LineTo(x1- tickslength,y); end; end;

if Fshowmajorgrid then begin Fcanvas.Pen.Style:=psSolid; fcanvas.MoveTo(fchartrect.Left,y); fcanvas.LineTo(fchartrect.Right,y); Fcanvas.Pen.Style:=psSolid; end; if fshowlabels then begin labels:=formatfloat(flabelsformat,fminimum*power(10,i-1)); tx:=x1+tickslength+2; ty:=y+canvas.Textwidth(labels) div 2; textoutan(fcanvas,tx,ty,90,labels); end; end; //--------------------fcanvas.Pen.Color:=fminorscolor; if fminors= 1 then begin if freverse then yy:=y+minorsarray[5] else

yy:=y-minorsarray[5]; case ticksStyle of TSinner:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1+ tickslength div 2,yy); end; tsouter:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1- tickslength div 2,yy) end; Tsboth:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1+ tickslength div 2,yy); fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1- tickslength div 2,yy) end; end;//case if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot; fcanvas.MoveTo(fchartrect.Left,yy); fcanvas.LineTo(fchartrect.Right,yy); Fcanvas.Pen.Style:=psSolid; end;// grid end else

if fminors= 4 then begin for j:=1 to 4 do begin if freverse then yy:=y+minorsarray[j*2] else yy:=y-minorsarray[j*2]; case ticksStyle of TSinner:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1+ tickslength div 2,yy); end; tsouter:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1- tickslength div 2,yy) end; Tsboth:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1+ tickslength div 2,yy); fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1- tickslength div 2,yy) end; end; if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot;

fcanvas.MoveTo(fchartrect.Left,yy); fcanvas.LineTo(fchartrect.Right,yy); Fcanvas.Pen.Style:=psSolid; end; end; end

else begin for j:=2 to 9 do begin if freverse then yy:=y+minorsarray[j] else yy:=y-minorsarray[j]; case ticksStyle of TSinner:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1+ tickslength div 2,yy); end; tsouter:begin fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1- tickslength div 2,yy) end; Tsboth:begin fcanvas.MoveTo(x1,yy);

fcanvas.LineTo(x1+ tickslength div 2,yy); fcanvas.MoveTo(x1,yy); fcanvas.LineTo(x1- tickslength div 2,yy) end; end; if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot; fcanvas.MoveTo(fchartrect.Left,yy); fcanvas.LineTo(fchartrect.Right,yy); Fcanvas.Pen.Style:=psSolid; end; end; // for end; // case else

end;// for i //=============== fcanvas.Brush.Style:=bsclear; if Fshowtitle then begin tx:=x1+fcanvas.textheight('0')+tickslength+2; ty:=((y2+y1) div 2)+ fcanvas.textwidth(ftitle)div 2 ; textoutan(fcanvas,tx,ty,90,ftitle); end;

end

else begin // ------ minor ticks ----fcanvas.Pen.Color:=fminorscolor; dd:=round(fminimum / fminors); dd:=fminors*dd; fcanvas.Brush.Style:=bsclear; if dd < fminimum then dd:=dd+fminors; while dd < maximum do begin p:=v2p(dd,fminimum,fmaximum,y1,y2, not freverse); if (dd>fminimum) and (dd < maximum) then case ticksStyle of TSinner:begin fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1- tickslength div 2,p); end; tsouter:begin fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1+ tickslength div 2,p) end; Tsboth:begin fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1+ tickslength div 2,p); fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1- tickslength div 2,p)

end; end; dd:=dd+fminors;

if Fshowminorgrid then begin Fcanvas.Pen.Style:=psdot; fcanvas.MoveTo(fchartrect.Left,p); fcanvas.LineTo(fchartrect.Right,p); Fcanvas.Pen.Style:=psSolid; end; end;

fcanvas.Brush.Style:=bsclear; if Fshowtitle then begin tx:=x1+fcanvas.textheight('0')+tickslength+2; ty:=((y2+y1) div 2)+ fcanvas.textwidth(ftitle)div 2 ; textoutan(fcanvas,tx,ty,90,ftitle); end;

// ----- major ticks ----fcanvas.Pen.Color:=fmajorscolor; dd:=round(fminimum / fmajors); dd:=fmajors*dd; labels:=formatfloat( flabelsformat,fmaximum);

if dd < fminimum then dd:=dd+fmajors;

while dd < fmaximum do begin p:=v2p(dd,minimum,fmaximum,y1,y2,not freverse); if (dd>fminimum) and (dd < maximum) then case ticksStyle of TSinner:begin fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1- tickslength,p); end; tsouter:begin fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1+ tickslength,p); end; Tsboth:begin fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1+tickslength,p); fcanvas.MoveTo(x1,p); fcanvas.LineTo(x1- tickslength,p); end; end;

if Fshowmajorgrid then begin Fcanvas.Pen.Style:=psSolid;

fcanvas.MoveTo(fchartrect.Left,p); fcanvas.LineTo(fchartrect.Right,p); Fcanvas.Pen.Style:=psSolid; end; if fshowlabels then begin labels:=formatfloat( flabelsformat,dd); ty:=p+fcanvas.Textwidth(labels) div 2; tx:=x1+tickslength+2; if (dd>fminimum) and (dd < maximum) then textoutan(fcanvas,tx,ty,90,labels); end; dd:=dd+majors; end;

end;/// if norm axis end;

procedure TGRightAxis.PrintAx(aleft,atop,abottom,aright:double); var oldR:trect; po:tprinterop; oldcanvas:tcanvas; begin oldR:=Faxrect; oldcanvas:=fcanvas;

po:=tprinterop.create; try faxrect.Left:=po.CmtopixelsX(aLeft); faxrect.Right:=po.CmtopixelsX(aRight)-2*printer.Canvas.TextHeight('0'); faxrect.Top:=po.CmtopixelsY(aTop); faxrect.bottom:=po.CmtopixelsY(aBottom); fcanvas:=printer.Canvas; draw; fcanvas.Rectangle(faxrect); finally Faxrect:=oldR; fcanvas:=oldcanvas; freeandnil(po); end;

end;

function TGRightAxis.Topix(value: double): integer; begin if faxistype = atlog then result:=logv2p(value,fminimum,fmaximum,fchartrect.Top,fchartrect.Bottom,not freverse) else result:=v2p(value,fminimum,fmaximum,fchartrect.Top,fchartrect.Bottom,not freverse); end;

function TGRightAxis.Toval(pix: integer): double; begin if faxistype = atlog then result:=logp2v(pix,fminimum,fmaximum,fchartrect.Top,fchartrect.Bottom,not freverse) else result:=p2v(pix,fminimum,fmaximum,fchartrect.Top,fchartrect.Bottom,not freverse); end;

{ Tgeoimage }

constructor TgeoChart.create; begin inherited create; fbitmap:=tbitmap.Create; fwidth:=500; fheight:=500; fbkbitmap:=tbitmap.Create; fwidth:=500; fheight:=500; fbitmap.width:=fwidth; fbitmap.height:=fheight; fleftmargin:=20; frightmargin:=20; fbottommargin:=20; ftopmargin:=20;

fbordercolor:=clblack; fpanelcolor:=clyellow; fbkcolor:=clwhite; fshowbkbitmap:=false; fproportionalXY:=false; Fvertaxis:=valeft; fhorizaxis:=habottom; fshowleftaxis:=true; fshowtopaxis:=false; fshowbottomaxis:=true; fshowrightaxis:=false; ftransparent:=false; DrawBorder:=False; with bitmap do begin leftaxis:=tgleftaxis.create ; leftaxis.Canvas:=canvas; rightaxis:=tgrightaxis.create ; rightaxis.Canvas:=canvas; topaxis:=tgtopaxis.create ; topaxis.Canvas:=canvas; bottomaxis:=tgbottomaxis.create ; bottomaxis.Canvas:=canvas; leftaxis.TicksStyle:=tsboth; rightaxis.TicksStyle:=tsboth;

bottomaxis.TicksStyle:=tsboth; topaxis.TicksStyle:=tsboth; leftaxis.ShowMajorgrid:=true; rightaxis.ShowMinorgrid:=true; topaxis.ShowMajorgrid:=true; bottomaxis.ShowMinorgrid:=true; end; end;

procedure TgeoChart.Draw; var th:integer; x1,x2,y1,y2:integer; begin with fbitmap do begin width:=fwidth; height:=fheight; canvas.Pen.Color:=fbordercolor; canvas.Brush.Color:=fpanelcolor; if ftransparent then canvas.Brush.Style:=bsclear else canvas.Brush.Style:=bsSolid; canvas.rectangle(-1,-1,canvas.ClipRect.Right+1,canvas.ClipRect.Bottom+1);

th:=canvas.TextHeight('0')*2+15; if showtopaxis then y1:=ftopmargin+th else y1:=ftopmargin; if showrightaxis then x2:=width-frightmargin-th else x2:=width-frightmargin; if showbottomaxis then y2:= height-fbottommargin-th else y2:= height-fbottommargin; if showleftaxis then x1:=fleftmargin+th else x1:=fleftmargin; fchartrect:=rect(x1,y1,x2,y2 );

canvas.Pen.Color:=fbordercolor; canvas.Brush.Color:=fbkcolor;

canvas.Brush.Style:=bsSolid; canvas.fillrect(fchartrect);

if showbkbitmap then canvas.StretchDraw(fchartrect,fbkbitmap); leftaxis.chartRect:=fchartrect; topaxis.chartRect:=fchartrect; rightaxis.chartRect:=fchartrect; bottomaxis.chartRect:=fchartrect; with fchartrect do begin leftaxis.Axrect:=rect(Left-6,top, left+6,bottom); topaxis.Axrect:=rect(left,top-6,right, top+6); rightaxis.Axrect:=rect(right-6,top, right+6,bottom); bottomaxis.Axrect:=rect(left,bottom-6, right,bottom+6); end; topaxis.PenColor:=fbordercolor; leftaxis.PenColor:=fbordercolor; bottomaxis.PenColor:=fbordercolor; rightaxis.PenColor:=fbordercolor; if showtopaxis then topaxis.Draw; if showrightaxis then rightaxis.draw; if showbottomaxis then

bottomaxis.draw; if showleftaxis then leftaxis.draw; canvas.Brush.Style:=bsclear; canvas.Pen.Color:=fbordercolor;

if Fdrawborder then with fchartrect do canvas.rectangle(left,top,right,bottom); end; end;

procedure TgeoChart.SetBitmap(const Value: tbitmap); begin FBitmap := Value; end;

procedure TgeoChart.Setbkcolor(const Value: tcolor); begin Fbkcolor := Value; end;

procedure TgeoChart.Setbordercolor(const Value: tcolor); begin

Fbordercolor := Value; end;

procedure TgeoChart.Setbottommargin(const Value: integer); begin Fbottommargin := Value; end; { procedure TgeoChart.Setchartrect(const Value: trect); begin Fchartrect := Value; end; } procedure TgeoChart.Setheight(const Value: integer); begin Fheight := Value; if proportionalXY then fwidth:=trunc(Fheight*XrangeperYrange); end;

procedure TgeoChart.Sethorizaxis(const Value: thorizaxis); begin Fhorizaxis := Value; end;

procedure TgeoChart.Setleftmargin(const Value: integer); begin Fleftmargin := Value; end;

procedure TgeoChart.Setpanelcolor(const Value: tcolor); begin Fpanelcolor := Value; end;

procedure TgeoChart.Setrightmargin(const Value: integer); begin Frightmargin := Value; end;

procedure TgeoChart.Setshowbottomaxis(const Value: boolean); begin Fshowbottomaxis := Value; end;

procedure TgeoChart.SetShowleftaxis(const Value: boolean); begin FShowleftaxis := Value; end;

procedure TgeoChart.Setshowrightaxis(const Value: boolean); begin Fshowrightaxis := Value; end;

procedure TgeoChart.Setshowtopaxis(const Value: boolean); begin Fshowtopaxis := Value; end;

procedure TgeoChart.SetTitle(const Value: str100); begin FTitle := Value; end;

procedure TgeoChart.Settopmargin(const Value: integer); begin Ftopmargin := Value; end;

procedure TgeoChart.Setvertaxis(const Value: tvertaxis); begin Fvertaxis := Value; fbitmap.Height:=fheight; end;

procedure TgeoChart.Setwidth(const Value: integer); begin Fwidth := Value; if proportionalXY then Fheight:=trunc(fwidth/XrangeperYrange);

end; procedure TgeoChart.DrawPoint(canvas:tcanvas;x,y:double); var px,py:integer; begin if fhorizaxis=habottom then px:=bottomaxis.Topix(x) else px:= topaxis.Topix(x); if fvertaxis=valeft then py:= leftaxis.Topix(y) else py:= rightaxis.Topix(y) ; canvas.Rectangle(px-3,py-3, px+3,py+3); end; procedure TgeoChart.Drawline(canvas: tcanvas; x1, y1, x2, y2: double); var

px,py:integer; begin if fhorizaxis=habottom then px:=bottomaxis.Topix(x1) else px:= topaxis.Topix(x1); if fvertaxis=valeft then py:= leftaxis.Topix(y1) else py:= rightaxis.Topix(y1) ; canvas.MoveTo(px,py);

if fhorizaxis=habottom then px:=bottomaxis.Topix(x2) else px:= topaxis.Topix(x2); if fvertaxis=valeft then py:= leftaxis.Topix(y2) else py:= rightaxis.Topix(y2) ; canvas.lineTo(px,py); end;

{ Tsymbol }

constructor Tsymbol.create; begin inherited create; fcolor:=clred; fsize:=6; fx:=0; fy:=0; fsrect:=rect(-3,-3,3,3); fbitmap:=tbitmap.Create; fbitmap.Width:=fsize; fbitmap.Height:=fsize; fbitmapid:=1; flabelpos:=slpup; flabelbkcolor:=clwhite; fspacing:=4; end;

procedure Tsymbol.draw(canvas: tcanvas); var px,py:integer;

begin px:=fsize div 2; py:=fsize div 2; canvas.brush.Color:=fcolor;

fsrect:=rect (x-px,y-py,x+px,y+py); fbitmap.Width:=fsize+2; fbitmap.Height:=fsize+2;

fbitmap.Canvas.CopyRect(fbitmap.Canvas.ClipRect,canvas,fsrect); case fbitmapid of 0:canvas.Pixels[x,y]:=canvas.Brush.Color; 1:begin canvas.Rectangle(fsrect); end; 2:begin canvas.Ellipse(fsrect); end; 3:begin canvas.MoveTo(x,y-py); canvas.LineTo(x,y+py+1); canvas.MoveTo(x-px,y); canvas.LineTo(x+px+1,y); end; 4:begin canvas.MoveTo(x-px,y-py); canvas.LineTo(x+px,y+py); canvas.MoveTo(x+px,y-py); canvas.LineTo(x-px,y+py); end;

5:canvas.Polygon([point(x-px,y-py),point(x+px,y-py),point(x,y+py)]); 6:canvas.Polygon([point(x,y-py),point(x-px,y+py),point(x+px,y+py)]); 7:begin canvas.Polygon([point(x,y),point(x-px,y-py),point(x+px,y-py)]); canvas.MoveTo(x,y); canvas.LineTo(x,y+py); end; 8:begin canvas.MoveTo(x-px,y); canvas.LineTo(x+px,y); end; 9:begin canvas.MoveTo(x,y-py); canvas.LineTo(x,y+py); end; 10:canvas.Polygon([point(x,y-py),point(x+px,y),point(x,y+py),point(x-px,y)]); 11:begin canvas.MoveTo(x,y); canvas.LineTo(x,y+py); canvas.Polygon([point(x,y),point(x,y-py),point(x+px,y-(py div 2))]); end; end; if fshowname then begin canvas.Font.Color:=clblack;

canvas.Brush.Color:=clyellow; canvas.Pen.Color:=clblack; case Flabelpos of slpup :begin py:=fsrect.Top-canvas.TextHeight('0')-fspacing; px:=((fsrect.Right+fsrect.Left) div 2)-(canvas.TextWidth(fname) div 2); end; slpdown:begin py:=fsrect.Bottom+fspacing; px:=((fsrect.Right+fsrect.Left) div 2)-(canvas.TextWidth(fname) div 2); end; slpleft:begin px:=fsrect.Left-spacing-canvas.TextWidth(fname); py:=((fsrect.Top+fsrect.Bottom) div 2)-(canvas.TextHeight('0') div 2);; end; slpright:begin px:=fsrect.right+spacing; py:=((fsrect.Top+fsrect.Bottom) div 2)-(canvas.TextHeight('0') div 2);;

end; end;// case if not FtransparentText then begin canvas.Brush.Color:=Flabelbkcolor; canvas.Brush.Style:=BsSolid;

canvas.Rectangle(rect(px-3,py-1,px+canvas.TextWidth(fname)+3, py+canvas.TextHeight('0')+1)); end ; canvas.Brush.Style:=bsclear; canvas.TextOut(px,py,fname); end; end;

procedure Tsymbol.drawselect(canvas: tcanvas; clr: tcolor); var r:trect; oldpen:tpen;oldbrush:tbrush; begin oldpen:=tpen.Create; oldbrush:=tbrush.Create; oldbrush.Color:=canvas.Brush.Color; oldbrush.Style:=canvas.Brush.Style; oldpen.Color:=canvas.Pen.Color; r.Left:=fsrect.Left-2; r.top:=fsrect.top-2; r.right:=fsrect.right+2; r.bottom:=fsrect.bottom+2; canvas.Pen.Color:=clr; canvas.Brush.Style:=bsclear; canvas.Rectangle(r);

canvas.Brush.Color:=oldbrush.Color; canvas.Brush.Style:=oldbrush.Style; canvas.Pen.Color:=oldpen.Color; end;

procedure Tsymbol.erase(canvas: tcanvas);

begin Canvas.CopyRect(fsrect,fbitmap.canvas,fbitmap.canvas.ClipRect);

end;

function Tsymbol.pointin(x, y: integer): boolean; begin if inrange(x,fsrect.Left,fsrect.Right)and inrange(y,fsrect.top,fsrect.bottom) then result:=true else result:=false; end;

procedure Tsymbol.Setbitmap(const Value: tbitmap); begin Fbitmap := Value; end;

procedure Tsymbol.Setbitmapid(const Value: integer); begin Fbitmapid := Value; end;

procedure Tsymbol.Setcolor(const Value: tcolor); begin Fcolor := Value; end;

procedure Tsymbol.Setid(const Value: integer); begin Fid := Value; end;

procedure Tsymbol.Setlabelbkcolor(const Value: tcolor); begin Flabelbkcolor := Value; end;

procedure Tsymbol.SetLabelPos(const Value: TlabelPos); begin FLabelPos := Value; end;

procedure Tsymbol.SetName(const Value: str100); begin FName := Value; end;

procedure Tsymbol.Setselected(const Value: boolean); begin Fselected := Value; end;

procedure Tsymbol.Setshowname(const Value: boolean); begin Fshowname := Value; end;

procedure Tsymbol.Setsize(const Value: integer);

var px,py:integer; begin Fsize := Value ; px:=fsize div 2; py:=fsize div 2; fsrect:=rect (x-px,y-py,x+px,y+py); fbitmap.Width:=fsize;

fbitmap.Height:=fsize;

end;

procedure Tsymbol.Setspacing(const Value: integer); begin Fspacing := Value; end;

procedure Tsymbol.Setsrect(const Value: trect); begin Fsrect := Value; end;

procedure Tsymbol.SetTransparentText(const Value: boolean); begin FTransparentText := Value; end;

procedure Tsymbol.Setx(const Value: integer); var px,py:integer; begin Fx := Value; px:=fsize div 2;

py:=fsize div 2; fsrect:=rect (x-px,y-py,x+px,y+py); fbitmap.Width:=fsize; fbitmap.Height:=fsize;

end;

procedure Tsymbol.Sety(const Value: integer); var px,py:integer; begin Fy := Value; px:=fsize div 2; py:=fsize div 2; fsrect:=rect (x-px,y-py,x+px,y+py); fbitmap.Width:=fsize; fbitmap.Height:=fsize;

end;

procedure TgeoChart.DrawSymbol(canvas: tcanvas; x, y: double; var sym: tsymbol);

begin

if fhorizaxis=habottom then sym.x:=bottomaxis.Topix(x) else sym.x:= topaxis.Topix(x); if fvertaxis=valeft then sym.y:= leftaxis.Topix(y) else sym.y:= rightaxis.Topix(y) ;

if inrange(sym.x,fchartrect.Left,fchartrect.Right) and inrange(sym.y,fchartrect.top,fchartrect.Bottom) then sym.draw(canvas); end;

procedure TgeoChart.Drawcurve(canvas: tcanvas; N: integer; F: realarray;color:tcolor); var i:integer; begin canvas.Brush.Style:=bsclear; canvas.Pen.Color:=color; for i:=1 to n-1 do drawline(canvas,f[i].x,f[i].y,f[i+1].x,f[i+1].y); end;

procedure TgeoChart.setminmax(minx, maxx, miny, maxy:double);

begin leftaxis.Minimum:=miny; leftaxis.Maximum:=maxy; rightaxis.Minimum:=miny; rightaxis.Maximum:=maxy; topaxis.Maximum:=maxx; bottomaxis.Minimum:=minx; topaxis.Minimum:=minx; bottomaxis.Maximum:=maxx; end;

{ TVES }

procedure Tves.assign(vs: tves); var i:integer; begin

symbol.showname:=vs.Symbol.showname; FArraytype:=vs.Arraytype; FmDate:=vs.MDate; FDirection:=vs.Direction; Fequip:=vs.equip; Flocation:=vs.location; FNumpoints:=vs.Numpoints;

Foperator:=vs.operator; Fproject:=vs.project; FStation_No:=vs.Station_No; fvisible:=vs.Visible; fx:=vs.X;fy:=vs.Y;fz:=vs.Z; fdipolelength:=vs.Dipolelength; for i:=1 to fnumpoints do begin points[i].ab2:=vs.points[i].ab2; points[i].rho:=vs.points[i].rho; end; end;

procedure Tves.autoab(np: integer); var dx:double; k,i,j:integer;

begin if fnumpoints>1 then begin dx:=1/np; k:=1; for i:=0 to 3 do begin

j:=1; while k<=fnumpoints do begin if k>fnumpoints then exit; x:=power(10,i)*power(10,j*dx); points[k].ab2:=x; inc(j); inc(k); end; end; end; end;

constructor Tves.create; begin inherited create; symbol:=tsymbol.create; symbol.showname:=true; sympoint:=tsymbol.create; sympoint.showname:=false; FArraytype:=schlumberger; FmDate:='6/10/2004'; FDirection:=120; Fequip:='SAS 4000'; Flocation:='Damascus';

FNumpoints:=0; Foperator:='Talal Albader'; Fproject:='Damas 100'; FStation_No:='ves_1'; fx:=0;fy:=0;fz:=0; fdipolelength:=0; Model.n:=0; fshowmodel:=true; fshowpoints:=true; fmodellineclr:=clblue; fmodellinewidth:=3; end;

destructor Tves.destroy; begin if assigned(symbol) then freeandnil(symbol); if assigned(sympoint) then freeandnil( sympoint);

inherited destroy; end;

procedure Tves.draw(canvas:tcanvas); var i:integer; begin for i:=1 to fnumpoints do chart.DrawSymbol(Canvas,points[i].ab2,points[i].rho,sympoint); end;

procedure Tves.drawmodel(image: timage); var i:integer; x1,y1,x2,y2:integer; begin if model.n<1 then exit; image.Canvas.Pen.Width:=fmodellinewidth; image.Canvas.Pen.Color:=fmodellineclr; x1:=chart.chartrect.Left; x2:=chart.bottomaxis.Topix(model.h[1]); y1:=chart.leftaxis.Topix(model.rho[1]);

y2:=y1;

image.Canvas.MoveTo(x1,y1); image.Canvas.LineTo(x2,y2); for i:=2 to model.n-1 do begin x1:=chart.bottomaxis.Topix(getdepth(i-1)); x2:=chart.bottomaxis.Topix(getdepth(i)); y1:=chart.leftaxis.Topix(model.rho[i]); y2:=y1 ; image.Canvas.MoveTo(x1,y1); image.Canvas.LineTo(x2,y2); end; x1:=chart.bottomaxis.Topix(getdepth(model.n-1)); x2:=chart.chartrect.Right; y1:=chart.leftaxis.Topix(model.rho[model.n]); y2:=y1; image.Canvas.MoveTo(x1,y1); image.Canvas.LineTo(x2,y2); for i:=1 to model.n-1 do begin x1:=chart.bottomaxis.Topix(getdepth(i)); x2:=x1; y1:=chart.leftaxis.Topix(model.rho[i]); y2:=chart.leftaxis.Topix(model.rho[i+1]);

image.Canvas.MoveTo(x1,y1); image.Canvas.LineTo(x2,y2); end;

end;

function Tves.getDepth(idx: integer): double; var i:integer; sum:double; begin result:=0; if model.n>1 then begin sum:=0; if idx<model.n then for i:=1 to idx do sum:=sum+model.h[i]; result:=sum;

end;

end;

procedure Tves.loadfromfile(fn: str200);

VAR I:INTEGER; lines:tstrings; fv:textfile; st:string; begin if fileexists(fn) then begin lines:=tstringlist.Create; assignfile(fv,fn); reset(fv); readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>1 then st:=lines[1]; if uppercase(st[1])= 'S' then farraytype:=schlumberger else if uppercase(st[1])= 'W' then farraytype:= wenner else if uppercase(st[1])= 'D' then farraytype:=dipole;

if farraytype = dipole then begin lines.Clear;

readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>1 then fdipolelength:=strtofloat(lines[1]); end; lines.Clear; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>1 then fstation_No:=lines[1];

lines.Clear; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>1 then fdirection:=strtoint(lines[1]);

lines.Clear; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>1 then fmdate:=lines[1]; if lines.Count>2 then for i:=2 to lines.Count-1 do Fmdate:=fmdate+' '+lines[i];

lines.Clear; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>1 then Fproject:=lines[1]; if lines.Count>2 then for i:=2 to lines.Count-1 do Fproject:=Fproject+' '+lines[i];

lines.Clear; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>1 then Flocation:=lines[1]; if lines.Count>2 then for i:=2 to lines.Count-1 do Flocation:=Flocation+' '+lines[i];

lines.Clear; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>1 then fx:=strtofloat(lines[1]); if lines.Count>2 then

fy:=strtofloat(lines[2]); if lines.Count>2 then fz:=strtofloat(lines[3]);

lines.Clear; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>1 then Foperator:=lines[1]; if lines.Count>1 then for i:=2 to lines.Count-1 do Foperator:=Foperator+' '+lines[i];

lines.Clear; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>1 then Fequip:=lines[1]; if lines.Count>1 then for i:=2 to lines.Count-1 do Fequip:=Fequip+' '+lines[i];

lines.Clear; readln(fv,st);

extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>1 then fremarks:=lines[1]; if lines.Count>1 then for i:=2 to lines.Count-1 do fremarks:=fremarks+' '+lines[i];

lines.Clear; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>1 then fnumpoints:=strtoint(lines[1]);

case farraytype of schlumberger:begin readln(fv); for i:=1 to fnumpoints do begin lines.Clear; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>0 then points[i].ab2:=strtofloat(lines[0]); points[i].rho:=strtofloat(lines[1]); end;

end;

wenner:begin readln(fv); for i:=1 to fnumpoints do begin lines.Clear; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>0 then points[i].ab2:=strtofloat(lines[0]); points[i].rho:=strtofloat(lines[1]);

end; end; dipole:begin readln(fv); for i:=1 to fnumpoints do begin lines.Clear; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>0 then points[i].ab2:=strtofloat(lines[0]); points[i].rho:=strtofloat(lines[1]);

end; end; end;// case

readln(fv); lines.Clear; st:=''; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>0 then model.n:=strtoint(lines[0]); if model.n>0 then for i:=1 to model.n do begin lines.Clear; readln(fv,st); extractstrings([#9,' ',','],[' '],pchar(st),lines); if lines.Count>0 then model.rho[i]:=strtofloat(lines[0]); if lines.Count>1 then model.H[i]:=strtofloat(lines[1]); end;

closefile(fv); end; end;

function Tves.mouseonH(x, y: integer; var idx: integer): boolean; var i:integer; x1,x2,y1,y2:integer; begin result:=false; if model.n<2 then exit;

for i:=1 to model.n-1 do begin x1:=chart.bottomaxis.Topix(getdepth(i)); x2:=x1; y1:=chart.leftaxis.Topix(model.rho[i]); y2:=chart.leftaxis.Topix(model.rho[i+1]); if cursoronline(x,y,x1,y1,x2,y2,2) then begin idx:=i; result:=true; exit; end; end;

end;

function Tves.mouseonpoint(x, y:integer;var idx: integer): boolean; var i:integer; xx1,yy1:integer; found:boolean; begin i:=1; found:=false; result:=false; while (i<=fnumpoints) and not found do begin xx1:=fchart.bottomaxis.Topix(points[i].ab2); yy1:=fchart.leftaxis.Topix(points[i].rho) ; sympoint.x:=xx1; sympoint.y:=yy1;

if sympoint.pointin(x,y) then begin idx:=i; found:=true; result:=true; end; inc(i);

end; end;

function Tves.mouseonR(x, y: integer; var idx: integer): boolean; var i:integer; x1,x2,y1,y2:integer; begin result:=false; if model.n<2 then exit;

x1:=chart.chartrect.Left; x2:=chart.bottomaxis.Topix(model.h[1]); y1:=chart.leftaxis.Topix(model.rho[1]); y2:=y1;

if cursoronline(x,y,x1,y1,x2,y2,2) then begin idx:=1; result:=true; exit; end; for i:=2 to model.n-1 do begin

x1:=chart.bottomaxis.Topix(getdepth(i-1)); x2:=chart.bottomaxis.Topix(getdepth(i)); y1:=chart.leftaxis.Topix(model.rho[i]); y2:=y1 ; if cursoronline(x,y,x1,y1,x2,y2,2) then begin idx:=i; result:=true; exit; end; end; x1:=chart.bottomaxis.Topix(getdepth(model.n-1)); x2:=chart.chartrect.Right; y1:=chart.leftaxis.Topix(model.rho[model.n]); y2:=y1; if cursoronline(x,y,x1,y1,x2,y2,2) then begin idx:=model.n; result:=true; exit; end; end;

procedure Tves.printit(aLeft, atop, aright, abottom: double;addmodel:boolean); var

pp:tprinterop; x1,y1,x2,y2:integer; i,oldsize:integer; begin pp:=tprinterop.create; try pp.chart.assign(chart); pp.chart.setminmax(chart.bottomaxis.Minimum,chart.bottomaxis.Maximum, chart.leftaxis.Minimum,chart.leftaxis.Maximum ); pp.chart.DrawBorder:=true; pp.chart.printit(aLeft, atop, aright, abottom); if fshowpoints then for i:=1 to fnumpoints do begin oldsize:=sympoint.size; sympoint.size:=round(pp.PixelsPerInchX*sympoint.size/screen.PixelsPerInch); pp.chart.DrawSymbol(printer.Canvas,points[i].ab2,points[i].rho,sympoint); sympoint.size:=oldsize; end; if fshowmodel then begin if model.n<1 then exit; printer.Canvas.Pen.Width:=fmodellinewidth; printer.Canvas.Pen.Color:=fmodellineclr;

x1:=pp.chart.chartrect.Left; x2:=pp.chart.bottomaxis.Topix(model.h[1]); y1:=pp.chart.leftaxis.Topix(model.rho[1]); y2:=y1;

printer.Canvas.MoveTo(x1,y1); printer.Canvas.LineTo(x2,y2); for i:=2 to model.n-1 do begin x1:=pp.chart.bottomaxis.Topix(getdepth(i-1)); x2:=pp.chart.bottomaxis.Topix(getdepth(i)); y1:=pp.chart.leftaxis.Topix(model.rho[i]); y2:=y1 ; printer.Canvas.MoveTo(x1,y1); printer.Canvas.LineTo(x2,y2); end; x1:=pp.chart.bottomaxis.Topix(getdepth(model.n-1)); x2:=pp.chart.chartrect.Right; y1:=pp.chart.leftaxis.Topix(model.rho[model.n]); y2:=y1; printer.Canvas.MoveTo(x1,y1); printer.Canvas.LineTo(x2,y2); for i:=1 to model.n-1 do begin x1:=pp.chart.bottomaxis.Topix(getdepth(i));

x2:=x1; y1:=pp.chart.leftaxis.Topix(model.rho[i]); y2:=pp.chart.leftaxis.Topix(model.rho[i+1]); printer.Canvas.MoveTo(x1,y1); printer.Canvas.LineTo(x2,y2); end;

end; finally freeandnil(pp); end; end;

procedure Tves.resetVES; var i:integer; begin

symbol.color:=clred; symbol.size:=6; symbol.x:=0; symbol.y:=0; symbol.srect:=rect(-3,-3,3,3); symbol.color:=clred;

symbol.showname:=true;

sympoint.color:=clred; sympoint.size:=6; sympoint.x:=0; sympoint.y:=0; sympoint.srect:=rect(-3,-3,3,3); sympoint.color:=clred; sympoint.showname:=true;

FArraytype:=schlumberger; FmDate:='6/10/2004'; FDirection:=120; Fequip:='SAS 4000'; Flocation:='Damascus';

Foperator:='Talal Albader'; Fproject:='Damas 100'; FStation_No:='ves_1'; fx:=0;fy:=0;fz:=0; fdipolelength:=0; Model.n:=0; if fnumpoints>0 then for i:=1 to fnumpoints do

with points[i] do begin ab2:=0; rho:=0; end; FNumpoints:=0;

end;

procedure Tves.savetofile(fn: str200); var fv:textfile; i:integer; begin

assignfile(fv,fn); rewrite(fv); case farraytype of schlumberger: writeln(fv,'Array: Schlumberger'); wenner: writeln(fv,'Array: Wenner'); Dipole:begin writeln(fv,'Array: Dipole'); writeln(fv,'dipole_length: ',formatfloat('0.000',fdipolelength)); end; end;

writeln(fv,'Station_No.: ',fstation_No); writeln(fv,'Direction: ',fdirection); writeln(fv,'Date: ',Fmdate); writeln(fv,'Project: ',Fproject); writeln(fv,'Location: ',Flocation); writeln(fv,'Coord.: ',formatfloat('0.000',fx),' ',formatfloat('0.000',fy),' ', formatfloat('0.000',fz)); writeln(fv,'Operator: ',Foperator); writeln(fv,'Equip: ',Fequip); writeln(fv,'Remarks: ',fremarks); writeln(fv,'Num_points: ',fnumpoints); case farraytype of schlumberger:begin writeln(fv,'AB/2 RHO');

for i:=1 to fnumpoints do begin write(fv, formatfloat('0.000',points[i].ab2),' '); writeln(fv,formatfloat('0.000', points[i].rho)); end; end; wenner:begin writeln(fv,'AB/2 RHO_a');

for i:=1 to fnumpoints do begin write(fv, formatfloat('0.000',points[i].ab2),' ');

writeln(fv,formatfloat('0.000', points[i].rho)); end; end; dipole:begin writeln(fv,'ab/2 RHO_a');

for i:=1 to fnumpoints do begin write(fv, formatfloat('0.000',points[i].ab2),' '); writeln(fv,formatfloat('0.000', points[i].rho)); end; end; end;// case

writeln(fv,'********* MODEL ***********'); writeln(fv,model.n) ; if model.n>0 then for i:=1 to model.n-1 do begin write(fv,formatfloat('0.000',model.rho[i]),' '); writeln(fv,formatfloat('0.000',model.h[i]),' '); end; write(fv,formatfloat('0.000',model.rho[model.n]),' ');

closefile(fv);

end;

procedure Tves.SetArraytype(const Value: tarraytype); begin FArraytype := Value; end;

procedure Tves.Setchart(const Value: tgeochart); begin Fchart := Value;

end;

procedure Tves.SetDipolelength(const Value: double); begin FDipolelength := Value; end;

procedure Tves.SetDirection(const Value: integer); begin FDirection := Value; end;

procedure Tves.Setequip(const Value: str100); begin Fequip := Value; end;

procedure Tves.Setlocation(const Value: str100); begin Flocation := Value; end;

procedure Tves.SetMDate(const Value: str100); begin FMDate := Value; end;

procedure Tves.SetNumpoints(const Value: integer);

begin if value<1 then exit; FNumpoints := Value;

end;

procedure Tves.Setoperator(const Value: str100); begin Foperator := Value; end;

procedure Tves.Setproject(const Value: str100); begin Fproject := Value; end;

procedure Tves.SetRemarks(const Value: str200); begin FRemarks := Value; end;

procedure Tves.Setshowpoints(const Value: boolean); begin Fshowpoints := Value; end;

procedure Tves.Setshowmodel(const Value: boolean); begin Fshowmodel := Value;

end;

procedure Tves.SetStation_No(const Value: str100); begin FStation_No := Value; Symbol.Name:=fstation_no; end;

procedure Tves.SetVisible(const Value: boolean); begin FVisible := Value; end;

procedure Tves.SetX(const Value: double); begin FX := Value;

end;

procedure Tves.Sety(const Value: double); begin Fy := Value;

end;

procedure Tves.Setz(const Value: double); begin Fz := Value; end;

procedure Tves.Setmodellineclr(const Value: tcolor); begin Fmodellineclr := Value; end;

procedure Tves.Setmodellinewidth(const Value: byte); begin Fmodellinewidth := Value; end;

{ Tvesproject }

procedure Tvesproject.autominmaxX; var maxx,minx:double; dx:double; tx,i:integer; range:double; begin if fnumves<2 then exit;

maxx:=ves[1].X; minx:=ves[1].X;

for i:=2 to fnumves do begin if ves[i].X>maxx then maxx:=ves[i].X; if ves[i].X<minx then minx:=ves[i].X; end; if minx=maxx then maxx:=minx+10; minx:=minx-10; dx:=(maxx-minx)/10;

map.topaxis.Maximum :=Maxx+dx; map.topaxis.Minimum :=Minx-dx; range:= map.topaxis.Maximum- map.topaxis.Minimum ; tx:=round(range/20); map.topaxis.Majors:=tx*2; map.topaxis.Minors:=tx;

map.bottomaxis.Maximum :=Maxx+dx; map.bottomaxis.Minimum :=Minx-dx; range:= map.bottomaxis.Maximum- map.bottomaxis.Minimum ; tx:=round(range/20); map.bottomaxis.Majors:=tx*2;

map.bottomaxis.Minors:=tx ;

end;

procedure Tvesproject.autominmaxY; var maxy,miny:double; dy:double; tx,i:integer; range:double; begin if fnumves<2 then exit; maxy:=ves[1].y; miny:=ves[1].y; for i:=2 to fnumves do begin if ves[i].y>maxy then maxy:=ves[i].y; if ves[i].y<miny then miny:=ves[i].y; end; if miny=maxy then maxy:=miny+10; miny:=miny-10; dy:=(maxy-miny)/10; map.leftaxis.Maximum :=Maxy+dy; map.leftaxis.Minimum :=Miny-dy;

range:= map.leftaxis.Maximum- map.leftaxis.Minimum ; tx:=round(range/20); map.leftaxis.Majors:=tx*2; map.leftaxis.Minors:=tx ;

map.rightaxis.Maximum :=Maxy+dy; map.rightaxis.Minimum :=Miny-dy; range:= map.rightaxis.Maximum- map.rightaxis.Minimum ; tx:=round(range/20); map.rightaxis.Majors:=tx*2; map.rightaxis.Minors:=tx; end;

procedure Tvesproject.blnkingfile(fn: str200;topo:boolean); var i:integer; fv:textfile; xx,maxz:double; begin assignfile(fv,fn); rewrite(fv); writeln(fv,2*fpronumves+2,' ',0); xx:=0; if topo then begin

writeln(fv,-1,' ',ves[proindexes[1]].z) ; for i:=1 to fpronumves do if i>1 then begin xx:=xx+sqrt(Sqr(abs (ves[proindexes[i]].x -ves[proindexes[i-1]].x))+ sqr(abs( ves[proindexes[i]].y - ves[proindexes[i-1]].y ))); writeln(fv,xx,' ',ves[proindexes[i]].z)

end; maxz:=ves[proindexes[fpronumves]].zves[proindexes[fpronumves]].points[ves[proindexes[fpronumves]].Numpoints].ab2; writeln(fv,xx,' ',maxz); for i:=fpronumves-1 downto 1 do begin xx:=xx-sqrt(Sqr(abs (ves[proindexes[i]].x -ves[proindexes[i+1]].x))+ sqr(abs( ves[proindexes[i]].y - ves[proindexes[i+1]].y ))); maxz:=ves[proindexes[i]].z-ves[proindexes[i]].points[ves[proindexes[i]].Numpoints].ab2; writeln(fv,xx,' ',maxz); end; maxz:=ves[proindexes[1]].z-ves[proindexes[1]].points[ves[proindexes[1]].Numpoints].ab2; writeln(fv,-1,' ',maxz); writeln(fv,-1,' ',ves[proindexes[1]].z) end // topo else begin writeln(fv,-1,' ',0.0) ; for i:=1 to fpronumves do

if i>1 then begin xx:=xx+sqrt(Sqr(abs (ves[proindexes[i]].x -ves[proindexes[i-1]].x))+ sqr(abs( ves[proindexes[i]].y - ves[proindexes[i-1]].y ))); writeln(fv,xx,' ',0.0)

end; maxz:= -ves[proindexes[fpronumves]].points[ves[proindexes[fpronumves]].Numpoints].ab2; writeln(fv,xx,' ',maxz); for i:=fpronumves-1 downto 1 do begin xx:=xx-sqrt(Sqr(abs (ves[proindexes[i]].x -ves[proindexes[i+1]].x))+ sqr(abs( ves[proindexes[i]].y - ves[proindexes[i+1]].y ))); maxz:=-ves[proindexes[i]].points[ves[proindexes[i]].Numpoints].ab2; writeln(fv,xx,' ',maxz); end; maxz:=-ves[proindexes[1]].points[ves[proindexes[1]].Numpoints].ab2 ; writeln(fv,-1,' ',maxz); writeln(fv,-1,' ',0.0) end; closefile(fv); end;

constructor Tvesproject.create;

begin

map:=tgeochart.create; fnumves:=0; map.panelcolor:=clwhite; map.bordercolor:=clblack; map.leftaxis.FontColor:=clblack; map.leftaxis.Majorscolor:=clblack; fdrawprofileline:=false; fpronumves:=0; fprofileselected:=false; map.bottomaxis.FontColor:=clblack; map.bottomaxis.Majorscolor:=clblack;

map.topaxis.FontColor:=clblack; map.topaxis.Majorscolor:=clblack;

map.rightaxis.FontColor:=clblack; map.rightaxis.Majorscolor:=clblack;

map.leftaxis.ShowMajorgrid:=false; map.leftaxis.ShowMinorgrid:=false; map.bottomaxis.ShowMajorgrid:=false; map.bottomaxis.ShowMinorgrid:=false; map.topaxis.ShowMinorgrid:=false; map.rightaxis.ShowMinorgrid:=false; map.topaxis.ShowMajorgrid:=false;

map.rightaxis.ShowMajorgrid:=false; map.showtopaxis:=true; map.showrightaxis:=true; map.rightaxis.TicksStyle:=tsinner; map.topaxis.TicksStyle:=tsinner; map.leftaxis.TicksStyle:=tsinner; map.bottomaxis.TicksStyle:=tsinner;

map.leftaxis.Title:='Northing'; map.bottomaxis.Title:='Easting'; map.rightaxis.Title:='Northing'; map.topaxis.Title:='Easting';

prochart:=tgeochart.create; with prochart do begin horizaxis:=habottom; vertaxis:=valeft;

horizaxis:=habottom; leftaxis.Reverse:=false; bottomaxis.Reverse:=false; vertaxis:=valeft; leftmargin:=0; topmargin:=20;

bottommargin:=0; rightmargin:=110; bottomaxis.ShowMajorgrid:=false; bottomaxis.ShowMinorgrid:=false; leftaxis.ShowMinorgrid:=false; leftaxis.Title:='Resistivity / ohm.m'; bottomaxis.Title:='Destance/ m'; panelcolor:=clwhite; leftaxis.TicksStyle:=tsouter; leftaxis.Majors:=50; leftaxis.Minors:=10; bottomaxis.Majors:=50; bottomaxis.Minors:=10; bottomaxis.TicksStyle:=tsouter; setminmax(0,1000,0,1000);

end; end;

procedure Tvesproject.crossSection(fn:str200;topo:boolean); var i,j:integer; fv:textfile; xx,yy:double; begin

if fpronumves<2 then exit; if fpronumves > fnumves then exit; assignfile(fv,fn); rewrite(fv); xx:=0; writeln(fv,'"X","z","Rho_a"'); for i:=1 to fpronumves do begin if i=1 then xx:=0 else xx:=xx+sqrt(Sqr(abs (ves[proindexes[i]].x -ves[proindexes[i-1]].x))+ sqr(abs( ves[proindexes[i]].y - ves[proindexes[i-1]].y )));

for j:=1 to ves[proindexes[i]]. Numpoints do begin if topo then yy:= ves[proindexes[i]].z-ves[proindexes[i]].points[j].ab2 else yy:= -ves[proindexes[i]].points[j].ab2; writeln(fv,xx:15:4,' ',yy:15:4,' ',ves[proindexes[i]].points[j].rho:15:4); end;

end;

closefile(fv);

end;

destructor Tvesproject.destroy; var i:integer; begin if fnumves>0 then for i:=1 to fnumves do if assigned(ves[i]) then ves[i].Free; inherited; end;

procedure Tvesproject.Draw(var image:timage); var i:integer; xx1,xx2,yy1,yy2,xx,yy,dx,dy:integer; begin map.leftmargin:=10; map.topmargin:=10; map.rightmargin:=10; map.bottommargin:=10;

map.Draw; image.AutoSize:=true; image.Picture.Assign(map.Bitmap); image.AutoSize:=false; if (fdrawprofileline) and (fpronumves >1) then begin image.Canvas.Pen.Color:=flineclr; for i:=1 to fpronumves-1 do map.Drawline(image.Canvas,ves[proindexes[i]].X,ves[proindexes[i]].y, ves[proindexes[i+1]].x,ves[proindexes[i+1]].y);

end; for i:=1 to fnumves do if VES[i].Visible then begin if fshowdir then begin image.Canvas.Pen.Color:=ves[i].symbol.color; dx:=round(2*ves[i].Symbol.size*sin(degtorad(ves[i].Direction))); dy:=round(2*ves[i].Symbol.size*cos(degtorad(ves[i].Direction))); xx:=map.bottomaxis.Topix(ves[i].X); yy:=map.leftaxis.Topix(ves[i].y) ; xx1:=xx+dx; xx2:=xx-dx; yy1:=yy-dy;

yy2:=yy+dy; image.Canvas.MoveTo(xx1,yy1); image.Canvas.LineTo(xx2,yy2); end; ves[i].Symbol.showname:= fshowlabels; image.Canvas.Pen.Color:=clblack; map.DrawSymbol(image.Canvas,ves[i].X,ves[i].y,ves[i].symbol); if fselectedID=i then ves[i].Symbol.drawselect(image.Canvas,clred); end; // profile line

end;

procedure Tvesproject.inhomo(fn: str200;topo:boolean); var i,j,k,m:integer; line1,line2:tlinerec; a,b,rho,zm:double; xm,x1,x2:double; fv:textfile; oldx,oldr,oldz:double; dz,zz:double; begin

if fpronumves<2 then exit; if fpronumves >numves then exit;

assignfile(fv,fn); rewrite(fv); writeln(fv,'" X "," Z ","Rho"'); x1:=0; oldx:=-1000; oldz:=0.00001; oldr:=-1000; for i:=1 to fpronumves-1 do begin x2:=x1+sqrt(Sqr(ves[proindexes[i+1]].x -ves[proindexes[i]].x)+ sqr(ves[proindexes[i+1]].y - ves[proindexes[i]].y ));

if ves[proindexes[i]].Numpoints>ves[proindexes[i+1]].Numpoints then m:= ves[proindexes[i+1]].Numpoints else m:= ves[proindexes[i]].Numpoints; for j:=1 to m-1 do for k:=j+1 to m do begin line1.x1:=x1; line1.x2:=x2; line1.y1:=ves[proindexes[i]].points[j].rho;

line1.y2:=ves[proindexes[i+1]].points[j].rho; line2.x1:=x1; line2.x2:=x2; line2.y1:=ves[proindexes[i]].points[k].rho; line2.y2:=ves[proindexes[i+1]].points[k].rho; if intersect(line1,line2,xm,rho) then begin

dz:=(ves[proindexes[i]].points[j].ab2+ves[proindexes[i]].points[k].ab2)/2; if topo then begin a:=(ves[proindexes[i+1]].z-ves[proindexes[i]].z)/(x2-x1); b:=ves[proindexes[i]].z-a*x1; zz:=a*xm+b; zm:=zz-dz; if (xm<>oldx) and (rho<>oldr) and (zm<>oldz) then begin writeln(fv,xm:15:4,' ',zm:15:4,' ',rho:15:4); oldz:=zm; oldx:=xm;oldr:=rho; end; end else begin if (xm<>oldx) and (rho<>oldr) and (-dz<>oldz) then begin writeln(fv,xm:15:4,' ',-dz:15:4,' ',rho:15:4);

oldz:=-dz; oldx:=xm;oldr:=rho; end; end; end; end;// for j x1:=x2; end;// for i closefile(fv);

end;

procedure Tvesproject.loadfromlist(files: tstrings); var i:integer;

begin fnumves:=files.Count; for i:=1 to fnumves do begin if assigned(ves[i]) then ves[i].Free; ves[i]:=tves.create; ves[i].loadfromfile(files[i-1]); ves[i].Symbol.Name:=ves[i].Station_No; end;

autominmaxX; autominmaxY;

end;

procedure Tvesproject.savetofile(fn: str200); var i,k:integer; fv:textfile;

astr:string; begin if fnumves<1 then exit; assignfile(fv,fn); rewrite(fv); writeln(fv,fnumves);

for K:=1 to numves do with ves[k] do begin writeln(fv,'==============( VES ',k,' )=============='); case arraytype of schlumberger: astr:='Schlumberger'; wenner: astr:='Wenner'; Dipole: astr:='Dipole';

end; // case if project='' then project :=' '; if location='' then location :=' '; if station_No='' then station_No :=' '; if mdate='' then mdate :=' '; if operator='' then operator :=' '; if equip='' then equip :=' '; writeln(fv,project,tab,location,tab,station_No,tab,astr,tab, mdate,tab,operator,tab,equip); writeln(fv,numpoints:6,x:10:2,y:10:2,z:10:2,direction:10,dipolelength:10:2); writeln(fv,remarks); for i:=1 to ves[k].numpoints do write(fv, points[i].ab2:10:2,' '); writeln(fv); for i:=1 to ves[k].numpoints do write(fv,points[i].rho:10:2,' '); writeln(fv);

write(fv,'Model: '); writeln(fv,model.n); write(fv,'Thickness: '); if model.n>1 then for i:=1 to model.n-1 do write(fv,model.h[i],' '); writeln(fv);

write(fv,'Resistivity: '); if model.n>0 then for i:=1 to model.n do write(fv,model.rho[i],' '); writeln(fv);

end;// for k closefile(fv); end;

procedure Tvesproject.loadfromfile(fn: str200); var i,k:integer; fv:textfile; st1,st,astr:string; lines:tstrings; xx,yy,zz,diplen:double ; n,adir:integer;

begin if fileexists(fn) then begin if fnumves>0 then for i:=1 to numves do if assigned(ves[i]) then ves[i].Free;

lines:=tstringlist.Create; assignfile(fv,fn); reset(fv); readln(fv,fnumves); if fnumves>0 then for i:=1 to numves do ves[i]:=tves.create; for K:=1 to numves do with ves[k] do begin readln(fv); ves[k].chart:=fchart; readln(fv,st1); lines.clear; extractstrings([tab,','],[' '],pchar(st1),lines); project:=lines[0]; astr:=project; location:=lines[1]; astr:= location ; station_No:=lines[2]; astr:= station_No ; astr:=lines[3] ; if uppercase(astr[1])= 'S' then arraytype:=schlumberger

else if uppercase(astr[1])= 'W' then arraytype:= wenner else if uppercase(astr[1])= 'D' then arraytype:=dipole; mdate:=lines[4]; operator:=lines[5]; equip:=lines[6];

readln(fv,n,xx,yy,zz,adir,diplen); numpoints:=n; x:=xx; y:=yy; z:=zz; direction:=adir; dipolelength:=diplen; readln(fv,astr); remarks:=astr; st:=''; lines.Clear; readln(fv,st); extractstrings([tab,' ',','],[' '],pchar(st),lines); for i:=1 to ves[k].numpoints do points[i].ab2:=strtofloat(lines[i-1]); st:=''; lines.Clear;

readln(fv,st); extractstrings([tab,' ',','],[' '],pchar(st),lines); for i:=1 to ves[k].numpoints do points[i].rho:=strtofloat(lines[i-1]);

// reading the model prameters

st:=''; lines.Clear; readln(fv,st); extractstrings([tab,' ',','],[' '],pchar(st),lines); if lines.Count>0 then model.n:=strtoint(lines[1]); st:=''; lines.Clear; readln(fv,st); extractstrings([tab,' ',','],[' '],pchar(st),lines); // reading thicknesses if model.n>1 then for i:=1 to model.n-1 do model.H[i]:=strtofloat(lines[i]); // reading resistivities st:=''; lines.Clear; readln(fv,st);

extractstrings([tab,' ',','],[' '],pchar(st),lines); if model.n>0 then for i:=1 to model.n do model.rho[i]:=strtofloat(lines[i]);

end;// for k closefile(fv); end; end; procedure Tvesproject.Setnumves(const Value: integer); begin Fnumves := Value; end;

procedure TgeoChart.Setbkbitmap(const Value: tbitmap); begin Fbkbitmap := Value; end;

procedure TgeoChart.Setshowbkbitmap(const Value: boolean); begin Fshowbkbitmap := Value;

end;

destructor TgeoChart.destroy; begin fbitmap.Free; fbkbitmap.Free; leftaxis.Free; rightaxis.Free; topaxis.Free; bottomaxis.Free; inherited; end;

procedure TgeoChart.drawtoimage(image: timage); begin draw; image.Picture.Assign(fbitmap); end;

procedure TgeoChart.setallcolors(borderclr, panelclr, bkclr, fontclr, majorclr, minorclr: tcolor); begin fbordercolor:=borderclr; fpanelcolor:=panelclr; fbkcolor:= bkclr;

leftaxis.FontColor:= fontclr; leftaxis.Majorscolor:=majorclr; leftaxis.MinorsColor:=minorclr; rightaxis.FontColor:= fontclr; rightaxis.Majorscolor:=majorclr; rightaxis.MinorsColor:=minorclr; topaxis.FontColor:= fontclr; topaxis.Majorscolor:=majorclr; topaxis.MinorsColor:=minorclr; bottomaxis.FontColor:= fontclr; bottomaxis.Majorscolor:=majorclr; bottomaxis.MinorsColor:=minorclr;

end;

procedure TgeoChart.setaxistype(horizaxis,vertaxis:tgaxistype); begin leftaxis.AxisType:=vertaxis ; rightaxis.AxisType:=vertaxis ; topaxis.AxisType:=horizaxis; bottomaxis.AxisType:=horizaxis;

end;

procedure TgeoChart.setallticks(major, minor: integer);

begin leftaxis.Majors:= major; leftaxis.Minors:=minor;

rightaxis.Majors:= major; rightaxis.Minors:=minor;

topaxis.Majors:= major; topaxis.Minors:=minor;

bottomaxis.Majors:= major; bottomaxis.Minors:=minor; end;

procedure TgeoChart.setchartrect(arect: trect); var th:integer; begin fchartrect:=arect; th:=fbitmap.Canvas.TextHeight('0')*2+15; fleftmargin:=fchartrect.Left-th; ftopmargin:=fchartrect.Top-th ; frightmargin:=fwidth-fchartrect.Right-th ; fbottommargin:=fheight-fchartrect.Bottom-th;

end;

procedure TgeoChart.Settransparent(const Value: boolean); begin Ftransparent := Value; end;

procedure Tvesproject.vesloc(fn: str200;topo:boolean); var fv:textfile; i:integer; xx:double; begin assignfile(fv,fn); rewrite(fv); xx:=0; writeln(fv,'"X","z","Ves_name"'); for i:=1 to fpronumves do begin if i=1 then xx:=0 else xx:=xx+sqrt(Sqr(abs (ves[proindexes[i]].x -ves[proindexes[i-1]].x))+ sqr(abs( ves[proindexes[i]].y - ves[proindexes[i-1]].y ))); if topo then

writeln(fv,xx,' ',ves[proindexes[i]].z,' ', ves[proindexes[i]].Station_No,' ',21) else writeln(fv,xx,' ',0.0,' ', ves[proindexes[i]].Station_No,' ',21); end; closefile(fv); end;

procedure TgeoChart.loadbkfromfile(fn: str200); var ext:str100; begin if fileExists(fn ) then begin ext:=extractfileext(fn); if uppercase(ext)='.BMP' then Fbkbitmap.LoadFromFile(fn) else if uppercase(ext)='.JPG' then fbkbitmap:=jpeg2bitmap(fn);

end else messagedlg('File not found',mterror,[mbok],0); end;

procedure Tvesproject.DeleteVes(id: integer); var i:integer; begin for i:=id to fnumves-1 do VES[i].assign(ves[i+1]);

//VES[numves].Free; fnumves:=fnumves-1; end;

procedure Tvesproject.insertVES(id: integer; vs: tves); var i:integer; begin if id<1 then begin fnumves:=1; if assigned(ves[1]) then ves[1].Free; ves[1]:=tves.create; ves[1].assign(vs); end else begin if (id>fnumves) then exit;

fnumves:=fnumves+1; if assigned(ves[fnumves]) then ves[fnumves].Free;

ves[fnumves]:=tves.create; if id=fnumves-1 then begin ves[fnumves].assign(vs); end else begin for i:=fnumves downto id+1 do ves[i].assign(ves[i-1]);

ves[id].assign(vs); end; end; end;

procedure Tvesproject.Setprofileselected(const Value: boolean); var i:integer; begin

Fprofileselected := Value; if not (Fprofileselected) then begin if fpronumves>1 then for i:=1 to fpronumves do proindexes[i]:=0; pronumves:=0; end; end;

procedure Tvesproject.Setpronumves(const Value: integer); begin Fpronumves := Value; end;

procedure Tvesproject.Setdrawprofileline(const Value: boolean); begin Fdrawprofileline := Value; end;

constructor TprinterOp.create; begin inherited create; scalingx:=2.54;

scalingy:=2.54; chart:=tgeochart.create; chart.width:=pagewidth; chart.height:=pageheight; end;

function TprinterOp.GetPageWidth: Integer; begin result := GetDeviceCaps(Printer.Handle, PHYSICALWIDTH) end;

function TprinterOp.GetPageHeight: Integer; begin result := GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT) end;

function TprinterOp.GetPageOffsetLeft: Integer; begin result := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX) end;

function TprinterOp.GetPageOffsetRight: Integer; begin result := GetPageWidth - GetPageOffsetLeft - GetDeviceCaps(Printer.Handle, HORZRES) end;

function TprinterOp.GetPageOffsetTop: Integer; begin result := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY) end;

function TprinterOp.GetPageOffsetBottom: Integer; begin result := GetPageHeight - GetPageOffsetTop - GetDeviceCaps(Printer.Handle, VERTRES) end;

function TprinterOp.GetPixelsPerInchX: Integer; begin result := GetDeviceCaps(Printer.Handle, LOGPIXELSX) end;

function TprinterOp.GetPixelsPerInchY: Integer; begin result := GetDeviceCaps(Printer.Handle, LOGPIXELSY) end;

procedure TprinterOp.SetscalingX(const Value: double); begin FscalingX := Value; end;

procedure TprinterOp.Setscalingy(const Value: double); begin Fscalingy := Value; end;

function TprinterOp.CmtopixelsX(cm: double): integer; begin result:=round(cm*GetPixelsPerInchX/scalingX); end;

function TprinterOp.IntopixelsX(inches: double): integer; begin result:=round(inches*GetPixelsPerInchX) ; end;

function TprinterOp.CmtopixelsY(cm: double): integer; begin result:=round(cm*GetPixelsPerInchY/scalingY); end;

function TprinterOp.IntopixelsY(inches: double): integer; begin result:=round(inches*GetPixelsPerInchY) ; end;

procedure Tvesproject.initprofiles; const colors:array[1..50] of tcolor= ( clblack ,clblue ,clred ,clgreen ,clgray,

clmaroon,clolive ,clpurple ,clteal ,cllime, claqua ,clfuchsia,clmoneygreen,clskyblue,clyellow, clblack ,clblue ,clred ,clgreen ,clgray,

clmaroon,clolive ,clpurple ,clteal ,cllime, claqua ,clfuchsia,clmoneygreen,clskyblue,clyellow , clblack ,clblue ,clred ,clgreen ,clgray,

clmaroon,clolive ,clpurple ,clteal ,cllime, claqua ,clfuchsia,clmoneygreen,clskyblue,clyellow, clblack ,clblue ,clred ,clgreen ,clgray);

var

i,j:integer; v,xx,y1,y2:double;

x:Trealarray; dd:integer; minx,maxx,miny,maxy:double; maxabindx,maxab:integer; nv:integer; xx2,yy1,yy2:integer; begin if fpronumves >0 then for i:=1 to fpronumves do // Max number of polygons if assigned(profiles[i]) then begin profiles[i].Free; profiles[i]:=nil; end; if (fpronumves>1) and Fprofileselected then begin // maxabindx:=1; maxab:=ves[proindexes[1]].Numpoints; for i:=2 to fpronumves do if ves[proindexes[i]].Numpoints>maxab then begin maxab:=ves[proindexes[i]].Numpoints; maxabindx:=i; // you have detect a profileline

end; // if ves for i:=1 to maxab do begin v:=ves[proindexes[maxabindx]].points[i].ab2 ; profiles[i]:=tgrealpoly.create; profiles[i].visible:=true; profiles[i].Setcolors(clred); profiles[i].ID:=floattostr(v) ; profiles[i].chart:=prochart; end; // for i // calculating X values for i:=1 to fpronumves do x[i]:=0; xx:=0; x[1]:=xx; for i:=2 to fpronumves do begin xx:=xx+sqrt(Sqr(ves[proindexes[i]].x -ves[proindexes[i-1]].x)+ sqr( ves[proindexes[i]].y - ves[proindexes[i-1]].y )); x[i]:=xx; end; minx:=x[1]; maxx:=x[pronumves];

// calculating miny and maxy

miny:=100000; maxy:=-100; for j:=1 to maxab do for i:=1 to fpronumves do if ( j<=ves[proindexes[i]].Numpoints) then begin y1:=ves[proindexes[i]].points[j].rho; if y1 < miny then miny:= y1 ; if y1 > maxy then maxy:= y1; end; prochart.bottomaxis.Maximum:=maxx; prochart.bottomaxis.Minimum:=minx; prochart.leftaxis.Maximum:=maxy+0.1* Maxy; prochart.leftaxis.Minimum:=miny -0.2*Miny ; // for j:=1 to maxab do begin nv:=0; for i:=1 to fpronumves-1 do if ( j<=ves[proindexes[i]].Numpoints) and ( j<=ves[proindexes[i+1]].Numpoints) then inc(nv);

inc(nv); profiles[j].numV:=nv ; end;

// for j:=1 to maxab do if j<=50 then profiles[j].Setcolors(colors[j]) else profiles[j].Setcolors(clblack);

//

for j:=1 to maxab do begin dd:=1; for i:=1 to fpronumves-1 do if ( j<=ves[proindexes[i]].Numpoints)and ( j<=ves[proindexes[i+1]].Numpoints) begin y1:=ves[proindexes[i]].points[j].rho; y2:=ves[proindexes[i+1]].points[j].rho; profiles[j].vertex[dd].x1:=x[i] ; profiles[j].vertex[dd].x2:=x[i+1] ; profiles[j].vertex[dd].y1:=y1 ; then

profiles[j].vertex[dd].y2:=y2 ; inc(dd); end; end;

fnumprofiles:=maxab;

end;// if profile selected

end;

procedure Tvesproject.SetNumprofiles(const Value: integer); begin FNumprofiles := Value; end;

procedure Tvesproject.Drawprofiles(var image: timage); var i,yy1,xx1,xx2,tx,ty:integer; r:trect; begin

if prochart.rightmargin<120 then prochart.rightmargin:=120; prochart.drawtoimage(image);

xx1:=prochart.chartrect.Right+image.Canvas.TextWidth(profiles[fnumprofiles].ID)+15; r.Left:=xx1-image.Canvas.TextWidth(profiles[fnumprofiles].ID)-5; xx2:=xx1+30; r.Right:=xx2+5; yy1:=prochart.chartrect.Top; r.Top:=yy1; image.Canvas.Font.Color:=prochart.leftaxis.FontColor; yy1:=yy1+image.Canvas.TextHeight('A') div 2; r.Bottom:=yy1+image.Canvas.TextHeight('A'); for i:=1 to fnumprofiles do if profiles[i].visible then r.Bottom:=r.Bottom+image.Canvas.TextHeight('A');

image.Canvas.Brush.Color:=clsilver; image.Canvas.FillRect(rect(r.Left+3,r.Top+3,r.Right+3,r.Bottom+3)); image.Canvas.Brush.Color:=prochart.bkcolor; image.Canvas.Rectangle(r);

image.Canvas.TextOut(xx1-image.Canvas.TextWidth('AB/2'),r.Top+2,'AB/2');

for i:=1 to fnumprofiles do if profiles[i].visible then with profiles[i].vertex[profiles[i].numV] do begin yy1:=yy1+image.Canvas.TextHeight('A');

tx:=xx1-image.Canvas.TextWidth(profiles[i].ID) -3; ty:=yy1-image.Canvas.TextHeight('A') div 2; image.Canvas.TextOut(tx,ty,profiles[i].ID); x1:=prochart.bottomaxis.Toval(xx1); x2:=prochart.bottomaxis.Toval(xx2); y1:=prochart.leftaxis.Toval(yy1); y2:=y1;

end;

for i:=1 to fNumprofiles do if profiles[i].visible then profiles[i].Drawline(image.Canvas);

end;

procedure Tvesproject.Setchart(const Value: tgeochart); var i:integer; begin Fchart := Value; if fnumves>0 then for i:=1 to fnumves do ves[i].chart:=fchart;

end;

procedure Tvesproject.SetshowDir(const Value: boolean); begin FshowDir := Value; end;

procedure Tvesproject.Setlineclr(const Value: tcolor); begin Flineclr := Value; end;

procedure Tvesproject.Setshowlabels(const Value: boolean); begin Fshowlabels := Value; end;

procedure Tvesproject.SetSelectedID(const Value: integer); begin FSelectedID := Value; end;

procedure Tvesproject.printmap(aleft, atop, aright, abottom: double); var pp:tprinterop;

i,oldsize,OLDSPC:integer; xx1,xx2,yy1,yy2,xx,yy,dx,dy:integer; begin pp:=tprinterop.create; Try pp.chart.assign(map); // pp.chart.setminmax(map.bottomaxis.Minimum,map.bottomaxis.Maximum, // map.leftaxis.Minimum,map.leftaxis.Maximum);

pp.chart.DrawBorder:=false; pp.chart.printit(aleft, atop, aright, abottom); if (fdrawprofileline) and (fpronumves >1) then begin printer.Canvas.Pen.Color:=flineclr; for i:=1 to fpronumves-1 do pp.chart.Drawline(printer.Canvas,ves[proindexes[i]].X,ves[proindexes[i]].y, ves[proindexes[i+1]].x,ves[proindexes[i+1]].y); end; for i:=1 to fnumves do if VES[i].Visible then begin oldsize:= ves[i].Symbol.size; Oldspc:= ves[i].Symbol.spacing; ves[i].Symbol.size:=round(pp.PixelsPerInchX*ves[i].Symbol.size/ screen.PixelsPerInch); ves[i].Symbol.spacing:=round(pp.PixelsPerInchX*ves[i].Symbol.spacing/

screen.PixelsPerInch);

if fshowdir then begin

printer.Canvas.Pen.Color:=ves[i].symbol.color; dx:=round(2*ves[i].Symbol.size*sin(degtorad(ves[i].Direction))); dy:=round(2*ves[i].Symbol.size*cos(degtorad(ves[i].Direction))); xx:=pp.chart.bottomaxis.Topix(ves[i].X); yy:=pp.chart.leftaxis.Topix(ves[i].y) ; xx1:=xx+dx; xx2:=xx-dx; yy1:=yy-dy; yy2:=yy+dy; printer.Canvas.MoveTo(xx1,yy1); printer.Canvas.LineTo(xx2,yy2); end; ves[i].Symbol.showname:= fshowlabels; printer.Canvas.Pen.Color:=clblack; pp.chart.DrawSymbol(printer.Canvas,ves[i].X,ves[i].y,ves[i].symbol); if fselectedID=i then ves[i].Symbol.drawselect(printer.Canvas,clred); ves[i].Symbol.size:=oldsize; ves[i].Symbol.spacing:=oldspc; end;

finally freeandnil(pp); end;// try end; procedure Tvesproject.printprofile(aleft, atop, aright, abottom: double); var i,yy1,xx1,xx2,tx,ty:integer; r:trect; pp:tprinterop;

begin pp:=tprinterop.create; Try pp.chart.assign(prochart); // pp.chart.setminmax(prochart.bottomaxis.Minimum,prochart.bottomaxis.Maximum, // prochart.leftaxis.Minimum,prochart.leftaxis.Maximum);

pp.chart.printit(aleft, atop, aright, abottom);

xx1:=pp.chart.chartrect.Right+printer.Canvas.TextWidth(profiles[fnumprofiles].ID)+pp.CmtopixelsX(2); r.Left:=xx1-printer.Canvas.TextWidth(profiles[fnumprofiles].ID)-pp.CmtopixelsX(0.5); xx2:=xx1+pp.CmtopixelsX(1.2); r.Right:=xx2+pp.CmtopixelsX(0.5);; yy1:=pp.chart.chartrect.Top; r.Top:=yy1; printer.Canvas.Font.Color:=pp.chart.leftaxis.FontColor;

yy1:=yy1+printer.Canvas.TextHeight('A') div 2; r.Bottom:=yy1+printer.Canvas.TextHeight('A'); for i:=1 to fnumprofiles do if profiles[i].visible then r.Bottom:=r.Bottom+printer.Canvas.TextHeight('A');

printer.Canvas.Brush.Color:=clsilver; printer.Canvas.FillRect(rect(r.Left+pp.CmtopixelsX(0.3),r.Top+pp.CmtopixelsX(0.3), r.Right+pp.CmtopixelsX(0.3),r.Bottom+pp.CmtopixelsX(0.3))); printer.Canvas.Brush.Color:=pp.chart.bkcolor; printer.Canvas.Rectangle(r);

printer.Canvas.TextOut(xx1-printer.Canvas.TextWidth('AB/2'),r.Top+2,'AB/2');

for i:=1 to fnumprofiles do if profiles[i].visible then with profiles[i].vertex[profiles[i].numV] do begin yy1:=yy1+printer.Canvas.TextHeight('A'); tx:=xx1-printer.Canvas.TextWidth(profiles[i].ID) -pp.CmtopixelsX(0.3); ty:=yy1-printer.Canvas.TextHeight('A') div 2; printer.Canvas.TextOut(tx,ty,profiles[i].ID); x1:=pp.chart.bottomaxis.Toval(xx1); x2:=pp.chart.bottomaxis.Toval(xx2); y1:=pp.chart.leftaxis.Toval(yy1);

y2:=y1;

end;

for i:=1 to fNumprofiles do if profiles[i].visible then profiles[i].Drawlineat(printer.Canvas,pp.chart); for i:=1 to fNumprofiles do profiles[i].chart:=chart; finally Freeandnil(pp); end;//try end;

procedure Tvesproject.Sectioninfo(fn: str200;topo:boolean); var i:integer; fv:textfile; xx:double; col1:integer; col2,col3,col4:double; begin assignfile(fv,fn); rewrite(fv); writeln(fv,fpronumves);

writeln(fv,'index x z maxab'); xx:=0; col1:=proindexes[1]; col2:=xx; col3:=ves[proindexes[1]].z ; col4:=ves[proindexes[1]].points[ves[proindexes[1]].Numpoints].ab2; writeln(fv,col1,' ',col2,' ',col3,' ',col4) ; for i:=1 to fpronumves do if i>1 then begin xx:=xx+sqrt(Sqr(abs (ves[proindexes[i]].x -ves[proindexes[i-1]].x))+ sqr(abs( ves[proindexes[i]].y - ves[proindexes[i-1]].y ))); col1:=proindexes[i]; col2:=xx; if topo then col3:=ves[proindexes[i]].z else col3:=0; col4:=ves[proindexes[i]].points[ves[proindexes[i]].Numpoints].ab2; writeln(fv,col1,' ',col2,' ',col3,' ',col4) ; end; closefile(fv);

end;

procedure Tvesproject.GeoSect(fn: str200; topo: boolean);

var i,j:integer; fv:textfile; xx,yy:double; begin assignfile(fv,fn); rewrite(fv); xx:=0; writeln(fv,'"X","z","rho"'); for i:=1 to fpronumves do if ves[proindexes[i]].model.n>0 then begin if i=1 then xx:=0 else xx:=xx+sqrt(Sqr(abs (ves[proindexes[i]].x -ves[proindexes[i-1]].x))+ sqr(abs( ves[proindexes[i]].y - ves[proindexes[i-1]].y )));

if ves[proindexes[i]].model.n>1 then for j:=1 to ves[proindexes[i]].model.n-1 do begin if topo then yy:= ves[proindexes[i]].z-ves[proindexes[i]].Model.h[j] else yy:= -ves[proindexes[i]].Model.h[j]; writeln(fv,xx:15:4,' ',yy:15:4,' ',ves[proindexes[i]].Model.rho[j]:15:4);

end; if topo then yy:= ves[proindexes[i]].zves[proindexes[i]].points[ves[proindexes[i]].Numpoints].ab2 else yy:=-ves[proindexes[i]].points[ves[proindexes[i]].Numpoints].ab2; writeln(fv,xx:15:4,' ',yy,' ',ves[proindexes[i]].Model.rho[ves[proindexes[i]].Model.n]:15:4); end; closefile(fv); end;

{ TGline }

constructor TGline.create; begin inherited create; fx1:=0; fy1:=0; fx2:=10; fy2:=10; fcolor:=clblack; fstyle:=pssolid; fwidth:=1; end;

procedure TGline.Draw(canvas:tcanvas;penmode:tpenmode); var pen:tpen; begin pen:=tpen.Create;

pen.Assign(canvas.Pen); canvas.pen.color:=fcolor; canvas.Pen.Width:=fwidth; canvas.Pen.Style:=fstyle; canvas.Pen.Mode:=penmode; Canvas.MoveTo(fx1,fy1); Canvas.LineTo(fx2,fy2); canvas.Pen.Assign(pen); end;

function TGline.pointin(x, y: integer): boolean; begin result:= cursorOnline(x,y,x1,y1,x2,y2,fwidth); end;

procedure TGline.Setcolor(const Value: tcolor); begin Fcolor := Value; end;

procedure TGline.Setselected(const Value: boolean); begin Fselected := Value; end;

procedure TGline.Setstyle(const Value: tpenstyle); begin Fstyle := Value; end;

procedure TGline.Setwidth(const Value: byte); begin Fwidth := Value; end;

procedure TGline.Setx1(const Value: integer); begin Fx1 := Value;

end;

procedure TGline.Setx2(const Value: integer); begin Fx2 := Value; end;

procedure TGline.Sety1(const Value: integer); begin Fy1 := Value; end;

procedure TGline.Sety2(const Value: integer); begin Fy2 := Value; end;

{ Tgpoly }

procedure Tgpoly.add(vrtx: tgline);

begin inc(fnumv); if assigned (vertex[fnumv]) then vertex[fnumv].Free; vertex[fnumv]:=tgline.create;

with vertex[fnumv] do begin x1:=vrtx.x1; y1:=vrtx.y1; x2:=vrtx.x2; y2:=vrtx.y2; color:=vrtx.color; style:=vrtx.style; width:=vrtx.width; end; end;

constructor Tgpoly.create; begin inherited create; fnumV:=0; fid:='poly1' ; visible:=true; modefied:=false; end;

destructor Tgpoly.destroy; var i:integer; begin

if fnumv>0 then for i:=1 to fnumv do if assigned(vertex[i]) then begin vertex[i].Free; vertex[i]:=nil; end; inherited destroy; end;

procedure Tgpoly.Drawarea(canvas: tcanvas); var p:array of tpoint; i:integer; begin if (fnumv>2) and (visible) then begin SetLength(p, fnumv+1); for i:=1 to fnumv do begin p[i-1].X:=vertex[i].x1; p[i-1].Y:=vertex[i].y1; end; p[numv].X:=vertex[fnumv].x2; p[numv].Y:=vertex[fnumv].y2;

canvas.Polygon(p); SetLength(p,0); end;

end;

procedure Tgpoly.Drawline(canvas: tcanvas); var i:integer; begin if (fnumv>0) and (visible) then for i:=1 to fnumv do vertex[i].Draw(canvas,pmcopy);

end;

function Tgpoly.pointin(x, y: integer; var idx: integer): boolean; var i:integer; done:boolean; begin result:=false; if fnumv>0 then begin

i:=1; done:=false;

while (i<=fnumv)and not done do begin if vertex[i].pointin(x,y) then begin idx:=i; result:=true; done:=true; end else begin result:=false; done:=false; end; inc(i); end; end; end;

procedure Tgpoly.Setcolors(color: tcolor); var i:integer; begin if fnumv>0 then

for i:=1 to fnumv do vertex[i].color:=color; end;

procedure Tgpoly.SetID(const Value: str100); begin FID := Value; end;

procedure Tgpoly.Setmodefied(const Value: boolean); begin Fmodefied := Value; end;

procedure Tgpoly.SetNumV(const Value: integer); var i:integer; begin if (value<1) or (value=fnumv) then exit; if value>fnumv then begin if fnumv=0 then fnumv:=1; for i:=fnumv to value do

begin if assigned(vertex[i]) then vertex[i].Free; vertex[i]:=tgline.create; end ; end else if value<fnumV then for i:=value to fnumv do if assigned(vertex[i]) then vertex[i].Free;

FNumV := Value; end;

procedure Tgpoly.setpenstyle(penstyle: tpenstyle); var i:integer; begin if numv>0 then for i:=1 to numv do vertex[i].style:=penstyle; end;

procedure Tgpoly.Setvisible(const Value: boolean); begin Fvisible := Value;

end;

procedure Tgpoly.setwidths(W: byte); var i:integer; begin if Fnumv>0 then for i:=1 to Fnumv do vertex[i].width:=w; end;

function TgeoChart.pixtox(xp: integer): double; begin if fhorizaxis=habottom then result:=bottomaxis.Toval(xp) else result:= topaxis.Toval(xp); end;

function TgeoChart.pixtoy(yp: integer): double; begin if fvertaxis=valeft then result:= leftaxis.Toval(yp) else result:= rightaxis.Toval(yp) ;

end;

function TgeoChart.xtopix(xv: double): integer; begin if fhorizaxis=habottom then result:=bottomaxis.Topix(xv) else result:= topaxis.Topix(xv); end;

function TgeoChart.ytopix(yv: double): integer; begin if fvertaxis=valeft then result:= leftaxis.Topix(yv) else result:= rightaxis.Topix(yv) ; end;

{ TgrealLine }

constructor TgrealLine.create; begin inherited create; fx1:=0; fy1:=0;

fx2:=10; fy2:=10; fcolor:=clblack; fstyle:=pssolid; fwidth:=1; end;

procedure TgrealLine.Draw(canvas: tcanvas; penmode: tpenmode); var xx1,xx2,yy1,yy2:integer; pen:tpen; begin if fchart.horizaxis=hatop then begin xx1:=fchart.topaxis.Topix(fx1); xx2:=fchart.topaxis.Topix(fx2); end else begin xx1:=fchart.bottomaxis.Topix(fx1); xx2:=fchart.bottomaxis.Topix(fx2); end;

if fchart.vertaxis=varight then begin

yy1:=fchart.rightaxis.Topix(fy1); yy2:=fchart.rightaxis.Topix(fy2); end else begin yy1:=fchart.leftaxis.Topix(fy1); yy2:=fchart.leftaxis.Topix(fy2); end; pen:=tpen.Create;

pen.Assign(canvas.Pen); canvas.pen.color:=fcolor; canvas.Pen.Width:=fwidth; canvas.Pen.Style:=fstyle; canvas.Pen.Mode:=penmode; Canvas.MoveTo(xx1,yy1); Canvas.LineTo(xx2,yy2); canvas.Pen.Assign(pen); end;

function TgrealLine.inside: boolean;

begin if fchart.horizaxis=hatop then begin

if (fx1>= fchart.topaxis.Minimum) and (fx1<= fchart.topaxis.Maximum) and (fx2>= fchart.topaxis.Minimum) and (fx2<= fchart.topaxis.Maximum) then result:=true else result:=false; end else begin if (fx1>= fchart.bottomaxis.Minimum) and (fx1<= fchart.bottomaxis.Maximum) and (fx2>= fchart.bottomaxis.Minimum) and (fx2<= fchart.bottomaxis.Maximum) then result:=true else result:=false; end;

if fchart.vertaxis=varight then begin if (fy1>= fchart.topaxis.Minimum) and (fy1<= fchart.rightaxis.Maximum) and (fy2>= fchart.rightaxis.Minimum) and (fy2<= fchart.rightaxis.Maximum) then

result:=true else result:=false; end else begin if (fy1>= fchart.topaxis.Minimum) and (fy1<= fchart.leftaxis.Maximum) and (fy2>= fchart.leftaxis.Minimum) and (fy2<= fchart.leftaxis.Maximum) then result:=true else result:=false; end; end;

function TgrealLine.mousein(x, y: integer): boolean; var xx1,xx2,yy1,yy2:integer; begin if fchart.horizaxis=hatop then begin xx1:=fchart.topaxis.Topix(fx1); xx2:=fchart.topaxis.Topix(fx2); end

else begin xx1:=fchart.bottomaxis.Topix(fx1); xx2:=fchart.bottomaxis.Topix(fx2); end;

if fchart.vertaxis=varight then begin yy1:=fchart.rightaxis.Topix(fy1); yy2:=fchart.rightaxis.Topix(fy2); end else begin yy1:=fchart.leftaxis.Topix(fy1); yy2:=fchart.leftaxis.Topix(fy2); end; result:=false; if cursorOnline(x,y,xx1,yy1,xx2,yy2,fwidth ) then result:=true; end;

procedure TgrealLine.Setchart(const Value: tgeochart); begin Fchart := Value; end;

procedure TgrealLine.Setcolor(const Value: tcolor); begin Fcolor := Value; end;

procedure TgrealLine.Setselected(const Value: boolean); begin Fselected := Value; end;

procedure TgrealLine.Setstyle(const Value: tpenstyle); begin Fstyle := Value; end;

procedure TgrealLine.Setwidth(const Value: byte); begin Fwidth := Value; end;

procedure TgrealLine.Setx1(const Value: double); begin Fx1 := Value; end;

procedure TgrealLine.Setx2(const Value: double); begin Fx2 := Value; end;

procedure TgrealLine.Sety1(const Value: double); begin Fy1 := Value; end;

procedure TgrealLine.Sety2(const Value: double); begin Fy2 := Value; end;

{ Tgrealpoly }

procedure Tgrealpoly.add(vrtx: tgrealline); begin inc(fnumv); if assigned (vertex[fnumv]) then vertex[fnumv].Free; vertex[fnumv]:=tgrealline.create; with vertex[fnumv] do begin

x1:=vrtx.x1; y1:=vrtx.y1; x2:=vrtx.x2; y2:=vrtx.y2; color:=vrtx.color; style:=vrtx.style; width:=vrtx.width; end; end;

constructor Tgrealpoly.create; begin inherited create; fnumV:=0; fid:='realpoly1' ; visible:=true; modefied:=false; end;

destructor Tgrealpoly.destroy; var i:integer; begin if fnumv>0 then for i:=1 to fnumv do

if assigned(vertex[i]) then freeandnil(vertex[i]); inherited; end;

procedure Tgrealpoly.Drawarea(canvas: tcanvas); var p:array of tpoint; i:integer; x,y:integer; begin if (fnumv>2) and (visible) then begin for i:=1 to fnumv do if vertex[i].chart=nil then vertex[i].chart:=chart; SetLength(p, fnumv+1); for i:=1 to fnumv do begin if fchart.horizaxis=hatop then x:=fchart.topaxis.Topix(vertex[i].x1) else x:=fchart.bottomaxis.Topix(vertex[i].x1); if fchart.vertaxis=varight then y:=fchart.rightaxis.Topix(vertex[i].y1)

else y:=fchart.leftaxis.Topix(vertex[i].y1);

p[i-1].X:=x; p[i-1].Y:=y; end;

if fchart.horizaxis=hatop then x:=fchart.topaxis.Topix(vertex[fnumv].x2) else x:=fchart.bottomaxis.Topix(vertex[fnumv].x2); if fchart.vertaxis=varight then y:=fchart.rightaxis.Topix(vertex[fnumv].y2) else y:=fchart.leftaxis.Topix(vertex[fnumv].y2);

p[numv].X:=x; p[numv].Y:=y; canvas.Polygon(p); SetLength(p,0); end;

end;

procedure Tgrealpoly.Drawareaat(acanvas: tcanvas; grf: tgeochart);

var p:array of tpoint; i:integer; x,y:integer; begin if (fnumv>2) and (visible) then begin for i:=1 to fnumv do vertex[i].chart:=grf; SetLength(p, fnumv+1); for i:=1 to fnumv do begin if grf.horizaxis=hatop then x:=grf.topaxis.Topix(vertex[i].x1) else x:=grf.bottomaxis.Topix(vertex[i].x1); if grf.vertaxis=varight then y:=grf.rightaxis.Topix(vertex[i].y1) else y:=grf.leftaxis.Topix(vertex[i].y1);

p[i-1].X:=x; p[i-1].Y:=y; end;

if grf.horizaxis=hatop then x:=grf.topaxis.Topix(vertex[fnumv].x2) else x:=grf.bottomaxis.Topix(vertex[fnumv].x2); if grf.vertaxis=varight then y:=grf.rightaxis.Topix(vertex[fnumv].y2) else y:=grf.leftaxis.Topix(vertex[fnumv].y2);

p[numv].X:=x; p[numv].Y:=y; acanvas.Polygon(p); SetLength(p,0); end;

end;

procedure Tgrealpoly.Drawline(canvas: tcanvas); var i:integer; begin if (fnumv>0) and (visible) then for i:=1 to fnumv do begin if vertex[i].chart=nil then

vertex[i].chart:=fchart; vertex[i].Draw(canvas,pmcopy); end;

end;

procedure Tgrealpoly.Drawlineat(acanvas: tcanvas; grf: tgeochart); var i:integer; begin if (fnumv>0) and (visible) then for i:=1 to fnumv do begin vertex[i].chart:=grf; vertex[i].Draw(acanvas,pmcopy); vertex[i].chart:=fchart; end; end;

function Tgrealpoly.mousein(x, y: integer; var idx: integer): boolean; var i:integer; done:boolean; begin result:=false;

if fnumv>0 then begin i:=1; done:=false;

while (i<=fnumv)and not done do begin if vertex[i].mousein(x,y) then begin idx:=i; result:=true; done:=true; end else begin result:=false; done:=false; end; inc(i); end; end; end;

procedure Tgrealpoly.Setchart(const Value: tgeochart); begin Fchart := Value;

end;

procedure Tgrealpoly.Setcolors(color: tcolor); var i:integer; begin if fnumv>0 then for i:=1 to fnumv do vertex[i].color:=color; end;

procedure Tgrealpoly.SetID(const Value: str100); begin FID := Value; end;

procedure Tgrealpoly.Setmodefied(const Value: boolean); begin Fmodefied := Value; end;

procedure Tgrealpoly.SetnumV(const Value: integer); var i:integer; begin

if (value<1) or (value=fnumv) then exit; if value>fnumv then begin if fnumv=0 then fnumv:=1; for i:=fnumv to value do begin if assigned(vertex[i]) then vertex[i].Free; vertex[i]:=tgrealline.create;

end ; end else if value<fnumV then for i:=value to fnumv do if assigned(vertex[i]) then vertex[i].Free;

FNumV := Value; if fnumv>0 then for i:=1 to fnumv do vertex[i].chart:=fchart; end;

procedure Tgrealpoly.setpenstyle(penstyle: tpenstyle); var i:integer;

begin if numv>0 then for i:=1 to numv do vertex[i].style:=penstyle; end;

procedure Tgrealpoly.Setvisible(const Value: boolean); begin Fvisible := Value; end;

procedure Tgrealpoly.setwidths(W: byte); var i:integer; begin if Fnumv>0 then for i:=1 to Fnumv do vertex[i].width:=w; end;

procedure TgeoChart.SetProportionalXY(const Value: boolean); begin FProportionalXY := Value; end;

function TgeoChart.WperH: double; begin result:=fwidth/fheight; end;

function TgeoChart.XrangeperYrange: double; var xr,yr:double; begin if fhorizaxis=hatop then xr:=topaxis.Maximum-topaxis.Minimum else xr:=bottomaxis.Maximum-bottomaxis.Minimum; if fvertaxis=varight then yr:=rightaxis.Maximum-rightaxis.Minimum else yr:=leftaxis.Maximum-leftaxis.Minimum; result:=xr/yr; end;

procedure TgeoChart.printit(aleft,atop,aright,abottom:double); var pp:tprinterop; perx,pery:double;

prect:trect; begin pp:=tprinterop.create; try fchartrect:=rect(pp.CmtopixelsX(aLeft), pp.CmtopixelsY(aTop), pp.CmtopixelsX(aRight), pp.CmtopixelsY(aBottom)); leftaxis.chartRect:=fchartrect; topaxis.chartRect:=fchartrect; bottomaxis.chartRect:=fchartrect; rightaxis.chartRect:=fchartrect;

printer.Canvas.Brush.Style:=bsClear; perX:=(fchartrect.Right-fchartrect.Left)*0.00005; perY:=(fchartrect.Bottom-fchartrect.top)*0.00005; with fchartrect do begin leftaxis.Axrect:=rect(Left-trunc(fwidth*perX),top, left+trunc(fwidth*perX),bottom); topaxis.Axrect:=rect(left,top-trunc(Fheight*perY),right, top+trunc(Fheight*perY)); rightaxis.Axrect:=rect(right-trunc(fwidth*perX),top, right+trunc(fwidth*perX),bottom); bottomaxis.Axrect:=rect(left,bottom-trunc(Fheight*perY), right,bottom+trunc(Fheight*perY));

end; prect.Left:=leftaxis.Axrect.Left-printer.Canvas.TextHeight('0')*3; prect.Right:=rightaxis.Axrect.Right+printer.Canvas.TextHeight('0')*3; prect.Top:=topaxis.Axrect.Top-printer.Canvas.TextHeight('0')*3; prect.Bottom:=bottomaxis.Axrect.Bottom+printer.Canvas.TextHeight('0')*3 ; printer.Canvas.Create.Brush.Style:=bsSolid; printer.Canvas.Brush.Color:=fpanelcolor; printer.Canvas.Rectangle(prect);

printer.Canvas.Brush.Color:=fbkcolor; if showbkbitmap then printer.canvas.StretchDraw(fchartrect,fbkbitmap) else printer.Canvas.Rectangle(fchartrect); printer.Canvas.Brush.Style:=bsclear; topaxis.drawaxisline:=true; leftaxis.drawaxisline:=true; bottomaxis.drawaxisline:=true; rightaxis.drawaxisline:=true; topaxis.Canvas:=printer.Canvas; leftaxis.Canvas:=printer.Canvas; bottomaxis.Canvas:=printer.Canvas; rightaxis.Canvas:=printer.Canvas; if showtopaxis then topaxis.Draw;

if showrightaxis then rightaxis.draw; if showbottomaxis then bottomaxis.draw; if showleftaxis then leftaxis.draw; printer.canvas.Brush.Style:=bsclear; printer.canvas.Pen.Color:=fbordercolor; if drawborder then with fchartrect do printer.canvas.rectangle(left,top,right,bottom); finally freeandnil(pp); end; end;

procedure TgeoChart.SetDrawBorder(const Value: boolean); begin FDrawBorder := Value; end;

procedure TgeoChart.assign(achart: tgeochart); begin fbitmap:=achart.Bitmap; fwidth:=achart.width;

fheight:=achart.height; fbkbitmap:=achart.bkbitmap; fleftmargin:=achart.leftmargin; frightmargin:=achart.rightmargin; fbottommargin:=achart.bottommargin; ftopmargin:=achart.topmargin; fbordercolor:=achart.bordercolor; fpanelcolor:=achart.panelcolor; fbkcolor:=achart.bkcolor; fshowbkbitmap:=achart.showbkbitmap; fproportionalXY:=achart.ProportionalXY; Fvertaxis:=achart.vertaxis; fhorizaxis:=achart.horizaxis; fshowleftaxis:=achart.Showleftaxis; fshowtopaxis:=achart.showtopaxis; fshowbottomaxis:=achart.showbottomaxis; fshowrightaxis:=achart.showrightaxis; ftransparent:=achart.transparent; DrawBorder:=achart.DrawBorder; leftaxis.Assign(achart.leftaxis); rightaxis.Assign(achart.rightaxis); topaxis.Assign(achart.topaxis); bottomaxis.Assign(achart.bottomaxis); end;

function TprinterOp.PixelstocmX(px: integer): double; begin result:=px*scalingX/GetPixelsPerInchX; end;

function TprinterOp.PixelstocmY(py: integer): double; begin result:=py*scalingy/GetPixelsPerInchy; end;

function TprinterOp.pixelstoInX(px: integer): double; begin result:=px/GetPixelsPerInchy; end;

function TprinterOp.pixelstoInY(py: integer): double; begin result:=py/GetPixelsPerInchy; end;

{ TVesSection }

constructor TVesSection.create;

begin inherited create; lsym:=tsymbol.create; vsym:=tsymbol.create; isym:=tsymbol.create; showx:=false; chart:=tgeochart.create; chart.showrightaxis:=true; chart.panelcolor:=clwhite; chart.leftaxis.ShowMajorgrid:=true; chart.leftaxis.ShowMinorgrid:=false;

chart.rightaxis.ShowMajorgrid:=false; chart.rightaxis.ShowMinorgrid:=false; chart.topaxis.ShowMajorgrid:=false;

chart.topaxis.ShowMinorgrid:=false; chart.bottomaxis.ShowMajorgrid:=false; chart.bottomaxis.ShowMinorgrid:=false; end;

destructor TVesSection.destroy; begin if assigned(lsym) then freeandnil(lsym); if assigned(vsym) then freeandnil(vsym);

if assigned(isym) then freeandnil(isym); if assigned(chart) then freeandnil(chart); if fnuminhomos>0 then inherited destroy; end;

procedure TVesSection.Draw(image:timage); var i,j,nn:integer; xx,yy:double; begin if infoloaded then begin image.Width:=chart.width; image.Height:=chart.height; chart.drawtoimage(image); vsym.bitmapid:=7; for i:=1 to vesproject.pronumves do begin if fshowX then vsym.Name:=formatfloat('0.##',vesinfo[i].x) else vsym.Name:=vesinfo[i].name; if vesinfo[i].showname then vsym.showname:=true

else vsym.showname:=false; vsym.TransparentText:=false; vsym.labelbkcolor:=clwhite; chart.DrawSymbol(image.Canvas,vesinfo[i].x,vesinfo[i].z1,vsym); end; { for i:=1 to form1.vespro.pronumves do begin xs[i].x:=vesp[i].x; xs[i].y:=vesp[i].y1; end; dx:=vesp[vesproject.pronumves].x/200; for i:=1 to 199 do begin xx:=i*dx; yy:=interpol(form1.vespro.pronumves,xx,xs,2); xx1:=(i+1)*dx ; yy1:=interpol(form1.vespro.pronumves,xx1,xs,2); image1.Canvas.Pen.Color:=clred; chart.Drawline(image.Canvas,xx,yy,xx1,yy1); end; } image.Canvas.Pen.Color:=clblack; for i:=1 to vesproject.pronumves-1 do begin chart.Drawline(image.Canvas,vesinfo[i].x,vesinfo[i].z1,vesinfo[i+1].x,vesinfo[i+1].z1);

if fdrawdepthline then chart.Drawline(image.Canvas,vesinfo[i].x,vesinfo[i].z2,vesinfo[i+1].x,vesinfo[i+1].z2); end; if hloaded then begin for i:=1 to numinhomos do if inhomos[i].visible then begin isym.Name:=formatfloat('0.00',inhomos[i].rho); isym.bitmapid:=3; isym.color:=clred; chart.DrawSymbol(image.Canvas,inhomos[i].x,inhomos[i].z,isym); end; end;

for i:=1 to fnves do begin xx:=vesinfo[i].x; nn:=vesproject.ves[vesinfo[i].id].Model.n ; if nn>1 then for j:=1 to nn do begin lsym.bitmapid:=8; lsym.color:=clgreen; lsym.showname:=true;

lsym.labelbkcolor:=clwhite; lsym.LabelPos:=slpup; lsym.showname:=vesinfo[i].layers[j].showname; if j<nn then yy:=vesinfo[i].z1-vesproject.ves[vesinfo[i].id].getDepth(j) else begin if vesinfo[i].z2> chart.leftaxis.Minimum then yy:=vesinfo[i].z2 else yy:=chart.leftaxis.Minimum; end; vesinfo[i].layers[j].depth:=yy; lsym.Name:=formatfloat('0.##" ohm"',vesproject.ves[vesinfo[i].id].Model.rho[j]); chart.DrawSymbol(image.Canvas,xx,yy,lsym); end;

end; end;

end;

function TVesSection.inhomoselected(x, y: integer; var Vidx: integer): boolean; var i,xx,yy:integer;

found:boolean; begin i:=1; found:=false; result:=false; while (i<=fnuminhomos ) and not Found do begin xx:=chart.xtopix(inhomos[i].x); yy:=chart.ytopix(inhomos[i].z); isym.x:=xx; isym.y:=yy; if isym.pointin(x,y ) then begin vidx:=i; found:=true; result:=true; exit; end; inc(i); end;

end;

function TVesSection.layerselected(x, y: integer; var Vidx:integer;

var lidx: integer): boolean; var i,j,xx,yy:integer; found:boolean; begin i:=1; found:=false; result:=false; while (i<=fnves ) and not Found do begin xx:=chart.xtopix(vesinfo[i].x); j:=1; while (j<=vesinfo[i].nlayer ) and not found do begin yy:=chart.ytopix(vesinfo[i].layers[j].depth); lsym.x:=xx; lsym.y:=yy; if lsym.pointin(x,y ) then begin vidx:=i; lidx:=j; found:=true; result:=true; exit; end;

inc(j); end; inc(i); end;

end;

procedure TVesSection.loadinfo(infofile: str200); var fv:textfile; i,idx:integer; xx,yy,zz:double; maxy,miny:double; lines:tstrings; ext,fn:string[200]; st:string; begin

assignfile(fv,infofile); reset(fv);

lines:=tstringlist.create;

readln(fv,fnves); readln(fv);

vesproject.pronumves:=fnves; for i:=1 to fnves do begin st:=''; readln(fv,st); lines.Clear; extractstrings([#9,' ',','],[' '],pchar(st),lines); idx:=strtoint(lines[0]); //vesproject.proindexes[i]:=idx; vesinfo[i].id:=idx; vesproject.VES[idx].Visible:=true; xx:=strtofloat(lines[1]); yy:=strtofloat(lines[2]); zz:=strtofloat(lines[3]); vesinfo[i].x:=xx; vesinfo[i].z1:=yy; vesinfo[i].z2:=yy-zz; vesinfo[i].name:=vesproject.ves[idx].Station_No; vesinfo[i].nlayer:=vesproject.ves[idx].Model.n; end; closefile(fv); maxy:=vesinfo[1].z1; miny:=vesinfo[1].z2; for i:=1 to vesproject.pronumves do begin

if vesinfo[i].z1>maxy then maxy:=vesinfo[i].z1 ; if vesinfo[i].z2>maxy then maxy:=vesinfo[i].z2 ; if vesinfo[i].z1<miny then miny:=vesinfo[i].z1 ; if vesinfo[i].z2<miny then miny:=vesinfo[i].z2 ; end; miny:=round(miny); maxy:=round(maxy); chart.setminmax(0,vesinfo[fnves].x,miny,maxy); chart.leftaxis.Majors:=50; chart.leftaxis.Minors:=25; chart.rightaxis.Majors:=chart.leftaxis.Majors; chart.rightaxis.Minors:= chart.leftaxis.Minors; infoloaded:=true; ext:=extractfileext(infofile); fn:=copy(infofile,1,length(infofile)-length(ext)-4); fn:=fn+'inh.dat'; if fileexists(fn) then loadinhomo(fn);

end;

procedure TVesSection.loadinhomo(homofile: str200);

var fv:textfile; n:integer; lines:tstrings; st:string; begin assignfile(fv,homofile); reset(fv); lines:=tstringlist.create;

readln(fv); n:=1; while not eof(fv) do begin st:=''; readln(fv,st); lines.Clear; extractstrings([#9,' ',','],[' '],pchar(st),lines); with inhomos[n] do begin x:=strtofloat(lines[0]); z:=strtofloat(lines[1]); rho:=strtofloat(lines[2]); visible:=true; end; inc(n);

end;// while fnuminhomos:=n-1; closefile(fv); hloaded:=true; end;

procedure TVesSection.printit(aleft, atop, aright, abottom: double); var i,j,nn:integer; xx,yy:double; po:tprinterop; oldspc,oldsize:integer; begin

if infoloaded then begin po:=tprinterop.create; Try po.chart.assign(chart); po.chart.DrawBorder:=false; po.chart.printit(aleft, atop, aright, abottom); vsym.bitmapid:=7; oldsize:= vsym.size; oldspc:= vsym.spacing;

vsym.size:=round(po.PixelsPerInchX*vsym.size/screen.PixelsPerInch); vsym.spacing:=round(po.PixelsPerInchX*vsym.spacing/screen.PixelsPerInch); for i:=1 to vesproject.pronumves do begin if fshowX then vsym.Name:=formatfloat('0.##',vesinfo[i].x) else vsym.Name:=vesinfo[i].name; if vesinfo[i].showname then vsym.showname:=true else vsym.showname:=false; vsym.TransparentText:=false; vsym.labelbkcolor:=clwhite; po.chart.DrawSymbol(printer.Canvas,vesinfo[i].x,vesinfo[i].z1,vsym); end; vsym.size:=oldsize; vsym.spacing:=oldspc; printer.Canvas.Pen.Color:=clblack; for i:=1 to vesproject.pronumves-1 do begin po.chart.Drawline(printer.Canvas,vesinfo[i].x,vesinfo[i].z1,vesinfo[i+1].x,vesinfo[i+1].z1); if fdrawdepthline then end; if hloaded then

begin isym.bitmapid:=3; isym.color:=clred; oldsize:= vsym.size; oldspc:= isym.spacing; isym.size:=round(po.PixelsPerInchX*isym.size/screen.PixelsPerInch); isym.spacing:=round(po.PixelsPerInchX*isym.spacing/screen.PixelsPerInch); for i:=1 to numinhomos do if inhomos[i].visible then begin isym.Name:=formatfloat('0.00',inhomos[i].rho); po.chart.DrawSymbol(printer.Canvas,inhomos[i].x,inhomos[i].z,isym); end; vsym.size:= oldsize ; isym.spacing:= oldspc ;

end;

lsym.size:=10; oldsize:= lsym.size; oldspc:= lsym.spacing; lsym.size:=round(po.PixelsPerInchX*lsym.size/screen.PixelsPerInch); lsym.spacing:=round(po.PixelsPerInchX*lsym.spacing/screen.PixelsPerInch); lsym.bitmapid:=8; lsym.color:=clgreen;

lsym.showname:=true; lsym.labelbkcolor:=clwhite; lsym.LabelPos:=slpup; for i:=1 to fnves do begin xx:=vesinfo[i].x; nn:=vesproject.ves[vesinfo[i].id].Model.n ; if nn>1 then for j:=1 to nn do begin

lsym.showname:=vesinfo[i].layers[j].showname; if j<nn then yy:=vesinfo[i].z1-vesproject.ves[vesinfo[i].id].getDepth(j) else begin if vesinfo[i].z2> chart.leftaxis.Minimum then yy:=vesinfo[i].z2 else yy:=chart.leftaxis.Minimum; end; vesinfo[i].layers[j].depth:=yy; lsym.Name:=formatfloat('0.##" ohm"',vesproject.ves[vesinfo[i].id].Model.rho[j]); po.chart.DrawSymbol(printer.Canvas,xx,yy,lsym); end; lsym.size:=oldsize ; lsym.spacing:=oldspc;

end; lsym.size:=oldsize ; lsym.spacing:=oldspc; finally freeandnil(po); end;// try

end;

end;

procedure TVesSection.Setdrawdepthline(const Value: boolean); begin Fdrawdepthline := Value; end;

procedure TVesSection.Setdrawinhomos(const Value: boolean); begin Fdrawinhomos := Value; end;

procedure TVesSection.Setdrawlayers(const Value: boolean); begin Fdrawlayers := Value; end;

procedure TVesSection.SetDrawvesline(const Value: boolean); begin FDrawvesline := Value; end;

procedure TVesSection.Sethloaded(const Value: boolean); begin Fhloaded := Value; end;

procedure TVesSection.Setinfoloaded(const Value: boolean); begin Finfoloaded := Value; end;

procedure TVesSection.Setnuminhomos(const Value: integer); begin fnuminhomos:=value; end;

procedure TVesSection.Setnves(const Value: integer); begin Fnves := Value; end;

procedure TVesSection.Setshowx(const Value: boolean); begin Fshowx := Value; end;

function TVesSection.VesSelected(x, y: integer; var Vidx: integer): boolean; var i,xx,yy:integer; found:boolean; begin i:=1; found:=false; result:=false; while (i<=fnves ) and not Found do begin xx:=chart.xtopix(vesinfo[i].x); yy:=chart.ytopix(vesinfo[i].z1); vsym.x:=xx; vsym.y:=yy; if vsym.pointin(x,y ) then begin vidx:=i; found:=true;

result:=true; exit; end; inc(i); end;

end;

end.

You might also like