Concatenate Data Folder References?
Irvine_audit
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/2055For 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
Because dfr:subfolder is a new data folder reference and
DataFolderExists
expects a string.As you already found out, my
DataFolderExistsDFR
accepts things likeDataFolderExistsDFR(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
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.
October 22, 2014 at 07:16 am - Permalink
Interestingly, the following code:
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
October 22, 2014 at 07:30 am - Permalink
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
October 22, 2014 at 07:37 am - Permalink
Good catch! Indeed the following snippet
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.October 22, 2014 at 08:28 am - Permalink
DisplayHelpTopic "Data Folder References"
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 22, 2014 at 01:27 pm - Permalink
DataFolderRefStatus
statesand this made me think that just checking DataFolderRefStatus is not enough to ensure that the datafolder behin the DFREF does exist.
October 22, 2014 at 03:16 pm - Permalink
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...
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 secondNewDataFolder
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 andDataFolderexists
, isn´t it?And
DataFolderrefstatus
allows one more folder after the dfr because it does not want a string likeDataFolderexists
?It starts to make sense now! :)
Best regards,
Martin
October 23, 2014 at 02:19 am - Permalink
Huh. I didn't notice that. So I wrote a test function that does exactly what's in the documentation:
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
October 23, 2014 at 10:03 am - Permalink