#pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 // Use modern global access method and strict wave access. // Shows all graph windows containing at least // one wave that is in the current data folder. All // other graph windows are hidden. Function ShowGraphsWithWaveInCDF() String graphWinList = WinList("*", ";", "WIN:1") WAVE/T graphWinWave = ListToTextWave(graphWinList, ";") Variable numGraphWins = numpnts(graphWinWave) Make/O/FREE/B/U/N=(numGraphWins) showWindowWave // Wave to hold 1 to show window or 0 to hide it if (numGraphWins < 1) // Nothing to do, so exit early. return 0 endif // Create and populate a wave reference wave that holds wave references // to all waves within the current data folder and // all child data folders. Make/O/FREE/WAVE/N=(0) wavesInCurrentDF GetWavesInDFR(wavesInCurrentDF, GetDataFolderDFR(), 1) // Iterate through all windows in graphWinWave to determine // if it contains any waves in the current data folder, to determine // if it should be hidden or shown. showWindowWave[] = WindowContainsWaveInList(graphWinWave[p], wavesInCurrentDF) // Now show or hide the windows as appropriate. Variable n For (n=0; n < numGraphWins; n++) SetWindow $(graphWinWave[n]) hide=!(showWindowWave[n]) EndFor End // Returns 1 if windowName contains one or more of the waves // in wavesInCDF. Otherwise returns 0. windowName is expected // to be a valid graph or table window name. // NOTE: If windowName has subwindows, those subwindows will also // be checked for use of the waves. Function WindowContainsWaveInList(windowName, wavesInCDF) String windowName Wave/WAVE wavesInCDF Variable numWaves = numpnts(wavesInCDF) Variable n For (n=0; n < numWaves; n++) WAVE thisWave = wavesInCDF[n] CheckDisplayed/W=$(windowName) thisWave if (V_flag != 0) // The window uses this wave. We're done checking. return 1 endif EndFor return 0 // No waves in the list are used by this window End // Appends wave references for all waves in dfr to waveRefWave. // If recurse is non-zero, the function recurses into child // data folders as well. ThreadSafe Function GetWavesInDFR(waveRefWave, dfr, recurse) WAVE/WAVE waveRefWave DFREF dfr Variable recurse Variable index = 0 Variable numWaves = numpnts(waveRefWave) do Wave/Z w = WaveRefIndexedDFR(dfr, index) if (!WaveExists(w)) break endif waveRefWave[numWaves] = {w} numWaves++ index += 1 while(1) if (recurse) Variable numChildDataFolders = CountObjectsDFR(dfr, 4) Variable i for(i=0; i