source: trunk/User Procedures/Nika/NI1_Main.ipf @ 1221

Last change on this file since 1221 was 1221, checked in by ilavsky, 5 months ago

NIka, 12IDB work. Added Transpose/flip to image import and removed Calibrated 2D data. Not sure if used at all.

  • Property svn:executable set to *
File size: 44.0 KB
Line 
1#pragma TextEncoding = "UTF-8"
2#pragma rtGlobals=3             // Use modern global access method.
3#pragma version=1.84
4#pragma IgorVersion=8.04
5
6//DO NOT renumber Main files every time, these are main release numbers...
7
8constant CurrentNikaVersionNumber = 1.842
9constant FixBackgroundOversubScale=1.05                 //this is used to fix oversubtracted background. Adds FixBackgroundOversubScale*abs(V_min) to all intensity value.
10constant NikaNumberOfQCirclesDisp=15
11constant NikaLengthOfPathForPanelDisplay=100
12//*************************************************************************\
13//* Copyright (c) 2005 - 2022, Argonne National Laboratory
14//* This file is distributed subject to a Software License Agreement found
15//* in the file LICENSE that is included with this distribution.
16//*************************************************************************/
17
18//1.84  Ocotber2021 version
19//                      Fixes for some loaders where users found failures. 
20//1.83          require Igor 8.03 now. Not testing Igor 7 anymore.
21//                      Improve NXcanSAS 2D calibrated data import for NSLS-SMI beamline.
22//1.826         Beta version after February2020 release
23//1.82  rtGlobal=3 forced for all
24//                      Added support for 12ID-C data.
25//                      Add print in history which version has compiled, Useful info later when debugging.
26//1.81   December 2018 release. Updated 64bit xops, mainly for OSX.
27//                      Added 12ID-C support, first release.
28//1.80          Official Igor 8 release, Fixed NEXUS exporter to save data which are easily compatible with sasView. sasView has serious limitations on what it can accept as input NXcanSAS nexus data.
29//                      Removed range selection controls and moved Save data options to its own tab "Save"
30//                      Added ImageStatistics and control for user for delay between series of images.
31//                      Added font type and size control from configuration to be used for CCD image label.
32//                      Added ability to fix negative intensities oversubtraction. Checkbox on Empty tab and if checked, ~1.5*abs(V_min) is added to ALL points intensities.
33//1.79          Converted all procedure files to UTF8 to prevent text encoding issues.
34//                      Modified main interface to have radio buttons and only one button for action. This makes cleaner interface as some controls can be hidden. Unluckily, panel is now higher by 20 points.
35//                      Added support for ALS SRoXS soft energy beamline.
36//                      Improved 9IDC USAXS support.
37//                      Added more masking options into main panel listbox right click.
38//                      Checked that - with reduced functionality - code will work without Github distributed xops.
39//                      Bug fix - changed ki/kout single precision waves to double precision. This caused issues under very small angles when data were unintentionally binned to less points what should have been produced. This is very old bug causing issues at very small Q vectors with short wavelengths and no beamstops. 
40//                      Tested and fixed for Igor 8 beta version.
41//                       
42//1.78  Promoted Igor requirements to 7.05 due to bug in HDF5 support at lower versions
43//              FIxed problem with change geometries, when Nexus Import TMP foldr was not deleted and this caused issues.
44//              Added simple recording to my web site about version checking for statistical purposes. Records Nika version, Igor platform and version. 
45//              Creating new configuration will now reopen 9ID config screen if it was opened before.
46//              modified Configuration manager to be may be less confusing...
47//1.77  Updated CheckForUpdate to check on Github for latest release version
48//              Add call to ReadTheDocs manuals. Added CheckDisplayArea and modified how Nika checks for available screen size.
49//              #pragma IgorVersion=7.00
50//1.76 version 1.75 with on line help and Igor 6 only
51//1.75 rewrote Nexus support, added check for desktop resolution
52//1.74          added scaling of images on large displays       
53//1.73 added functions to scale panels to larger sizes.
54//1.72 changed check for update procedure to check http first, then ftp, and the fail.
55//1.71 Added NI1_SetAllPathsInNIka function to set all paths to the same place for users with simple setups.
56//1.70 added multiple geometries manager, removed the warning about the uncertainty method, drive me crazy and no one seems to care enough.
57//1.69 added some warnings about uncertainty method changes when read from preferences.
58//1.68 release, fixes for 9ID USAXS and other fixes listed
59//1.67 Release to fix Mask tool broken in 1.66 release.
60//1.66 fixed ListProRoutine which had troubles with links
61//1.65 minor changes, timed with Indra 2 release.
62//1.64 match current release number
63//1.61 added Monthly check for updates and reminder with citations
64//1.60  9IDC support changes
65//1.59 Minor updates
66//1.58 Fixed GUI fonts/size controls issues on Widonws 7, modified Configure Nika preferences to include action on double click.
67//1.57 New mailing list, SSRL SAXS support, fixes to 15ID SAXS etc.
68//1.56 More pinSAXS support (and not finished yet) and some changes to available color scales.
69//1.55 Fixed 9IDC Nexus support for 2/2012 Nexus files.
70//1.53 Added support for azimuthal angle output (useful when using ellipse for line profile)
71//1.52 Added pinSAXS support for 9IDC USAXS instrument
72//1.51 added Movie creation and Pilatus 300k
73//1.50 minor update, fixed bug in calibration routien when correction for transmission was done before dark frame subtraction.
74//1.49 main fix is tilts. Number of other improvements.
75//1.48 added license for ANL, fixed compatibility problem for Igor 6.21 and TransformAxis1.2 upgrade
76//version 1.47 fix for Igor 6.20
77//version 1.46 fixed bug in Configuring the GUI parameters
78//version 1.45 adds mpa/UC file type
79// version 1.44  fixed bug for adding Q axes in the image
80// version 1.43  adds Pilatus loader. Unfinished, need to get test files to check 1M and 2M.
81// version 1.42 adds line profile support - including GISAXS geometry and ellipse.
82//date: October 30, 2009 released as final 1.42 version.
83//This is main procedure file for NIKA 1 2-D SAS data conversion package
84
85
86Menu "SAS 2D"
87        "Main panel", NI1A_Convert2Dto1DMainPanel()
88        help={"This should call the conversion routines for CCD data"}
89        "Beam center and Geometry cor.", NI1_CreateBmCntrFile()
90        help={"Tool to create beam center and geometry corrections."}
91        "Create mask", NI1M_CreateMask()
92        help={"Allows user to create mask based on selected measurement image"}
93        "Create flood field", NI1_Create2DSensitivityFile()
94        help={"Allows user to create pixel 2 d sensitivity file based on selected measured image"}
95        "Image line profile", NI1_CreateImageLineProfileGraph()
96        help={"Calls Image line profile (Wavemetrics provided) function"}
97        "---"
98        "Config fonts, uncertainties, names",NI1_ConfigMain()
99        help={"Configure method for uncertainity values for GUI behavior and for panels font sizes and font types"}
100        "Configuration manager", NI1_GeometriesManager()
101        help={"This enables switching among multiple Nika geometries, such as distances or wavelengths"}
102        Submenu "Instrument configurations"
103                "9IDC USAXS-SAXS-WAXS", NI1_9IDCConfigureNika()
104                help={"Support for data from 9ID or9IDC (USAXS/SAXS) beamline at APS"}
105                "RSoXS ALS soft energy instrument", NI1_RSoXSCreateGUI()
106                help={"Support for data from ALS soft energy beamline"}
107                "APS 12ID-C SAXS with Gold Detector", NI1_12IDCLoadAndSetup()
108                help={"Support for data from APS 12ID-C camera"}
109                "APS 12ID-B SAXS-WAXS (Nexus or tiff)", NI1_12IDBLoadAndSetup()
110                help={"Support for data from APS 12ID-B camera"}               
111                "DND CAT", NI1_DNDConfigureNika()
112                help={"Support for data from DND CAT (5ID) beamline at APS"}
113                "SSRL Mat SAXS", NI1_SSRLSetup()
114                help={"Support for data from SSRL Materials Scienc e SAXS beamline"}
115                "TPA", NI1_TPASetup()
116                help={"Support for data TPA  XML (SANS)"}
117        end
118        Submenu "Helpful tools"
119                "Set same paths and Image types", NI1_SetAllPathsInNIka()
120                help={"Sets the paths for Sample, Empty, Mask, Calibrant to the same place."}
121        end
122        "HouseKeeping", NI1_Cleanup2Dto1DFolder()
123        help={"Removes large waves from this experiment, makes file much smaller. Resets junk... "}
124        "Remove stored images", NI1_RemoveSavedImages()
125        help={"Removes stored images - does not remove USED images, makes file much smaller. "}
126        "---"
127        "Open Nika web page", NI1_OpenNikaWebPage()
128        help={"Opens Nika web page."}
129        "Open Nika web manual", IN2G_OpenWebManual("")
130        help={"Opens Nika web manual in default web bropwser."}
131        "Remove Nika 1 macros", NI1_RemoveNika1Mac()
132        help={"Removes the macros from the current experiment. Macros can be loaded when necessary again"}
133        "Nika Mailing list signup and options", NI1_SignUpForMailingList()
134        help={"Opens web page in the browser where you can sing up or control options for nika_users mailing list."}
135        "Check for updates", NI1_CheckNikaUpdate(1)
136        help={"Run Check for update and present citations to use in publications"}     
137        "Close all Nika Panels and Windows", NI1_GMCloseAllNikaW()
138        help={"Closes all Panels and windows from Nika. "}     
139        "Check Igor display size", IN2G_CheckForGraphicsSetting(1)
140        help={"Check if current display area is suitable for the code"}
141        "Open Readme", NI1_OpenReadme()
142        help={"Open notes about recent changes in the code. "}
143        "About", NI1_AboutPanel()
144        help={"Get Panel with info about this release of Nika macros"}
145//      "---"
146//      "Test Marquee", NI1B_Fitto2DGaussian1()
147end
148
149
150Menu "GraphMarquee"
151        "Image Expand", NI1_MarExpandContractImage(1)
152        "Image Contract", NI1_MarExpandContractImage(0)
153End
154
155Menu "Macros", dynamic
156        NI1_MacrosMenuItem()
157end
158
159Function/S NI1_MacrosMenuItem()
160        if((Exists("ShowResizeControlsPanel")==6)&& (!Exists("IR1_AboutPanel")))
161                return "ShowResizeControlsPanel"
162        else
163                return ""
164        endif
165end
166//*****************************************************************************************************************
167//*****************************************************************************************************************
168//*****************************************************************************************************************
169//*****************************************************************************************************************
170//****************************************************************
171//*****************************************************************************************************************
172//*****************************************************************************************************************
173
174Function NI1_SetAllPathsInNIka()
175                DoWindow NI1A_Convert2Dto1DPanel
176                if(!V_Flag)             //does nto exists, quit
177                        NI1A_Convert2Dto1DMainPanel()
178                else
179                        DoWIndow/F NI1A_Convert2Dto1DPanel
180                endif
181                PathInfo/S Convert2Dto1DEmptyDarkPath
182                NewPath/C/O/M="Select path to your data" Convert2Dto1DDataPath
183                PathInfo Convert2Dto1DDataPath
184                string pathInforStrL = S_path[strlen(S_path)-NikaLengthOfPathForPanelDisplay,strlen(S_path)-1]
185                NewPath/O/Q Convert2Dto1DEmptyDarkPath, pathInforStrL           
186                SVAR MainPathInfoStr=root:Packages:Convert2Dto1D:MainPathInfoStr
187                MainPathInfoStr = pathInforStrL
188                SVAR/Z BCPathInfoStr=root:Packages:Convert2Dto1D:BCPathInfoStr
189                if(!SVAR_Exists(BCPathInfoStr))
190                        NI1BC_InitCreateBmCntrFile()
191                        SVAR BCPathInfoStr=root:Packages:Convert2Dto1D:BCPathInfoStr
192                endif
193                NewPath/O/Q Convert2Dto1DBmCntrPath, pathInforStrL
194                //PathInfo Convert2Dto1DBmCntrPath
195                BCPathInfoStr=S_Path
196                NewPath/O/Q Convert2Dto1DMaskPath, pathInforStrL
197                //now also let users set the correct image type
198                String SelectedImageType=".tif"
199                SVAR ListOfKnownExtensions = root:Packages:Convert2Dto1D:ListOfKnownExtensions
200                Prompt SelectedImageType, "Image type", popup, ListOfKnownExtensions
201                DoPrompt /HELP="Select proper image type" "Select Image type for all images", SelectedImageType
202                if(V_Flag==0)
203                        //here we need to set all types.
204                        print SelectedImageType
205                        SVAR DataFileExtension=root:Packages:Convert2Dto1D:DataFileExtension
206                        DataFileExtension = SelectedImageType
207                        if(cmpstr(DataFileExtension,"GeneralBinary")==0)
208                                NI1_GBLoaderPanelFnct()
209                        endif
210                        if(cmpstr(DataFileExtension,"Pilatus")==0)
211                                NI1_PilatusLoaderPanelFnct()
212                        endif
213                        if(cmpstr(DataFileExtension,"ESRFedf")==0)
214                                NI1_ESRFEdfLoaderPanelFnct()
215                        endif   
216                        if(cmpstr(DataFileExtension,"Nexus")==0)
217                                NEXUS_NikaCall(1)
218                                NVAR NX_InputFileIsNexus=root:Packages:Irena_Nexus:NX_InputFileIsNexus
219                                NX_InputFileIsNexus = 1
220                        else
221                                NVAR/Z NX_InputFileIsNexus=root:Packages:Irena_Nexus:NX_InputFileIsNexus
222                                if(NVAR_Exists(NX_InputFileIsNexus))
223                                        NX_InputFileIsNexus = 0
224                                endif
225                        endif   
226                        NEXUS_NikaCall(0)
227                        //update main pane
228                        DoWIndow NI1A_Convert2Dto1DPanel
229                        if(V_Flag)
230                                PopupMenu Select2DDataType   win=NI1A_Convert2Dto1DPanel, popmatch=SelectedImageType
231                        PopupMenu SelectBlank2DDataType  win=NI1A_Convert2Dto1DPanel, popmatch=SelectedImageType
232                        endif
233                       
234                        SVAR BlankFileExtension=root:Packages:Convert2Dto1D:BlankFileExtension
235                        BlankFileExtension = SelectedImageType
236                        SVAR BMFunctionName=root:Packages:Convert2Dto1D:BMFunctionName
237                        BMFunctionName = SelectedImageType
238                        SVAR BmCntrFileType=root:Packages:Convert2Dto1D:BmCntrFileType
239                        BmCntrFileType = SelectedImageType
240                        DoWIndow NI1_CreateBmCntrFieldPanel
241                        if(V_Flag)
242                                PopupMenu BmCntrFileType win=NI1_CreateBmCntrFieldPanel, popmatch=SelectedImageType
243                        endif
244                       
245                       
246                        SVAR CCDFileExtension = root:Packages:Convert2Dto1D:CCDFileExtension
247                        CCDFileExtension = SelectedImageType
248                        DoWIndow NI1M_ImageROIPanel
249                        if(V_Flag)
250                                PopupMenu CCDFileExtension win=NI1M_ImageROIPanel, popmatch=SelectedImageType
251                        endif
252                       
253                endif
254                NI1BC_UpdateBmCntrListBox()     
255                NI1A_UpdateDataListBox()       
256                NI1A_UpdateEmptyDarkListBox()   
257end
258
259//****************************************************************************************
260//****************************************************************************************
261//****************************************************************************************
262
263static Function AfterCompiledHook( )                    //check if all windows are up to date to match their code
264
265        NVAR/Z LastCheckNika=root:Packages:LastCheckNika
266        if(!NVAR_Exists(LastCheckNika))
267                variable/g root:Packages:LastCheckNika
268                NVAR LastCheckNika=root:Packages:LastCheckNika
269        endif   
270        string WindowProcNames="NI1A_Convert2Dto1DPanel=NI1A_MainCheckVersion;NI1_CreateBmCntrFieldPanel=NIBC_MainCheckVersion;NEXUS_ConfigurationPanel=Nexus_MainCheckVersion;"
271       
272        NI1A_CheckWIndowsProcVersions(WindowProcNames)
273        IN2G_ResetSizesForALlPanels(WindowProcNames)
274        IN2G_AddButtonsToBrowser()              //adds button to DataBrowser.
275        if((DateTime - LastCheckNika)>60*60*12)         //run this only once per 12 hours.
276                IN2G_CheckForGraphicsSetting(0)
277                NI1_CheckNikaUpdate(0)
278                print "*** >>>  Nika version : "+num2str(CurrentNikaVersionNumber)+", compiled on "+date()+"  "+time()
279                LastCheckNika = DateTime
280        endif
281       
282end
283 
284
285//*****************************************************************************************************************
286//*****************************************************************************************************************
287//*****************************************************************************************************************
288//*****************************************************************************************************************
289//*****************************************************************************************************************
290
291Function NI1_RemoveNika1Mac()
292                NI1_Cleanup2Dto1DFolder()
293                Execute/P "NI1_KillGraphsAndPanels()"
294                Execute/P "DELETEINCLUDE \"NI1_Loader\""
295                SVAR strChagne=root:Packages:Nika12DSASItem1Str
296                strChagne= "Load Nika 2D SAS Macros"
297                BuildMenu "Macros"
298                Execute/P "COMPILEPROCEDURES "
299end
300
301//*****************************************************************************************************************
302
303Function NI1_KillGraphsAndPanels()
304
305
306
307        String ListOfWindows
308        ListOfWindows = "NI1A_Convert2Dto1DPanel;NI1_9IDCConfigPanel;CCDImageToConvertFig;EmptyOrDarkImage;NI1_CreateBmCntrFieldPanel;CCDImageForBmCntr;"
309        ListOfWindows += "NI1M_ImageROIPanel;NI1_CreateFloodFieldPanel;NI1_GeometriesManagerPanel;NI1_RSoXSMainPanel;APS12IDC_Instructions;DND_Instructions;"
310       
311       
312        variable i
313        string TempNm
314        For(i=0;i<ItemsInList(ListOfWindows);i+=1)
315                TempNm = stringFromList(i,ListOfWindows)
316                KillWIndow/Z $TempNm
317        endfor
318end
319
320////*****************************************************************************************************************
321Function NI1_OpenReadme()
322        DoWIndow NikaReadme
323        if(V_Flag)
324                DoWIndow/F NikaReadme
325        else
326                string PathToReadMe= RemoveListItem(ItemsInList(FunctionPath("NI1_OpenReadme"),":")-1, FunctionPath("NI1_OpenReadme"), ":")
327                PathToReadMe = PathToReadMe+"Modification history.txt"
328                OpenNotebook /K=1 /R /N=NikaReadme /ENCG=3 /W=(20,20,720,600) /Z PathToReadMe
329        endif
330end
331////*****************************************************************************************************************
332////*****************************************************************************************************************
333//*****************************************************************************************************************
334//*****************************************************************************************************************
335Function NI1_SignUpForMailingList()
336        DoAlert 1,"Your web browser will open page with the page where you can control your maling list options. OK?"
337        if(V_flag==1)
338                BrowseURL "https://mailman.aps.anl.gov/mailman/listinfo/nika_users"
339        endif
340End
341//****************************************************************
342Function NI1_OpenNikaWebPage()
343                BrowseURL "https://usaxs.xray.aps.anl.gov/software/nika"
344end
345//**************************************************************
346//*****************************************************************************************************************
347//*****************************************************************************************************************
348
349Function NI1_AboutPanel()
350        KillWIndow/Z About_Nika_1_Macros
351        PauseUpdate             // building window...
352        NewPanel/K=1 /W=(173.25,101.75,550,340) as "About_Nika_1_Macros"
353        DoWindow/C About_Nika_1_Macros
354        SetDrawLayer UserBack
355        SetDrawEnv fsize= 18,fstyle= 1,textrgb= (16384,28160,65280)
356        DrawText 10,37,"Nika 1 macros for Igor Pro 8.04 & 9.x"
357        SetDrawEnv fsize= 16,textrgb= (16384,28160,65280)
358        DrawText 52,64,"@ ANL, 2021"
359        DrawText 49,103,"Release "+num2str(CurrentNikaVersionNumber)
360        DrawText 11,136,"To get help please contact: ilavsky@aps.anl.gov"
361        DrawText 11,156,"https://usaxs.xray.aps.anl.gov/software-description"
362
363        DrawText 11,190,"Set of macros to convert 2D SAS images"
364        DrawText 11,210,"into 1 D data"
365        //DrawText 11,230,"     "
366        //DrawText 11,250," "
367        //DrawText 11,265,"Igor 8.04 & 9.x compatible"
368end
369
370//*****************************************************************************************************************
371//*****************************************************************************************************************
372//*****************************************************************************************************************
373//*****************************************************************************************************************
374//*****************************************************************************************************************
375Function NI1_RemoveSavedImages()
376       
377        string OldDf=GetDataFolder(1)
378        setDataFolder root:
379        NewDataFOlder/S/O SavedImages
380        string AllWaves=IN2G_CreateListOfItemsInFolder("root:SavedImages", 2)
381        variable i
382        For(i=0;i<ItemsInList(AllWaves);i+=1)
383                Killwaves/Z $(StringFromList(i,AllWaves))
384        endfor
385        setDataFolder root:
386        if(strlen(IN2G_CreateListOfItemsInFolder("root:SavedImages", 2))<2)
387                KillDataFolder root:SavedImages
388        endif
389        setDataFolder OldDf
390end
391//*****************************************************************************************************************
392//*****************************************************************************************************************
393//*****************************************************************************************************************
394//*****************************************************************************************************************
395//*****************************************************************************************************************
396Function NI1_Cleanup2Dto1DFolder()
397
398        string OldDf=getDataFolder(1)
399        if(!DataFolderExists("root:Packages:Convert2Dto1D" ))
400                abort
401        endif
402        setDataFolder root:Packages:Convert2Dto1D
403       
404        string ListOfWaves=IN2G_ConvertDataDirToList(DataFolderDir(2 ))
405        string CurStr
406        variable i, imax=ItemsInList(ListOfWaves)
407        String ListOfWavesToKill
408        ListOfWavesToKill="Rdistribution1D;Radius2DWave;AnglesWave;Qvector_;LUT;HistogramWv;Dspacing;Qvectorwidth;TwoTheta;Q2DWave;RadiusPix2DWave;"
409        variable j
410
411        For(i=0;i<imax;i+=1)
412                CurStr = stringFromList(i,ListOFWaves)
413                For(j=0;j<ItemsInList(ListOfWavesToKill);j+=1)
414                        if(stringmatch(CurStr, "*"+stringFromList(j,ListOfWavesToKill)+"*"))
415                                Wave killme=$(CurStr)
416                                KillWaves/Z killme
417                        endif
418                endfor
419        endfor
420        KillWaves/Z CCImageToConvert_dis, DarkFieldData_dis,EmptyData_dis, MaskCCDImage, Calibrated2DDataSet, Pixel2DSensitivity_dis
421        KillWaves/Z FloodFieldImg, MaxNumPntsLookupWv, MaxNumPntsLookupWvLBL, PixRadius2DWave, fit_BmCntrCCDImg,fit_BmCntrCCDImgX,fit_BmCntrCCDImgY
422        KillWaves/Z BmCntrCCDImg,BmCntrDisplayImage, BmCntrDisplayImage, BmCntrCCDImg, xwave, xwaveT, ywave, ywaveT
423       
424        setDataFolder OldDf
425end
426//*******************************************************************************************************************************************
427//*******************************************************************************************************************************************
428//*******************************************************************************************************************************************
429//*******************************************************************************************************************************************
430//*******************************************************************************************************************************************
431//*******************************************************************************************************************************************
432Function NI1_MarExpandContractImage(isExpand)
433        Variable isExpand
434       
435        String imName= StringFromList(0,ImageNameList("",";"))
436        String imInfo= ImageInfo("",imName,0)
437        if( strlen(imInfo) == 0 )
438                return 0        // no image
439        endif
440       
441        String xa= StringByKey("XAXIS",imInfo)
442        String ya= StringByKey("YAXIS",imInfo)
443       
444        GetMarquee/K $xa,$ya
445        Variable x0= V_left, x1= V_right, y0= V_top, y1= V_bottom
446       
447        GetAxis/Q $xa
448        Variable xmin= V_min, xmax= V_max
449        GetAxis/Q $ya
450        Variable ymin= V_min, ymax= V_max
451       
452        Variable fract= (x1-x0)/ (xmax-xmin)            // take x expand or contract as the single factor
453       
454        Variable yc= (y0+y1)/2, xc= (x0+x1)/2
455       
456       
457        if( isExpand )
458                x0= xc - fract*(xmax-xmin)/2
459                x1= xc + fract*(xmax-xmin)/2
460                y0= yc - fract*(ymax-ymin)/2
461                y1= yc + fract*(ymax-ymin)/2
462        else
463                x0= xc -(xmax-xmin)/(2*fract)
464                x1= xc +(xmax-xmin)/(2*fract)
465                y0= yc -(ymax-ymin)/(2*fract)
466                y1= yc +(ymax-ymin)/(2*fract)
467                       
468        endif
469       
470        if( xmin > xmax )
471                SetAxis/R $xa,x0,x1
472        else
473                SetAxis $xa,x0,x1
474        endif
475        if(ymin > ymax )
476                SetAxis/R $ya,y0,y1
477        else
478                SetAxis $ya,y0,y1
479        endif
480end
481//***********************************************************
482//***********************************************************
483//***********************************************************
484
485Function NI1_ConfigMain()               //call configuration routine
486        IN2G_ConfigMain()       
487       
488end
489
490//***********************************************************
491//***********************************************************
492//***********************************************************
493//***********************************************************
494
495Function NI1_ReadNikaGUIPackagePrefs()
496        IN2G_ReadIrenaGUIPackagePrefs(0)
497end
498//***********************************************************
499//***********************************************************
500//***********************************************************
501//***********************************************************
502///***********************************************************
503//***********************************************************
504////***********************************************************
505//***********************************************************
506//***********************************************************
507//***********************************************************
508//***********************************************************
509
510Function NI1_ChangePanelControlsStyle()
511
512        SVAR DefaultFontType=root:Packages:IrenaConfigFolder:DefaultFontType
513        NVAR DefaultFontSize=root:Packages:IrenaConfigFolder:DefaultFontSize
514
515        if (stringMatch(IgorInfo(2),"*Windows*"))               //Windows
516                DefaultGUIFont /Win   all= {DefaultFontType, DefaultFontSize, 0 }
517        else
518                DefaultGUIFont /Mac   all= {DefaultFontType, DefaultFontSize, 0 }
519        endif
520
521end
522//***********************************************************
523//***********************************
524//***********************************
525
526Function NI1_CheckNikaUpdate(CalledFromMenu)
527        variable CalledFromMenu
528        //CalledFromMenu=1 run always...
529        IN2G_ReadIrenaGUIPackagePrefs(0)
530        NVAR LastUpdateCheckNika=root:Packages:IrenaConfigFolder:LastUpdateCheckNika   
531        if(datetime - LastUpdateCheckNika >30 * 24 * 60 * 60 || CalledFromMenu)
532                        //call check version procedure and advise user on citations
533                        NI1_CheckVersions()
534                        IN2G_SubmitCheckRecordToWeb("Nika "+num2str(CurrentNikaVersionNumber))
535                        LastUpdateCheckNika = datetime
536                        IN2G_SaveIrenaGUIPackagePrefs(0)
537                        IN2G_GetAndDisplayUpdateMessage()
538        endif
539        if (str2num(stringByKey("IGORVERS",IgorInfo(0)))<7.05)
540                        DoAlert /T="Igor update message :"  0, "Igor has been updated to version 7.05 or higher. Please, update your Igor to the latest version." 
541                        BrowseURL "http://www.wavemetrics.com/support/versions.htm"
542        endif
543         
544end
545
546//****************************************************************
547//****************************************************************
548static Function NI1_CheckVersions()
549        string PackageString   
550        //create list of Igor procedure files on this machine
551        IN2G_ListIgorProcFiles()
552        DoWIndow CheckForNikaUpdatePanel
553        if(V_Flag)
554                DoWIndow/F CheckForNikaUpdatePanel                                                             
555        else
556                Execute("CheckForNikaUpdatePanel()")                   
557        endif
558        //Nika code
559        string OldDf=GetDataFolder(1)
560        //create location for the results waves...
561        NewDataFolder/O/S root:Packages
562        NewDataFolder/O/S root:Packages:UseProcedureFiles
563        variable/g InstalledNikaVersion
564        variable/g WebNikaVersion               
565        InstalledNikaVersion = IN2G_FindFileVersion("Boot Nika.ipf")   
566        WebNikaVersion = IN2G_CheckForNewVersion("Nika")
567        if(numtype(WebNikaVersion)!=0)
568                Print "Check for latest Nika version failed. Check your Internet connection. Try later again..."
569        endif
570        SetDataFOlder OldDf
571end     
572
573
574
575//Motofit paper [J. Appl. Cryst. 39, 273-276]
576//http://scripts.iucr.org/cgi-bin/paper?S0021889806005073
577//J. Appl. Cryst. (2006). 39, 273-276    [ doi:10.1107/S0021889806005073 ]
578//A. Nelson, Co-refinement of multiple-contrast neutron/X-ray reflectivity data using MOTOFIT
579//
580
581
582
583Function NI1_CheckVersionButtonProc(ba) : ButtonControl
584        STRUCT WMButtonAction &ba
585
586        switch( ba.eventCode )
587                case 2: // mouse up
588                        // click code here
589                        if(stringmatch(ba.ctrlName,"OpenNikaWebPage"))
590                                //open web page with Nika
591                                BrowseURL "https://usaxs.xray.aps.anl.gov/software/nika"
592                        endif
593                        if(stringmatch(ba.ctrlName,"OpenNikaManuscriptWebPage"))
594                                //open web page with Nika
595                                BrowseURL "http://dx.doi.org/10.1107/S0021889812004037"
596                        endif
597                        if(stringmatch(ba.ctrlName,"OpenGCManuscriptWebPage"))
598                                //doi:10.1007/s11661-009-9950-x
599                                BrowseURL "https://link.springer.com/article/10.1007/s11661-009-9950-x"
600                        endif
601                       
602                        break
603                case -1: // control being killed
604                        break
605        endswitch
606
607        return 0
608End
609//****************************************************************
610//****************************************************************
611//***********************************
612//***********************************
613
614Window CheckForNikaUpdatePanel() : Panel
615        PauseUpdate             // building window...
616        NewPanel /W=(116,68,880,400)/K=1 as "Nika check for updates"
617        SetDrawLayer UserBack
618        SetDrawEnv fsize= 20,fstyle= 3,textrgb= (0,0,65535)
619        DrawText 114,37,"Once-per-month reminder to check for Nika update"
620        SetDrawEnv fsize= 14,fstyle= 3,textrgb= (65535,0,0)
621        DrawText 27,110,"Reminder: When publishing data reduced using Nika package, please cite following manuscripts:"
622        SetDrawEnv textrgb= (0,0,65535)
623        DrawText 27,133,"J. Ilavsky Nika: software for two-dimensional data reduction "
624        SetDrawEnv textrgb= (0,0,65535)
625        DrawText 27,158,"J. Appl. Cryst. (2012). 45, 324–328"
626        SetDrawEnv textrgb= (0,0,65535)
627        DrawText 27,205,"Glassy Carbon Absolute Int. Calibration: F. Zhang, J. Ilavsky, G. G. Long, J. P.G. Quintana, "
628        SetDrawEnv textrgb= (0,0,65535)
629        DrawText 27,230,"A. J. Allen, and P. Jemian, Glassy Carbon as an Absolute Intensity Calibration Standard"
630        SetDrawEnv textrgb= (0,0,65535)
631        DrawText 27,255,"for Small-Angle Scattering, MMTA, DOI: 10.1007/s11661-009-9950-x"
632
633        SetDrawEnv fstyle= 2,fsize= 10,textrgb= (0,0,0)
634        DrawText 10,320,"This tool runs automatically every 30 days on each computer. It can be also called from the SAS2D menu as \"Check for updates\""
635
636        SetVariable InstalledNikaVersion,pos={48,56},size={199,15},bodyWidth=100,title="Installed Nika Version"
637        SetVariable InstalledNikaVersion,help={"This is the current Nika version installed"}
638        SetVariable InstalledNikaVersion,fStyle=1
639        SetVariable InstalledNikaVersion,limits={0,0,0},value= root:Packages:UseProcedureFiles:InstalledNikaVersion,noedit= 1
640        SetVariable WebNikaVersion,pos={297,56},size={183,15},bodyWidth=100,title="Web Nika Version"
641        SetVariable WebNikaVersion,help={"This is the current Nika version installed"}
642        SetVariable WebNikaVersion,fStyle=1
643        SetVariable WebNikaVersion,limits={0,0,0},value= root:Packages:UseProcedureFiles:WebNikaVersion,noedit= 1
644        Button OpenNikaWebPage,pos={551,53},size={150,20},proc=NI1_CheckVersionButtonProc,title="Open Nika web page"
645        Button OpenNikaManuscriptWebPage,pos={551,143},size={150,20},proc=NI1_CheckVersionButtonProc,title="Manuscript web page"
646        Button OpenGCManuscriptWebPage,pos={551,240},size={150,20},proc=NI1_CheckVersionButtonProc,title="Manuscript web page"
647EndMacro
648//****************************************************************
649//****************************************************************
650//***********************************
651
652//**************************************************************************
653Function NI1_GeometriesManager()
654        //initialize first...
655        string OldDF=GetDataFolder(1)
656        setDataFolder root:
657        NewDataFolder/O/S root:Packages
658        NewDataFolder/O/S root:Packages:NikaGeometries
659        String/G CurrentGeomName, ListOfGeomsSaved
660        variable/g CleanupTheFolderPriorSave
661        if(strlen(CurrentGeomName)<1)
662                CurrentGeomName = "Not saved"
663        endif
664        ListOfGeomsSaved = IN2G_ConvertDataDirToList(DataFolderDir(1))
665        if(strlen(ListOfGeomsSaved)<1)
666                ListOfGeomsSaved = "None saved"
667        endif
668       
669       
670        DoWIndow NI1_GeometriesManagerPanel
671        if(V_Flag)
672                DoWindow/F NI1_GeometriesManagerPanel
673        else
674                Execute ("NI1_GeometriesManagerPanel()")
675        endif
676        setDataFolder oldDf
677end
678
679//**************************************************************************
680//**************************************************************************
681//**************************************************************************
682Function NI1_GMLoadGeometries(LoadThisGeom)
683        STRING LoadThisGeom
684       
685        if(stringMatch(LoadThisGeom,"---")||stringmatch(LoadThisGeom,"None Saved")||stringmatch(LoadThisGeom,"_none_"))
686                return 0
687        endif
688        string OldDF=GetDataFolder(1)
689        SetDataFolder root:Packages:NikaGeometries
690        SVAR CurrentGeomName = root:Packages:NikaGeometries:CurrentGeomName
691        SVAR ListOfGeomsSaved = root:Packages:NikaGeometries:ListOfGeomsSaved
692
693        DoAlert /T="What do we do with current Geometries?" 2, "Current Geometries : "+CurrentGeomName+". Do you want to save it?"
694                if(V_Flag==3)
695                        abort
696                elseif(V_Flag==2)
697                       
698                elseif(V_Flag==1)
699                        NI1_GMSaveGeometries()
700                endif           
701        NI1_GMCloseAllNikaW()   
702        KillDataFolder root:Packages:Convert2Dto1D
703        DuplicateDataFolder $(LoadThisGeom), root:Packages:Convert2Dto1D
704        //restore paths . Use strings in the root:Packages:Convert2Dto1D folder
705        SVAR/Z Convert2Dto1DDataPathS=root:Packages:Convert2Dto1D:Convert2Dto1DDataPathS
706        SVAR/Z Convert2Dto1DEmptyDarkPathS=root:Packages:Convert2Dto1D:Convert2Dto1DEmptyDarkPathS
707        SVAR/Z Convert2Dto1DBmCntrPathS=root:Packages:Convert2Dto1D:Convert2Dto1DBmCntrPathS
708        SVAR/Z Convert2Dto1DMaskPathS=root:Packages:Convert2Dto1D:Convert2Dto1DMaskPathS
709        if(SVAR_Exists(Convert2Dto1DDataPathS))
710                NewPath/O/Q Convert2Dto1DDataPath, Convert2Dto1DDataPathS
711                NewPath/O/Q Convert2Dto1DEmptyDarkPath, Convert2Dto1DEmptyDarkPathS
712                NewPath/O/Q Convert2Dto1DBmCntrPath, Convert2Dto1DBmCntrPathS
713                NewPath/O/Q Convert2Dto1DMaskPath, Convert2Dto1DMaskPathS
714                print "Restored original paths to data"
715        endif
716        //Ok, paths are stored...
717
718        ListOfGeomsSaved = IN2G_ConvertDataDirToList(DataFolderDir(1))
719        CurrentGeomName = LoadThisGeom
720        PopupMenu RestoreGeometries,win=NI1_GeometriesManagerPanel,value= #"root:Packages:NikaGeometries:ListOfGeomsSaved", mode=0
721        setDataFolder oldDf
722        NI1A_Convert2Dto1DMainPanel()
723end
724
725//**************************************************************************
726//**************************************************************************
727//**************************************************************************
728Function NI1_GMDeleteGeom()
729        string OldDF=GetDataFolder(1)
730        SetDataFolder root:Packages:NikaGeometries
731        SVAR CurrentGeomName = root:Packages:NikaGeometries:CurrentGeomName
732        SVAR ListOfGeomsSaved = root:Packages:NikaGeometries:ListOfGeomsSaved
733        ListOfGeomsSaved = IN2G_ConvertDataDirToList(DataFolderDir(1))
734        STRING DeleteThisGeom=stringFromList(0,ListOfGeomsSaved)
735        Prompt DeleteThisGeom, "Select Geometries to delete", popup, ListOfGeomsSaved
736        DoPrompt "Deleting saved Geometries. This cannot be undone!", DeleteThisGeom
737        if (V_Flag)
738                abort                                                           // User canceled
739        endif
740
741        DoAlert /T="Are you sure?" 2, "You are about to delete Geometries : "+DeleteThisGeom+". Are you sure?"
742                if(V_Flag==3)
743                        abort
744                elseif(V_Flag==2)
745                        abort
746                elseif(V_Flag==1)
747                        KillDataFolder $(DeleteThisGeom)
748                endif           
749        ListOfGeomsSaved = IN2G_ConvertDataDirToList(DataFolderDir(1))
750        setDataFolder oldDf
751end
752
753//**************************************************************************
754//**************************************************************************
755//**************************************************************************
756Function NI1_GMCreateNewGeom()
757        STRING LoadThisGeom
758        string OldDF=GetDataFolder(1)
759        SetDataFolder root:Packages:NikaGeometries
760        SVAR CurrentGeomName = root:Packages:NikaGeometries:CurrentGeomName
761        SVAR ListOfGeomsSaved = root:Packages:NikaGeometries:ListOfGeomsSaved
762
763        DoAlert /T="What do we do with current Configuration?" 2, "Last name for this Configuration was : "+CurrentGeomName+". Do you want to save it?"
764                if(V_Flag==3)
765                        abort
766                elseif(V_Flag==2)
767                       
768                elseif(V_Flag==1)
769                        NI1_GMSaveGeometries()
770                endif           
771        variable WasNI1_9IDCConfigPanel
772        DoWIndow NI1_9IDCConfigPanel
773        if(V_Flag)
774                WasNI1_9IDCConfigPanel=1
775        else
776                WasNI1_9IDCConfigPanel=0
777        endif
778        NI1_GMCloseAllNikaW()   
779        KillDataFolder root:Packages:Convert2Dto1D
780        KillDataFolder/Z root:Packages:NexusImportTMP:
781        ListOfGeomsSaved = IN2G_ConvertDataDirToList(DataFolderDir(1))
782        CurrentGeomName = "Not saved"
783        PopupMenu RestoreGeometries,win=NI1_GeometriesManagerPanel,value= #"root:Packages:NikaGeometries:ListOfGeomsSaved", mode=0
784        NI1A_Convert2Dto1DMainPanel()
785        if(WasNI1_9IDCConfigPanel)
786                NI1_9IDCConfigureNika()
787        endif
788        setDataFolder oldDf
789end
790
791//**************************************************************************
792//**************************************************************************
793//**************************************************************************
794Function NI1_GMSaveGeometries()
795        string OldDF=GetDataFolder(1)
796        SetDataFolder root:Packages:NikaGeometries
797        SVAR CurrentGeomName = root:Packages:NikaGeometries:CurrentGeomName
798        String NewSaveName
799        if(stringmatch(CurrentGeomName,"Not saved"))
800                NewSaveName = "SavedGeom_"+Secs2Date(DateTime,-2)
801        else
802                NewSaveName = CurrentGeomName
803        endif
804        Prompt NewSaveName, "Enter short name, will be made in Igor folder name"
805        DoPrompt "Input name for the current Geometries", NewSaveName
806        if (V_Flag)
807                abort                                                           // User canceled
808        endif
809        NewSaveName = CleanupName(NewSaveName, 1 )
810        if(DataFolderExists(NewSaveName ))
811                DoAlert /T="New folder name conflict"  2, "The Configuration "+NewSaveName+" already exists, do you want to overwrite (Yes), create unique name (No), or cancel?"
812                if(V_Flag==3)
813                        abort
814                elseif(V_Flag==2)
815                        NewSaveName = UniqueName(NewSaveName, 11, 0 )
816                elseif(V_Flag==1)
817                        KillDataFolder NewSaveName
818                endif           
819        endif
820        NVAR CleanupTheFolderPriorSave = root:Packages:NikaGeometries:CleanupTheFolderPriorSave
821        if(CleanupTheFolderPriorSave)
822                NI1_Cleanup2Dto1DFolder()                               //lets clean up the folder to make it smaller....
823        endif
824        //save paths so we can restore them later. Use strings in the root:Packages:Convert2Dto1D folder
825        string/g root:Packages:Convert2Dto1D:Convert2Dto1DDataPathS
826        string/g root:Packages:Convert2Dto1D:Convert2Dto1DEmptyDarkPathS
827        string/g root:Packages:Convert2Dto1D:Convert2Dto1DBmCntrPathS
828        string/g root:Packages:Convert2Dto1D:Convert2Dto1DMaskPathS
829        SVAR Convert2Dto1DDataPathS=root:Packages:Convert2Dto1D:Convert2Dto1DDataPathS
830        SVAR Convert2Dto1DEmptyDarkPathS=root:Packages:Convert2Dto1D:Convert2Dto1DEmptyDarkPathS
831        SVAR Convert2Dto1DBmCntrPathS=root:Packages:Convert2Dto1D:Convert2Dto1DBmCntrPathS
832        SVAR Convert2Dto1DMaskPathS=root:Packages:Convert2Dto1D:Convert2Dto1DMaskPathS
833        PathInfo Convert2Dto1DDataPath
834        Convert2Dto1DDataPathS = S_path
835        PathInfo Convert2Dto1DEmptyDarkPath
836        Convert2Dto1DEmptyDarkPathS = S_path
837        PathInfo Convert2Dto1DBmCntrPath
838        Convert2Dto1DBmCntrPathS = S_path
839        PathInfo Convert2Dto1DMaskPath
840        Convert2Dto1DMaskPathS = S_path
841        //Ok, paths are stored...
842        DuplicateDataFolder root:Packages:Convert2Dto1D, $(NewSaveName)
843        SVAR ListOfGeomsSaved = root:Packages:NikaGeometries:ListOfGeomsSaved
844        SVAR CurrentGeomName = root:Packages:NikaGeometries:CurrentGeomName
845        ListOfGeomsSaved = IN2G_ConvertDataDirToList(DataFolderDir(1))
846        CurrentGeomName = NewSaveName
847       
848        PopupMenu RestoreGeometries,win=NI1_GeometriesManagerPanel,value=#"root:Packages:NikaGeometries:ListOfGeomsSaved", mode=0
849
850       
851        setDataFolder oldDf
852end
853//**************************************************************************
854//**************************************************************************
855//**************************************************************************
856
857Function NI1_GMCloseAllNikaW()          //close all open panels and windows
858        string ListOfNikaWindows="NI1A_Convert2Dto1DPanel;CCDImageToConvertFig;LineuotDisplayPlot_Q;LineuotDisplayPlot_D;LineuotDisplayPlot_T;"
859        ListOfNikaWindows+="Sample_Information;SquareMapIntvsPixels;NI1_CreateBmCntrFieldPanel;CCDImageForBmCntr;NI1M_ImageROIPanel;CCDImageForMask;"
860        ListOfNikaWindows+="EmptyOrDarkImage;NI1_CreateFloodFieldPanel;NI1_MainConfigPanel;NI1_9IDCConfigPanel;Instructions_9IDC;APS12IDC_Instructions;"
861        variable i
862        string TempNm
863        For(i=0;i<ItemsInList(ListOfNikaWindows);i+=1)
864                TempNm = stringFromList(i,ListOfNikaWindows)
865                KillWIndow/Z $TempNm
866        endfor
867        //
868end
869//**************************************************************************
870//**************************************************************************
871//**************************************************************************
872
873Function NI1_GMButtonProc(ba) : ButtonControl
874        STRUCT WMButtonAction &ba
875
876        switch( ba.eventCode )
877                case 2: // mouse up
878                        // click code here
879                        if(stringmatch(ba.ctrlName,"SaveGeometries"))
880                                NI1_GMSaveGeometries()
881                        endif
882                        if(stringmatch(ba.ctrlName,"NewGeometries"))
883                                NI1_GMCreateNewGeom()
884                        endif
885                        if(stringmatch(ba.ctrlName,"DeleteGeometries"))
886                                NI1_GMDeleteGeom()
887                        endif
888                        break
889                case -1: // control being killed
890                        break
891        endswitch
892
893        return 0
894End
895//**************************************************************************
896//**************************************************************************
897//**************************************************************************
898
899Function NI1_GMPopMenuProc(pa) : PopupMenuControl
900        STRUCT WMPopupAction &pa
901
902        switch( pa.eventCode )
903                case 2: // mouse up
904                        Variable popNum = pa.popNum
905                        String popStr = pa.popStr
906                        if(stringmatch(pa.ctrlName,"RestoreGeometries"))
907                                NI1_GMLoadGeometries(popStr)
908                        endif
909                        break
910                case -1: // control being killed
911                        break
912        endswitch
913
914        return 0
915End
916//**************************************************************************
917//**************************************************************************
918//**************************************************************************
919
920Window NI1_GeometriesManagerPanel() : Panel
921        PauseUpdate             // building window...
922        NewPanel/K=1 /W=(600,45,1000,337) as "NIka Configuration manager"
923        SetDrawLayer UserBack
924        SetDrawEnv fsize= 16,textrgb= (16385,16388,65535)
925        DrawText 76,17,"ika Configuration manager"
926        SetDrawEnv fsize= 16,textrgb= (16385,16388,65535)
927        DrawText 113,25,"Nika Configuration manager"
928        DrawText 15,45,"Save and restore Nika Configurations + switch between them"
929        DrawText 15,60,"as needed. Please note, that this is very memory intensive "
930        DrawText 15,75,"and creates huge Igor files. Delete Configs when no more needed."
931        DrawText 15,90,"When changing Configurations, all Nika windows are closed."
932        DrawText 15,105,"You need to reopen them. "
933        Button NewGeometries,pos={99,123},size={200,20},proc=NI1_GMButtonProc,title="Create New Configuration"
934        Button NewGeometries,help={"This will create a new (empty) Nika. Existing one can be saved and named."}
935        Button SaveGeometries,pos={99,150},size={200,20},proc=NI1_GMButtonProc,title="Save Current Configuration"
936        Button SaveGeometries,help={"This will save current Nika configuration so it can be restored later."}
937        Setvariable CurrentGeomName, pos={5,200}, size={300,25}, title="Last Saved/loaded Config name: ", variable=root:Packages:NikaGeometries:CurrentGeomName, disable=2
938        Setvariable CurrentGeomName, help={"Name of last saved - or loaded - geometry. Keep in mind yuou might have changed it since the last save/load operation."}
939        checkbox CleanupTheFolderPriorSave, pos={80,175}, size={200,15}, variable=root:Packages:NikaGeometries:CleanupTheFolderPriorSave, noproc, title="Clean up folder before saving? (Housekeeping)"
940        checkbox CleanupTheFolderPriorSave,help={"If checked, the geometry being stored will be cleaned up to save space."}
941        PopupMenu RestoreGeometries,pos={99,228},size={200,20},proc=NI1_GMPopMenuProc,title="Load Stored Configurations :"
942        PopupMenu RestoreGeometries,mode=0,value= root:Packages:NikaGeometries:ListOfGeomsSaved
943        PopupMenu RestoreGeometries,help={"This is list of saved geometries available in this Igor experiment."}
944        Button DeleteGeometries,pos={99,263},size={200,20},proc=NI1_GMButtonProc,title="Delete Saved Configuration"
945        Button DeleteGeometries,help={"Will let you select from existing saved geometries one to delete."}
946EndMacro
947//**************************************************************************
948//**************************************************************************
949//**************************************************************************
Note: See TracBrowser for help on using the repository browser.