// Tree controls

#define   NTREE 5

//     HWND hWndTree ;	// general
	 HWND hWndTreeSer ;	// sets and suites
	 HWND hWndTreeExp ;	// Experimental
	 HWND hWndTreeArc ; // Archives 

typedef struct tagTrees
			{

	  int iNumTreeItems[NTREE] ;	// Per-tree item counts
	  int iTotTreeItems ;			// total (all-tree) item count
	 char szItems[50] ;				// string version of total

HTREEITEM  hTreeItems[NTREE][MAXITEM] ;	// per-tree items by ordinal index

// ROOT Items ***************************

HTREEITEM hTreeExpPfx[MAXPFXS] ; // prefix items in Exp. tree

// CHILD Items ***************************

// Series Tree Sets
HTREEITEM hTreeSerimgSet[MAXPFXS] ;
HTREEITEM hTreeSeriniSet[MAXPFXS] ;
HTREEITEM hTreeSerdatSet[MAXPFXS] ;
HTREEITEM hTreeSertrkSet[MAXPFXS] ;
HTREEITEM hTreeSersuiSet[MAXPFXS] ;

// "Experimental" Tree
HTREEITEM hTreeExpImg[MAXINST] ;
HTREEITEM hTreeExpIni[MAXINST] ;
HTREEITEM hTreeExpDat[MAXINST] ;
HTREEITEM hTreeExpTrk[MAXINST] ;

// PATH items ***************************

// Series tree
HTREEITEM hTreeSerIniPth[MAXINST] ;
HTREEITEM hTreeSerDatPth[MAXINST] ;
HTREEITEM hTreeSerTrkPth[MAXINST] ;

// "Experimental" Tree
HTREEITEM hTreeExpImgPth[MAXINST] ;
HTREEITEM hTreeExpIniPth[MAXINST] ;
HTREEITEM hTreeExpDatPth[MAXINST] ;
HTREEITEM hTreeExpTrkPth[MAXINST] ;

							} TREES, * LPTREES ;
TREES T ;

HTREEITEM   htvSel ;	// handle of a selection
HTREEITEM htvDaddy ;	// handle of a parent
   TVITEM    tvItm ;	// handle of an item
   TVITEM   tvItm1 ;	// handle of an item

      int tvPfx ;
	  int tvImg ;
	  int tvIni ;
	  int tvDat ;
	  int tvTrk ;
	  int tvPth ;
	  int tvSer ;
	  int tvSui ;

	  int tvImgSer ;
	  int tvIniSer ;
	  int tvDatSer ;
	  int tvTrkSer ;
	  int tvSuiSer ;

	  int tvImgpth ;
	  int tvInipth ;
	  int tvDatpth ;
	  int tvTrkpth ;
	  int tvSerpth ;

	  int tvArc ;
	  int tvBul ;

// *********************** Prototypes

HTREEITEM PutInTree
(
		 HWND hWndTV,	// tree view handle
	HTREEITEM hti,		// parent-item handle
	HTREEITEM htia,		// insert-after handle
	    LPSTR pszItem,	// item string
		 UINT TVIMG,	// image list index
		 UINT data		// for the item data area
) ;

HTREEITEM LookinTree
(
	  HWND hWndTV,
	   int what,
 HTREEITEM hti,
     LPSTR szFind,
	  UINT * ID,
	  UINT * TYP
) ;

	 BOOL RemoveFromTree( HWND, char * ) ;

HTREEITEM SearchTree
(
		   HWND hWndTV,
		    int what,		// whether to find item text, or item TYP/ID
		  LPSTR szFind,		// item text to find
		   UINT * ID,		// address of ID   to find
		   UINT * TYP		// address of type to find
) ;

	 void				   FillTree( HWND hWndT ) ;
	 void				FillTreeSer( void ) ;
	 void				UpdateTrees( void ) ;
	 UINT				  PutItmDat( UINT, UINT ) ;
	 UINT				GetItemData( HWND, HTREEITEM, UINT * ) ;

//WorkFile(char *pfx)
//{
	// does the prefix have a suite or suites?
	//		if not,
	//		-create one in the ABR,
	//		-give it a default name (or option to ask for name?),
	//		-fill in the details.
	// have we seen this epoch for this prefix?
	//		no,
	//		add it to the list under [epochs]
	// have 
//}


 /*************************************************************
							SUITES

		A "Suite" of files is the set of bud files
		corresponding to a particular "assay" of a 
		bud instance-series.
		
		The bud files come in groups according to type
			- image(IMG), INI, DAT and track(TRK) -
		and the prefix (PFX) of an instance may be
		associated with files in one or more of the groups.

		Each file in a group may exist on more than one
		path, and there is a list of paths per file.

		A SUITE struct contains ordinal information per-group 
		about the paths on which to find files for an assay.
		
		Thus, for some prefix and some assay -

		The images for the assay are to be found on the Nth
		path to images with that prefix.

		the INIs for an assay on the Mth path to INIs with
		that prefix.
		
		--- and so on.

 **************************************************************/
#define    DFLT  0

LPSUITE MakeSuite
(
 char * desc,
 int iIMG,
 int iINI,
 int iDAT,
 int iTRK,
 LPSUITE suite
) ;

LPSUITE CreateSuite(char *p, int pfxID) ;

//**************************************************************

int iPfxID,  iPfximgID, iGpthID ;
int iImgID,  iPathID ;
int iIniID,  iInipthID ;
int iTrkID,  iTrkpthID ;
int iDatID,  iDatpthID ;

int iSuites = 0 ;

// The following strings are used by the Inventory() function
// when compiling data lists for archive work, and by the
// SaveInifile() function. They follow the conventions
// of Get/WritePrivateProfileString() ;

  static char * szField[] = {							  // field-
	                         "Details",					  // 0
	                         "Projective Lambdas & MRDs", // 1
                             "Regression Lambdas & MRDs", // 2
							 "Standard Deviations",		  // 3
							 "Dimensions",				  // 4
							 "Files"					  // 5
                            } ;
  
  static char   * szKey[] = {							// key-	  field-
	                         "Identity ","Place ",		// 0,1	  0
							 "Latitude ","Longitude ",	// 2,3
							 "Date ","Time ",			// 4,5
							 "Pr_Diam ",			    // 6	  1
							 "Pr_LRad ",			    // 7
							 "Pr_RRad ",			    // 8
							 "Rg_Diam ",			    // 9	  2
							 "Rg_LRad ",			    // 10
							 "Rg_RRad ",			    // 11
							 "Raw St.Dev. ",			// 12
							 "Mean St.Dev. ",			// 13
							 "Pixel Width",				// 14	  3a
							 "Pixel Height",			// 15
							 "Sub-Image x",			    // 16
							 "Sub-Image y",			    // 17
							 "Sub-Image Width",			// 18
							 "Sub-Image Height",		// 19
							 "Framing ",				// 20	  3b
							 "Poles ",					// 21
					         "Levels Used ",			// 22
							 "Calibration",				// 23
							 "Units",					// 24
							 "Inter-Mark size",			// 25
							 "Inter-Mark DIBits",		// 26
							 "xCal_1",					// 27
							 "yCal_1",					// 28
							 "xCal_2",					// 29
							 "yCal_2",					// 30
		"LevelA", "LevelB", "LevelC", "LevelD", "LevelE",	// 31-35  3c
		"LevelF", "LevelG", "LevelH", "LevelI", "LevelJ",	// 36-40
		"LevelK", "LevelL", "LevelM", "LevelN", "LevelO",	// 41-45
		"LevelP", "LevelQ", "LevelR", "LevelS", "LevelT",	// 46-50
		"LevelU", "LevelV", "LevelW", "LevelX", "LevelY",	// 51-55
		"LevelZ",											// 56
		"Level27","Level28","Level29","Level30","Level31",	// 57-61  3d
		"Level32","Level33","Level34","Level35","Level36",	// 62-66
		"Level37","Level38","Level39","Level40","Level41",	// 67-71
		"Level42","Level43","Level44","Level45","Level46",	// 72-76
		"Level47","Level48","Level49","Level50","Level51",	// 77-81
		"Level52",											// 82
					"IMG","DAT","INI","DIR"					// 83-86  4
                                                 } ;

       char szString[255] = {'\0'} ;
	   char    intxt[255] = {'\0'} ;


void WPPS(int field, int key)
{
  WritePrivateProfileString(
	  szField[field],
	  szKey[key],
	  szString,
	  szIniPath
	  ) ;
}

char * PreWrt(int field, int key, char * str1 )
{
		strcpy(intxt, szField[field]) ;
		strcat(intxt,": ") ;
		strcat(intxt, szKey[key]) ;
		strcat(intxt, "::   ") ;
		strcat(intxt, str1) ;
		return intxt ;
}

void SaveIniFile(int toTree, IDS I)
{
	int field , key ;
	LPBUDRESULTS B ;
	HTREEITEM HT, hT; // hp ;
	LPSUITE suite ;
	UINT FID, ID, TYP, wid, hyt ;
	char nstr[100] ;
	char buff[256] ;
	 int k ;
	HISSRC  hSrc ;
	HGLOBAL hRGB ;
	HISDEST hDest ;
	BYTE * pRGB ;

	static isOpen = 0 ;

	B = pBudResults ;

 if (gotimage) // do we have an image on board?
{
	// we have an image
	// OK, let's get a source manager, and open the image source

	if ((hSrc = _ISOpenFileSource(szFile)) != (HISSRC)NULL)
	{
	_ISSeek(hSrc,0,0) ;
			
	hRGB = _ISReadJPG			// get the image
					(
					hSrc,
					&wid,
					&hyt,
					24
					 ) ;

	pRGB = (BYTE *) hRGB ;

	isOpen = 1;
	}
 }
	
	if (toTree)
	{
	// do we have the tree?
	if (hWndTreeExp != (HWND)NULL)
	{
		// we have the tree.
		// do we have the corresponding prefix reference?
		if (SearchTree(hWndTreeExp, 0, A.szKnownpfx[I.pfxID], &ID, &TYP) != (HTREEITEM)NULL)
		{
			// we have the prefix reference: 
			// do we have the IMG reference?
			if ((HT = SearchTree(hWndTreeExp, 0, A.szKnownimg[I.imgID], &ID, &TYP)) != (HTREEITEM)NULL)
			{
				// we have the IMG reference:
				// do we have the INI reference?
				if (SearchTree(hWndTreeExp, 0, A.szKnownini[I.iniID], &ID, &TYP) == (HTREEITEM)NULL)
				{
					// we don't have the INI reference
					// install it now under the IMG reference
				FID = PutItmDat(I.iniID, INI) ;
				T.hTreeExpIni[I.iniID] = hT = PutInTree(hWndTreeExp, HT, HT,
													A.szKnownini[I.iniID],
													tvIni, FID) ;
					// we don't have the INI path reference
					// install it now under the INI reference
				FID = PutItmDat(I.inipth, INIPTH) ;
				T.hTreeExpIniPth[I.inipth] = PutInTree(hWndTreeExp, hT, hT,
													   A.szKnownpth[I.inipth],
													   tvInipth, FID) ;
				} // we have the INI ref and the INI path ref

/****
				hp = T.hTreeExpIniPth[I.inipth] ;

				PutInTree(hWndTreeExp, hp, hp,
								ResultCombo[0],
								tvBul, 0) ;

				PutInTree(hWndTreeExp, hp, hp,
								ResultCombo[3],
								tvBul, 0) ;
***/
			} // no image
		} // no prefix
	} // no tree


	if (hWndTreeSer != (HWND)NULL)
	{ 
		// we have the tree
		// do we have the prefix reference?
		if ((HT = SearchTree(hWndTreeSer, 0, A.szKnownpfx[I.pfxID], &ID, &TYP)) != (HTREEITEM)NULL)
		{
		// we have the prefix reference (handle HT)
			// do we have the INI set count?
			if ((hT = T.hTreeSeriniSet[I.pfxID]) != (HTREEITEM)NULL)
			{
				// we have the INI set count (handle hT):
				// change it now
						_itoa((k = A.iNuminipthsperpfx[I.pfxID]), nstr, 10) ;
						if (k == 1)
					   strcat(nstr, " set.") ;
						else
					   strcat(nstr, " sets.") ;

						tvItm.mask = TVIF_TEXT ;						// specify item to change
						tvItm.hItem = hT ;								// get and give the handle
						tvItm.pszText = nstr ;							// buffer with new text
						TreeView_SetItem(hWndTreeSer, &tvItm) ;			// change item text (new ini path count)

			// do we have the path reference?
			if ((SearchTree(hWndTreeSer, 0, A.szKnownpth[I.inipth], &ID, &TYP)) == NULL)
			{
				// we don't have the path reference
				// insert it now under the ini path count
					FID = PutItmDat(A.iInipthperpfx[I.pfxID][I.iniID], INIPTH) ;
					PutInTree(hWndTreeSer,			// add new ini path to tree
							hT,						// under the ini path count
							hT,
							A.szKnownpth[I.inipth],	// 
							tvInipth,				// 
							FID) ;					//
			} // we have the path reference
			} // no INI set count
		} // no prefix reference
	} // no tree

	} // end if (toTree)

 for (field = 0 ; field < 5 ; field++)
  {
		switch(field)
	{
case 0 : for (key = 0 ; key <= 5 ; key++)
		 {
			 switch( key )
			 {
			 case 0: strcpy(szString,pBudResults->BudSpecTxt) ;
				 break ;
			 case 1: strcpy(szString,pBudResults->BudPlaceTxt) ;
				 break ;
			 case 2: strcpy(szString,pBudResults->BudLatitudeTxt) ;
				 break ;
			 case 3: strcpy(szString,pBudResults->BudLongitudeTxt) ;
				 break ;
			 case 4: strcpy(szString,pBudResults->BudDateTxt) ;
				 break ;
			 case 5: strcpy(szString,pBudResults->BudTimeTxt) ;
				 break ;
			 }
			 WPPS(field, key) ;
		 }
	break ;

case 1:	 for (key = 6 ; key <= 8 ; key++)
		 {
			 strcpy(szString,ResultCombo[key-6]) ;
			 WPPS(field, key) ;
		 }
	break ;

case 2:  for (key = 9 ; key <= 11 ; key++)
		 {
			 strcpy(szString,ResultCombo[key-6]) ;
			 WPPS(field, key) ;
		 }

	break ;

case 3:	 									  // [Standard Deviations]

	         sprintf(szString, "%4.3f", RStDev) ; // moving std. dev. on raw lambdas
		     WPPS(field, 12) ;

	         sprintf(szString, "%4.3f", MStDev) ; // moving std. dev. on mean lambdas
		     WPPS(field, 13) ;

	break ;


case 4:	 for (key = 14 ; key <= 19 ; key++)	  // [Dimensions]
		 {
			 switch (key)			// Sub_Image rectangle
			 {
			 case 14: sprintf(szString,"%d", dibwid ) ;
				 break ;
			 case 15: sprintf(szString,"%d", dibhyt ) ;
				 break ;
			 case 16: sprintf(szString,"%d", pBudResults->SubImageX ) ;
				 break ;
			 case 17: sprintf(szString,"%d", pBudResults->SubImageY ) ;
				 break ;
			 case 18: sprintf(szString,"%d", ws ) ;
				 break ;
			 case 19: sprintf(szString,"%d", hs ) ;
			 }
			 WPPS(field, key) ;
		 }
	
	     for (key = 20 ; key <= 30 ; key++)
		 {
			 switch(key)					  
			 {
			 case 20:  strcpy(szString,DimenCombo[0]) ;	 // Framing
				 break ;
			 case 21:  strcpy(szString,DimenCombo[1]) ;	 // Poles
				 break ;
			 case 22: sprintf(szString,"%d", Levels) ;	 // Levels used
				 break ;
			 case 23: sprintf(szString,"%d", calibrated) ;//Calibration
				 break ;
			 case 24: switch (Units)					 // Units in use
					  {
						case METRIC:
							sprintf(szString," Millimetres") ;
							break ;
						case IMPERIAL:
							sprintf(szString," Inches") ;
							break ;
						case IMAGEUNITS:
							sprintf(szString," Image-Units") ;
							break;
					  }
				 break ;
			 case 25: sprintf(szString," %4.3f", CalSize) ;
				 break ;
			 case 26: sprintf(szString," %4.3f", InterCalMarkDIBits) ;
			     break ;
			 case 27: sprintf(szString," %d", xBCal1) ;
				 break ;
			 case 28: sprintf(szString," %d", yBCal1) ;
				 break ;
			 case 29: sprintf(szString," %d", xBCal2) ;
				 break ;
			 case 30: sprintf(szString," %d", yBCal2) ;
				 break ;
			 }
			 WPPS(field, key) ;
		 }

         for (key = 31 ; key < Levels + 31 ; key++) // measures at Level
		 {
			 sprintf(szString,"%s",	DimenCombo[key - 31 + 3]) ;
			 WPPS(field, key) ;
		 }
	break ;
	}	
  }

  //  record the measurement origins
  // (i.e., their sources: manual, from track etc.)

  for ( key = 1 ; key <= Levels ; key++ )
  {
	  char b[10] ;
	  sprintf(   b, "%d", key ) ;
	  sprintf(szString, "%d %d", LEdgeOrg[key], REdgeOrg[key]) ;
	  wpps("Dimensions", b, szString, szIniPath) ;
  }

  // and the indexed list of levels included in Lambda calculations

  for ( key = 1 ; key <= Levels ; key++ )
  {
	  char b[10] ; int num ;
	  sprintf(b, "%d", key ) ;
		sprintf(szString, "%d ", IncludeLev[key]) ;
		wpps("Inclusions", b, szString, szIniPath) ;
  }

  // record mode of measurement-height distribution, and
  // colour(s) on which line-scanning was done.
  {
	  char b[20] ;
	  char * c[] = {"A", "R", "G", "B"} ;				// All (i.e. Grayscale), Red, Green, Blue
	  char str[256] ;
	  DWORD nSize = 512 ;
	  DWORD uSize = UNLEN + 1 ; 
	  char computer[512] ;
	  char username[UNLEN + 1] ;
	  //LPSUITE sui ;

  if (GrowthMeasure)
	  strcpy(b, "Growth") ; else strcpy(b, "Linear") ;
	  wpps("Dimensions","Mode", b,						 szIniPath) ;


  if (GrowthMeasure)
	  sprintf(b, " %4.3f", growth) ; else strcpy(b, " None") ;
	  wpps("Dimensions","Coef", b,						 szIniPath) ;


	  wpps("Dimensions","ScanColour", c[scancolour],	 szIniPath) ;

	  wpps("Details","Sample Epoch", NULL,				 szIniPath) ;

	  wpps("Details","Epoch", JulEpCpy,				 szIniPath) ;

	  wpps("Details","In Archive", szUsingArchive,		 szIniPath) ;


	  suite = A.pSuiteperpfx[BudPfxID][LastSuite] ;
	  wpps("Details","Suite", suite->desc,				 szIniPath) ;


	  GetComputerName(computer, &nSize) ;
	  wpps("Details","Computer", computer,				 szIniPath) ;


	  GetUserName(username, &uSize) ;
	  wpps("Details", "User Name", username,			 szIniPath) ;



	  wpps("Standard Deviations", NULL, NULL,			 szIniPath) ;	// remove any standard deviations entries

	  gpps("Files", "BMP", "None", buff, (DWORD)256,	 szIniPath) ;	// remove any BMP entry
	  if (strlen(buff) != 0)
	  wpps("Files", "BMP", NULL,						 szIniPath) ;

	  gpps("Files", "Level52", "None", buff, (DWORD)256, szIniPath) ;	// remove any Level 52 entry
	  if (strlen(buff) != 0)
	  wpps("Files", "Level52", NULL,					 szIniPath) ;

	  strcpy(str, A.szKnownpth[I.imgpth]) ;
	  strcat(str, A.szKnownimg[I.imgID]) ;
	  wpps("Files","IMG", str,							 szIniPath) ;	// IMG


	  if (useDATs)
	  {
	  strcpy(str, A.szKnownpth[I.datpth]) ;
	  strcat(str, A.szKnowndat[I.datID]) ; 
	  wpps("Files","DAT", str,							 szIniPath) ;	  // DAT

	  }

	  strcpy(str, A.szKnownpth[I.inipth]) ;
	  strcat(str, A.szKnownini[I.iniID]) ; 
	  wpps("Files","INI", str ,							 szIniPath) ;	// INI


	  if (autotracked)
	  {
	  strcpy(str, A.szKnownpth[I.trkpth]) ;
	  strcat(str, szTrkFile) ;
	  wpps("Files","TRK", str ,							 szIniPath) ;	// TRK

	  }
	  else
	  wpps("Files","TRK", NULL ,						 szIniPath) ;	// no TRK, remove any TRK entry
	  gpps("Files","DIR", "None", buff, (DWORD)256,		 szIniPath) ;	// remove any DIR entry
	  if (strlen(buff) != 0)
	  wpps("Files", "DIR", NULL,						 szIniPath) ;
	}
 
  {
	  char stuff[255] ;
	  char  more[255] ;
	  char   num[ 20] ;
	  char    nm[ 20] ;
	  LPMEASURE M ;
	  M = pMeasure ;

	wpps("WASDAT", "BudSpec",		B->BudSpecTxt,      szIniPath) ;

	wpps("WASDAT", "BudPlace",		B->BudPlaceTxt,     szIniPath) ;

	wpps("WASDAT", "BudLatitude",	B->BudLatitudeTxt,  szIniPath) ;

	wpps("WASDAT", "BudLongitude",	B->BudLongitudeTxt, szIniPath) ;

	wpps("WASDAT", "BudImageFile",  B->BudImageFile,    szIniPath) ;

	wpps("WASDAT", "BudDataFile",   B->BudDataFile,     szIniPath) ;

	wpps("WASDAT", "BudTextFile",   B->BudTextFile,     szIniPath) ;

	wpps("WASDAT", "BudDateTxt",    B->BudDateTxt,      szIniPath) ;

	wpps("WASDAT", "BudTimeTxt",    B->BudTimeTxt,      szIniPath) ;

	wpps("WASDAT", "NumHyts",		_itoa(B->NumHyts,   num, 10), szIniPath) ;

	wpps("WASDAT", "SubImageX",		_itoa(B->SubImageX, num, 10), szIniPath) ;

	wpps("WASDAT", "SubImageY ",		_itoa(B->SubImageY, num, 10), szIniPath) ;

	wpps("WASDAT", "SubImageW",		_itoa(B->SubImageW, num, 10), szIniPath) ;

	wpps("WASDAT", "SubImageH",		_itoa(B->SubImageH, num, 10), szIniPath) ;

			for (k = 1 ; k <= Levels ; k++)
		  {
					_itoa(k, num, 10) ;
				strcpy(more, "Edges") ; strcat(more, num) ;
		  wpps("WASDAT", more, _itoa(B->Edges[k], nm, 10), szIniPath) ;

		  }

		  sprintf(stuff, "%5.5f",B->BudMag) ;
		  wpps("WASDAT", "BudMag",        stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->BudLength) ;
		  wpps("WASDAT", "BudLength",     stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f ",B->BudTilt) ;
		  wpps("WASDAT", "BudTilt",       stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->BudTopPoleX) ;
		  wpps("WASDAT", "BudTopPoleX",   stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f ",B->BudTopPoleY) ;
		  wpps("WASDAT", "BudTopPoleY",   stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->BudBotPoleX) ;
		  wpps("WASDAT", "BudBotPoleX",   stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->BudBotPoleY) ;
		  wpps("WASDAT", "BudBotPoleY ",   stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->LeftProjLambda) ;
		  wpps("WASDAT", "LeftProjLambda",   stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->LeftProjMRD) ;
		  wpps("WASDAT", "LeftProjMRD",      stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->LeftRegrLambda) ;
		  wpps("WASDAT", "LeftRegrLambda",   stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->LeftRegrMRD) ;
		  wpps("WASDAT", "LeftRegrMRD",      stuff, szIniPath) ;
		  

		  sprintf(stuff, "%5.5f",B->RightProjLambda) ;
		  wpps("WASDAT", "RightProjLambda",  stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->RightProjMRD) ;
		  wpps("WASDAT", "RightProjMRD",     stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->RightRegrLambda) ;
		  wpps("WASDAT", "RightRegrLambda",  stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->RightRegrMRD) ;
		  wpps("WASDAT", "RightRegrMRD",     stuff, szIniPath) ;
		  

		  sprintf(stuff, "%5.5f",B->DiamProjLambda) ;
		  wpps("WASDAT", "DiamProjLambda",   stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->DiamProjMRD) ;
		  wpps("WASDAT", "DiamProjMRD",      stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->DiamRegrLambda) ;
		  wpps("WASDAT", "DiamRegrLambda",   stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->DiamRegrMRD) ;
		  wpps("WASDAT", "DiamRegrMRD",      stuff, szIniPath) ;
		  

		  for (k = 1 ; k <= Levels ; k++)
		  {
					_itoa(k, num, 10) ;
				strcpy(more, "RProjDev") ; strcat(more, num) ;
				sprintf(stuff, "%5.5f", B->RProjDev[k]) ;
				wpps("WASDAT", more, stuff, szIniPath) ;
				

				strcpy(more, "LProjDev") ; strcat(more, num) ;
				sprintf(stuff, "%5.5f", B->LProjDev[k]) ;
				wpps("WASDAT", more, stuff, szIniPath) ;
				

				strcpy(more, "BProjDev") ; strcat(more, num) ;
				sprintf(stuff, "%5.5f", B->BProjDev[k]) ;
				wpps("WASDAT", more, stuff, szIniPath) ;
				

				strcpy(more, "RRegrDev") ; strcat(more, num) ;
				sprintf(stuff, "%5.5f", B->RRegrDev[k]) ;
				wpps("WASDAT", more, stuff, szIniPath) ;
				

				strcpy(more, "LRegrDev") ; strcat(more, num) ;
				sprintf(stuff, "%5.5f", B->LRegrDev[k]) ;
				wpps("WASDAT", more, stuff, szIniPath) ;
				

				strcpy(more, "BRegrDev") ; strcat(more, num) ;
				sprintf(stuff, "%5.5f", B->BRegrDev[k]) ;
				wpps("WASDAT", more, stuff, szIniPath) ;
				
		  }
//2345
	wpps("WASDAT", "RProjBestAt",		_itoa(B->RProjBestAt, num, 10), szIniPath) ;
	wpps("WASDAT", "LProjBestAt",		_itoa(B->LProjBestAt, num, 10), szIniPath) ;
	wpps("WASDAT", "BProjBestAt",		_itoa(B->BProjBestAt, num, 10), szIniPath) ;

	wpps("WASDAT", "RRegrBestAt",		_itoa(B->RRegrBestAt, num, 10), szIniPath) ;
	wpps("WASDAT", "LRegrBestAt",		_itoa(B->LRegrBestAt, num, 10), szIniPath) ;
	wpps("WASDAT", "BRegrBestAt",		_itoa(B->BRegrBestAt, num, 10), szIniPath) ;

		  sprintf(stuff, "%5.5f",B->RightRegrCoeff) ;
		  wpps("WASDAT", "RightRegrCoeff",      stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->LeftRegrCoeff) ;
		  wpps("WASDAT", "LeftRegrCoeff",      stuff, szIniPath) ;
		  
		  sprintf(stuff, "%5.5f",B->BothRegrCoeff) ;
		  wpps("WASDAT", "BothRegrCoeff",      stuff, szIniPath) ;
		  

//****************  Measure stuff started here in the DAT

	  sprintf(stuff,"%5.5f", M->iTopPole.x) ;
		  wpps("WASDAT","xTopPole", stuff, szIniPath) ;
		  
	  sprintf(stuff,"%5.5f", M->iTopPole.y) ;
		  wpps("WASDAT","yTopPole", stuff, szIniPath) ;
		  
		  
		  
	  sprintf(stuff,"%5.5f", M->iBotPole.x) ;
		  wpps("WASDAT","xBotPole", stuff, szIniPath) ;
		  
	  sprintf(stuff,"%5.5f", M->iBotPole.y) ;
		  wpps("WASDAT","yBotPole", stuff, szIniPath) ;
		  

	  sprintf(stuff,"%5.5f", M->iAxisGradIcept.x) ;
		  wpps("WASDAT","AxisGrad", stuff, szIniPath) ;
		  
	  sprintf(stuff,"%5.5f", M->iAxisGradIcept.y) ;
		  wpps("WASDAT","AxisIcept", stuff, szIniPath) ;
		  

		  for (k = 1 ; k <= Levels ; k++)
		  {
			  _itoa(k, num, 10) ;
	  strcpy(more, "xAxisCut") ;	  strcat(more, num) ; 
	  sprintf(stuff,"%5.5f", M->iAxisCuts[k].x) ;
		  wpps("WASDAT", more, stuff, szIniPath) ;
		  
		  
	  strcpy(more, "yAxisCut") ;	  strcat(more, num) ; 
	  sprintf(stuff,"%5.5f", M->iAxisCuts[k].y) ;
		  wpps("WASDAT", more, stuff, szIniPath) ;
		  
		  }
		  
		  for (k = 1 ; k <= Levels ; k++)
		  {
			  _itoa(k, num, 10) ;
	  strcpy(more, "LevelGrad") ;	  strcat(more, num) ; 
	  sprintf(stuff,"%5.5f", M->iLevGradIcepts[k].x) ;
		  wpps("WASDAT", more, stuff, szIniPath) ;
		  
		  
	  strcpy(more, "LevelIcept") ;	  strcat(more, num) ; 
	  sprintf(stuff,"%5.5f", M->iLevGradIcepts[k].y) ;
		  wpps("WASDAT", more, stuff, szIniPath) ;
		  
		  }

 		  for (k = 1 ; k <= Levels ; k++)
		  {
			  _itoa(k, num, 10) ;
	  strcpy(more, "xLeft") ;	  strcat(more, num) ; 
	  sprintf(stuff,"%5.5f", M->iLeftCut[k].x) ;
		  wpps("WASDAT", more, stuff, szIniPath) ;
		  
		  
	  strcpy(more, "yLeft") ;	  strcat(more, num) ; 
	  sprintf(stuff,"%5.5f", M->iLeftCut[k].y) ;
		  wpps("WASDAT", more, stuff, szIniPath) ;
		  
		  }

		  for (k = 1 ; k <= Levels ; k++)
		  {
			  _itoa(k, num, 10) ;
	  strcpy(more, "xRight") ;	  strcat(more, num) ; 
	  sprintf(stuff,"%5.5f", M->iRightCut[k].x) ;
		  wpps("WASDAT", more, stuff, szIniPath) ;
		  
		  
	  strcpy(more, "yRight") ;	  strcat(more, num) ; 
	  sprintf(stuff,"%5.5f", M->iRightCut[k].y) ;
		  wpps("WASDAT", more, stuff, szIniPath) ;
		  
		  }

		  for (k = 1 ; k <= Levels ; k++)
		  {
			  _itoa(k, num, 10) ;
	  strcpy(more, "LeftRadius") ;	strcat(more, num) ;
	  sprintf(stuff,"%5.5f", M->iLeftRad[k]) ;
		  wpps("WASDAT", more, stuff, szIniPath) ;
		  
	  
	  strcpy(more, "RightRadius") ;	strcat(more, num) ;
	  sprintf(stuff,"%5.5f", M->iRightRad[k]) ;
		  wpps("WASDAT", more, stuff, szIniPath) ;
		  

	  strcpy(more, "Diameter") ;	strcat(more, num) ;
	  sprintf(stuff,"%5.5f", M->iDiameter[k]) ;
		  wpps("WASDAT", more, stuff, szIniPath) ;
		  
		  }
 }
			if (isOpen)
			{
			hDest = _ISOpenFileDest( szFile ) ;			// szfile is the fully qualified path of a JPG

						_ISWriteJPG
						(
							hDest,
							pRGB,
							wid,
							hyt,
							JPGQuality,
							0,
							24,
							NULL
						) ;

			_ISCloseDest(hDest) ;
			_ISClearJPGOutputText() ;	// clear output texts
			GlobalFree(hRGB) ;
			} 			
}


DWORD gpps(char * field, char * key, char * dflt, char * info, DWORD bsize, char * ini)
{
	return GetPrivateProfileString
			( field, key, dflt, info, bsize, ini ) ;
}

void wpps(char * field, char * key, char * info, char * ini)
{
		WritePrivateProfileString
			( field, key, info, ini ) ;
}

int NextLine(HFILE f, char * L)
{
      int n, i  ;
	 char c ;

	i = 0 ;
	while (n = _lread(f,&c,1))
	{
		if (c != 13) // if not a CR, append character
			L[i++] = c ;
		else		 
		{
			L[i] ='\0' ;  // make ASCIIZ

		    return L ;
		}
	}

	 return -1 ; // signal end of file
}


void SaveDatFile(int toTree, IDS I)
{
	//OFSTRUCT of ;
LPBUDRESULTS B ;
   LPMEASURE M ;
      HANDLE hbud ;
	    BOOL bErrorFlag = FALSE ;
	   DWORD dwBytesToWrite1 = (DWORD)sizeof(struct tagBUDRESULTS) ;
	   DWORD dwBytesToWrite2 = (DWORD)sizeof(struct tagMEASURE) ;
       DWORD dwBytesWritten  = 0;
   HTREEITEM HT, hT ;
	    UINT FID, ID, TYP ;
		char nstr[100] ;
		 int k ;

      B = pBudResults ;
	  M = pMeasure ;

	  Note(1, "Saving to DAT") ;

hbud = CreateFile(szDatPath,                // name of the write
                       GENERIC_WRITE,          // open for writing
                       0,                      // do not share
                       NULL,                   // default security
                       CREATE_ALWAYS,          // create and overwrite existing
                       FILE_ATTRIBUTE_NORMAL,  // normal file
                       NULL);                  // no attr. template

    if (hbud == INVALID_HANDLE_VALUE) 
	   {
		   char str[255];
		   sprintf(str,
                   "Save Data File\n" \
                   "%s\n" \
                   "failed. Not Written.",
                    szDatPath) ;
		   msgbox = 1 ;
		   MessageBox(NULL,str,"SaveDatFile()",MB_OK) ;
		   msgbox = 0 ;
		   return ; // do NOT attempt to write to the file or update trees
	   }

bErrorFlag = WriteFile( 
                    hbud,				// open file handle
                    B,					// start of data to write
                    dwBytesToWrite1,	// number of bytes to write
                    &dwBytesWritten,	// number of bytes that were written
                    NULL);				// no overlapped structure

    if (FALSE == bErrorFlag)
       printf("Unable to write to file.\n");

bErrorFlag = WriteFile( 
                    hbud,				// open file handle
                    M,					// start of data to write
                    dwBytesToWrite2,	// number of bytes to write
                    &dwBytesWritten,	// number of bytes that were written
                    NULL);				// no overlapped structure

    if (FALSE == bErrorFlag)
       printf("Unable to write to file.\n");
	CloseHandle(hbud) ;

	if (toTree)
	{

	if (hWndTreeSer != (HWND)NULL)
	{
		if ((HT = SearchTree(hWndTreeSer, 0, A.szKnownpfx[I.pfxID], &ID, &TYP)) != (HTREEITEM)NULL)
		{
			// we have the prefix reference

						_itoa((k = A.iNumdatpthsperpfx[I.pfxID]), nstr, 10) ;
						if (k == 1)
					   strcat(nstr, " set.") ;
						else
					   strcat(nstr, " sets.") ;


				if ((hT = SearchTree(hWndTreeSer, 0, A.szKnownpth[I.datpth], &ID, &TYP)) == NULL)
				{
					// no ref to DAT path: insert it
					FID = PutItmDat(A.iDatpthperpfx[I.pfxID][I.datID], DATPTH) ;
					PutInTree(hWndTreeSer,			// add new DAT path to tree
							hT,						// under the DAT path count
							hT,
							A.szKnownpth[I.datpth],	// 
							tvDatpth,				// 
							FID) ;					//
				} // is ref to Datpath

				if ((hT = T.hTreeSerdatSet[I.pfxID]) != (HTREEITEM)NULL)
				{
						tvItm.mask = TVIF_TEXT ;						// specify item to change
						tvItm.hItem = hT ;								// get and give the handle
						tvItm.pszText = nstr ;							// buffer with new text
						TreeView_SetItem(hWndTreeSer, &tvItm) ;			// change item text (new dat path count)
				}
		} // no prefix
	} // no tree available
	}

}

void SaveTrkFile(LPTRKINFO trk, int toTree, IDS I)
// This is for adventitious tracks, i.e., for tracks just made.
// Not used during a general search of the archive
{
	OFSTRUCT of ;
	HFILE htrack ;
	HTREEITEM HT, hT ;
	UINT FID, ID, TYP ;
	char nstr[100] ;
	 int k ;

	if ((htrack = OpenFile(szTrkPath, &of, OF_WRITE)) == HFILE_ERROR)
	{
		char str[255] ;
		sprintf(str,
                "Save Track File\n" \
                "%s \n" \
                "failed. Not written.",
                 szTrkPath) ;
		msgbox = 1 ;
		MessageBox(NULL, str, "SaveTrkFile()", MB_OK) ;
		msgbox = 0 ;
		return ; // do NOT attempt to write to the file or update the trees
	}

	// After a header, the tracks are written to disk just as they currently are in memory.
	//
	// The header provides the image height in pixels, then gives the line indices where
	// tracks begin and end, first on the left, then on the right. The indices increase from
	// zero at the _bottom_ of the image.
												   
	  _hwrite(htrack, (LPBYTE)&hs,  sizeof(int)) ;				// the height in lines

	  _hwrite(htrack, (LPBYTE)trk->Blftloidx,  sizeof(int)) ;	// the  left lo index
	  _hwrite(htrack, (LPBYTE)trk->Blfthiidx,  sizeof(int)) ;	// the  left hi index
	  _hwrite(htrack, (LPBYTE)trk->Brytloidx,  sizeof(int)) ;	// thr right lo index
	  _hwrite(htrack, (LPBYTE)trk->Brythiidx,  sizeof(int)) ;	// the right hi index

	  // entire left track info
	  _hwrite(htrack, (LPBYTE)trk->Beplft, hs * sizeof(int)) ; // can be negative
	  // entire right track info
	  _hwrite(htrack, (LPBYTE)trk->Bepryt, hs * sizeof(int)) ;

	  _lclose(htrack) ;

	if (toTree) // we are checking tree entries for this TRK
	{ // is there a tree?
	if (hWndTreeExp != (HWND)NULL)
	{ // yes, there is.  is the ref. to the TRK installed?
	  if (SearchTree(hWndTreeExp, 0, A.szKnowntrk[I.trkID], &ID, &TYP) == (HTREEITEM)NULL)
	  { // no, it isn't.  is the corresponding prefix in the tree?
		if (SearchTree(hWndTreeExp, 0, A.szKnownpfx[I.pfxID], &ID, &TYP) != (HTREEITEM)NULL)
		{ // yes, it is.  is there a corresponding image in the tree?
			if ((HT = SearchTree(hWndTreeExp, 0, A.szKnownimg[I.imgID], &ID, &TYP)) != (HTREEITEM)NULL)
			{// yes, there is. insert the ref.
				FID = PutItmDat(I.trkID, TRK) ;
				T.hTreeExpTrk[I.trkID] = hT = PutInTree(hWndTreeExp, HT, HT,
														A.szKnowntrk[I.trkID],
														tvTrk, FID) ;
				// we have the image reference (handle hT)
				// insert the path to the ref.
				FID = PutItmDat(I.trkpth, TRKPTH) ;
				T.hTreeExpTrkPth[I.trkpth] = PutInTree(hWndTreeExp, hT, hT,
													   A.szKnownpth[I.trkpth],
													   tvTrkpth, FID) ;
			} // drop through => was no image
		} // drop through => was no prefix  
	  } // drop through => ref is already installed
	} // drop through => no valid tree

	if (hWndTreeSer != (HWND)NULL) // the series and suites tree 
	{
		// do we have the prefix reference?
		if ((HT = SearchTree(hWndTreeSer, 0, A.szKnownpfx[I.pfxID], &ID, &TYP)) != (HTREEITEM)NULL)
		{
			// yes, we have the prefix reference (handle HT).
			// do we have the track count?
			if ((hT = T.hTreeSertrkSet[I.pfxID]) != (HTREEITEM)NULL)
			{
				// yes, we have the track count reference (handle hT)
				// get the track count
				_itoa((k = A.iNumtrkpthsperpfx[I.pfxID]), nstr, 10) ;
						if (k == 1)
					   strcat(nstr, " set.") ;
						else
					   strcat(nstr, " sets.") ;

						tvItm.mask = TVIF_TEXT ;						// specify item to change
						tvItm.hItem = hT;								// get and give the handle
						tvItm.pszText = nstr ;							// buffer with new text
						TreeView_SetItem(hWndTreeSer, &tvItm) ;			// change item text (new trk path count)

				// do we have the corresponding track path reference?  
				if (SearchTree(hWndTreeSer, 0, A.szKnownpth[I.trkpth], &ID, &TYP) == NULL)
				{
					// No, there is no ref to track path: insert it
					FID = PutItmDat(I.trkpth, TRKPTH) ;
					PutInTree(hWndTreeSer,			// add new trk path to tree
							hT,						// under the trk path count
							hT,
							A.szKnownpth[I.trkpth],	// 
							tvTrkpth,				// 
							FID) ;					//
				} // is ref to trkpath
			} // ref to track path count
		} // no prefix
	} // no tree
	} // End enter in trees
}

LPSUITE MakeSuite
(
 char * description,
 int iIMG,
 int iINI,
 int iDAT,
 int iTRK,
 LPSUITE pS
)
{
				  strcpy(pS->desc, description) ;	// suite description-string 
						 pS->iIMGpth = iIMG ; // use the iIMG'th path in the IMG path list
						 pS->iINIpth = iINI ; // use the iINI'th path in the INI path list
						 pS->iDATpth = iDAT ; // use the iDAT'th path in the DAT path list
						 pS->iTRKpth = iTRK ; // use the iTRK'th path in the TRK path list

				return pS ;
}

LPSUITE CreateSuite(char *p, int pfxID)
/*********************************************
	Create a new Suite and its corresponding
	file structure within the current Working
	Archive for a given Prefix ID
 *********************************************/
{
 HTREEITEM hT ;
   LPSUITE pS ;
	char *d ;
	char  dfltstr[100] ;
//	char szImgpth[256] ;
	char szInipth[256] ;
	char szDatpth[256] ;
	char szTrkpth[256] ;
	char szSubstitute[256] ;
	char     nstr[ 20] ;
     int u, k;
	 int inipth, datpth, trkpth ;
  // int imgpth ;
				if ((pS = (LPSUITE)GlobalAlloc(GPTR, sizeof(SUITE))) != NULL)
						{
/*++
 						 usename = DialogBox(hInst,
					     MAKEINTRESOURCE(IDD_NAME_SUITE),
					     hWndCtrl,
						 NameSuiteDlgProc) ;
--*/
						strcpy(dfltstr, p) ;
						strcat(dfltstr, " default") ;

/****
						strcpy(szImgpth, AllImg) ;  // form a path to images
						strcat(szImgpth, dfltstr1) ;
						strcat(szImgpth, "\\") ;
						if (!(_mkdir(szImgpth)))	// create a subdir (returns zero on success)
						{
						// if subdir OK
						imgpth = A.iGpthIDs ;
						d = (char *)GlobalAlloc(GPTR,(strlen(szImgpth) + 2) * sizeof(char)) ; // record path in ABR
						strcpy(d, szImgpth) ;
						A.szKnownpth[imgpth] = d ;
						
						// move the image file from its current location
						// into the ABR.
						strcat(d, DropPath(f)) ;
						CopyFile(f, d, FALSE) ;
						//DeleteFile() ;
						// acquaint the PFX ID with the IMG PTH ID
						u = A.iNumimgpthsperpfx[pfxID]  ;
						A.iImgpthperpfx[pfxID][u] = imgpth ;
						A.iNumimgpthsperpfx[pfxID]++ ;
						checkABR(imgpth) ;
						}
****/

						strcpy(szInipth, AllIni) ;  // form a path to INIs
						strcat(szInipth, "\\") ;
						strcat(szInipth, dfltstr) ;
						strcat(szInipth, "\\") ;
						//strcpy(szSubstitute, DupSlash(szInipth)) ;
						strcpy(szSubstitute, szInipth) ;

						if (!(_mkdir(szSubstitute)))	// create a subdir (returns zero on success)
						{
						// if subdir OK
						inipth = A.iGpthIDs ;
						d = (char *)GlobalAlloc(GPTR,(strlen(szInipth) + 2) * sizeof(char)) ; // record path in ABR
						strcpy(d, szInipth) ;
						A.szKnownpth[inipth] = d ;
						incpth("CreateSuite(): ini path") ; //A.iGpthIDs++ ; nearing limit?

						// acquaint the PFX ID with the INI PTH ID
						u = A.iNuminipthsperpfx[pfxID]  ;
						A.iInipthperpfx[pfxID][u] = inipth ;
						A.iNuminipthsperpfx[pfxID]++ ;
						}
						else
							MessageBox(NULL, "Failed to Create INI path", "CreateSuite()", MB_OK) ;

						if (useDATs)
						{
						strcpy(szDatpth, AllDat) ;	// form a path to DATs
						strcat(szDatpth, "\\") ;
						strcat(szDatpth, dfltstr) ;
						//strcat(szDatpth, "\\") ;
						//strcpy(szSubstitute, DupSlash(szDatpth)) ; 
						strcpy(szSubstitute, szDatpth) ;
						if (!(_mkdir(szSubstitute)))	// create a subdir (returns zero on success)
						{
						// if subdir OK
						datpth = A.iGpthIDs ;
						d = (char *)GlobalAlloc(GPTR,(strlen(szDatpth) + 2) * sizeof(char)) ; // record path in ABR
						strcpy(d, szDatpth) ;
						A.szKnownpth[datpth] = d ;
						incpth("CreateSuite(): dat path")  ; //A.iGpthIDs++ ;

						// acquaint the PFX ID with the DAT PTH ID
						u = A.iNumdatpthsperpfx[pfxID]  ;
						A.iDatpthperpfx[pfxID][u] = datpth ;
						A.iNumdatpthsperpfx[pfxID]++ ;
						}
						else
							MessageBox(NULL, "Failed to Create DAT path", "CreateSuite()", MB_OK) ;
						}

						strcpy(szTrkpth, AllTrk) ;	// form a path to TRKs
						strcat(szTrkpth, "\\") ;
						strcat(szTrkpth, dfltstr) ;
						strcat(szTrkpth, "\\") ;
						//strcpy(szSubstitute, DupSlash(szTrkpth)) ;
						strcpy(szSubstitute, szTrkpth) ;
						if (!(_mkdir(szSubstitute)))
						{
						// if subdir OK
						trkpth = A.iGpthIDs ;
						d = (char *)GlobalAlloc(GPTR,(strlen(szTrkpth) + 2) * sizeof(char)) ; // record path in ABR
						strcpy(d, szTrkpth) ;
						A.szKnownpth[trkpth] = d ;
						incpth("CreateSuite(): trk path")  ; //A.iGpthIDs++ ;

						// acquaint the PFX ID with the TRK PTH ID
						u = A.iNumtrkpthsperpfx[pfxID] ;
						A.iTrkpthperpfx[pfxID][u] = trkpth ;
						A.iNumtrkpthsperpfx[pfxID]++ ;
						
						}
						else
							MessageBox(NULL, "Failed to Create TRK path", "CreateSuite()", MB_OK) ;


						// construct the default suite
						// for the new prefix.
						pS = MakeSuite(dfltstr,
											0,
											inipth,
											datpth,
											trkpth,
											pS ) ;

						// add the suite to the prefix's Suite List.
						A.pSuiteperpfx[pfxID][A.iNumsuiperpfx[pfxID]] = pS ;
						A.iNumsuiperpfx[pfxID]++ ;

						// get it into the Series & Suites Tree.
						_itoa((k = A.iNumsuiperpfx[pfxID]), nstr, 10) ; // suite-count as text

						if (k != 1)
						strcat(nstr, " suites.") ;	// if plural, or none
						else
						strcat(nstr, " suite.") ;	// if singular

						tvItm.mask = TVIF_TEXT ;						// specify item to change
						tvItm.hItem = hT = T.hTreeSersuiSet[pfxID];		// get and give the handle
						tvItm.pszText = nstr ;							// buffer with new text

						TreeView_SetItem(hWndTreeSer, &tvItm) ;			// change item text (new suite count)

									  PutInTree(hWndTreeSer,			// add new suite to tree
												hT,						// under the suite count
												hT,
												pS->desc,				// suite's description
												tvSui,					// suite bitmap
												0) ;					// don't need the ID

						return pS ; // return pointer to new suite
						}
				return (LPSUITE)NULL ; // or a null if it didn't work
}

/****************************************

  Tree View functions

 ****************************************/

void UpdateTrees( void )
{
			// fill the per-prefix tree view
			// FillTree(hWndTree) ;

			// fill the 'Experimental' tree view
			FillTree(hWndTreeExp) ;

			// fill the per-series tree view
			FillTreeSer() ;
}

//******************************************************************
// InitTreeViewImageLists - creates an image list, adds bitmaps 
// to it, and associates the image list with a tree view control. 
// Returns TRUE if successful, or FALSE otherwise. 
// hWndTV - handle to the tree view control. 
//
// Global variables and constants 
// tvPfx, tvImg, tvIni, tvDat etc. - integer variables for 
// indices of the images. 
//******************************************************************

BOOL InitTreeViewImageLists(HWND hWndTV) 
{ 
    HIMAGELIST himl;  // handle to image list 
    HBITMAP hbmp;     // handle to bitmap 

    // Create the image list, return its handle.
	
    if ((himl = ImageList_Create(16, 16, FALSE, 19, 0)) == NULL)
        return FALSE;

    // Load and add the bitmaps. 
    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_PFX));	// prefix 
    tvPfx = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp); 

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_IMG)); // IMG 
    tvImg = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp); 

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_INI)); // INI 
    tvIni = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp); 

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_DAT));	// DAT 
    tvDat = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp); 

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_TRK));	// TRK 
    tvTrk = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp); 

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_PTH));	// Path 
    tvPth = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp);
	
    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_SER));	// Series 
    tvSer = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp);

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_IMGSER));	// IMG file in a set 
    tvImgSer = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp);

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_INISER));	// INI file in a set
    tvIniSer = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp);

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_DATSER));	// DAT file in a set
    tvDatSer = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp);

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_TRKSER));	// TRK file in a set
    tvTrkSer = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp);

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_SUI)); 
    tvSui = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp);
	
    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_SUISER)); 
    tvSuiSer = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp);

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_IMGPTH)); 
    tvImgpth = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp); 

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_INIPTH)); 
    tvInipth = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp); 

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_DATPTH)); 
    tvDatpth = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp); 

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_TRKPTH)); 
    tvTrkpth = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp); 

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_ARC)); 
    tvArc = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp);

    hbmp  = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TV_BULLET)); 
    tvBul = ImageList_Add(himl, hbmp, (HBITMAP) NULL); 
    DeleteObject(hbmp);

   // Fail if not all of the images were added. 
    if (ImageList_GetImageCount(himl) < 19)
        return FALSE;

    // Associate the image list with the tree view control. 
    TreeView_SetImageList(hWndTV, himl, TVSIL_NORMAL); 

    return TRUE; 
}

/* --------------------------------------------------
	Place an item in a Tree View.

  The ID number here is the composite of the TYPE
  (IMG, INI, DAT etc) and the per-type global ID
  of the item.
   --------------------------------------------------*/
HTREEITEM PutInTree
(
		 HWND hWndTV,	// tree view window handle
	HTREEITEM hti,		// parent-item handle
	HTREEITEM htia,		// insert-after handle
	    LPSTR pszItem,	// item string
		 UINT TVIMG,	// image list index
		 UINT ID		// composite ID number
)
{
			   int Tree ;
	        TVITEM tvi ;
    TVINSERTSTRUCT tvins ;
	     HTREEITEM hRet ;

		 if (hWndTV == hWndTreeSer) {Tree = 1 ; goto gotit ;}
		 if (hWndTV == hWndTreeExp) {Tree = 2 ; goto gotit ;}
		 if (hWndTV == hWndTreeArc)  Tree = 3 ;
gotit:
		 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM ; // types that can go in the collection

           tvi.pszText = pszItem ;			// Set the text of the item. 
        tvi.cchTextMax = strlen(pszItem) ;	// Set the length of the text
            tvi.iImage = TVIMG ;			// "Non-selected" image 
    tvi.iSelectedImage = TVIMG ;			// "Selected" image
			tvi.lParam = (LPARAM)ID ;		// User-defined 32 bit number

			tvins.item = tvi ;				// the collection of items to insert
         tvins.hParent = hti ;				// the item receiving the insertion 
    tvins.hInsertAfter = htia ;				// after which item to insert the collection
	
    // Add the item to the tree view control
	hRet = TreeView_InsertItem(hWndTV, &tvins) ;		// do it!
	UpdateWindow(hWndTV) ;

	if (hRet != NULL)									// keep accounts
	{
		 int u ;
		u = T.iNumTreeItems[Tree] ;			// currently available ordinal for Tree
		T.hTreeItems[Tree][u] = hRet ;			// record the inserted item's handle
        T.iNumTreeItems[Tree] = ++u ;				// next ordinal
	    T.iTotTreeItems++ ;								// increment total
			_itoa(T.iTotTreeItems, T.szItems, 10) ;
			strcat(T.szItems, " Tree Items") ;
			SetWindowText(GetDlgItem(hDlgStats, IDC_S_ITEMCOUNT), T.szItems ) ;
		return hRet ;
	}
	else	// it didn't work
	{
		char str[10] ;
		char  st[100] = "Tree " ;
		_itoa(Tree, str, 10) ;
		strcat(st, str) ;
		strcat(st," - Insert failed.") ;
		MessageBox(NULL, st, "Tree View", MB_OK) ;	// report failure
	}
	return hRet ;
}

/* -----------------------------------------------------------
	Get Info from Item in the Tree.

  if 'what' is zero, get item text
  if 'what' is greater than zero, get item TYP/ID

  if item found, return the item's Tree handle
		- if text   found, copy TYP and ID back
		- if TYP/ID found, copy text back

	else return a NULL handle.
   ----------------------------------------------------------- */
HTREEITEM LookinTree
(
	  HWND hWndTV,			// tree handle
	   int what,			// what == 0 means find text, what == 1 means find TYP/ID
 HTREEITEM hti,				// item's handle
     LPSTR szFind,			// text in or out
	  UINT * ID,			// ID   in or out
	  UINT * TYP			// TYP  in or out
)
{
	  UINT itemdata[3] ;
	  UINT TYPE ; 
	TVITEM tvItm ;
	  char szText[256] ;
	// specify items wanted
			 tvItm.mask = TVIF_TEXT | TVIF_PARAM ;	// want text and Composite ID
			 tvItm.hItem = hti ;					// give the selection's handle
			 tvItm.pszText = szText ;				// text buffer
			 tvItm.cchTextMax = 256 ;				// length of text buffer

			 TreeView_GetItem(hWndTV, &tvItm) ;	// get the item

			 if (what)	// (what > 0) implies we are checking out either type or ID, or both 
			 {
				if (TYPE = GetItemData(hWndTV, hti, itemdata))
				{
				// TYP is non-zero
				 if ((TYPE == * TYP) && (itemdata[1] == * ID))
				 {
				  // type and ID both check out
					 strcpy(szFind, szText) ;				// copy item text over
					 return hti ;							// item found, return its handle
				 }
				}
			 }
			 else		// (what == 0) implies we are checking out text
			 {
				if (!strcmp(szFind, szText))
				{
				// the texts match
					GetItemData(hWndTV, hti, itemdata) ;	// get type and ID
					* TYP = itemdata[0] ;					// copy over TYP
					 * ID = itemdata[1] ;					// copy over ID
					 return hti ;							// item found, return its handle
				}
			 }
			 return (HTREEITEM)NULL ;
}

/* -----------------------------------------------------------
				Find an Item in the Tree.

  detects which tree from tree window handle, and uses
  the appropriate list of tree item handles

  if 'what' is zero, search for an item with text szFind
  if 'what' is greater than zero, search for item with TYP/ID

  calls LookinTree()

  if item found, return the item's tree item handle
		- if text   found, copy TYP and ID back
		- if TYP/ID found, copy text back
							else return a NULL handle.
   ----------------------------------------------------------- */
HTREEITEM SearchTree
(
		   HWND hWndTV,		// tree handle
		    int what,		// whether to find item text (what == 0), or item TYP/ID (what != 0)
		   char * szFind,	// item text to find, or found
		   UINT * ID,		//        ID to find, or found
		   UINT * TYP		//      type to find, or found
)
{
	   int i, n, Tree ;
	   if (hWndTV == hWndTreeSer)	{Tree = 1 ; goto gottree ;}
	   if (hWndTV == hWndTreeExp)	{Tree = 2 ; goto gottree ;}
	   if (hWndTV == hWndTreeArc)    Tree = 3 ;
gottree:;
	  for (i = 0, n = T.iNumTreeItems[Tree] ; i < n  ; i++)
	  {
		  HTREEITEM hitm ;
		  if (
			  (hitm = LookinTree(hWndTV, what, T.hTreeItems[Tree][i],
								 szFind,	// text to find, or found
								 ID,		//   ID to find, or found
								 TYP)		//  TYP to find, or found
								) != (HTREEITEM)NULL
			 )
				return hitm ;	// item found, return the item's handle
	  }
		return (HTREEITEM)NULL ;	  // item not found
}

BOOL RemoveFromTree
(
		HWND hWndTV,	// tree handle
		char * szFind	// text of item to remove
)
{
	HTREEITEM hitm ;
	UINT ID ;
	UINT TYP ;
	// first see if the item is actually in the tree
	if ((hitm = SearchTree(hWndTV, 0, szFind, &ID, &TYP)) == (HTREEITEM)NULL)
		return FALSE;	// item not in tree, nothing to remove
		return TreeView_DeleteItem(hWndTV, hitm) ;
}

// form composite tree item data number 
// from a global ID and a type  
UINT PutItmDat(UINT ID, UINT typ)
{
	UINT SID, TID ;

	SID = ID ;			// the ID
	TID = typ ;			// the type
	TID <<= 24 ;		// left shift type to most significant 8 bits
	TID |= SID ;		// OR it with the ID

	return TID ;
}

// get type and ID from composite item data
// associated with a Tree item
UINT GetItemData( HWND hWnd, HTREEITEM hti, UINT * itemdat )
{
	TVITEM tvi ;
	  UINT TYP, ID ;

	 tvi.mask = TVIF_PARAM ;
	tvi.hItem = hti ;

	TreeView_GetItem(hWnd, &tvi) ;

		  TYP = ID = (UINT)tvi.lParam ;
		  TYP >>= 24 ;				// right-shift top 8 bits to bottom to obtain the type
		   ID &= 0x00FFFFFF ;		// zero the topmost 8 bits of the ID to isolate the ID

		   if (TYP > 0)				// type numbers start at 1, so zero indicates an error
		   {
			   itemdat[0] = TYP ;
			   itemdat[1] = ID ;
		   }
			   return TYP ;
}

void FillTreeSer( void )
{
		  int i, j, k ;
		 UINT FID, ID ;
		 char nstr[40] ;
    HTREEITEM ht, HT ;

			for (i = 0 ; i < A.iPfxIDs ; i++)
			{
				// PFXs **********************
					FID = PutItmDat( (UINT)i, PFX ) ;
						  HT = PutInTree(hWndTreeSer, 
										 TVI_ROOT,			// place in Tree View ROOT
										 TVI_ROOT,			// place in Tree View ROOT
										 A.szKnownpfx[i],	// the Prefix string
										 tvPfx,				// use Prefix icon
										 FID) ;				// store type and PFX ID in item data area

					// ************* Suites

					_itoa((k = A.iNumsuiperpfx[i]), nstr, 10) ; // num as text
						if (k == 1)
						strcat(nstr, " suite.") ;
						else
						strcat(nstr, " suites.") ;
						T.hTreeSersuiSet[i] = ht = PutInTree(hWndTreeSer,
												HT, HT,
												nstr,
												tvSuiSer,
												0) ;

				for (j = 0 ; j < A.iNumsuiperpfx[i] ; j++)
				{
					LPSUITE ps ;
					FID = PutItmDat( (UINT)j, SUIT ) ;
					ps  = A.pSuiteperpfx[i][j] ;
									  PutInTree(hWndTreeSer,
												ht, ht,
												ps->desc,
												tvSui,
												FID) ;
				}

					// ************* Images 

					_itoa((k = A.iNumimgpthsperpfx[i]), nstr, 10) ; // num as text
						if (k == 1)
						strcat(nstr, " set.") ;
						else
						strcat(nstr, " sets.") ;
						T.hTreeSerimgSet[i] = ht = PutInTree(hWndTreeSer,
												HT, HT,
												nstr,
												tvImgSer,
												0) ;


				for (j = 0 ; j < A.iNumimgpthsperpfx[i] ; j++)
				{
					FID = PutItmDat(ID = (UINT)A.iImgpthperpfx[i][j], IMGPTH) ;
									  PutInTree(hWndTreeSer,
												ht, ht,
												A.szKnownpth[ID],
												tvImgpth,
												FID) ;
				}

					// ************* INIs

					_itoa((k = A.iNuminipthsperpfx[i]), nstr, 10) ; // num as text
						if (k == 1)
						strcat(nstr, " set.") ;
						else
						strcat(nstr, " sets.") ;
						T.hTreeSeriniSet[i] = ht = PutInTree(hWndTreeSer,
												HT, HT,
												nstr,
												tvIniSer,
												0) ;

				for (j = 0 ; j < A.iNuminipthsperpfx[i] ; j++)
				{
					FID = PutItmDat(ID = (UINT)A.iInipthperpfx[i][j], INIPTH) ;
					T.hTreeSerIniPth[ID] = PutInTree(hWndTreeSer,
												ht, ht,
												A.szKnownpth[ID],
												tvInipth,
												FID) ;
				}

					// ************* DATs

					_itoa((k = A.iNumdatpthsperpfx[i]), nstr, 10) ; // num as text
						if (k == 1)
						strcat(nstr, " set.") ;
						else
						strcat(nstr, " sets.") ;
						T.hTreeSerdatSet[i] = ht = PutInTree(hWndTreeSer,
												HT, HT,
												nstr,
												tvDatSer,
												0) ;


				for (j = 0 ; j < A.iNumdatpthsperpfx[i] ; j++)
				{
					FID = PutItmDat(ID = (UINT)A.iDatpthperpfx[i][j], DATPTH) ;
					T.hTreeSerDatPth[ID] = PutInTree(hWndTreeSer,
												ht, ht,
												A.szKnownpth[ID],
												tvDatpth,
												FID) ;
				}

					// ************* TRKs

					_itoa((k = A.iNumtrkpthsperpfx[i]), nstr, 10) ; // num as text
						if (k == 1)
						strcat(nstr, " set.") ;
						else
						strcat(nstr, " sets.") ;
						T.hTreeSertrkSet[i] = ht =PutInTree(hWndTreeSer,
												HT, HT,
												nstr,
												tvTrkSer,
												0) ;

				for (j = 0 ; j < A.iNumtrkpthsperpfx[i] ; j++)
				{
					FID = PutItmDat(ID = (UINT)A.iTrkpthperpfx[i][j], TRKPTH) ;
					T.hTreeSerTrkPth[ID] = PutInTree(hWndTreeSer,
												ht, ht,
												A.szKnownpth[ID],
												tvTrkpth,
												FID) ;
				}
			}
}


/******************************************************************
						FillTree()
	The Archivist should have searched the system for valid files
	before this	function is called, as it expects the inclusions
	in proper order.
 ******************************************************************/
void FillTree(HWND hWndT)
{
		  int i, j, k, m ;
		 UINT FID, ID, PID, DID ;
	HTREEITEM HT, ht, Ht, hp ;
static HTREEITEM htImg[MAXINST] ; 
	   //char  ininame[256], buff[256] ;
		 char   pfx[256] ;

			for (i = 0 ; i < A.iPfxIDs ; i++) // for all the known prefixes
			{
				strcpy(pfx, A.szKnownpfx[i]) ;

				if (!A.iNumImgperpfx[i]) // if there are no images for this pfx, double star its tree string
					strcat(pfx,"**") ;

				// show ALL the prefixes

				// PFXs **********************
					FID = PutItmDat( (UINT)i, PFX ) ;
						  HT = PutInTree(hWndT, 
										 TVI_ROOT,		// place in Tree View ROOT
										 TVI_ROOT,		// place in Tree View ROOT
										 pfx,			// the Prefix string
										 tvPfx,			// use Prefix icon
										 FID) ;			// store type and PFX ID in item data area

				for (j = 0 ; j < A.iNumImgperpfx[i] ; j++)	// do images first
				{
					// INSTANCES (IMGs) **********************
					// insert the image instances
					// belonging to this prefix

					 ID = (UINT)A.Imgperpfx[i][j] ;
					FID = PutItmDat(ID, IMG) ;	// image instance IDs for prefix
				    htImg[ID] = ht = PutInTree(hWndT,
										 HT, HT,			// insert under the Prefix entry
										 A.szKnownimg[ID],	// the instance string
										 tvImg,				// use image icon 
										 FID) ;				// store type and IMG ID in item data area
					
					// INSTANCE (IMG) PATHS
					// insert the paths to the image
					// instances belonging to this prefix

					for (k = 0 ; k < A.iNumpthsperimg[ID] ; k++) // num paths for instance ID
					{
					 PID = (UINT)A.iPthIDperimg[ID][k] ;
					 FID = PutItmDat(PID, IMGPTH) ; // k'th global path ID for instance image
									PutInTree(hWndT,
										ht, ht,				// under the instance/image entry
										A.szKnownpth[PID],	// the path string
										tvImgpth,			// use IMG path icon
										FID) ;				// store type and IMG path ID in item data area
					}
				}

					// INIs **********************
					// insert the INIs pertaining to the
					// instances(images) belonging to this prefix

				if (A.iNumImgperpfx[i]) // prefixes with images on the system
				{
				for (j = 0 ; j < A.iNumImgperpfx[i] ; j++)
				{
					// get the image ID
					ID = (UINT)A.Imgperpfx[i][j] ;
					// need the image item handle here
					ht = htImg[ID] ;
					for (k = 0 ; k < A.iNuminiperimg[ID] ; k++) // num global INIs for instance ID
					{
					 PID = (UINT)A.iIniperimg[ID][k] ;
					 FID = PutItmDat(PID, INI) ; // k'th global INI ID for instance image
				   T.hTreeExpIni[PID] = Ht = PutInTree(hWndT,
										ht, ht,				// under the instance/image
										A.szKnownini[PID],	// the INI string
										tvIni,			// use INI icon
										FID) ;			// store type and INI ID in item data area
					 // INI PATHS
					 // insert the INI paths pertaining to the INIs
					 // pertaining to the instances belonging to this prefix

						for (m = 0 ; m < A.iNumpthsperini[PID] ; m++) // paths to INIs
						{
							DID = (UINT)A.iPthIDperini[PID][m] ;
							FID = PutItmDat(DID, INIPTH) ;
			T.hTreeExpIniPth[DID] = hp = PutInTree(hWndT,		//
											Ht, Ht,				// under the INI entry
											A.szKnownpth[DID],	// the path string
											tvInipth,			// use path icon
											FID) ;				// store type and INI path ID in item data area
/***
							// we need some or all of the data from the INI on this path

						strcpy(ininame, A.szKnownpth[DID]) ;	// path to ini
						strcat(ininame, A.szKnownini[PID]) ;	// concat. ini name with path

						gpps("Projective Lambdas & MRDs", "Pr_Diam", "None",
							  buff, (DWORD)256, ininame) ;					// projective on diameters

							 PutInTree(hWndT,		//
									  hp, hp,			// under the INI PTH entry
									  buff,				// the data string
									  tvBul,			// use bullet
									  0) ;

						gpps("Regression Lambdas & MRDs", "Rg_Diam", "None",
							  buff, (DWORD)256, ininame) ;					// regression on diameters

							 PutInTree(hWndT,		//
									  hp, hp,			// under the INI PTH entry
									  buff,				// the data string
									  tvBul,			// use bullet
									  0) ;
***/
					 hp = hp ;	// dummy for breakpoint
						}
					}
				}
				}
				else // there is no image, place INI directly under the starred prefix
				{
					for (k = 0 ; k < A.iNumIniperpfx[i] ; k++) // num global INIs for instance ID
					{
					 PID = (UINT)A.Iniperpfx[i][k] ;
					 FID = PutItmDat(PID, INI) ; // k'th global INI ID for instance image
					T.hTreeExpIni[PID] = Ht = PutInTree(hWndT,
											HT, HT,				// under the starred prefix
											A.szKnownini[PID],	// the INI string
											tvIni,			// use INI icon
											FID) ;			// store type and INI ID in item data area
					 // INI PATHS
					 // insert the INI paths pertaining to the INIs
					 // pertaining to the instances belonging to this prefix

						for (m = 0 ; m < A.iNuminipthsperpfx[i] ; m++) // paths to INIs
						{
							DID = (UINT)A.iPthIDperini[PID][m] ;
							FID = PutItmDat(DID, INIPTH) ;
				T.hTreeExpIniPth[DID] = hp = PutInTree(hWndT,
									  Ht, Ht,			// under the INI entry
									  A.szKnownpth[DID],	// the path string
									  tvInipth,			// use path icon
									  FID) ;			// store type and INI path ID in item data area

							// we need some or all of the data from the INI on this path
/**
						strcpy(ininame, A.szKnownpth[DID]) ;	// path to ini
						strcat(ininame, A.szKnownini[PID]) ;	// concat. ini name with path

						gpps("Projective Lambdas & MRDs", "Pr_Diam", "None",
							  buff, (DWORD)256, ininame) ;					// projective on diameters

							 PutInTree(hWndT,		//
									  hp, hp,			// under the INI PTH entry
									  buff,				// the data string
									  tvBul,			// use bullet
									  0) ;

						gpps("Regression Lambdas & MRDs", "Rg_Diam", "None",
							  buff, (DWORD)256, ininame) ;					// regression on diameters

							 PutInTree(hWndT,		//
									  hp, hp,			// under the INI PTH entry
									  buff,				// the data string
									  tvBul,			// use bullet
									  0) ;
**/
							 hp = hp ;	// dummy for break

						}
					}
				}

					// TRKs **********************
				if (A.iNumImgperpfx[i]) // prefixes with images on the system
				{
				for (j = 0 ; j < A.iNumImgperpfx[i] ; j++)
				{
					ID = (UINT)A.Imgperpfx[i][j] ;
					// need the image item handle here
					ht = htImg[ID] ;
					for (k = 0 ; k < A.iNumtrkperimg[ID] ; k++) // num global TRKs for instance ID
					{
					 PID = (UINT)A.iTrkperimg[ID][k] ;
					 FID = PutItmDat(PID, TRK) ; // k'th global TRK ID for instance image
						   Ht = PutInTree(hWndT,
										  ht, ht,				// under the instance-image entry
										  A.szKnowntrk[PID],	// the TRK string
										  tvTrk,				// use TRK icon
										  FID) ;				// store type and TRK ID in item data area

						// TRK PATHS
						for (m = 0 ; m < A.iNumpthspertrk[PID] ; m++)	// paths to TRKs
						{
							DID = (UINT)A.iPthIDpertrk[PID][m] ;
							FID = PutItmDat(DID, TRKPTH) ;
							PutInTree(hWndT,
									  Ht, Ht,				// under the TRK entry
									  A.szKnownpth[DID],	// the path string
									  tvTrkpth,				// use path icon
									  FID) ;				// store type and TRK path ID in item data area
						}
					}
				}
				}
				else // there is no image, place TRK directly under the starred prefix
				{
					for (k = 0 ; k < A.iNumtrkpthsperpfx[i] ; k++) // num global TRKs for instance ID
					{
					 PID = (UINT)A.Trkperpfx[i][k] ;
					 FID = PutItmDat(PID, TRK) ; // k'th global TRK ID for instance image
						   Ht = PutInTree(hWndT,
										  HT, HT,				// under the starred prefix
										  A.szKnowntrk[PID],	// the TRK string
										  tvTrk,				// use TRK icon
										  FID) ;				// store type and TRK ID in item data area

						// TRK PATHS
						for (m = 0 ; m < A.iNumpthspertrk[PID] ; m++)	// paths to TRKs
						{
							DID = (UINT)A.iPthIDpertrk[PID][m] ;
							FID = PutItmDat(DID, TRKPTH) ;
							PutInTree(hWndT,
									  Ht, Ht,				// under the TRK entry
									  A.szKnownpth[DID],	// the path string
									  tvTrkpth,				// use path icon
									  FID) ;				// store type and TRK path ID in item data area
						}
					}
				}
		}

}// FillTree()

