source: trunk/User Procedures/Irena/IR2_DataExport.ipf @ 1183

Last change on this file since 1183 was 1183, checked in by ilavsky, 7 months ago

Fixes for Export data wavelength user input. Had out of order bug and logic, which was askign for wavelength when not needed. SHould be more logical now.

  • Property svn:executable set to *
File size: 60.3 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=1.19
3Constant IR2EversionNumber = 1.18
4
5//*************************************************************************\
6//* Copyright (c) 2005 - 2022, Argonne National Laboratory
7//* This file is distributed subject to a Software License Agreement found
8//* in the file LICENSE that is included with this distribution.
9//*************************************************************************/
10
11//1.19 fix ASCII export of USAXS data which was exporting incorrect Q data.
12//1.18 added export of all data from current experiment using IR2E_ExportAllAsNexus(), for now sets dQ=0 for DSM data, sets dQl=slit length and dQw to dQ for SMR data.
13//1.17 fixed dQ USAXS data Nexus export which exported always SMR dQ.
14//1.16 add option to export ASCII with d, two theta or Q. Tested against Nika TTH, Q, and D data and works fine within precision errors.
15//1.15 add option to reduce output to single precision output (requested)
16//1.14 fix missign wwavelength if dsata are imported as ASII from Irena and exported again.
17//1.13 fix naming bug for Nexus which caused the names not being changed as needed, when Nexus was used.
18//1.12 fix extensions mess, force extesions, cannot make the old one to be remebered correctly... Too many options.
19//1.11 fix bug that GSAS-II data type was not updating/chaqnging output name as expected.
20//1.10 added export of xye data file for GSAS-II
21//1.09 added getHelp button calling to www manual
22//1.08 changes for panel scaling
23//1.07 fixed multiple data export with QRS
24//1.06 modified GUI to disable Export Data & notes on main panel, when Multiple data selection panel is opened. Confused users. Changeds call to pull up without initialization, if exists.
25//              changed mode for Listbox to enable shift-click selection of range of data, use ctrl/cmd for one-by-one data selection
26//1.05 added in panel version control and added vertical scrolling
27//1.04 fixed Multiple data export which was broken by update to control procedures
28//1.03 fixed QRS data export which was not working due to eventCode missing in structure
29//1.02 removed all font and font size from panel definitions to enable user control
30//1.01 added license for ANL
31 
32
33//This is tool to export any type of 2 - 3 column data we have x, y, and error (if exists)
34
35Function IR2E_UniversalDataExport()
36 
37        //check for panel if exists - pull up, if not create
38        DoWindow UnivDataExportPanel
39        if(V_Flag)
40                DoWindow/F UnivDataExportPanel
41                DoWIndow IR2E_MultipleDataSelectionPnl
42                if(V_Flag)
43                        DoWindow/F IR2E_MultipleDataSelectionPnl
44                endif
45        else
46                //initialize, as usually
47                IR2E_InitUnivDataExport()
48                NVAR ExportMultipleDataSets = root:Packages:IR2_UniversalDataExport:ExportMultipleDataSets
49                ExportMultipleDataSets=0                //do not start in multiple data export, it does not set parameters well... 
50                IR2E_UnivDataExportPanel()
51                ING2_AddScrollControl()
52                IR1_UpdatePanelVersionNumber("UnivDataExportPanel", IR2EversionNumber,1)
53        endif
54 
55end
56//************************************************************************************************************
57//************************************************************************************************************
58//************************************************************************************************************
59//************************************************************************************************************
60
61Function IR2E_MainCheckVersion()       
62        DoWindow UnivDataExportPanel
63        if(V_Flag)
64                if(!IR1_CheckPanelVersionNumber("UnivDataExportPanel", IR2EversionNumber))
65                        DoAlert /T="The ASCII Export panel was created by incorrect version of Irena " 1, "Export ASCII may need to be restarted to work properly. Restart now?"
66                        if(V_flag==1)
67                                KillWindow UnivDataExportPanel
68                                IR2E_UniversalDataExport()
69                        else            //at least reinitialize the variables so we avoid major crashes...
70                                IR2E_InitUnivDataExport()
71                        endif
72                endif
73        endif
74end
75//************************************************************************************************************
76//************************************************************************************************************
77//************************************************************************************************************
78//************************************************************************************************************
79
80Function IR2E_UnivDataExportPanel()
81        //PauseUpdate                   // building window...
82        NewPanel /K=1 /W=(2.25,43.25,390,690) as "Universal data export tool"
83        DoWindow/C UnivDataExportPanel
84       
85        string AllowedIrenaTypes="DSM_Int;M_DSM_Int;SMR_Int;M_SMR_Int;R_Int;"
86        IR2C_AddDataControls("IR2_UniversalDataExport","UnivDataExportPanel",AllowedIrenaTypes,"AllCurrentlyAllowedTypes","","","","", 0,0)
87        CheckBox UseQRSdata proc=IR2E_InputPanelCheckboxProc
88        CheckBox UseIndra2Data proc=IR2E_InputPanelCheckboxProc
89        CheckBox UseResults proc=IR2E_InputPanelCheckboxProc
90        TitleBox MainTitle title="\Zr220Universal data export panel",pos={20,0},frame=0,fstyle=3, fixedSize=1,font= "Times New Roman", size={350,24},anchor=MC,fColor=(0,0,52224)
91        TitleBox FakeLine1 title=" ",fixedSize=1,size={330,3},pos={16,181},frame=0,fColor=(0,0,52224), labelBack=(0,0,52224)
92        TitleBox Info1 title="\Zr160Data input",pos={10,27},frame=0,fstyle=1, fixedSize=1,size={80,20},fColor=(0,0,52224)
93        TitleBox Info2 title="\Zr160Preview Options:",pos={20,190},frame=0,fstyle=2, fixedSize=1,size={150,20},fColor=(0,0,52224)
94        TitleBox Info3 title="\Zr160Output Options:",pos={20,320},frame=0,fstyle=2, fixedSize=0,size={20,15},fColor=(0,0,52224)
95        TitleBox FakeLine1 title=" ",fixedSize=1,size={330,3},pos={16,307},frame=0,fColor=(0,0,52224), labelBack=(0,0,52224)
96
97        CheckBox ExportMultipleDataSets,pos={100,160},size={225,14},proc=IR2E_UnivExpCheckboxProc,title="Export multiple data sets?"
98        CheckBox ExportMultipleDataSets,variable= root:Packages:IR2_UniversalDataExport:ExportMultipleDataSets, help={"When checked the multiple data sets with same data can be exported"}
99
100        Button GetHelp,pos={305,105},size={80,15},fColor=(65535,32768,32768), proc=IR2E_InputPanelButtonProc,title="Get Help", help={"Open www manual page for this tool"}
101        CheckBox GraphDataCheckbox,pos={15,220},size={225,14},noproc,title="Display graph with data?"
102        CheckBox GraphDataCheckbox,variable= root:Packages:IR2_UniversalDataExport:GraphData, help={"When checked the graph displaying data will be displayed"}
103        CheckBox DisplayWaveNote,pos={15,250},size={225,14},noproc,title="Display notes about data?"
104        CheckBox DisplayWaveNote,variable= root:Packages:IR2_UniversalDataExport:DisplayWaveNote, help={"When checked notebook with notes about data history will be displayed"}
105        Button LoadAndGraphData, pos={100,280},size={180,20}, proc=IR2E_InputPanelButtonProc,title="Load data", help={"Load data into the tool, generate graph and display notes if checkboxes are checked."}
106
107        //Nexus or ASCII?
108        CheckBox ExportASCII,pos={10,340},size={190,14},proc=IR2E_UnivExportCheckProc,title="Export ASCII?", mode=1
109        CheckBox ExportASCII,variable= root:Packages:IR2_UniversalDataExport:ExportASCII, help={"When checked ASCII files will be created"}
110        CheckBox ExportGSASxye,pos={130,340},size={190,14},proc=IR2E_UnivExportCheckProc,title="Export GSAS-II xye?", mode=1
111        CheckBox ExportGSASxye,variable= root:Packages:IR2_UniversalDataExport:ExportGSASxye, help={"When checked ASCII files for GSAS-II will be created"}
112        CheckBox ExportCanSASNexus,pos={260,340},size={190,14},proc=IR2E_UnivExportCheckProc,title="Export NEXUS?", mode=1
113        CheckBox ExportCanSASNexus,variable= root:Packages:IR2_UniversalDataExport:ExportCanSASNexus, help={"When checked Nexus (canSAS for data) files will be created"}
114       
115        CheckBox ExportSingleCanSASFile,pos={15,360},size={190,14},proc=IR2E_UnivExportCheckProc,title="Export Single canSAS NEXUS (with multiple data)?"
116        CheckBox ExportSingleCanSASFile,variable= root:Packages:IR2_UniversalDataExport:ExportSingleCanSASFile, help={"When checked Nexus (canSAS for data) files will be created"}
117
118        CheckBox ASCIIExportQ,pos={10,360},size={190,14},proc=IR2E_UnivExportCheckProc,title="Use Q?", mode=1
119        CheckBox ASCIIExportQ,variable= root:Packages:IR2_UniversalDataExport:ASCIIExportQ, help={"When checked ASCII files will be exported with Q"}
120        CheckBox ASCIIExportD,pos={130,360},size={190,14},proc=IR2E_UnivExportCheckProc,title="Use d?", mode=1
121        CheckBox ASCIIExportD,variable= root:Packages:IR2_UniversalDataExport:ASCIIExportD, help={"When checked ASCII files will be exported with d"}
122        CheckBox ASCIIExportTTH,pos={260,360},size={190,14},proc=IR2E_UnivExportCheckProc,title="Use Two Theta?", mode=1
123        CheckBox ASCIIExportTTH,variable= root:Packages:IR2_UniversalDataExport:ASCIIExportTTH, help={"When checked  ASCII files will be created with two theta"}
124
125       
126        CheckBox AttachWaveNote,pos={10,378},size={190,14},noproc,title="Attach notes about data?"
127        CheckBox AttachWaveNote,variable= root:Packages:IR2_UniversalDataExport:AttachWaveNote, help={"When checked block of text with notes about data history will be attached before the data itself"}
128        CheckBox reduceOutputPrecision,pos={220,378},size={190,14},noproc,title="Reduce precision?"
129        CheckBox reduceOutputPrecision,variable= root:Packages:IR2_UniversalDataExport:reduceOutputPrecision, help={"When checked, data are converted to single precision (default is double precision)"}
130
131
132        CheckBox UseFolderNameForOutput,pos={10,395},size={190,14},proc=IR2E_UnivExportCheckProc,title="Use Sample/Fldr name for output?"
133        CheckBox UseFolderNameForOutput,variable= root:Packages:IR2_UniversalDataExport:UseFolderNameForOutput, help={"Use Folder name for output file name"}
134        CheckBox UseYWaveNameForOutput,pos={220,395},size={190,14},proc=IR2E_UnivExportCheckProc,title="Use Ywv name for output?"
135        CheckBox UseYWaveNameForOutput,variable= root:Packages:IR2_UniversalDataExport:UseYWaveNameForOutput, help={"Use Y wave name for output file name"}
136
137
138        SetVariable CurrentlyLoadedDataName,limits={0,Inf,0},value= root:Packages:IR2_UniversalDataExport:CurrentlyLoadedDataName, noedit=1,noProc,frame=0
139        SetVariable CurrentlyLoadedDataName,pos={3,420},size={385,25},title="Loaded data:", help={"This is data set currently loaded in the tool. These data will be saved."},fstyle=1,labelBack=(65280,21760,0)
140
141        SetVariable CurrentlySetOutputPath,limits={0,Inf,0},value= root:Packages:IR2_UniversalDataExport:CurrentlySetOutputPath, noedit=1,noProc,frame=0
142        SetVariable CurrentlySetOutputPath,pos={3,455},size={370,25},title="Export Folder:", help={"This is data folder outside Igor  where the data will be saved."},fstyle=0
143        Button ExportOutputPath, pos={100,480},size={180,20}, proc=IR2E_InputPanelButtonProc,title="Set export folder:", help={"Select export folder where to save new ASCII data sets."}
144//      Button ExportNexusFile, pos={100,492},size={180,20}, proc=IR2E_InputPanelButtonProc,title="Create/Find Nexus Output file", help={"Create output Nexus file name in above location."}
145
146        SetVariable NewFileOutputName,limits={0,Inf,0},value= root:Packages:IR2_UniversalDataExport:NewFileOutputName,noProc,frame=1
147        SetVariable NewFileOutputName,pos={3,520},size={370,25},title="Export file name:", help={"This is name for new data file which will be created"},fstyle=1
148        SetVariable OutputNameExtension,limits={0,Inf,0},value= root:Packages:IR2_UniversalDataExport:OutputNameExtension,noProc,frame=1
149        SetVariable OutputNameExtension,pos={3,540},size={200,25},title="Export file extension:", help={"This is extension for new data file which will be created"},fstyle=1
150        SetVariable HeaderSeparator,limits={0,Inf,0},value= root:Packages:IR2_UniversalDataExport:HeaderSeparator,proc=IR2E_UnivExportToolSetVarProc,frame=1
151        SetVariable HeaderSeparator,pos={3,560},size={180,25},title="Header separator:", help={"This is symnol at the start of header line. Include here spaces if you want them..."},fstyle=1
152//
153        Button ExportData, pos={100,600},size={180,20}, proc=IR2E_InputPanelButtonProc,title="Export Data & Notes", help={"Save ASCII file with data and notes for these data"}
154        IR2E_FixMainGUI()
155end
156//*******************************************************************************************************************************
157//this is override or IR2C procedure so it also updates GUI...
158Function IR2E_InputPanelCheckboxProc(CB_Struct)
159        STRUCT WMCheckboxAction &CB_Struct
160
161        IR2C_InputPanelCheckboxProc(CB_Struct)
162        IR2E_FixMainGUI()
163end
164
165//*******************************************************************************************************************************
166Function IR2E_FixMainGUI()
167       
168        DoWIndow UnivDataExportPanel
169        if(V_Flag)
170                NVAR MultipleData=root:Packages:IR2_UniversalDataExport:ExportMultipleDataSets
171                NVAR ExportCanSASNexus = root:Packages:IR2_UniversalDataExport:ExportCanSASNexus
172                NVAR ExportASCII = root:Packages:IR2_UniversalDataExport:ExportASCII
173                NVAR ExportGSASxye = root:Packages:IR2_UniversalDataExport:ExportGSASxye
174                NVAR ExportSingleCanSASFile = root:Packages:IR2_UniversalDataExport:ExportSingleCanSASFile
175                NVAR UseIndra2Data = root:Packages:IR2_UniversalDataExport:UseIndra2Data
176                NVAR UseQRSdata = root:Packages:IR2_UniversalDataExport:UseQRSdata
177                NVAR UseResults = root:Packages:IR2_UniversalDataExport:UseResults
178
179                Button ExportData, win=UnivDataExportPanel, disable=2*MultipleData
180                CheckBox AttachWaveNote,win=UnivDataExportPanel, disable=(ExportCanSASNexus || ExportGSASxye)
181                SetVariable HeaderSeparator, win=UnivDataExportPanel, disable=!(ExportASCII)
182                CheckBox UseYWaveNameForOutput, win=UnivDataExportPanel, disable=(ExportCanSASNexus&&ExportSingleCanSASFile)
183                CheckBox UseFolderNameForOutput, win=UnivDataExportPanel, disable=(ExportCanSASNexus&&ExportSingleCanSASFile)
184                CheckBox ExportSingleCanSASFile, win=UnivDataExportPanel, disable=(ExportASCII || ExportGSASxye)
185                CheckBox reduceOutputPrecision, win=UnivDataExportPanel, disable=(ExportCanSASNexus || ExportGSASxye)
186                CheckBox ASCIIExportQ, win=UnivDataExportPanel, disable=!(ExportASCII&&(UseIndra2Data||UseQRSdata))
187                CheckBox ASCIIExportD, win=UnivDataExportPanel, disable=!(ExportASCII&&(UseIndra2Data||UseQRSdata))
188                CheckBox ASCIIExportTTH, win=UnivDataExportPanel, disable=!(ExportASCII&&(UseIndra2Data||UseQRSdata))
189        endif
190end
191
192//*******************************************************************************************************************************
193//*******************************************************************************************************************************
194//*******************************************************************************************************************************
195Function IR2E_UnivExpCheckboxProc(CB_Struct)
196        STRUCT WMCheckboxAction &CB_Struct
197
198//      DoAlert 0,"Fix IR2E_UnivExpCheckboxProc"
199        if(CB_Struct.EventCode==2)
200                if(stringMatch(CB_Struct.ctrlName,"ExportMultipleDataSets"))
201                        if(CB_Struct.checked)
202       
203                                IR2E_UpdateListOfAvailFiles()
204                                DoWindow IR2E_MultipleDataSelectionPnl
205                                if(!V_Flag)                             
206                                        NewPanel/K=1 /W=(400,44,800,355) as "Multiple Data Export selection"
207                                        DoWIndow/C IR2E_MultipleDataSelectionPnl
208                                        SetDrawLayer UserBack
209                                        SetDrawEnv fsize= 20,fstyle= 1,textrgb= (0,0,65535)
210                                        DrawText 29,29,"Multiple Data Export selection"
211                                        DrawText 10,255,"Configure Universal export tool panel options"
212                                        DrawText 10,275,"Select multiple data above and export : "
213                                        ListBox DataFolderSelection,pos={4,35},size={372,200}, mode=10, special={0,0,1 }                //this will scale the width of column, users may need to slide right using slider at the bottom.
214                                        ListBox DataFolderSelection,listWave=root:Packages:IR2_UniversalDataExport:ListOfAvailableData
215                                        ListBox DataFolderSelection,selWave=root:Packages:IR2_UniversalDataExport:SelectionOfAvailableData
216       
217                                        Button UpdateData,pos={280,245},size={100,15},proc=IR2E_ButtonProc,title="Update list"
218                                        Button UpdateData,fSize=10,fStyle=2
219                                       
220                                        Button AllData,pos={4,285},size={100,15},proc=IR2E_ButtonProc,title="Select all data"
221                                        Button AllData,fSize=10,fStyle=2
222                                        Button NoData,pos={120,285},size={100,15},proc=IR2E_ButtonProc,title="DeSelect all data"
223                                        Button NoData,fSize=10,fStyle=2
224                                        Button ProcessAllData,pos={240,285},size={150,15},proc=IR2E_ButtonProc,title="Export selected data"
225                                        Button ProcessAllData,fSize=10,fStyle=2
226                                        Button ProcessAllData fColor=(65535,16385,16385)
227                                else
228                               
229                                        DoWindow/F IR2E_MultipleDataSelectionPnl
230                                       
231                                endif
232                                AutoPositionWindow/M=0 /R=UnivDataExportPanel IR2E_MultipleDataSelectionPnl
233                        else
234                                KillWIndow/Z IR2E_MultipleDataSelectionPnl
235                        endif
236                endif           //end of ExportMultipleDataSets
237
238        endif
239        IR2E_FixMainGUI()
240End
241//**************************************************************************************
242//**************************************************************************************
243//**************************************************************************************
244//**************************************************************************************
245//**************************************************************************************
246
247
248
249Function IR2E_ButtonProc(ctrlName) : ButtonControl
250        String ctrlName
251
252                wave SelectionOfAvailableData=root:Packages:IR2_UniversalDataExport:SelectionOfAvailableData
253        if(stringmatch(ctrlName,"AllData"))
254                SelectionOfAvailableData=1
255        endif
256        if(stringmatch(ctrlName,"NoData"))
257                SelectionOfAvailableData=0
258        endif
259        if(stringmatch(ctrlName,"UpdateData"))
260                IR2E_UpdateListOfAvailFiles()
261        endif
262        if(stringmatch(ctrlName,"ProcessAllData"))
263                IR2E_ExportMultipleFiles()
264                print "Export of all data is DONE!"
265        endif
266       
267       
268End
269
270//**************************************************************************************
271//**************************************************************************************
272//**************************************************************************************
273Function IR2E_ExportMultipleFiles()
274
275        DFref oldDf= GetDataFolderDFR()
276
277        setDataFolder root:Packages:IR2_UniversalDataExport
278
279        NVAR UseQRSdata=root:Packages:IR2_UniversalDataExport:UseQRSData
280        SVAR DataFolderName = root:Packages:IR2_UniversalDataExport:DataFolderName
281        SVAR IntensityWaveName=root:Packages:IR2_UniversalDataExport:IntensityWaveName
282        SVAR QWavename=root:Packages:IR2_UniversalDataExport:QWavename
283        SVAR ErrorWaveName=root:Packages:IR2_UniversalDataExport:ErrorWaveName
284        string StartFolderName = RemoveFromList(stringFromList(ItemsInList(DataFolderName , ":")-1,DataFolderName,":"), DataFolderName  , ":")
285
286        Wave/T ListOfAvailableData=root:Packages:IR2_UniversalDataExport:ListOfAvailableData
287        Wave SelectionOfAvailableData=root:Packages:IR2_UniversalDataExport:SelectionOfAvailableData
288
289        variable i
290       
291        For(i=0;i<numpnts(ListOfAvailableData);i+=1)
292                if(!UseQRSdata)         //just stuff in Folder name and go ahead...
293                        if(SelectionOfAvailableData[i])
294                                DataFolderName = StartFolderName+ListOfAvailableData[i]
295                                if(!DataFolderExists(DataFolderName ))
296                                        Abort "Problem with data folder definition. Please \"Update list\" and try again"
297                                endif
298                                IR2E_LoadDataInTool()           
299                                DoUpdate
300                                sleep/S 1       
301                                IR2E_ExportTheData()
302                        endif
303                else    //we need to set all strings for qrs data...
304                        if(SelectionOfAvailableData[i])
305                                DataFolderName = StartFolderName+ListOfAvailableData[i]
306                                if(!DataFolderExists(DataFolderName ))
307                                        Abort "Problem with data folder definition. Please \"Update list\" and try again"
308                                endif
309                                //now for qrs we need to reload the other wave names...
310                                STRUCT WMPopupAction PU_Struct
311                                PU_Struct.ctrlName = "SelectDataFolder"
312                                PU_Struct.popNum=-1
313                                PU_Struct.eventCode=2
314                                PU_Struct.popStr=DataFolderName
315                                PU_Struct.win = "UnivDataExportPanel"
316                                //PopupMenu SelectDataFolder win=UnivDataExportPanel, popmatch=DataFolderName
317                                PopupMenu SelectDataFolder win=UnivDataExportPanel, popmatch=StringFromList(ItemsInList(DataFolderName,":")-1,DataFolderName,":")
318                                IR2C_PanelPopupControl(PU_Struct)
319                                IR2E_LoadDataInTool()           
320                                DoUpdate
321                                sleep/S 1       
322                                IR2E_ExportTheData()
323                        endif
324                endif
325       
326        endfor
327       
328
329        setDataFolder OldDF
330end
331//*******************************************************************************************************************************
332//*******************************************************************************************************************************
333//*******************************************************************************************************************************
334//*******************************************************************************************************************************
335//*******************************************************************************************************************************
336
337Function IR2E_UpdateListOfAvailFiles()
338
339        DFref oldDf= GetDataFolderDFR()
340
341        setDataFolder root:Packages:IR2_UniversalDataExport
342       
343        NVAR UseIndra2Data=root:Packages:IR2_UniversalDataExport:UseIndra2Data
344        NVAR UseQRSdata=root:Packages:IR2_UniversalDataExport:UseQRSData
345        NVAR UseResults = root:Packages:IR2_UniversalDataExport:UseResults
346        NVAR UseSMRData = root:Packages:IR2_UniversalDataExport:UseSMRData
347//      SVAR StartFolderName=root:Packages:IR2_UniversalDataExport:StartFolderName
348        SVAR DataFolderName = root:Packages:IR2_UniversalDataExport:DataFolderName
349        string StartFolderName = RemoveFromList(stringFromList(ItemsInList(DataFolderName , ":")-1,DataFolderName,":"), DataFolderName  , ":")
350        SVAR IntensityWaveName=root:Packages:IR2_UniversalDataExport:IntensityWaveName
351       
352        //string CurrentFolders=IR2S_GenStringOfFolders(StartFolderName,UseIndra2Data, UseQRSData,UseSMRData,1)
353        string CurrentFolders
354        IR2P_GenStringOfFolders(winNm="UnivDataExportPanel")
355        SVAR RealLongListOfFolder = root:Packages:IR2_UniversalDataExport:RealLongListOfFolder          //after 2/2013 update this is where the list is.
356        CurrentFolders = RealLongListOfFolder
357        //these are all folders with data... Now we need to check for results of different type... And clean up those which are not in the same subfolder...
358        variable i, j
359        string TempStr
360        For(i=ItemsInList(CurrentFolders , ";")-1;i>=0;i-=1)                    //cleanup from other start folders...
361                TempStr =  StringFromList(i, CurrentFolders , ";")
362                if(!stringmatch(TempStr, StartFolderName+"*" ))
363                        CurrentFolders = RemoveListItem(i, CurrentFolders , ";")
364                endif
365        endfor 
366        //now cleanup from different wave names... Valid only for Indra 2 data and results, not qrs data...
367        if(UseIndra2Data || UseResults)
368                For(i=ItemsInList(CurrentFolders , ";")-1;i>=0;i-=1)                    //cleanup from other start folders...
369                        TempStr =  StringFromList(i, CurrentFolders , ";")
370                        if(UseIndra2Data)               //check for Indra 2 data of the right kind...
371                                if(!stringmatch(IN2G_CreateListOfItemsInFolder(TempStr,2), "*"+IntensityWaveName+"*" ))
372                                        CurrentFolders = RemoveListItem(i, CurrentFolders , ";")
373                                endif
374                        else            //results... May need to modify later, this will manage only same generation results...
375                                if(!stringmatch(IN2G_CreateListOfItemsInFolder(TempStr,2), "*"+IntensityWaveName+"*" ))
376                                        CurrentFolders = RemoveListItem(i, CurrentFolders , ";")
377                                endif
378                        endif
379                endfor 
380               
381        endif
382       
383        Wave/T ListOfAvailableData=root:Packages:IR2_UniversalDataExport:ListOfAvailableData
384        Wave SelectionOfAvailableData=root:Packages:IR2_UniversalDataExport:SelectionOfAvailableData
385               
386        Redimension/N=(ItemsInList(CurrentFolders , ";")) ListOfAvailableData
387        j=0
388        For(i=0;i<ItemsInList(CurrentFolders , ";");i+=1)
389                TempStr = ReplaceString(StartFolderName, StringFromList(i, CurrentFolders , ";"),"")
390                if(strlen(TempStr)>0)
391                        ListOfAvailableData[j] = tempStr
392                        j+=1
393                endif
394        endfor
395        Redimension/N=(Numpnts(ListOfAvailableData))  SelectionOfAvailableData
396        SelectionOfAvailableData = 0
397        setDataFolder OldDF
398end
399
400//*******************************************************************************************************************************
401//*******************************************************************************************************************************
402//*******************************************************************************************************************************
403//*******************************************************************************************************************************
404//*******************************************************************************************************************************
405
406Function IR2E_UnivExportToolSetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl
407        String ctrlName
408        Variable varNum
409        String varStr
410        String varName
411       
412        if(cmpstr(ctrlName,"HeaderSeparator")==0)
413                DoWindow ExportNoteDisplay
414                if(V_Flag)
415                        KillWIndow/Z ExportNoteDisplay
416                else
417                        abort
418                endif
419
420                DFref oldDf= GetDataFolderDFR()
421
422                setDataFolder root:Packages:IR2_UniversalDataExport
423
424                NVAR AttachWaveNote
425                NVAR DisplayWaveNote
426                NVAR UseFolderNameForOutput
427                NVAR UseYWaveNameForOutput
428
429                SVAR DataFolderName
430                SVAR IntensityWaveName
431                SVAR QWavename
432                SVAR ErrorWaveName
433                SVAR CurrentlyLoadedDataName
434                SVAR CurrentlySetOutputPath
435                SVAR NewFileOutputName
436                SVAR HeaderSeparator
437               
438               
439                Wave/Z tempY=$(DataFolderName+possiblyQUoteName(IntensityWaveName))
440                if(!WaveExists(tempY))
441                        setDataFolder OldDf
442                        abort
443                endif   
444                string OldNote
445                String nb = "ExportNoteDisplay"
446                variable i
447                if(DisplayWaveNote)
448                        OldNote = note(TempY) +"Exported="+date()+" "+time()+";"
449                        NewNotebook/K=1/N=$nb/F=0/V=1/K=0/W=(300,270,700,530) as "Data Notes"
450                        Notebook $nb defaultTab=20, statusWidth=238, pageMargins={72,72,72,72}
451                        Notebook $nb font="Arial", fStyle=0, textRGB=(0,0,0)
452                        For(i=0;i<ItemsInList(OldNOte);i+=1)
453                                Notebook $nb text=HeaderSeparator + stringFromList(i,OldNote)+"\r"
454                        endfor
455                endif
456                setDataFolder OldDf
457        endif
458
459End
460
461//*******************************************************************************************************************************
462//*******************************************************************************************************************************
463//*******************************************************************************************************************************
464//*******************************************************************************************************************************
465//*******************************************************************************************************************************
466
467Function IR2E_UnivExportCheckProc(ctrlName,checked) : CheckBoxControl
468        String ctrlName
469        Variable checked
470       
471        DFref oldDf= GetDataFolderDFR()
472
473        setDataFolder root:Packages:IR2_UniversalDataExport
474       
475        NVAR UseFolderNameForOutput
476        NVAR UseYWaveNameForOutput
477
478        SVAR DataFolderName
479        SVAR IntensityWaveName
480        SVAR QWavename
481        SVAR ErrorWaveName
482        SVAR CurrentlyLoadedDataName
483        SVAR CurrentlySetOutputPath
484        SVAR NewFileOutputName
485        NVAR ExportCanSASNexus = root:Packages:IR2_UniversalDataExport:ExportCanSASNexus
486        NVAR ExportASCII = root:Packages:IR2_UniversalDataExport:ExportASCII
487        NVAR ExportGSASxye = root:Packages:IR2_UniversalDataExport:ExportGSASxye
488        NVAR ASCIIExportQ = root:Packages:IR2_UniversalDataExport:ASCIIExportQ
489        NVAR ASCIIExportD = root:Packages:IR2_UniversalDataExport:ASCIIExportD
490        NVAR ASCIIExportTTH = root:Packages:IR2_UniversalDataExport:ASCIIExportTTH
491                       
492                SVAR OutputNameExtension = root:Packages:IR2_UniversalDataExport:OutputNameExtension
493                if(stringMatch(ctrlName,"ASCIIExportQ"))
494                        if(checked)
495                                ASCIIExportQ = 1
496                                ASCIIExportD = 0
497                                ASCIIExportTTH = 0
498                        endif
499                endif
500                if(stringMatch(ctrlName,"ASCIIExportD"))
501                        if(checked)
502                                ASCIIExportQ = 0
503                                ASCIIExportD = 1
504                                ASCIIExportTTH = 0
505                        endif
506                endif
507                if(stringMatch(ctrlName,"ASCIIExportTTH"))
508                        if(checked)
509                                ASCIIExportQ = 0
510                                ASCIIExportD = 0
511                                ASCIIExportTTH = 1
512                        endif
513                endif
514
515
516                if(stringMatch(ctrlName,"ExportASCII"))
517                        if(checked)
518                                ExportASCII = 1
519                                ExportCanSASNexus = 0
520                                ExportGSASxye = 0
521                                OutputNameExtension  = "dat"
522                        endif
523                endif
524                if(stringMatch(ctrlName,"ExportGSASxye"))
525                        if(checked)
526                                ExportGSASxye = 1
527                                ExportASCII = 0
528                                ExportCanSASNexus = 0
529                                OutputNameExtension  = "xye"
530                        endif
531                endif
532                if(stringMatch(ctrlName,"ExportCanSASNexus"))
533                        if(checked)
534                                ExportGSASxye =0
535                                ExportASCII = 0
536                                ExportCanSASNexus = 1
537                                OutputNameExtension  = "h5"
538                        endif
539                        if(ExportCanSASNexus)
540                                DoAlert /T="NXcanSAS Warning for slit smeared data" 0, "At this time NO software has been verified to be able to use slit smeared data. Export ONLY desmeared USAXS data, please."
541                        endif
542                endif
543                NVAR UseFolderNameForOutput = root:Packages:IR2_UniversalDataExport:UseFolderNameForOutput
544                NVAR UseYWaveNameForOutput = root:Packages:IR2_UniversalDataExport:UseYWaveNameForOutput
545                if(stringMatch(ctrlName,"UseFolderNameForOutput"))
546                        if(checked)
547                                UseFolderNameForOutput = 1
548                                UseYWaveNameForOutput = 0
549                        else
550                                UseFolderNameForOutput = 0
551                                UseYWaveNameForOutput = 1
552                        endif
553                endif
554                if(stringMatch(ctrlName,"UseYWaveNameForOutput"))
555                        if(checked)
556                                UseFolderNameForOutput = 0
557                                UseYWaveNameForOutput = 1
558                        else
559                                UseFolderNameForOutput = 1
560                                UseYWaveNameForOutput = 0
561                        endif
562                endif
563        if(cmpstr(ctrlName,"UseFolderNameForOutput")==0 || cmpstr(ctrlName,"UseYWaveNameForOutput")==0)
564               
565                NewFileOutputName = ""
566                if(UseFolderNameForOutput)
567                        NewFileOutputName += IN2G_RemoveExtraQuote(StringFromList(ItemsInList(DataFolderName,":")-1,DataFolderName,":"),1,1)
568                endif
569                if(UseFolderNameForOutput && UseYWaveNameForOutput)
570                        NewFileOutputName += "_"
571                endif
572                if(UseYWaveNameForOutput)
573                        NewFileOutputName += IN2G_RemoveExtraQuote(IntensityWaveName,1,1)
574                endif   
575               
576        endif
577        nVAR ExportSingleCanSASFile = root:Packages:IR2_UniversalDataExport:ExportSingleCanSASFile
578        if(stringMatch(ctrlName,"ExportSingleCanSASFile"))
579                if(checked)
580                        ExportSingleCanSASFile=1
581                        DoALert 0, "Type in \"Export file name\" name of file. Make sure it is acceptable name for the OS. "
582                else
583                        ExportSingleCanSASFile=0
584                endif
585        endif
586       
587       
588
589        IR2E_FixMainGUI()
590        setDataFolder OldDf
591End
592
593//*******************************************************************************************************************************
594//*******************************************************************************************************************************
595//*******************************************************************************************************************************
596//*******************************************************************************************************************************
597//*******************************************************************************************************************************
598
599Function IR2E_InputPanelButtonProc(ctrlName) : ButtonControl
600        String ctrlName
601
602        DFref oldDf= GetDataFolderDFR()
603
604        setDataFolder root:Packages:IR2_UniversalDataExport
605        if(cmpstr(ctrlName,"LoadAndGraphData")==0)
606                //here we load the data and create default values
607                IR2E_LoadDataInTool()
608        endif
609        if(cmpstr(ctrlName,"ExportOutputPath")==0)
610                //here we set output path and patch it in the string to be seen by user
611                IR2E_ChangeExportPath()
612        endif
613        if(cmpstr(ctrlName,"ExportData")==0)
614                //here we do whatever is apropriate...
615                IR2E_ExportTheData()
616        endif
617        if(cmpstr(ctrlName,"GetHelp")==0)
618                //Open www manual with the right page
619                IN2G_OpenWebManual("Irena/ExportData.html")
620        endif
621       
622        setDataFolder oldDF
623end
624//*******************************************************************************************************************************
625//*******************************************************************************************************************************
626//*******************************************************************************************************************************
627//*******************************************************************************************************************************
628//*******************************************************************************************************************************
629
630Function IR2E_ExportTheData()
631
632        DFref oldDf= GetDataFolderDFR()
633
634        setDataFolder root:Packages:IR2_UniversalDataExport
635
636        NVAR AttachWaveNote
637        NVAR GraphData
638        NVAR DisplayWaveNote
639        NVAR UseFolderNameForOutput
640        NVAR UseYWaveNameForOutput
641        NVAR reduceOutputPrecision
642
643        SVAR DataFolderName
644        SVAR IntensityWaveName
645        SVAR QWavename
646        SVAR ErrorWaveName
647        SVAR CurrentlyLoadedDataName
648        SVAR CurrentlySetOutputPath
649        SVAR NewFileOutputName
650        SVAR OutputNameExtension
651        SVAR HeaderSeparator
652       
653        string UserSampleName=IN2G_ReturnUserSampleName(DataFolderName)
654
655        NVAR ExportCanSASNexus
656        NVAR ExportASCII
657        NVAR ExportGSASxye
658        NVAR ExportMultipleCanSASFiles
659        NVAR ExportSingleCanSASFile
660
661        NVAR UseIndra2Data=root:Packages:IR2_UniversalDataExport:UseIndra2Data
662        NVAR UseQRSdata=root:Packages:IR2_UniversalDataExport:UseQRSdata
663        NVAR UseResults=root:Packages:IR2_UniversalDataExport:UseResults
664        NVAR UseSMRData=root:Packages:IR2_UniversalDataExport:UseSMRData
665
666        NVAR ASCIIExportQ=root:Packages:IR2_UniversalDataExport:ASCIIExportQ
667        NVAR ASCIIExportD=root:Packages:IR2_UniversalDataExport:ASCIIExportD
668        NVAR ASCIIExportTTH=root:Packages:IR2_UniversalDataExport:ASCIIExportTTH
669
670       
671        Wave/Z TempY=$(DataFolderName+possiblyquoteName(IntensityWaveName))
672        Wave/Z TempX=$(DataFolderName+possiblyquoteName(QWavename))
673        Wave/Z TempE=$(DataFolderName+possiblyquoteName(ErrorWaveName))
674        if(!WaveExists(TempE))
675                Duplicate/Free TempX, TempE
676                TempE = 0
677        endif
678        if(UseIndra2Data)
679                Wave/Z TempdX=$(DataFolderName+ReplaceString("Qvec", QWavename, "dQ"))
680        elseif(UseQRSdata)
681                Wave/Z TempdX=$(DataFolderName+possiblyquoteName(ReplaceString("s_", ErrorWaveName, "w_", 0,1)))
682        else
683                //no such thing for other options
684        endif
685        if(!WaveExists(TempdX))
686                Duplicate/Free TempE, tempdX
687                tempdX = 0
688        endif
689
690        if(!WaveExists(TempY) && !WaveExists(TempX))
691                abort
692        endif
693        variable HaveErrors=0
694        if(WaveExists(TempE))
695                HaveErrors=1
696        endif
697
698        if(strlen(NewFileOutputName)==0)
699                abort "Create output file name first, please"
700        endif
701        variable refnum
702        string FinalOutputName, oldNote, OldNoteT1
703        variable wvlgth
704       
705       
706        if(ExportASCII)                 //this is old ASCII method...
707                //Check for existing file and manage on our own...
708                FinalOutputName=NewFileOutputName
709                if(strlen(OutputNameExtension)>0)
710                        FinalOutputName+="."+OutputNameExtension
711                endif
712       
713                Open/Z=1 /R/P=IR2E_ExportPath refnum as FinalOutputName
714                if(V_Flag==0)
715                        DoAlert 1, "The file with this name: "+FinalOutputName+ " in this location already exists, overwrite?"
716                        if(V_Flag!=1)
717                                abort
718                        endif
719                        close/A
720                        //user wants to delete the file
721                        OpenNotebook/V=0/P=IR2E_ExportPath/N=JunkNbk  FinalOutputName
722                        DoWindow/D /K JunkNbk
723                endif
724                close/A
725                Duplicate/O TempY, NoteTempY
726                string OldNoteT=note(TempY)
727                //      wvlgth = NumberByKey("Nika_Wavelength", OldNoteT1 , "=", ";")
728                //      if(numtype(wvlgth)!=0)
729                //              wvlgth = NumberByKey("Wavelength", OldNoteT1 , "=", ";")
730                //              if(numtype(wvlgth)!=0)
731                //                      Prompt wvlgth, "Wavelength not found, please, provide"
732                //                      DoPrompt "Provide wavelength is A", wvlgth
733                //                      if (V_Flag || numtype(wvlgth)!=0 || wvlgth<0.01)
734                //                              return -1                                                               // User canceled
735                //                      endif   
736                //              endif
737                //      endif
738
739                note/K NoteTempY
740                note NoteTempY, OldNoteT+"Exported="+date()+" "+time()+";"
741                make/T/O WaveNoteWave
742                if (AttachWaveNote ||(ASCIIExportTTH&&(UseIndra2Data || UseQRSdata)))
743                        IN2G_PasteWnoteToWave("NoteTempY", WaveNoteWave,HeaderSeparator)
744                        Save/G/M="\r\n"/P=IR2E_ExportPath WaveNoteWave as FinalOutputName
745                endif
746                if( UseIndra2Data || UseQRSdata)        //scattering data
747                        //lower precision if needed
748                        Duplicate/O TempY,Intensity
749                        if(HaveErrors)
750                                Duplicate/O TempE, Uncertainty
751                        endif
752
753                        OldNoteT1=note(Intensity)
754
755                        //convert q tth or d into what is asked for...
756                        Duplicate/Free tempX, TempXConverted
757                        if(ASCIIExportQ)                //user wants Q
758                                if(StringMatch(QWavename, "q_*") || StringMatch(QWavename, "'q_*")||StringMatch(QWavename, "*_Qvec"))           //q wave
759                                        TempXConverted = tempX
760                                elseif(StringMatch(QWavename, "d_*") || StringMatch(QWavename, "'d_*"))         //d wave
761                                        //q = 2pi/d
762                                        TempXConverted = 2*pi / TempX
763                                else            //Two theta wave, convert to Q
764                                        //q = 4pi sin(theta)/lambda
765                                        wvlgth = IR2E_GetWavelength(OldNoteT1)
766                                        TempXConverted = 4*pi*sin(TempX/(2 * 180/pi)) / wvlgth
767                                endif
768                                Duplicate/O TempXConverted,Qvector_A
769                                //reduce precision here...
770                                if(reduceOutputPrecision)
771                                        Redimension/S Qvector_A,Intensity
772                                        if(HaveErrors)
773                                                Redimension/S Uncertainty
774                                        endif
775                                endif
776
777                                if(HaveErrors)
778                                        Save/A=2/G/W/M="\r\n"/P=IR2E_ExportPath Qvector_A,Intensity,Uncertainty as FinalOutputName                     
779                                else
780                                        Save/A=2/G/W/M="\r\n"/P=IR2E_ExportPath Qvector_A,Intensity as FinalOutputName         
781                                endif
782                        elseif(ASCIIExportD)            //user wants d
783                                if(StringMatch(QWavename, "q_*") || StringMatch(QWavename, "'q_*")||StringMatch(QWavename, "*_Qvec"))           //q wave
784                                        //d = 2pi/q
785                                        TempXConverted = 2*pi / TempX
786                                elseif(StringMatch(QWavename, "d_*") || StringMatch(QWavename, "'d_*"))         //d wave
787                                        TempXConverted = tempX
788                                else            //Two theta wave, convert to d
789                                        //q = 4pi sin(theta)/lambda
790                                        //d = 2*pi/Q : 2pi/(4pi*sin(theta)/lambda)
791                                        //TTH = 114.592 * asin((2*pi/D) * wvlgth /(4*pi))       
792                                        //D = 2*pi/(4*pi)*sin(TTH/114.592)/wvlgth 
793                                        wvlgth = IR2E_GetWavelength(OldNoteT1)
794                                        TempXConverted = 1/(2*sin(TempX/(2 * 180/pi))/ wvlgth)
795                                endif
796                                Duplicate/O TempXConverted,Dspacing_A
797                                //reduce precision here...
798                                if(reduceOutputPrecision)
799                                        Redimension/S Dspacing_A,Intensity
800                                        if(HaveErrors)
801                                                Redimension/S Uncertainty
802                                        endif
803                                endif
804                                if(HaveErrors)
805                                        Save/A=2/G/W/M="\r\n"/P=IR2E_ExportPath Dspacing_A,Intensity,Uncertainty as FinalOutputName                     
806                                else
807                                        Save/A=2/G/W/M="\r\n"/P=IR2E_ExportPath Dspacing_A,Intensity as FinalOutputName         
808                                endif
809                        elseif(ASCIIExportTTH)  //user wants Two Theta
810                                if(StringMatch(QWavename, "q_*") || StringMatch(QWavename, "'q_*")||StringMatch(QWavename, "*_Qvec"))           //q wave
811                                        //TwoTheta = 2* asin(q * lambda /4pi)
812                                        wvlgth = IR2E_GetWavelength(OldNoteT1)
813                                        TempXCOnverted = 114.592 * asin(TempX * wvlgth /(4*pi))         
814                                elseif(StringMatch(QWavename, "d_*") || StringMatch(QWavename, "'d_*"))         //d wave
815                                        //TwoTheta = 2* asin(q * lambda /4pi), Q = 2*pi/D
816                                        wvlgth = IR2E_GetWavelength(OldNoteT1)
817                                        TempXCOnverted = 114.592 * asin((2*pi/TempX) * wvlgth /(4*pi))         
818                                else            //Two theta wave, convert to d
819                                        TempXConverted = tempX
820                                endif
821                                Duplicate/O TempXConverted,TwoTheta_Deg
822                                //reduce precision here...
823                                if(reduceOutputPrecision)
824                                        Redimension/S TwoTheta_Deg,Intensity
825                                        if(HaveErrors)
826                                                Redimension/S Uncertainty
827                                        endif
828                                endif
829                                if(HaveErrors)
830                                        Save/A=2/G/W/M="\r\n"/P=IR2E_ExportPath TwoTheta_Deg,Intensity,Uncertainty as FinalOutputName                   
831                                else
832                                        Save/A=2/G/W/M="\r\n"/P=IR2E_ExportPath TwoTheta_Deg,Intensity as FinalOutputName               
833                                endif
834                        endif   
835                        KillWaves/Z WaveNoteWave, NoteTempY, Qvector_A,Intensity,Uncertainty, Dspacing_A, TwoTheta_Deg
836                else            //results or other, no idea what x, y, e is...
837                        //lower precision if needed
838                        Duplicate/O TempX,Xdata
839                        Duplicate/O TempY,Ydata
840                        if(HaveErrors)
841                                Duplicate/O TempE, Uncertainty
842                        endif
843                        if(reduceOutputPrecision)
844                                Redimension/S Xdata,Ydata
845                                if(HaveErrors)
846                                        Redimension/S Uncertainty
847                                endif
848                        endif
849                        if(HaveErrors)
850                                Save/A=2/G/W/M="\r\n"/P=IR2E_ExportPath Xdata,Ydata,Uncertainty as FinalOutputName     
851                        else
852                                Save/A=2/G/W/M="\r\n"/P=IR2E_ExportPath Xdata,Ydata as FinalOutputName         
853                        endif
854                        KillWaves/Z WaveNoteWave, NoteTempY, Xdata,Ydata,Uncertainty   
855                endif
856        endif
857
858        if(ExportGSASxye)                       //this is GSAS-II xye file...
859                //Check for existing file and manage on our own...
860                FinalOutputName=NewFileOutputName
861                if(strlen(OutputNameExtension)>0)
862                        FinalOutputName+="."+OutputNameExtension
863                endif
864       
865                Open/Z=1 /R/P=IR2E_ExportPath refnum as FinalOutputName
866                if(V_Flag==0)
867                        DoAlert 1, "The file with this name: "+FinalOutputName+ " in this location already exists, overwrite?"
868                        if(V_Flag!=1)
869                                abort
870                        endif
871                        close/A
872                        //user wants to delete the file
873                        OpenNotebook/V=0/P=IR2E_ExportPath/N=JunkNbk  FinalOutputName
874                        DoWindow/D /K JunkNbk
875                endif
876                close/A
877                Duplicate TempY, NoteTempY
878                OldNoteT1=note(TempY)
879                note/K NoteTempY
880                note NoteTempY, OldNoteT1+"Exported="+date()+" "+time()+";"
881                //              wvlgth = NumberByKey("Nika_Wavelength", OldNoteT1 , "=", ";")
882                //              if(numtype(wvlgth)!=0)
883                //                      wvlgth = NumberByKey("Wavelength", OldNoteT1 , "=", ";")
884                //                      if(numtype(wvlgth)!=0)
885                //                              Prompt wvlgth, "Wavelength not found, please, provide"
886                //                              DoPrompt "Provide wavelength is A", wvlgth
887                //                              if (V_Flag || numtype(wvlgth)!=0 || wvlgth<0.01)
888                //                                      return -1                                                               // User canceled
889                //                              endif   
890                //                      endif
891                //              endif
892                //convert q or d into two theta as needed...
893                Duplicate/Free tempX, TempXCOnverted
894                if(StringMatch(QWavename, "q_*") || StringMatch(QWavename, "'q_*")||StringMatch(QWavename, "*_Qvec"))           //q wave
895                        wvlgth = IR2E_GetWavelength(OldNoteT1)
896                        TempXCOnverted = 2 * 180/pi * asin(TempX * wvlgth /(4*pi))             
897                elseif(StringMatch(QWavename, "d_*") || StringMatch(QWavename, "'d_*"))         //d wave
898                        wvlgth = IR2E_GetWavelength(OldNoteT1)
899                        TempXCOnverted = 2 * 180/pi * (wvlgth / (2*TempX))
900                else            //Two theta wave nothing needed...
901
902                endif
903               
904                make/T/O WaveNoteWave
905                if (1)
906                        IN2G_PasteWnoteToWave("NoteTempY",WaveNoteWave ,HeaderSeparator)
907                        InsertPoints 0, 2, WaveNoteWave
908                        InsertPoints numpnts(WaveNoteWave), 2, WaveNoteWave
909                        WaveNoteWave[0] = "/*"
910                        wvlgth = IR2E_GetWavelength(OldNoteT1)
911                        WaveNoteWave[1] = HeaderSeparator+"wavelength = "+num2str(wvlgth)
912                        WaveNoteWave[numpnts(WaveNoteWave)-2] = "# 2Theta  Intensity  Error"   
913                        WaveNoteWave[numpnts(WaveNoteWave)-1] = "*/"   
914                        Save/G/M="\r\n"/P=IR2E_ExportPath WaveNoteWave as FinalOutputName
915                endif
916                if(HaveErrors)
917                        Save/A=2/G/M="\r\n"/P=IR2E_ExportPath TempXCOnverted,TempY,TempE as FinalOutputName             
918                else
919                        Save/A=2/G/M="\r\n"/P=IR2E_ExportPath TempXCOnverted,TempY as FinalOutputName           
920                endif
921                KillWaves/Z WaveNoteWave, NoteTempY
922        endif
923
924        variable SlitLength
925       
926        if(ExportCanSASNexus)                   //export Nexus... now assume this is data, not model results.
927                if(UseIndra2Data || UseQRSdata)
928                        FinalOutputName=NewFileOutputName
929                        if(strlen(OutputNameExtension)>0)
930                                FinalOutputName+="."+OutputNameExtension
931                        else
932                                OutputNameExtension= "hdf"
933                                FinalOutputName+="."+"hdf"
934                        endif
935                        oldNote=note(TempY)
936                        if(UseSMRData || stringMatch(NameOfWave(TempX),"*SMR*"))
937                                SlitLength = NumberByKey("SlitLength", oldNote, "=", ";")
938                        else
939                                SlitLength = 0
940                        endif
941                        PathInfo IR2E_ExportPath
942                        NEXUS_WriteNx1DCanSASdata(UserSampleName, S_path+FinalOutputName, TempY, TempE, TempX, TempdX, "", "Irena", oldNote, SlitLength)
943                else            //results, not canSAS Nexus export available
944                        Abort "Cannot export Results into the canSAS Nexus files"
945                endif
946        endif   
947        print "Saved data into : "+FinalOutputName
948end
949
950//*******************************************************************************************************************************
951//*******************************************************************************************************************************
952static Function IR2E_GetWavelength(OldNoteT1)
953        string OldNoteT1
954       
955        DFref oldDf= GetDataFolderDFR()
956        setDataFolder root:Packages:IR2_UniversalDataExport
957        variable wvlgth
958        NVAR/Z TempExportwvlgth //this is buffer of wavelength value if users chooses to store it.
959        string KeepwVlgth = "No"
960       
961        wvlgth = NumberByKey("Nika_Wavelength", OldNoteT1 , "=", ";")
962        if(numtype(wvlgth)!=0)
963                wvlgth = NumberByKey("Wavelength", OldNoteT1 , "=", ";")
964                if(numtype(wvlgth)!=0)
965                        //check if we have stored one here...
966                        if(NVAR_Exists(TempExportwvlgth))
967                                wvlgth = TempExportwvlgth       
968                                print "*** Using previously user input wavelentgh of "+num2str(wvlgth)+" A for current data set. *** "
969                                print "If this is wrong, type in command line : \"Killvariables root:Packages:IR2_UniversalDataExport:TempExportwvlgth \"."
970                                print "*** And re-export the data, you will get wavelength input dialog again ***"
971                        else
972                                Prompt wvlgth, "Wavelength not found, please, provide"
973                                Prompt KeepwVlgth, "Store for future use? Must be same for all data!", popup, "No;Yes;"
974                                DoPrompt "Provide wavelength is A", wvlgth, KeepwVlgth
975                                if (V_Flag || numtype(wvlgth)!=0 || wvlgth<0.01)
976                                        return -1                                                               // User canceled
977                                endif   
978                                print "*** Using user input wavelentgh of "+num2str(wvlgth)+" A for current data set. *** "
979                                if(StringMatch(KeepwVlgth, "Yes"))
980                                        variable/g TempExportwvlgth
981                                        TempExportwvlgth = wvlgth
982                                        print "*** Stored user input wavelentgh of "+num2str(wvlgth)+" A for use for all data sets.  *** "
983                                endif
984                        endif
985                endif
986        endif
987
988        setDataFolder oldDF
989        return wvlgth
990end
991
992//*******************************************************************************************************************************
993//*******************************************************************************************************************************
994//*******************************************************************************************************************************
995
996Function IR2E_LoadDataInTool()
997
998        KillWIndow/Z TempExportGraph
999        KillWIndow/Z ExportNoteDisplay
1000        KillWaves/Z TempX, TampY, TempE
1001
1002
1003        DFref oldDf= GetDataFolderDFR()
1004
1005        setDataFolder root:Packages:IR2_UniversalDataExport
1006
1007        NVAR AttachWaveNote = root:Packages:IR2_UniversalDataExport:AttachWaveNote
1008        NVAR GraphData = root:Packages:IR2_UniversalDataExport:GraphData
1009        NVAR DisplayWaveNote = root:Packages:IR2_UniversalDataExport:DisplayWaveNote
1010        NVAR UseFolderNameForOutput = root:Packages:IR2_UniversalDataExport:UseFolderNameForOutput
1011        NVAR UseYWaveNameForOutput = root:Packages:IR2_UniversalDataExport:UseYWaveNameForOutput
1012        NVAR ExportCanSASNexus = root:Packages:IR2_UniversalDataExport:ExportCanSASNexus
1013        NVAR ExportASCII = root:Packages:IR2_UniversalDataExport:ExportASCII
1014        NVAR ExportMultipleCanSASFiles = root:Packages:IR2_UniversalDataExport:ExportMultipleCanSASFiles
1015        NVAR ExportSingleCanSASFile = root:Packages:IR2_UniversalDataExport:ExportSingleCanSASFile
1016        NVAR ExportGSASxye = root:Packages:IR2_UniversalDataExport:ExportGSASxye
1017
1018        SVAR DataFolderName = root:Packages:IR2_UniversalDataExport:DataFolderName
1019        SVAR IntensityWaveName = root:Packages:IR2_UniversalDataExport:IntensityWaveName
1020        SVAR QWavename = root:Packages:IR2_UniversalDataExport:QWavename
1021        SVAR ErrorWaveName = root:Packages:IR2_UniversalDataExport:ErrorWaveName
1022        SVAR CurrentlyLoadedDataName = root:Packages:IR2_UniversalDataExport:CurrentlyLoadedDataName
1023        SVAR CurrentlySetOutputPath = root:Packages:IR2_UniversalDataExport:CurrentlySetOutputPath
1024        SVAR NewFileOutputName = root:Packages:IR2_UniversalDataExport:NewFileOutputName
1025        SVAR HeaderSeparator = root:Packages:IR2_UniversalDataExport:HeaderSeparator
1026       
1027       
1028        Wave/Z tempY=$(DataFolderName+possiblyquoteName(IntensityWaveName))
1029        Wave/Z tempX=$(DataFolderName+possiblyquoteName(QWavename))
1030        Wave/Z tempE=$(DataFolderName+possiblyquoteName(ErrorWaveName))
1031       
1032        if(!WaveExists(tempY) && !WaveExists(tempX))
1033                abort
1034        endif
1035       
1036        CurrentlyLoadedDataName = DataFolderName+IntensityWaveName
1037
1038        if(GraphData)
1039                Display/K=1/W=(300,40,700,250)  TempY vs TempX as "Preview of export data"
1040                DoWindow/C TempExportGraph
1041                ModifyGraph log=1
1042                TextBox/C/N=text0  CurrentlyLoadedDataName
1043                IN2G_AutoAlignPanelAndGraph()
1044        endif
1045        string OldNote
1046        String nb = "ExportNoteDisplay"
1047        variable i
1048        if(DisplayWaveNote)
1049                OldNote = note(TempY) +"Exported="+date()+" "+time()+";"
1050                NewNotebook/K=1/N=$nb/F=0/V=1/K=0/W=(300,270,700,530) as "Data Notes"
1051                Notebook $nb defaultTab=20, statusWidth=238, pageMargins={72,72,72,72}
1052                Notebook $nb font="Arial", fSize=10, fStyle=0, textRGB=(0,0,0)
1053                For(i=0;i<ItemsInList(OldNOte);i+=1)
1054                        Notebook $nb text=HeaderSeparator+ stringFromList(i,OldNote)+"\r"
1055                endfor
1056                        AutopositionWindow/M=0 /R=TempExportGraph ExportNoteDisplay
1057        endif
1058       
1059
1060        if(ExportASCII || ExportGSASxye ||(ExportCanSASNexus * !ExportSingleCanSASFile))
1061                NewFileOutputName = ""
1062                if(UseFolderNameForOutput)
1063                        NewFileOutputName += IN2G_ReturnUserSampleName(DataFolderName)                 
1064                endif
1065                if(UseFolderNameForOutput && UseYWaveNameForOutput)
1066                        NewFileOutputName += "_"
1067                endif
1068                if(UseYWaveNameForOutput)
1069                        NewFileOutputName += IN2G_RemoveExtraQuote(IntensityWaveName,1,1)
1070                endif   
1071        endif
1072       
1073        setDataFolder oldDF
1074
1075end
1076//*******************************************************************************************************************************
1077//*******************************************************************************************************************************
1078//*******************************************************************************************************************************
1079//*******************************************************************************************************************************
1080//*******************************************************************************************************************************
1081
1082Function IR2E_ChangeExportPath()
1083
1084        DFref oldDf= GetDataFolderDFR()
1085
1086        setDataFolder root:Packages:IR2_UniversalDataExport
1087        SVAR CurrentlySetOutputPath=root:Packages:IR2_UniversalDataExport:CurrentlySetOutputPath
1088        NewPath/O/M="Select new output folder" IR2E_ExportPath
1089        PathInfo IR2E_ExportPath
1090        CurrentlySetOutputPath=S_Path
1091
1092        setDataFolder oldDF
1093
1094end
1095
1096///******************************************************************************************
1097///******************************************************************************************
1098///******************************************************************************************
1099///******************************************************************************************
1100///******************************************************************************************
1101///******************************************************************************************
1102
1103
1104Function IR2E_InitUnivDataExport()
1105
1106
1107        DFref oldDf= GetDataFolderDFR()
1108
1109        setdatafolder root:
1110        NewDataFolder/O/S root:Packages
1111        NewDataFolder/O/S IR2_UniversalDataExport
1112
1113        string ListOfVariables
1114        string ListOfStrings
1115        variable i
1116       
1117        //here define the lists of variables and strings needed, separate names by ;...
1118       
1119        ListOfVariables="UseIndra2Data;UseQRSdata;UseResults;UseSMRData;UseUserDefinedData;"
1120        ListOfVariables+="AttachWaveNote;GraphData;DisplayWaveNote;UseFolderNameForOutput;UseYWaveNameForOutput;"
1121        ListOfVariables+="ExportMultipleDataSets;ASCIIExportQ;ASCIIExportD;ASCIIExportTTH;"
1122        ListOfVariables+="ExportCanSASNexus;ExportASCII;ExportGSASxye;"
1123        ListOfVariables+="ExportMultipleCanSASFiles;ExportSingleCanSASFile;reduceOutputPrecision;"
1124
1125        ListOfStrings="DataFolderName;IntensityWaveName;QWavename;ErrorWaveName;"
1126        ListOfStrings+="CurrentlyLoadedDataName;CurrentlySetOutputPath;NewFileOutputName;"
1127       
1128        //and here we create them
1129        for(i=0;i<itemsInList(ListOfVariables);i+=1)   
1130                IN2G_CreateItem("variable",StringFromList(i,ListOfVariables))
1131        endfor         
1132                                                                               
1133        for(i=0;i<itemsInList(ListOfStrings);i+=1)     
1134                IN2G_CreateItem("string",StringFromList(i,ListOfStrings))
1135        endfor 
1136
1137
1138        make/O/T/N=0 ListOfAvailableData
1139        make/O/N=0 SelectionOfAvailableData
1140       
1141        SVAR/Z OutputNameExtension
1142        if(!SVAR_Exists(OutputNameExtension))
1143                string/G OutputNameExtension
1144                OutputNameExtension="dat"
1145        endif
1146        SVAR/Z HeaderSeparator
1147        if(!SVAR_Exists(HeaderSeparator))
1148                string/G HeaderSeparator
1149                HeaderSeparator="#   "
1150        endif
1151        //Ouptu path
1152        PathInfo IR2E_ExportPath
1153        if(!V_Flag)
1154                PathInfo Igor
1155                NewPath/Q IR2E_ExportPath S_Path
1156        endif
1157        PathInfo IR2E_ExportPath
1158        SVAR CurrentlySetOutputPath
1159        CurrentlySetOutputPath=S_Path
1160       
1161        SVAR NewFileOutputName
1162        NewFileOutputName=""
1163        SVAR CurrentlyLoadedDataName
1164        CurrentlyLoadedDataName = ""
1165        SVAR DataFolderName
1166        DataFolderName=""
1167        SVAR IntensityWaveName
1168        IntensityWaveName=""
1169        SVAR QWavename
1170        QWavename=""
1171        SVAR ErrorWaveName
1172        ErrorWaveName=""
1173       
1174        NVAR UseFolderNameForOutput
1175        NVAR UseYWaveNameForOutput
1176        if(UseFolderNameForOutput+UseYWaveNameForOutput !=1)
1177                UseFolderNameForOutput = 1
1178                UseYWaveNameForOutput = 0
1179        endif
1180               
1181        NVAR ExportASCII
1182        NVAR ExportCanSASNexus
1183        NVAR ExportGSASxye
1184        if(ExportASCII + ExportCanSASNexus + ExportGSASxye !=1)
1185                ExportASCII = 1
1186                ExportCanSASNexus= 0
1187                ExportGSASxye = 0
1188        endif
1189        NVAR ASCIIExportQ
1190        NVAR ASCIIExportD
1191        NVAR ASCIIExportTTH
1192        if(ASCIIExportQ+ASCIIExportD+ASCIIExportTTH !=1)
1193                ASCIIExportQ =1
1194                ASCIIExportD = 0
1195                ASCIIExportTTH = 0
1196        endif
1197        setDataFolder OldDf
1198
1199end
1200
1201//*******************************************************************************************************************************
1202//*******************************************************************************************************************************
1203//*******************************************************************************************************************************
1204//*******************************************************************************************************************************
1205//*******************************************************************************************************************************
1206
1207
1208
1209Function IR2E_ExportAllAsNexus()
1210        //this function exports all USAXS, SAXS, and WAXS data in current experiment
1211        //use standard export tool, but hide it from user...
1212        IR2E_UniversalDataExport()
1213        DoWIndow/hide=1 UnivDataExportPanel
1214        NVAR UseIndra2data = root:Packages:IR2_UniversalDataExport:UseIndra2data
1215        NVAR UseQRSdata = root:Packages:IR2_UniversalDataExport:UseQRSdata
1216        NVAR UseResults = root:Packages:IR2_UniversalDataExport:UseResults
1217        SVAR DataFolderName = root:Packages:IR2_UniversalDataExport:DataFolderName
1218        SVAR IntensityWaveName=root:Packages:IR2_UniversalDataExport:IntensityWaveName
1219        SVAR QWavename=root:Packages:IR2_UniversalDataExport:QWavename
1220        SVAR ErrorWaveName=root:Packages:IR2_UniversalDataExport:ErrorWaveName
1221        UseResults = 0
1222        UseQRSdata = 0
1223        UseIndra2data = 1
1224        string CurrentFoldersUSAXS=IR2P_GenStringOfFolders(winNm="UnivDataExportPanel", returnListOfFolders=1, forceReset=1)
1225        CurrentFoldersUSAXS = GrepList(CurrentFoldersUSAXS, "---",1 , ";" )
1226        //now we have all folders with data. These could be either USAXS SMR, USAXS DSM, and we have separate list for QRS data.
1227        //print CurrentFoldersUSAXS
1228        //print CurrentFoldersQRS
1229        //mneed to verify the file name and location are available, use name of current Igor experiment and its location,
1230        //add _nxcansas to it.
1231        string currentEXPName=IgorInfo(1)
1232        PathInfo home
1233        string FinalOutputName, oldNote, OldNoteT1, tempFldr
1234        string UserSampleName
1235        string HomePathStr=S_path
1236        FinalOutputName = currentEXPName+"_nxcansas.h5"
1237        //print HomePathStr
1238        variable refnum, SlitLength
1239        variable i
1240       
1241        Open/Z=1 /R/P=home refnum as FinalOutputName
1242        if(V_Flag==0)
1243                DoAlert 1, "The file with this name: "+FinalOutputName+ " already exists in "+HomePathStr+" , overwrite?"
1244                if(V_Flag!=1)
1245                        abort
1246                endif
1247                close/A
1248                //user wants to delete the file
1249                DeleteFile /P=home  FinalOutputName
1250        else
1251                DoAlert 1, "New file with this name: "+FinalOutputName+ " will be created in "+HomePathStr+", continue?"
1252                if(V_Flag!=1)
1253                        abort
1254                endif
1255                close/A
1256        endif
1257        variable ExportUSAXS=1
1258        variable ExportSAXS=1
1259        variable ExportWAXS=1
1260        variable ExportOtherQRS=1
1261        Prompt ExportUSAXS, "Export USAXS?", popup, "Yes;No;"
1262        Prompt ExportSAXS, "Export QRS in root:SAXS/SAS/ImportedSAS?", popup, "Yes;No;"
1263        Prompt ExportWAXS, "Export QRS in root:WAXS/WAS/ImportedWAXS?", popup, "Yes;No;"
1264        Prompt ExportOtherQRS, "Export QRS in other locations?", popup, "Yes;No;"
1265        DoPrompt/HELP="Choose if these specific types of data should be exported" "Select which data will be exported", ExportUSAXS, ExportSAXS, ExportWAXS, ExportOtherQRS
1266        if (V_Flag)
1267                return -1                                                               // User canceled
1268        endif
1269        //      note, value of 2 = NO
1270        //      to preset the names, code is here: IR2E_ExportMultipleFiles()
1271        //export USAXS data
1272        SVAR FolderMatchStr = root:Packages:IrenaControlProcs:UnivDataExportPanel:FolderMatchStr
1273        FolderMatchStr=""
1274        UseResults = 0
1275        UseQRSdata = 0
1276        UseIndra2data = 1
1277        STRUCT WMPopupAction PU_Struct
1278        if(ItemsInList(CurrentFoldersUSAXS, ";")>0 && ExportUSAXS==1)
1279                For(i=0;i<ItemsInList(CurrentFoldersUSAXS, ";");i+=1)
1280                        tempFldr = StringFromList(i, CurrentFoldersUSAXS, ";")
1281                        DataFolderName = StringFromList(i, CurrentFoldersUSAXS, ";")
1282                        PU_Struct.ctrlName = "SelectDataFolder"
1283                        PU_Struct.popNum=-1
1284                        PU_Struct.eventCode=2
1285                        PU_Struct.popStr=DataFolderName
1286                        PU_Struct.win = "UnivDataExportPanel"
1287                        PopupMenu SelectDataFolder win=UnivDataExportPanel, popmatch=StringFromList(ItemsInList(DataFolderName,":")-1,DataFolderName,":")
1288                        IR2C_PanelPopupControl(PU_Struct)
1289                        Wave/Z TempY=$(tempFldr+possiblyquoteName(IntensityWaveName))
1290                        Wave/Z TempX=$(tempFldr+possiblyquoteName(QWavename))
1291                        Wave/Z TempE=$(tempFldr+possiblyquoteName(ErrorWaveName))
1292                        Wave/Z TempdX=$(DataFolderName+ReplaceString("Qvec", QWavename, "dQ"))
1293                        if(!WaveExists(TempdX))
1294                                Duplicate/Free TempE, tempdXLoc
1295                                tempdXLoc = 0
1296                        else
1297                                Duplicate/Free TempdX, tempdXLoc
1298                        endif
1299                        oldNote=note(TempY)
1300                        if(stringMatch(NameOfWave(TempX),"*SMR*"))
1301                                SlitLength = NumberByKey("SlitLength", oldNote, "=", ";")
1302                        else
1303                                SlitLength = 0
1304                                print "Did not export dQ data as this causes issues in sasView"
1305                                tempdXLoc = 0
1306                        endif
1307                        UserSampleName=IN2G_ReturnUserSampleName(DataFolderName)
1308                        NEXUS_WriteNx1DCanSASdata(UserSampleName, HomePathStr+FinalOutputName, TempY, TempE, TempX, tempdXLoc, "", "Irena", oldNote, SlitLength)       
1309                endfor
1310        endif   
1311
1312        UseResults = 0
1313        UseQRSdata = 1
1314        UseIndra2data = 0
1315        string CurrentFoldersQRS=IR2P_GenStringOfFolders(winNm="UnivDataExportPanel", returnListOfFolders=1, forceReset=1)
1316        CurrentFoldersQRS = GrepList(CurrentFoldersQRS, "---",1 , ";" )
1317        string TempList =""
1318        string TempList2 = ""
1319        if(ExportSAXS==1)
1320                TempList += GrepList(CurrentFoldersQRS, ":SAXS:" ,0 )+GrepList(CurrentFoldersQRS, ":SAS:" ,0 )+GrepList(CurrentFoldersQRS, ":ImportedSAS:" ,0 )
1321        endif
1322        if(ExportWAXS==1)
1323                TempList += GrepList(CurrentFoldersQRS, ":WAXS:" ,0 )+GrepList(CurrentFoldersQRS, ":WAS:" ,0 )+GrepList(CurrentFoldersQRS, ":ImportedWAXS:" ,0 )
1324        endif
1325        if(ExportOtherQRS==1)
1326                TempList2 = GrepList(CurrentFoldersQRS, ":WAXS:" ,1 )
1327                TempList2 = GrepList(TempList2, ":SAXS:" ,1 )
1328                TempList2 = GrepList(TempList2, ":WAS:" ,1 )
1329                TempList2 = GrepList(TempList2, ":SAS:" ,1 )
1330                TempList2 = GrepList(TempList2, ":ImportedWAXS:" ,1 )
1331                TempList2 = GrepList(TempList2, ":ImportedSAS:" ,1 )
1332        endif
1333        CurrentFoldersQRS = TempList + TempList2
1334        if(ItemsInList(CurrentFoldersQRS, ";")>0)
1335                For(i=0;i<ItemsInList(CurrentFoldersQRS, ";");i+=1)
1336                        tempFldr = StringFromList(i, CurrentFoldersQRS, ";")
1337                        DataFolderName = StringFromList(i, CurrentFoldersQRS, ";")
1338                        PU_Struct.ctrlName = "SelectDataFolder"
1339                        PU_Struct.popNum=-1
1340                        PU_Struct.eventCode=2
1341                        PU_Struct.popStr=DataFolderName
1342                        PU_Struct.win = "UnivDataExportPanel"
1343                        PopupMenu SelectDataFolder win=UnivDataExportPanel, popmatch=StringFromList(ItemsInList(DataFolderName,":")-1,DataFolderName,":")
1344                        IR2C_PanelPopupControl(PU_Struct)
1345                        Wave/Z TempY=$(tempFldr+possiblyquoteName(IntensityWaveName))
1346                        Wave/Z TempX=$(tempFldr+possiblyquoteName(QWavename))
1347                        Wave/Z TempE=$(tempFldr+possiblyquoteName(ErrorWaveName))
1348                        Wave/Z TempdX=$(DataFolderName+ReplaceString("Qvec", QWavename, "dQ"))
1349                        if(!WaveExists(TempdX))
1350                                Duplicate/Free TempE, tempdX
1351                                tempdX = 0
1352                        endif
1353                        oldNote=note(TempY)
1354                        SlitLength = 0
1355                        UserSampleName=IN2G_ReturnUserSampleName(DataFolderName)
1356                        NEXUS_WriteNx1DCanSASdata(UserSampleName, HomePathStr+FinalOutputName, TempY, TempE, TempX, TempdX, "", "Irena", oldNote, SlitLength)   
1357                endfor
1358        endif   
1359
1360
1361        DOwindow/K UnivDataExportPanel
1362        print "Exported all data from current experiment in file:" +FinalOutputName
1363end
1364
1365
1366
1367//************************************************************************************************************
1368//************************************************************************************************************
1369//************************************************************************************************************
1370//************************************************************************************************************
Note: See TracBrowser for help on using the repository browser.