(FILECREATED "21-Aug-86 12:10:58" {QV}<NOTECARDS>1.3K>LIBRARY>NOTEFILESTATS.;26 68595  

      changes to:  (FNS NFSTAT.SummarizeDataFiles)

      previous date: "19-Aug-86 18:39:39" {QV}<NOTECARDS>1.3K>LIBRARY>NOTEFILESTATS.;24)


(* Copyright (c) 1986 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT NOTEFILESTATSCOMS)

(RPAQQ NOTEFILESTATSCOMS ((* * This code computes statistics for a notefile.)
			    (GLOBALVARS NFSTAT.HistSize NFSTAT.HashArraySize)
			    (VARS (NFSTAT.HistSize 100)
				  (NFSTAT.HashArraySize 100))
			    (RECORDS NOTEFILEINFO NOTEFILEATTRIBUTES NOTEFILEDATA ALLCARDSDATA 
				     CARDTYPEDATA FILEBOXDATA CARDHISTENTRY FILEBOXHISTENTRY 
				     CARDSTATS STATSFROMHIST EXTRAFILEBOXDATA SPECIALFBDATA)
			    (* * Top level functions.)
			    (FNS NFSTAT.AnalyzeRemoteNoteFile NFSTAT.GatherNoteFileData)
			    (* * Helper functions.)
			    (FNS NFSTAT.MakeFreshNoteFileDataRecord NFSTAT.ProcessCards 
				 NFSTAT.ProcessFileBoxHierarchies NFSTAT.ComputeNoteFileStats)
			    (FNS NFSTAT.AddCardDataToHist NFSTAT.AddFileBoxDataToHist 
				 NFSTAT.AddCardSizeDataToHist NFSTAT.MakeFreshHistRecord 
				 NFSTAT.TraverseFileBoxHierarchy NFSTAT.ComputeSubstanceSize 
				 NFSTAT.IncrementHashItem NFSTAT.FetchCardTypeData 
				 NFSTAT.FillInCardStats)
			    (MACROS NFSTAT.AddFieldEntryToHist NFSTAT.AnalyzeHist)
			    (* * Stuff for dealing with extra file box data.)
			    (FNS NFSTAT.MakeFreshExtraFileBoxDataRecord 
				 NFSTAT.MakeFreshSpecialFBDataRecord NFSTAT.InstallExtraFileBoxData 
				 NFSTAT.InstallSpecialFBData NFSTAT.ComputeExtraFileBoxStats 
				 NFSTAT.ComputeSpecialFBStats NFSTAT.CombineExtraFileBoxData 
				 NFSTAT.CombineSpecialFBData)
			    (* * Miscellaneous accelerators.)
			    (FNS NFSTAT.AnalyzeSetsOfNoteFiles NFSTAT.AnalyzeListOfNoteFiles 
				 NFSTAT.MakeOutputFileName NFSTAT.InspectDataFile)
			    (* * Functions for plotting.)
			    (FILES PLOTEXAMPLES)
			    (FNS NFSTAT.NoteFileInfoHistPlot NFSTAT.FileBoxDataHistPlot 
				 NFSTAT.CardDataHistPlot NFSTAT.ExtraFileBoxDataHistPlot 
				 NFSTAT.AttachStatsWindow)
			    (MACROS NFSTAT.HistPlot)
			    (* * Functions for combining stats from multiple notefiles.)
			    (FNS NFSTAT.SummarizeDataFiles NFSTAT.CombineNoteFileData 
				 NFSTAT.CombineCardTypesData NFSTAT.CombineHashArrays 
				 NFSTAT.CombineHists NFSTAT.ComputeStatsFromDepthHist)
			    (DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS
				      (ADDVARS (NLAMA)
					       (NLAML)
					       (LAMA NFSTAT.AnalyzeSetsOfNoteFiles)))))
(* * This code computes statistics for a notefile.)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NFSTAT.HistSize NFSTAT.HashArraySize)
)

(RPAQQ NFSTAT.HistSize 100)

(RPAQQ NFSTAT.HashArraySize 100)
[DECLARE: EVAL@COMPILE 

(DATATYPE NOTEFILEINFO (NOTEFILEATTRIBUTES NOTEFILEDATA EXTRAFILEBOXDATA))

(DATATYPE NOTEFILEATTRIBUTES (FULLNAME AUTHOR CREATIONDATE WRITEDATE READDATE (SIZE INTEGER)))

(DATATYPE NOTEFILEDATA (ALLCARDSDATA CARDTYPESHASHARRAY FILEBOXDATA LINKTYPESHASHARRAY
				       (NUMLINKS INTEGER)))

(DATATYPE ALLCARDSDATA (ALLCARDSSIZEHIST1 ALLCARDSSIZEHIST2 ALLCARDSHIST ALLCARDSSTATS))

(DATATYPE CARDTYPEDATA (CARDTYPESIZEHIST1 CARDTYPESIZEHIST2 CARDTYPEHIST CARDTYPESTATS))

(DATATYPE FILEBOXDATA (FILEBOXHIST FILEDCARDSTATS SUBBOXSTATS TOCDEPTHHIST TOCDEPTHSTATS 
				     TBFDEPTHHIST TBFDEPTHSTATS ORPHDEPTHHIST ORPHDEPTHSTATS))

(DATATYPE CARDHISTENTRY ((HISTENTRYPARENTS INTEGER)
			   (HISTENTRYTOLINKS INTEGER)
			   (HISTENTRYFROMLINKS INTEGER)
			   (HISTENTRYGLOBALLINKS INTEGER)))

(DATATYPE FILEBOXHISTENTRY ((HISTENTRYFILEDCARDLINKS INTEGER)
			      (HISTENTRYSUBBOXLINKS INTEGER)))

(DATATYPE CARDSTATS ((TOTAL INTEGER)
		       PARENTSSTATS TOLINKSSTATS FROMLINKSSTATS GLOBALLINKSSTATS SIZESTATS))

(DATATYPE STATSFROMHIST ((TOTAL INTEGER)
			   (MIN FLOATING)
			   (MAX FLOATING)
			   (MEAN FLOATING)
			   (MEDIAN FLOATING)
			   (MODE FLOATING)))

(DATATYPE EXTRAFILEBOXDATA (FBW/OSUBBOXESDATA FBW/OFILEDCARDSDATA FBW/OCHILDRENDATA OTHERFBDATA))

(DATATYPE SPECIALFBDATA (SPECIALFBSIZEHIST1 SPECIALFBSIZEHIST2 SPECIALFBHIST SPECIALFBSTATS 
					      SPECIALFBLINKSHIST SPECIALFBFILEDCARDSTATS 
					      SPECIALFBSUBBOXSTATS))
]
(/DECLAREDATATYPE (QUOTE NOTEFILEINFO)
		  (QUOTE (POINTER POINTER POINTER))
		  (QUOTE ((NOTEFILEINFO 0 POINTER)
			  (NOTEFILEINFO 2 POINTER)
			  (NOTEFILEINFO 4 POINTER)))
		  (QUOTE 6))
(/DECLAREDATATYPE (QUOTE NOTEFILEATTRIBUTES)
		  (QUOTE (POINTER POINTER POINTER POINTER POINTER FIXP))
		  (QUOTE ((NOTEFILEATTRIBUTES 0 POINTER)
			  (NOTEFILEATTRIBUTES 2 POINTER)
			  (NOTEFILEATTRIBUTES 4 POINTER)
			  (NOTEFILEATTRIBUTES 6 POINTER)
			  (NOTEFILEATTRIBUTES 8 POINTER)
			  (NOTEFILEATTRIBUTES 10 FIXP)))
		  (QUOTE 12))
(/DECLAREDATATYPE (QUOTE NOTEFILEDATA)
		  (QUOTE (POINTER POINTER POINTER POINTER FIXP))
		  (QUOTE ((NOTEFILEDATA 0 POINTER)
			  (NOTEFILEDATA 2 POINTER)
			  (NOTEFILEDATA 4 POINTER)
			  (NOTEFILEDATA 6 POINTER)
			  (NOTEFILEDATA 8 FIXP)))
		  (QUOTE 10))
(/DECLAREDATATYPE (QUOTE ALLCARDSDATA)
		  (QUOTE (POINTER POINTER POINTER POINTER))
		  (QUOTE ((ALLCARDSDATA 0 POINTER)
			  (ALLCARDSDATA 2 POINTER)
			  (ALLCARDSDATA 4 POINTER)
			  (ALLCARDSDATA 6 POINTER)))
		  (QUOTE 8))
(/DECLAREDATATYPE (QUOTE CARDTYPEDATA)
		  (QUOTE (POINTER POINTER POINTER POINTER))
		  (QUOTE ((CARDTYPEDATA 0 POINTER)
			  (CARDTYPEDATA 2 POINTER)
			  (CARDTYPEDATA 4 POINTER)
			  (CARDTYPEDATA 6 POINTER)))
		  (QUOTE 8))
(/DECLAREDATATYPE (QUOTE FILEBOXDATA)
		  (QUOTE (POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER))
		  (QUOTE ((FILEBOXDATA 0 POINTER)
			  (FILEBOXDATA 2 POINTER)
			  (FILEBOXDATA 4 POINTER)
			  (FILEBOXDATA 6 POINTER)
			  (FILEBOXDATA 8 POINTER)
			  (FILEBOXDATA 10 POINTER)
			  (FILEBOXDATA 12 POINTER)
			  (FILEBOXDATA 14 POINTER)
			  (FILEBOXDATA 16 POINTER)))
		  (QUOTE 18))
(/DECLAREDATATYPE (QUOTE CARDHISTENTRY)
		  (QUOTE (FIXP FIXP FIXP FIXP))
		  (QUOTE ((CARDHISTENTRY 0 FIXP)
			  (CARDHISTENTRY 2 FIXP)
			  (CARDHISTENTRY 4 FIXP)
			  (CARDHISTENTRY 6 FIXP)))
		  (QUOTE 8))
(/DECLAREDATATYPE (QUOTE FILEBOXHISTENTRY)
		  (QUOTE (FIXP FIXP))
		  (QUOTE ((FILEBOXHISTENTRY 0 FIXP)
			  (FILEBOXHISTENTRY 2 FIXP)))
		  (QUOTE 4))
(/DECLAREDATATYPE (QUOTE CARDSTATS)
		  (QUOTE (FIXP POINTER POINTER POINTER POINTER POINTER))
		  (QUOTE ((CARDSTATS 0 FIXP)
			  (CARDSTATS 2 POINTER)
			  (CARDSTATS 4 POINTER)
			  (CARDSTATS 6 POINTER)
			  (CARDSTATS 8 POINTER)
			  (CARDSTATS 10 POINTER)))
		  (QUOTE 12))
(/DECLAREDATATYPE (QUOTE STATSFROMHIST)
		  (QUOTE (FIXP FLOATP FLOATP FLOATP FLOATP FLOATP))
		  (QUOTE ((STATSFROMHIST 0 FIXP)
			  (STATSFROMHIST 2 FLOATP)
			  (STATSFROMHIST 4 FLOATP)
			  (STATSFROMHIST 6 FLOATP)
			  (STATSFROMHIST 8 FLOATP)
			  (STATSFROMHIST 10 FLOATP)))
		  (QUOTE 12))
(/DECLAREDATATYPE (QUOTE EXTRAFILEBOXDATA)
		  (QUOTE (POINTER POINTER POINTER POINTER))
		  (QUOTE ((EXTRAFILEBOXDATA 0 POINTER)
			  (EXTRAFILEBOXDATA 2 POINTER)
			  (EXTRAFILEBOXDATA 4 POINTER)
			  (EXTRAFILEBOXDATA 6 POINTER)))
		  (QUOTE 8))
(/DECLAREDATATYPE (QUOTE SPECIALFBDATA)
		  (QUOTE (POINTER POINTER POINTER POINTER POINTER POINTER POINTER))
		  (QUOTE ((SPECIALFBDATA 0 POINTER)
			  (SPECIALFBDATA 2 POINTER)
			  (SPECIALFBDATA 4 POINTER)
			  (SPECIALFBDATA 6 POINTER)
			  (SPECIALFBDATA 8 POINTER)
			  (SPECIALFBDATA 10 POINTER)
			  (SPECIALFBDATA 12 POINTER)))
		  (QUOTE 14))
(* * Top level functions.)

(DEFINEQ

(NFSTAT.AnalyzeRemoteNoteFile
  (LAMBDA (NoteFileName LocalHostAndDirectory OutputFile Don'tDeleteLocalCopyFlg QuietFlg)
                                                             (* rht: "18-Aug-86 16:57")

          (* * First get attributes from remote file. Then copy to local disk, open notefile, gather data, close, and write 
	  out data to OutputFile. Delete local copy of notefile unless Don'tDeleteLocalCopyFlg non-nil.)


    (if (OPENP NoteFileName)
	then (NCP.PrintMsg NIL T "Must close notefile before analyzing: " NoteFileName)
	       (FLASHW PROMPTWINDOW)
      else (LET ((FullFileName (FULLNAME NoteFileName))
		   LocalFileName NoteFileAttributes NoteFileData ResultOfOper NoteFile)

          (* * Fill in fresh NOTEFILEATTRIBUTES record.)


	          (SETQ NoteFileAttributes (create NOTEFILEATTRIBUTES
						       FULLNAME ← FullFileName
						       AUTHOR ←(GETFILEINFO FullFileName
									      (QUOTE AUTHOR))
						       CREATIONDATE ←(GETFILEINFO FullFileName
										    (QUOTE 
										     CREATIONDATE))
						       WRITEDATE ←(GETFILEINFO FullFileName
										 (QUOTE WRITEDATE))
						       READDATE ←(GETFILEINFO FullFileName
										(QUOTE READDATE))
						       SIZE ←(GETFILEINFO FullFileName
									    (QUOTE SIZE))))

          (* * Copy notefile to local disk.)


	          (SETQ LocalFileName (PACKFILENAME (QUOTE NAME)
							(FILENAMEFIELD FullFileName (QUOTE NAME))
							(QUOTE EXTENSION)
							(QUOTE NOTEFILE)
							(QUOTE BODY)
							LocalHostAndDirectory))
	          (OR QuietFlg (NCP.PrintMsg NIL T "Copying " FullFileName " to " LocalFileName 
						 " ..."))
	          (if (NULL (ERSETQ (COPYFILE FullFileName LocalFileName)))
		      then (ERROR "Trouble copying from " (CONCAT FullFileName " to " 
									LocalFileName)))

          (* * Open, process, and close.)


	          (SETQ ResultOfOper (ERSETQ (SETQ NoteFile
						   (NCP.OpenNoteFile LocalFileName T T QuietFlg NIL 
								       T T))))
	          (if (OR (NULL ResultOfOper)
			      (NULL (CAR ResultOfOper)))
		      then (ERROR "Trouble opening " LocalFileName))
	          (if (NULL (ERSETQ (SETQ NoteFileData (NFSTAT.GatherNoteFileData NoteFile 
											 QuietFlg))))
		      then (ERROR "Trouble gathering data for " LocalFileName))
	          (if (NULL (ERSETQ (NCP.CloseNoteFiles NoteFile QuietFlg)))
		      then (ERROR "Trouble closing " LocalFileName))

          (* * Write results out to OutputFile.)


	          (if (NULL (ERSETQ (OPENFILE OutputFile (QUOTE OUTPUT))))
		      then (ERROR "Trouble opening " OutputFile))
	          (OR QuietFlg (NCP.PrintMsg NIL T "Writing out results to " OutputFile " ..."))
	          (HPRINT (CONS NoteFileAttributes NoteFileData)
			    OutputFile T)
	          (CLOSEF OutputFile)

          (* * Delete local notefile if desired.)


	          (OR Don'tDeleteLocalCopyFlg (DELFILE LocalFileName))
	          (OR QuietFlg (NCP.PrintMsg NIL T "Done."))
	      OutputFile))))

(NFSTAT.GatherNoteFileData
  (LAMBDA (NoteFile QuietFlg)                                (* rht: "15-Aug-86 15:57")

          (* * Accumulate data on this notefile into a fresh NOTEFILEDATA record.)


    (LET ((FileName (fetch (NoteFile FullFileName) of NoteFile))
	  (NoteFileDataRecord (NFSTAT.MakeFreshNoteFileDataRecord))
	  (ExtraFileBoxData (NFSTAT.MakeFreshExtraFileBoxDataRecord)))

          (* * Fill in the ALLCARDSHIST, FILEBOXHIST, CARDTYPESHASHARRAY, LINKTYPESHASHARRAY fields.)


         (NFSTAT.ProcessCards NoteFileDataRecord ExtraFileBoxData NoteFile QuietFlg)

          (* * Fill in the TOCDEPTHHIST, TBFDEPTHHIST, ORPHDEPTHHIST fields.)


         (NFSTAT.ProcessFileBoxHierarchies (fetch (NOTEFILEDATA FILEBOXDATA) of 
									       NoteFileDataRecord)
					     NoteFile QuietFlg)
         (OR QuietFlg (NCP.PrintMsg NIL T "Done."))
         (LIST NoteFileDataRecord ExtraFileBoxData))))
)
(* * Helper functions.)

(DEFINEQ

(NFSTAT.MakeFreshNoteFileDataRecord
  (LAMBDA NIL                                                (* rht: "24-Jul-86 18:42")

          (* * Initialize and return a fresh data record.)


    (create NOTEFILEDATA
	      ALLCARDSDATA ←(create ALLCARDSDATA
				      ALLCARDSSIZEHIST1 ←(ARRAY NFSTAT.HistSize (QUOTE FIXP)
								  0 0)
				      ALLCARDSSIZEHIST2 ←(ARRAY NFSTAT.HistSize (QUOTE FIXP)
								  0 0)
				      ALLCARDSHIST ←(ARRAY NFSTAT.HistSize NIL NIL 0)
				      ALLCARDSSTATS ←(create CARDSTATS
							       TOTAL ← 0))
	      CARDTYPESHASHARRAY ←(HASHARRAY NFSTAT.HashArraySize)
	      LINKTYPESHASHARRAY ←(HASHARRAY NFSTAT.HashArraySize)
	      FILEBOXDATA ←(create FILEBOXDATA
				     FILEBOXHIST ←(ARRAY NFSTAT.HistSize NIL NIL 0)
				     TOCDEPTHHIST ←(ARRAY NFSTAT.HistSize (QUOTE FIXP)
							    0 0)
				     TBFDEPTHHIST ←(ARRAY NFSTAT.HistSize (QUOTE FIXP)
							    0 0)
				     ORPHDEPTHHIST ←(ARRAY NFSTAT.HistSize (QUOTE FIXP)
							     0 0))
	      NUMLINKS ← 0)))

(NFSTAT.ProcessCards
  (LAMBDA (NoteFileDataRecord ExtraFileBoxData NoteFile QuietFlg)
                                                             (* rht: "18-Aug-86 13:45")

          (* * Run through all the cards in the currently open notefile, computing vital data for each and storing in the 
	  proper histograms in NoteFileDataRecord.)


    (LET ((CardNum 0)
	  (CardTotal (SUB1 (fetch (NoteFile NextIndexNum) of NoteFile)))
	  (RealCardTotal 0)
	  (TotalFileBoxesw/oSubBoxes 0)
	  (TotalFileBoxesw/oFiledCards 0))
         (OR QuietFlg (NCP.PrintMsg NIL T "Processing card number " 1 " out of " CardTotal))
         (with
	   NOTEFILEDATA NoteFileDataRecord
	   (with
	     ALLCARDSDATA ALLCARDSDATA
	     (with
	       FILEBOXDATA FILEBOXDATA
	       (NCP.MapCards
		 NoteFile
		 (FUNCTION (LAMBDA (Card)
		     (BLOCK)
		     (SETQ CardNum (ADD1 CardNum))
		     (AND (NULL QuietFlg)
			    (ZEROP (REMAINDER CardNum 100))
			    (NCP.PrintMsg NIL T "Processing card number " CardNum " out of " 
					    CardTotal))
		     (LET ((CardType (NCP.CardType Card))
			   (ToLinks (NCP.GetLinks Card))
			   (FromLinks (NCP.GetLinks NIL Card))
			   SubstanceSize NumParents NumToLinks NumFromLinks NumGlobalLinks)
		          (with CARDTYPEDATA (NFSTAT.FetchCardTypeData CardType 
									   CARDTYPESHASHARRAY)
				  (with CARDSTATS CARDTYPESTATS 

          (* * Keep track of total # of cards and by card type.)


					  (add RealCardTotal 1)
					  (add TOTAL 1)

          (* * Keep running total of substance size and by card type.)


					  (NFSTAT.AddCardSizeDataToHist ALLCARDSSIZEHIST1 
									  ALLCARDSSIZEHIST2
									  (SETQ SubstanceSize
									    (
								      NFSTAT.ComputeSubstanceSize
									      Card)))
					  (NFSTAT.AddCardSizeDataToHist CARDTYPESIZEHIST1 
									  CARDTYPESIZEHIST2 
									  SubstanceSize)
                                                             (* Special handling for filebox subtypes.)

          (* * Keep track of vital links info in allcards histograms and by card type.)


					  (SETQ NumParents (for Link in FromLinks
								count (FMEMB (NCP.LinkType
										   Link)
										 (QUOTE
										   (SubBox FiledCard))
										 )))
					  (SETQ NumToLinks (LENGTH ToLinks))
					  (SETQ NumFromLinks (LENGTH FromLinks))
					  (SETQ NumGlobalLinks (for Link in ToLinks
								    count
								     (EQ (fetch (Link AnchorMode)
									      of Link)
									   (QUOTE GLOBAL))))
					  (NFSTAT.AddCardDataToHist ALLCARDSHIST NumParents 
								      NumToLinks NumFromLinks 
								      NumGlobalLinks)
					  (NFSTAT.AddCardDataToHist CARDTYPEHIST NumParents 
								      NumToLinks NumFromLinks 
								      NumGlobalLinks)

          (* * Keep track specially of filebox linking info.)


					  (if (EQ CardType (QUOTE FileBox))
					      then (LET ((NumFiledCardLinks
							     (for Link in ToLinks
								count (EQ (NCP.LinkType Link)
									      (QUOTE FiledCard))))
							   (NumSubBoxLinks
							     (for Link in ToLinks
								count (EQ (NCP.LinkType Link)
									      (QUOTE SubBox)))))
						          (NFSTAT.AddFileBoxDataToHist FILEBOXHIST 
										NumFiledCardLinks 
										   NumSubBoxLinks)
						          (NFSTAT.InstallExtraFileBoxData 
										 ExtraFileBoxData 
										NumFiledCardLinks 
										   NumSubBoxLinks 
										    SubstanceSize 
										       NumParents 
										       NumToLinks 
										     NumFromLinks 
										   NumGlobalLinks)))

          (* * Keep track of total number of links of each type.)


					  (for Link in ToLinks
					     do (NFSTAT.IncrementHashItem (NCP.LinkType Link)
									      LINKTYPESHASHARRAY)
						  (add NUMLINKS 1))))))))
	       (replace (CARDSTATS TOTAL) of ALLCARDSSTATS with RealCardTotal)

          (* * analyze the histograms to obtain vital stats.)


	       (NFSTAT.ComputeNoteFileStats NoteFileDataRecord QuietFlg T)
	       (NFSTAT.ComputeExtraFileBoxStats ExtraFileBoxData QuietFlg)))))))

(NFSTAT.ProcessFileBoxHierarchies
  (LAMBDA (FileBoxDataRecord NoteFile QuietFlg)              (* rht: "27-Jul-86 00:11")

          (* * Run down each of the three main filebox hierarchies to make and analyze a histogram of depths.)


    (with FILEBOXDATA FileBoxDataRecord (OR QuietFlg (NCP.PrintMsg NIL T 
					"Traversing filebox hierarchy under Contents FileBox ..."))
	    (SETQ TOCDEPTHSTATS (NFSTAT.AnalyzeHist TOCDEPTHHIST 1 (
							NFSTAT.TraverseFileBoxHierarchy
							(fetch (NoteFile TableOfContentsCard)
							   of NoteFile)
							TOCDEPTHHIST 0)
						      NIL NIL))
	    (OR QuietFlg (NCP.PrintMsg NIL T 
				       "Traversing filebox hierarchy under ToBeFiled FileBox ..."))
	    (SETQ TBFDEPTHSTATS (NFSTAT.AnalyzeHist TBFDEPTHHIST 1 (
							NFSTAT.TraverseFileBoxHierarchy
							(fetch (NoteFile ToBeFiledCard)
							   of NoteFile)
							TBFDEPTHHIST 0)
						      NIL NIL))
	    (OR QuietFlg (NCP.PrintMsg NIL T 
					 "Traversing filebox hierarchy under Orphans FileBox ..."))
	    (SETQ ORPHDEPTHSTATS (NFSTAT.AnalyzeHist ORPHDEPTHHIST 1 (
							 NFSTAT.TraverseFileBoxHierarchy
							 (fetch (NoteFile OrphansCard)
							    of NoteFile)
							 ORPHDEPTHHIST 0)
						       NIL NIL)))))

(NFSTAT.ComputeNoteFileStats
  (LAMBDA (NoteFileDataRecord QuietFlg Don'tComputeDepthStatsFlg)
                                                             (* rht: "15-Aug-86 15:58")

          (* * Fill in all the various stats fields for the given record. Note that we expect the TOTAL fields of each Stats 
	  record to be already filled in.)


    (with NOTEFILEDATA NoteFileDataRecord
	    (with ALLCARDSDATA ALLCARDSDATA
		    (with FILEBOXDATA FILEBOXDATA 

          (* * analyze the histograms to obtain vital stats.)


			    (LET ((TotalFileBoxes (fetch (CARDSTATS TOTAL)
						     of (fetch (CARDTYPEDATA CARDTYPESTATS)
							     of (GETHASH (QUOTE FileBox)
									     CARDTYPESHASHARRAY)))))
			         (OR QuietFlg (NCP.PrintMsg NIL T 
				      "Computing statistics from card and filebox histograms ..."))
			         (NFSTAT.FillInCardStats ALLCARDSHIST ALLCARDSSTATS)
			         (replace (CARDSTATS SIZESTATS) of ALLCARDSSTATS
				    with (NFSTAT.AnalyzeHist (LIST ALLCARDSSIZEHIST1 
								       ALLCARDSSIZEHIST2)
							       (QUOTE (100 1000))
							       (fetch (CARDSTATS TOTAL)
								  of ALLCARDSSTATS)
							       NIL NIL))
			         (MAPHASH CARDTYPESHASHARRAY
					    (FUNCTION (LAMBDA (Item Key)
						(BLOCK)
						(with CARDTYPEDATA Item (NFSTAT.FillInCardStats
							  CARDTYPEHIST CARDTYPESTATS)
							(replace (CARDSTATS SIZESTATS)
							   of CARDTYPESTATS
							   with (NFSTAT.AnalyzeHist
								    (LIST CARDTYPESIZEHIST1 
									    CARDTYPESIZEHIST2)
								    (QUOTE (100 1000))
								    (fetch (CARDSTATS TOTAL)
								       of CARDTYPESTATS)
								    NIL NIL))))))

          (* * Analyze the FileBox histogram for stats on SubBox and FiledCard links.)


			         (SETQ FILEDCARDSTATS (NFSTAT.AnalyzeHist FILEBOXHIST 1 
									    TotalFileBoxes 
									    FILEBOXHISTENTRY 
									  HISTENTRYFILEDCARDLINKS))
			         (SETQ SUBBOXSTATS (NFSTAT.AnalyzeHist FILEBOXHIST 1 TotalFileBoxes 
									 FILEBOXHISTENTRY 
									 HISTENTRYSUBBOXLINKS))

          (* * Compute the stats for filebox depths if desired.)


			         (if (NULL Don'tComputeDepthStatsFlg)
				     then (SETQ TOCDEPTHSTATS (NFSTAT.ComputeStatsFromDepthHist
						TOCDEPTHHIST))
					    (SETQ TBFDEPTHSTATS (NFSTAT.ComputeStatsFromDepthHist
						TBFDEPTHHIST))
					    (SETQ ORPHDEPTHSTATS (NFSTAT.ComputeStatsFromDepthHist
						ORPHDEPTHHIST)))))))))
)
(DEFINEQ

(NFSTAT.AddCardDataToHist
  (LAMBDA (Hist NumParents NumToLinks NumFromLinks NumGlobalLinks)
                                                             (* rht: "15-Jun-86 20:40")

          (* * Insert the data for this card into given histogram)


    (NFSTAT.AddFieldEntryToHist CARDHISTENTRY Hist HISTENTRYPARENTS NumParents)
    (NFSTAT.AddFieldEntryToHist CARDHISTENTRY Hist HISTENTRYTOLINKS NumToLinks)
    (NFSTAT.AddFieldEntryToHist CARDHISTENTRY Hist HISTENTRYFROMLINKS NumFromLinks)
    (NFSTAT.AddFieldEntryToHist CARDHISTENTRY Hist HISTENTRYGLOBALLINKS NumGlobalLinks)))

(NFSTAT.AddFileBoxDataToHist
  (LAMBDA (FileBoxHist FiledCardLinks SubBoxLinks)           (* rht: "15-Jun-86 18:05")

          (* * Insert the data for this FileBox into the FileBox histogram.)


    (NFSTAT.AddFieldEntryToHist FILEBOXHISTENTRY FileBoxHist HISTENTRYFILEDCARDLINKS FiledCardLinks)
    (NFSTAT.AddFieldEntryToHist FILEBOXHISTENTRY FileBoxHist HISTENTRYSUBBOXLINKS SubBoxLinks)))

(NFSTAT.AddCardSizeDataToHist
  (LAMBDA (Hist1 Hist2 Size)                                 (* rht: "22-Jun-86 20:59")

          (* * Insert the size of this card into given histograms. The two 100 box histograms have different box widths.
	  The first runs from 0 to 9999 by 100's while the second runs from 10000 to 999999 by 1000's.)


    (OR (LESSP Size 109999)
	  (SETQ Size 109999))
    (LET (BoxNum)
         (if (LESSP Size 10000)
	     then (SETQ BoxNum (QUOTIENT Size 100))
		    (SETA Hist1 BoxNum (ADD1 (ELT Hist1 BoxNum)))
	   else (SETQ BoxNum (QUOTIENT (DIFFERENCE Size 10000)
					     1000))
		  (SETA Hist2 BoxNum (ADD1 (ELT Hist2 BoxNum)))))))

(NFSTAT.MakeFreshHistRecord
  (LAMBDA (HistRecordType)                                   (* rht: "15-Jun-86 20:49")

          (* * Make a zero-filled instance of HistRecordType.)


    (if (EQ HistRecordType (QUOTE CARDHISTENTRY))
	then (create CARDHISTENTRY
			 HISTENTRYPARENTS ← 0
			 HISTENTRYTOLINKS ← 0
			 HISTENTRYFROMLINKS ← 0
			 HISTENTRYGLOBALLINKS ← 0)
      elseif (EQ HistRecordType (QUOTE FILEBOXHISTENTRY))
	then (create FILEBOXHISTENTRY
			 HISTENTRYFILEDCARDLINKS ← 0
			 HISTENTRYSUBBOXLINKS ← 0))))

(NFSTAT.TraverseFileBoxHierarchy
  (LAMBDA (RootCard Hist CurrentDepth)                       (* rht: "15-Jun-86 21:03")

          (* * Walk down the filebox hierarchy till a non-filebox or empty filebox is found. Register its depth in Hist.
	  Return total number of terminals.)


    (LET (Children)
         (BLOCK)
         (if (AND (NCP.FileBoxP RootCard)
		      (SETQ Children (NCP.FileBoxChildren RootCard)))
	     then (for Child in Children sum (NFSTAT.TraverseFileBoxHierarchy Child Hist
											(ADD1
											  
										     CurrentDepth)))
	   else (SETA Hist CurrentDepth (ADD1 (ELT Hist CurrentDepth)))
		  1))))

(NFSTAT.ComputeSubstanceSize
  (LAMBDA (Card)                                             (* rht: "27-Jul-86 00:25")

          (* * Compute the size of this card's substance.)


    (LET* ((NoteFile (fetch (Card NoteFile) of Card))
	   (Stream (fetch (NoteFile Stream) of NoteFile)))
          (WITH.MONITOR (NC.FetchMonitor NoteFile)
			(LET ((EndPtr (GETEOFPTR Stream))
			      IdentifierAndVersionNum)
			     (SETFILEPTR Stream (fetch (Card MainLoc) of Card))
			     (AND (NC.ReadPtr Stream 3)
				    (SETQ IdentifierAndVersionNum (NC.RobustReadItemIdentifier
					Stream))
				    (if (GEQ (CDR IdentifierAndVersionNum)
						 1)
					then (NC.RobustReadDate Stream)
				      else T)
				    (EQ (CAR IdentifierAndVersionNum)
					  NC.ItemIdentifier)
				    (NC.SameUIDP (fetch (Card UID) of Card)
						   (NC.RobustReadUID Stream))
				    (CAR (NC.RobustReadAtom Stream))
				    (NC.RobustReadRegion Stream EndPtr)
				    (NC.CheckForValidSubstance Stream EndPtr Card)))))))

(NFSTAT.IncrementHashItem
  (LAMBDA (Item HashArray)                                   (* rht: "13-Jun-86 15:19")

          (* * Increment the value of Item in HashArray)


    (PUTHASH Item (ADD1 (OR (NUMBERP (GETHASH Item HashArray))
				  0))
	       HashArray)))

(NFSTAT.FetchCardTypeData
  (LAMBDA (CardType CardTypesHashArray)                      (* rht: "19-Jun-86 11:11")

          (* * Returns the data record for given card type.)


    (OR (GETHASH CardType CardTypesHashArray)
	  (PUTHASH CardType (create CARDTYPEDATA
					CARDTYPESIZEHIST1 ←(ARRAY NFSTAT.HistSize (QUOTE FIXP)
								    0 0)
					CARDTYPESIZEHIST2 ←(ARRAY NFSTAT.HistSize (QUOTE FIXP)
								    0 0)
					CARDTYPEHIST ←(ARRAY NFSTAT.HistSize NIL NIL 0)
					CARDTYPESTATS ←(create CARDSTATS
								 TOTAL ← 0))
		     CardTypesHashArray))))

(NFSTAT.FillInCardStats
  (LAMBDA (Hist CardStats)                                   (* rht: "19-Jun-86 01:03")

          (* * Fill in the various CardStats by analyzing Hist.)


    (with CARDSTATS CardStats (SETQ PARENTSSTATS (NFSTAT.AnalyzeHist Hist 1 TOTAL CARDHISTENTRY 
									 HISTENTRYPARENTS))
	    (SETQ TOLINKSSTATS (NFSTAT.AnalyzeHist Hist 1 TOTAL CARDHISTENTRY HISTENTRYTOLINKS))
	    (SETQ FROMLINKSSTATS (NFSTAT.AnalyzeHist Hist 1 TOTAL CARDHISTENTRY HISTENTRYFROMLINKS))
	    (SETQ GLOBALLINKSSTATS (NFSTAT.AnalyzeHist Hist 1 TOTAL CARDHISTENTRY 
							 HISTENTRYGLOBALLINKS)))))
)
(DECLARE: EVAL@COMPILE 
(DEFMACRO NFSTAT.AddFieldEntryToHist (HistType Hist FieldName Num)
	  (* * First make sure that Hist has a non-nil Num entry. Then increment FieldName field of 
	     the record in that entry. This is a macro so as to avoid call to RECORDACCESS.)
	  (BQUOTE (LET* ((Index (if (GEQ , Num NFSTAT.HistSize)
				    then
				    (SUB1 NFSTAT.HistSize)
				    else , Num))
			 (Val (ELT , Hist Index)))
			(if (NULL Val)
			    then
			    (SETQ Val (SETA , Hist Index (NFSTAT.MakeFreshHistRecord (QUOTE , 
											 HistType)))))
			(replace (, HistType , FieldName)
				 of Val with (ADD1 (fetch (, HistType , FieldName)
							  of Val))))))
(DEFMACRO
  NFSTAT.AnalyzeHist
  (Hists BoxWidths Total RecordType Field)
  (* * Compute statistics on the data in Hist into a STATSFROMHIST record. If Field is non-nil, then 
     hist entries are records of type RecordType and we're interested in Field of that record. 
     Otherwise, hist entries are numbers. This is a macro to avoid doing RECORDACCESS.)
  (* * Hists can be a list of histograms which should be the same length as IntervalWidths. The 
     latter gives the width of a histogram entry or box, one for each histogram.)
  (BQUOTE
    (LET ((StatsFromHist (create STATSFROMHIST TOTAL ← , Total MIN ← 99999.0 MAX ← 0.0 MEAN ← 0.0 
				 MEDIAN ← -1.0 MODE ← 0)))
	 (with STATSFROMHIST StatsFromHist
	       (for Hist in (MKLIST , Hists)
		    as BoxWidth in (MKLIST , BoxWidths)
		    bind TotalDivBy2 ← (FQUOTIENT TOTAL 2)
		    NumSeen ← 0 LastNonEmptyEndBox ← -.5 StartBox ← -.5 ModeVal ← 0 HalfBox do
		    (SETQ HalfBox (FQUOTIENT BoxWidth 2))
		    (for i from 0 to (SUB1 NFSTAT.HistSize)
			 eachtime
			 (BLOCK)
			 bind MidBox EndBox do
			 (LET* ((Entry (ELT Hist i))
				(Val , (if (OR (NULL RecordType)
					       (NULL Field))
					   then
					   (BQUOTE (OR Entry 0))
					   else
					   (BQUOTE (OR (AND (type? , RecordType Entry)
							    (fetch (, RecordType , Field)
								   of Entry))
						       0)))))
			       (SETQ EndBox (PLUS StartBox BoxWidth))
			       (SETQ MidBox (PLUS StartBox HalfBox))
			       (* Update MAX and MIN.)
			       (if (GREATERP Val 0)
				   then
				   (if (LESSP MidBox MIN)
				       then
				       (SETQ MIN MidBox))
				   (if (GREATERP MidBox MAX)
				       then
				       (SETQ MAX MidBox)))
			       (* Keep running total in MEAN.)
			       (add MEAN (TIMES Val MidBox))
			       (* Update MODE.)
			       (if (GREATERP Val ModeVal)
				   then
				   (SETQ ModeVal Val)
				   (SETQ MODE MidBox))
			       (* Compute MEDIAN if not already done.)
			       (if (AND (LESSP MEDIAN -.5)
					(GREATERP Val 0))
				   then
				   (if (EQUAL NumSeen TotalDivBy2)
				       then
				       (SETQ MEDIAN (FQUOTIENT (PLUS LastNonEmptyEndBox StartBox)
							       2))
				       elseif
				       (LESSP TotalDivBy2 (add NumSeen Val))
				       then
				       (SETQ MEDIAN (FPLUS StartBox (FQUOTIENT (TIMES (DIFFERENCE
											NumSeen 
										      TotalDivBy2)
										      BoxWidth)
									       Val)))
				       else
				       (SETQ LastNonEmptyEndBox EndBox)))
			       (* Set up StartBox for next iteration.)
			       (add StartBox BoxWidth))))
	       (* Divide total in MEAN by num cards.)
	       (SETQ MEAN (FQUOTIENT MEAN TOTAL))
	       StatsFromHist))))
)
(* * Stuff for dealing with extra file box data.)

(DEFINEQ

(NFSTAT.MakeFreshExtraFileBoxDataRecord
  (LAMBDA NIL                                                (* rht: "15-Aug-86 15:48")

          (* * Initialize and return a fresh data record.)


    (create EXTRAFILEBOXDATA
	      FBW/OCHILDRENDATA ←(NFSTAT.MakeFreshSpecialFBDataRecord)
	      FBW/OSUBBOXESDATA ←(NFSTAT.MakeFreshSpecialFBDataRecord)
	      FBW/OFILEDCARDSDATA ←(NFSTAT.MakeFreshSpecialFBDataRecord)
	      OTHERFBDATA ←(NFSTAT.MakeFreshSpecialFBDataRecord))))

(NFSTAT.MakeFreshSpecialFBDataRecord
  (LAMBDA NIL                                                (* rht: "15-Aug-86 15:00")

          (* * Initialize and return a fresh data record.)


    (create SPECIALFBDATA
	      SPECIALFBSIZEHIST1 ←(ARRAY NFSTAT.HistSize (QUOTE FIXP)
					   0 0)
	      SPECIALFBSIZEHIST2 ←(ARRAY NFSTAT.HistSize (QUOTE FIXP)
					   0 0)
	      SPECIALFBHIST ←(ARRAY NFSTAT.HistSize NIL NIL 0)
	      SPECIALFBSTATS ←(create CARDSTATS
					TOTAL ← 0)
	      SPECIALFBLINKSHIST ←(ARRAY NFSTAT.HistSize NIL NIL 0))))

(NFSTAT.InstallExtraFileBoxData
  (LAMBDA (ExtraFileBoxData NumFiledCardLinks NumSubBoxLinks SubstanceSize NumParents NumToLinks 
			    NumFromLinks NumGlobalLinks)     (* rht: "15-Aug-86 15:47")

          (* * Check which of the special filebox types, this card is and fill in the appropriate fields of ExtraFileBoxData)


    (with EXTRAFILEBOXDATA ExtraFileBoxData
	    (COND
	      ((AND (ZEROP NumFiledCardLinks)
		      (ZEROP NumSubBoxLinks))
		(NFSTAT.InstallSpecialFBData FBW/OCHILDRENDATA NumFiledCardLinks NumSubBoxLinks 
					       SubstanceSize NumParents NumToLinks NumFromLinks 
					       NumGlobalLinks))
	      ((ZEROP NumFiledCardLinks)
		(NFSTAT.InstallSpecialFBData FBW/OFILEDCARDSDATA NumFiledCardLinks NumSubBoxLinks 
					       SubstanceSize NumParents NumToLinks NumFromLinks 
					       NumGlobalLinks))
	      ((ZEROP NumSubBoxLinks)
		(NFSTAT.InstallSpecialFBData FBW/OSUBBOXESDATA NumFiledCardLinks NumSubBoxLinks 
					       SubstanceSize NumParents NumToLinks NumFromLinks 
					       NumGlobalLinks))
	      (T (NFSTAT.InstallSpecialFBData OTHERFBDATA NumFiledCardLinks NumSubBoxLinks 
						SubstanceSize NumParents NumToLinks NumFromLinks 
						NumGlobalLinks))))))

(NFSTAT.InstallSpecialFBData
  (LAMBDA (SpecialFBData NumFiledCardLinks NumSubBoxLinks SubstanceSize NumParents NumToLinks 
			 NumFromLinks NumGlobalLinks)        (* rht: "15-Aug-86 15:54")

          (* * Fill in appropriate fields of SPECIALFBDATA record.)


    (with SPECIALFBDATA SpecialFBData (add (fetch (CARDSTATS TOTAL) of SPECIALFBSTATS)
					       1)
	    (NFSTAT.AddCardSizeDataToHist SPECIALFBSIZEHIST1 SPECIALFBSIZEHIST2 SubstanceSize)
	    (NFSTAT.AddCardDataToHist SPECIALFBHIST NumParents NumToLinks NumFromLinks 
					NumGlobalLinks)
	    (NFSTAT.AddFileBoxDataToHist SPECIALFBLINKSHIST NumFiledCardLinks NumSubBoxLinks))))

(NFSTAT.ComputeExtraFileBoxStats
  (LAMBDA (ExtraFileBoxData QuietFlg)                        (* rht: "15-Aug-86 16:06")

          (* * Compute stats for the extra filebox data.)


    (with EXTRAFILEBOXDATA ExtraFileBoxData (NFSTAT.ComputeSpecialFBStats FBW/OSUBBOXESDATA 
									      QuietFlg)
	    (NFSTAT.ComputeSpecialFBStats FBW/OFILEDCARDSDATA QuietFlg)
	    (NFSTAT.ComputeSpecialFBStats FBW/OCHILDRENDATA QuietFlg)
	    (NFSTAT.ComputeSpecialFBStats OTHERFBDATA QuietFlg))))

(NFSTAT.ComputeSpecialFBStats
  (LAMBDA (SpecialFBData QuietFlg)                           (* rht: "15-Aug-86 17:06")

          (* * Compute the stats for a SpecialFBData record.)


    (with SPECIALFBDATA SpecialFBData (OR QuietFlg (NCP.PrintMsg NIL T 
					    "Computing statistics from special filebox data ... "))
	    (NFSTAT.FillInCardStats SPECIALFBHIST SPECIALFBSTATS)
	    (replace (CARDSTATS SIZESTATS) of SPECIALFBSTATS with (NFSTAT.AnalyzeHist
									  (LIST SPECIALFBSIZEHIST1 
									       SPECIALFBSIZEHIST2)
									  (QUOTE (100 1000))
									  (fetch (CARDSTATS TOTAL)
									     of SPECIALFBSTATS)
									  NIL NIL))
	    (SETQ SPECIALFBFILEDCARDSTATS (NFSTAT.AnalyzeHist SPECIALFBLINKSHIST 1
								(fetch (CARDSTATS TOTAL)
								   of SPECIALFBSTATS)
								FILEBOXHISTENTRY 
								HISTENTRYFILEDCARDLINKS))
	    (SETQ SPECIALFBSUBBOXSTATS (NFSTAT.AnalyzeHist SPECIALFBLINKSHIST 1
							     (fetch (CARDSTATS TOTAL) of 
										   SPECIALFBSTATS)
							     FILEBOXHISTENTRY HISTENTRYSUBBOXLINKS))))
)

(NFSTAT.CombineExtraFileBoxData
  (LAMBDA (SummaryExtraFileBoxData NoteFileExtraFileBoxData)
                                                             (* rht: "18-Aug-86 17:26")

          (* * Add in the extra filebox data for the notefile into that of the summary.)


    (with EXTRAFILEBOXDATA SummaryExtraFileBoxData (NFSTAT.CombineSpecialFBData
	      FBW/OSUBBOXESDATA
	      (fetch (EXTRAFILEBOXDATA FBW/OSUBBOXESDATA) of NoteFileExtraFileBoxData))
	    (NFSTAT.CombineSpecialFBData FBW/OFILEDCARDSDATA (fetch (EXTRAFILEBOXDATA 
									      FBW/OFILEDCARDSDATA)
								  of NoteFileExtraFileBoxData))
	    (NFSTAT.CombineSpecialFBData FBW/OCHILDRENDATA (fetch (EXTRAFILEBOXDATA 
										FBW/OCHILDRENDATA)
								of NoteFileExtraFileBoxData))
	    (NFSTAT.CombineSpecialFBData OTHERFBDATA (fetch (EXTRAFILEBOXDATA OTHERFBDATA)
							  of NoteFileExtraFileBoxData)))))

(NFSTAT.CombineSpecialFBData
  (LAMBDA (SummarySpecialFBData NoteFileSpecialFBData)       (* rht: "19-Aug-86 18:27")

          (* * Add in the special FB data for the notefile into that of the summary.)

                                                             (* First, the size histograms.)
    (replace (SPECIALFBDATA SPECIALFBSIZEHIST1) of SummarySpecialFBData
       with (NFSTAT.CombineHists (fetch (SPECIALFBDATA SPECIALFBSIZEHIST1) of 
									     SummarySpecialFBData)
				     (fetch (SPECIALFBDATA SPECIALFBSIZEHIST1) of 
									    NoteFileSpecialFBData)))
    (replace (SPECIALFBDATA SPECIALFBSIZEHIST2) of SummarySpecialFBData
       with (NFSTAT.CombineHists (fetch (SPECIALFBDATA SPECIALFBSIZEHIST2) of 
									     SummarySpecialFBData)
				     (fetch (SPECIALFBDATA SPECIALFBSIZEHIST2) of 
									    NoteFileSpecialFBData)))
                                                             (* Now, the data on parents, tolinks, fromlinks, and 
							     global links.)
    (replace (SPECIALFBDATA SPECIALFBHIST) of SummarySpecialFBData
       with (NFSTAT.CombineHists (fetch (SPECIALFBDATA SPECIALFBHIST) of SummarySpecialFBData)
				     (fetch (SPECIALFBDATA SPECIALFBHIST) of 
									    NoteFileSpecialFBData)
				     (QUOTE CARDHISTENTRY)))
                                                             (* Now, the info on filedcard and subbox links.)
    (replace (SPECIALFBDATA SPECIALFBLINKSHIST) of SummarySpecialFBData
       with (NFSTAT.CombineHists (fetch (SPECIALFBDATA SPECIALFBLINKSHIST) of 
									     SummarySpecialFBData)
				     (fetch (SPECIALFBDATA SPECIALFBLINKSHIST) of 
									    NoteFileSpecialFBData)
				     (QUOTE FILEBOXHISTENTRY)))
                                                             (* Increment total.)
    (LET ((SpecialFBStats (fetch (SPECIALFBDATA SPECIALFBSTATS) of SummarySpecialFBData)))
         (add (fetch (CARDSTATS TOTAL) of SpecialFBStats)
		(fetch (CARDSTATS TOTAL) of (fetch (SPECIALFBDATA SPECIALFBSTATS) of 
									    NoteFileSpecialFBData)))))
)
)
(* * Miscellaneous accelerators.)

(DEFINEQ

(NFSTAT.AnalyzeSetsOfNoteFiles
  (LAMBDA NumArgs                                            (* rht: "22-Jun-86 21:43")

          (* * Analyze sets of notefiles, each set having the same prefix for their OutputFileName. Args should be a proplist
	  of pairs, the first of which is a list of file names and the second of which is an OutputFilename prefix.)


    (for ArgNum from 1 to NumArgs by 2 do (LET ((FileNames (ARG NumArgs ArgNum))
							  (Prefix (ARG NumArgs (ADD1 ArgNum))))
						         (NFSTAT.AnalyzeListOfNoteFiles FileNames 
											  Prefix)))))

(NFSTAT.AnalyzeListOfNoteFiles
  (LAMBDA (NoteFiles OutputNamePrefix)                       (* rht: "22-Jun-86 18:46")

          (* * Analyze a whole list of notefiles.)


    (for NoteFile in NoteFiles do (NFSTAT.AnalyzeRemoteNoteFile NoteFile (QUOTE {dsk1})
									(NFSTAT.MakeOutputFileName
									  NoteFile OutputNamePrefix)))
    ))

(NFSTAT.MakeOutputFileName
  (LAMBDA (NoteFileName Owner)                               (* rht: "22-Jun-86 17:11")

          (* * Create a file name for the output file.)


    (PACKFILENAME (QUOTE HOST)
		    (QUOTE {dsk2})
		    (QUOTE DIRECTORY)
		    NIL
		    (QUOTE EXTENSION)
		    (QUOTE data)
		    (QUOTE VERSION)
		    NIL
		    (QUOTE NAME)
		    (CONCAT Owner "-" (FILENAMEFIELD NoteFileName (QUOTE NAME))))))

(NFSTAT.InspectDataFile
  (LAMBDA (FileName)                                         (* rht: "18-Aug-86 14:40")

          (* * Open, read and inspect a data file.)


    (LET ((File (OPENFILE FileName (QUOTE INPUT))))
         (if File
	     then (LET ((ThingRead (HREAD File)))
		         (INSPECT (PROG1 (create NOTEFILEINFO
						       NOTEFILEATTRIBUTES ←(CAR ThingRead)
						       NOTEFILEDATA ←(CADR ThingRead)
						       EXTRAFILEBOXDATA ←(CADDR ThingRead))
					     (CLOSEF File))))))))
)
(* * Functions for plotting.)

(FILESLOAD PLOTEXAMPLES)
(DEFINEQ

(NFSTAT.NoteFileInfoHistPlot
  (LAMBDA (NoteFileInfo)                                     (* rht: "19-Aug-86 15:39")

          (* * Let the user choose which histogram to plot, then plot it using HISTPLOT.)


    (with NOTEFILEINFO NoteFileInfo
	    (with NOTEFILEDATA NOTEFILEDATA
		    (LET* ((FullName (fetch (NOTEFILEATTRIBUTES FULLNAME) of NOTEFILEATTRIBUTES))
			   (FileNamePrefix (CONCAT (if (LISTP FullName)
							 then (QUOTE SUMMARY)
						       else (FILENAMEFIELD FullName (QUOTE
										 NAME)))
						     ": ")))
		          (SELECTQ (MENU (create MENU
						       ITEMS ←(QUOTE ((FileBoxData (QUOTE 
										      FileBoxData)
										     
							  "Plot link or depth data for fileboxes")
									 (CardData (QUOTE CardData)
										   
						  "Plot size, linking, or filing data for cards.")
									 (ExtraFileBoxData
									   (QUOTE ExtraFileBoxData)
									   
					       "Plot filing data for special kinds of fileboxes.")))))
				     (FileBoxData (NFSTAT.FileBoxDataHistPlot FILEBOXDATA 
										FileNamePrefix))
				     (CardData (NFSTAT.CardDataHistPlot ALLCARDSDATA 
									  CARDTYPESHASHARRAY 
									  FileNamePrefix))
				     (ExtraFileBoxData (NFSTAT.ExtraFileBoxDataHistPlot
							 EXTRAFILEBOXDATA
							 (GETHASH (QUOTE FileBox)
								    CARDTYPESHASHARRAY)
							 FILEBOXDATA FileNamePrefix))
				     NIL))))))

(NFSTAT.FileBoxDataHistPlot
  (LAMBDA (FileBoxData FileNamePrefix)                       (* rht: "19-Aug-86 14:39")

          (* * Plot hists for whatever part of the filebox data the user desires.)


    (with FILEBOXDATA FileBoxData (SELECTQ (MENU (create MENU
								 ITEMS ←(QUOTE
								   ((FiledCardLinksData (QUOTE
											  
									       FiledCardLinksData)
											
					    "Plot data on number of FiledCard links per filebox.")
								     (SubBoxLinksData (QUOTE 
										  SubBoxLinksData)
										      
					       "Plot data on number of SubBox links per filebox.")
								     (TableOfContentsDepthData
								       (QUOTE 
									 TableOfContentsDepthData)
								       
					"Plot data on depths of cards under TableOfContents box.")
								     (ToBeFiledDepthData
								       (QUOTE ToBeFiledDepthData)
								       
					      "Plot data on depths of cards under ToBeFiled box.")
								     (OrphansDepthData (QUOTE
											 
										 OrphansDepthData)
										       
						"Plot data on depths of cards under Orphans box.")))))
					       (FiledCardLinksData (NFSTAT.AttachStatsWindow
								     (NFSTAT.HistPlot FILEBOXHIST
										      (CONCAT
											
										   FileNamePrefix 
								    "FiledCard links per filebox")
										      
										 FILEBOXHISTENTRY 
									  HISTENTRYFILEDCARDLINKS)
								     FILEDCARDSTATS))
					       (SubBoxLinksData (NFSTAT.AttachStatsWindow
								  (NFSTAT.HistPlot FILEBOXHIST
										   (CONCAT 
										   FileNamePrefix 
								       "SubBox links per filebox")
										   FILEBOXHISTENTRY 
									     HISTENTRYSUBBOXLINKS)
								  SUBBOXSTATS))
					       (TableOfContentsDepthData (NFSTAT.AttachStatsWindow
									   (NFSTAT.HistPlot
									     TOCDEPTHHIST
									     (CONCAT FileNamePrefix 
						      "depths of cards under TableOfContents box"))
									   TOCDEPTHSTATS))
					       (ToBeFiledDepthData (NFSTAT.AttachStatsWindow
								     (NFSTAT.HistPlot TBFDEPTHHIST
										      (CONCAT
											
										   FileNamePrefix 
							    "depths of cards under ToBeFiled box"))
								     TBFDEPTHSTATS))
					       (OrphansDepthData (NFSTAT.AttachStatsWindow
								   (NFSTAT.HistPlot ORPHDEPTHHIST
										    (CONCAT 
										   FileNamePrefix 
							      "depths of cards under Orphans box"))
								   ORPHDEPTHSTATS))
					       NIL))))

(NFSTAT.CardDataHistPlot
  (LAMBDA (AllCardsData CardTypesHashArray FileNamePrefix)   (* rht: "19-Aug-86 14:59")

          (* * Make hist plot of whatever CardData user desires. Let user choose both card type and type of data to plot from
	  a stylesheet.)


    (with ALLCARDSDATA AllCardsData
	    (LET ((ChoiceStyle
		    (STYLESHEET (CREATE.STYLE
				    (QUOTE TITLE)
				    "Type of info to plot?"
				    (QUOTE ITEM.TITLES)
				    (QUOTE ("Card Type" "Data type"))
				    (QUOTE ITEMS)
				    (LIST (create MENU
						      ITEMS ←(CONS
							(QUOTE ALL% CARDS)
							(LET (CardTypes)
							     (MAPHASH CardTypesHashArray
									(FUNCTION (LAMBDA (Value
									      Key)
									    (push CardTypes Key))))
							 CardTypes)))
					    (create MENU
						      ITEMS ←(QUOTE (SmallSizes LargeSizes Parents 
										  ToLinks FromLinks 
										  GlobalLinks))))
				    (QUOTE SELECTIONS)
				    (QUOTE (ALL% CARDS NIL)))))
		  CardType DataType)
	         (SETQ CardType (CAR ChoiceStyle))
	         (SETQ DataType (CADR ChoiceStyle))
	         (LET ((CardTypeData (AND (NOT (EQ CardType (QUOTE ALL% CARDS)))
					    (GETHASH CardType CardTypesHashArray)))
		       Hist Stats MessagePrefix)
		      (if CardTypeData
			  then (SETQ Hist (fetch (CARDTYPEDATA CARDTYPEHIST) of CardTypeData))
				 (SETQ Stats (fetch (CARDTYPEDATA CARDTYPESTATS) of 
										     CardTypeData))
				 (SETQ MessagePrefix (CONCAT FileNamePrefix CardType "s: "))
			else (SETQ Hist ALLCARDSHIST)
			       (SETQ Stats ALLCARDSSTATS)
			       (SETQ MessagePrefix (CONCAT FileNamePrefix "All cards: ")))
		      (with CARDSTATS Stats (SELECTQ
				DataType
				(SmallSizes (NFSTAT.AttachStatsWindow
					      (if (EQ CardType (QUOTE ALL% CARDS))
						  then (NFSTAT.HistPlot ALLCARDSSIZEHIST1
									  (CONCAT MessagePrefix 
							      "sizes under 10K in 100 byte steps"))
						else (NFSTAT.HistPlot (fetch (CARDTYPEDATA 
										CARDTYPESIZEHIST1)
									   of CardTypeData)
									(CONCAT MessagePrefix 
							      "sizes under 10K in 100 byte steps")))
					      SIZESTATS))
				(LargeSizes (NFSTAT.AttachStatsWindow
					      (if (EQ CardType (QUOTE ALL% CARDS))
						  then (NFSTAT.HistPlot ALLCARDSSIZEHIST2
									  (CONCAT MessagePrefix 
							      "sizes over 10K in 1000 byte steps"))
						else (NFSTAT.HistPlot (fetch (CARDTYPEDATA 
										CARDTYPESIZEHIST2)
									   of CardTypeData)
									(CONCAT MessagePrefix 
							      "sizes over 10K in 1000 byte steps")))
					      SIZESTATS))
				(Parents (NFSTAT.AttachStatsWindow (NFSTAT.HistPlot Hist
										      (CONCAT
											MessagePrefix 
								     "number of parents per card")
										      CARDHISTENTRY 
										 HISTENTRYPARENTS)
								     PARENTSSTATS))
				(ToLinks (NFSTAT.AttachStatsWindow (NFSTAT.HistPlot Hist
										      (CONCAT
											MessagePrefix 
								    "number of To Links per card")
										      CARDHISTENTRY 
										 HISTENTRYTOLINKS)
								     TOLINKSSTATS))
				(FromLinks (NFSTAT.AttachStatsWindow (NFSTAT.HistPlot Hist
											(CONCAT
											  
										    MessagePrefix 
								  "number of From Links per card")
											CARDHISTENTRY 
									       HISTENTRYFROMLINKS)
								       FROMLINKSSTATS))
				(GlobalLinks (NFSTAT.AttachStatsWindow (NFSTAT.HistPlot
									   Hist
									   (CONCAT MessagePrefix 
								"number of Global Links per card")
									   CARDHISTENTRY 
									   HISTENTRYGLOBALLINKS)
									 GLOBALLINKSSTATS))
				NIL)))))))

(NFSTAT.ExtraFileBoxDataHistPlot
  (LAMBDA (ExtraFileBoxData FileBoxData FileBoxLinksData FileNamePrefix)
                                                             (* rht: "19-Aug-86 15:39")

          (* * Make hist plot of whatever ExtraFileBoxData user desires. Let user choose both filebox type and type of data 
	  to plot from a stylesheet.)


    (with EXTRAFILEBOXDATA ExtraFileBoxData
	    (with CARDTYPEDATA FileBoxData
		    (LET ((ChoiceStyle (STYLESHEET (CREATE.STYLE
						       (QUOTE TITLE)
						       "Type of info to plot?"
						       (QUOTE ITEM.TITLES)
						       (QUOTE ("FileBox Type" "Data type"))
						       (QUOTE ITEMS)
						       (LIST (create MENU
									 ITEMS ←(QUOTE
									   (ALL% FILEBOXES 
									 FileBoxes% w/o% SubBoxes 
								       FileBoxes% w/o% FiledCards 
									 FileBoxes% w/o% Children 
										 Other% FileBoxes)))
							       (create MENU
									 ITEMS ←(QUOTE
									   (SmallSizes LargeSizes 
										       Parents 
										       ToLinks 
										       FromLinks 
										      GlobalLinks 
										   FiledCardLinks 
										      SubBoxLinks))))
						       (QUOTE SELECTIONS)
						       (QUOTE (ALL% FILEBOXES NIL)))))
			  FileBoxType DataType)
		         (SETQ FileBoxType (CAR ChoiceStyle))
		         (SETQ DataType (CADR ChoiceStyle))
		         (LET ((SpecialFBData (SELECTQ FileBoxType
							 (FileBoxes% w/o% SubBoxes FBW/OSUBBOXESDATA)
							 (FileBoxes% w/o% FiledCards 
									      FBW/OFILEDCARDSDATA)
							 (FileBoxes% w/o% Children FBW/OCHILDRENDATA)
							 (Other% FileBoxes OTHERFBDATA)
							 NIL))
			       Stats Hist LinksHist MessagePrefix)
			      (with SPECIALFBDATA SpecialFBData (if SpecialFBData
								      then (SETQ Stats 
									       SPECIALFBSTATS)
									     (SETQ Hist 
									       SPECIALFBHIST)
									     (SETQ LinksHist 
									       SPECIALFBLINKSHIST)
									     (SETQ MessagePrefix
									       (CONCAT 
										   FileNamePrefix 
										      FileBoxType 
											 ": "))
								    else (SETQ Stats 
									     CARDTYPESTATS)
									   (SETQ Hist CARDTYPEHIST)
									   (SETQ LinksHist
									     (fetch (FILEBOXDATA
											FILEBOXHIST)
										of FileBoxLinksData)
									     )
									   (SETQ MessagePrefix
									     (CONCAT FileNamePrefix 
										"All fileboxes: ")))
				      (with CARDSTATS Stats
					      (SELECTQ DataType
							 (SmallSizes (NFSTAT.AttachStatsWindow
								       (NFSTAT.HistPlot (if 
										    SpecialFBData
											    then
											     
									       SPECIALFBSIZEHIST1
											  else
											   
										CARDTYPESIZEHIST1)
											(CONCAT
											  
										    MessagePrefix 
							      "sizes under 10K in 100 byte steps"))
								       SIZESTATS))
							 (LargeSizes (NFSTAT.AttachStatsWindow
								       (NFSTAT.HistPlot (if 
										    SpecialFBData
											    then
											     
									       SPECIALFBSIZEHIST2
											  else
											   
										CARDTYPESIZEHIST2)
											(CONCAT
											  
										    MessagePrefix 
							      "sizes over 10K in 1000 byte steps"))
								       SIZESTATS))
							 (Parents (NFSTAT.AttachStatsWindow
								    (NFSTAT.HistPlot Hist
										     (CONCAT 
										    MessagePrefix 
								     "number of parents per card")
										     CARDHISTENTRY 
										 HISTENTRYPARENTS)
								    PARENTSSTATS))
							 (ToLinks (NFSTAT.AttachStatsWindow
								    (NFSTAT.HistPlot Hist
										     (CONCAT 
										    MessagePrefix 
								    "number of To Links per card")
										     CARDHISTENTRY 
										 HISTENTRYTOLINKS)
								    TOLINKSSTATS))
							 (FromLinks (NFSTAT.AttachStatsWindow
								      (NFSTAT.HistPlot Hist
										       (CONCAT
											 
										    MessagePrefix 
								  "number of From Links per card")
										       CARDHISTENTRY 
									       HISTENTRYFROMLINKS)
								      FROMLINKSSTATS))
							 (GlobalLinks (NFSTAT.AttachStatsWindow
									(NFSTAT.HistPlot
									  Hist
									  (CONCAT MessagePrefix 
								"number of Global Links per card")
									  CARDHISTENTRY 
									  HISTENTRYGLOBALLINKS)
									GLOBALLINKSSTATS))
							 (FiledCardLinks
							   (NFSTAT.AttachStatsWindow
							     (NFSTAT.HistPlot LinksHist
									      (CONCAT MessagePrefix 
								    "FiledCard links per filebox")
									      FILEBOXHISTENTRY 
									  HISTENTRYFILEDCARDLINKS)
							     (if SpecialFBData
								 then SPECIALFBFILEDCARDSTATS
							       else (fetch (FILEBOXDATA 
										   FILEDCARDSTATS)
									 of FileBoxLinksData))))
							 (SubBoxLinks
							   (NFSTAT.AttachStatsWindow
							     (NFSTAT.HistPlot LinksHist
									      (CONCAT MessagePrefix 
								       "SubBox links per filebox")
									      FILEBOXHISTENTRY 
									     HISTENTRYSUBBOXLINKS)
							     (if SpecialFBData
								 then SPECIALFBSUBBOXSTATS
							       else (fetch (FILEBOXDATA 
										      SUBBOXSTATS)
									 of FileBoxLinksData))))
							 NIL)))))))))

(NFSTAT.AttachStatsWindow
  (LAMBDA (HistPlot Stats)                                   (* rht: "26-Jul-86 22:52")

          (* * Attach an inspector window on a stats record to the hist window.)


    (ATTACHWINDOW (INSPECT Stats NIL (QUOTE (1500 . 1500)))
		    (GETPLOTWINDOW HistPlot)
		    (QUOTE RIGHT)
		    (QUOTE TOP)
		    (QUOTE LOCALCLOSE))))
)
(DECLARE: EVAL@COMPILE 
(DEFMACRO NFSTAT.HistPlot (Hist Label &OPTIONAL RecordName &OPTIONAL FieldName)
	  (* * Create a histogram plot using HISTPLOT from the PLOTEXAMPLES package of that field of 
	     Hist given by FieldName. If FieldName is nil, then Hist is assumed to contain integers 
	     rather than datatype entries.)
	  (if RecordName then
	      (BQUOTE (HISTPLOT (for i from 0 to (SUB1 NFSTAT.HistSize)
				     collect
				     (LET ((HistEntry (ELT , Hist i)))
					  (CONS i (OR (AND (type? , RecordName HistEntry)
							   (fetch (, RecordName , FieldName)
								  of HistEntry))
						      0))))
				(OR , Label (CONCAT (QUOTE , FieldName)
						    " of "
						    (QUOTE , RecordName)))))
	      else
	      (BQUOTE (HISTPLOT (for i from 0 to (SUB1 NFSTAT.HistSize)
				     collect
				     (LET ((HistEntry (ELT , Hist i)))
					  (CONS i (OR (NUMBERP HistEntry)
						      0))))
				, Label))))
)
(* * Functions for combining stats from multiple notefiles.)

(DEFINEQ

(NFSTAT.SummarizeDataFiles
  (LAMBDA (Files OutputFile SummaryFileName QuietFlg)        (* rht: "21-Aug-86 11:58")

          (* * Files can either be a list of files or a DIRECTORY style file group. Combine the information from all the data
	  files in Files and output to OutputFile. If SummaryFile is non-nil, then it should be a starting summary already 
	  containing summarized data for some data files.)


    (OR (LISTP Files)
	  (SETQ Files (DIRECTORY Files)))
    (LET ((SummaryFile (AND SummaryFileName (OPENFILE SummaryFileName (QUOTE INPUT))))
	  SummaryDataFileInfo SummaryDataFileAttributes SummaryDataFileData Result ExtraFileBoxData)
         (AND SummaryFile (SETQ SummaryDataFileInfo (HREAD SummaryFile)))
         (if (AND SummaryDataFileInfo (NOT (type? NOTEFILEINFO SummaryDataFileInfo)))
	     then (SETQ SummaryDataFileInfo (create NOTEFILEINFO
							  NOTEFILEATTRIBUTES ←(CAR 
									      SummaryDataFileInfo)
							  NOTEFILEDATA ←(CADR SummaryDataFileInfo)
							  EXTRAFILEBOXDATA ←(CADDR 
									      SummaryDataFileInfo))))
         (SETQ SummaryDataFileAttributes
	   (if SummaryDataFileInfo
	       then (fetch (NOTEFILEINFO NOTEFILEATTRIBUTES) of SummaryDataFileInfo)
	     else (create NOTEFILEATTRIBUTES
			      FULLNAME ← Files
			      AUTHOR ← NIL
			      CREATIONDATE ← NIL
			      WRITEDATE ← NIL
			      READDATE ← NIL
			      SIZE ←(LENGTH Files))))
         (if SummaryDataFileInfo
	     then (with NOTEFILEATTRIBUTES SummaryDataFileAttributes (SETQ FULLNAME
			      (APPEND FULLNAME Files))
			    (add SIZE (LENGTH Files))))
         (SETQ SummaryDataFileData (if SummaryDataFileInfo
					 then (fetch (NOTEFILEINFO NOTEFILEDATA) of 
									      SummaryDataFileInfo)
				       else (NFSTAT.MakeFreshNoteFileDataRecord)))
         (SETQ ExtraFileBoxData (if SummaryDataFileInfo
				      then (fetch (NOTEFILEINFO EXTRAFILEBOXDATA) of 
									      SummaryDataFileInfo)
				    else (NFSTAT.MakeFreshExtraFileBoxDataRecord)))
         (for FileName in Files eachtime (BLOCK)
	    do (LET ((File (OPENFILE FileName (QUOTE INPUT))))
		      (if File
			  then (OR QuietFlg (NCP.PrintMsg NIL T "Combining data from file ..."
								(CHARACTER 13)
								File " ..."))
				 (LET ((ThingRead (HREAD File))
				       NoteFileInfo NoteFileExtraFileBoxData)
				      (COND
					((type? NOTEFILEINFO ThingRead)
					  (SETQ NoteFileInfo (fetch (NOTEFILEINFO NOTEFILEDATA)
								  of ThingRead))
					  (SETQ NoteFileExtraFileBoxData (fetch (NOTEFILEINFO
										      
										 EXTRAFILEBOXDATA)
									      of ThingRead)))
					((LISTP (CDR ThingRead))
					  (SETQ NoteFileInfo (CADR ThingRead))
					  (SETQ NoteFileExtraFileBoxData (CADDR ThingRead)))
					(T (SETQ NoteFileInfo (CDR ThingRead))))
				      (NFSTAT.CombineNoteFileData SummaryDataFileData NoteFileInfo)
				      (AND NoteFileExtraFileBoxData (
					       NFSTAT.CombineExtraFileBoxData ExtraFileBoxData 
									 NoteFileExtraFileBoxData)))
				 (CLOSEF File))))

          (* * Fill in stats.)


         (NFSTAT.ComputeNoteFileStats SummaryDataFileData QuietFlg)
         (NFSTAT.ComputeExtraFileBoxStats ExtraFileBoxData QuietFlg)

          (* * Write results out to OutputFile.)


         (if (ERSETQ (OPENFILE OutputFile (QUOTE OUTPUT)))
	     then (OR QuietFlg (NCP.PrintMsg NIL T "Writing out results to " OutputFile " ..."))
		    (HPRINT (SETQ Result (LIST SummaryDataFileAttributes SummaryDataFileData 
						     ExtraFileBoxData))
			      OutputFile T)
		    (CLOSEF OutputFile)
		    (OR QuietFlg (NCP.PrintMsg NIL T "Done."))
		    Result
	   else (ERROR "Trouble opening " OutputFile)))))

(NFSTAT.CombineNoteFileData
  (LAMBDA (SummaryData NoteFileData)                         (* rht: "26-Jul-86 19:20")

          (* * Add in the NoteFileData into SummaryData.)


    (LET ((SummaryAllCardsData (fetch (NOTEFILEDATA ALLCARDSDATA) of SummaryData))
	  (NoteFileAllCardsData (fetch (NOTEFILEDATA ALLCARDSDATA) of NoteFileData))
	  (SummaryFileBoxData (fetch (NOTEFILEDATA FILEBOXDATA) of SummaryData))
	  (NoteFileFileBoxData (fetch (NOTEFILEDATA FILEBOXDATA) of NoteFileData)))

          (* * First deal with the data for all cards, as opposed to by card type.)

                                                             (* First, the size histograms.)
         (replace (ALLCARDSDATA ALLCARDSSIZEHIST1) of SummaryAllCardsData
	    with (NFSTAT.CombineHists (fetch (ALLCARDSDATA ALLCARDSSIZEHIST1) of 
									      SummaryAllCardsData)
					  (fetch (ALLCARDSDATA ALLCARDSSIZEHIST1) of 
									     NoteFileAllCardsData)))
         (replace (ALLCARDSDATA ALLCARDSSIZEHIST2) of SummaryAllCardsData
	    with (NFSTAT.CombineHists (fetch (ALLCARDSDATA ALLCARDSSIZEHIST2) of 
									      SummaryAllCardsData)
					  (fetch (ALLCARDSDATA ALLCARDSSIZEHIST2) of 
									     NoteFileAllCardsData)))
                                                             (* Now, the data on parents, tolinks, fromlinks, and 
							     global links.)
         (replace (ALLCARDSDATA ALLCARDSHIST) of SummaryAllCardsData
	    with (NFSTAT.CombineHists (fetch (ALLCARDSDATA ALLCARDSHIST) of 
									      SummaryAllCardsData)
					  (fetch (ALLCARDSDATA ALLCARDSHIST) of 
									     NoteFileAllCardsData)
					  (QUOTE CARDHISTENTRY)))

          (* * Now combine the card types data.)


         (NFSTAT.CombineCardTypesData (fetch (NOTEFILEDATA CARDTYPESHASHARRAY) of SummaryData)
					(fetch (NOTEFILEDATA CARDTYPESHASHARRAY) of NoteFileData))

          (* * Now combine the filebox data.)

                                                             (* First the info on filedcard and subbox links.)
         (replace (FILEBOXDATA FILEBOXHIST) of SummaryFileBoxData
	    with (NFSTAT.CombineHists (fetch (FILEBOXDATA FILEBOXHIST) of SummaryFileBoxData)
					  (fetch (FILEBOXDATA FILEBOXHIST) of NoteFileFileBoxData)
					  (QUOTE FILEBOXHISTENTRY)))
                                                             (* Next the info on depth of filebox hierarchies.)
         (replace (FILEBOXDATA TOCDEPTHHIST) of SummaryFileBoxData
	    with (NFSTAT.CombineHists (fetch (FILEBOXDATA TOCDEPTHHIST) of SummaryFileBoxData)
					  (fetch (FILEBOXDATA TOCDEPTHHIST) of 
									      NoteFileFileBoxData)))
         (replace (FILEBOXDATA TBFDEPTHHIST) of SummaryFileBoxData
	    with (NFSTAT.CombineHists (fetch (FILEBOXDATA TBFDEPTHHIST) of SummaryFileBoxData)
					  (fetch (FILEBOXDATA TBFDEPTHHIST) of 
									      NoteFileFileBoxData)))
         (replace (FILEBOXDATA ORPHDEPTHHIST) of SummaryFileBoxData
	    with (NFSTAT.CombineHists (fetch (FILEBOXDATA ORPHDEPTHHIST) of 
									       SummaryFileBoxData)
					  (fetch (FILEBOXDATA ORPHDEPTHHIST) of 
									      NoteFileFileBoxData)))

          (* * Now combine the linktypes hash arrays.)


         (NFSTAT.CombineHashArrays (fetch (NOTEFILEDATA LINKTYPESHASHARRAY) of SummaryData)
				     (fetch (NOTEFILEDATA LINKTYPESHASHARRAY) of NoteFileData))

          (* * Now combine the numlinks info.)


         (replace (NOTEFILEDATA NUMLINKS) of SummaryData with (PLUS (fetch (NOTEFILEDATA
										       NUMLINKS)
									       of SummaryData)
									    (fetch (NOTEFILEDATA
										       NUMLINKS)
									       of NoteFileData)))

          (* * Increment the total num cards)


         (with CARDSTATS (fetch (ALLCARDSDATA ALLCARDSSTATS) of SummaryAllCardsData)
		 (add TOTAL (fetch (CARDSTATS TOTAL) of (fetch (ALLCARDSDATA ALLCARDSSTATS)
								 of NoteFileAllCardsData)))))))

(NFSTAT.CombineCardTypesData
  (LAMBDA (SummaryCardTypesHashArray NoteFileCardTypesHashArray)
                                                             (* rht: "27-Jul-86 00:31")

          (* * Combine the card types data from NoteFileCardTypesHashArray into the summary data.)


    (MAPHASH NoteFileCardTypesHashArray (FUNCTION
		 (LAMBDA (CardTypeData CardType)
		   (LET ((CurVal (GETHASH CardType SummaryCardTypesHashArray)))
		        (BLOCK)
		        (if CurVal
			    then                           (* First, the size histograms by cardtype.)
				   (replace (CARDTYPEDATA CARDTYPESIZEHIST1) of CurVal
				      with (NFSTAT.CombineHists (fetch (CARDTYPEDATA 
										CARDTYPESIZEHIST1)
								       of CurVal)
								    (fetch (CARDTYPEDATA 
										CARDTYPESIZEHIST1)
								       of CardTypeData)))
				   (replace (CARDTYPEDATA CARDTYPESIZEHIST2) of CurVal
				      with (NFSTAT.CombineHists (fetch (CARDTYPEDATA 
										CARDTYPESIZEHIST2)
								       of CurVal)
								    (fetch (CARDTYPEDATA 
										CARDTYPESIZEHIST2)
								       of CardTypeData)))
                                                             (* Now, the data on parents, tolinks, fromlinks, and 
							     global links by cardtype.)
				   (replace (CARDTYPEDATA CARDTYPEHIST) of CurVal
				      with (NFSTAT.CombineHists (fetch (CARDTYPEDATA 
										     CARDTYPEHIST)
								       of CurVal)
								    (fetch (CARDTYPEDATA 
										     CARDTYPEHIST)
								       of CardTypeData)
								    (QUOTE CARDHISTENTRY)))
                                                             (* Increment the total num cards for this type.)
				   (with CARDSTATS (fetch (CARDTYPEDATA CARDTYPESTATS)
							of CurVal)
					   (add TOTAL (fetch (CARDSTATS TOTAL)
							   of (fetch (CARDTYPEDATA CARDTYPESTATS)
								   of CardTypeData))))
			  else (PUTHASH CardType CardTypeData SummaryCardTypesHashArray))))
		 (SummaryCardTypesHashArray)))))

(NFSTAT.CombineHashArrays
  (LAMBDA (SummaryHashArray NoteFileHashArray)               (* rht: "27-Jul-86 00:32")

          (* * Combine the second hash array into the first.)


    (MAPHASH NoteFileHashArray (FUNCTION (LAMBDA (Value Key)
					       (LET ((CurVal (GETHASH Key SummaryHashArray)))
						    (BLOCK)
						    (PUTHASH Key (if CurVal
								       then (PLUS CurVal Value)
								     else Value)
							       SummaryHashArray)))
					     (SummaryHashArray)))))

(NFSTAT.CombineHists
  (LAMBDA (SummaryHist Hist RecordName)                      (* rht: "27-Jul-86 00:31")

          (* * Adds the contents of Hist2 to Hist1. If RecordName is non-nil then it should be the record type of the entries
	  in Hists. If nil, then the entries are numbers.)


    (if RecordName
	then (for i from 0 to (SUB1 NFSTAT.HistSize) eachtime (BLOCK)
		  do (LET ((SummaryHistEntry (ELT SummaryHist i))
			     (HistEntry (ELT Hist i)))
			    (if HistEntry
				then (if (NULL SummaryHistEntry)
					   then            (* Make a fresh hist entry for this slot if needed.)
						  (SETA SummaryHist i (SETQ SummaryHistEntry
							    (NFSTAT.MakeFreshHistRecord RecordName))
							  ))
                                                             (* Add fields of Hist entry to fields of SummaryHist 
							     entry.)
				       (for FieldName in (RECORDFIELDNAMES RecordName)
					  do (RECORDACCESS FieldName SummaryHistEntry NIL
							       (QUOTE REPLACE)
							       (PLUS (RECORDACCESS FieldName 
										 SummaryHistEntry NIL
										       (QUOTE
											 FETCH))
								       (RECORDACCESS FieldName 
										       HistEntry NIL
										       (QUOTE
											 FETCH))))))))
      else                                                 (* No records to fool with, just add integers.)
	     (for i from 0 to (SUB1 NFSTAT.HistSize) eachtime (BLOCK)
		do (SETA SummaryHist i (PLUS (ELT SummaryHist i)
						   (ELT Hist i)))))
    SummaryHist))

(NFSTAT.ComputeStatsFromDepthHist
  (LAMBDA (DepthHist)                                        (* rht: "26-Jul-86 20:29")

          (* * Returns a stats record for DepthHist.)


    (NFSTAT.AnalyzeHist DepthHist 1 (for i from 0 to (SUB1 NFSTAT.HistSize)
				       sum (ELT DepthHist i))
			NIL NIL)))
)
(DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS 

(ADDTOVAR NLAMA )

(ADDTOVAR NLAML )

(ADDTOVAR LAMA NFSTAT.AnalyzeSetsOfNoteFiles)
)
(PUTPROPS NOTEFILESTATS COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (7554 11869 (NFSTAT.AnalyzeRemoteNoteFile 7564 . 10887) (NFSTAT.GatherNoteFileData 10889
 . 11867)) (11900 21332 (NFSTAT.MakeFreshNoteFileDataRecord 11910 . 13000) (NFSTAT.ProcessCards 13002
 . 17376) (NFSTAT.ProcessFileBoxHierarchies 17378 . 18706) (NFSTAT.ComputeNoteFileStats 18708 . 21330)
) (21333 27060 (NFSTAT.AddCardDataToHist 21343 . 21939) (NFSTAT.AddFileBoxDataToHist 21941 . 22347) (
NFSTAT.AddCardSizeDataToHist 22349 . 23100) (NFSTAT.MakeFreshHistRecord 23102 . 23674) (
NFSTAT.TraverseFileBoxHierarchy 23676 . 24392) (NFSTAT.ComputeSubstanceSize 24394 . 25509) (
NFSTAT.IncrementHashItem 25511 . 25810) (NFSTAT.FetchCardTypeData 25812 . 26425) (
NFSTAT.FillInCardStats 26427 . 27058)) (30457 38369 (NFSTAT.MakeFreshExtraFileBoxDataRecord 30467 . 
30972) (NFSTAT.MakeFreshSpecialFBDataRecord 30974 . 31559) (NFSTAT.InstallExtraFileBoxData 31561 . 
32825) (NFSTAT.InstallSpecialFBData 32827 . 33510) (NFSTAT.ComputeExtraFileBoxStats 33512 . 34031) (
NFSTAT.ComputeSpecialFBStats 34033 . 35161) (NFSTAT.CombineExtraFileBoxData 35163 . 36112) (
NFSTAT.CombineSpecialFBData 36114 . 38367)) (38410 40466 (NFSTAT.AnalyzeSetsOfNoteFiles 38420 . 39039)
 (NFSTAT.AnalyzeListOfNoteFiles 39041 . 39420) (NFSTAT.MakeOutputFileName 39422 . 39901) (
NFSTAT.InspectDataFile 39903 . 40464)) (40528 54239 (NFSTAT.NoteFileInfoHistPlot 40538 . 42030) (
NFSTAT.FileBoxDataHistPlot 42032 . 44553) (NFSTAT.CardDataHistPlot 44555 . 48407) (
NFSTAT.ExtraFileBoxDataHistPlot 48409 . 53841) (NFSTAT.AttachStatsWindow 53843 . 54237)) (55235 68350 
(NFSTAT.SummarizeDataFiles 55245 . 59323) (NFSTAT.CombineNoteFileData 59325 . 63625) (
NFSTAT.CombineCardTypesData 63627 . 65781) (NFSTAT.CombineHashArrays 65783 . 66313) (
NFSTAT.CombineHists 66315 . 68008) (NFSTAT.ComputeStatsFromDepthHist 68010 . 68348)))))
STOP