number t,dx,dy,cFlag
number sizeX,sizeY,sizeZ,sx,sy,sz,z;
number mval,mx,my,firstNumber;
Image img1,img2,imgT;
string fileName,fileBase,comment;
number thickCount = 10;
number defCount   = 10;
number it,idef
T_setverbose(0)

If (!OpenDialog(fileName))
Throw("No file name selected");

Result("File: "+fileName+"\n");
GetNumber("Number of different thicknesses (img_[t]_[def].img):",thickCount,thickCount);
GetNumber("Number of different defoci (img_[t]_[def].img):",defCount,defCount);


Image img = T_readImg(filename,t,dx,dy,cFlag,comment);

fileBase = left(filename,len(filename)-7);
Result("File: "+fileBase+"\n");


img.GetSize(sx,sy);
realImage tgt = Realimage("Thickness_Defocus_Map",4,sx*defCount,sy*thickCount);

for (it=0;it<thickCount;it++) {
	for (idef=0;idef<defCount;idef++) {
		filename = fileBase+it+"_"+idef+".img"
		// Result("Reading "+filename+"\n");

		img = T_readImg(filename,t,dx,dy,cFlag,comment);
		tgt[it*sy,idef*sx,(it+1)*sy,(idef+1)*sx] = real(img);
	}
	Result("Thickness: "+(0.1*t)+" nm\n");
}
tgt.setname("Thickness_Defocus_Map");
tgt.setscale(0.1*dx,0.1*dy);
tgt.setunitstring("nm");
showimage(tgt)
	
