-
Notifications
You must be signed in to change notification settings - Fork 0
/
fit2dmacros.pro
1341 lines (1276 loc) · 58.3 KB
/
fit2dmacros.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;*******************************************************************
; Multfit efficient processing of 2D diffraction images
; Copyright (C) 2000-2014 S. Merkel, Universite Lille 1
; http://merkel.zoneo.net/Multifit/
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 2
; of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
;
; *******************************************************************
;
;
; Old routines to create Fit2d macro for a single 2D diffraction image
; This macro forces fit2d to perform "cake" multiple times for the same image
; It is quite slow.
;
;
; *******************************************************************
FUNCTION fit2dinput, log, startAz, endAz, interval, directory, basename
macrofile = strtrim(strtrim(directory)+strtrim(basename)+'.mac')
if (endAz lt startAz) then return, "Start azimuth larger than end azimuth!"
ON_IOERROR, BADINPUT
GET_LUN, lun
OPENW, lun, macrofile
printf, lun, "%!*\\ MACRO FOR fit2d"
printf, lun, "%!*\\ generated by Multifit by Sebastien Merkel"
printf, lun, "%!*\\ output files: " + strtrim(directory) + strtrim(basename) + "_***.chi"
printf, lun, "%!*\\ start azimuth: " + STRING(startAz,/PRINT)
printf, lun, "%!*\\ end azimuth: " + STRING(endAz,/PRINT)
printf, lun, "%!*\\ interval: " + STRING(interval,/PRINT)
printf, lun, "%!*\\"
printf, lun, "EXIT"
printf, lun, "POWDER DIFFRACTION (2-D)"
top = (endAz-startAz)/interval
if (top eq 1) then top = 0
for i=0,top do begin
angle = startAz+i*interval
anglelow = 1.0*angle-1.0*interval/2.
anglehigh = 1.0*angle+1.0*interval/2.
if (anglelow gt 180.) then anglelow = anglelow-360.
if (anglehigh gt 180.) then anglehigh = anglehigh-360.
filename = strtrim(directory)+strtrim(basename) + "_" + STRTRIM(STRING(angle,/PRINT),2) + ".chi"
if ((i eq 0) or (i eq top)) then $
logit, log, "Integration for delta between " + STRTRIM(STRING(anglelow,/PRINT),2) + " and " + STRTRIM(STRING(anglehigh,/PRINT),2) + " to be save in " + filename
if (i eq 0) then logit, log, " ..."
printf, lun, "CAKE"
printf, lun, "INTEGRATE"
printf, lun, "O.K."
printf, lun, "START AZIMUTH"
printf, lun, STRTRIM(STRING(anglelow,/PRINT),2)
printf, lun, "END AZIMUTH"
printf, lun, STRTRIM(STRING(anglehigh,/PRINT),2)
printf, lun, "AZIMUTH BIN"
printf, lun, STRTRIM(STRING(1,/PRINT),2)
printf, lun, "O.K."
printf, lun, "EXIT"
if (i eq 0) then begin
printf, lun, "OPTIONS"
printf, lun, "Z-AXIS LABEL"
printf, lun, "Intensity"
printf, lun, "EXIT"
endif
printf, lun, "OUTPUT"
printf, lun, "CHIPLOT"
printf, lun, "FILE NAME"
printf, lun, filename
printf, lun, "O.K."
printf, lun, "EXCHANGE"
endfor
printf, lun, "EXIT"
printf, lun, "MACROS / LOG FILE"
printf, lun, "%!*\\ END OF EXPG_IO MACRO FILE"
free_lun, lun
logit, log, "Macro save in file: " + macrofile
return, 1
BADINPUT: return, !ERR_STRING
END
FUNCTION fit2dinputlong, log, inputTiff, inputMar
common fit2dinputlong, inputdir, outputdir, base, ext, firstS, lastS, digitsS, startAzS, endAzS, intervalS
if (WIDGET_INFO(inputTiff, /BUTTON_SET) eq 1) then begin
fileFormat = 0
endif else if (WIDGET_INFO(inputMar, /BUTTON_SET) eq 1) then begin
fileFormat = 1
endif
first = FIX(FLOAT(firstS[0]))
last = FIX(FLOAT(lastS[0]))
digits = FIX(FLOAT(digitsS[0]))
startAz = FIX(FLOAT(startAzS[0]))
endAz = FIX(FLOAT(endAzS[0]))
interval = FIX(FLOAT(intervalS[0]))
macrofile = strtrim(strtrim(outputdir)+strtrim(base)+'.mac')
logit, log, "Macro file: " + macrofile
if (endAz lt startAz) then return, "Start azimuth larger than end azimuth!"
ON_IOERROR, BADINPUT
GET_LUN, lun
OPENW, lun, macrofile
printf, lun, "%!*\\ MACRO FOR fit2d"
printf, lun, "%!*\\ generated by Multifit by Sebastien Merkel"
fileindex = intformat(first,digits);
filename = strtrim(inputdir) + strtrim(base) + "_" + strtrim(fileindex) + strtrim(ext)
logit, log, "First input file: " + filename
printf, lun, "%!*\\ First input file: " + filename
fileindex = intformat(last,digits);
filename = strtrim(inputdir) + strtrim(base) + "_" + strtrim(fileindex) + strtrim(ext)
logit, log, "Last input file: " + filename
printf, lun, "%!*\\ Last input file: \n " + filename
fileindex = intformat(first,digits);
filename1 = strtrim(outputdir) + strtrim(base) + "_" + strtrim(fileindex) + "_" + strtrim(string(startAz),2) + ".chi"
filename2 = strtrim(outputdir) + strtrim(base) + "_" + strtrim(fileindex) + "_" + strtrim(string(endAz),2) + ".chi"
printf, lun, "%!*\\ output files:"
printf, lun, "%!*\\ " + filename1 + " ---- " + filename2
printf, lun, "%!*\\ ------ "
fileindex = intformat(last,digits);
filename1 = strtrim(outputdir) + strtrim(base) + "_" + strtrim(fileindex) + "_" + strtrim(string(startAz),2) + ".chi"
filename2 = strtrim(outputdir) + strtrim(base) + "_" + strtrim(fileindex) + "_" + strtrim(string(endAz),2) + ".chi"
printf, lun, "%!*\\ " + filename1 + " ---- " + filename2
printf, lun, "%!*\\ start azimuth: " + STRING(startAz,/PRINT)
printf, lun, "%!*\\ end azimuth: " + STRING(endAz,/PRINT)
printf, lun, "%!*\\ interval: " + STRING(interval,/PRINT)
printf, lun, "%!*\\"
printf, lun, "EXIT"
printf, lun, "POWDER DIFFRACTION (2-D)"
topAz = (endAz-startAz)/interval
if (topAz eq 1) then topAz = 0
topInputs = (last-first)+1
nChi = ((last-first)+1)*topAz
logit, log, "Number of chi files to be created by fit2d: " + strtrim(STRING(nChi,/PRINT),2)
for j=first,last do begin
printf, lun, "INPUT"
fileindex = intformat(j,digits);
filename = strtrim(inputdir) + strtrim(base) + "_" + strtrim(fileindex) + strtrim(ext)
printf, lun, filename
printf, lun, "O.K."
; If Tiff file, we need a second OK
if (fileFormat eq 0) then printf, lun, "O.K."
basechi = strtrim(outputdir) + strtrim(base) + "_" + strtrim(fileindex) + "_"
logit, log, "Data in " + strtrim(STRING(topAz,/PRINT),2) + " files: " + basechi + strtrim(STRING(startAz,/PRINT),2) + ".chi --- " + basechi + strtrim(STRING(endAz,/PRINT),2) + ".chi"
for i=0,topAz do begin
angle = startAz+i*interval
anglelow = 1.0*angle-1.0*interval/2.
anglehigh = 1.0*angle+1.0*interval/2.
if (anglelow gt 180.) then anglelow = anglelow-360.
if (anglehigh gt 180.) then anglehigh = anglehigh-360.
filename = strtrim(basechi) + STRTRIM(STRING(angle,/PRINT),2) + ".chi"
printf, lun, "CAKE"
printf, lun, "INTEGRATE"
printf, lun, "O.K."
printf, lun, "START AZIMUTH"
printf, lun, STRTRIM(STRING(anglelow,/PRINT),2)
printf, lun, "END AZIMUTH"
printf, lun, STRTRIM(STRING(anglehigh,/PRINT),2)
printf, lun, "AZIMUTH BIN"
printf, lun, STRTRIM(STRING(1,/PRINT),2)
printf, lun, "O.K."
printf, lun, "EXIT"
if ((i eq 0) and (j eq first)) then begin
printf, lun, "OPTIONS"
printf, lun, "Z-AXIS LABEL"
printf, lun, "Intensity"
printf, lun, "EXIT"
endif
printf, lun, "OUTPUT"
printf, lun, "CHIPLOT"
printf, lun, "FILE NAME"
printf, lun, filename
printf, lun, "O.K."
printf, lun, "EXCHANGE"
endfor
endfor
printf, lun, "EXIT"
printf, lun, "MACROS / LOG FILE"
printf, lun, "%!*\\ END OF EXPG_IO MACRO FILE"
free_lun, lun
logit, log, "Macro save in file: " + macrofile
return, 1
BADINPUT: return, !ERR_STRING
END
; subroutine with GUI to create macro for a single image
PRO fit2dmac_event, ev
WIDGET_CONTROL, ev.TOP, GET_UVALUE=stash
WIDGET_CONTROL, ev.ID, GET_UVALUE=uval
log=stash.log
if (uval eq 'OK') then begin
WIDGET_CONTROL, stash.fit2dMacAzimuthSt, GET_VALUE=startAz
WIDGET_CONTROL, stash.fit2dMacAzimuthEnd, GET_VALUE=endAz
WIDGET_CONTROL, stash.fit2dMacSliceText, GET_VALUE=interval
WIDGET_CONTROL, stash.fit2dMacDirText, GET_VALUE=directory
WIDGET_CONTROL, stash.fit2dMacBaseText, GET_VALUE=basename
logit, log, "Creating macro for fit2d..."
logit, log, "Fit2d will create files starting with " + basename + "_ with angles from " + startAz + " to " + endAz + " with interval " + interval
result = fit2dinput(log, FIX(FLOAT(startAz[0])), FIX(FLOAT(endAz[0])), FIX(FLOAT(interval[0])), directory, basename)
if (FIX(result) ne 1) then begin
logit, log, "Macro creation failed"
tmp = DIALOG_MESSAGE(result, /ERROR)
endif else begin
WIDGET_CONTROL, ev.TOP, /DESTROY
endelse
endif else begin
logit, log, "Creating macro for fit2d... Cancel."
WIDGET_CONTROL, ev.TOP, /DESTROY
endelse
END
PRO fit2dmac, base, log
common fonts, titlefont, boldfont, mainfont, avFontHeight
common files, extension, datadirectory, outputdirectory, defaultdirectory, jcpdsdirectory
fit2d = WIDGET_BASE(/COLUMN, Title='Create macro for fit2d (single images)', /MODAL, GROUP_LEADER=base)
fit2dMacLa = WIDGET_LABEL(fit2d, VALUE='Create macro for fit2d (single images)', /ALIGN_center, font=titlefont)
fit2dMacDir = WIDGET_BASE(fit2d, /ROW)
fit2dMacDirLa = WIDGET_LABEL(fit2dMacDir, VALUE='Directory for CHI files export', /ALIGN_LEFT)
fit2dMacDirText = WIDGET_TEXT(fit2dMacDir, VALUE=datadirectory, XSIZE=60)
fit2dMacBase = WIDGET_BASE(fit2d, /ROW)
fit2dMacBaseLa = WIDGET_LABEL(fit2dMacBase, VALUE='Base for filenames', /ALIGN_LEFT)
fit2dMacBaseText = WIDGET_TEXT(fit2dMacBase, VALUE='filename', XSIZE=60, /EDITABLE)
fit2dMacAzimuth = WIDGET_BASE(fit2d, /ROW)
fit2dMacAzimuthLa = WIDGET_LABEL(fit2dMacAzimuth, VALUE='Range for azimuth angles', /ALIGN_LEFT)
fit2dMacAzimuthSt = WIDGET_TEXT(fit2dMacAzimuth, VALUE='0',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
fit2dMacAzimuthLa2 = WIDGET_LABEL(fit2dMacAzimuth, VALUE='to', /ALIGN_LEFT)
fit2dMacAzimuthEnd = WIDGET_TEXT(fit2dMacAzimuth, VALUE='360',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
fit2dMacSlice = WIDGET_BASE(fit2d, /ROW)
fit2dMacSliceLa = WIDGET_LABEL(fit2dMacSlice, VALUE='Sliced size (degrees)', /ALIGN_LEFT)
fit2dMacSliceText = WIDGET_TEXT(fit2dMacSlice, VALUE='5',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
buttons = WIDGET_BASE(fit2d,/ROW, /ALIGN_CENTER)
ok = WIDGET_BUTTON(buttons, VALUE='Ok', UVALUE='OK', xsize=80)
cancel = WIDGET_BUTTON(buttons, VALUE='Cancel', UVALUE='CANCEL', xsize=80)
stash = {log:log, fit2dMacDirText:fit2dMacDirText, fit2dMacBaseText:fit2dMacBaseText, $
fit2dMacAzimuthSt:fit2dMacAzimuthSt, fit2dMacAzimuthEnd:fit2dMacAzimuthEnd, $
fit2dMacSliceText:fit2dMacSliceText}
WIDGET_CONTROL, fit2d, SET_UVALUE=stash
WIDGET_CONTROL, fit2d, /REALIZE
XMANAGER, 'fit2dmac', fit2d
END
; *******************************************************************
;
;
; Old routines to create Fit2d macro for multiple 2D diffraction images
; This macro forces fit2d to perform "cake" multiple times for the same image
; It is quite slow.
;
;
; *******************************************************************
PRO chgDiffDir, base, widget
common files, extension, datadirectory, outputdirectory, defaultdirectory, jcpdsdirectory
result=dialog_pickfile(/DIRECTORY,title='Directory with diffraction data...', path=defaultdirectory, DIALOG_PARENT=base)
if (result ne '') then begin
WIDGET_CONTROL, widget, SET_VALUE=result
endif
END
PRO fit2dmaclong_event, ev
common fit2dinputlong, inputdir, outputdir, base, ext, first, last, digits, startAz, endAz, interval
WIDGET_CONTROL, ev.TOP, GET_UVALUE=stash
WIDGET_CONTROL, ev.ID, GET_UVALUE=uval
log=stash.log
if (uval eq 'OK') then begin
WIDGET_CONTROL, stash.fit2dInputText, GET_VALUE=inputdir
WIDGET_CONTROL, stash.fit2dInputFilesBaseSt, GET_VALUE=base
WIDGET_CONTROL, stash.fit2dInputFilesFirstSt, GET_VALUE=first
WIDGET_CONTROL, stash.fit2dInputFilesLastSt, GET_VALUE=last
WIDGET_CONTROL, stash.fit2dInputFilesDigitsSt, GET_VALUE=digits
WIDGET_CONTROL, stash.fit2dInputFilesExtSt, GET_VALUE=ext
WIDGET_CONTROL, stash.fit2dOutputDirText, GET_VALUE=outputdir
WIDGET_CONTROL, stash.fit2dMacAzStVa, GET_VALUE=startAz
WIDGET_CONTROL, stash.fit2dMacAzLtVa, GET_VALUE=endAz
WIDGET_CONTROL, stash.fit2dMacAzInVa, GET_VALUE=interval
logit, log, "Creating macro for fit2d..."
; test if the diffraction images can be found
firstInt = FIX(FLOAT(first[0]))
lastInt = FIX(FLOAT(last[0]))
digitsInt = FIX(FLOAT(digits[0]))
for index = firstInt, lastInt do begin
fileindex = intformat(index,digits);
filename = strtrim(inputdir) + strtrim(base) + "_" + strtrim(fileindex) + strtrim(ext)
if (FILE_TEST(filename) ne 1) then begin
messages = strarr(3)
messages[0] = filename + " can not be found."
messages[1] = "Fit2d will not find it either."
messages[2] = "Keep going?"
tmp = DIALOG_MESSAGE( messages , /QUESTION)
if (tmp eq 'No') then return
endif
endfor
;
result = fit2dinputlong(log, stash.inputTiff, stash.inputMar)
if (FIX(result) ne 1) then begin
logit, log, "Macro creation failed"
tmp = DIALOG_MESSAGE(result, /ERROR)
endif else begin
WIDGET_CONTROL, ev.TOP, /DESTROY
endelse
endif else if (uval eq 'DIFFDIR') then begin
chgDiffDir, stash.base, stash.fit2dInputText
endif else if (uval eq 'CANCEL') then begin
logit, log, "Creating macro for fit2d... Cancel."
WIDGET_CONTROL, ev.TOP, /DESTROY
endif
END
PRO fit2dmaclong, base, log
common fonts, titlefont, boldfont, mainfont, avFontHeight
common files, extension, datadirectory, outputdirectory, defaultdirectory, jcpdsdirectory
fit2d = WIDGET_BASE(/COLUMN, Title='Create macro for fit2d (multiple images)', /MODAL, GROUP_LEADER=base)
fit2dMacLa = WIDGET_LABEL(fit2d, VALUE='Create macro for fit2d (multiple images)', /ALIGN_CENTER, font=titlefont)
; Input files: diffraction images
fit2dInput = WIDGET_BASE(fit2d, /COLUMN, FRAME=1)
fit2dInputDir = WIDGET_BASE(fit2dInput, COLUMN=3)
fit2dInputDirLa = WIDGET_LABEL(fit2dInputDir, VALUE='Directory with diffraction images', /ALIGN_LEFT)
fit2dInputText = WIDGET_TEXT(fit2dInputDir, VALUE='', XSIZE=60)
fit2dInputBu = WIDGET_BUTTON(fit2dInputDir, VALUE='Change', UVALUE='DIFFDIR')
fit2dInputFiles = WIDGET_BASE(fit2dInput, COLUMN=2, /GRID_LAYOUT)
fit2dInputFilesBaseLa = WIDGET_LABEL(fit2dInputFiles, VALUE='Root name of image files', /ALIGN_LEFT)
fit2dInputFilesFirstLa = WIDGET_LABEL(fit2dInputFiles, VALUE='First number', /ALIGN_LEFT)
fit2dInputFilesLastLa = WIDGET_LABEL(fit2dInputFiles, VALUE='Last number', /ALIGN_LEFT)
fit2dInputFilesDigitsLa = WIDGET_LABEL(fit2dInputFiles, VALUE='Number of digits for file numbers', /ALIGN_LEFT)
fit2dInputFilesExtLa = WIDGET_LABEL(fit2dInputFiles, VALUE='Extension', /ALIGN_LEFT)
fit2dInputFilesBaseSt = WIDGET_TEXT(fit2dInputFiles, VALUE='', XSIZE=20, /EDITABLE)
fit2dInputFilesFirstSt = WIDGET_TEXT(fit2dInputFiles, VALUE='', XSIZE=10, /EDITABLE)
fit2dInputFilesLastSt = WIDGET_TEXT(fit2dInputFiles, VALUE='', XSIZE=10, /EDITABLE)
fit2dInputFilesDigitsSt = WIDGET_TEXT(fit2dInputFiles, VALUE='', XSIZE=10, /EDITABLE)
fit2dInputFilesExtSt = WIDGET_TEXT(fit2dInputFiles, VALUE='.tiff', XSIZE=10, /EDITABLE)
fit2dInputFormat = WIDGET_BASE(fit2dInput, COLUMN=2)
fit2dInputFormatLa = WIDGET_LABEL(fit2dInputFormat, VALUE='File format', /ALIGN_LEFT)
format = Widget_Base(fit2dInputFormat, Column=1, /Exclusive)
inputTiff = Widget_Button(format, Value='Tiff', UVALUE='FORMAT')
inputMar = Widget_Button(format, Value='Mar3450', UVALUE='FORMAT')
; Output files: chi files
fit2dOutput = WIDGET_BASE(fit2d, /COLUMN, FRAME=1)
fit2dOutputDir = WIDGET_BASE(fit2dOutput, /ROW)
fit2dOutputDirLa = WIDGET_LABEL(fit2dOutputDir, VALUE='Directory for CHI files export ', /ALIGN_LEFT)
fit2dOutputDirText = WIDGET_TEXT(fit2dOutputDir, VALUE=datadirectory, XSIZE=60)
fit2dOutputFiles = WIDGET_BASE(fit2dOutput, COLUMN=2, /GRID_LAYOUT)
fit2dMacAzStLa = WIDGET_LABEL(fit2dOutputFiles, VALUE='First azimuth angle', /ALIGN_LEFT)
fit2dMacAzLtLa = WIDGET_LABEL(fit2dOutputFiles, VALUE='Last azimuth angle', /ALIGN_LEFT)
fit2dMacAzInLa = WIDGET_LABEL(fit2dOutputFiles, VALUE='Interval', /ALIGN_LEFT)
fit2dMacAzStVa = WIDGET_TEXT(fit2dOutputFiles, VALUE='0',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
fit2dMacAzLtVa = WIDGET_TEXT(fit2dOutputFiles, VALUE='360',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
fit2dMacAzInVa = WIDGET_TEXT(fit2dOutputFiles, VALUE='5',/ALIGN_LEFT, XSIZE=10, /EDITABLE)
; Buttons
buttons = WIDGET_BASE(fit2d,/ROW, /ALIGN_CENTER, /GRID_LAYOUT)
ok = WIDGET_BUTTON(buttons, VALUE='Ok', UVALUE='OK', xsize=80)
cancel = WIDGET_BUTTON(buttons, VALUE='Cancel', UVALUE='CANCEL', xsize=80)
; Finishing up
stash = {log:log, base:fit2d, fit2dInputText:fit2dInputText, fit2dInputFilesBaseSt: fit2dInputFilesBaseSt, fit2dInputFilesFirstSt: fit2dInputFilesFirstSt, fit2dInputFilesLastSt:fit2dInputFilesLastSt, fit2dInputFilesDigitsSt: fit2dInputFilesDigitsSt, fit2dInputFilesExtSt: fit2dInputFilesExtSt, fit2dOutputDirText:fit2dOutputDirText, fit2dMacAzStVa:fit2dMacAzStVa, fit2dMacAzLtVa:fit2dMacAzLtVa, fit2dMacAzInVa:fit2dMacAzInVa, inputTiff: inputTiff, inputMar: inputMar}
WIDGET_CONTROL, fit2d, SET_UVALUE=stash
WIDGET_CONTROL, fit2d, /REALIZE
XMANAGER, 'fit2dmaclong', fit2d
END
; *******************************************************************
;
;
; New subroutines to create Fit2d macro for multiple images
; For each image, fit2d will generate one cake only.
;
;
; *******************************************************************
FUNCTION makefit2dmac2DData, log, stash
; Number of digits for chi loop (set by fit2d)
digitsChiLoop = 5
; Number of digits for image loop in output (forced)
digitsImageLoop = 3
; extracting variables
WIDGET_CONTROL, stash.dataDirText, GET_VALUE=dataDirText
dataDir = strtrim(dataDirText)
WIDGET_CONTROL, stash.chiDirText, GET_VALUE=chiDirText
chiDir = strtrim(chiDirText)
WIDGET_CONTROL, stash.baseNamesText, GET_VALUE=baseNamesText
baseNames = strtrim(baseNamesText)
WIDGET_CONTROL, stash.firstImageText, GET_VALUE=firstImageText
firstImage = FIX(FLOAT(firstImageText[0]))
WIDGET_CONTROL, stash.lastImageText, GET_VALUE=lastImageText
lastImage = FIX(FLOAT(lastImageText[0]))
WIDGET_CONTROL, stash.digitsImageText, GET_VALUE=digitsImageText
digitsImage = FIX(FLOAT(digitsImageText[0]))
WIDGET_CONTROL, stash.extText, GET_VALUE=extText
ext = strtrim(extText)
WIDGET_CONTROL, stash.xPixelText, GET_VALUE=xPixelText
xPixel = FLOAT(xPixelText[0])
WIDGET_CONTROL, stash.yPixelText, GET_VALUE=yPixelText
yPixel = FLOAT(yPixelText[0])
WIDGET_CONTROL, stash.waveText, GET_VALUE=waveText
wave = FLOAT(waveText[0])
WIDGET_CONTROL, stash.xCenterText, GET_VALUE=xCenterText
xCenter = FLOAT(xCenterText[0])
WIDGET_CONTROL, stash.yCenterText, GET_VALUE=yCenterText
yCenter = FLOAT(yCenterText[0])
WIDGET_CONTROL, stash.detDisText, GET_VALUE=detDisText
detDis = FLOAT(detDisText[0])
WIDGET_CONTROL, stash.tiltRotationText, GET_VALUE=tiltRotationText
tiltRotation = FLOAT(tiltRotationText[0])
WIDGET_CONTROL, stash.tiltAngleText, GET_VALUE=tiltAngleText
tiltAngle = FLOAT(tiltAngleText[0])
WIDGET_CONTROL, stash.detRotText, GET_VALUE=detRotText
detRot = FLOAT(detRotText[0])
WIDGET_CONTROL, stash.azStartText, GET_VALUE=azStartText
azStart = FLOAT(azStartText[0])
WIDGET_CONTROL, stash.azEndText, GET_VALUE=azEndText
azEnd = FLOAT(azEndText[0])
WIDGET_CONTROL, stash.azBinsText, GET_VALUE=azBinsText
azBins = FIX(FLOAT(azBinsText[0]))
WIDGET_CONTROL, stash.innerRadiusText, GET_VALUE=innerRadiusText
innerRadius = FLOAT(innerRadiusText[0])
WIDGET_CONTROL, stash.outerRadiusText, GET_VALUE=outerRadiusText
outerRadius = FLOAT(outerRadiusText[0])
; Testing that files actually exist. Otherwise, fit2d will crash
if (azEnd lt azStart) then return, "Start azimuth larger than end azimuth!"
for j=firstImage,lastImage do begin
if (digitsImage eq 0) then fileindex = string(j) else fileindex = intformat(j,digitsImage)
filename = strtrim(dataDir) + strtrim(baseNames) + "_" + strtrim(fileindex,2) + strtrim(ext)
; print, "Testing " + filename
if (FILE_TEST(filename) eq 0) then return, "File " + filename + " not found. Fit2d will crash."
endfor
; Defining name for macro file
macrofile = DIALOG_PICKFILE(PATH=dataDir, TITLE='Select name of fit2d macro file', FILTER='*.mac', /OVERWRITE_PROMPT,/WRITE, FILE=baseNames+'.mac')
if (macrofile eq '') then return, "No output file selected"
logit, log, "Macro file: " + macrofile
; We are ready to create a fit2d macro, preparing text
ccr = STRING(13B) ; Carriage Return
clf = STRING([10B]) ; line feed
endline = ccr + clf
fit2d = "%!*\\ MACRO FOR fit2d" + STRING(13B) $
+ "%!*\\ generated by Multifit, S. Merkel, N. Hilairet, J Appl Cryst, 48, 1307-1313 (2015) [doi: 10.1107/S1600576715010390]" + endline
if (digitsImage eq 0) then fileindex = string(firstImage) else fileindex = intformat(firstImage,digitsImage)
filename = strtrim(dataDir) + strtrim(baseNames) + "_" + strtrim(fileindex,2) + strtrim(ext)
fileindex = intformat(firstImage,digitsImageLoop)
firstchi = strtrim(dataDir) + strtrim(baseNames) + "_" + strtrim(fileindex,2) + "_00000.chi"
logit, log, "First input file: " + filename
fit2d += "%!*\\ First input file: " + filename + endline
if (digitsImage eq 0) then fileindex = string(lastImage) else fileindex = intformat(lastImage,digitsImage)
filename = strtrim(dataDir) + strtrim(baseNames) + "_" + strtrim(fileindex,2) + strtrim(ext)
fileindex = intformat(lastImage,digitsImageLoop)
lastchi = strtrim(dataDir) + strtrim(baseNames) + "_" + strtrim(fileindex,2) + "_" + intformat(azBins,digitsChiLoop) + ".chi"
logit, log, "Last input file: " + filename
fit2d += "%!*\\ Last input file: " + filename + endline $
+ "%!*\\ start azimuth: " + STRING(azStart,/PRINT) + endline $
+ "%!*\\ end azimuth: " + STRING(azEnd,/PRINT) + endline $
+ "%!*\\ number of bins: " + STRING(azBins,/PRINT) + endline
nchi = string((lastImage-firstImage+1)*azBins)
logit, log, "Number of chi files generated: " + nchi
fit2d += "%!*\\ Number of chi files generated: " + nchi + endline
logit, log, "Output files: " + firstchi + " to " + lastchi
fit2d += "%!*\\ output files:" + endline $
+ "%!*\\ " + firstchi + " to " + lastchi + endline $
+ "%!*\\ Multifit parameters" + endline $
+ "%!*\\ Multifit_dataDir | " + dataDir + endline $
+ "%!*\\ Multifit_chiDir | " + chiDir + endline $
+ "%!*\\ Multifit_baseNames | " + baseNames + endline $
+ "%!*\\ Multifit_firstImage | " + STRTRIM(STRING(firstImage,/PRINT),2) + endline $
+ "%!*\\ Multifit_lastImage | " + STRTRIM(STRING(lastImage,/PRINT),2) + endline $
+ "%!*\\ Multifit_digitsImage | " + STRTRIM(STRING(digitsImage,/PRINT),2) + endline $
+ "%!*\\ Multifit_ext | " + ext + endline $
+ "%!*\\ Multifit_xPixel | " + STRTRIM(STRING(xPixel,/PRINT),2) + endline $
+ "%!*\\ Multifit_yPixel | " + STRTRIM(STRING(yPixel,/PRINT),2) + endline $
+ "%!*\\ Multifit_wave | " + STRTRIM(STRING(wave,/PRINT),2) + endline $
+ "%!*\\ Multifit_xCenter | " + STRTRIM(STRING(xCenter,/PRINT),2) + endline $
+ "%!*\\ Multifit_yCenter | " + STRTRIM(STRING(yCenter,/PRINT),2) + endline $
+ "%!*\\ Multifit_detDis | " + STRTRIM(STRING(detDis,/PRINT),2) + endline $
+ "%!*\\ Multifit_tiltRotation | " + STRTRIM(STRING(tiltRotation,/PRINT),2) + endline $
+ "%!*\\ Multifit_tiltAngle | " + STRTRIM(STRING(tiltAngle,/PRINT),2) + endline $
+ "%!*\\ Multifit_detRot | " + STRTRIM(STRING(detRot,/PRINT),2) + endline $
+ "%!*\\ Multifit_azStart | " + STRTRIM(STRING(azStart,/PRINT),2) + endline $
+ "%!*\\ Multifit_azEnd | " + STRTRIM(STRING(azEnd,/PRINT),2) + endline $
+ "%!*\\ Multifit_azBins | " + STRTRIM(STRING(azBins,/PRINT),2) + endline $
+ "%!*\\ Multifit_innerRadius | " + STRTRIM(STRING(innerRadius,/PRINT),2) + endline $
+ "%!*\\ Multifit_outerRadius | " + STRTRIM(STRING(outerRadius,/PRINT),2) + endline $
+ "%!*\\" + endline $
+ "EXIT" + endline $
+ "%!*\ Enter the keybboard interface to define variables" + endline $
+ "KEYBOARD INTERFACE" + endline $
+ "variable" + endline $
+ "#first_image" + endline $
+ "integer" + endline $
+ STRTRIM(STRING(firstImage,/PRINT),2) + endline $
+ "variable" + endline $
+ "#last_image" + endline $
+ "integer" + endline $
+ STRTRIM(STRING(lastImage,/PRINT),2) + endline $
+ "variable" + endline $
+ "#path_to_images" + endline $
+ "string" + endline $
+ dataDir + endline $
+ "variable" + endline $
+ "#path_to_chi_files" + endline $
+ "string" + endline $
+ chiDir + endline $
+ "variable" + endline $
+ "#stem" + endline $
+ "string" + endline $
+ baseNames + endline $
+ "variable" + endline $
+ "#X_PIXEL_SIZE" + endline $
+ "real" + endline $
+ STRTRIM(STRING(xPixel,/PRINT),2) + endline $
+ "variable" + endline $
+ "#Y_PIXEL_SIZE" + endline $
+ "real" + endline $
+ STRTRIM(STRING(yPixel,/PRINT),2) + endline $
+ "variable" + endline $
+ "#DISTANCE" + endline $
+ "real" + endline $
+ STRTRIM(STRING(detDis,/PRINT),2) + endline $
+ "variable" + endline $
+ "#WAVELENGTH" + endline $
+ "real" + endline $
+ STRTRIM(STRING(wave,/PRINT),2) + endline $
+ "variable" + endline $
+ "#X_BEAM_CENTRE" + endline $
+ "real" + endline $
+ STRTRIM(STRING(xCenter,/PRINT),2) + endline $
+ "variable" + endline $
+ "#Y_BEAM_CENTRE" + endline $
+ "real" + endline $
+ STRTRIM(STRING(yCenter,/PRINT),2) + endline $
+ "variable" + endline $
+ "#TILT_ROTATION" + endline $
+ "real" + endline $
+ STRTRIM(STRING(tiltRotation,/PRINT),2) + endline $
+ "variable" + endline $
+ "#ANGLE_OF_TILT" + endline $
+ "real" + endline $
+ STRTRIM(STRING(tiltAngle,/PRINT),2) + endline $
+ "variable" + endline $
+ "#DETECTOR_ROTATION" + endline $
+ "real" + endline $
+ STRTRIM(STRING(detRot,/PRINT),2) + endline $
+ "variable" + endline $
+ "#START_AZIMUTH" + endline $
+ "real" + endline $
+ STRTRIM(STRING(azStart,/PRINT),2) + endline $
+ "variable" + endline $
+ "#END_AZIMUTH" + endline $
+ "real" + endline $
+ STRTRIM(STRING(azEnd,/PRINT),2) + endline $
+ "variable" + endline $
+ "#INNER_RADIUS" + endline $
+ "real" + endline $
+ STRTRIM(STRING(innerRadius,/PRINT),2) + endline $
+ "variable" + endline $
+ "#OUTER_RADIUS" + endline $
+ "real" + endline $
+ STRTRIM(STRING(outerRadius,/PRINT),2) + endline $
+ "variable" + endline $
+ "#AZIMUTH_BINS" + endline $
+ "integer" + endline $
+ STRTRIM(STRING(azBins,/PRINT),2) + endline $
+ "EXIT" + endline $
+ "%!*\ " + endline $
+ "%!*\ " + endline $
+ "%!*\ " + endline $
+ "%!*\ " + endline $
+ "%!*\ Loop on images" + endline $
+ "%!*\ You should not change anything below this point" + endline $
+ "%!*\ " + endline $
+ "%!*\ " + endline $
+ "%!*\ " + endline $
+ "DO #COUNT = #first_image, #last_image, 1" + endline $
+ "%!*\ Enter the keybboard interface to define file names" + endline $
+ " KEYBOARD INTERFACE" + endline $
+ " I2C" + endline $
+ " #COUNT" + endline $
+ " NO" + endline $
+ STRTRIM(STRING(digitsImageLoop,/PRINT),2) + endline $
+ " #VALUEWITHZERO" + endline $
+ " concat" + endline $
+ " #path_to_images" + endline $
+ " #stem" + endline $
+ " #image" + endline
if (digitsImage eq 0) then begin
fit2d += " concat" + endline $
+ "#image" + endline $
+ "_" + endline $
+ " #image" + endline $
+ " concat" + endline $
+ "#image" + endline $
+ "#COUNT" + endline $
+ " #image" + endline $
+ " concat" + endline $
+ "#image" + endline $
+ ".tif" + endline $
+ " #image" + endline
endif else begin
fit2d += " I2C" + endline $
+ " #COUNT" + endline $
+ " NO" + endline $
+ STRTRIM(STRING(digitsImage,/PRINT),2) + endline $
+ " #VALUEFORIMAGEWITHZERO" + endline $
+ " concat" + endline $
+ "#image" + endline $
+ "_" + endline $
+ " #image" + endline $
+ " concat" + endline $
+ "#image" + endline $
+ "#VALUEFORIMAGEWITHZERO" + endline $
+ " #image" + endline $
+ " concat" + endline $
+ "#image" + endline $
+ ".tif" + endline $
+ " #image" + endline
endelse
fit2d += " concat" + endline $
+ "#stem" + endline $
+ "_" + endline $
+ " #chistem" + endline $
+ " concat" + endline $
+ "#chistem" + endline $
+ "#VALUEWITHZERO " + endline $
+ " #chistem" + endline $
+ " concat" + endline $
+ "#chistem" + endline $
+ "_ " + endline $
+ " #chistem" + endline $
+ "%!*\ Exit the keybboard interface" + endline $
+ " EXIT" + endline $
+ " POWDER DIFFRACTION (2-D)" + endline $
+ " INPUT" + endline $
+ " #image" + endline $
+ " O.K." + endline $
+ " O.K." + endline $
+ " CAKE" + endline $
+ " INTEGRATE" + endline $
+ " X-PIXEL SIZE" + endline $
+ " #X_PIXEL_SIZE" + endline $
+ " Y-PIXEL SIZE" + endline $
+ " #Y_PIXEL_SIZE" + endline $
+ " DISTANCE" + endline $
+ " #DISTANCE" + endline $
+ " WAVELENGTH" + endline $
+ " #WAVELENGTH" + endline $
+ " X-BEAM CENTRE" + endline $
+ " #X_BEAM_CENTRE" + endline $
+ " Y-BEAM CENTRE" + endline $
+ " #Y_BEAM_CENTRE" + endline $
+ " TILT ROTATION" + endline $
+ " #TILT_ROTATION" + endline $
+ " ANGLE OF TILT" + endline $
+ " #ANGLE_OF_TILT" + endline $
+ " DETECTOR ROTATION" + endline $
+ " #DETECTOR_ROTATION" + endline $
+ " DETECTOR OFFSET" + endline $
+ " #DETECTOR_OFFSET" + endline $
+ " O.K." + endline $
+ " START AZIMUTH" + endline $
+ " #START_AZIMUTH" + endline $
+ " END AZIMUTH" + endline $
+ " #END_AZIMUTH" + endline $
+ " INNER RADIUS" + endline $
+ " #INNER_RADIUS" + endline $
+ " OUTER RADIUS" + endline $
+ " #OUTER_RADIUS" + endline $
+ " AZIMUTH BINS" + endline $
+ " #AZIMUTH_BINS" + endline $
+ " O.K." + endline $
+ " EXIT" + endline $
+ " OUTPUT" + endline $
+ " MULTI-CHIPLOT" + endline $
+ " OUTPUT DIRECTORY" + endline $
+ " #path_to_chi_files" + endline $
+ " BASE NAME" + endline $
+ " #chistem" + endline $
+ " O.K." + endline $
+ " EXCHANGE" + endline $
+ " EXIT" + endline $
+ "%!*\ End of loop on images" + endline $
+ "END DO" + endline $
+ "%!*\ Return to macro" + endline $
+ "MACROS / LOG FILE" + endline $
+ "%!*\ END OF IO MACRO FILE"
ON_IOERROR, BADINPUT
GET_LUN, lun
OPENW, lun, macrofile
printf, lun, fit2d
free_lun, lun
logit, log, "Macro save in file: " + macrofile
return, 1
BADINPUT: return, !ERR_STRING
END
PRO setFit2dmac2DDataFromPrevious, file, stash
openr, lun, file, /get_lun
while ~ EOF(lun) do begin
row = ""
readf, lun, row
word = strsplit(row, '|', COUNT=nn, /EXTRACT)
if (nn gt 1) then begin
word2 = strsplit(word[0], COUNT=nn, /EXTRACT)
label = word2[1]
CASE label OF
"Multifit_baseNames": WIDGET_CONTROL, stash.baseNamesText, SET_VALUE=strtrim(word[1],2)
"Multifit_firstImage": WIDGET_CONTROL, stash.firstImageText, SET_VALUE=strtrim(word[1],2)
"Multifit_lastImage": WIDGET_CONTROL, stash.lastImageText, SET_VALUE=strtrim(word[1],2)
"Multifit_digitsImage": WIDGET_CONTROL, stash.digitsImageText, SET_VALUE=strtrim(word[1],2)
"Multifit_ext": WIDGET_CONTROL, stash.extText, SET_VALUE=strtrim(word[1],2)
"Multifit_xPixel": WIDGET_CONTROL, stash.xPixelText, SET_VALUE=strtrim(word[1],2)
"Multifit_yPixel": WIDGET_CONTROL, stash.yPixelText, SET_VALUE=strtrim(word[1],2)
"Multifit_wave": WIDGET_CONTROL, stash.waveText, SET_VALUE=strtrim(word[1],2)
"Multifit_xCenter": WIDGET_CONTROL, stash.xCenterText, SET_VALUE=strtrim(word[1],2)
"Multifit_yCenter": WIDGET_CONTROL, stash.yCenterText, SET_VALUE=strtrim(word[1],2)
"Multifit_detDis": WIDGET_CONTROL, stash.detDisText, SET_VALUE=strtrim(word[1],2)
"Multifit_tiltRotation": WIDGET_CONTROL, stash.tiltRotationText, SET_VALUE=strtrim(word[1],2)
"Multifit_tiltAngle": WIDGET_CONTROL, stash.tiltAngleText, SET_VALUE=strtrim(word[1],2)
"Multifit_detRot": WIDGET_CONTROL, stash.detRotText, SET_VALUE=strtrim(word[1],2)
"Multifit_azStart": WIDGET_CONTROL, stash.azStartText, SET_VALUE=strtrim(word[1],2)
"Multifit_azEnd": WIDGET_CONTROL, stash.azEndText, SET_VALUE=strtrim(word[1],2)
"Multifit_azBins": WIDGET_CONTROL, stash.azBinsText, SET_VALUE=strtrim(word[1],2)
"Multifit_innerRadius": WIDGET_CONTROL, stash.innerRadiusText, SET_VALUE=strtrim(word[1],2)
"Multifit_outerRadius": WIDGET_CONTROL, stash.outerRadiusText, SET_VALUE=strtrim(word[1],2)
else:
endcase
endif
endwhile
free_lun, lun
END
PRO fit2dmac2DData_event, ev
common files, extension, datadirectory, outputdirectory, defaultdirectory, jcpdsdirectory
WIDGET_CONTROL, ev.TOP, GET_UVALUE=stash
WIDGET_CONTROL, ev.ID, GET_UVALUE=uval
log=stash.log
if (uval eq 'OK') then begin
result = makefit2dmac2DData(log,stash)
if (FIX(result) ne 1) then begin
logit, log, "Macro creation failed"
tmp = DIALOG_MESSAGE(result, /ERROR)
endif else begin
WIDGET_CONTROL, ev.TOP, /DESTROY
endelse
endif else if (uval eq 'PARSEOLDMACRO') then begin
oldmacro = dialog_pickfile(title='Select previous macro', path=defaultdirectory, DIALOG_PARENT=base)
if (oldmacro ne '') then setFit2dmac2DDataFromPrevious, oldmacro, stash
endif else if (uval eq 'DATADIR') then begin
result=dialog_pickfile(/DIRECTORY,title='Select directory with diffraction data', path=defaultdirectory, DIALOG_PARENT=base)
if (result ne '') then WIDGET_CONTROL, stash.dataDirText, SET_VALUE=result
endif else begin
logit, log, "Creating macro for fit2d... Cancel."
WIDGET_CONTROL, ev.TOP, /DESTROY
endelse
END
PRO fit2dmac2DData, leader, log
common fonts, titlefont, boldfont, mainfont, avFontHeight
common files, extension, datadirectory, outputdirectory, defaultdirectory, jcpdsdirectory
common experiment, wavelength, detectordistance, experimenttype
fit2d = WIDGET_BASE(/COLUMN, Title='Create macro for fit2d (Regular 2D data, multipe images)', GROUP_LEADER=leader, TAB_MODE=1)
; Options
base = WIDGET_BASE(fit2d, /column)
parse = WIDGET_BUTTON(base, VALUE='Parse parameters from previous multifit macro', UVALUE='PARSEOLDMACRO', xsize=150)
base2 = WIDGET_BASE(base, /row)
label = WIDGET_LABEL(base2, VALUE='Directory diffraction data', /ALIGN_LEFT, xsize=200)
dataDirText = WIDGET_BUTTON(base2, /ALIGN_LEFT, VALUE='Not set', XSIZE=400, UVALUE='DATADIR')
base2 = WIDGET_BASE(base, /row)
label = WIDGET_LABEL(base2, VALUE='Directory to save chi files', /ALIGN_LEFT, xsize=200)
chiDirText = WIDGET_TEXT(base2, VALUE=datadirectory, XSIZE=40)
base2 = WIDGET_BASE(base, /row)
label = WIDGET_LABEL(base2, VALUE='Base for file names', /ALIGN_LEFT, xsize=150)
baseNamesText = WIDGET_TEXT(base2, VALUE='filename', XSIZE=10, /EDITABLE)
label = WIDGET_LABEL(base2, VALUE='Extension', /ALIGN_LEFT, xsize=150)
extText = WIDGET_TEXT(base2, VALUE='.tiff', XSIZE=10, /EDITABLE)
base2 = WIDGET_BASE(base, /row)
label = WIDGET_LABEL(base2, VALUE='First image number', /ALIGN_LEFT, xsize=150)
firstImageText = WIDGET_TEXT(base2, VALUE='', XSIZE=10, /EDITABLE)
label = WIDGET_LABEL(base2, VALUE='Last image number', /ALIGN_LEFT, xsize=150)
lastImageText = WIDGET_TEXT(base2, VALUE='', XSIZE=10, /EDITABLE)
label = WIDGET_LABEL(base2, VALUE='Number of digits', /ALIGN_LEFT, xsize=150)
digitsImageText = WIDGET_TEXT(base2, VALUE='3', XSIZE=10, /EDITABLE)
base2 = WIDGET_BASE(base, /row)
label = WIDGET_LABEL(base2, VALUE='X pixel size', /ALIGN_LEFT, xsize=150)
xPixelText = WIDGET_TEXT(base2, VALUE='200.', XSIZE=10, /EDITABLE)
label = WIDGET_LABEL(base2, VALUE='Y pixel size', /ALIGN_LEFT, xsize=150)
yPixelText = WIDGET_TEXT(base2, VALUE='200.', XSIZE=10, /EDITABLE)
label = WIDGET_LABEL(base2, VALUE='Wavelength', /ALIGN_LEFT, xsize=150)
waveText = WIDGET_TEXT(base2, VALUE=strtrim(string(wavelength),2), XSIZE=10, /EDITABLE)
base2 = WIDGET_BASE(base, /row)
label = WIDGET_LABEL(base2, VALUE='X beam center', /ALIGN_LEFT, xsize=150)
xCenterText = WIDGET_TEXT(base2, VALUE='0.', XSIZE=10, /EDITABLE)
label = WIDGET_LABEL(base2, VALUE='Y beam center', /ALIGN_LEFT, xsize=150)
yCenterText = WIDGET_TEXT(base2, VALUE='0.', XSIZE=10, /EDITABLE)
label = WIDGET_LABEL(base2, VALUE='Detec. distance', /ALIGN_LEFT, xsize=150)
detDisText = WIDGET_TEXT(base2, VALUE=strtrim(string(detectordistance),2), XSIZE=10, /EDITABLE)
base2 = WIDGET_BASE(base, /row)
label = WIDGET_LABEL(base2, VALUE='Tilt rotation', /ALIGN_LEFT, xsize=150)
tiltRotationText = WIDGET_TEXT(base2, VALUE='0.', XSIZE=10, /EDITABLE)
label = WIDGET_LABEL(base2, VALUE='Angle of tilt', /ALIGN_LEFT, xsize=150)
tiltAngleText = WIDGET_TEXT(base2, VALUE='0.', XSIZE=10, /EDITABLE)
label = WIDGET_LABEL(base2, VALUE='Detec. rotation', /ALIGN_LEFT, xsize=150)
detRotText = WIDGET_TEXT(base2, VALUE='0.', XSIZE=10, /EDITABLE)
base2 = WIDGET_BASE(base, /row)
label = WIDGET_LABEL(base2, VALUE='Start for azimuth angles', /ALIGN_LEFT, xsize=150)
azStartText = WIDGET_TEXT(base2, VALUE='0', XSIZE=10, /EDITABLE)
label = WIDGET_LABEL(base2, VALUE='End for azimuth angles', /ALIGN_LEFT, xsize=150)
azEndText = WIDGET_TEXT(base2, VALUE='360', XSIZE=10, /EDITABLE)
label = WIDGET_LABEL(base2, VALUE='Number of bins', /ALIGN_LEFT, xsize=150)
azBinsText = WIDGET_TEXT(base2, VALUE='72', XSIZE=10, /EDITABLE)
base2 = WIDGET_BASE(base, /row)
label = WIDGET_LABEL(base2, VALUE='Inner radius (pixels)', /ALIGN_LEFT, xsize=150)
innerRadiusText = WIDGET_TEXT(base2, VALUE='400', XSIZE=10, /EDITABLE)
label = WIDGET_LABEL(base2, VALUE='Outer radius (pixels)', /ALIGN_LEFT, xsize=150)
outerRadiusText = WIDGET_TEXT(base2, VALUE='2000', XSIZE=10, /EDITABLE)
; Buttons
buttons = WIDGET_BASE(fit2d,/ROW, /ALIGN_CENTER)
ok = WIDGET_BUTTON(buttons, VALUE='Ok', UVALUE='OK', xsize=80)
cancel = WIDGET_BUTTON(buttons, VALUE='Cancel', UVALUE='CANCEL', xsize=80)
stash = {log:log, base:base, dataDirText:dataDirText, chiDirText:chiDirText, baseNamesText:baseNamesText, firstImageText:firstImageText, lastImageText:lastImageText, digitsImageText:digitsImageText, extText:extText, xPixelText:xPixelText, yPixelText:yPixelText, waveText:waveText, xCenterText:xCenterText, yCenterText:yCenterText, detDisText:detDisText, tiltRotationText:tiltRotationText, tiltAngleText:tiltAngleText, detRotText:detRotText, azStartText:azStartText, azEndText:azEndText, azBinsText:azBinsText, innerRadiusText:innerRadiusText, outerRadiusText:outerRadiusText}
WIDGET_CONTROL, fit2d, SET_UVALUE=stash
WIDGET_CONTROL, fit2d, /REALIZE
XMANAGER, 'fit2dmac2DData', fit2d
END
; *******************************************************************
;
;
; Subroutines to create Fit2d macro with ID06 data
;
;
; *******************************************************************
FUNCTION fit2dMacroID06, log, stash
; Number of digits for chi loop (set by fit2d)
digitsChiLoop = 5
; Number of digits for image loop in output (forced)
digitsImageLoop = 3
; extracting variables
WIDGET_CONTROL, stash.dataDirText, GET_VALUE=dataDirText
dataDir = strtrim(dataDirText)
WIDGET_CONTROL, stash.chiDirText, GET_VALUE=chiDirText
chiDir = strtrim(chiDirText)
WIDGET_CONTROL, stash.baseNamesText, GET_VALUE=baseNamesText
baseNames = strtrim(baseNamesText)
WIDGET_CONTROL, stash.firstImageText, GET_VALUE=firstImageText
firstImage = FIX(FLOAT(firstImageText[0]))
WIDGET_CONTROL, stash.lastImageText, GET_VALUE=lastImageText
lastImage = FIX(FLOAT(lastImageText[0]))
WIDGET_CONTROL, stash.digitsImageText, GET_VALUE=digitsImageText
digitsImage = FIX(FLOAT(digitsImageText[0]))
WIDGET_CONTROL, stash.extText, GET_VALUE=extText
ext = strtrim(extText)
WIDGET_CONTROL, stash.xPixelText, GET_VALUE=xPixelText
xPixel = FLOAT(xPixelText[0])
WIDGET_CONTROL, stash.yPixelText, GET_VALUE=yPixelText
yPixel = FLOAT(yPixelText[0])
WIDGET_CONTROL, stash.waveText, GET_VALUE=waveText
wave = FLOAT(waveText[0])
WIDGET_CONTROL, stash.xCenterText, GET_VALUE=xCenterText
xCenter = FLOAT(xCenterText[0])
WIDGET_CONTROL, stash.yCenterText, GET_VALUE=yCenterText
yCenter = FLOAT(yCenterText[0])
WIDGET_CONTROL, stash.detDisText, GET_VALUE=detDisText
detDis = FLOAT(detDisText[0])
WIDGET_CONTROL, stash.tiltRotationText, GET_VALUE=tiltRotationText
tiltRotation = FLOAT(tiltRotationText[0])
WIDGET_CONTROL, stash.tiltAngleText, GET_VALUE=tiltAngleText
tiltAngle = FLOAT(tiltAngleText[0])
WIDGET_CONTROL, stash.detRotText, GET_VALUE=detRotText
detRot = FLOAT(detRotText[0])
WIDGET_CONTROL, stash.detOffsetText, GET_VALUE=detOffsetText
detOffset = FLOAT(detOffsetText[0])
WIDGET_CONTROL, stash.azStartText, GET_VALUE=azStartText
azStart = FLOAT(azStartText[0])
WIDGET_CONTROL, stash.azEndText, GET_VALUE=azEndText
azEnd = FLOAT(azEndText[0])
WIDGET_CONTROL, stash.azBinsText, GET_VALUE=azBinsText
azBins = FIX(FLOAT(azBinsText[0]))
WIDGET_CONTROL, stash.innerRadiusText, GET_VALUE=innerRadiusText
innerRadius = FLOAT(innerRadiusText[0])
WIDGET_CONTROL, stash.outerRadiusText, GET_VALUE=outerRadiusText
outerRadius = FLOAT(outerRadiusText[0])
; Testing that files actually exist. Otherwise, fit2d will crash
if (azEnd lt azStart) then return, "Start azimuth larger than end azimuth!"
for j=firstImage,lastImage do begin
if (digitsImage eq 0) then fileindex = string(j) else fileindex = intformat(j,digitsImage)
filename = strtrim(dataDir) + strtrim(baseNames) + "_" + strtrim(fileindex,2) + strtrim(ext)
; print, "Testing " + filename
if (FILE_TEST(filename) eq 0) then return, "File " + filename + " not found. Fit2d will crash."
endfor
; Defining name for macro file
macrofile = DIALOG_PICKFILE(PATH=dataDir, TITLE='Select name of fit2d macro file', FILTER='*.mac', /OVERWRITE_PROMPT,/WRITE, FILE=baseNames+'.mac')
if (macrofile eq '') then return, "No output file selected"
logit, log, "Macro file: " + macrofile
; We are ready to create a fit2d macro, preparing text
ccr = STRING(13B) ; Carriage Return
clf = STRING([10B]) ; line feed
endline = ccr + clf
fit2d = "%!*\\ MACRO FOR fit2d" + STRING(13B) $
+ "%!*\\ generated by Multifit, S. Merkel, N. Hilairet, J Appl Cryst, 48, 1307-1313 (2015) [doi: 10.1107/S1600576715010390]" + endline
if (digitsImage eq 0) then fileindex = string(firstImage) else fileindex = intformat(firstImage,digitsImage)
filename = strtrim(dataDir) + strtrim(baseNames) + "_" + strtrim(fileindex,2) + strtrim(ext)
fileindex = intformat(firstImage,digitsImageLoop)
firstchi = strtrim(dataDir) + strtrim(baseNames) + "_" + strtrim(fileindex,2) + "_00000.chi"
logit, log, "First input file: " + filename
fit2d += "%!*\\ First input file: " + filename + endline
if (digitsImage eq 0) then fileindex = string(lastImage) else fileindex = intformat(lastImage,digitsImage)
filename = strtrim(dataDir) + strtrim(baseNames) + "_" + strtrim(fileindex,2) + strtrim(ext)
fileindex = intformat(lastImage,digitsImageLoop)
lastchi = strtrim(dataDir) + strtrim(baseNames) + "_" + strtrim(fileindex,2) + "_" + intformat(azBins,digitsChiLoop) + ".chi"
logit, log, "Last input file: " + filename
fit2d += "%!*\\ Last input file: " + filename + endline $
+ "%!*\\ start azimuth: " + STRING(azStart,/PRINT) + endline $
+ "%!*\\ end azimuth: " + STRING(azEnd,/PRINT) + endline $
+ "%!*\\ number of bins: " + STRING(azBins,/PRINT) + endline
nchi = string((lastImage-firstImage+1)*azBins)
logit, log, "Number of chi files generated: " + nchi
fit2d += "%!*\\ Number of chi files generated: " + nchi + endline
logit, log, "Output files: " + firstchi + " to " + lastchi
fit2d += "%!*\\ output files:" + endline $
+ "%!*\\ " + firstchi + " to " + lastchi + endline $
+ "%!*\\ Multifit parameters" + endline $
+ "%!*\\ Multifit_dataDir | " + dataDir + endline $
+ "%!*\\ Multifit_chiDir | " + chiDir + endline $
+ "%!*\\ Multifit_baseNames | " + baseNames + endline $
+ "%!*\\ Multifit_firstImage | " + STRTRIM(STRING(firstImage,/PRINT),2) + endline $
+ "%!*\\ Multifit_lastImage | " + STRTRIM(STRING(lastImage,/PRINT),2) + endline $
+ "%!*\\ Multifit_digitsImage | " + STRTRIM(STRING(digitsImage,/PRINT),2) + endline $
+ "%!*\\ Multifit_ext | " + ext + endline $
+ "%!*\\ Multifit_xPixel | " + STRTRIM(STRING(xPixel,/PRINT),2) + endline $
+ "%!*\\ Multifit_yPixel | " + STRTRIM(STRING(yPixel,/PRINT),2) + endline $
+ "%!*\\ Multifit_wave | " + STRTRIM(STRING(wave,/PRINT),2) + endline $
+ "%!*\\ Multifit_xCenter | " + STRTRIM(STRING(xCenter,/PRINT),2) + endline $
+ "%!*\\ Multifit_yCenter | " + STRTRIM(STRING(yCenter,/PRINT),2) + endline $
+ "%!*\\ Multifit_detDis | " + STRTRIM(STRING(detDis,/PRINT),2) + endline $
+ "%!*\\ Multifit_tiltRotation | " + STRTRIM(STRING(tiltRotation,/PRINT),2) + endline $
+ "%!*\\ Multifit_tiltAngle | " + STRTRIM(STRING(tiltAngle,/PRINT),2) + endline $
+ "%!*\\ Multifit_detRot | " + STRTRIM(STRING(detRot,/PRINT),2) + endline $
+ "%!*\\ Multifit_detOffset | " + STRTRIM(STRING(detOffset,/PRINT),2) + endline $
+ "%!*\\ Multifit_azStart | " + STRTRIM(STRING(azStart,/PRINT),2) + endline $
+ "%!*\\ Multifit_azEnd | " + STRTRIM(STRING(azEnd,/PRINT),2) + endline $
+ "%!*\\ Multifit_azBins | " + STRTRIM(STRING(azBins,/PRINT),2) + endline $
+ "%!*\\ Multifit_innerRadius | " + STRTRIM(STRING(innerRadius,/PRINT),2) + endline $
+ "%!*\\ Multifit_outerRadius | " + STRTRIM(STRING(outerRadius,/PRINT),2) + endline $
+ "%!*\\" + endline $
+ "EXIT" + endline $
+ "%!*\ Enter the keybboard interface to define variables" + endline $
+ "KEYBOARD INTERFACE" + endline $
+ "variable" + endline $
+ "#first_image" + endline $
+ "integer" + endline $
+ STRTRIM(STRING(firstImage,/PRINT),2) + endline $
+ "variable" + endline $
+ "#last_image" + endline $
+ "integer" + endline $
+ STRTRIM(STRING(lastImage,/PRINT),2) + endline $
+ "variable" + endline $
+ "#path_to_images" + endline $
+ "string" + endline $
+ dataDir + endline $
+ "variable" + endline $
+ "#path_to_chi_files" + endline $
+ "string" + endline $
+ chiDir + endline $
+ "variable" + endline $
+ "#stem" + endline $
+ "string" + endline $
+ baseNames + endline $
+ "variable" + endline $