source: trunk/User Procedures/Irena/IR1_ImportData.ipf @ 938

Last change on this file since 938 was 938, checked in by ilavsky, 2 years ago

Igor 9 related changes

  • Property svn:executable set to *
File size: 153.0 KB
Line 
1#pragma rtGlobals = 3   // Use strict wave reference mode and runtime bounds checking
2//#pragma rtGlobals=2           // Use modern global access method.
3#pragma version=2.40
4
5#if(IgorVersion()<9)    //no need to include, Igor 9 has this by default. 
6#include <HDF5 Browser>
7#endif
8
9
10Constant IR1IversionNumber = 2.37
11Constant IR1IversionNumber2 = 2.36
12Constant IR1IversionNumberNexus = 2.36
13Constant IR1TrimNameLength = 28
14
15
16//*************************************************************************\
17//* Copyright (c) 2005 - 2020, Argonne National Laboratory
18//* This file is distributed subject to a Software License Agreement found
19//* in the file LICENSE that is included with this distribution.
20//*************************************************************************/
21
22//2.40 minor fixes for importing Slit smeared data.
23//2.39 made long names capable for Igor 8 when user chooses.
24//2.38 Modified Screen Size check to match the needs
25//2.37 added Plot button to SAXS importer also.
26//2.36 added GetHelp button
27//2.35 fixed lack of too many points message and remvoed hidden tfiles from dialogs.
28//2.34 fixed problems with negative intensities which screwed up errors. Added abs(Int) for error generation and avoided error message when error was not used.
29//2.33 added Nexus file importer.
30//2.32 fixed window naming issue which prevented scaling from work.
31//2.31 Added non SAS import tool, needs debugging and testing for all of teh known types. Not finished yet.
32//2.30 fixes for labels presentation, added cleanup for imported names removing bad characters.
33//2.29 added slit smearing and dq wave name
34//2.28 changes for panel scaling
35//2.27 fixes for naming of USAXS weave which seemed to have typo in naming system.
36//2.26 added check for Error import - will abort import if Errors contain negative values, 0, INFs or NANs. Check import works with csv files.
37//2.25 minor fix for data with too many columns of data - Irena can handle only first 6 columns...
38//2.24 minor change in how calibration units are displayed in the panel.
39//2.23 added sorting of imported waves as some users seem to have data which are not increasing in q. Weird, but possible... DOne before optional rebinning.
40//2.22 changed Import rebinning on log scale to match minimum step (defined as the difference between first two original points left after trimming and 0 int removal).
41//2.21 changed import to load data as double precision waves. SOme users were running out of precision.
42//2.20 added RemoveStringFromName to remove part of name which user does not want to see...
43//2.19 Removed error when file being imported has less columns than found originally, if these are not being imported and used.
44//              enabled use of following characters in names: (){}%#^$?|&@
45//2.18 modified log-rebinning to use more simple log-scale, control parameter is removed. Changed to rtGlobals=2
46//         modified so any separator and leading spaces are removed when storing header info in wave note.
47//         Remove negative intensities now removes 0 also (Int<=0 are removed). Same for Q<=0.
48//2.17 added controls for Units - Arbitrary, cm2/cm3, and cm2/g are known units for now...
49//2.16 added cleanup of weird characters (,),%, {, } of names. Allowed by igor but cause problems to my opther code.
50//2.15 added vertical scrolling for panel.
51//2.14 added option to trunkate long names in front or end.
52//2.13 FIxed bug when selection Qmax for trimming larger than Qmax f data resulted in no data in the file at all. Fixed note when scaling data.
53//2.12 removed popup to select fodler. Confusing users, keep putting data into Packages folder. Users need to type new folder names in.
54//2.11 modified GUI and added ability to reduce number of points to meaningful number, added too high number of points warning.
55//2.10 removed all font and font size from panel definitions to enable user control
56//2.09 added ability to trim data Q range on import and small cosmetic changes.
57//2.08 added match string for name of data files imported and fixed bug created in last release when data without "errors" gave Igor code error.
58//2.07 modified to default to use File names for Folder Names and use qrs wave names. Clean up the waves for negative q and optionally negative intensities
59//              added check for version update and forced reload.
60//2.06 adds checking for snesible %error scaling (larger than 1e-12) to prevent users from creating errors with 0 in them for all points. Really happened!
61//2.05 added license for ANL
62
63//2.03 adds checking for presence of columns of data in the folder - in case user chooses wrong number of columns.
64//2.02 added some print commands in history to let user know what is happening
65//2.04 5/10/2010 FIxed issue with naming of the waves. Used || instead of &&, how come it actually worked (ever)?
66
67//this should allow user to import data to Igor - let's deal with 3 column data in ASCII for now
68
69
70Function IR1I_ImportSASASCIIDataMain()
71        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
72        IN2G_CheckScreenSize("height",720)
73        DoWindow IR1I_ImportOtherASCIIData
74        if(V_Flag)
75                DoALert/T="Window conflict notice" 1, "Import Other ASCII data cannot be open while using this tool, close (Yes) or abort (no)?"
76                if(V_flag==1)
77                        KillWIndow/Z IR1I_ImportOtherASCIIData
78                else
79                        abort
80                endif
81        endif
82        DoWindow IR1I_ImportNexusCanSASData
83        if(V_Flag)
84                DoALert/T="Window conflict notice" 1, "Import Nexus data cannot be open while using this tool, close (Yes) or abort (no)?"
85                if(V_flag==1)
86                        KillWIndow/Z IR1I_ImportNexusCanSASData
87                else
88                        abort
89                endif
90        endif
91        KillWIndow/Z IR1I_ImportData
92        IR1I_InitializeImportData()
93        Execute("IR1I_ImportSASASCIIData()")
94        ING2_AddScrollControl()
95        IR1_UpdatePanelVersionNumber("IR1I_ImportData", IR1IversionNumber,1)
96        //fix checboxes
97        IR1I_FIxCheckboxesForWaveTypes()
98end
99
100//************************************************************************************************************
101//************************************************************************************************************
102//************************************************************************************************************
103//************************************************************************************************************
104
105Function IR1I_MainCheckVersion()       
106        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
107        DoWindow IR1I_ImportData
108        if(V_Flag)
109                if(!IR1_CheckPanelVersionNumber("IR1I_ImportData", IR1IversionNumber))
110                        DoAlert /T="The ASCII Import panel was created by incorrect version of Irena " 1, "Import ASCII may need to be restarted to work properly. Restart now?"
111                        if(V_flag==1)
112                                IR1I_ImportSASASCIIDataMain()
113                        else            //at least reinitialize the variables so we avoid major crashes...
114                                IR1I_InitializeImportData()
115                        endif
116                endif
117        endif
118end
119//************************************************************************************************************
120//************************************************************************************************************
121
122Function IR1I_MainCheckVersion2()       
123        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
124        DoWindow IR1I_ImportOtherASCIIData
125        if(V_Flag)
126                if(!IR1_CheckPanelVersionNumber("IR1I_ImportOtherASCIIData", IR1IversionNumber2))
127                        DoAlert /T="The non-SAS Import panel was created by incorrect version of Irena " 1, "Import non-SAS may need to be restarted to work properly. Restart now?"
128                        if(V_flag==1)
129                                IR1I_ImportOtherASCIIMain()
130                        else            //at least reinitialize the variables so we avoid major crashes...
131                                IR1I_InitializeImportData()
132                        endif
133                endif
134        endif
135end
136//************************************************************************************************************
137//************************************************************************************************************
138
139Function IR1I_MainCheckVersionNexus()   
140        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
141        DoWindow IR1I_ImportNexusCanSASData
142        if(V_Flag)
143                if(!IR1_CheckPanelVersionNumber("IR1I_ImportNexusCanSASData", IR1IversionNumberNexus))
144                        DoAlert /T="The Nexus Import panel was created by incorrect version of Irena " 1, "Import Nexus canSAS may need to be restarted to work properly. Restart now?"
145                        if(V_flag==1)
146                                Execute/P("IR1I_ImportNexusCanSASMain()")
147                        else            //at least reinitialize the variables so we avoid major crashes...
148                                IR1I_InitializeImportData()
149                        endif
150                endif
151        endif
152end
153
154//************************************************************************************************************
155//************************************************************************************************************
156//************************************************************************************************************
157//************************************************************************************************************
158
159Proc IR1I_ImportSASASCIIData()
160        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
161        PauseUpdate; Silent 1           // building window...
162        NewPanel /K=1 /W=(3,40,430,760)/N=IR1I_ImportData as "Import SAXS/SANS data"
163        TitleBox MainTitle title="\Zr200Import SAS ASCII Data in Igor",pos={20,5},frame=0,fstyle=3, fixedSize=1,font= "Times New Roman", size={350,24},anchor=MC,fColor=(0,0,52224)
164        TitleBox FakeLine1 title=" ",fixedSize=1,size={330,3},pos={16,40},frame=0,fColor=(0,0,52224), labelBack=(0,0,52224)
165        TitleBox Info1 title="\Zr140List of available files",pos={30,107},frame=0,fstyle=1, fixedSize=1,size={120,20},fColor=(0,0,52224)
166        TitleBox Info21 title="\Zr140Column 1",pos={216,215},frame=0,fstyle=2, fixedSize=1,size={150,20}
167        TitleBox Info22 title="\Zr140Column 2",pos={216,232},frame=0,fstyle=2, fixedSize=1,size={150,20}
168        TitleBox Info23 title="\Zr140Column 3",pos={216,249},frame=0,fstyle=2, fixedSize=1,size={150,20}
169        TitleBox Info24 title="\Zr140Column 4",pos={216,266},frame=0,fstyle=2, fixedSize=1,size={150,20}
170        TitleBox Info25 title="\Zr140Column 5",pos={216,283},frame=0,fstyle=2, fixedSize=1,size={150,20}
171        TitleBox Info26 title="\Zr140Column 6",pos={216,300},frame=0,fstyle=2, fixedSize=1,size={150,20}
172        TitleBox Info6 title="\Zr150Q",pos={287,195},frame=0,fstyle=2, fixedSize=0,size={40,15}
173        TitleBox Info7 title="\Zr150Int",pos={318,195},frame=0,fstyle=2, fixedSize=0,size={40,15}
174        TitleBox Info8 title="\Zr150Err",pos={351,195},frame=0,fstyle=2, fixedSize=0,size={40,15}
175        TitleBox Info9 title="\Zr150dQ",pos={382,195},frame=0,fstyle=2, fixedSize=0,size={40,15}
176        Button SelectDataPath,pos={99,53},size={130,20}, proc=IR1I_ButtonProc,title="Select data path"
177        Button SelectDataPath,help={"Select data path to the data"}
178        Button GetHelp,pos={335,60},size={80,15},fColor=(65535,32768,32768), proc=IR1I_ButtonProc,title="Get Help", help={"Open www manual page for this tool"}
179        SetVariable DataPathString,pos={2,85},size={415,19},title="Data path :", noedit=1
180        SetVariable DataPathString,help={"This is currently selected data path where Igor looks for the data"}
181        SetVariable DataPathString,limits={-Inf,Inf,0},value= root:Packages:ImportData:DataPathName
182        SetVariable DataExtensionString,pos={220,110},size={150,19},proc=IR1I_SetVarProc,title="Data extension:"
183        SetVariable DataExtensionString,help={"Insert extension string to mask data of only some type (dat, txt, ...)"}
184        //SetVariable DataExtensionString,fSize=12
185        SetVariable DataExtensionString,value= root:Packages:ImportData:DataExtension
186
187
188        ListBox ListOfAvailableData,pos={7,128},size={196,244}
189        ListBox ListOfAvailableData,help={"Select files from this location you want to import"}
190        ListBox ListOfAvailableData,listWave=root:Packages:ImportData:WaveOfFiles
191        ListBox ListOfAvailableData,selWave=root:Packages:ImportData:WaveOfSelections
192        ListBox ListOfAvailableData,mode= 4, proc=IR1_ImportListBoxProc
193
194
195        SetVariable NameMatchString,pos={10,375},size={180,19},proc=IR1I_SetVarProc,title="Match name (string):"
196        SetVariable NameMatchString,help={"Insert RegEx select only data with matching name (uses grep)"}
197        SetVariable NameMatchString,value= root:Packages:ImportData:NameMatchString
198
199
200        Button SelectAll,pos={5,396},size={100,20}, proc=IR1I_ButtonProc,title="Select All"
201        Button SelectAll,help={"Select all waves in the list"}
202
203        Button DeSelectAll,pos={120,396},size={100,20}, proc=IR1I_ButtonProc,title="Deselect All"
204        Button DeSelectAll,help={"Deselect all waves in the list"}
205
206
207        CheckBox SkipLines,pos={220,133},size={16,14},proc=IR1I_CheckProc,title="Skip lines?",variable= root:Packages:ImportData:SkipLines, help={"Check if you want to skip lines in header. Needed ONLY for weird headers..."}
208        SetVariable SkipNumberOfLines,pos={300,133},size={70,19},proc=IR1I_SetVarProc,title=" "
209        SetVariable SkipNumberOfLines,help={"Insert number of lines to skip"}
210        SetVariable SkipNumberOfLines,variable= root:Packages:ImportData:SkipNumberOfLines, disable=(!root:Packages:ImportData:SkipLines)
211
212        Button TestImport,pos={205,152},size={70,15}, proc=IR1I_ButtonProc,title="Test"
213        Button TestImport,help={"Test how if import can be succesful and how many waves are found"}
214        Button Preview,pos={278,152},size={70,15}, proc=IR1I_ButtonProc,title="Preview"
215        Button Preview,help={"Preview selected file."}
216        Button Plot,pos={350,152},size={70,15}, proc=IR1I_ButtonProc,title="Plot"
217        Button Plot,help={"Preview selected file."}
218
219
220        TitleBox TooManyPointsWarning variable=root:Packages:ImportData:TooManyPointsWarning,fColor=(0,0,0)
221        TitleBox TooManyPointsWarning pos={220,170},size={150,19}, disable=1
222        CheckBox Col1Qvec,pos={289,216},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col1Qvec, help={"What does this column contain?"}
223        CheckBox Col1Int,pos={321,216},size={16,14},proc=IR1I_CheckProc,title="", variable= root:Packages:ImportData:Col1Int, help={"What does this column contain?"}
224        CheckBox Col1Error,pos={354,216},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col1Err, help={"What does this column contain?"}
225        CheckBox Col1QError,pos={384,216},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col1QErr, help={"What does this column contain?"}
226
227        CheckBox Col2Qvec,pos={289,233},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col2Qvec, help={"What does this column contain?"}
228        CheckBox Col2Int,pos={321,233},size={16,14},proc=IR1I_CheckProc,title="", variable= root:Packages:ImportData:Col2Int, help={"What does this column contain?"}
229        CheckBox Col2Error,pos={354,233},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col2Err, help={"What does this column contain?"}
230        CheckBox Col2QError,pos={384,233},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col2QErr, help={"What does this column contain?"}
231
232        CheckBox Col3Qvec,pos={289,250},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col3Qvec, help={"What does this column contain?"}
233        CheckBox Col3Int,pos={321,250},size={16,14},proc=IR1I_CheckProc,title="", variable= root:Packages:ImportData:Col3Int, help={"What does this column contain?"}
234        CheckBox Col3Error,pos={354,250},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col3Err, help={"What does this column contain?"}
235        CheckBox Col3QError,pos={384,250},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col3QErr, help={"What does this column contain?"}
236
237        CheckBox Col4Qvec,pos={289,267},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col4Qvec, help={"What does this column contain?"}
238        CheckBox Col4Int,pos={321,267},size={16,14},proc=IR1I_CheckProc,title="", variable= root:Packages:ImportData:Col4Int, help={"What does this column contain?"}
239        CheckBox Col4Error,pos={354,267},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col4Err, help={"What does this column contain?"}
240        CheckBox Col4QError,pos={384,267},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col4QErr, help={"What does this column contain?"}
241
242        CheckBox Col5Qvec,pos={289,284},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col5Qvec, help={"What does this column contain?"}
243        CheckBox Col5Int,pos={321,284},size={16,14},proc=IR1I_CheckProc,title="", variable= root:Packages:ImportData:Col5Int, help={"What does this column contain?"}
244        CheckBox Col5Error,pos={354,284},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col5Err, help={"What does this column contain?"}
245        CheckBox Col5QError,pos={384,284},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col5QErr, help={"What does this column contain?"}
246
247        CheckBox Col6Qvec,pos={289,301},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col6Qvec, help={"What does this column contain?"}
248        CheckBox Col6Int,pos={321,301},size={16,14},proc=IR1I_CheckProc,title="", variable= root:Packages:ImportData:Col6Int, help={"What does this column contain?"}
249        CheckBox Col6Error,pos={354,301},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col6Err, help={"What does this column contain?"}
250        CheckBox Col6QError,pos={384,301},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col6QErr, help={"What does this column contain?"}
251
252
253        SetVariable FoundNWaves,pos={220,320},size={150,19},title="Found columns :",proc=IR1I_SetVarProc
254        SetVariable FoundNWaves,help={"This is how many columns were found in the tested file"}, disable=2
255        SetVariable FoundNWaves,limits={0,Inf,0},value= root:Packages:ImportData:FoundNWaves
256
257        CheckBox QvectorInA,pos={240,340},size={16,14},proc=IR1I_CheckProc,title="Qvec units [A^-1]",variable= root:Packages:ImportData:QvectInA, help={"What units is Q in? Select if in Angstroems ^-1"}
258        CheckBox QvectorInNM,pos={240,355},size={16,14},proc=IR1I_CheckProc,title="Qvec units [nm^-1]",variable= root:Packages:ImportData:QvectInNM, help={"What units is Q in? Select if in nanometers ^-1. WIll be converted to inverse Angstroems"}
259        CheckBox CreateSQRTErrors,pos={240,370},size={16,14},proc=IR1I_CheckProc,title="Create SQRT Errors?",variable= root:Packages:ImportData:CreateSQRTErrors, help={"If input data do not contain errors, create errors as sqrt of intensity?"}
260        CheckBox CreatePercentErrors,pos={240,385},size={16,14},proc=IR1I_CheckProc,title="Create n% Errors?",variable= root:Packages:ImportData:CreatePercentErrors, help={"If input data do not contain errors, create errors as n% of intensity?, select how many %"}
261        SetVariable PercentErrorsToUse, pos={240,403}, size={100,20},title="Error %?:", proc=IR1I_setvarProc, disable=!(root:Packages:ImportData:CreatePercentErrors)
262        SetVariable PercentErrorsToUse value= root:packages:ImportData:PercentErrorsToUse,help={"Input how many percent error you want to create."}
263
264
265        CheckBox UseFileNameAsFolder,pos={10,420},size={16,14},proc=IR1I_CheckProc,title="Use File Nms as Fldr Nms?",variable= root:Packages:ImportData:UseFileNameAsFolder, help={"Use names of imported files as folder names for the data?"}
266        CheckBox IncludeExtensionInName,pos={240,420},size={16,14},proc=IR1I_CheckProc,title="Include Extn?",variable= root:Packages:ImportData:IncludeExtensionInName, help={"Include file extension in imported data foldername?"}, disable=!(root:Packages:ImportData:UseFileNameAsFolder)
267        CheckBox UseIndra2Names,pos={10,436},size={16,14},proc=IR1I_CheckProc,title="Use USAXS names?",variable= root:Packages:ImportData:UseIndra2Names, help={"Use wave names using Indra 2 name structure? (DSM_Int, DSM_Qvec, DSM_Error)"}
268        CheckBox ImportSMRdata,pos={150,436},size={16,14},proc=IR1I_CheckProc,title="Slit smeared?",variable= root:Packages:ImportData:ImportSMRdata, help={"Check if the data are slit smeared, changes suggested Indra data names to SMR_Qvec, SMR_Int, SMR_Error"}
269        CheckBox ImportSMRdata, disable= !root:Packages:ImportData:UseIndra2Names
270        CheckBox UseQRSNames,pos={10,452},size={16,14},proc=IR1I_CheckProc,title="Use QRS wave names?",variable= root:Packages:ImportData:UseQRSNames, help={"Use QRS name structure? (Q_filename, R_filename, S_filename)"}
271        CheckBox UseQISNames,pos={150,452},size={16,14},proc=IR1I_CheckProc,title="Use QIS (NIST) wv nms?",variable= root:Packages:ImportData:UseQISNames, help={"Use QIS name structure? (filename_q, filename_i, filename_s)"}
272
273        CheckBox AutomaticallyOverwrite,pos={300,452},size={16,14},proc=IR1I_CheckProc,title="Auto overwrite?",variable= root:Packages:ImportData:AutomaticallyOverwrite, help={"Automatically overwrite imported data if same data exist?"}, disable=!(root:Packages:ImportData:UseFileNameAsFolder)
274
275        CheckBox ScaleImportedDataCheckbox,pos={10,472},size={16,14},proc=IR1I_CheckProc,title="Scale Imported data?",variable= root:Packages:ImportData:ScaleImportedData, help={"Check to scale (multiply by) factor imported data. Both Intensity and error will be scaled by same number. Insert appriate number right."}
276        SetVariable ScaleImportedDataBy, pos={200,472}, size={140,20},title="Scaling factor?:", proc=IR1I_setvarProc, disable=!(root:Packages:ImportData:ScaleImportedData)
277        SetVariable ScaleImportedDataBy limits={1e-32,inf,1},value= root:packages:ImportData:ScaleImportedDataBy,help={"Input number by which you want to multiply the imported intensity and errors."}
278        CheckBox SlitSmearDataCheckbox,pos={10,490},size={16,14},proc=IR1I_CheckProc,title="Slit Smear Imp. data?",variable= root:Packages:ImportData:SlitSmearData, help={"Check to slit smear imported data. Both Intensity and error will be smeared. Insert appriate number right."}
279        SetVariable SlitLength, pos={200,490}, size={140,20},title="Slit length?:", proc=IR1I_setvarProc, disable=!(root:Packages:ImportData:SlitSmearData)
280        SetVariable SlitLength limits={1e-32,inf,0},value= root:packages:ImportData:SlitLength,help={"Input slit length in Q units."}
281
282        CheckBox RemoveNegativeIntensities,pos={10,507},size={16,14},proc=IR1I_CheckProc,title="Remove Int<=0?",variable= root:Packages:ImportData:RemoveNegativeIntensities, help={"Remove Intensities smaller than 0?"}
283
284        CheckBox TrimData,pos={10,526},size={16,14},proc=IR1I_CheckProc,title="Trim data?",variable= root:Packages:ImportData:TrimData, help={"Check to trim Q range of the imported data."}
285        SetVariable TrimDataQMin, pos={110,524}, size={110,20},title="Qmin=", proc=IR1I_setvarProc, disable=!(root:Packages:ImportData:TrimData)
286        SetVariable TrimDataQMin limits={1e-32,inf,0},value= root:packages:ImportData:TrimDataQMin,help={"Qmin for trimming data. Leave 0 if not trimming at low q is needed."}
287        SetVariable TrimDataQMax, pos={240,524}, size={110,20},title="Qmax=", proc=IR1I_setvarProc, disable=!(root:Packages:ImportData:TrimData)
288        SetVariable TrimDataQMax limits={1e-32,inf,0},value= root:packages:ImportData:TrimDataQMax,help={"Qmax for trimming data. Leave 0 if not trimming at low q is needed."}
289
290        CheckBox ReduceNumPnts,pos={10,543},size={16,14},proc=IR1I_CheckProc,title="Reduce points?",variable= root:Packages:ImportData:ReduceNumPnts, help={"Check to log-reduce number of points"}
291        SetVariable TargetNumberOfPoints, pos={110,541}, size={110,20},title="Num points=", proc=IR1I_setvarProc, disable=!(root:Packages:ImportData:ReduceNumPnts)
292        SetVariable TargetNumberOfPoints limits={10,1000,0},value= root:packages:ImportData:TargetNumberOfPoints,help={"Target number of points after reduction. Uses same method as Data manipualtion I"}
293
294        CheckBox TrunkateStart,pos={10,560},size={16,14},proc=IR1I_CheckProc,title="Truncate start of long names?",variable= root:Packages:ImportData:TrunkateStart, help={"Truncate names longer than 24 characters in front"}
295        CheckBox TrunkateEnd,pos={240,560},size={16,14},proc=IR1I_CheckProc,title="Truncate end of long names?",variable= root:Packages:ImportData:TrunkateEnd, help={"Truncate names longer than 24 characters at the end"}
296        SetVariable RemoveStringFromName, pos={5,578}, size={320,20},title="Remove Str From Name=", noproc
297        SetVariable RemoveStringFromName value= root:packages:ImportData:RemoveStringFromName,help={"Input string to be removed from name, leve empty if none"}
298
299        CheckBox DataCalibratedArbitrary,pos={10,597},size={16,14},mode=1,proc=IR1I_CheckProc,title="Calibration Arbitrary\S \M",variable= root:Packages:ImportData:DataCalibratedArbitrary, help={"Data not calibrated (on relative scale)"}
300        CheckBox DataCalibratedVolume,pos={150,597},size={16,14},mode=1,proc=IR1I_CheckProc,title="Calibration cm\S-1\Msr\S-1\M",variable= root:Packages:ImportData:DataCalibratedVolume, help={"Data calibrated to volume"}
301        CheckBox DataCalibratedWeight,pos={290,597},size={16,14},mode=1,proc=IR1I_CheckProc,title="Calibration cm\S2\Mg\S-1\Msr\S-1\M",variable= root:Packages:ImportData:DataCalibratedWeight, help={"Data calibrated to weight"}
302
303        SetVariable NewDataFolderName, pos={5,620}, size={410,20},title="New data folder:", proc=IR1I_setvarProc
304        SetVariable NewDataFolderName value= root:packages:ImportData:NewDataFolderName,help={"Folder for the new data. Will be created, if does not exist. Use popup above to preselect."}
305        SetVariable NewQwaveName, pos={5,640}, size={320,20},title="Q wave names ", proc=IR1I_setvarProc
306        SetVariable NewQwaveName, value= root:packages:ImportData:NewQWaveName,help={"Input name for the new Q wave"}
307        SetVariable NewIntensityWaveName, pos={5,660}, size={320,20},title="Intensity names", proc=IR1I_setvarProc
308        SetVariable NewIntensityWaveName, value= root:packages:ImportData:NewIntensityWaveName,help={"Input name for the new intensity wave"}
309        SetVariable NewErrorWaveName, pos={5,680}, size={320,20},title="Error wv names", proc=IR1I_setvarProc
310        SetVariable NewErrorWaveName, value= root:packages:ImportData:NewErrorWaveName,help={"Input name for the new Error wave"}
311        SetVariable NewQErrorWaveName, pos={5,700}, size={320,20},title="dQ wv names  ", proc=IR1I_setvarProc
312        SetVariable NewQErrorWaveName, value= root:packages:ImportData:NewQErrorWaveName,help={"Input name for the new Q data Error wave"}
313
314        Button ImportData,pos={330,660},size={80,30}, proc=IR1I_ButtonProc,title="Import"
315        Button ImportData,help={"Import the selected data files."}
316
317        IR1I_CheckProc("UseQRSNames",1)
318
319EndMacro
320
321//************************************************************************************************************
322//************************************************************************************************************
323Function IR1_ImportListBoxProc(lba) : ListBoxControl
324        STRUCT WMListboxAction &lba
325        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
326
327        Variable row = lba.row
328        Variable col = lba.col
329        WAVE/T/Z listWave = lba.listWave
330        WAVE/Z selWave = lba.selWave
331
332        switch( lba.eventCode )
333                case -1: // control being killed
334                        break
335                case 1: // mouse down
336                        break
337                case 3: // double click
338                        IR1I_testImport()
339                        IR1I_TestImportNotebook()
340                        break
341                case 4: // cell selection
342                case 5: // cell selection plus shift key
343                        break
344                case 6: // begin edit
345                        break
346                case 7: // finish edit
347                        break
348                case 13: // checkbox clicked (Igor 6.2 or later)
349                        break
350        endswitch
351
352        return 0
353End
354//************************************************************************************************************
355//************************************************************************************************************
356Function IR1I_ImportDataFnct()
357        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
358
359        string TopPanel=WinName(0, 64)
360        string OldDf = getDataFolder(1)
361       
362        Wave/T WaveOfFiles      = root:Packages:ImportData:WaveOfFiles
363        Wave WaveOfSelections = root:Packages:ImportData:WaveOfSelections
364
365        IR1I_CheckForProperNewFolder()
366        variable i, imax, icount
367        string SelectedFile
368        imax = numpnts(WaveOfSelections)
369        icount = 0
370        for(i=0;i<imax;i+=1)
371                if (WaveOfSelections[i])
372                        selectedfile = WaveOfFiles[i]
373                        IR1I_CreateImportDataFolder(selectedFile)
374                        KillWaves/Z TempIntensity, TempQvector, TempError
375                        IR1I_ImportOneFile(selectedFile)
376                        IR1I_ProcessImpWaves(selectedFile)              //this thing also creates new error waves, removes negative qs and intesities and does everything else
377                        IR1I_RecordResults(selectedFile)
378                        icount+=1
379                endif
380        endfor
381        print "Imported "+num2str(icount)+" data file(s) in total"
382        setDataFolder OldDf
383end
384
385//**********************************************************************************************************
386//**********************************************************************************************************
387//**********************************************************************************************************
388//**********************************************************************************************************
389//replaced by IN2G_RebinLogData(Wx,Wy,NumberOfPoints,MinStep,[Wsdev,Wxwidth,W1, W2, W3, W4, W5])
390//Function  IR1I_ImportRebinData(TempInt,TempQ,TempE,TempQr,NumberOfPoints, LogBinParam)
391//      wave TempInt,TempQ,TempE, TempQr
392//      variable NumberOfPoints, LogBinParam
393//
394//      string OldDf
395//      OldDf = GetDataFOlder(1)
396//      NewDataFolder/O/S root:packages
397//      NewDataFolder/O/S root:packages:TempDataRebin
398//     
399//      //Log rebinning, if requested....
400//      //create log distribution of points...
401//      make/O/D/FREE/N=(NumberOfPoints) tempNewLogDist, tempNewLogDistBinWidth
402//      make/O/D/FREE/N=(NumberOfPoints) Rebinned_TempQ, Rebinned_tempInt, Rebinned_TempErr
403//      variable StartQ, EndQ
404//      variable RealStart, RealEnd, MinStep, StartX,EndX,startOld
405//      if(TempQ[0]<1e-8)
406//              findlevel/P TempQ, 1e-8
407//              startQ=log(TempQ[ceil(V_LevelX)])
408//              RealStart = TempQ[ceil(V_LevelX)]
409//              MinStep = TempQ[ceil(V_LevelX)+1] - TempQ[ceil(V_LevelX)]
410//      else
411//              startQ=log(TempQ[0])
412//              RealStart =TempQ[0]
413//              MinStep = TempQ[1] - TempQ[0]
414//      endif
415//      endQ=log(TempQ[numpnts(TempQ)-1])
416//      RealEnd = TempQ[numpnts(TempQ)-1]
417//      //this did not guarrantee minimum step... Use method developed for Fly USAXS scans 12/2013
418//      StartX = IN2G_FindCorrectLogScaleStart(RealStart,RealEnd,NumberOfPoints,MinStep)
419//      EndX = StartX +(RealEnd - RealStart)
420//      startQ=log(StartX)
421//      endQ = log(EndX)
422//      tempNewLogDist = startQ + p*(endQ-startQ)/numpnts(tempNewLogDist)
423//      tempNewLogDist = 10^(tempNewLogDist)
424//      startOld = tempNewLogDist[0]
425//      tempNewLogDist += RealStart - startOld
426//      tempNewLogDistBinWidth = tempNewLogDist[p+1] - tempNewLogDist[p]
427//      tempNewLogDistBinWidth[numpnts(tempNewLogDistBinWidth)-1] = tempNewLogDistBinWidth[numpnts(tempNewLogDistBinWidth)-2]
428//      Rebinned_tempInt=0
429//      Rebinned_TempErr=0     
430//      variable i, j   //, startIntg=TempQ[1]-TempQ[0]
431//      //first assume that we can step through this easily...
432//      variable cntPoints, BinHighEdge
433//      //variable i will be from 0 to number of new points, moving through destination waves
434//      j=0             //this variable goes through data to be reduced, therefore it goes from 0 to numpnts(TempInt)
435//      For(i=0;i<NumberOfPoints;i+=1)
436//              cntPoints=0
437//              BinHighEdge = tempNewLogDist[i]+tempNewLogDistBinWidth[i]/2
438//              Do
439//                      Rebinned_tempInt[i]+=TempInt[j]
440//                      Rebinned_TempErr[i]+=TempE[j]
441//                      Rebinned_TempQ[i] += TempQ[j]
442//                      cntPoints+=1
443//              j+=1
444//              While(TempQ[j]<BinHighEdge && j<numpnts(TempInt))
445//              Rebinned_tempInt[i]/=   cntPoints
446//              Rebinned_TempErr[i]/=cntPoints
447//              Rebinned_TempQ[i]/=cntPoints
448//      endfor
449//     
450//      Rebinned_TempQ = (Rebinned_TempQ[p]>0) ? Rebinned_TempQ[p] : NaN
451//      //Rebinned_TempQ[numpnts(Rebinned_TempQ)-1]=NaN
452//     
453//      IN2G_RemoveNaNsFrom3Waves(Rebinned_tempInt,Rebinned_TempErr,Rebinned_TempQ)
454//
455//     
456//      Redimension/N=(numpnts(Rebinned_tempInt))/D TempInt,TempQ,TempE, TempQr
457//      TempInt=Rebinned_tempInt
458//      TempQ=Rebinned_TempQ
459//      TempE=Rebinned_TempErr
460//      //temp Qr has changed, it now is represented by Q lmits of the new Q wave
461//     
462//      TempQr = (TempQ[p]-TempQ[p-1])/2 + (TempQ[p+1] - TempQ[p])/2
463//      TempQr[0] = TempQ[1]-TempQ[0]
464//      TempQr[numpnts(TempQ)-1] = TempQ[numpnts(TempQ)-1] - TempQ[numpnts(TempQ)-2]
465//
466//      setDataFolder OldDF
467//      KillDataFolder/Z root:packages:TempDataRebin
468//end
469
470//************************************************************************************************************
471//************************************************************************************************************
472//************************************************************************************************************
473//************************************************************************************************************
474
475Function IR1I_CheckForProperNewFolder()
476        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
477
478        SVAR NewDataFolderName = root:packages:ImportData:NewDataFolderName
479        if (strlen(NewDataFolderName)>0 && cmpstr(":",NewDataFolderName[strlen(NewDataFolderName)-1])!=0)
480                NewDataFolderName = NewDataFolderName + ":"
481        endif
482end
483//************************************************************************************************************
484//************************************************************************************************************
485//************************************************************************************************************
486//************************************************************************************************************
487Function IR1I_RecordResults(selectedFile)
488        string selectedFile     //before or after - that means fit...
489        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
490
491        DFref oldDf= GetDataFolderDFR()
492
493        setdataFolder root:Packages:ImportData
494
495        SVAR DataPathName=root:Packages:ImportData:DataPathName
496        SVAR NewDataFolderName=root:Packages:ImportData:NewDataFolderName
497        SVAR NewIntensityWaveName=root:Packages:ImportData:NewIntensityWaveName
498        SVAR NewQWaveName=root:Packages:ImportData:NewQWaveName
499        SVAR NewErrorWaveName=root:Packages:ImportData:NewErrorWaveName
500        SVAR NewQErrorWaveName=root:Packages:ImportData:NewQErrorWaveName       
501        SVAR RemoveStringFromName=root:Packages:ImportData:RemoveStringFromName
502        string NewFldrNm,NewIntName, NewQName, NewEName, NewQEName, tempFirstPart, tempLastPart
503        NVAR TrunkateStart=root:Packages:ImportData:TrunkateStart       
504        NVAR TrunkateEnd=root:Packages:ImportData:TrunkateEnd   
505       
506        if(stringMatch(NewDataFolderName,"*<fileName>*")==0)
507                NewFldrNm = CleanupName(NewDataFolderName, 1 )
508                NewFldrNm=IR1I_TrunkateName(NewFldrNm,TrunkateStart,TrunkateEnd,RemoveStringFromName)
509        else
510                TempFirstPart = NewDataFolderName[0,strsearch(NewDataFolderName, "<fileName>", 0 )-1]
511                tempLastPart  = NewDataFolderName[strsearch(NewDataFolderName, "<fileName>", 0 )+10,inf]
512                NewFldrNm = TempFirstPart+CleanupName(IR1I_TrunkateName(StringFromList(0,selectedFile,"."),TrunkateStart,TrunkateEnd,RemoveStringFromName), 1 )+tempLastPart
513        endif
514        if(stringMatch(NewIntensityWaveName,"*<fileName>*")==0)
515                NewIntName = CleanupName(NewIntensityWaveName, 1 )
516                NewIntName = IR1I_TrunkateName(NewIntensityWaveName,TrunkateStart,TrunkateEnd,RemoveStringFromName)
517        else
518                TempFirstPart = NewIntensityWaveName[0,strsearch(NewIntensityWaveName, "<fileName>", 0 )-1]
519                tempLastPart  = NewIntensityWaveName[strsearch(NewIntensityWaveName, "<fileName>", 0 )+10,inf]
520                NewIntName = TempFirstPart+IR1I_TrunkateName(StringFromList(0,selectedFile,"."),TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
521                NewIntName = CleanupName(NewIntName, 1 )
522        endif
523        if(stringMatch(NewQwaveName,"*<fileName>*")==0)
524                NewQName = CleanupName(NewQwaveName, 1 )
525                NewQName = IR1I_TrunkateName(NewQwaveName,TrunkateStart,TrunkateEnd,RemoveStringFromName)
526        else
527                TempFirstPart = NewQwaveName[0,strsearch(NewQwaveName, "<fileName>", 0 )-1]
528                tempLastPart  = NewQwaveName[strsearch(NewQwaveName, "<fileName>", 0 )+10,inf]
529                NewQName = TempFirstPart+IR1I_TrunkateName(StringFromList(0,selectedFile,"."),TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
530                NewQName = CleanupName(NewQName, 1 )
531        endif
532        if(stringMatch(NewErrorWaveName,"*<fileName>*")==0)
533                NewEName = CleanupName(NewErrorWaveName, 1 )
534                NewEName = IR1I_TrunkateName(NewErrorWaveName,TrunkateStart,TrunkateEnd,RemoveStringFromName)
535        else
536                TempFirstPart = NewErrorWaveName[0,strsearch(NewErrorWaveName, "<fileName>", 0 )-1]
537                tempLastPart  = NewErrorWaveName[strsearch(NewErrorWaveName, "<fileName>", 0 )+10,inf]
538                NewEName = TempFirstPart+IR1I_TrunkateName(StringFromList(0,selectedFile,"."),TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
539                NewEName = CleanupName(NewEName, 1 )
540        endif
541        if(stringMatch(NewQErrorWaveName,"*<fileName>*")==0)
542                NewQEName = CleanupName(NewQErrorWaveName, 1 )
543                NewQEName=IR1I_TrunkateName(NewQErrorWaveName,TrunkateStart,TrunkateEnd,RemoveStringFromName)
544        else
545                TempFirstPart = NewQErrorWaveName[0,strsearch(NewQErrorWaveName, "<fileName>", 0 )-1]
546                tempLastPart  = NewQErrorWaveName[strsearch(NewQErrorWaveName, "<fileName>", 0 )+10,inf]
547                NewQEName = TempFirstPart+IR1I_TrunkateName(StringFromList(0,selectedFile,"."),TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
548                NewQEName = CleanupName(NewQEName, 1 )
549        endif
550
551        NVAR DataContainErrors=root:Packages:ImportData:DataContainErrors
552        NVAR CreateSQRTErrors=root:Packages:ImportData:CreateSQRTErrors
553        NVAR CreatePercentErrors=root:Packages:ImportData:CreatePercentErrors
554        NVAR PercentErrorsToUse=root:Packages:ImportData:PercentErrorsToUse
555        NVAR ScaleImportedData=root:Packages:ImportData:ScaleImportedData
556        NVAR ScaleImportedDataBy=root:Packages:ImportData:ScaleImportedDataBy
557        NVAR ImportSMRdata=root:Packages:ImportData:ImportSMRdata
558        NVAR SkipLines=root:Packages:ImportData:SkipLines
559        NVAR SkipNumberOfLines =root:Packages:ImportData:SkipNumberOfLines
560        NVAR QvectInA=root:Packages:ImportData:QvectInA
561        NVAR QvectInNM=root:Packages:ImportData:QvectInNM
562
563        NVAR DataCalibratedArbitrary=root:Packages:ImportData:DataCalibratedArbitrary
564        NVAR DataCalibratedVolume=root:Packages:ImportData:DataCalibratedVolume
565        NVAR DataCalibratedWeight=root:Packages:ImportData:DataCalibratedWeight
566
567        IR1_CreateLoggbook()            //this creates the logbook
568        SVAR nbl=root:Packages:SAS_Modeling:NotebookName
569
570        IR1L_AppendAnyText("     ")
571        IR1L_AppendAnyText("***********************************************")
572        IR1L_AppendAnyText("***********************************************")
573        IR1L_AppendAnyText("Data load record ")
574        IR1_InsertDateAndTime(nbl)
575        IR1L_AppendAnyText("File path and file name \t"+DataPathName+selectedFile)
576        IR1L_AppendAnyText(" ")
577        IR1L_AppendAnyText("Loaded on       \t\t\t"+ Date()+"    "+time())
578        IR1L_AppendAnyText("Data stored in : \t\t \t"+ NewFldrNm)
579        IR1L_AppendAnyText("New waves named (Int,q,error) :  \t"+ NewIntName+"\t"+NewQName+"\t"+NewEName)
580        IR1L_AppendAnyText("Comments and processing:")
581        if(DataContainErrors)
582                IR1L_AppendAnyText("Data Contained errors")     
583        elseif(CreateSQRTErrors)
584                IR1L_AppendAnyText("Data did not contain errors, created sqrt(int) errors")     
585        elseif(CreatePercentErrors)
586                IR1L_AppendAnyText("Data did not contain errors, created %(Int) errors, used "+num2str(PercentErrorsToUse)+"  %")       
587        endif
588        if(ScaleImportedData)
589                IR1L_AppendAnyText("Data (Intensity and error) scaled by \t "+num2str(ScaleImportedDataBy))     
590        endif
591        if(QvectInA)
592                IR1L_AppendAnyText("Q was in A")       
593        elseif(QvectInNM)
594                IR1L_AppendAnyText("Q was in nm, scaled to A ")
595        endif
596        if(DataCalibratedArbitrary)
597                IR1L_AppendAnyText("Intensity was imported on relative scale") 
598        elseif(DataCalibratedVolume)
599                IR1L_AppendAnyText("Intensity was imported with volume calibration [cm2/cm3]") 
600        elseif(DataCalibratedWeight)
601                IR1L_AppendAnyText("Intensity was imported with weight calibration [cm2/g]")   
602        endif
603        if(SkipLines)
604                IR1L_AppendAnyText("Following number of lines was skiped from the original file "+num2str(SkipNumberOfLines))   
605        endif
606
607        //and print in history, so user has some feedback...
608        print "Imported data from :"+DataPathName+selectedFile+"\r"
609        print "\tData stored in :\t\t\t"+IR1I_RemoveBadCharacters(NewFldrNm)
610        if(DataContainErrors || CreateSQRTErrors || CreatePercentErrors)
611                print  "\tNew Wave names are :\t"+ IR1I_RemoveBadCharacters(NewIntName)+"\t"+IR1I_RemoveBadCharacters(NewQName)+"\t"+IR1I_RemoveBadCharacters(NewEName)+"\r"
612        else //no errors...
613                print  "\tNew Wave names are :\t"+ NewIntName+"\t"+NewQName+"\r"
614                print  "\tNo errors were loaded or created \r"
615        endif
616        setdataFolder oldDf
617end
618
619
620//************************************************************************************************************
621//************************************************************************************************************
622//************************************************************************************************************
623//************************************************************************************************************
624//************************************************************************************************************
625Function/S IR1I_TrunkateName(InputName,TrunkateStart,TrunkateEnd, RemoveStringFromName)
626        string InputName, RemoveStringFromName
627        variable TrunkateStart,TrunkateEnd
628        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
629       
630        NVAR Igor8UseLongNames = root:Packages:IrenaConfigFolder:Igor8UseLongNames
631        string ModName=ReplaceString(RemoveStringFromName, InputName, "")
632        if(Igor8UseLongNames && IgorVersion()>7.99)             //Igor 8 and user wants long names
633                return IN2G_CreateUserName(ModName,31, 0, 11)
634        endif
635        variable inpuLength=strlen(ModName)
636        variable removePoints=inpuLength - IR1TrimNameLength
637        string TempStr=ModName 
638        if(removePoints>0)
639                if(TrunkateEnd)
640                        tempStr=ModName[0,IR1TrimNameLength-1]
641                elseif(TrunkateStart)
642                        tempStr=ModName[removePoints,inf]
643                endif
644        endif
645        return cleanupName(tempStr,1)
646end
647
648//************************************************************************************************************
649//************************************************************************************************************
650//************************************************************************************************************
651
652Function IR1I_ProcessImpWaves(selectedFile)
653        string selectedFile
654        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
655
656        variable i, numOfInts, numOfQs, numOfErrs, numOfQErrs, refNum
657        numOfInts  = 0
658        numOfQs   = 0
659        numOfErrs = 0
660        numOfQErrs = 0
661        string HeaderFromData=""
662        NVAR SkipNumberOfLines=root:Packages:ImportData:SkipNumberOfLines
663        NVAR SkipLines=root:Packages:ImportData:SkipLines       
664        NVAR FoundNWaves = root:Packages:ImportData:FoundNWaves
665        NVAR TrunkateStart = root:Packages:ImportData:TrunkateStart
666        NVAR TrunkateEnd = root:Packages:ImportData:TrunkateEnd
667        variable GenError=0
668
669        if(!SkipLines)                  //lines automatically skipped, so the header may make sense, add to header...
670                Open/R/P=ImportDataPath refNum as selectedFile
671                HeaderFromData=""
672                Variable j
673               String text
674              For(j=0;j<SkipNumberOfLines;j+=1)
675                     FReadLine refNum, text
676                        HeaderFromData+=ZapNonLetterNumStart(IN2G_ZapControlCodes(text))+";"
677                endfor       
678              Close refNum
679        endif   
680        NVAR DataContainErrors=root:Packages:ImportData:DataContainErrors
681        DataContainErrors=0
682        variable LimitFoundWaves = (FoundNWaves<=6) ? FoundNWaves : 7
683        For(i=0;i<LimitFoundWaves;i+=1)
684                NVAR testIntStr = $("root:Packages:ImportData:Col"+num2str(i+1)+"Int")
685                NVAR testQvecStr = $("root:Packages:ImportData:Col"+num2str(i+1)+"Qvec")
686                NVAR testErrStr = $("root:Packages:ImportData:Col"+num2str(i+1)+"Err")
687                NVAR testQErrStr = $("root:Packages:ImportData:Col"+num2str(i+1)+"QErr")
688                Wave/Z CurrentWave = $("wave"+num2str(i))
689                SVAR DataPathName=root:Packages:ImportData:DataPathName
690                if (testIntStr&&WaveExists(CurrentWave))
691                        duplicate/O CurrentWave, TempIntensity
692                        //print "Data imported from folder="+DataPathName+";Data file name="+selectedFile+";"+HeaderFromData+";"
693                        note/NOCR TempIntensity, "Data imported from folder="+DataPathName+";Data file name="+selectedFile+";Data header (1st line)="+HeaderFromData+";"
694                        //print note(TempIntensity)
695                        numOfInts+=1
696                endif
697                if (testQvecStr&&WaveExists(CurrentWave))
698                        duplicate/O CurrentWave, TempQvector
699                        note/NOCR TempQvector, "Data imported from folder="+DataPathName+";Data file name="+selectedFile+";Data header (1st line)="+HeaderFromData+";"
700                        numOfQs+=1
701                endif
702                if (testErrStr&&WaveExists(CurrentWave))
703                        duplicate/O CurrentWave, TempError
704                        note/NOCR TempError, "Data imported from folder="+DataPathName+";Data file name="+selectedFile+";Data header (1st line)="+HeaderFromData+";"
705                        numOfErrs+=1
706                        DataContainErrors=1
707                endif
708                if (testQErrStr&&WaveExists(CurrentWave))
709                        duplicate/O CurrentWave, TempQError
710                        note TempQError, "Data imported from folder="+DataPathName+";Data file name="+selectedFile+";Data header (1st line)="+HeaderFromData+";"
711                        numOfQErrs+=1
712                endif
713                if(!WaveExists(CurrentWave))
714                        GenError=0
715                        string Messg="Error, the column of data selected did not exist in the data file. The missing column is : "
716                        if(testIntStr)
717                                Messg+="Intensity"
718                                GenError=1
719                        elseif(testQvecStr)
720                                Messg+="Q vector"
721                                GenError=1
722                        elseif(testErrStr)
723                                Messg+="Error"
724                                GenError=1
725                        elseif(testQErrStr)
726                                Messg+="Q Error"
727                                GenError=1
728                        endif
729                        if(GenError)
730                                DoAlert 0, Messg
731                        endif
732                endif
733        endfor
734        if (numOfInts!=1 || numOfQs!=1 || numOfErrs>1|| numOfQErrs>1)
735                Abort "Import waves problem, check values in checkboxes which indicate which column contains Intensity, Q and error"
736        endif
737
738        //here we will modify the data if user wants to do so...
739        NVAR QvectInA=root:Packages:ImportData:QvectInA
740        NVAR QvectInNM=root:Packages:ImportData:QvectInNM
741        NVAR ScaleImportedData=root:Packages:ImportData:ScaleImportedData
742        NVAR ScaleImportedDataBy=root:Packages:ImportData:ScaleImportedDataBy
743        if (QvectInNM)
744                TempQvector=TempQvector/10                      //converts nm-1 in A-1  ???
745                note TempQvector, "Q data converted from nm to A-1;"
746                if(WaveExists(TempQError))
747                        TempQError = TempQError/10
748                        note/NOCR TempQError, "Q error converted from nm to A-1;"
749                endif
750        endif
751        if (ScaleImportedData)
752                TempIntensity=TempIntensity*ScaleImportedDataBy         //scales imported data for user
753                note/NOCR TempIntensity, "Data scaled by="+num2str(ScaleImportedDataBy)+";"
754                if (WaveExists(TempError))
755                        TempError=TempError*ScaleImportedDataBy         //scales imported data for user
756                        note/NOCR TempError, "Data scaled by="+num2str(ScaleImportedDataBy)+";"
757                endif
758        endif
759        //lets insert here the Units into the wave notes...
760        NVAR DataCalibratedArbitrary=root:Packages:ImportData:DataCalibratedArbitrary
761        NVAR DataCalibratedVolume=root:Packages:ImportData:DataCalibratedVolume
762        NVAR DataCalibratedWeight=root:Packages:ImportData:DataCalibratedWeight
763        if(DataCalibratedWeight)
764                note/NOCR TempIntensity, "Units=cm2/g;"
765        elseif(DataCalibratedVolume)
766                note/NOCR TempIntensity, "Units=cm2/cm3;"       
767        elseif(DataCalibratedArbitrary)
768                note/NOCR TempIntensity, "Units=Arbitrary;"     
769        endif
770       
771        //here we will deal with erros, if the user needs to create them
772        NVAR CreateSQRTErrors=root:Packages:ImportData:CreateSQRTErrors
773        NVAR CreatePercentErrors=root:Packages:ImportData:CreatePercentErrors
774        NVAR PercentErrorsToUse=root:Packages:ImportData:PercentErrorsToUse
775        if ((CreatePercentErrors||CreateSQRTErrors) && WaveExists(TempError))   
776                DoAlert 0, "Debugging message: Should create SQRT errors, but error wave exists. Mess in the checkbox values..."
777        endif
778        if (CreatePercentErrors && PercentErrorsToUse<1e-12)
779                DoAlert 0, "You want to create percent error wave, but your error fraction is extremally small. This is likely error, so please, check the number and reimport the data"
780                abort
781        endif
782        if (CreateSQRTErrors && !WaveExists(TempError))
783                Duplicate/O TempIntensity, TempError
784                TempError = sqrt(TempIntensity)
785                note TempError, "Error data created for user as SQRT of intensity;"
786        endif
787        if (CreatePercentErrors && !WaveExists(TempError))
788                Duplicate/O TempIntensity, TempError
789                TempError = TempIntensity * (PercentErrorsToUse/100)
790                note TempError, "Error data created for user as percentage of intensity;Amount of error as percentage="+num2str(PercentErrorsToUse/100)+";"
791        endif
792        //let's clean up the data from negative Qs, if there are any...
793        //data are in           TempQvector, TempIntensity, TempError
794        //w = w[p]==0 ? NaN : w[p]
795        TempQvector = TempQvector[p]<=0 ?  NaN :  TempQvector[p]
796        if(WaveExists(TempError)&&WaveExists(TempQError))       //have 4 waves
797                IN2G_RemoveNaNsFrom4Waves(TempQvector, TempIntensity, TempError,TempQError)
798        elseif(WaveExists(TempError)&&!WaveExists(TempQError))  //have 3 waves
799                IN2G_RemoveNaNsFrom3Waves(TempQvector, TempIntensity, TempError)
800        else    //only 2 waves
801                IN2G_RemoveNaNsFrom2Waves(TempQvector, TempIntensity)
802        endif
803        //just in case, we need to sort the data (some users have data which are not sorted...
804        if(WaveExists(TempError))
805                if(waveExists(TempQError))
806                        sort TempQvector,TempQvector, TempIntensity, TempError,TempQError
807                else
808                        sort TempQvector,TempQvector, TempIntensity, TempError
809                endif
810        else
811                sort TempQvector,TempQvector, TempIntensity
812        endif
813        //smear the data,       this may remove some negative intensities, so do it first
814        NVAR SlitSmearData = root:Packages:ImportData:SlitSmearData
815        NVAR SlitLength = root:Packages:ImportData:SlitLength   
816        if(SlitSmearData && (SlitLength>0))                     //slit smear the data here...
817                Duplicate/Free TempIntensity, TempIntToSmear
818                IR1B_SmearData(TempIntToSmear, TempQvector, SlitLength, TempIntensity) 
819                note/NOCR TempIntensity, "Slitlength="+num2str(SlitLength)+";" 
820                //next smear errors. Assume we can smear them same as intensities for now. Probably incorrect assumption, need to check somehow.
821                if(WaveExists(TempError))               
822                        Duplicate/Free TempError, TempErrorToSmear
823                        IR1B_SmearData(TempErrorToSmear, TempQvector, SlitLength, TempError)   
824                        note/NOCR TempError, "Slitlength="+num2str(SlitLength)+";"                             
825                endif
826                //now we need to sort out the resolution. Two choices - user provided a resolution, needs to be convoluted with slit length here
827                //of user did not provide resolution, need to create here and set = slit length...
828                if(!WaveExists(TempQError))
829                        Duplicate/O TempQvector, TempQError
830                        TempQError = 0
831                endif
832                TempQError = sqrt(TempQError[p]^2+SlitLength^2)
833        endif
834        //add slit length if imported data are slit smeared...
835        NVAR ImportSMRdata=root:Packages:ImportData:ImportSMRdata
836        if(ImportSMRdata)
837                if(SlitLength<0.0001)
838                        //SLit length not set, we need tyo get that set by user...
839                        variable SlitLengthLocal
840                        Prompt SlitLengthLocal, "Bad slit length found, need correct value in [1/A]"
841                        DoPrompt "Missing Slit length input needed", SlitLengthLocal
842                        if(V_Flag)
843                                abort
844                        endif
845                        SlitLength = SlitLengthLocal
846                endif
847                note/NOCR TempIntensity, "Slitlength="+num2str(SlitLength)+";" 
848                if(WaveExists(TempError))               
849                        note/NOCR TempError, "Slitlength="+num2str(SlitLength)+";"                             
850                endif           
851        endif
852       
853        //now remove negative intensities. If there are still some left and asked for.
854        NVAR RemoveNegativeIntensities = root:packages:ImportData:RemoveNegativeIntensities
855        if(RemoveNegativeIntensities)
856                TempIntensity = TempIntensity[p]<=0 ?  NaN :  TempIntensity[p] 
857        endif
858        if(WaveExists(TempError)&&WaveExists(TempQError))       //have 4 waves
859                IN2G_RemoveNaNsFrom4Waves(TempQvector, TempIntensity, TempError,TempQError)
860        elseif(WaveExists(TempError)&&!WaveExists(TempQError))  //have 3 waves
861                IN2G_RemoveNaNsFrom3Waves(TempQvector, TempIntensity, TempError)
862        elseif(!WaveExists(TempError)&&WaveExists(TempQError))  //have 3 waves
863                IN2G_RemoveNaNsFrom3Waves(TempQvector, TempIntensity, TempQError)
864        else    //only 2 waves
865                IN2G_RemoveNaNsFrom2Waves(TempQvector, TempIntensity)
866        endif
867        //all negative qs are removed...
868        //optionally trim the Q range here...
869        NVAR TrimData= root:packages:ImportData:TrimData
870        NVAR TrimDataQMin= root:packages:ImportData:TrimDataQMin
871        NVAR TrimDataQMax= root:packages:ImportData:TrimDataQMax
872        if(TrimData)
873                variable StartPointsToRemove=0
874                if(TrimDataQMin>0)
875                        StartPointsToRemove=binarysearch(TempQvector,TrimDataQMin)
876                endif
877                variable EndPointsToRemove=numpnts(TempQvector)
878                if(TrimDataQMax>0 && TrimDataQMax<TempQvector[inf])
879                        EndPointsToRemove=binarysearch(TempQvector,TrimDataQMax)
880                endif
881                if(TrimDataQMin>0 && StartPointsToRemove>0)
882                        TempQvector[0,StartPointsToRemove]=NaN
883                endif
884                if(TrimDataQMax>0 && TrimDataQMax<TempQvector[inf] && EndPointsToRemove>0)
885                        TempQvector[EndPointsToRemove+1,inf]=NaN
886                endif
887                if(WaveExists(TempError)&&WaveExists(TempQError))       //have 4 waves
888                        IN2G_RemoveNaNsFrom4Waves(TempQvector, TempIntensity, TempError,TempQError)
889                elseif(WaveExists(TempError)&&!WaveExists(TempQError))  //have 3 waves
890                        IN2G_RemoveNaNsFrom3Waves(TempQvector, TempIntensity, TempError)
891                elseif(!WaveExists(TempError)&&WaveExists(TempQError))  //have 3 waves
892                        IN2G_RemoveNaNsFrom3Waves(TempQvector, TempIntensity, TempQError)
893                else    //only 2 waves
894                        IN2G_RemoveNaNsFrom2Waves(TempQvector, TempIntensity)
895                endif
896        endif   
897
898        //here rebind the data down....
899        NVAR ReduceNumPnts= root:packages:ImportData:ReduceNumPnts
900        NVAR TargetNumberOfPoints= root:packages:ImportData:TargetNumberOfPoints
901        if(ReduceNumPnts)
902                variable tempMinStep=TempQvector[1]-TempQvector[0]
903                if(WaveExists(TempError)&&WaveExists(TempQError))       //have 4 waves
904                        IN2G_RebinLogData(TempQvector,TempIntensity,TargetNumberOfPoints,tempMinStep,Wsdev=TempError,Wxsdev=TempQError)
905                elseif(WaveExists(TempError)&&!WaveExists(TempQError))  //have 3 waves
906                        Duplicate/O TempError, TempQError
907                        IN2G_RebinLogData(TempQvector,TempIntensity,TargetNumberOfPoints,tempMinStep,Wsdev=TempError,Wxwidth=TempQError)
908                elseif(!WaveExists(TempError)&&WaveExists(TempQError))  //have 3 waves
909                        Duplicate/O TempQError, TempError
910                        IN2G_RebinLogData(TempQvector,TempIntensity,TargetNumberOfPoints,tempMinStep,Wsdev=TempError,Wxwidth=TempQError)
911                else    //only 2 waves
912                        Duplicate/O TempIntensity, TempError, TempQError
913                        IN2G_RebinLogData(TempQvector,TempIntensity,TargetNumberOfPoints,tempMinStep, Wsdev=TempError, Wxwidth=TempQError)
914                endif
915        endif
916        //check on TempError if it contains meaningful number and stop user if not...
917        if(!WaveExists(TempError))
918                abort "The Errors (Uncertainities) data do NOT exiost. Please, select a method to create them and try again."
919        endif
920        wavestats/Q TempError
921        if((V_min<=0)||(V_numNANs>0)||(V_numINFs>0))
922                abort "The Errors (Uncertainities) contain negative values, 0, NANs, or INFs. This is not acceptable. Import aborted. Please, check the input data or use % or SQRT errors"
923        endif
924
925        SVAR NewIntensityWaveName= root:packages:ImportData:NewIntensityWaveName
926        SVAR NewQwaveName= root:packages:ImportData:NewQWaveName
927        SVAR NewErrorWaveName= root:packages:ImportData:NewErrorWaveName
928        SVAR NewQErrorWaveName= root:packages:ImportData:NewQErrorWaveName
929        SVAR RemoveStringFromName=root:Packages:ImportData:RemoveStringFromName
930        NVAR IncludeExtensionInName=root:packages:ImportData:IncludeExtensionInName
931        string NewIntName, NewQName, NewEName, NewQEName, tempFirstPart, tempLastPart
932       
933        if(stringMatch(NewIntensityWaveName,"*<fileName>*")==0)
934                NewIntName = IR1I_RemoveBadCharacters(NewIntensityWaveName)
935                NewIntName = CleanupName(NewIntName, 1 )
936                NewIntName=IR1I_TrunkateName(NewIntName,TrunkateStart,TrunkateEnd,RemoveStringFromName)
937        else
938                TempFirstPart = NewIntensityWaveName[0,strsearch(NewIntensityWaveName, "<fileName>", 0 )-1]
939                tempLastPart  = NewIntensityWaveName[strsearch(NewIntensityWaveName, "<fileName>", 0 )+10,inf]
940                if(IncludeExtensionInName)
941                        NewIntName = TempFirstPart+IR1I_TrunkateName(selectedFile,TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
942                else
943                        NewIntName = TempFirstPart+IR1I_TrunkateName(StringFromList(0,selectedFile,"."),TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
944                endif
945                NewIntName = IR1I_RemoveBadCharacters(NewIntName)
946                NewIntName = CleanupName(NewIntName, 1 )
947        endif
948        if(stringMatch(NewQwaveName,"*<fileName>*")==0)
949                NewQName =IR1I_RemoveBadCharacters(NewQwaveName)
950                NewQName = CleanupName(NewQName, 1 )
951                NewQName=IR1I_TrunkateName(NewQName,TrunkateStart,TrunkateEnd,RemoveStringFromName)
952        else
953                TempFirstPart = NewQwaveName[0,strsearch(NewQwaveName, "<fileName>", 0 )-1]
954                tempLastPart  = NewQwaveName[strsearch(NewQwaveName, "<fileName>", 0 )+10,inf]
955                if(IncludeExtensionInName)
956                        NewQName = TempFirstPart+IR1I_TrunkateName(selectedFile,TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
957                else
958                        NewQName = TempFirstPart+IR1I_TrunkateName(StringFromList(0,selectedFile,"."),TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
959                endif
960                NewQName =IR1I_RemoveBadCharacters(NewQName)
961                NewQName = CleanupName(NewQName, 1 )
962        endif
963        if(stringMatch(NewErrorWaveName,"*<fileName>*")==0)
964                NewEName =IR1I_RemoveBadCharacters(NewErrorWaveName)
965                NewEName = CleanupName(NewEName, 1 )
966                NewEName=IR1I_TrunkateName(NewEName,TrunkateStart,TrunkateEnd,RemoveStringFromName)
967        else
968                TempFirstPart = NewErrorWaveName[0,strsearch(NewErrorWaveName, "<fileName>", 0 )-1]
969                tempLastPart  = NewErrorWaveName[strsearch(NewErrorWaveName, "<fileName>", 0 )+10,inf]
970                if(IncludeExtensionInName)
971                        NewEName = TempFirstPart+IR1I_TrunkateName(selectedFile,TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
972                else
973                        NewEName = TempFirstPart+IR1I_TrunkateName(StringFromList(0,selectedFile,"."),TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
974                endif
975                NewEName =IR1I_RemoveBadCharacters(NewEName)
976                NewEName = CleanupName(NewEName, 1 )
977        endif
978        if(stringMatch(NewQErrorWaveName,"*<fileName>*")==0)
979                NewQEName =IR1I_RemoveBadCharacters(NewQErrorWaveName)
980                NewQEName = CleanupName(NewQEName, 1 )
981                NewQEName=IR1I_TrunkateName(NewQEName,TrunkateStart,TrunkateEnd,RemoveStringFromName)
982        else
983                TempFirstPart = NewQErrorWaveName[0,strsearch(NewQErrorWaveName, "<fileName>", 0 )-1]
984                tempLastPart  = NewQErrorWaveName[strsearch(NewQErrorWaveName, "<fileName>", 0 )+10,inf]
985                if(IncludeExtensionInName)
986                        NewQEName = TempFirstPart+IR1I_TrunkateName(selectedFile,TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
987                else
988                        NewQEName = TempFirstPart+IR1I_TrunkateName(StringFromList(0,selectedFile,"."),TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
989                endif
990                NewQEName =IR1I_RemoveBadCharacters(NewQEName)
991                NewQEName = CleanupName(NewQEName, 1 )
992        endif
993        NVAr AutomaticallyOverwrite = root:Packages:ImportData:AutomaticallyOverwrite
994        Wave/Z testE=$NewEName
995        Wave/Z testQ=$NewQName
996        Wave/Z testI=$NewIntName
997        Wave/Z testQE=$NewQEName
998        if ((WaveExists(testI) || WaveExists(testQ)||WaveExists(testE)||WaveExists(testQE))&&!AutomaticallyOverwrite)
999                DoAlert 1, "The data of this name : "+NewIntName+" , "+NewQName+ " , "+NewEName+" , or "+NewQEName+"  exist. DO you want to overwrite them?"
1000                if (V_Flag==2)
1001                        abort
1002                endif
1003        elseif((WaveExists(testI) || WaveExists(testQ)||WaveExists(testE)||WaveExists(testQE))&&AutomaticallyOverwrite)
1004                //we ovewrote some data, let's at least know about it
1005                print "The data of this name : "+NewIntName+" , "+NewQName+ " , "+NewEName+" , or "+NewQEName+"  existed. Due to user selection, old data were deleted and replaced with newly imported ones."
1006        endif
1007               
1008        Duplicate/O TempQvector, $NewQName
1009        Duplicate/O TempIntensity, $NewIntName
1010        if(WaveExists(TempError))
1011                Duplicate/O TempError, $NewEName
1012        endif   
1013        if(WaveExists(TempQError))
1014                Duplicate/O TempQError, $NewQEName
1015        else
1016//              //fake resolution here
1017//              Duplicate/Free TempQvector, TempdQvector
1018//              TempdQvector[1,numpnts(TempdQvector)-1]=TempdQvector[p]-TempdQvector[p-1]
1019//              TempdQvector[0]=TempdQvector[1]
1020//              print "Q Resolution not provided, Import function faked them with dQ difference between points. This may be totally wrong, BE AWARE."
1021//              Duplicate/O TempdQvector, $NewQEName
1022        endif   
1023        KillWaves/Z tempError, tempQvector, TempIntensity, TempQError
1024        IR1I_KillAutoWaves()
1025end
1026//************************************************************************************************************
1027//************************************************************************************************************
1028//************************************************************************************************************
1029//************************************************************************************************************
1030Function/S IR1I_RemoveBadCharacters(StringName)
1031        string StringName
1032        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1033       
1034        //here we can clean up what Igor allows but would be major problem with my code, such as ( or ) from names
1035        make/Free/T/N=0 ListOfBadChars
1036        ListOfBadChars = {"(", ")", "{","}","%","&","$","#","@","*"}
1037        variable i
1038        For (i=0;i<numpnts(ListOfBadChars);i+=1)
1039                StringName = ReplaceString(ListOfBadChars[i], StringName, "_" )
1040        endfor
1041        return StringName
1042end
1043//************************************************************************************************************
1044//************************************************************************************************************
1045//************************************************************************************************************
1046//************************************************************************************************************
1047
1048Function IR1I_ImportOneFile(selectedFile)
1049        string selectedFile
1050        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1051               
1052        NVAR SkipNumberOfLines=root:Packages:ImportData:SkipNumberOfLines
1053        NVAR SkipLines=root:Packages:ImportData:SkipLines       
1054                IR1I_KillAutoWaves()
1055                //Variable err
1056        if (SkipLines)
1057                LoadWave/Q/A/D/G/L={0, SkipNumberOfLines, 0, 0, 0}/P=ImportDataPath  selectedfile
1058        else
1059                LoadWave/Q/A/D/G/P=ImportDataPath  selectedfile
1060                //; err = GetRTError(0)
1061                //if (err != 0)
1062                //      String message = GetErrMessage(err)
1063                //      string usermessage
1064                //      sprintf usermessage, "Error loading data: %s\r", message
1065                //      DoAlert /T="Error loading" 0, usermessage
1066                //      err = GetRTError(1)                     // Clear error state
1067                //      abort
1068                //endif
1069                SkipNumberOfLines = IR1I_CountHeaderLines("ImportDataPath", selectedfile)
1070        endif
1071
1072end
1073//************************************************************************************************************
1074//************************************************************************************************************
1075//************************************************************************************************************
1076//************************************************************************************************************
1077
1078Function IR1I_CountHeaderLines(pathName, fileName)
1079        String pathName         // Symbolic path name
1080        String fileName                 // File name or full path
1081        String FirstPoint               //string containing first point number....
1082                        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1083       
1084        Variable refNum = 0
1085       
1086        Open/R/P=$pathName refNum as fileName
1087        if (refNum == 0)
1088                return -1                                               // File was not opened. Probably bad file name.
1089        endif
1090       
1091        Variable tmp
1092        Variable count = 0
1093        String text
1094        do
1095                FReadLine refNum, text
1096                if (strlen(text) == 0)
1097                        break
1098                endif
1099               
1100                sscanf text, "%g", tmp
1101                if (V_flag == 1)                                // Found a number at the start of the line?
1102                        break                                           // This marks the start of the numeric data.
1103                endif
1104//                      if( strsearch(text, FirstPoint, 0) >= 0)
1105//                              break   //found first data point
1106//                      endif             
1107                count += 1
1108        while(1)
1109       
1110        Close refNum
1111       
1112        return count
1113End
1114//************************************************************************************************************
1115//************************************************************************************************************
1116//************************************************************************************************************
1117//************************************************************************************************************
1118
1119Function IR1I_KillAutoWaves()
1120        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1121
1122        variable i
1123        for(i=0;i<=100;i+=1)
1124                Wave/Z test = $("wave"+num2str(i))
1125                KillWaves/Z test
1126        endfor
1127end
1128//************************************************************************************************************
1129//************************************************************************************************************
1130//************************************************************************************************************
1131//************************************************************************************************************
1132
1133Function IR1I_CreateImportDataFolder(selectedFile)
1134        string selectedFile
1135        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1136
1137        SVAR NewDataFolderName = root:packages:ImportData:NewDataFolderName
1138        NVAR IncludeExtensionInName = root:packages:ImportData:IncludeExtensionInName
1139        NVAR TrunkateStart = root:packages:ImportData:TrunkateStart
1140        NVAR TrunkateEnd = root:packages:ImportData:TrunkateEnd
1141        SVAR RemoveStringFromName=root:Packages:ImportData:RemoveStringFromName
1142
1143        variable i
1144        string tempFldrName, tempSelectedFile
1145        setDataFolder root:
1146        For (i=0;i<ItemsInList(NewDataFolderName, ":");i+=1)
1147                tempFldrName = StringFromList(i, NewDataFolderName , ":")
1148                if (cmpstr(tempFldrName,"<fileName>")!=0 )
1149                        if(cmpstr(tempFldrName,"root")!=0)
1150                                NewDataFolder/O/S $(cleanupName(IN2G_RemoveExtraQuote(tempFldrName,1,1),1))
1151                        endif
1152                else
1153                        if(!IncludeExtensionInName)
1154                                selectedFile = stringFromList(0,selectedFile,".")
1155                        endif
1156                        selectedFile=IR1I_TrunkateName(selectedFile,TrunkateStart,TrunkateEnd,RemoveStringFromName)
1157                        selectedFile =IR1I_RemoveBadCharacters(selectedFile)
1158                        selectedFile = CleanupName(selectedFile, 1 )
1159                        NewDataFolder/O/S $selectedFile
1160                endif
1161        endfor
1162end
1163
1164//************************************************************************************************************
1165//************************************************************************************************************
1166//************************************************************************************************************
1167//************************************************************************************************************
1168
1169
1170Function IR1I_PopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl
1171        String ctrlName
1172        Variable popNum
1173        String popStr
1174        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1175
1176        if (Cmpstr(ctrlName,"SelectFolderNewData")==0)
1177                SVAR NewDataFolderName = root:packages:ImportData:NewDataFolderName
1178                NewDataFolderName = popStr
1179                        NVAR UseFileNameAsFolder = root:Packages:ImportData:UseFileNameAsFolder
1180                        if (UseFileNameAsFolder)
1181                                NewDataFolderName+="<fileName>:"
1182                        endif           
1183        endif
1184        if (Cmpstr(ctrlName,"SelectFolderNewData2")==0)
1185                SVAR NewDataFolderName = root:packages:ImportData:NewDataFolderName
1186                if(stringMatch(popStr,"---"))
1187                        NewDataFolderName = "root:ImportedData:"               
1188                else
1189                        NewDataFolderName = popStr
1190                endif
1191                        NVAR UseFileNameAsFolder = root:Packages:ImportData:UseFileNameAsFolder
1192                        if (UseFileNameAsFolder)
1193                                NewDataFolderName+="<fileName>:"
1194                        endif           
1195        endif
1196        if (Cmpstr(ctrlName,"ImportDataType")==0)
1197                SVAR DataTypeToImport=root:Packages:ImportData:DataTypeToImport
1198                DataTypeToImport = popStr
1199                SetVariable Wavelength, win=IR1I_ImportOtherASCIIData, disable = !StringMatch(DataTypeToImport,"Tth-Int")
1200                IR1I_ImportOtherSetNames()
1201        endif
1202End
1203//************************************************************************************************************
1204//************************************************************************************************************
1205//************************************************************************************************************
1206//************************************************************************************************************
1207
1208Function IR1I_SetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl
1209        String ctrlName
1210        Variable varNum
1211        String varStr
1212        String varName
1213        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1214
1215        if (cmpstr(ctrlName,"DataExtensionString")==0)
1216                IR1I_UpdateListOfFilesInWvs()
1217        endif
1218        if (cmpstr(ctrlName,"NameMatchString")==0)
1219                IR1I_UpdateListOfFilesInWvs()
1220        endif
1221        if (cmpstr(ctrlName,"FoundNWaves")==0)
1222                IR1I_FIxCheckboxesForWaveTypes()
1223        endif
1224       
1225End
1226
1227//************************************************************************************************************
1228//************************************************************************************************************
1229//************************************************************************************************************
1230//************************************************************************************************************
1231Function IR1I_ButtonProc(ctrlName) : ButtonControl
1232        String ctrlName
1233        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1234       
1235        if(cmpstr(ctrlName,"SelectDataPath")==0)
1236                IR1I_SelectDataPath()   
1237                IR1I_UpdateListOfFilesInWvs()
1238        endif
1239        if(cmpstr(ctrlName,"TestImport")==0)
1240                IR1I_testImport()
1241        endif
1242        if(cmpstr(ctrlName,"GetHelp")==0)
1243                //Open www manual with the right page
1244                IN2G_OpenWebManual("Irena/ImportData.html")
1245        endif
1246        if(cmpstr(ctrlName,"Preview")==0)
1247                IR1I_TestImportNotebook()
1248        endif
1249        if(cmpstr(ctrlName,"Plot")==0)
1250                IR1I_TestPlotData()
1251        endif
1252        if(cmpstr(ctrlName,"SelectAll")==0)
1253                IR1I_SelectDeselectAll(1)
1254        endif
1255        if(cmpstr(ctrlName,"DeselectAll")==0)
1256                IR1I_SelectDeselectAll(0)
1257        endif
1258        if(cmpstr(ctrlName,"ImportData")==0)
1259                IR1I_ImportDataFnct()
1260        endif
1261        if(cmpstr(ctrlName,"ImportData2")==0)
1262                IR1I_ImportDataFnct2()
1263        endif
1264        if(cmpstr(ctrlName,"ImportDataNexus")==0)
1265                IR1I_ImportDataFnctNexus()
1266        endif
1267        if(cmpstr(ctrlName,"OpenFileInBrowser")==0)
1268                IR1I_NexusOpenHdf5File()
1269        endif
1270
1271End
1272//************************************************************************************************************
1273//************************************************************************************************************
1274//************************************************************************************************************
1275//************************************************************************************************************
1276
1277Function IR1I_SelectDeselectAll(SetNumber)
1278                variable setNumber
1279                IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1280               
1281                Wave WaveOfSelections=root:Packages:ImportData:WaveOfSelections
1282
1283                WaveOfSelections = SetNumber
1284end
1285//************************************************************************************************************
1286//************************************************************************************************************
1287//************************************************************************************************************
1288//************************************************************************************************************
1289Function IR1I_TestImport()
1290        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1291
1292        string TopPanel=WinName(0, 64)
1293       
1294        Wave/T WaveOfFiles      = root:Packages:ImportData:WaveOfFiles
1295        Wave WaveOfSelections = root:Packages:ImportData:WaveOfSelections
1296        NVAR FoundNWaves = root:Packages:ImportData:FoundNWaves
1297        NVAR SkipNumberOfLines=root:Packages:ImportData:SkipNumberOfLines
1298        NVAR SkipLines=root:Packages:ImportData:SkipLines
1299        NVAR NumOfPointsFound=root:Packages:ImportData:NumOfPointsFound
1300        SVAR TooManyPointsWarning=root:Packages:ImportData:TooManyPointsWarning
1301        TooManyPointsWarning=""
1302        FoundNWaves = 0
1303        NumOfPointsFound=0
1304       
1305        variable i, imax, firstSelectedPoint, maxWaves
1306        string SelectedFile
1307        imax = numpnts(WaveOfSelections)
1308        firstSelectedPoint = NaN
1309        For(i=0;i<numpnts(WaveOfSelections);i+=1)
1310                if(WaveOfSelections[i]==1)
1311                        firstSelectedPoint = i
1312                        break
1313                endif
1314        endfor
1315        if (numtype(firstSelectedPoint)==2)
1316                abort
1317        endif
1318        selectedfile = WaveOfFiles[firstSelectedPoint]
1319       
1320        killWaves/Z wave0, wave1, wave2, wave3, wave4, wave5, wave6,wave7,wave8,wave9
1321       
1322        if (SkipLines)
1323                LoadWave/Q/A/D/G/L={0, SkipNumberOfLines, 0, 0, 0}/P=ImportDataPath  selectedfile
1324                FoundNWaves = V_Flag
1325        else
1326                LoadWave/Q/A/D/G/P=ImportDataPath  selectedfile
1327                FoundNWaves = V_Flag
1328        endif
1329        wave wave0
1330        NumOfPointsFound=numpnts(wave0)
1331        if(stringmatch(TopPanel,"IR1I_ImportData"))
1332                if(NumOfPointsFound<300)
1333                        sprintf TooManyPointsWarning, "Found %g data points",NumOfPointsFound
1334                        TitleBox TooManyPointsWarning win=IR1I_ImportData  ,fColor=(0,0,0), disable=0
1335                else
1336                        sprintf TooManyPointsWarning, "%g data points, consider reduction ",NumOfPointsFound
1337                        TitleBox TooManyPointsWarning win=IR1I_ImportData  ,fColor=(65200,0,0), disable=0
1338                endif
1339        endif
1340        //now fix the checkboxes as needed
1341        IR1I_FIxCheckboxesForWaveTypes()
1342end
1343//************************************************************************************************************
1344//************************************************************************************************************
1345//************************************************************************************************************
1346//************************************************************************************************************
1347Function IR1I_TestImportNotebook()
1348        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1349
1350        string TopPanel=WinName(0, 64)
1351        Wave/T WaveOfFiles      = root:Packages:ImportData:WaveOfFiles
1352        Wave WaveOfSelections = root:Packages:ImportData:WaveOfSelections
1353        variable i, imax, firstSelectedPoint, maxWaves
1354        string SelectedFile
1355        imax = numpnts(WaveOfSelections)
1356        firstSelectedPoint = NaN
1357        For(i=0;i<numpnts(WaveOfSelections);i+=1)
1358                if(WaveOfSelections[i]==1)
1359                        firstSelectedPoint = i
1360                        break
1361                endif
1362        endfor
1363        if (numtype(firstSelectedPoint)==2)
1364                abort
1365        endif
1366        selectedfile = WaveOfFiles[firstSelectedPoint]
1367       
1368       
1369        //LoadWave/Q/A/G/P=ImportDataPath  selectedfile
1370        KillWIndow/Z FilePreview
1371        OpenNotebook /K=1 /N=FilePreview /P=ImportDataPath /R /V=1 selectedfile
1372        MoveWindow /W=FilePreview 450, 5, 1000, 400     
1373        AutoPositionWindow/M=0 /R=$(TopPanel) FilePreview
1374end
1375
1376//************************************************************************************************************
1377//************************************************************************************************************
1378//************************************************************************************************************
1379//************************************************************************************************************
1380Function IR1I_TestPlotData()
1381        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1382
1383        string TopPanel=WinName(0, 64)
1384        string OldDf = getDataFolder(1)
1385       
1386        Wave/T WaveOfFiles      = root:Packages:ImportData:WaveOfFiles
1387        Wave WaveOfSelections   = root:Packages:ImportData:WaveOfSelections
1388        NVAR FoundNWaves                        = root:Packages:ImportData:FoundNWaves
1389        variable i, imax, firstSelectedPoint, maxWaves
1390        string SelectedFile
1391        imax = numpnts(WaveOfSelections)
1392        firstSelectedPoint = NaN
1393        For(i=0;i<numpnts(WaveOfSelections);i+=1)
1394                if(WaveOfSelections[i]==1)
1395                        firstSelectedPoint = i
1396                        break
1397                endif
1398        endfor
1399        if (numtype(firstSelectedPoint)==2)
1400                abort
1401        endif
1402        selectedfile = WaveOfFiles[firstSelectedPoint]
1403
1404        NewDataFOlder/O/S root:Packages:IrenaImportTemp
1405        KillWIndow/Z FilePlotPreview
1406        KillWaves/Z TempIntensity, TempQvector, TempError, TempQError
1407        IR1I_KillAutoWaves()
1408        //LoadWave/Q/A/G/P=ImportDataPath  selectedfile
1409        IR1I_ImportOneFile(selectedFile)
1410        variable LimitFoundWaves = (FoundNWaves<=6) ? FoundNWaves : 7
1411        For(i=0;i<LimitFoundWaves;i+=1)
1412                NVAR testIntStr = $("root:Packages:ImportData:Col"+num2str(i+1)+"Int")
1413                NVAR testQvecStr = $("root:Packages:ImportData:Col"+num2str(i+1)+"Qvec")
1414                NVAR testErrStr = $("root:Packages:ImportData:Col"+num2str(i+1)+"Err")
1415                NVAR testQErrStr = $("root:Packages:ImportData:Col"+num2str(i+1)+"QErr")
1416                Wave/Z CurrentWave = $("wave"+num2str(i))
1417                SVAR DataPathName=root:Packages:ImportData:DataPathName
1418                if (testIntStr&&WaveExists(CurrentWave))
1419                        duplicate/O CurrentWave, TempIntensity
1420                endif
1421                if (testQvecStr&&WaveExists(CurrentWave))
1422                        duplicate/O CurrentWave, TempQvector
1423                endif
1424                if (testErrStr&&WaveExists(CurrentWave))
1425                        duplicate/O CurrentWave, TempError
1426                endif
1427                if (testQErrStr&&WaveExists(CurrentWave))
1428                        duplicate/O CurrentWave, TempQError
1429                endif
1430        endfor
1431        Wave/Z TempIntensity
1432        Wave/Z TempQvector
1433        Wave/Z TempError
1434        Wave/Z TempQError
1435        if(WaveExists(TempIntensity) && WaveExists(TempQvector))
1436                Display /K=1/N=FilePlotPreview TempIntensity vs TempQvector as "Preview of the data"
1437                MoveWindow /W=FilePlotPreview 450, 5, 1000, 400
1438                AutoPositionWindow/M=0 /R=$(TopPanel) FilePlotPreview
1439                TextBox/C/N=text0/A=MC selectedfile
1440                if(WaveExists(TempError))
1441                        if(!WaveExists(TempQError))
1442                                ErrorBars TempIntensity Y,wave=(TempError,TempError)
1443                        else
1444                                ErrorBars TempIntensity XY,wave=(TempQError,TempQError),wave=(TempError,TempError)
1445                        endif
1446                endif
1447                DoWindow IR1I_ImportData
1448                if(V_Flag)
1449                        ModifyGraph log=1
1450                endif
1451        endif
1452end
1453
1454//************************************************************************************************************
1455//************************************************************************************************************
1456//************************************************************************************************************
1457//************************************************************************************************************
1458
1459Function IR1I_FIxCheckboxesForWaveTypes()
1460        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1461
1462        string TopPanel=WinName(0, 64)
1463        NVAR FoundNWaves = root:Packages:ImportData:FoundNWaves
1464        variable maxWaves, i
1465        maxWaves = FoundNWaves
1466        if (MaxWaves>6)
1467                MaxWaves = 6
1468        endif
1469
1470        For (i=1;i<=MaxWaves;i+=1)
1471                CheckBox $("Col"+num2str(i)+"Int") disable=0, win=$(TopPanel)
1472                CheckBox $("Col"+num2str(i)+"Qvec") disable=0, win=$(TopPanel) 
1473                CheckBox $("Col"+num2str(i)+"Error") disable=0, win=$(TopPanel) 
1474                CheckBox $("Col"+num2str(i)+"QError") disable=0, win=$(TopPanel) 
1475        endfor
1476        For (i=FoundNWaves+1;i<=6;i+=1)
1477                CheckBox $("Col"+num2str(i)+"Int") disable=1, win=$(TopPanel) 
1478                CheckBox $("Col"+num2str(i)+"Qvec") disable=1, win=$(TopPanel) 
1479                CheckBox $("Col"+num2str(i)+"Error") disable=1, win=$(TopPanel) 
1480                CheckBox $("Col"+num2str(i)+"QError") disable=1, win=$(TopPanel) 
1481                NVAR ColInt=$("root:Packages:ImportData:Col"+num2str(i)+"Int")
1482                NVAR ColQvec=$("root:Packages:ImportData:Col"+num2str(i)+"Qvec")
1483                NVAR ColErr=$("root:Packages:ImportData:Col"+num2str(i)+"Err")
1484                NVAR ColQErr=$("root:Packages:ImportData:Col"+num2str(i)+"QErr")
1485                ColInt=0
1486                ColQvec=0
1487                ColErr=0
1488                ColQErr=0
1489        endfor
1490       
1491        NVAR Col1QErr=root:Packages:ImportData:Col1QErr
1492        NVAR Col2QErr=root:Packages:ImportData:Col2QErr
1493        NVAR Col3QErr=root:Packages:ImportData:Col3QErr
1494        NVAR Col4QErr=root:Packages:ImportData:Col4QErr
1495        NVAR Col5QErr=root:Packages:ImportData:Col5QErr
1496        NVAR Col6QErr=root:Packages:ImportData:Col6QErr
1497        if(Col6QErr || Col5QErr || Col4QErr || Col3QErr || Col2QErr || Col1QErr)
1498                SetVariable NewQErrorWaveName, disable = 0
1499        else   
1500                SetVariable NewQErrorWaveName, disable = 1
1501        endif
1502
1503end
1504
1505
1506//************************************************************************************************************
1507//************************************************************************************************************
1508//************************************************************************************************************
1509//************************************************************************************************************
1510
1511Function IR1I_SelectDataPath()
1512        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1513
1514        NewPath /M="Select path to data to be imported" /O ImportDataPath
1515        if (V_Flag!=0)
1516                abort
1517        endif
1518        PathInfo ImportDataPath
1519        SVAR DataPathName=root:Packages:ImportData:DataPathName
1520        DataPathName = S_Path
1521end
1522//************************************************************************************************************
1523//************************************************************************************************************
1524//************************************************************************************************************
1525//************************************************************************************************************
1526
1527Function IR1I_CheckProc(ctrlName,checked) : CheckBoxControl
1528        String ctrlName
1529        Variable checked
1530        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
1531        string TopPanel=WinName(0, 64)
1532       
1533        NVAR Col1Int=root:Packages:ImportData:Col1Int
1534        NVAR Col1Qvec=root:Packages:ImportData:Col1Qvec
1535        NVAR Col1Err=root:Packages:ImportData:Col1Err
1536        NVAR Col1QErr=root:Packages:ImportData:Col1QErr
1537
1538        NVAR Col2Int=root:Packages:ImportData:Col2Int
1539        NVAR Col2Qvec=root:Packages:ImportData:Col2Qvec
1540        NVAR Col2Err=root:Packages:ImportData:Col2Err
1541        NVAR Col2QErr=root:Packages:ImportData:Col2QErr
1542
1543        NVAR Col3Int=root:Packages:ImportData:Col3Int
1544        NVAR Col3Qvec=root:Packages:ImportData:Col3Qvec
1545        NVAR Col3Err=root:Packages:ImportData:Col3Err
1546        NVAR Col3QErr=root:Packages:ImportData:Col3QErr
1547
1548        NVAR Col4Int=root:Packages:ImportData:Col4Int
1549        NVAR Col4Qvec=root:Packages:ImportData:Col4Qvec
1550        NVAR Col4Err=root:Packages:ImportData:Col4Err
1551        NVAR Col4QErr=root:Packages:ImportData:Col4QErr
1552
1553        NVAR Col5Int=root:Packages:ImportData:Col5Int
1554        NVAR Col5Qvec=root:Packages:ImportData:Col5Qvec
1555        NVAR Col5Err=root:Packages:ImportData:Col5Err
1556        NVAR Col5QErr=root:Packages:ImportData:Col5QErr
1557
1558        NVAR Col6Int=root:Packages:ImportData:Col6Int
1559        NVAR Col6Qvec=root:Packages:ImportData:Col6Qvec
1560        NVAR Col6Err=root:Packages:ImportData:Col6Err
1561        NVAR Col6QErr=root:Packages:ImportData:Col6QErr
1562
1563        NVAR QvectInA=root:Packages:ImportData:QvectInA
1564        NVAR QvectInNM=root:Packages:ImportData:QvectInNM
1565        NVAR CreateSQRTErrors=root:Packages:ImportData:CreateSQRTErrors
1566        NVAR CreatePercentErrors=root:Packages:ImportData:CreatePercentErrors
1567
1568        NVAR UseFileNameAsFolder = root:Packages:ImportData:UseFileNameAsFolder
1569        NVAR UseIndra2Names = root:Packages:ImportData:UseIndra2Names
1570        NVAR UseQRSNames = root:Packages:ImportData:UseQRSNames
1571        NVAR UseQISNames = root:Packages:ImportData:UseQISNames
1572
1573        NVAR SkipLines = root:Packages:ImportData:SkipLines
1574        NVAR SkipNumberOfLines = root:Packages:ImportData:SkipNumberOfLines
1575        NVAR DataContainErrors=root:Packages:ImportData:DataContainErrors
1576
1577        NVAR TrunkateStart = root:Packages:ImportData:TrunkateStart
1578        NVAR TrunkateEnd = root:Packages:ImportData:TrunkateEnd
1579
1580        NVAR SlitSmearData = root:Packages:ImportData:SlitSmearData
1581        NVAR SlitLength = root:Packages:ImportData:SlitLength
1582        NVAR ImportSMRdata=root:Packages:ImportData:ImportSMRdata
1583       
1584        SVAR NewDataFolderName = root:packages:ImportData:NewDataFolderName
1585        SVAR NewIntensityWaveName= root:packages:ImportData:NewIntensityWaveName
1586        SVAR NewQwaveName= root:packages:ImportData:NewQWaveName
1587        SVAR NewErrorWaveName= root:packages:ImportData:NewErrorWaveName
1588        SVAR NewQErrorWaveName= root:packages:ImportData:NewQErrorWaveName
1589
1590        NVAR UseFileNameAsFolder= root:Packages:ImportData:UseFileNameAsFolder
1591        NVAR UsesasEntryNameAsFolder= root:Packages:ImportData:UsesasEntryNameAsFolder
1592        NVAR UseTitleNameAsFolder= root:Packages:ImportData:UseTitleNameAsFolder
1593        if(cmpstr(ctrlName,"UseFileNameAsFolderNX")==0)
1594                //UseFileNameAsFolder = 0
1595                UsesasEntryNameAsFolder = 0
1596                UseTitleNameAsFolder = 0
1597        endif
1598        if(cmpstr(ctrlName,"UsesasEntryNameAsFolderNX")==0)     
1599                UseFileNameAsFolder = 0
1600                //UsesasEntryNameAsFolder = 0
1601                UseTitleNameAsFolder = 0
1602        endif
1603        if(cmpstr(ctrlName,"UseTitleNameAsFolderNX")==0)       
1604                UseFileNameAsFolder = 0
1605                UsesasEntryNameAsFolder = 0
1606                //UseTitleNameAsFolder = 0
1607        endif
1608       
1609        NVAR DataCalibratedArbitrary = root:Packages:ImportData:DataCalibratedArbitrary
1610        NVAR DataCalibratedVolume = root:Packages:ImportData:DataCalibratedVolume
1611        NVAR DataCalibratedWeight = root:Packages:ImportData:DataCalibratedWeight
1612        if(cmpstr(ctrlName,"DataCalibratedArbitrary")==0)       
1613                //DataCalibratedArbitrary = 0
1614                DataCalibratedVolume = 0
1615                DataCalibratedWeight = 0
1616        endif
1617        if(cmpstr(ctrlName,"DataCalibratedVolume")==0) 
1618                DataCalibratedArbitrary = 0
1619                //DataCalibratedVolume = 0
1620                DataCalibratedWeight = 0
1621        endif
1622        if(cmpstr(ctrlName,"DataCalibratedWeight")==0) 
1623                DataCalibratedArbitrary = 0
1624                DataCalibratedVolume = 0
1625                //DataCalibratedWeight = 0
1626        endif
1627
1628
1629
1630        NVAR DataCalibratedArbitrary = root:Packages:ImportData:DataCalibratedArbitrary
1631        NVAR DataCalibratedVolume = root:Packages:ImportData:DataCalibratedVolume
1632        NVAR DataCalibratedWeight = root:Packages:ImportData:DataCalibratedWeight
1633        if(cmpstr(ctrlName,"DataCalibratedArbitrary")==0)       
1634                //DataCalibratedArbitrary = 0
1635                DataCalibratedVolume = 0
1636                DataCalibratedWeight = 0
1637        endif
1638        if(cmpstr(ctrlName,"DataCalibratedVolume")==0) 
1639                DataCalibratedArbitrary = 0
1640                //DataCalibratedVolume = 0
1641                DataCalibratedWeight = 0
1642        endif
1643        if(cmpstr(ctrlName,"DataCalibratedWeight")==0) 
1644                DataCalibratedArbitrary = 0
1645                DataCalibratedVolume = 0
1646                //DataCalibratedWeight = 0
1647        endif
1648
1649        if(cmpstr(ctrlName,"SlitSmearDataCheckbox")==0)
1650                if(checked)
1651                        SetVariable SlitLength, disable=0
1652                        if(UseIndra2Names)
1653                                ImportSMRdata=1
1654                        endif
1655                        DoAlert /T="Just checking..." 1, "Do you really want to slit smear imported data?"
1656                        if(V_Flag>1)
1657                                ImportSMRdata=0
1658                                SetVariable SlitLength, disable=1
1659                                NVAR SlitSmearData = root:Packages:ImportData:SlitSmearData
1660                                SlitSmearData = 0
1661                        endif
1662                else
1663                        SetVariable SlitLength, disable=1
1664                        if(UseIndra2Names)
1665                                ImportSMRdata=0
1666                        endif
1667                endif
1668                IR1I_CheckProc("UseIndra2Names",UseIndra2Names)
1669        endif
1670
1671
1672        if(cmpstr(ctrlName,"UseFileNameAsFolder")==0)   
1673                CheckBox IncludeExtensionInName, disable=!(checked)
1674                if (checked && UseIndra2Names)
1675                        CheckBox ImportSMRdata, disable=0
1676                else
1677                        CheckBox ImportSMRdata, disable=1
1678                endif
1679                if(!checked)
1680                        //UseFileNameAsFolder = 1
1681                        //UseQRSNames = 0
1682                        UseIndra2Names = 0
1683                        if (!UseQRSNames)
1684                                NewDataFolderName = "" 
1685                                NewIntensityWaveName= ""
1686                                NewQwaveName= ""
1687                                NewErrorWaveName= ""
1688                        endif
1689                        if (stringmatch(NewDataFolderName, "*<fileName>*"))
1690                                NewDataFolderName = RemoveFromList("<fileName>", NewDataFolderName , ":")
1691                        endif
1692                else
1693                        if (!stringmatch(NewDataFolderName, "*<fileName>*"))
1694                                if(strlen(NewDataFolderName)==0)
1695                                        NewDataFolderName="root:"
1696                                endif
1697                                NewDataFolderName+="<fileName>:"
1698                        endif           
1699                endif
1700        endif
1701        if(cmpstr(ctrlName,"UseIndra2Names")==0)
1702                CheckBox ImportSMRdata, disable= !checked
1703                if(checked)
1704                        UseFileNameAsFolder = 1
1705                        UseQRSNames = 0
1706                        UseQISNames = 0
1707                        //UseIndra2Names = 0
1708                        if (ImportSMRdata)
1709                                NewDataFolderName = "root:USAXS:ImportedData:<fileName>:"       
1710                                NewIntensityWaveName= "SMR_Int"
1711                                NewQwaveName= "SMR_Qvec"
1712                                NewErrorWaveName= "SMR_Error"
1713                                NewQErrorWavename = "SMR_dQ"
1714                        else
1715                                NewDataFolderName = "root:USAXS:ImportedData:<fileName>:"       
1716                                NewIntensityWaveName= "DSM_Int"
1717                                NewQwaveName= "DSM_Qvec"
1718                                NewErrorWaveName= "DSM_Error"
1719                                NewQErrorWavename = "DSM_dQ"
1720                        endif
1721                endif
1722        endif
1723
1724        if(cmpstr(ctrlName,"ImportSMRdata")==0)
1725                NVAR UseIndra2Names=root:Packages:ImportData:UseIndra2Names
1726                if(checked)
1727                        UseFileNameAsFolder = 1
1728                        UseQRSNames = 0
1729                        UseQISNames = 0
1730                        SetVariable SlitLength, disable=0
1731                        //UseIndra2Names = 0
1732                        if (UseIndra2Names)
1733                                NewDataFolderName = "root:USAXS:ImportedData:<fileName>:"       
1734                                NewIntensityWaveName= "SMR_Int"
1735                                NewQwaveName= "SMR_Qvec"
1736                                NewErrorWaveName= "SMR_Error"
1737                                NewQErrorWavename = "SMR_dQ"
1738                        endif
1739                else
1740                        SetVariable SlitLength, disable=1
1741                        if (UseIndra2Names)
1742                                NewDataFolderName = "root:USAXS:ImportedData:<fileName>:"       
1743                                NewIntensityWaveName= "DSM_Int"
1744                                NewQwaveName= "DSM_Qvec"
1745                                NewErrorWaveName= "DSM_Error"
1746                                NewQErrorWavename = "DSM_dQ"
1747                        endif
1748                endif
1749        endif
1750
1751
1752        if(cmpstr(ctrlName,"UseQRSNames")==0)
1753                if (!checked && UseIndra2Names)
1754                        CheckBox ImportSMRdata, disable=0
1755                else
1756                        CheckBox ImportSMRdata, disable=1
1757                endif
1758                if(checked)
1759                        //UseFileNameAsFolder = 1
1760                        UseQISNames = 0
1761                        UseIndra2Names = 0
1762                        NewDataFolderName = "root:SAS:ImportedData:"   
1763                        if (UseFileNameAsFolder)
1764                                NewDataFolderName+="<fileName>:"
1765                        endif           
1766                        NewIntensityWaveName= "R_<fileName>"
1767                        NewQwaveName= "Q_<fileName>"
1768                        NewErrorWaveName= "S_<fileName>"
1769                        NewQErrorWaveName= "W_<fileName>"
1770                endif
1771        endif
1772        if(cmpstr(ctrlName,"UseQISNames")==0)
1773                if (!checked && UseIndra2Names)
1774                        CheckBox ImportSMRdata, disable=0
1775                else
1776                        CheckBox ImportSMRdata, disable=1
1777                endif
1778                if(checked)
1779                        //UseFileNameAsFolder = 1
1780                        UseQRSNames = 0
1781                        UseIndra2Names = 0
1782                        NewDataFolderName = "root:"     
1783                        //if (UseFileNameAsFolder)
1784                                NewDataFolderName+="<fileName>:"
1785                        //endif         
1786                        NewIntensityWaveName= "<fileName>_i"
1787                        NewQwaveName= "<fileName>_q"
1788                        NewErrorWaveName= "<fileName>_s"
1789                        NewQErrorWaveName= "<fileName>_w"
1790                endif
1791        endif
1792       
1793        if(cmpstr(ctrlName,"QvectorInA")==0)
1794                if(checked)
1795                        QvectInNM = 0
1796                else
1797                        QvectInNM = 1
1798                endif
1799        endif
1800        if(cmpstr(ctrlName,"QvectorInNM")==0)
1801                if(checked)
1802                        QvectInA = 0
1803                else
1804                        QvectInA = 1   
1805                endif
1806        endif
1807
1808        if(cmpstr(ctrlName,"TrimData")==0)
1809                                SetVariable TrimDataQMin, win=$(TopPanel) , disable=!(checked)
1810                                SetVariable TrimDataQMax, win=$(TopPanel) , disable=!(checked)
1811        endif
1812        if(cmpstr(ctrlName,"TrunkateStart")==0)
1813                        if(checked)
1814                                TrunkateEnd=0
1815                        else
1816                                TrunkateEnd=1
1817                        endif
1818        endif
1819
1820        if(cmpstr(ctrlName,"TrunkateEnd")==0)
1821                        if(checked)
1822                                TrunkateStart=0
1823                        else
1824                                TrunkateStart=1
1825                        endif
1826        endif
1827
1828        if(cmpstr(ctrlName,"Col1Int")==0)
1829                //fix others for col 1
1830                if(checked)
1831                        //Col1Int=0
1832                        Col2Int=0
1833                        Col3Int=0
1834                        Col4Int=0
1835                        Col5Int=0
1836                        Col6Int=0
1837                        Col1Qvec=0
1838                        Col1Err=0                       
1839                        Col1QErr=0                     
1840                endif
1841        endif
1842        if(cmpstr(ctrlName,"Col1Qvec")==0)
1843                        Col1Int=0
1844                        //Col1Qvec=0
1845                        Col2Qvec=0
1846                        Col3Qvec=0
1847                        Col4Qvec=0
1848                        Col5Qvec=0
1849                        Col6Qvec=0
1850                        Col1Err=0                       
1851                        Col1QErr=0                     
1852        endif
1853        if(cmpstr(ctrlName,"Col1Error")==0)
1854                        Col1Int=0
1855                        Col1Qvec=0
1856                        //Col1Err=0                     
1857                        Col2Err=0                       
1858                        Col3Err=0                       
1859                        Col4Err=0                       
1860                        Col5Err=0                       
1861                        Col6Err=0                       
1862                        Col1QErr=0             
1863        endif
1864        if(cmpstr(ctrlName,"Col1QError")==0)
1865                        Col1Int=0
1866                        Col1Qvec=0
1867                        //Col1Err=0                     
1868                        Col2QErr=0                     
1869                        Col3QErr=0                     
1870                        Col4QErr=0                     
1871                        Col5QErr=0                     
1872                        Col6QErr=0                     
1873                        Col1Err=0                       
1874        endif
1875
1876
1877        if(cmpstr(ctrlName,"Col2Int")==0)
1878                if(checked)
1879                        Col1Int=0
1880                        //Col2Int=0
1881                        Col3Int=0
1882                        Col4Int=0
1883                        Col5Int=0
1884                        Col6Int=0
1885                        Col2Qvec=0
1886                        Col2Err=0                       
1887                        Col2QErr=0                     
1888                endif
1889        endif
1890        if(cmpstr(ctrlName,"Col2Qvec")==0)
1891                        Col2Int=0
1892                        Col1Qvec=0
1893                        //Col2Qvec=0
1894                        Col3Qvec=0
1895                        Col4Qvec=0
1896                        Col5Qvec=0
1897                        Col6Qvec=0
1898                        Col2Err=0                       
1899                        Col2QErr=0                     
1900        endif
1901        if(cmpstr(ctrlName,"Col2Error")==0)
1902                        Col2Int=0
1903                        Col2Qvec=0
1904                        Col1Err=0                       
1905                        //Col2Err=0                     
1906                        Col3Err=0                       
1907                        Col4Err=0                       
1908                        Col5Err=0                       
1909                        Col6Err=0                       
1910                        Col2QErr=0                     
1911        endif
1912        if(cmpstr(ctrlName,"Col2QError")==0)
1913                        Col2Int=0
1914                        Col2Qvec=0
1915                        Col1QErr=0                     
1916                        //Col2Err=0                     
1917                        Col3QErr=0                     
1918                        Col4QErr=0                     
1919                        Col5QErr=0                     
1920                        Col6QErr=0                     
1921                        Col2Err=0                       
1922        endif
1923       
1924        if(cmpstr(ctrlName,"Col3Int")==0)
1925                if(checked)
1926                        Col1Int=0
1927                        Col2Int=0
1928                        //Col3Int=0
1929                        Col4Int=0
1930                        Col5Int=0
1931                        Col6Int=0
1932                        Col3Qvec=0
1933                        Col3Err=0                       
1934                        Col3QErr=0                     
1935                endif
1936        endif
1937        if(cmpstr(ctrlName,"Col3Qvec")==0)
1938                        Col3Int=0
1939                        Col1Qvec=0
1940                        Col2Qvec=0
1941                        //Col3Qvec=0
1942                        Col4Qvec=0
1943                        Col5Qvec=0
1944                        Col6Qvec=0
1945                        Col3Err=0                       
1946                        Col3QErr=0                     
1947        endif
1948        if(cmpstr(ctrlName,"Col3Error")==0)
1949                        Col3Int=0
1950                        Col3Qvec=0
1951                        Col1Err=0                       
1952                        Col2Err=0                       
1953                        //Col3Err=0                     
1954                        Col4Err=0                       
1955                        Col5Err=0                       
1956                        Col6Err=0                       
1957                        Col3QErr=0                     
1958        endif
1959        if(cmpstr(ctrlName,"Col3QError")==0)
1960                        Col3Int=0
1961                        Col3Qvec=0
1962                        Col1QErr=0                     
1963                        Col2QErr=0                     
1964                        //Col3Err=0                     
1965                        Col4QErr=0                     
1966                        Col5QErr=0                     
1967                        Col6QErr=0                     
1968                        Col3Err=0                       
1969        endif
1970       
1971        if(cmpstr(ctrlName,"Col4Int")==0)
1972                if(checked)
1973                        Col1Int=0
1974                        Col2Int=0
1975                        Col3Int=0
1976                        //Col4Int=0
1977                        Col5Int=0
1978                        Col6Int=0
1979                        Col4Qvec=0
1980                        Col4Err=0                       
1981                        Col4QErr=0                     
1982                endif
1983        endif
1984        if(cmpstr(ctrlName,"Col4Qvec")==0)
1985                        Col4Int=0
1986                        Col1Qvec=0
1987                        Col2Qvec=0
1988                        Col3Qvec=0
1989                        //Col4Qvec=0
1990                        Col5Qvec=0
1991                        Col6Qvec=0
1992                        Col4Err=0                       
1993                        Col4QErr=0                     
1994        endif
1995        if(cmpstr(ctrlName,"Col4Error")==0)
1996                        Col4Int=0
1997                        Col4Qvec=0
1998                        Col1Err=0                       
1999                        Col2Err=0                       
2000                        Col3Err=0                       
2001                        //Col4Err=0                     
2002                        Col5Err=0                       
2003                        Col6Err=0                       
2004                        Col4QErr=0                     
2005        endif
2006        if(cmpstr(ctrlName,"Col4QError")==0)
2007                        Col4Int=0
2008                        Col4Qvec=0
2009                        Col1QErr=0                     
2010                        Col2QErr=0                     
2011                        Col3QErr=0                     
2012                        //Col4Err=0                     
2013                        Col5QErr=0                     
2014                        Col6QErr=0                     
2015                        Col4Err=0                       
2016        endif
2017
2018        if(cmpstr(ctrlName,"Col5Int")==0)
2019                if(checked)
2020                        Col1Int=0
2021                        Col2Int=0
2022                        Col3Int=0
2023                        Col4Int=0
2024                        //Col5Int=0
2025                        Col6Int=0
2026                        Col5Qvec=0
2027                        Col5Err=0                       
2028                        Col5QErr=0                     
2029                endif
2030        endif
2031        if(cmpstr(ctrlName,"Col5Qvec")==0)
2032                        Col5Int=0
2033                        Col1Qvec=0
2034                        Col2Qvec=0
2035                        Col3Qvec=0
2036                        Col4Qvec=0
2037                        //Col5Qvec=0
2038                        Col6Qvec=0
2039                        Col5Err=0                       
2040                        Col5QErr=0                     
2041        endif
2042        if(cmpstr(ctrlName,"Col5Error")==0)
2043                        Col5Int=0
2044                        Col5Qvec=0
2045                        Col1Err=0                       
2046                        Col2Err=0                       
2047                        Col3Err=0                       
2048                        Col4Err=0                       
2049                        //Col5Err=0                     
2050                        Col6Err=0                       
2051                        Col5QErr=0                     
2052        endif
2053        if(cmpstr(ctrlName,"Col5QError")==0)
2054                        Col5Int=0
2055                        Col5Qvec=0
2056                        Col1QErr=0                     
2057                        Col2QErr=0                     
2058                        Col3QErr=0                     
2059                        Col4QErr=0                     
2060                        //Col5Err=0                     
2061                        Col6QErr=0                     
2062                        Col5Err=0                       
2063        endif
2064
2065        if(cmpstr(ctrlName,"Col6Int")==0)
2066                if(checked)
2067                        Col1Int=0
2068                        Col2Int=0
2069                        Col3Int=0
2070                        Col4Int=0
2071                        Col5Int=0
2072                        //Col6Int=0
2073                        Col6Qvec=0
2074                        Col6Err=0                       
2075                        Col6QErr=0                     
2076                endif
2077        endif
2078        if(cmpstr(ctrlName,"Col6Qvec")==0)
2079                        Col6Int=0
2080                        Col1Qvec=0
2081                        Col2Qvec=0
2082                        Col3Qvec=0
2083                        Col4Qvec=0
2084                        Col5Qvec=0
2085                        //Col6Qvec=0
2086                        Col6Err=0                       
2087                        Col6QErr=0                     
2088        endif
2089        if(cmpstr(ctrlName,"Col6Error")==0)
2090                        Col6Int=0
2091                        Col6Qvec=0
2092                        Col1Err=0                       
2093                        Col2Err=0                       
2094                        Col3Err=0                       
2095                        Col4Err=0                       
2096                        Col5Err=0                       
2097                        //Col6Err=0                     
2098                        Col6QErr=0                     
2099        endif
2100        if(cmpstr(ctrlName,"Col6QError")==0)
2101                        Col6Int=0
2102                        Col6Qvec=0
2103                        Col1QErr=0                     
2104                        Col2QErr=0                     
2105                        Col3QErr=0                     
2106                        Col4QErr=0                     
2107                        Col5QErr=0                     
2108                        //Col6Err=0                     
2109                        Col6Err=0                       
2110        endif
2111        if(stringmatch(TopPanel,"IR1I_ImportData") || stringmatch(TopPanel,"IR1I_ImportOtherASCIIData") )
2112                if (Col1Err || Col2Err || Col3Err || Col4Err || Col5Err || Col6Err)
2113                        CheckBox CreateSQRTErrors, disable=1, win=$(TopPanel)
2114                        CheckBox CreatePercentErrors, disable=1, win=$(TopPanel)
2115                        CreateSQRTErrors=0
2116                        CreatePercentErrors=0
2117                        SetVariable PercentErrorsToUse, disable=1
2118                else
2119                        CheckBox CreateSQRTErrors, disable=0, win=$(TopPanel)
2120                        CheckBox CreatePercentErrors, disable=0, win=$(TopPanel)
2121                        SetVariable PercentErrorsToUse, disable=!(CreatePercentErrors)
2122                endif
2123               
2124                if(Col6QErr || Col5QErr || Col4QErr || Col3QErr || Col2QErr || Col1QErr)
2125                        SetVariable NewQErrorWaveName, disable = 0
2126                else   
2127                        SetVariable NewQErrorWaveName, disable = 1
2128                endif
2129        endif   
2130        if(cmpstr(ctrlName,"CreateSQRTErrors")==0)
2131                if(checked)
2132                        CreatePercentErrors=0
2133                        SetVariable PercentErrorsToUse, disable=1
2134                endif
2135        endif
2136        if(cmpstr(ctrlName,"CreatePercentErrors")==0)
2137                if(checked)
2138                        CreateSQRTErrors=0
2139                        SetVariable PercentErrorsToUse, disable=0
2140                else
2141                        SetVariable PercentErrorsToUse, disable=1
2142                endif
2143        endif
2144        if(cmpstr(ctrlName,"ReduceNumPnts")==0)
2145                if(checked)
2146                        SetVariable TargetNumberOfPoints, disable=0
2147                        //SetVariable ReducePntsParam, disable=0       
2148                else
2149                        SetVariable TargetNumberOfPoints, disable=1
2150                        //SetVariable ReducePntsParam, disable=1
2151                endif
2152        endif
2153       
2154        if(cmpstr(ctrlName,"ScaleImportedDataCheckbox")==0)
2155                if(checked)
2156                        SetVariable ScaleImportedDataBy, disable=0
2157                else
2158                        SetVariable ScaleImportedDataBy, disable=1
2159                endif
2160        endif
2161
2162
2163
2164        if(cmpstr(ctrlName,"SkipLines")==0)
2165                if(checked)
2166                        SetVariable SkipNumberOfLines, disable=0
2167                else
2168                        SetVariable SkipNumberOfLines, disable=1
2169                endif
2170        endif
2171       
2172End
2173//************************************************************************************************************
2174//************************************************************************************************************
2175//************************************************************************************************************
2176//************************************************************************************************************
2177Function IR1I_UpdateListOfFilesInWvs()
2178
2179        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
2180        SVAR DataPathName = root:Packages:ImportData:DataPathName
2181        SVAR DataExtension  = root:Packages:ImportData:DataExtension
2182        SVAR NameMatchString = root:Packages:ImportData:NameMatchString
2183        Wave/T WaveOfFiles      = root:Packages:ImportData:WaveOfFiles
2184        Wave WaveOfSelections = root:Packages:ImportData:WaveOfSelections
2185        string ListOfAllFiles
2186        string LocalDataExtension
2187        variable i, imax
2188        LocalDataExtension = DataExtension
2189        if (cmpstr(LocalDataExtension[0],".")!=0)
2190                LocalDataExtension = "."+LocalDataExtension
2191        endif
2192        PathInfo ImportDataPath
2193        if(V_Flag && strlen(DataPathName)>0)
2194                if (strlen(LocalDataExtension)<=1)
2195                        ListOfAllFiles = IndexedFile(ImportDataPath,-1,"????")
2196                else           
2197                        ListOfAllFiles = IndexedFile(ImportDataPath,-1,LocalDataExtension)
2198                endif
2199                if(strlen(NameMatchString)>0)
2200                        ListOfAllFiles = GrepList(ListOfAllFiles, NameMatchString )
2201                endif
2202                //remove Invisible Mac files, .DS_Store and .plist
2203                ListOfAllFiles = IN2G_RemoveInvisibleFiles(ListOfAllFiles)
2204       
2205                imax = ItemsInList(ListOfAllFiles,";")
2206                Redimension/N=(imax) WaveOfSelections
2207                Redimension/N=(imax) WaveOfFiles
2208                for (i=0;i<imax;i+=1)
2209                        WaveOfFiles[i] = stringFromList(i, ListOfAllFiles,";")
2210                endfor
2211        else
2212                Redimension/N=0 WaveOfSelections
2213                Redimension/N=0 WaveOfFiles
2214        endif
2215end
2216//************************************************************************************************************
2217//************************************************************************************************************
2218//************************************************************************************************************
2219//************************************************************************************************************
2220
2221
2222Function IR1I_InitializeImportData()
2223       
2224        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
2225        string OldDf = GetDataFolder(1)
2226       
2227        NewDataFolder/O/S root:Packages
2228        NewDataFolder/O/S root:Packages:ImportData
2229       
2230        string ListOfStrings
2231        string ListOfVariables
2232        variable i
2233       
2234        ListOfStrings = "DataPathName;DataExtension;IntName;QvecName;ErrorName;NewDataFolderName;NewIntensityWaveName;DataTypeToImport;"
2235        ListOfStrings+="NewQWaveName;NewErrorWaveName;NewQErrorWavename;NameMatchString;TooManyPointsWarning;RemoveStringFromName;"
2236        ListOfVariables = "UseFileNameAsFolder;UseIndra2Names;UseQRSNames;DataContainErrors;UseQISNames;"
2237        ListOfVariables += "SlitSmearData;SlitLength;UsesasEntryNameAsFolder;UseTitleNameAsFolder;"     
2238        ListOfVariables += "CreateSQRTErrors;Col1Int;Col1Qvec;Col1Err;Col1QErr;FoundNWaves;"   
2239        ListOfVariables += "Col2Int;Col2Qvec;Col2Err;Col2QErr;Col3Int;Col3Qvec;Col3Err;Col3QErr;Col4Int;Col4Qvec;Col4Err;Col4QErr;"     
2240        ListOfVariables += "Col5Int;Col5Qvec;Col5Err;Col5QErr;Col6Int;Col6Qvec;Col6Err;Col6QErr;Col7Int;Col7Qvec;Col7Err;Col7QErr;"     
2241        ListOfVariables += "QvectInA;QvectInNM;QvectInDegrees;CreateSQRTErrors;CreatePercentErrors;PercentErrorsToUse;"
2242        ListOfVariables += "ScaleImportedData;ScaleImportedDataBy;ImportSMRdata;SkipLines;SkipNumberOfLines;"   
2243        ListOfVariables += "IncludeExtensionInName;RemoveNegativeIntensities;AutomaticallyOverwrite;"   
2244        ListOfVariables += "TrimData;TrimDataQMin;TrimDataQMax;ReduceNumPnts;TargetNumberOfPoints;ReducePntsParam;"     
2245        ListOfVariables += "NumOfPointsFound;TrunkateStart;TrunkateEnd;Wavelength;"     
2246        ListOfVariables += "DataCalibratedArbitrary;DataCalibratedVolume;DataCalibratedWeight;"
2247        //Nexus
2248        ListOfVariables += "NX_InclsasInstrument;NX_Incl_sasSample;NX_Inclsasnote;"     
2249       
2250
2251                //and here we create them
2252        for(i=0;i<itemsInList(ListOfVariables);i+=1)   
2253                IN2G_CreateItem("variable",StringFromList(i,ListOfVariables))
2254        endfor         
2255                                                               
2256        for(i=0;i<itemsInList(ListOfStrings);i+=1)     
2257                IN2G_CreateItem("string",StringFromList(i,ListOfStrings))
2258        endfor 
2259
2260        SVAR TooManyPointsWarning
2261        TooManyPointsWarning=" "
2262       
2263        Make/O/T/N=0 WaveOfFiles
2264        Make/O/N=0 WaveOfSelections
2265       
2266        ListOfVariables = "CreateSQRTErrors;Col1Int;Col1Qvec;Col1Err;Col1QErr;"
2267        ListOfVariables += "Col2Int;Col2Qvec;Col2Err;Col2QErr;Col3Int;Col3Qvec;Col3Err;Col3QErr;Col4Int;Col4Qvec;Col4Err;Col4QErr;"     
2268        ListOfVariables += "Col5Int;Col5Qvec;Col5Err;Col5QErr;Col6Int;Col6Qvec;Col6Err;Col6QErr;Col7Int;Col7Qvec;Col7Err;Col7QErr;"     
2269        ListOfVariables += "QvectInNM;CreateSQRTErrors;CreatePercentErrors;"   
2270        ListOfVariables += "ScaleImportedData;ImportSMRdata;SkipLines;SkipNumberOfLines;UseQISNames;UseIndra2Names;NumOfPointsFound;"   
2271
2272        //We need list of known Data types for non-SAS importer
2273        string/g ListOfKnownDataTypes
2274        ListOfKnownDataTypes = "Q-Int;D-Int;Tth-Int;"//VolumeDistribution(Radius);VolumeDistribution(Diameter);"
2275        SVAR DataTypeToImport
2276        if(strlen(DataTypeToImport)<2)
2277                DataTypeToImport = StringFromList(0,ListOfKnownDataTypes)
2278        endif
2279        //Set numbers to 0
2280        for(i=0;i<itemsInList(ListOfVariables);i+=1)   
2281                NVAR test=$(StringFromList(i,ListOfVariables))
2282                test =0
2283        endfor         
2284        ListOfVariables = "QvectInA;PercentErrorsToUse;ScaleImportedDataBy;UseFileNameAsFolder;UseQRSNames;Wavelength;"
2285        //Set numbers to 1
2286        for(i=0;i<itemsInList(ListOfVariables);i+=1)   
2287                NVAR test=$(StringFromList(i,ListOfVariables))
2288                test =1
2289        endfor         
2290        ListOfVariables = "TargetNumberOfPoints;"       
2291        //Set numbers to 1
2292        for(i=0;i<itemsInList(ListOfVariables);i+=1)   
2293                NVAR test=$(StringFromList(i,ListOfVariables))
2294                if(test<1)
2295                        test =200
2296                endif
2297        endfor         
2298        ListOfVariables = "ReducePntsParam;"   
2299        //Set numbers to 1
2300        for(i=0;i<itemsInList(ListOfVariables);i+=1)   
2301                NVAR test=$(StringFromList(i,ListOfVariables))
2302                if(test<0.5)
2303                        test =5
2304                endif
2305        endfor         
2306       
2307        NVAR DataCalibratedArbitrary
2308        NVAR DataCalibratedVolume
2309        NVAR DataCalibratedWeight
2310        if(DataCalibratedArbitrary+DataCalibratedVolume+DataCalibratedWeight!=1)
2311                DataCalibratedArbitrary = 1
2312                DataCalibratedVolume = 0
2313                DataCalibratedWeight = 0
2314        endif
2315        NVAR TrunkateStart
2316        NVAR TrunkateEnd
2317        if(TrunkateStart+TrunkateEnd!=1)
2318                TrunkateStart=0
2319                TrunkateEnd=1
2320        endif
2321        NVAR QvectInA
2322        NVAR QvectInNM
2323        NVAR QvectInDegrees
2324        if(QvectInA+QvectInNM+QvectInDegrees!=1)
2325                QvectInA=1
2326                QvectInNM=0
2327                QvectInDegrees=0
2328        endif
2329       
2330        IR1I_UpdateListOfFilesInWvs()
2331end
2332
2333
2334//************************************************************************************************************
2335//************************************************************************************************************
2336//************************************************************************************************************
2337//************************************************************************************************************
2338
2339Function IR1I_ImportOtherASCIIMain()
2340        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
2341                //IR1_KillGraphsAndPanels()
2342        IN2G_CheckScreenSize("height",720)
2343        DoWindow IR1I_ImportData
2344        if(V_Flag)
2345                DoALert/T="Window conflict notice" 1, "Import SAS ASCII data cannot be open while using this tool, close (Yes) or abort (no)?"
2346                if(V_flag==1)
2347                        KillWIndow/Z IR1I_ImportData
2348                else
2349                        abort
2350                endif
2351        endif
2352        DoWindow IR1I_ImportNexusCanSASData
2353        if(V_Flag)
2354                DoALert/T="Window conflict notice" 1, "Import Nexus data cannot be open while using this tool, close (Yes) or abort (no)?"
2355                if(V_flag==1)
2356                        KillWIndow/Z IR1I_ImportNexusCanSASData
2357                else
2358                        abort
2359                endif
2360        endif
2361        KillWIndow/Z IR1I_ImportOtherASCIIData
2362        IR1I_InitializeImportData()
2363        IR1I_ImportOtherASCIIDataFnct()
2364        ING2_AddScrollControl()
2365        IR1_UpdatePanelVersionNumber("IR1I_ImportOtherASCIIData", IR1IversionNumber2,1)
2366        //fix checboxes
2367        //IR1I_FIxCheckboxesForWaveTypes()
2368end
2369
2370//************************************************************************************************************
2371//************************************************************************************************************
2372//************************************************************************************************************
2373//************************************************************************************************************
2374
2375Function IR1I_ImportOtherASCIIDataFnct()
2376        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
2377        PauseUpdate; Silent 1           // building window...
2378        NewPanel /K=1 /W=(3,40,430,760)/N=IR1I_ImportOtherASCIIData as "Import non-SAS data"
2379        TitleBox MainTitle title="\Zr200Import non SAS ASCII Data in Igor",pos={20,5},frame=0,fstyle=3, fixedSize=1,font= "Times New Roman", size={400,24},anchor=MC,fColor=(0,0,52224)
2380        TitleBox FakeLine1 title=" ",fixedSize=1,size={330,3},pos={16,40},frame=0,fColor=(0,0,52224), labelBack=(0,0,52224)
2381        TitleBox Info21 title="\Zr140Col. 1",pos={239,192},frame=0,fstyle=2, fixedSize=1,size={150,20}
2382        TitleBox Info22 title="\Zr140Col. 2",pos={239,209},frame=0,fstyle=2, fixedSize=1,size={150,20}
2383        TitleBox Info23 title="\Zr140Col. 3",pos={239,226},frame=0,fstyle=2, fixedSize=1,size={150,20}
2384        TitleBox Info24 title="\Zr140Col. 4",pos={239,243},frame=0,fstyle=2, fixedSize=1,size={150,20}
2385        TitleBox Info25 title="\Zr140Col. 5",pos={239,260},frame=0,fstyle=2, fixedSize=1,size={150,20}
2386        TitleBox Info26 title="\Zr140Col. 6",pos={239,277},frame=0,fstyle=2, fixedSize=1,size={150,20}
2387        TitleBox Info6 title="\Zr150X",pos={298,172},frame=0,fstyle=2, fixedSize=0,size={40,15}
2388        TitleBox Info7 title="\Zr150Y",pos={330,172},frame=0,fstyle=2, fixedSize=0,size={40,15}
2389        TitleBox Info8 title="\Zr150dY",pos={360,172},frame=0,fstyle=2, fixedSize=0,size={40,15}
2390        TitleBox Info9 title="\Zr150dX",pos={392,172},frame=0,fstyle=2, fixedSize=0,size={40,15}
2391       
2392        IR3C_AddDataControls("ImportDataPath", "ImportData", "IR1I_ImportOtherASCIIData","", "","","IR1I_DoubleClickFUnction")
2393        ListBox ListOfAvailableData,size={220,277}, pos={5,113}
2394        Button SelectAll,pos={5,395}
2395        Button DeSelectAll, pos={120,395}
2396
2397        CheckBox SkipLines,pos={230,133},size={16,14},proc=IR1I_CheckProc,title="Skip lines?",variable= root:Packages:ImportData:SkipLines, help={"Check if you want to skip lines in header. Needed ONLY for weird headers..."}
2398        SetVariable SkipNumberOfLines,pos={300,133},size={70,19},proc=IR1I_SetVarProc,title=" "
2399        SetVariable SkipNumberOfLines,help={"Insert number of lines to skip"}
2400        NVAR DisableSkipLines=root:Packages:ImportData:SkipLines
2401        SetVariable SkipNumberOfLines,variable= root:Packages:ImportData:SkipNumberOfLines, disable=(!DisableSkipLines)
2402
2403        Button TestImport,pos={230,152},size={80,15}, proc=IR1I_ButtonProc,title="Test"
2404        Button TestImport,help={"Test how if import can be succesful and how many waves are found"}
2405        Button Preview,pos={330,152},size={80,15}, proc=IR1I_ButtonProc,title="Preview"
2406        Button Preview,help={"Preview selected file."}
2407        Button GetHelp,pos={335,60},size={80,15},fColor=(65535,32768,32768), proc=IR1I_ButtonProc,title="Get Help", help={"Open www manual page for this tool"}
2408//
2409        CheckBox Col1Qvec,pos={299,192},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col1Qvec, help={"What does this column contain?"}
2410        CheckBox Col1Int,pos={331,192},size={16,14},proc=IR1I_CheckProc,title="", variable= root:Packages:ImportData:Col1Int, help={"What does this column contain?"}
2411        CheckBox Col1Error,pos={364,192},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col1Err, help={"What does this column contain?"}
2412        CheckBox Col1QError,pos={394,192},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col1QErr, help={"What does this column contain?"}
2413
2414        CheckBox Col2Qvec,pos={299,209},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col2Qvec, help={"What does this column contain?"}
2415        CheckBox Col2Int,pos={331,209},size={16,14},proc=IR1I_CheckProc,title="", variable= root:Packages:ImportData:Col2Int, help={"What does this column contain?"}
2416        CheckBox Col2Error,pos={364,209},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col2Err, help={"What does this column contain?"}
2417        CheckBox Col2QError,pos={394,209},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col2QErr, help={"What does this column contain?"}
2418
2419        CheckBox Col3Qvec,pos={299,226},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col3Qvec, help={"What does this column contain?"}
2420        CheckBox Col3Int,pos={331,226},size={16,14},proc=IR1I_CheckProc,title="", variable= root:Packages:ImportData:Col3Int, help={"What does this column contain?"}
2421        CheckBox Col3Error,pos={364,226},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col3Err, help={"What does this column contain?"}
2422        CheckBox Col3QError,pos={394,226},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col3QErr, help={"What does this column contain?"}
2423
2424        CheckBox Col4Qvec,pos={299,243},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col4Qvec, help={"What does this column contain?"}
2425        CheckBox Col4Int,pos={331,243},size={16,14},proc=IR1I_CheckProc,title="", variable= root:Packages:ImportData:Col4Int, help={"What does this column contain?"}
2426        CheckBox Col4Error,pos={364,243},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col4Err, help={"What does this column contain?"}
2427        CheckBox Col4QError,pos={394,243},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col4QErr, help={"What does this column contain?"}
2428
2429        CheckBox Col5Qvec,pos={299,260},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col5Qvec, help={"What does this column contain?"}
2430        CheckBox Col5Int,pos={331,260},size={16,14},proc=IR1I_CheckProc,title="", variable= root:Packages:ImportData:Col5Int, help={"What does this column contain?"}
2431        CheckBox Col5Error,pos={364,260},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col5Err, help={"What does this column contain?"}
2432        CheckBox Col5QError,pos={394,260},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col5QErr, help={"What does this column contain?"}
2433
2434        CheckBox Col6Qvec,pos={299,277},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col6Qvec, help={"What does this column contain?"}
2435        CheckBox Col6Int,pos={331,277},size={16,14},proc=IR1I_CheckProc,title="", variable= root:Packages:ImportData:Col6Int, help={"What does this column contain?"}
2436        CheckBox Col6Error,pos={364,277},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col6Err, help={"What does this column contain?"}
2437        CheckBox Col6QError,pos={394,277},size={16,14},proc=IR1I_CheckProc,title="",variable= root:Packages:ImportData:Col6QErr, help={"What does this column contain?"}
2438
2439//
2440//
2441        SetVariable FoundNWaves,pos={239,296},size={160,19},title="Found cols.:  ",proc=IR1I_SetVarProc
2442        SetVariable FoundNWaves,help={"This is how many columns were found in the tested file"}, disable=2
2443        SetVariable FoundNWaves,limits={0,Inf,0},value= root:Packages:ImportData:FoundNWaves
2444
2445        Button Plot,pos={330,317},size={80,15}, proc=IR1I_ButtonProc,title="Plot"
2446        Button Plot,help={"Preview selected file."}
2447
2448        CheckBox QvectorInA,pos={240,340},size={16,14},proc=IR1I_CheckProc,title="X units [1/A, deg, A]",variable= root:Packages:ImportData:QvectInA, help={"What units is X in? Select if in 1/A for Q, A for d, degree for TwoTheta"}
2449        CheckBox QvectorInNM,pos={240,355},size={16,14},proc=IR1I_CheckProc,title="X units [1/nm or nm]",variable= root:Packages:ImportData:QvectInNM, help={"What units is X in? Select if in 1/nm for Q or nm for d. WIll be converted to 1/A or A"}
2450        //CheckBox QvectInDegrees,pos={240,355},size={16,14},proc=IR1I_CheckProc,title="X units [degree]",variable= root:Packages:ImportData:QvectInDegrees, help={"What units is X axis in? Select if in degrees... WIll be converted to inverse Angstroems"}
2451
2452        CheckBox CreateSQRTErrors,pos={240,370},size={16,14},proc=IR1I_CheckProc,title="Create SQRT dY?",variable= root:Packages:ImportData:CreateSQRTErrors, help={"If input data do not contain errors, create errors as sqrt of intensity?"}
2453        CheckBox CreatePercentErrors,pos={240,385},size={16,14},proc=IR1I_CheckProc,title="Create n% dY?",variable= root:Packages:ImportData:CreatePercentErrors, help={"If input data do not contain errors, create errors as n% of intensity?, select how many %"}
2454        NVAR DiablePctErr=root:Packages:ImportData:CreatePercentErrors
2455        SetVariable PercentErrorsToUse, pos={240,403}, size={100,20},title="dY %?:", proc=IR1I_setvarProc, disable=!(DiablePctErr)
2456        SetVariable PercentErrorsToUse value= root:packages:ImportData:PercentErrorsToUse,help={"Input how many percent error you want to create."}
2457        CheckBox UseFileNameAsFolder,pos={10,420},size={16,14},proc=IR1I_CheckProc,title="Use File Nms as Fldr Nms?",variable= root:Packages:ImportData:UseFileNameAsFolder, help={"Use names of imported files as folder names for the data?"}
2458        NVAR DisableExt=root:Packages:ImportData:UseFileNameAsFolder
2459        NVAR DisableOver=root:Packages:ImportData:UseFileNameAsFolder
2460        CheckBox AutomaticallyOverwrite,pos={240,420},size={16,14},proc=IR1I_CheckProc,title="Overwrite existing data?",variable= root:Packages:ImportData:AutomaticallyOverwrite, help={"Automatically overwrite imported data if same data exist?"}, disable=!(DisableOver)
2461
2462        SVAR DataTypeToImport=root:Packages:ImportData:DataTypeToImport
2463        SVAR ListOfKnownDataTypes=root:Packages:ImportData:ListOfKnownDataTypes
2464        PopupMenu ImportDataType,pos={10,450},size={250,21},proc=IR1I_PopMenuProc,title="Data Type", help={"Select waht data are being imported for proper naming"}
2465        PopupMenu ImportDataType,mode=1,popvalue=DataTypeToImport,value= #"root:Packages:ImportData:ListOfKnownDataTypes"
2466        SetVariable Wavelength, pos={260,453}, size={150,10}, variable=root:Packages:ImportData:Wavelength, noproc, help={"For Two Theta (Tth) we need wavelength in A"}
2467        SetVariable Wavelength, disable = !StringMatch(DataTypeToImport,"Tth-Int")
2468
2469        CheckBox ScaleImportedDataCheckbox,pos={10,475},size={16,14},proc=IR1I_CheckProc,title="Scale Imported data?",variable= root:Packages:ImportData:ScaleImportedData, help={"Check to scale (multiply by) factor imported data. Both Intensity and error will be scaled by same number. Insert appriate number right."}
2470        NVAR DisableScale=root:Packages:ImportData:ScaleImportedData
2471        SetVariable ScaleImportedDataBy, pos={200,475}, size={140,20},title="Scaling factor?:", proc=IR1I_setvarProc, disable=!(DisableScale)
2472        SetVariable ScaleImportedDataBy limits={1e-32,inf,1},value= root:packages:ImportData:ScaleImportedDataBy,help={"Input number by which you want to multiply the imported intensity and errors."}
2473        CheckBox RemoveNegativeIntensities,pos={10,500},size={16,14},proc=IR1I_CheckProc,title="Remove Int<=0?",variable= root:Packages:ImportData:RemoveNegativeIntensities, help={"Remove Intensities smaller than 0?"}
2474        NVAR DisableTrim=root:Packages:ImportData:TrimData
2475        CheckBox TrimData,pos={10,526},size={16,14},proc=IR1I_CheckProc,title="Trim data?",variable= root:Packages:ImportData:TrimData, help={"Check to trim Q range of the imported data."}
2476        SetVariable TrimDataQMin, pos={110,524}, size={110,20},title="X min=", proc=IR1I_setvarProc, disable=!(DisableTrim)
2477        SetVariable TrimDataQMin limits={0,inf,0},value= root:packages:ImportData:TrimDataQMin,help={"Xmin for trimming data. Leave 0 if not trimming at low q is needed."}
2478        SetVariable TrimDataQMax, pos={240,524}, size={110,20},title="X max=", proc=IR1I_setvarProc, disable=!(DisableTrim)
2479        SetVariable TrimDataQMax limits={0,inf,0},value= root:packages:ImportData:TrimDataQMax,help={"Xmax for trimming data. Leave 0 if not trimming at low q is needed."}
2480//
2481        CheckBox TrunkateStart,pos={10,545},size={16,14},proc=IR1I_CheckProc,title="Truncate start of long names?",variable= root:Packages:ImportData:TrunkateStart, help={"Truncate names longer than 24 characters in front"}
2482        CheckBox TrunkateEnd,pos={240,545},size={16,14},proc=IR1I_CheckProc,title="Truncate end of long names?",variable= root:Packages:ImportData:TrunkateEnd, help={"Truncate names longer than 24 characters at the end"}
2483        SetVariable RemoveStringFromName, pos={5,565}, size={320,20},title="Remove Str From Name=", noproc
2484        SetVariable RemoveStringFromName value= root:packages:ImportData:RemoveStringFromName,help={"Input string to be removed from name, leve empty if none"}
2485        PopupMenu SelectFolderNewData2,pos={10,590},size={250,21},proc=IR1I_PopMenuProc,title="Select data folder", help={"Select folder with data"}
2486        PopupMenu SelectFolderNewData2,mode=1,popvalue="---",value= #"\"---;\"+IN2G_NewFindFolderWithWaveTypes(\"root:\", 10, \"*\", 1)"
2487        SetVariable NewDataFolderName, pos={5,620}, size={410,20},title="New data folder:", proc=IR1I_setvarProc
2488        SetVariable NewDataFolderName value= root:packages:ImportData:NewDataFolderName,help={"Folder for the new data. Will be created, if does not exist.Or pick one ip popup above"}
2489        SetVariable NewQwaveName, pos={5,640}, size={320,20},title="X wave names ", proc=IR1I_setvarProc
2490        SetVariable NewQwaveName, value= root:packages:ImportData:NewQWaveName,help={"Input name for the new Q wave"}
2491        SetVariable NewIntensityWaveName, pos={5,660}, size={320,20},title="Y wave names", proc=IR1I_setvarProc
2492        SetVariable NewIntensityWaveName, value= root:packages:ImportData:NewIntensityWaveName,help={"Input name for the new intensity wave"}
2493        SetVariable NewErrorWaveName, pos={5,680}, size={320,20},title="dY wv names", proc=IR1I_setvarProc
2494        SetVariable NewErrorWaveName, value= root:packages:ImportData:NewErrorWaveName,help={"Input name for the new Error wave"}
2495        SetVariable NewQErrorWaveName, pos={5,700}, size={320,20},title="dX wv names  ", proc=IR1I_setvarProc
2496        SetVariable NewQErrorWaveName, value= root:packages:ImportData:NewQErrorWaveName,help={"Input name for the new Q data Error wave"}
2497
2498        Button ImportData2,pos={330,660},size={80,30}, proc=IR1I_ButtonProc,title="Import"
2499        Button ImportData2,help={"Import the selected data files."}
2500
2501        IR1I_ImportOtherSetNames()
2502
2503EndMacro
2504
2505//************************************************************************************************************
2506//************************************************************************************************************
2507Function IR1I_DoubleClickFUnction()
2508
2509        IR1I_ButtonProc("TestImport")
2510       
2511end
2512
2513
2514//************************************************************************************************************
2515//************************************************************************************************************
2516Function IR1I_ImportDataFnct2()
2517        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
2518
2519        string TopPanel=WinName(0, 64)
2520        string OldDf = getDataFolder(1)
2521       
2522        Wave/T WaveOfFiles      = root:Packages:ImportData:WaveOfFiles
2523        Wave WaveOfSelections = root:Packages:ImportData:WaveOfSelections
2524
2525        IR1I_CheckForProperNewFolder()
2526        variable i, imax, icount
2527        string SelectedFile
2528        imax = numpnts(WaveOfSelections)
2529        icount = 0
2530        for(i=0;i<imax;i+=1)
2531                if (WaveOfSelections[i])
2532                        selectedfile = WaveOfFiles[i]
2533                        IR1I_CreateImportDataFolder(selectedFile)
2534                        KillWaves/Z TempIntensity, TempQvector, TempError
2535                        IR1I_ImportOneFile(selectedFile)
2536                                        IR1I_ProcessImpWaves2(selectedFile)             //this thing also creates new error waves, removes negative qs and intesities and does everything else
2537                        IR1I_RecordResults(selectedFile)
2538                        icount+=1
2539                endif
2540        endfor
2541        print "Imported "+num2str(icount)+" data file(s) in total"
2542        setDataFolder OldDf
2543end
2544
2545//************************************************************************************************************
2546//************************************************************************************************************
2547
2548
2549//IR1I_TestPlotData()
2550
2551Function IR1I_ImportOtherSetNames()
2552
2553        SVAR NewDataFolderName = root:packages:ImportData:NewDataFolderName
2554        SVAR NewIntensityWaveName= root:packages:ImportData:NewIntensityWaveName
2555        SVAR NewQwaveName= root:packages:ImportData:NewQWaveName
2556        SVAR NewErrorWaveName= root:packages:ImportData:NewErrorWaveName
2557        SVAR NewQErrorWaveName= root:packages:ImportData:NewQErrorWaveName
2558        NVAR UseFileNameAsFolder = root:Packages:ImportData:UseFileNameAsFolder
2559        SVAR DataTypeToImport=root:Packages:ImportData:DataTypeToImport
2560       
2561        if(!stringmatch(NewDataFolderName[0,3],"root"))
2562                        NewDataFolderName = "root:ImportedData:"               
2563        endif
2564        if(UseFileNameAsFolder&&(!GrepString(NewDataFolderName, "<fileName>")))
2565                        NewDataFolderName+="<fileName>:"
2566        endif
2567        //      ListOfKnownDataTypes = "Q-Int;D-Int;Tth-Int;VolumeDistribution(Radius);VolumeDistribution(Diameter);"
2568        if(StringMatch(DataTypeToImport, "Q-Int"))
2569                if(UseFileNameAsFolder)                 
2570                        NewQwaveName= "Q_<fileName>"
2571                        NewIntensityWaveName= "R_<fileName>"
2572                        NewErrorWaveName= "S_<fileName>"
2573                        NewQErrorWaveName= "W_<fileName>"
2574                else
2575                        NewQwaveName= "Q_ChangeMe"
2576                        NewIntensityWaveName= "R_"
2577                        NewErrorWaveName= "S_"
2578                        NewQErrorWaveName= "W_"
2579                endif
2580        elseif(StringMatch(DataTypeToImport, "D-Int")   )
2581                if(UseFileNameAsFolder)                 
2582                        NewQwaveName= "D_<fileName>"
2583                        NewIntensityWaveName= "R_<fileName>"
2584                        NewErrorWaveName= "S_<fileName>"
2585                        NewQErrorWaveName= "W_<fileName>"
2586                else
2587                        NewQwaveName= "D_ChangeMe"
2588                        NewIntensityWaveName= "R_"
2589                        NewErrorWaveName= "S_"
2590                        NewQErrorWaveName= "W_"
2591                endif
2592        elseif(StringMatch(DataTypeToImport, "Tth-Int") )
2593                if(UseFileNameAsFolder)                 
2594                        NewQwaveName= "T_<fileName>"
2595                        NewIntensityWaveName= "R_<fileName>"
2596                        NewErrorWaveName= "S_<fileName>"
2597                        NewQErrorWaveName= "W_<fileName>"
2598                else
2599                        NewQwaveName= "T_ChangeMe"
2600                        NewIntensityWaveName= "R_"
2601                        NewErrorWaveName= "S_"
2602                        NewQErrorWaveName= "W_"
2603                endif
2604        elseif(StringMatch(DataTypeToImport, "VolumeDistribution(Radius)")      )
2605                if(UseFileNameAsFolder)                 
2606                        NewQwaveName= "Radius"
2607                        NewIntensityWaveName= "VoluemDistribution"
2608                        NewErrorWaveName= "S_<fileName>"
2609                        NewQErrorWaveName= "W_<fileName>"
2610                else
2611                        NewQwaveName= "D_ChangeMe"
2612                        NewIntensityWaveName= "R_"
2613                        NewErrorWaveName= "S_"
2614                        NewQErrorWaveName= "W_"
2615                endif
2616        elseif(StringMatch(DataTypeToImport, "VolumeDistribution(Diameter)"))   
2617                if(UseFileNameAsFolder)                 
2618                        NewQwaveName= "Diameter"
2619                        NewIntensityWaveName= "VolumeDistribution"
2620                        NewErrorWaveName= "S_<fileName>"
2621                        NewQErrorWaveName= "W_<fileName>"
2622                else
2623                        NewQwaveName= "D_ChangeMe"
2624                        NewIntensityWaveName= "R_"
2625                        NewErrorWaveName= "S_"
2626                        NewQErrorWaveName= "W_"
2627                endif
2628
2629        else
2630                if(UseFileNameAsFolder)                 
2631                        NewQwaveName= "Q_<fileName>"
2632                        NewIntensityWaveName= "R_<fileName>"
2633                        NewErrorWaveName= "S_<fileName>"
2634                        NewQErrorWaveName= "W_<fileName>"
2635                else
2636                        NewQwaveName= "Q_ChangeMe"
2637                        NewIntensityWaveName= "R_"
2638                        NewErrorWaveName= "S_"
2639                        NewQErrorWaveName= "W_"
2640                endif
2641        endif
2642
2643end
2644
2645
2646//************************************************************************************************************
2647//************************************************************************************************************
2648//************************************************************************************************************
2649
2650Function IR1I_ProcessImpWaves2(selectedFile)
2651        string selectedFile
2652        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
2653
2654        variable i, numOfInts, numOfQs, numOfErrs, numOfQErrs, refNum
2655        numOfInts  = 0
2656        numOfQs   = 0
2657        numOfErrs = 0
2658        numOfQErrs = 0
2659        string HeaderFromData=""
2660        NVAR SkipNumberOfLines=root:Packages:ImportData:SkipNumberOfLines
2661        NVAR SkipLines=root:Packages:ImportData:SkipLines       
2662        NVAR FoundNWaves = root:Packages:ImportData:FoundNWaves
2663        NVAR TrunkateStart = root:Packages:ImportData:TrunkateStart
2664        NVAR TrunkateEnd = root:Packages:ImportData:TrunkateEnd
2665        variable GenError=0
2666
2667        if(!SkipLines)                  //lines automatically skipped, so the header may make sense, add to header...
2668                Open/R/P=ImportDataPath refNum as selectedFile
2669                HeaderFromData=""
2670                Variable j
2671               String text
2672              For(j=0;j<SkipNumberOfLines;j+=1)
2673                     FReadLine refNum, text
2674                        HeaderFromData+=ZapNonLetterNumStart(IN2G_ZapControlCodes(text))+";"
2675                endfor       
2676              Close refNum
2677        endif   
2678        NVAR DataContainErrors=root:Packages:ImportData:DataContainErrors
2679        DataContainErrors=0
2680        variable LimitFoundWaves = (FoundNWaves<=6) ? FoundNWaves : 7
2681        For(i=0;i<LimitFoundWaves;i+=1)
2682                NVAR testIntStr = $("root:Packages:ImportData:Col"+num2str(i+1)+"Int")
2683                NVAR testQvecStr = $("root:Packages:ImportData:Col"+num2str(i+1)+"Qvec")
2684                NVAR testErrStr = $("root:Packages:ImportData:Col"+num2str(i+1)+"Err")
2685                NVAR testQErrStr = $("root:Packages:ImportData:Col"+num2str(i+1)+"QErr")
2686                Wave/Z CurrentWave = $("wave"+num2str(i))
2687                SVAR DataPathName=root:Packages:ImportData:DataPathName
2688                if (testIntStr&&WaveExists(CurrentWave))
2689                        duplicate/O CurrentWave, TempIntensity
2690                        //print "Data imported from folder="+DataPathName+";Data file name="+selectedFile+";"+HeaderFromData+";"
2691                        note/NOCR TempIntensity, "Data imported from folder="+DataPathName+";Data file name="+selectedFile+";"+HeaderFromData+";"
2692                        //print note(TempIntensity)
2693                        numOfInts+=1
2694                endif
2695                if (testQvecStr&&WaveExists(CurrentWave))
2696                        duplicate/O CurrentWave, TempQvector
2697                        note/NOCR TempQvector, "Data imported from folder="+DataPathName+";Data file name="+selectedFile+";"+HeaderFromData+";"
2698                        numOfQs+=1
2699                endif
2700                if (testErrStr&&WaveExists(CurrentWave))
2701                        duplicate/O CurrentWave, TempError
2702                        note/NOCR TempError, "Data imported from folder="+DataPathName+";Data file name="+selectedFile+";"+HeaderFromData+";"
2703                        numOfErrs+=1
2704                        DataContainErrors=1
2705                endif
2706                if (testQErrStr&&WaveExists(CurrentWave))
2707                        duplicate/O CurrentWave, TempQError
2708                        note TempQError, "Data imported from folder="+DataPathName+";Data file name="+selectedFile+";"+HeaderFromData+";"
2709                        numOfQErrs+=1
2710                endif
2711                if(!WaveExists(CurrentWave))
2712                        GenError=0
2713                        string Messg="Error, the column of data selected did not exist in the data file. The missing column is : "
2714                        if(testIntStr)
2715                                Messg+="Intensity"
2716                                GenError=1
2717                        elseif(testQvecStr)
2718                                Messg+="Q vector"
2719                                GenError=1
2720                        elseif(testErrStr)
2721                                Messg+="Error"
2722                                GenError=1
2723                        elseif(testQErrStr)
2724                                Messg+="Q Error"
2725                                GenError=1
2726                        endif
2727                        if(GenError)
2728                                DoAlert 0, Messg
2729                        endif
2730                endif
2731        endfor
2732        if (numOfInts!=1 || numOfQs!=1 || numOfErrs>1|| numOfQErrs>1)
2733                Abort "Import waves problem, check values in checkboxes which indicate which column contains Intensity, Q and error"
2734        endif
2735
2736        //here we will modify the data if user wants to do so...
2737        NVAR QvectInA=root:Packages:ImportData:QvectInA
2738        NVAR QvectInNM=root:Packages:ImportData:QvectInNM
2739        NVAR ScaleImportedData=root:Packages:ImportData:ScaleImportedData
2740        NVAR ScaleImportedDataBy=root:Packages:ImportData:ScaleImportedDataBy
2741        SVAR DataTypeToImport=root:Packages:ImportData:DataTypeToImport
2742        if (QvectInNM)
2743                if(stringMatch(DataTypeToImport,"Q-Int"))
2744                        TempQvector=TempQvector/10                      //converts nm-1 in A-1 
2745                        note TempQvector, "Q data converted from nm to A-1;"
2746                        if(WaveExists(TempQError))
2747                                TempQError = TempQError/10
2748                                note/NOCR TempQError, "Q error converted from nm to A-1;"
2749                        endif
2750                elseif(stringMatch(DataTypeToImport,"D-Int"))
2751                        TempQvector=TempQvector*10                      //converts nm in A
2752                        note TempQvector, "d data converted from nm to A;"
2753                        if(WaveExists(TempQError))
2754                                TempQError = TempQError/10
2755                                note/NOCR TempQError, "d error converted from nm to A;"
2756                        endif
2757                endif
2758        endif
2759        if (ScaleImportedData)
2760                TempIntensity=TempIntensity*ScaleImportedDataBy         //scales imported data for user
2761                note/NOCR TempIntensity, "Data scaled by="+num2str(ScaleImportedDataBy)+";"
2762                if (WaveExists(TempError))
2763                        TempError=TempError*ScaleImportedDataBy         //scales imported data for user
2764                        note/NOCR TempError, "Data scaled by="+num2str(ScaleImportedDataBy)+";"
2765                endif
2766        endif
2767        //lets insert here the Units into the wave notes...
2768        //deal with wavelength if data are Tth-Int:
2769        if(StringMatch(DataTypeToImport,"Tth-Int"))
2770                NVAR Wavelength=root:Packages:ImportData:Wavelength
2771                note/NOCR TempIntensity, "wavelength="+num2str(Wavelength)+";"
2772                if(WaveExists(TempError))
2773                        note/NOCR TempError, "wavelength="+num2str(Wavelength)+";"
2774                endif
2775                if(WaveExists(TempQError))
2776                        note/NOCR TempQError, "wavelength="+num2str(Wavelength)+";"     
2777                endif
2778        endif
2779        //here we will deal with erros, if the user needs to create them
2780        NVAR CreateSQRTErrors=root:Packages:ImportData:CreateSQRTErrors
2781        NVAR CreatePercentErrors=root:Packages:ImportData:CreatePercentErrors
2782        NVAR PercentErrorsToUse=root:Packages:ImportData:PercentErrorsToUse
2783        if ((CreatePercentErrors||CreateSQRTErrors) && WaveExists(TempError))   
2784                DoAlert 0, "Debugging message: Should create SQRT errors, but error wave exists. Mess in the checkbox values..."
2785        endif
2786        if (CreatePercentErrors && PercentErrorsToUse<1e-12)
2787                DoAlert 0, "You want to create percent error wave, but your error fraction is extremally small. This is likely error, so please, check the number and reimport the data"
2788                abort
2789        endif
2790        if (CreateSQRTErrors && !WaveExists(TempError))
2791                Duplicate/O TempIntensity, TempError
2792                TempError = sqrt(TempIntensity)
2793                note TempError, "Error data created for user as SQRT of intensity;"
2794        endif
2795        if (CreatePercentErrors && !WaveExists(TempError))
2796                Duplicate/O TempIntensity, TempError
2797                TempError = abs(TempIntensity) * (PercentErrorsToUse/100)
2798                note TempError, "Error data created for user as percentage of intensity;Amount of error as percentage="+num2str(PercentErrorsToUse/100)+";"
2799        endif
2800        //now remove negative intensities. If there are still some left and asked for.
2801        NVAR RemoveNegativeIntensities = root:packages:ImportData:RemoveNegativeIntensities
2802        if(RemoveNegativeIntensities)
2803                TempIntensity = TempIntensity[p]<=0 ?  NaN :  TempIntensity[p] 
2804        endif
2805        if(WaveExists(TempError)&&WaveExists(TempQError))       //have 4 waves
2806                IN2G_RemoveNaNsFrom4Waves(TempQvector, TempIntensity, TempError,TempQError)
2807        elseif(WaveExists(TempError)&&!WaveExists(TempQError))  //have 3 waves
2808                IN2G_RemoveNaNsFrom3Waves(TempQvector, TempIntensity, TempError)
2809        elseif(!WaveExists(TempError)&&WaveExists(TempQError))  //have 3 waves
2810                IN2G_RemoveNaNsFrom3Waves(TempQvector, TempIntensity, TempQError)
2811        else    //only 2 waves
2812                IN2G_RemoveNaNsFrom2Waves(TempQvector, TempIntensity)
2813        endif
2814        //just in case, we need to sort the data (some users have data which are not sorted...
2815        if(WaveExists(TempError))
2816                if(waveExists(TempQError))
2817                        sort TempQvector,TempQvector, TempIntensity, TempError,TempQError
2818                else
2819                        sort TempQvector,TempQvector, TempIntensity, TempError
2820                endif
2821        else
2822                sort TempQvector,TempQvector, TempIntensity     
2823        endif
2824        //all negative qs are removed...
2825        //optionally trim the Q range here...
2826        NVAR TrimData= root:packages:ImportData:TrimData
2827        NVAR TrimDataQMin= root:packages:ImportData:TrimDataQMin
2828        NVAR TrimDataQMax= root:packages:ImportData:TrimDataQMax
2829        if(TrimData)
2830                variable StartPointsToRemove=0
2831                if(TrimDataQMin>0)
2832                        StartPointsToRemove=binarysearch(TempQvector,TrimDataQMin)
2833                endif
2834                variable EndPointsToRemove=numpnts(TempQvector)
2835                if(TrimDataQMax>0 && TrimDataQMax<TempQvector[inf])
2836                        EndPointsToRemove=binarysearch(TempQvector,TrimDataQMax)
2837                endif
2838                if(TrimDataQMin>0)
2839                        TempQvector[0,StartPointsToRemove]=NaN
2840                endif
2841                if(TrimDataQMax>0 && TrimDataQMax<TempQvector[inf])
2842                        TempQvector[EndPointsToRemove+1,inf]=NaN
2843                endif
2844                if(WaveExists(TempError)&&WaveExists(TempQError))       //have 4 waves
2845                        IN2G_RemoveNaNsFrom4Waves(TempQvector, TempIntensity, TempError,TempQError)
2846                elseif(WaveExists(TempError)&&!WaveExists(TempQError))  //have 3 waves
2847                        IN2G_RemoveNaNsFrom3Waves(TempQvector, TempIntensity, TempError)
2848                elseif(!WaveExists(TempError)&&WaveExists(TempQError))  //have 3 waves
2849                        IN2G_RemoveNaNsFrom3Waves(TempQvector, TempIntensity, TempQError)
2850                else    //only 2 waves
2851                        IN2G_RemoveNaNsFrom2Waves(TempQvector, TempIntensity)
2852                endif
2853        endif   
2854        //check on TempError if it contains meaningful number and stop user if not...
2855        if(WaveExists(TempError))
2856                wavestats/Q TempError
2857                if((V_min<=0)||(V_numNANs>0)||(V_numINFs>0))
2858                        abort "The Errors (Uncertainities) contain negative values, 0, NANs, or INFs. This is not acceptable. Import aborted. Please, check the input data or use % or SQRT errors"
2859                endif
2860        endif
2861
2862        SVAR NewIntensityWaveName= root:packages:ImportData:NewIntensityWaveName
2863        SVAR NewQwaveName= root:packages:ImportData:NewQWaveName
2864        SVAR NewErrorWaveName= root:packages:ImportData:NewErrorWaveName
2865        SVAR NewQErrorWaveName= root:packages:ImportData:NewQErrorWaveName
2866        SVAR RemoveStringFromName=root:Packages:ImportData:RemoveStringFromName
2867        NVAR IncludeExtensionInName=root:packages:ImportData:IncludeExtensionInName
2868        string NewIntName, NewQName, NewEName, NewQEName, tempFirstPart, tempLastPart
2869       
2870        if(stringMatch(NewIntensityWaveName,"*<fileName>*")==0)
2871                NewIntName = IR1I_RemoveBadCharacters(NewIntensityWaveName)
2872                NewIntName = CleanupName(NewIntName, 1 )
2873                NewIntName=IR1I_TrunkateName(NewIntName,TrunkateStart,TrunkateEnd,RemoveStringFromName)
2874        else
2875                TempFirstPart = NewIntensityWaveName[0,strsearch(NewIntensityWaveName, "<fileName>", 0 )-1]
2876                tempLastPart  = NewIntensityWaveName[strsearch(NewIntensityWaveName, "<fileName>", 0 )+10,inf]
2877                if(IncludeExtensionInName)
2878                        NewIntName = TempFirstPart+IR1I_TrunkateName(selectedFile,TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
2879                else
2880                        NewIntName = TempFirstPart+IR1I_TrunkateName(StringFromList(0,selectedFile,"."),TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
2881                endif
2882                NewIntName = IR1I_RemoveBadCharacters(NewIntName)
2883                NewIntName = CleanupName(NewIntName, 1 )
2884        endif
2885        if(stringMatch(NewQwaveName,"*<fileName>*")==0)
2886                NewQName =IR1I_RemoveBadCharacters(NewQwaveName)
2887                NewQName = CleanupName(NewQName, 1 )
2888                NewQName=IR1I_TrunkateName(NewQName,TrunkateStart,TrunkateEnd,RemoveStringFromName)
2889        else
2890                TempFirstPart = NewQwaveName[0,strsearch(NewQwaveName, "<fileName>", 0 )-1]
2891                tempLastPart  = NewQwaveName[strsearch(NewQwaveName, "<fileName>", 0 )+10,inf]
2892                if(IncludeExtensionInName)
2893                        NewQName = TempFirstPart+IR1I_TrunkateName(selectedFile,TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
2894                else
2895                        NewQName = TempFirstPart+IR1I_TrunkateName(StringFromList(0,selectedFile,"."),TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
2896                endif
2897                NewQName =IR1I_RemoveBadCharacters(NewQName)
2898                NewQName = CleanupName(NewQName, 1 )
2899        endif
2900        if(stringMatch(NewErrorWaveName,"*<fileName>*")==0)
2901                NewEName =IR1I_RemoveBadCharacters(NewErrorWaveName)
2902                NewEName = CleanupName(NewEName, 1 )
2903                NewEName=IR1I_TrunkateName(NewEName,TrunkateStart,TrunkateEnd,RemoveStringFromName)
2904        else
2905                TempFirstPart = NewErrorWaveName[0,strsearch(NewErrorWaveName, "<fileName>", 0 )-1]
2906                tempLastPart  = NewErrorWaveName[strsearch(NewErrorWaveName, "<fileName>", 0 )+10,inf]
2907                if(IncludeExtensionInName)
2908                        NewEName = TempFirstPart+IR1I_TrunkateName(selectedFile,TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
2909                else
2910                        NewEName = TempFirstPart+IR1I_TrunkateName(StringFromList(0,selectedFile,"."),TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
2911                endif
2912                NewEName =IR1I_RemoveBadCharacters(NewEName)
2913                NewEName = CleanupName(NewEName, 1 )
2914        endif
2915        if(stringMatch(NewQErrorWaveName,"*<fileName>*")==0)
2916                NewQEName =IR1I_RemoveBadCharacters(NewQEName)
2917                NewQEName = CleanupName(NewQErrorWaveName, 1 )
2918                NewQEName=IR1I_TrunkateName(NewQEName,TrunkateStart,TrunkateEnd,RemoveStringFromName)
2919        else
2920                TempFirstPart = NewQErrorWaveName[0,strsearch(NewQErrorWaveName, "<fileName>", 0 )-1]
2921                tempLastPart  = NewQErrorWaveName[strsearch(NewQErrorWaveName, "<fileName>", 0 )+10,inf]
2922                if(IncludeExtensionInName)
2923                        NewQEName = TempFirstPart+IR1I_TrunkateName(selectedFile,TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
2924                else
2925                        NewQEName = TempFirstPart+IR1I_TrunkateName(StringFromList(0,selectedFile,"."),TrunkateStart,TrunkateEnd,RemoveStringFromName)+tempLastPart
2926                endif
2927                NewQEName =IR1I_RemoveBadCharacters(NewQEName)
2928                NewQEName = CleanupName(NewQEName, 1 )
2929        endif
2930        NVAr AutomaticallyOverwrite = root:Packages:ImportData:AutomaticallyOverwrite
2931        Wave/Z testE=$NewEName
2932        Wave/Z testQ=$NewQName
2933        Wave/Z testI=$NewIntName
2934        Wave/Z testQE=$NewQEName
2935        if ((WaveExists(testI) || WaveExists(testQ)||WaveExists(testE)||WaveExists(testQE))&&!AutomaticallyOverwrite)
2936                DoAlert 1, "The data of this name : "+NewIntName+" , "+NewQName+ " , "+NewEName+" , or "+NewQEName+"  exist. DO you want to overwrite them?"
2937                if (V_Flag==2)
2938                        abort
2939                endif
2940        elseif((WaveExists(testI) || WaveExists(testQ)||WaveExists(testE)||WaveExists(testQE))&&AutomaticallyOverwrite)
2941                //we ovewrote some data, let's at least know about it
2942                print "The data of this name : "+NewIntName+" , "+NewQName+ " , "+NewEName+" , or "+NewQEName+"  existed. Due to user selection, old data were deleted and replaced with newly imported ones."
2943        endif
2944               
2945        Duplicate/O TempQvector, $NewQName
2946        Duplicate/O TempIntensity, $NewIntName
2947        if(WaveExists(TempError))
2948                Duplicate/O TempError, $NewEName
2949        endif   
2950        if(WaveExists(TempQError))
2951                Duplicate/O TempQError, $NewQEName
2952        endif   
2953        KillWaves/Z tempError, tempQvector, TempIntensity, TempQError
2954        IR1I_KillAutoWaves()
2955end
2956//************************************************************************************************************
2957//************************************************************************************************************
2958//************************************************************************************************************
2959//************************************************************************************************************
2960//              Nexus Import functions
2961
2962//************************************************************************************************************
2963//************************************************************************************************************
2964
2965Function IR1I_ImportNexusCanSASMain()
2966        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
2967                //IR1_KillGraphsAndPanels()
2968        IN2G_CheckScreenSize("height",720)
2969        DoWindow IR1I_ImportData
2970        if(V_Flag)
2971                DoALert/T="Window conflict notice" 1, "Import SAS ASCII data cannot be open while using this tool, close (Yes) or abort (no)?"
2972                if(V_flag==1)
2973                        KillWIndow/Z IR1I_ImportData
2974                else
2975                        abort
2976                endif
2977        endif
2978        DoWindow IR1I_ImportOtherASCIIData
2979        if(V_Flag)
2980                DoALert/T="Window conflict notice" 1, "Import Nexus data cannot be open while using this tool, close (Yes) or abort (no)?"
2981                if(V_flag==1)
2982                        KillWIndow/Z IR1I_ImportOtherASCIIData
2983                else
2984                        abort
2985                endif
2986        endif
2987        KillWIndow/Z IR1I_ImportOtherASCIIData
2988        IR1I_InitializeImportData()
2989        IR1I_ImportNexusDataFnct()
2990        ING2_AddScrollControl()
2991        IR1_UpdatePanelVersionNumber("IR1I_ImportNexusCanSASData", IR1IversionNumberNexus,1)
2992        //fix these checkboxes;
2993        NVAR UseFileNameasFolder = root:Packages:ImportData:UseFileNameasFolder
2994        NVAR UsesasEntryNameAsFolder = root:Packages:ImportData:UsesasEntryNameAsFolder
2995        NVAR UseTitleNameAsFolder = root:Packages:ImportData:UseTitleNameAsFolder
2996        if((UseFileNameasFolder+UsesasEntryNameAsFolder+UseTitleNameAsFolder)!=1)
2997                UseFileNameasFolder  =0
2998                UsesasEntryNameAsFolder = 0
2999                UseTitleNameAsFolder = 1
3000        endif
3001
3002end
3003
3004//************************************************************************************************************
3005//************************************************************************************************************
3006//************************************************************************************************************
3007//************************************************************************************************************
3008//************************************************************************************************************
3009//************************************************************************************************************
3010
3011Function IR1I_ImportNexusDataFnct()
3012        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
3013        PauseUpdate; Silent 1           // building window...
3014        NewPanel /K=1 /W=(3,40,430,620)/N=IR1I_ImportNexusCanSASData as "Import Nexus canSAS data"
3015        TitleBox MainTitle title="\Zr200Import Nexus canSAS Data in Igor",pos={20,5},frame=0,fstyle=3, fixedSize=1,font= "Times New Roman", size={400,24},anchor=MC,fColor=(0,0,52224)
3016        IR3C_AddDataControls("ImportDataPath", "ImportData", "IR1I_ImportNexusCanSASData","", "","","IR1I_NexusDoubleClickFUnction")
3017        ListBox ListOfAvailableData,size={410,250}
3018        Button SelectDataPath pos={110,40}
3019        SetVariable DataPathString pos={2,62}
3020        SetVariable NameMatchString pos={5,85}
3021        SetVariable DataExtensionString pos={260,85}
3022        //CheckBox QvectorInA,pos={240,405},size={16,14},proc=IR1I_CheckProc,title="Q in [A^-1]",variable= root:Packages:ImportData:QvectInA, help={"What units is Q in? Select if in Angstroems ^-1"}
3023        //CheckBox QvectorInNM,pos={240,422},size={16,14},proc=IR1I_CheckProc,title="Q in [nm^-1]",variable= root:Packages:ImportData:QvectInNM, help={"What units is Q in? Select if in nanometers ^-1. WIll be converted to inverse Angstroems"}
3024        CheckBox UseFileNameAsFolderNX,pos={10,400},size={16,14},proc=IR1I_CheckProc,title="Use File Nms as Fldr Nms?",variable= root:Packages:ImportData:UseFileNameAsFolder, help={"Use names of imported files as folder names for the data?"}
3025        CheckBox UsesasEntryNameAsFolderNX,pos={10,415},size={16,14},proc=IR1I_CheckProc,title="Use sasEntry Nms as Fldr Nms?",variable= root:Packages:ImportData:UsesasEntryNameAsFolder, help={"Use names of imported files as folder names for the data?"}
3026        CheckBox UseTitleNameAsFolderNX,pos={10,430},size={16,14},proc=IR1I_CheckProc,title="Use sasTitle as Fldr Nms?",variable= root:Packages:ImportData:UseTitleNameAsFolder, help={"Use names of imported files as folder names for the data?"}
3027
3028        Button OpenFileInBrowser,pos={250,400},size={150,20},proc=IR1I_ButtonProc,title="Open File in Browser"
3029        Button OpenFileInBrowser,help={"Check file in HDF5 Browser"}
3030        Button GetHelp,pos={335,60},size={80,15},fColor=(65535,32768,32768), proc=IR1I_ButtonProc,title="Get Help", help={"Open www manual page for this tool"}
3031
3032        CheckBox NX_InclsasInstrument,pos={230,420},size={16,14},noproc,title="Incl sasInstrument in WVnote?",variable= root:Packages:ImportData:NX_InclsasInstrument, help={"Include values from sasInstrument group in wave note?"}
3033        CheckBox NX_Incl_sasSample,pos={230,435},size={16,14},noproc,title="Incl sasSample in WVnote?",variable= root:Packages:ImportData:NX_Incl_sasSample, help={"Include values from sasSample group in wave note?"}
3034        CheckBox NX_Inclsasnote,pos={230,450},size={16,14},noproc,title="Incl sasNote in WVnote?",variable= root:Packages:ImportData:NX_Inclsasnote, help={"Include values from sasNote group in wave note?"}
3035
3036        //CheckBox DataCalibratedArbitrary,pos={10,442},size={16,14},mode=1,proc=IR1I_CheckProc,title="Calibration Arbitrary\S \M",variable= root:Packages:ImportData:DataCalibratedArbitrary, help={"Data not calibrated (on relative scale)"}
3037        //CheckBox DataCalibratedVolume,pos={150,442},size={16,14},mode=1,proc=IR1I_CheckProc,title="Calibration cm\S-1\Msr\S-1\M",variable= root:Packages:ImportData:DataCalibratedVolume, help={"Data calibrated to volume"}
3038        //CheckBox DataCalibratedWeight,pos={290,442},size={16,14},mode=1,proc=IR1I_CheckProc,title="Calibration cm\S2\Mg\S-1\Msr\S-1\M",variable= root:Packages:ImportData:DataCalibratedWeight, help={"Data calibrated to weight"}
3039        SetVariable NewDataFolderName, pos={5,470}, size={410,20},title="New data folder:", proc=IR1I_setvarProc
3040        SetVariable NewDataFolderName value= root:packages:ImportData:NewDataFolderName,help={"Folder for the new data. Will be created, if does not exist.Or pick one ip popup above"}
3041        SetVariable NewQwaveName, pos={5,490}, size={320,20},title="Q wave names ", proc=IR1I_setvarProc, bodyWidth=230
3042        SetVariable NewQwaveName, value= root:packages:ImportData:NewQWaveName,help={"Input name for the new Q wave"}
3043        SetVariable NewIntensityWaveName, pos={5,510}, size={320,20},title="I wave names", proc=IR1I_setvarProc, bodyWidth=230
3044        SetVariable NewIntensityWaveName, value= root:packages:ImportData:NewIntensityWaveName,help={"Input name for the new intensity wave"}
3045        SetVariable NewErrorWaveName, pos={5,530}, size={320,20},title="Idev wv names", proc=IR1I_setvarProc, bodyWidth=230
3046        SetVariable NewErrorWaveName, value= root:packages:ImportData:NewErrorWaveName,help={"Input name for the new uncertyaintiy wave"}
3047        SetVariable NewQErrorWaveName, pos={5,550}, size={320,20},title="Qres wv names  ", proc=IR1I_setvarProc, bodyWidth=230
3048        SetVariable NewQErrorWaveName, value= root:packages:ImportData:NewQErrorWaveName,help={"Input name for the new Q resolution wave"}
3049
3050        Button ImportDataNexus,pos={330,510},size={80,30}, proc=IR1I_ButtonProc,title="Import"
3051        Button ImportDataNexus,help={"Import the selected data files."}
3052
3053        IR1I_ImportOtherSetNames()
3054//
3055//      PopupMenu SelectFolderNewData2,pos={10,590},size={250,21},proc=IR1I_PopMenuProc,title="Select data folder", help={"Select folder with data"}
3056//      PopupMenu SelectFolderNewData2,mode=1,popvalue="---",value= #"\"---;\"+IN2G_NewFindFolderWithWaveTypes(\"root:\", 10, \"*\", 1)"
3057//      CheckBox CreateSQRTErrors,pos={240,370},size={16,14},proc=IR1I_CheckProc,title="Create SQRT dY?",variable= root:Packages:ImportData:CreateSQRTErrors, help={"If input data do not contain errors, create errors as sqrt of intensity?"}
3058//      CheckBox CreatePercentErrors,pos={240,385},size={16,14},proc=IR1I_CheckProc,title="Create n% dY?",variable= root:Packages:ImportData:CreatePercentErrors, help={"If input data do not contain errors, create errors as n% of intensity?, select how many %"}
3059//      NVAR DiablePctErr=root:Packages:ImportData:CreatePercentErrors
3060//      SetVariable PercentErrorsToUse, pos={240,403}, size={100,20},title="dY %?:", proc=IR1I_setvarProc, disable=!(DiablePctErr)
3061//      SetVariable PercentErrorsToUse value= root:packages:ImportData:PercentErrorsToUse,help={"Input how many percent error you want to create."}
3062//
3063//      NVAR DisableExt=root:Packages:ImportData:UseFileNameAsFolder
3064//      CheckBox IncludeExtensionInName,pos={260,418},size={16,14},proc=IR1I_CheckProc,title="Include Extn?",variable= root:Packages:ImportData:IncludeExtensionInName, help={"Include file extension in imported data foldername?"}, disable=!(DisableExt)
3065////    CheckBox UseIndra2Names,pos={10,436},size={16,14},proc=IR1I_CheckProc,title="Use USAXS names?",variable= root:Packages:ImportData:UseIndra2Names, help={"Use wave names using Indra 2 name structure? (DSM_Int, DSM_Qvec, DSM_Error)"}
3066////    CheckBox ImportSMRdata,pos={150,436},size={16,14},proc=IR1I_CheckProc,title="Slit smeared?",variable= root:Packages:ImportData:ImportSMRdata, help={"Check if the data are slit smeared, changes suggested Indra data names to SMR_Qvec, SMR_Int, SMR_Error"}
3067////    CheckBox ImportSMRdata, disable= !root:Packages:ImportData:UseIndra2Names
3068//      CheckBox UseQRSNames,pos={10,452},size={16,14},proc=IR1I_CheckProc,title="Use QRS wave names?",variable= root:Packages:ImportData:UseQRSNames, help={"Use QRS name structure? (Q_filename, R_filename, S_filename)"}
3069////    CheckBox UseQISNames,pos={150,452},size={16,14},proc=IR1I_CheckProc,title="Use QIS (NIST) wv nms?",variable= root:Packages:ImportData:UseQISNames, help={"Use QIS name structure? (filename_q, filename_i, filename_s)"}
3070//
3071//      NVAR DisableOver=root:Packages:ImportData:UseFileNameAsFolder
3072//      CheckBox AutomaticallyOverwrite,pos={240,420},size={16,14},proc=IR1I_CheckProc,title="Overwrite existing data?",variable= root:Packages:ImportData:AutomaticallyOverwrite, help={"Automatically overwrite imported data if same data exist?"}, disable=!(DisableOver)
3073
3074//      SVAR DataTypeToImport=root:Packages:ImportData:DataTypeToImport
3075//      SVAR ListOfKnownDataTypes=root:Packages:ImportData:ListOfKnownDataTypes
3076//      PopupMenu ImportDataType,pos={10,450},size={250,21},proc=IR1I_PopMenuProc,title="Data Type", help={"Select waht data are being imported for proper naming"}
3077//      PopupMenu ImportDataType,mode=1,popvalue=DataTypeToImport,value= #"root:Packages:ImportData:ListOfKnownDataTypes"
3078//      SetVariable Wavelength, pos={260,453}, size={150,10}, variable=root:Packages:ImportData:Wavelength, noproc, help={"For Two Theta (Tth) we need wavelength in A"}
3079//      SetVariable Wavelength, disable = !StringMatch(DataTypeToImport,"Tth-Int")
3080
3081//      CheckBox ScaleImportedDataCheckbox,pos={10,475},size={16,14},proc=IR1I_CheckProc,title="Scale Imported data?",variable= root:Packages:ImportData:ScaleImportedData, help={"Check to scale (multiply by) factor imported data. Both Intensity and error will be scaled by same number. Insert appriate number right."}
3082//      NVAR DisableScale=root:Packages:ImportData:ScaleImportedData
3083//      SetVariable ScaleImportedDataBy, pos={200,475}, size={140,20},title="Scaling factor?:", proc=IR1I_setvarProc, disable=!(DisableScale)
3084//      SetVariable ScaleImportedDataBy limits={1e-32,inf,1},value= root:packages:ImportData:ScaleImportedDataBy,help={"Input number by which you want to multiply the imported intensity and errors."}
3085//      CheckBox RemoveNegativeIntensities,pos={10,500},size={16,14},proc=IR1I_CheckProc,title="Remove Int<=0?",variable= root:Packages:ImportData:RemoveNegativeIntensities, help={"Remove Intensities smaller than 0?"}
3086//      NVAR DisableTrim=root:Packages:ImportData:TrimData
3087//      CheckBox TrimData,pos={10,526},size={16,14},proc=IR1I_CheckProc,title="Trim data?",variable= root:Packages:ImportData:TrimData, help={"Check to trim Q range of the imported data."}
3088//      SetVariable TrimDataQMin, pos={110,524}, size={110,20},title="X min=", proc=IR1I_setvarProc, disable=!(DisableTrim)
3089//      SetVariable TrimDataQMin limits={0,inf,0},value= root:packages:ImportData:TrimDataQMin,help={"Xmin for trimming data. Leave 0 if not trimming at low q is needed."}
3090//      SetVariable TrimDataQMax, pos={240,524}, size={110,20},title="X max=", proc=IR1I_setvarProc, disable=!(DisableTrim)
3091//      SetVariable TrimDataQMax limits={0,inf,0},value= root:packages:ImportData:TrimDataQMax,help={"Xmax for trimming data. Leave 0 if not trimming at low q is needed."}
3092//
3093//      CheckBox ReduceNumPnts,pos={10,543},size={16,14},proc=IR1I_CheckProc,title="Reduce points?",variable= root:Packages:ImportData:ReduceNumPnts, help={"Check to log-reduce number of points"}
3094//      NVAR ReduceNumPnts = root:Packages:ImportData:ReduceNumPnts
3095//      SetVariable TargetNumberOfPoints, pos={140,541}, size={110,20},title="Num points=", proc=IR1I_setvarProc, disable=!(ReduceNumPnts)
3096//      SetVariable TargetNumberOfPoints limits={10,1000,0},value= root:packages:ImportData:TargetNumberOfPoints,help={"Target number of points after reduction. Uses same method as Data manipulation I"}
3097//
3098//      CheckBox TrunkateStart,pos={10,545},size={16,14},proc=IR1I_CheckProc,title="Truncate start of long names?",variable= root:Packages:ImportData:TrunkateStart, help={"Truncate names longer than 24 characters in front"}
3099//      CheckBox TrunkateEnd,pos={240,545},size={16,14},proc=IR1I_CheckProc,title="Truncate end of long names?",variable= root:Packages:ImportData:TrunkateEnd, help={"Truncate names longer than 24 characters at the end"}
3100//      SetVariable RemoveStringFromName, pos={5,565}, size={320,20},title="Remove Str From Name=", noproc
3101//      SetVariable RemoveStringFromName value= root:packages:ImportData:RemoveStringFromName,help={"Input string to be removed from name, leve empty if none"}
3102//
3103
3104EndMacro
3105 
3106 //************************************************************************************************************
3107//************************************************************************************************************
3108Function IR1I_NexusDoubleClickFUnction()
3109
3110        //IR1I_ButtonProc("TestImport")
3111        IR1I_ImportDataFnctNexus()
3112end
3113
3114 //************************************************************************************************************
3115//************************************************************************************************************
3116Function IR1I_ImportDataFnctNexus()
3117        IN2G_PrintDebugStatement(IrenaDebugLevel, 5,"")
3118
3119        string TopPanel=WinName(0, 64)
3120        string OldDf = getDataFolder(1)
3121       
3122        Wave/T WaveOfFiles      = root:Packages:ImportData:WaveOfFiles
3123        Wave WaveOfSelections = root:Packages:ImportData:WaveOfSelections
3124
3125        NVAR UseFolder = root:Packages:ImportData:UseFileNameasFolder
3126        NVAR UseEntry = root:Packages:ImportData:UsesasEntryNameAsFolder
3127        NVAR UseTitle = root:Packages:ImportData:UseTitleNameAsFolder
3128
3129        NVAR NX_SasIns = root:Packages:ImportData:NX_InclsasInstrument
3130        NVAR NX_SASSam = root:Packages:ImportData:NX_Incl_sasSample
3131        NVAR NX_SASNote = root:Packages:ImportData:NX_Inclsasnote
3132
3133        IR1I_CheckForProperNewFolder()
3134        variable i, imax, icount
3135        string SelectedFile
3136        imax = numpnts(WaveOfSelections)
3137        icount = 0
3138        for(i=0;i<imax;i+=1)
3139                if (WaveOfSelections[i])
3140                        selectedfile = WaveOfFiles[i]
3141                        NEXUS_NXcanSASDataReader("ImportDataPath",selectedFile,1,0, UseFolder, UseEntry,UseTitle, NX_SasIns,NX_SASSam,NX_SASNote )     
3142                        icount+=1
3143                endif
3144        endfor
3145        print "Imported "+num2str(icount)+" data file(s) in total"
3146        setDataFolder OldDf
3147end
3148
3149//************************************************************************************************************
3150//************************************************************************************************************
3151Function IR1I_NexusOpenHdf5File()
3152       
3153        Wave/T WaveOfFiles      = root:Packages:ImportData:WaveOfFiles
3154        Wave WaveOfSelections = root:Packages:ImportData:WaveOfSelections
3155       
3156        variable NumSelFiles=sum(WaveOfSelections)     
3157        variable OpenMultipleFiles=0
3158        if(NumSelFiles==0)
3159                return 0
3160        endif
3161        if(NumSelFiles>1)
3162                DoAlert /T="Choose what to do:" 2, "You have selected multiple files, do you want to open the first one [Yes], all [No], or cancel?"
3163                if(V_Flag==0)
3164                        return 0
3165                elseif(V_Flag==2)
3166                        OpenMultipleFiles=1
3167                endif
3168        endif
3169       
3170        variable i
3171        string FileName
3172        String browserName
3173        Variable locFileID
3174        For(i=0;i<numpnts(WaveOfSelections);i+=1)
3175                if(WaveOfSelections[i])
3176                        FileName= WaveOfFiles[i]
3177                        CreateNewHDF5Browser()
3178                        browserName = WinName(0, 64)
3179                        HDF5OpenFile/R /P=ImportDataPath locFileID as FileName
3180                        if (V_flag == 0)                                        // Open OK?
3181                                HDf5Browser#UpdateAfterFileCreateOrOpen(0, browserName, locFileID, S_path, S_fileName)
3182                        endif
3183                        if(!OpenMultipleFiles)
3184                                return 0
3185                        endif
3186                endif
3187        endfor
3188end
3189
3190//************************************************************************************************************
3191//************************************************************************************************************
Note: See TracBrowser for help on using the repository browser.