How to get the data folder of a trace on the top graph?

I don't want to use the command GetDataFolder(mode [, dfr ] ), because I may have different data with the same name in different folders.

It's strange that the command TraceInfo(graphNameStr, yWaveNameStr, instance ) doesn't return the YWAVE DataFolder but XWAVEDataFolder.

Thanks,
Quote:
It's strange that the command TraceInfo(graphNameStr, yWaveNameStr, instance ) doesn't return the YWAVE DataFolder but XWAVEDataFolder.


I think that's because you can get the y wave and its data folder through other means (see the first function below), but I agree, it would seem more complete to include this information in the result from TraceInfo.

Here are functions that should work for you.

Function/DF GetTracesDFR(graphName, traceName)
    String graphName        // "" for top graph
    String traceName        // e.g., "wave0" or "wave0#1"
   
    Wave/Z w = TraceNameToWaveRef(graphName, traceName)
    if (!WaveExists(w))
        return $""          // NULL DFREF
    endif
    DFREF dfr = GetWavesDataFolderDFR(w)
    return dfr
End

Function/S GetTracesDFStr(graphName, traceName, mode)
    String graphName        // "" for top graph
    String traceName        // e.g., "wave0" or "wave0#1"
    Variable mode           // 0: Get data folder name; 1: Get data folder path
   
    DFREF dfr = GetTracesDFR(graphName, traceName)
    if (DataFolderRefStatus(dfr) == 0)
        return ""
    endif
   
    String df = GetDataFolder(mode, dfr)
    return df
End


For information about trace names like "wave0#1", execute this:
DisplayHelpTopic "Instance Notation"

hrodstein wrote:
Quote:
It's strange that the command TraceInfo(graphNameStr, yWaveNameStr, instance ) doesn't return the YWAVE DataFolder but XWAVEDataFolder.


I think that's because you can get the y wave and its data folder through other means (see the first function below), but I agree, it would seem more complete to include this information in the result from TraceInfo.

Here are functions that should work for you.

Function/DF GetTracesDFR(graphName, traceName)
    String graphName        // "" for top graph
    String traceName        // e.g., "wave0" or "wave0#1"
   
    Wave/Z w = TraceNameToWaveRef(graphName, traceName)
    if (!WaveExists(w))
        return $""          // NULL DFREF
    endif
    DFREF dfr = GetWavesDataFolderDFR(w)
    return dfr
End

Function/S GetTracesDFStr(graphName, traceName, mode)
    String graphName        // "" for top graph
    String traceName        // e.g., "wave0" or "wave0#1"
    Variable mode           // 0: Get data folder name; 1: Get data folder path
   
    DFREF dfr = GetTracesDFR(graphName, traceName)
    if (DataFolderRefStatus(dfr) == 0)
        return ""
    endif
   
    String df = GetDataFolder(mode, dfr)
    return df
End


For information about trace names like "wave0#1", execute this:
DisplayHelpTopic "Instance Notation"

That's very useful. Thank you very much.