'get the active themes theGThemes = av.GetActiveDoc.GetActiveThemes theGrids = List.Make 'make the output filename fnStats = av.GetProject.MakeFileName("Stats","STA") fnStats = FileDialog.Put(fnStats,"*.STA","Input Statistics Filename") if (fnStats = nil) then exit end 'make sure all active themes are grid themes. for each t in theGthemes if (t.Is(Gtheme).Not) then msgBox.Error(t.GetName + " Is not a Grid Theme cannot use it.","") else theGrids.Add(t) end end if (theGrids.Count < 2) then msgBox.Error("You need at least two active grid themes that are the same spatially.","Not enough GThemes") exit end 'set up cell size and get rows and columns GRID.SetAnalysisCellSize (#GRID_ENVTYPE_MAXOF , nil) cols = theGrids.Get(0).GetGrid.GetNumRowsAndCols.Get(1) rows = theGrids.Get(0).GetGrid.GetNumRowsAndCols.Get(0) 'how many total cells elements = cols * rows 'set up an empty covarance and correlation matirx 'of the correct size corMat = {} for each i in 0..(theGrids.Count - 1) tmpLst = {} for each j in 0..(theGrids.Count - 1) tmpLst.Add("") end corMat.Add(tmpLst) end 'fill out the matrix with correct values cnt = 1 for each i in 0..(theGrids.Count - 1) for each j in i..(theGrids.Count - 1) g1 = theGrids.Get(i).GetGrid g1Stats = g1.GetStatistics g1Sum = g1Stats.Get(2) * elements g2 = theGrids.Get(j).GetGrid g2Stats = g2.GetStatistics g2Sum = g2Stats.Get(2) * elements sumProd = (g1Sum * g2Sum) / elements g3 = g1 * g2 g3Stats = g3.GetStatistics g3Sum = g3Stats.Get(2) * elements SP = g3Sum - sumProd cov = SP/elements r = cov/(g1Stats.Get(3) * g2Stats.Get(3)) lstTmp = {} lstTmp = corMat.Get(i) lstTmp.Set(j,r) corMat.Set(i,lstTmp) g1 = nil g2 = nil end cnt = cnt + 1 av.PurgeObjects end av.PurgeObjects for each i in 0..(corMat.Count-2) tmp1 = corMat.Get(i) for each j in (i+1)..(corMat.Count - 1) tmp2 = corMat.Get(j) tmp2.Set(i,tmp1.Get(j)) corMat.Set(j,tmp2) end end maxCnt = 0 for each i in theGrids if (i.GetName.Count > maxCnt) then maxCnt = i.GetName.Count end end 'create the output file fileStat = LineFile.Make(fnStats,#FILE_PERM_WRITE) 'creat a buffer for spacing in the file if (maxCnt > 10) then buf= String.MakeBuffer(maxCnt) else buf = String.MakeBuffer(10) end cnt = 0 outLine = "" fileStat.WriteElt("") fileStat.WriteElt("Correlation Matrix") cnt = 1 outLine = buf for each g in theGrids outLine = outLine + g.GetName + String.MakeBuffer(15 - g.GetName.Count) cnt = cnt + 1 end fileStat.WriteElt(outLine) cnt = 0 outLine = "" for each alst in corMat outLine = theGrids.Get(cnt).GetName + String.MakeBuffer(buf.Count - theGrids.Get(cnt).GetName.Count) for each x in alst outLine = outLine + x.asString + String.MakeBuffer(15 - x.asString.Count) end cnt = cnt + 1 fileStat.WriteElt(outLine) end 'close the file fileStat.Close