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

Last change on this file since 1180 was 1180, checked in by ilavsky, 11 months ago

Increase copyright to 2022

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