-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchdlgmod.f90
1933 lines (1856 loc) · 53.6 KB
/
chdlgmod.f90
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
! Copyright 2021, Christian Hafner
!
! This file is part of OpenMaXwell.
!
! OpenMaXwell 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 3 of the License, or
! (at your option) any later version.
! OpenMaXwell 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 OpenMaXwell. If not, see <http://www.gnu.org/licenses/>.
MODULE CHDLG
! compiler dependent libraries: Modify for using old Compaq Visual Fortran
USE IFLOGM !IVF uses this libraray
USE IFWIN !IVF uses this libraray - alternative for IFWIN
USE IFQWIN !IVF uses this libraray
USE IFPORT !IVF uses this libraray
!CVF USE DFLOGM !CVF uses this libraray
!CVF USE DFWIN !CVF uses this libraray
!CVF USE DFLIB !CVF uses this libraray
! Modeless dialogs, file dialogs, memory leaks
Save
Integer(4), Parameter :: mMLDlg=10
Integer(4) iMLDlg(mMLDlg),ich(1000)
Integer(INT_PTR_KIND()) iThreadHandle,iOutCheck1,iOutCheck2,iOutCheck3,iOutCheck4,iOutCheck5,iOutCheck6,iOutCheck7
Integer(4) iThreadAction,iDlgExit,iMovVarIn,iMovVarOut1,iMovVarOut2,iMovVarErr,iMovVar(0:999)
Integer(2) iWriteDigits,iSpaceRead,iPoints2DRead,iPoints3DRead
Real(8) space(3,0:3),SpaceAngle,Points2D(2,3),Points3D(3,3),rch(1000),rMovVar(0:999)
Logical lStopThread,lThreadStarted,lMatErr,l4,l5,l6,l7,lAutoStart
Character(32) SpaceText,Points2DText,Points3DText
Character(256) sch
Real(8) pSmall,nSmall,pBig,nBig
Public
type(dialog) mousedlg,outputdlg,actiondlg
contains
subroutine Cursor(begin,id)
! Show Cursor (begin = .true.) or restore the standard Cursor(begin = .false.).
! Predefined: id=
! IDC_APPSTARTING Standard arrow and small hourglass
! IDC_ARROW Standard arrow
! IDC_CROSS Crosshair
! IDC_WAIT Hourglass
implicit none
logical, intent(in) :: begin
integer(INT_PTR_KIND()) id,idum,i0
integer(4), static :: CursorRefCount = 0
type(T_POINT) cursorPos
logical(4) lfoo
i0=0
if(begin) then
if(CursorRefCount==0) then
Select Case(id)
case(IDC_APPSTARTING,IDC_ARROW,IDC_CROSS,IDC_WAIT)
idum=LoadCursor(i0,id)
lfoo=SetCursor(idum)
case Default
idum=LoadCursor(GetModuleHandle(Null),id)
lfoo=SetCursor(idum)
end Select
endif
CursorRefCount=CursorRefCount+1
else
CursorRefCount=CursorRefCount-1
if(CursorRefCount==0) then
lfoo=GetCursorPos(cursorPos)
lfoo=SetCursorPos(cursorPos%x, cursorPos%y)
endif
endif
end subroutine Cursor
subroutine InitIconButton(Dlg,IDButton,IDIcon)
! put the icon IDIcon on the button IDButton
implicit none
include 'resource.fd'
integer(INT_PTR_KIND()), intent(in) :: Dlg,IDIcon
integer(4), intent(in) :: IDButton
integer(INT_PTR_KIND()) hwndButton,idum,hInstance,hIcon
hInstance=GetModuleHandle(NULL)
hIcon=LoadIcon(hInstance,IDIcon)
hwndButton=GetDlgItem(Dlg,IDButton)
idum=SendMessage(hwndButton,BM_SETIMAGE,IMAGE_ICON,hIcon)
end subroutine InitIconButton
subroutine IntToStr(i,iwidth,ipadZeroes,str,lout)
Integer(4) i,iwidth,ipadZeroes
Character(*) str
Integer(4) lout
lout=iwidth
if(ipadZeroes.lt.1) then
select case(iwidth)
case(1)
write(str,'(1I1)') i
case(2)
write(str,'(1I2)') i
case(3)
write(str,'(1I3)') i
case(4)
write(str,'(1I4)') i
case(5)
write(str,'(1I5)') i
case(6)
write(str,'(1I6)') i
case(7)
write(str,'(1I7)') i
case(8)
write(str,'(1I8)') i
case(9)
write(str,'(1I9)') i
case default
write(str,'(1I10)') i
end select
lout=GetSLength(str)
call DelBlanks(str,lout)
else
select case(iwidth)
case(1)
write(str,'(1I1.1)') i
case(2)
write(str,'(1I2.2)') i
case(3)
write(str,'(1I3.3)') i
case(4)
write(str,'(1I4.4)') i
case(5)
write(str,'(1I5.5)') i
case(6)
write(str,'(1I6.6)') i
case(7)
write(str,'(1I7.7)') i
case(8)
write(str,'(1I8.8)') i
case(9)
write(str,'(1I9.9)') i
case default
write(str,'(1I3.3)') i
end select
lout=iwidth
end if
end subroutine IntToStr
subroutine RealToStr(r,iwidth,iprecision,str,lout)
Real(8) r
Integer(4) iwidth,iprecision,ip,iOK
Character(*) str
Integer(4) lout
ip=iprecision
if(iwidth.gt.0) ip=iwidth-8
select case(ip)
case(0)
write(str,'(1PE8.0E3)') r
case(1)
write(str,'(1PE9.1E3)') r
case(2)
write(str,'(1PE10.2E3)') r
case(3)
write(str,'(1PE11.3E3)') r
case(4)
write(str,'(1PE12.4E3)') r
case(5)
write(str,'(1PE13.5E3)') r
case(6)
write(str,'(1PE14.6E3)') r
case(7)
write(str,'(1PE15.7E3)') r
case(8)
write(str,'(1PE16.8E3)') r
case(9)
write(str,'(1PE17.9E3)') r
case(10)
write(str,'(1PE18.10E3)') r
case(11)
write(str,'(1PE19.11E3)') r
case(12)
write(str,'(1PE20.12E3)') r
case(13)
write(str,'(1PE21.13E3)') r
case default
write(str,'(1PE22.14E3)',iostat=iOK) r
if(iOK.ne.0) then
write(*,*) 'Unhandled problem in RealToStr!'
write(str,'(1PE18.10E3)') r
end if
end select
lout=GetSLength(str)
if((iwidth.lt.lout).and.(iwidth.gt.0)) then
write(*,*) 'Unhandled exception in RealToStr!'
end if
end subroutine RealToStr
subroutine StrToInt(str,i,iOK)
Character(*) str
Integer(4) i,iOK,l
l=GetSLength(str)
if(l.lt.1) then
iOK=-1
i=0
return
end if
if(str(l:l).eq.Char(0)) l=l-1
if(l.lt.1) then
iOK=-1
i=0
return
end if
read(str(1:l),*,iostat=iOK) i
if((iOK.eq.0).and.(ichar(str(1:1)).gt.64).and.(ichar(str(1:1)).lt.123)) iOK=999 ! first character f or t would be OK
end subroutine StrToInt
subroutine StrToRea(str,r,iOK)
Character(*) str
Real(8) r
Integer(4) iOK,i,l
l=GetSLength(str)
if(l.lt.1) then
iOK=-1
r=0.0d0
return
end if
if(str(l:l).eq.Char(0)) l=l-1
if(l.lt.1) then
iOK=-1
r=0.0d0
return
end if
if((ichar(str(1:1)).gt.64).and.(ichar(str(1:1)).lt.123)) then ! first character f or t would be OK for fortran iostat
iOK=999
return
end if
read(str(1:l),*,iostat=iOK) r
if(iOK.ne.0) then ! might be an iteger value that causes the iostat error
read(str(1:l),*,iostat=iOK) i
r=Dble(i)
end if
end subroutine StrToRea
Subroutine StopThread()
! set stop flag for stopping the current thread
Implicit none
Logical ldu
Integer(4) iUnit,idum
if(.not.lThreadStarted) return
lStopThread=.true.
call OutTxt('t3','Stop thread')
do iUnit=1,10
if((iUnit.gt.4).and.(iUnit.lt.7)) Cycle ! 5: keyboard in, 6: screen out
call SleepQQ(10_4)
inquire(unit=iUnit,opened=ldu)
if(ldu) then
write(iUnit,'(1H )',iostat=idum)
EndFile(iUnit)
close(iUnit)
end if
end do
call OutTxt('t3','Thread stopped')
end Subroutine StopThread
Subroutine WaitEndThread()
! wait until the current thread ends
Implicit none
Integer(4) it
it=1_4
do
if(.not.lThreadStarted) Exit
call SleepQQ(it)
it=min(it*2_2,1000_4)
end do
end Subroutine WaitEndThread
Subroutine EndThread()
! end of the current thread
Implicit none
if(.not.lThreadStarted) return
lThreadStarted=.false.
lStopThread=.false.
call StopThread()
call WaitEndThread()
call OutTxt('t3','End thread')
end Subroutine EndThread
! items of modeless dialogs
logical(4) function EnableDlg(Dlg, lEnable)
implicit none
integer(INT_PTR_KIND()), intent(in) :: Dlg
logical(4), intent(in) :: lEnable
Integer i
i=lEnable
EnableDlg = EnableWindow(dlg,i)
end function EnableDlg
logical(4) function EnableDlgItem(Dlg, id, lEnable)
implicit none
integer(INT_PTR_KIND()), intent(in) :: Dlg
integer(4), intent(in) :: id
logical(4), intent(in) :: lEnable
integer(INT_PTR_KIND()) hwnd
Integer i
i=lEnable
hwnd = GetDlgItem(Dlg, id)
EnableDlgItem = EnableWindow(hwnd,i)
end function EnableDlgItem
integer(4) function GetCheck(Dlg, id)
! radio buttons and check boxes
implicit none
integer(INT_PTR_KIND()), intent(in) :: Dlg
integer(4), intent(in) :: id
integer(INT_PTR_KIND()) hwndButton
hwndButton = GetDlgItem(Dlg, id)
GetCheck = SendMessage(hwndButton, BM_GETCHECK, 0, 0)
end function GetCheck
subroutine SetCheck(Dlg, id, check)
! radio buttons and check boxes
implicit none
integer(INT_PTR_KIND()), intent(in) :: Dlg
integer(4), intent(in) :: id
integer(INT_PTR_KIND()), intent(in) :: check
integer(INT_PTR_KIND()) hwndButton
integer(4) iFoo
hwndButton = GetDlgItem(Dlg, id)
iFoo = SendMessage(hwndButton, BM_SETCHECK, check, 0)
end subroutine SetCheck
subroutine OutTxt(s,str)
! set text in one of the output dialog text boxes
implicit none
include 'resource.fd'
character(2), intent(in) :: s
character(*), intent(in) :: str
integer(4) iFoo,idum
iFoo=getCheck(outputdlg%hwnd,IDC_OUT_CHECK4)
if(iFoo.ne.0_4) then
l4=.true.
else
l4=.false.
end if
iFoo=getCheck(outputdlg%hwnd,IDC_OUT_CHECK5)
if(iFoo.ne.0_4) then
l5=.true.
else
l5=.false.
end if
iFoo=getCheck(outputdlg%hwnd,IDC_OUT_CHECK6)
if(iFoo.ne.0_4) then
l6=.false.
else
l6=.true.
end if
iFoo=getCheck(outputdlg%hwnd,IDC_OUT_CHECK7)
if(iFoo.ne.0_4) then
l7=.false.
else
l7=.true.
end if
if(s(1:1).eq.'!') return
select case(s)
case('t1','T1')
iFoo=getCheck(outputdlg%hwnd,IDC_OUT_CHECK1)
if(iFoo.ne.0_4) idum=SetDlgItemText(outputdlg%hwnd,IDC_OUT_TEXT1,str//Char(0))
case('n1','N1')
iFoo=getCheck(outputdlg%hwnd,IDC_OUT_CHECK1)
if(iFoo.ne.0_4) idum=SetDlgItemText(outputdlg%hwnd,IDC_OUT_N1,str//Char(0))
case('m1','M1')
iFoo=getCheck(outputdlg%hwnd,IDC_OUT_CHECK1)
if(iFoo.ne.0_4) idum=SetDlgItemText(outputdlg%hwnd,IDC_OUT_M1,str//Char(0))
case('t2','T2')
iFoo=getCheck(outputdlg%hwnd,IDC_OUT_CHECK2)
if(iFoo.ne.0_4) idum=SetDlgItemText(outputdlg%hwnd,IDC_OUT_TEXT2,str//Char(0))
case('n2','N2')
iFoo=getCheck(outputdlg%hwnd,IDC_OUT_CHECK2)
if(iFoo.ne.0_4) idum=SetDlgItemText(outputdlg%hwnd,IDC_OUT_N2,str//Char(0))
case('m2','M2')
iFoo=getCheck(outputdlg%hwnd,IDC_OUT_CHECK2)
if(iFoo.ne.0_4) idum=SetDlgItemText(outputdlg%hwnd,IDC_OUT_M2,str//Char(0))
case('t3','T3')
iFoo=getCheck(outputdlg%hwnd,IDC_OUT_CHECK3)
if(iFoo.ne.0_4) idum=SetDlgItemText(outputdlg%hwnd,IDC_OUT_TEXT3,str//Char(0))
case('n3','N3')
iFoo=getCheck(outputdlg%hwnd,IDC_OUT_CHECK3)
if(iFoo.ne.0_4) idum=SetDlgItemText(outputdlg%hwnd,IDC_OUT_N3,str//Char(0))
case('m3','M3')
iFoo=getCheck(outputdlg%hwnd,IDC_OUT_CHECK3)
if(iFoo.ne.0_4) idum=SetDlgItemText(outputdlg%hwnd,IDC_OUT_M3,str//Char(0))
end select
end subroutine OutTxt
subroutine SetSel(dlg, id, istart, iend)
! Nur eine Hilfsfunktion zum Setzen der Selektion in Edit-Feldern
implicit none
integer(INT_PTR_KIND()), intent(in) :: dlg
integer(4), intent(in) :: id
integer(INT_PTR_KIND()), intent(in) :: istart
integer(INT_PTR_KIND()), intent(in) :: iend
integer(INT_PTR_KIND()) hwndEdit
integer(4) iFoo
hwndEdit = GetDlgItem(dlg, id)
iFoo = SendMessage(hwndEdit, EM_SETSEL, istart, iend)
end subroutine SetSel
subroutine GetSel(dlg, id, istart, iend)
! Nur eine Hilfsfunktion zum Ablesen der Selektion in Edit-Feldern
implicit none
integer(INT_PTR_KIND()), intent(in) :: dlg
integer(4), intent(in) :: id
integer(INT_PTR_KIND()), intent(out) :: istart
integer(INT_PTR_KIND()), intent(out) :: iend
integer(INT_PTR_KIND()) hwndEdit
integer(4) iFoo
hwndEdit = GetDlgItem(dlg, id)
iFoo = SendMessage(hwndEdit, EM_GETSEL, NULL, NULL)
istart = LOWORD(iFoo)
iend = HIWORD(iFoo)
end subroutine GetSel
! file open/save dialogs
subroutine CHGetFileName(title,filter1,extension,lExist,file_spec,ios)
! display file open dialog with title for getting the file name file_spec
! use filter_spec for file types. lExist defines whether file must exist or not
! returns file_spec and ios (0: no file selected, 1: file selected)
use comdlg32
use user32 ! Interface for GetForegroundWindow
implicit none
Integer(4) ios
Logical lExist
! Declare structure used to pass and receive attributes
type(T_OPENFILENAME) ofn
! Declare filter specification: concatenation of pairs of null-terminated strings.
! The first string in each pair is the file type name, the second is a semicolon-separated list
! of file types for the given name. The list ends with a trailing null-terminated empty string.
character*(*) filter1,extension
character*(512):: filter_spec
character*(256):: file_spec ! file to be opened
character*(256):: title ! dialog title
ios=0
filter_spec=filter1//'(*.'//Extension//')'//Char(0)//'*.'//Extension// &
Char(0)//'All Files (*.*)'//Char(0)//'*.*'//Char(0)
ofn%lStructSize=SIZEOF(ofn)
ofn%hwndOwner=GetForegroundWindow()
ofn%hInstance=NULL ! For Win32 applications, might be set to the appropriate hInstance
ofn%lpstrFilter=loc(filter_spec)
ofn%lpstrCustomFilter=NULL
ofn%nMaxCustFilter=0
ofn%nFilterIndex=1 ! Specifies initial filter value
ofn%lpstrFile=loc(file_spec)
ofn%nMaxFile=sizeof(file_spec)
ofn%nMaxFileTitle=0
ofn%lpstrInitialDir=NULL ! Use Windows default directory
ofn%lpstrTitle=loc(title)
if(lExist) then
ofn%Flags=IOR(IOR(OFN_EXPLORER,OFN_FILEMUSTEXIST),OFN_HIDEREADONLY)
else
ofn%Flags=IOR(IOR(OFN_EXPLORER,OFN_OVERWRITEPROMPT),OFN_HIDEREADONLY)
end if
ofn%lpstrDefExt=loc(Extension//Char(0))
ofn%lpfnHook=NULL
ofn%lpTemplateName=NULL
ios=GetOpenFileName(ofn) ! Call GetOpenFileName and check status
end subroutine CHGetFileName
Subroutine Open2read(ifnr,Title,filter1,fileName,Extension,ios)
Implicit none
integer(4) ifnr,ios
character*(*) Title,filter1,fileName,Extension
call CHGetFileName(title,filter1,Extension,.true.,fileName,ios)
if((ios.gt.0).and.(ifnr.gt.0)) then
open(ifnr,file=fileName,status='old',action='read',iostat=ios)
else
if(ios.gt.0) then
ios=0
else
ios=1
end if
end if
end Subroutine Open2read
Subroutine Open2write(ifnr,Title,filter1,fileName,Extension,ios)
Implicit none
integer(4) ifnr,ios
character*(*) Title,filter1,fileName,Extension
call CHGetFileName(title,filter1,Extension,.false.,fileName,ios)
if((ios.gt.0).and.(ifnr.gt.0)) then
open(ifnr,file=fileName,status='unknown',action='write',iostat=ios)
else
if(ios.gt.0) then
ios=0
else
ios=1
end if
end if
end Subroutine Open2write
! I/O dialogs
Subroutine DlgSetI(Dlg,idc,idcS,i0,imin,imax)
Implicit none
Integer(4), Intent(in):: idc,idcS,i0,imin,imax
Integer(4) i,lout
Logical ldum
Type(dialog) Dlg
Character(64) text
i=i0
if(imax.ge.imin) then
i=min(imax,max(imin,i0))
end if
call IntToStr(i,0_4,0_4,text,lout)
ldum=DlgSet(Dlg,idc,text)
if(idcS.gt.0_4) then
ldum=DlgSet(Dlg,idcS,1_4,Dlg_RangeMin)
ldum=DlgSet(Dlg,idcS,imax-imin+1_4,Dlg_RangeMax)
ldum=DlgSet(Dlg,idcS,imax-i+1_4,Dlg_position)
ldum=DlgSet(Dlg,idcS,1_4,Dlg_smallstep)
ldum=DlgSet(Dlg,idcS,1_4,Dlg_bigstep)
end if
end Subroutine DlgSetI
Subroutine DlgSetR(Dlg,idc,r,idigit)
Implicit none
Integer(4), Intent(in):: idc,idigit
Integer(4) lout
Real(8), Intent(in):: r
Logical ldum
Type(dialog) Dlg
Character(64) text
call RealToStr(r,0,idigit,text,lout)
ldum=DlgSet(Dlg,idc,text)
end Subroutine DlgSetR
Subroutine DlgSetSn(Dlg,idc,s,n,sn)
Implicit none
Integer(4), Intent(in):: idc,n
Integer(4) idum,ls
Logical ldum
Type(dialog) Dlg
Character(*), Intent(in):: s,sn(n)
ldum=DlgSet(Dlg,idc,n,Dlg_numitems)
ls=GetSLength(s)
ldum=DlgSetChar(Dlg,idc,s(1:ls)//char(0))
do idum=1,n
ls=GetSLength(sn(idum))
if(ls.lt.256) then
ldum=DlgSetChar(Dlg,idc,sn(idum)(1:ls),idum)
else
ldum=DlgSetChar(Dlg,idc,'!! LONG STRING !!'C,idum)
end if
end do
end Subroutine DlgSetSn
Subroutine DlgSetS1(Dlg,idc,s,s1)
Implicit none
Integer(4), Intent(in):: idc
Integer(4) ls
Logical ldum
Type(dialog) Dlg
Character(*), Intent(in):: s,s1
ldum=DlgSet(Dlg,idc,1,Dlg_numitems)
ls=GetSLength(s1)
if(ls.lt.256) then
ldum=DlgSet(Dlg,idc,s1(1:ls),1)
else
ldum=DlgSet(Dlg,idc,'!! LONG STRING !!'C,1)
end if
call DlgSetS0(Dlg,idc,s)
end Subroutine DlgSetS1
Subroutine DlgSetS0(Dlg,idc,s)
Implicit none
Integer(4), Intent(in):: idc
Integer(4) ls
Logical ldum
Type(dialog) Dlg
Character(*), Intent(in):: s
ls=GetSLength(s)
if(ls.lt.256) then
ldum=DlgSet(Dlg,idc,s(1:ls))
else
ldum=DlgSet(Dlg,idc,'!! LONG STRING !!'C)
end if
end Subroutine DlgSetS0
Subroutine DlgSetL(Dlg,idc,l)
Implicit none
Integer(4), Intent(in):: idc
Logical, Intent(in):: l
Logical ldum
Type(dialog) Dlg
ldum=DlgSet(Dlg,idc,l)
end Subroutine DlgSetL
Subroutine DlgGetI(Dlg,idc,idcS,id,i,imin,imax,idef)
Implicit none
Integer(4), Intent(in):: idc,idcS,id,imin,imax,idef
Integer(4), Intent(out):: i
Integer(4) i0,idum
Logical ldum
Type(dialog) Dlg
Character(64) text
if((id.lt.1).or.(idcS.lt.1)) then
ldum=DlgGet(Dlg,idc,text)
call StrToInt(text,i0,idum)
if(idum.ne.0) i0=idef
else
ldum=DlgGet(Dlg,idcS,i0,Dlg_position)
i0=imax-i0+1_4
end if
i=i0
if(imax.ge.imin) then
i=min(imax,max(imin,i0))
end if
call DlgSetI(Dlg,idc,idcS,i,imin,imax)
end Subroutine DlgGetI
Subroutine DlgGetR(Dlg,idc,r,rmin,rmax,rdef,idigit)
Implicit none
Integer(4), Intent(in):: idc,idigit
Integer(4) idum
Real(8), Intent(in):: rmin,rmax,rdef
Real(8), Intent(out):: r
Logical ldum
Type(dialog) Dlg
Character(64) text
ldum=DlgGet(Dlg,idc,text)
call StrToRea(text,r,idum)
if(idum.ne.0) r=rdef
r=max(rmin,min(rmax,r))
call DlgSetR(Dlg,idc,r,idigit)
end Subroutine DlgGetR
Subroutine DlgGetS(Dlg,idc,s)
Implicit none
Integer(4), Intent(in):: idc
Include 'RESOURCE.FD'
Logical ldum
Type(dialog) Dlg
Character(*), Intent(out):: s
Character(256) sg
ldum=DlgGet(Dlg,idc,sg)
if(sg(1:1).ne.'!') s=sg
end Subroutine DlgGetS
Subroutine DlgGetL(Dlg,idc,l)
Implicit none
Integer(4), Intent(in):: idc
Include 'RESOURCE.FD'
Logical, Intent(out):: l
Logical ldum
Type(dialog) Dlg
ldum=DlgGet(Dlg,idc,l)
end Subroutine DlgGetL
! read/write
Subroutine WriteStr0(unit,str,iostat)
! Write a string to a unit
implicit none
Integer(4) unit
character*(*) str
Integer(4) iostat
write(unit,'(a)',iostat=iostat) str
end Subroutine WriteStr0
Subroutine WriteStr(unit,str,iostat)
! Write a string to a unit
implicit none
Integer(4) unit,l
character*(*) str
Integer(4) iostat
l=GetSLength(str)
if(l.gt.0) then
write(unit,'(a)',iostat=iostat) str(1:l)
else
write(unit,'(a)',iostat=iostat) ' '
end if
end Subroutine WriteStr
Subroutine ReadStr(unit, str, iostat)
! Read a string from a unit.
! Reading stops when either
! - the string is full
! - we hit an end-of-line
! - an error hits us
implicit none
Integer(4) unit
character*(*) str
Integer(4) iostat
read(unit,'(a)',iostat=iostat) str
end Subroutine ReadStr
Subroutine chwrit2(iunit,i,ni,r,nr,cs,ns,iostat)
! write ni Integer(4) numbers contained in the array i followed by
! nr Real numbers contained in the array r, followed by ns characters
! contained in the character string cs on the unit number iunit
! in compressed form.
! Note: length of the output string <80
! cs: considered to be dummy comment -> may be cut
Implicit none
Integer(4) i(*),iunit,ni,nr,ns,iostat,len4
Real(8) r(*)
Integer(2) leng,ls
Character(82) rs
Character(*) cs
if(iWriteDigits.gt.10_2) then
if(ni.gt.0) then
if(nr.gt.0) then
write(iunit,*,iostat=iostat) i(1:ni),r(1:nr),cs(1:ns)
else
write(iunit,*,iostat=iostat) i(1:ni),cs(1:ns)
end if
else
if(nr.gt.0) then
write(iunit,*,iostat=iostat) r(1:nr),cs(1:ns)
else
write(iunit,'(a)',iostat=iostat) cs(1:ns)
end if
end if
return
end if
call cswrit2(i,Int2(ni),r,Int2(nr),rs,leng)
if(leng.lt.0) then ! string too long -> split
if(ni.gt.0_2) then
call cswrit2(i,Int2(ni),r,0_2,rs,leng) ! Integer(4) part
if(leng.lt.0) then
iostat=leng
return
end if
call WriteStr(iunit,rs(1:leng),iostat)
end if
call cswrit2(i,0_2,r,Int2(nr),rs,leng) ! real part
if(leng.lt.0) then ! real part too long -> split
call cswrit2(i,0_2,r(1:((nr+1)/2)),Int2((nr+1)/2),rs,leng) ! first half
if(leng.lt.0) then
iostat=leng
return
end if
call WriteStr(iunit,rs(1:leng),iostat)
call cswrit2(i,0_2,r((1+(nr+1)/2):nr),Int2(nr-(nr+1)/2),rs,leng) ! second half
if(leng.lt.0) then
iostat=leng
return
end if
end if
end if
if((ns.gt.0).and.(leng.lt.80_2)) then ! text string
leng=leng+1
rs(leng:leng)=' '
ls=Min(Int2(ns),80_2-leng)
if(ls.gt.0) then
rs(leng+1:leng+ls)=cs(1:ls)
leng=leng+ls
end if
end if
if((ni.lt.1).and.(nr.lt.1)) then
len4=Int(leng)
call DelLeadingBlanks(rs,len4)
leng=Int2(len4)
if(leng.lt.1) then ! set single blank if string is empty
rs(1:1)=' '
leng=1
end if
end if
call WriteStr(iunit,rs(1:leng),iostat)
end Subroutine chwrit2
Subroutine chread2(iunit,i,ni,r,nr,iostat)
! read ni Integer(4) numbers contained in the array i followed by
! nr Real numbers contained in the array r on the unit number iunit
Implicit none
Integer(4) i(*),iunit,ni,nr,iostat,i0,i1,i2,k
Real(8) r(*)
Character(82) cs
if((ni.lt.1).and.(nr.lt.1)) then
iostat=-9
return
end if
call ReadStr(iunit,cs,iostat)
if(iostat.ne.0) return
i0=1
call BStrB(cs,i0,i1,i2) ! test if the line is blank
do while(i2.lt.i1)
call ReadStr(iunit,cs,iostat)
if(iostat.ne.0) return
i0=1
call BStrB(cs,i0,i1,i2)
end do
k=1
do while(k.le.ni)
call BStrB(cs,i0,i1,i2)
do while(i2.lt.i1)
call ReadStr(iunit,cs,iostat)
if(iostat.ne.0) return
i0=1
call BStrB(cs,i0,i1,i2)
end do
i0=i2+1
call StrToInt(cs(i1:i2),i(k),iostat)
if(iostat.ne.0) then
call ReadStr(iunit,cs,iostat)
if(iostat.ne.0) return
i0=1
Cycle
end if
k=k+1
end do
k=1
do while(k.le.nr)
call BStrB(cs,i0,i1,i2)
do while(i2.lt.i1)
call ReadStr(iunit,cs,iostat)
if(iostat.ne.0) return
i0=1
call BStrB(cs,i0,i1,i2)
end do
i0=i2+1
call StrToRea(cs(i1:i2),r(k),iostat)
if(iostat.ne.0) then
call ReadStr(iunit,cs,iostat)
if(iostat.ne.0) return
i0=1
Cycle
end if
k=k+1
end do
end Subroutine chread2
Subroutine cswrit2(i,ni,r,nr,rs,leng)
! write ni Integer(4) numbers contained in the array i followed by
! nr Real numbers contained in the array r on the string rs
! in compressed form. leng=length of the string (leng<81)
Implicit none
Integer(2) leng,ni,nr,j,j1,l
Integer(4) i(*)
Real(8) r(*)
Character(82) rs
Character(20) rn
leng=0
if(ni.gt.0) then
call iswrit2(i(1),rs,leng)
do j=2,ni
call iswrit2(i(j),rn,l)
if((leng+l+1).gt.80) then
leng=-leng
return
end if
leng=leng+1
rs(leng:leng)=' '
rs(leng+1:leng+l)=rn(1:l)
leng=leng+l
end do
end if
if(nr.gt.0) then
if(leng.gt.0) then
j1=1
else
call rswrit2(r(1),iWriteDigits,rs,leng)
j1=2
end if
do j=j1,nr
call rswrit2(r(j),iWriteDigits,rn,l)
if((leng+l+1).gt.80) then
leng=-leng
return
end if
leng=leng+1
rs(leng:leng)=' '
rs(leng+1:leng+l)=rn(1:l)
leng=leng+l
end do
end if
end Subroutine cswrit2
Subroutine rswrit2(r,n,rss,leng)
! write Real number r on the string rs, use n digits (0<n<11),
! compress the string, leng=length of the string
Implicit none
Integer(2) n,n0,leng,ipos,i,man
Integer(4) lout,iprec
Real(8) r
Character(20) rs,rss
lMatErr=.false.
rs=' '
rss=' '
iprec=min(10,max(0,Int4(n-1)))
n0=Int2(iprec+1)
call RealToStr(r,0,iprec,rs,lout)
leng=Int2(lout)
if((rs(1:1).ne.' ').and.(rs(1:1).ne.'-').and.(rs(1:1).ne.'+')) then
lMatErr=.true.
return
end if
if(rs(3:3).ne.'.') then
lMatErr=.true.
return
end if
if((rs(n0+3_2:n0+3_2).ne.'E').and.(rs(n0+3_2:n0+3_2).ne.'e')) then
lMatErr=.true.
return
end if
if((rs(n0+4_2:n0+4_2).ne.' ').and.(rs(n0+4_2:n0+4_2).ne.'-').and.(rs(n0+4_2:n0+4_2).ne.'+')) then
lMatErr=.true.
return
end if
if(rs(n0+4_2:n0+7_2).eq.'-001') then
if(rs(1_2:1_2).eq.'-') then
rss(1_2:3_2)='-0.'
rss(4_2:4_2)=rs(2_2:2_2)
leng=4_2
if(n0.gt.1_2) then
rss(5_2:n0+3_2)=rs(4_2:n0+2_2)
leng=n0+3_2
end if
else
rss(1_2:2_2)='0.'
rss(3_2:3_2)=rs(2_2:2_2)
leng=3_2
if(n0.gt.1_2) then
rss(4_2:n0+2_2)=rs(4_2:n0+2_2)
leng=n0+2_2
end if
end if
do i=leng,1_2,-1_2
if(rss(i:i).ne.'0') exit
leng=leng-1_2
end do
else
if(rs(1:1).eq.'-') then
rss(1:1)=rs(1:1)
ipos=2_2
else
ipos=1_2
end if
if(rs(2:2).eq.'0') then
rss='0'
leng=1_2
else
rss(ipos:ipos)=rs(2:2)
man=n0-1_2
do i=n0+2_2,4_2,-1_2
if(rs(i:i).ne.'0') exit
man=man-1
end do
if(man.ne.0_2) then
ipos=ipos+1_2
rss(ipos:ipos)='.'
ipos=ipos+1_2
rss(ipos:ipos+man-1_2)=rs(4_2:3_2+man)
ipos=ipos+man-1_2
end if
if(rs(n0+5_2:n0+7_2).eq.'000') then
leng=ipos
else
if(rs(n0+4_2:n0+4_2).eq.'-') then
ipos=ipos+2_2
rss(ipos-1_2:ipos)='E-'
else
ipos=ipos+1_2
rss(ipos:ipos)='E'
end if
if(rs(n0+5_2:n0+5_2).ne.'0') then
ipos=ipos+3_2
rss(ipos-2_2:ipos)=rs(n0+5_2:n0+7_2)
else if(rs(n0+6_2:n0+6_2).ne.'0') then
ipos=ipos+2_2
rss(ipos-1_2:ipos)=rs(n0+6_2:n0+7_2)
else
ipos=ipos+1_2
rss(ipos:ipos)=rs(n0+7_2:n0+7_2)
end if
leng=ipos
end if
end if
end if
end Subroutine rswrit2
Subroutine iswrit2(i,is,leng)
! write Integer(4) number i on the string is
! compress the string, leng=length of the string
Implicit none
Integer(4) i,lout
Integer(2) leng
Character(*) is
call IntToStr(i,0,0,is,lout)
call DelBlanks(is,lout)
leng=Int2(lout)
end Subroutine iswrit2
Subroutine rswrit1(r,n,rss,leng)
Implicit none
Integer(2) n,leng
Integer(4) lout,iprec
Real(8) r
Character(20) rss