source: sans/Dev/trunk/NCNR_User_Procedures/Common/DataSetHandling.ipf @ 602

Last change on this file since 602 was 602, checked in by ajj, 13 years ago

Adding the start of dataset handling. Currently you can rename or duplicate a dataset.

Needed for re-write of NSORT and Subtract_1D.

File size: 1.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3// Functions and interfaces to manage datasets now that they are in data folders
4// Planned functions:
5// - Rename a data set
6// - Duplicate a data set
7// - Subtract one data set from another
8// - Add one data set to another
9// - Divide data sets
10// - Multiply data sets
11
12Function RenameDataSet(dataSetFolder, newName)
13        String dataSetFolder
14        String newName
15       
16        String dataSetFolderParent,basestr,objName
17        Variable index = 0
18       
19        //Abuse ParseFilePath to get path without folder name
20        dataSetFolderParent = ParseFilePath(1,dataSetFolder,":",1,0)
21        //Abuse ParseFilePath to get basestr
22        basestr = ParseFilePath(0,dataSetFolder,":",1,0)
23
24        try
25                RenameDataFolder $(dataSetFolder) $(newName); AbortOnRTE
26       
27
28                SetDataFolder $(dataSetFolderParent+newName); AbortOnRTE
29                do
30                        objName = GetIndexedObjName("",1,index)
31                        if (strlen(objName) == 0)
32                                break
33                        endif
34                        Rename $(objName) $(ReplaceString(basestr,objName,newName))
35                        index+=1
36                while(1)
37                SetDataFolder root:
38        catch
39                Print "Aborted: " + num2str(V_AbortCode)
40                SetDataFolder root:
41        endtry
42End
43
44
45Function DuplicateDataSet(dataSetFolder, newName)
46        String dataSetFolder
47        String newName
48
49        String dataSetFolderParent,basestr,objName
50        Variable index = 0
51
52        //Abuse ParseFilePath to get path without folder name
53        dataSetFolderParent = ParseFilePath(1,dataSetFolder,":",1,0)
54        //Abuse ParseFilePath to get basestr
55        basestr = ParseFilePath(0,dataSetFolder,":",1,0)
56       
57        try
58                DuplicateDataFolder $(dataSetFolder) $(dataSetFolderParent+newName); AbortOnRTE
59
60                SetDataFolder $(dataSetFolderParent+newName); AbortOnRTE
61                do
62                        objName = GetIndexedObjName("",1,index)
63                        if (strlen(objName) == 0)
64                                break
65                        endif
66                        Rename $(objName) $(ReplaceString(basestr,objName,newName))
67                        index+=1
68                while(1)
69                SetDataFolder root:
70        catch
71                Print "Aborted: " + num2str(V_AbortCode)
72                SetDataFolder root:
73        endtry
74End
Note: See TracBrowser for help on using the repository browser.