Concatenate Data Folder References?

Hello everybody,

I am not trying to flood the forum here; this is just another small issue that I have a hard time understanding:

I am quite heavily using DataFolderReferences (DFREFs). As far as I got it, you can concatenate one more thing after the created DFREF for use in a function like the mentioned example in the manual DFREF dfr = root:folder; Display dfr:ywave". The manual says:
The syntax is limited to a single name after the data folder reference [...]

So why can't I use it to check on DataFolderExists, something like DFREF dfr = root:folder; Datafolderexists(dfr:subfolder)? I saw that there is even a node open here addressing this issue: http://www.igorexchange.com/node/2055
For the prupose of checking DataFolderExists and if I may have to concatenate two subfolders I am still using strings the old way.
Honestly, I do not really get the actual advantage of using DFREFs over strings since for the latter it is easily possible to create a subfolder with a referenced string, something that makes things easier and that does not work with DFREFs.

Best regards,

Martin
Quote:
So why can't I use it to check on DataFolderExists, something like DFREF dfr = root:folder; Datafolderexists(dfr:subfolder)?

Because dfr:subfolder is a new data folder reference and DataFolderExists expects a string.

As you already found out, my DataFolderExistsDFR accepts things like DataFolderExistsDFR(dfr:Packages).

Datafolder references are lighweight replacements of strings refererring to datafolders. I also presume that they can be copied and checked for validity much faster. And you can put DFREFs into their waves which makes storing and accessing them quite fast.

I did some playing around with
Function DoStuff()
   
    NewDataFolder/O root:Packages

    dfref dfr1 = root:
    dfref dfr2 = dfr1:Packages
    print "1: ", GetDataFolder(1, dfr2)
    print "2: ", GetDataFolder(1, dfr1)
    dfref dfr1 = dfr1:Packages 
    print "3: ", GetDataFolder(1, dfr1)
End

and was a bit surprised that the output is
•DoStuff() 1: root:Packages: 2: root: 3:
As I wanted to suggest method 3 to solve your issue.
thomas_braun][quote wrote:

I did some playing around with
Function DoStuff()
   
    NewDataFolder/O root:Packages

    dfref dfr1 = root:
    dfref dfr2 = dfr1:Packages
    print "1: ", GetDataFolder(1, dfr2)
    print "2: ", GetDataFolder(1, dfr1)
    dfref dfr1 = dfr1:Packages 
    print "3: ", GetDataFolder(1, dfr1)
End

and was a bit surprised that the output is
•DoStuff() 1: root:Packages: 2: root: 3:
As I wanted to suggest method 3 to solve your issue.


Interestingly, the following code:

Function DoStuff()
 
    NewDataFolder/O root:Packages
 
    dfref dfr1 = root:
    dfref dfr2 = dfr1:Packages
    print "1: ", GetDataFolder(1, dfr2)
    print "2: ", GetDataFolder(1, dfr1)
    dfref dfr3 = dfr1:Packages 
    print "3: ", GetDataFolder(1, dfr3)
    dfref dfr1 = dfr1:Packages 
    print "4: ", GetDataFolder(1, dfr1)
End

produces the following output:
1: root:Packages:
2: root:
3: root:Packages:
4:

HTH,
Kurt
Hello Thomas!

Your method three is working; you just need to leave out the second DFREF declaration for dfr1!

Also, you are probably right that when it comes to checking two paths or do some serious debugging it is probably quite handy.
However, I think converting the dfr into a string via GetDataFolder to check the existence of a folder is not saving so much as if I would just use strings to reference paths right away.

Best regards,

Martin
Irvine_audit wrote:
Hello Thomas!

Your method three is working; you just need to leave out the second DFREF declaration for dfr1!

Also, you are probably right that when it comes to checking two paths or do some serious debugging it is probably quite handy.
However, I think converting the dfr into a string via GetDataFolder to check the existence of a folder is not saving so much as if I would just use strings to reference paths right away.

Best regards,

Martin


Good catch! Indeed the following snippet
Function DoStuff()
 
    NewDataFolder/O root:Packages
 
    dfref dfr1 = root:
    dfref dfr2 = dfr1:Packages
    print "1: ", GetDataFolder(1, dfr2)
    print "2: ", GetDataFolder(1, dfr1)
    dfr1 = dfr1:Packages   
    print "3: ", GetDataFolder(1, dfr1)
End

works as expected.

The reason why my DataFolderExistsDFR is not as fast as possible is that it considers empty DFREFs as invalid, as opposed to standard igor functions which, due to backward compatibility considerations, consider that as the current datafolder.
If you have a DFREF you can check for existence using DataFolderRefStatus(). See this for extensive discussion of data folder references and the functions that manipulate them:

DisplayHelpTopic "Data Folder References"

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
The documentation of DataFolderRefStatus states
Quote:

A data folder reference can be valid and yet point to a non-existent data folder:

and this made me think that just checking DataFolderRefStatus is not enough to ensure that the datafolder behin the DFREF does exist.
@johnweeks

Thank you John, that works just as I imagined! Still I have some questions to understand why it actually works. If I am using code like that...

Function check_dfr()
    string dfr_s
    dfr_s="root:test2:test2"
 
    NewDataFolder/O root:test2:Packages
    NewDataFolder/O root:test2:test2
 
    dfref dfr1 = root:test2
    if(DataFolderrefstatus(dfr1:test2))
        print "yes"
    else
        print "no"
    endif
    if(DataFolderexists(dfr_s))
    print "yes"
    else
    print "no"
    endif
End


... I can nicely verify that works just as using a string and DataFolderExists even if I commentize the second NewDataFolder declaration and kill the "test2" folder manually.

But I also stumbled upon what thomas_braun mentioned in his post. Am I right, that the dfr only remains valid if the KillDataFolder operation comes after checking the refstatus? Because this is just the same as if I'd be using strings and DataFolderexists, isn´t it?
And DataFolderrefstatus allows one more folder after the dfr because it does not want a string like DataFolderexists?
It starts to make sense now! :)

Best regards,

Martin
thomas_braun wrote:
The documentation of DataFolderRefStatus states
Quote:

A data folder reference can be valid and yet point to a non-existent data folder:

and this made me think that just checking DataFolderRefStatus is not enough to ensure that the datafolder behin the DFREF does exist.

Huh. I didn't notice that. So I wrote a test function that does exactly what's in the documentation:
Function test()

    NewDataFolder/O/S root:testdf
    DFREF newdf = GetDataFolderDFR()
    print "Before killing, status = ", DataFolderRefStatus(newdf)
    KillDataFolder newdf
    print "Current Data Folder =", GetDataFolder(1)     // should be root:
    print "After killing, status =", DataFolderRefStatus(newdf)
end

When I run it in Igor 6.35:

•test()
Before killing, status = 1
Current Data Folder = root:
After killing, status = 0

I'll have to look into that.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com