-
Notifications
You must be signed in to change notification settings - Fork 3
/
chfldmod.f90
4579 lines (4521 loc) · 149 KB
/
chfldmod.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 CHFLD
! Field evaluation
USE CHCFD
SAVE
CONTAINS
! Defaults
Subroutine Field_Defaults(lCheck)
! set default field
Implicit none
Logical, intent(in) :: lCheck
Logical ldum
call Cursor(.true.,IDC_WAIT)
ldum=lCheck
lWinFld(1:nWin)=.true.
lAskFld=.true.
lSkipFld=.false.
lSkipDerFld=.false.
lSkipVecFld=.false.
lSkipScaFld=.false.
lSkipFldHead=.false.
lStopThread=.false.
lDiffField=.false.
lDiffRel=.false.
lSingleFldPoint=.false.
call setNameExt(ProFileName,'FLD',FldFileName)
call setNameExt(ProFileName,'FLF',FlfFileName)
call setNameExt(ProFileName,'FLT',FltFileName)
call setNameExt(ProFileName,'PFD',PFDFileName)
call setNameExt(ProFileName,'GRF',GrfFileName)
call setNameExt(ProFileName,'GRT',GrtFileName)
! Grid definition Formula
Grd_Form(1)='add(-1,mul(2,div(sub(x,1),max(1,sub(p1,1)))))'C
Grd_Form(2)='add(-1,mul(2,div(sub(y,1),max(1,sub(p2,1)))))'C
Grd_Form(3)='add(0,mul(2,div(sub(z,1),max(1,sub(p3,1)))))'C
Grd_Def_Form(0,1:3)=Grd_Form(1:3)
Grd_Def_Form(1,1:3)=Grd_Form(1:3)
Grd_Def_Form(2,1)='mul(div(sub(x,1),max(1,sub(p1,1))),com(2,mul(c1,div(sub(y,1),sub(p2,1)))))'C
Grd_Def_Form(2,2)='mul(div(sub(x,1),max(1,sub(p1,1))),sim(2,mul(c1,div(sub(y,1),sub(p2,1)))))'C
Grd_Def_Form(2,3)='div(sub(z,1),max(1,sub(p3,1)))'C
Grd_Def_Form(3,1:3)='function'C
! Conformal mapping Formula
Con_Form='div(add(mul(p0,v),p1),add(mul(p2,v),p3))'C
Con_Def_Form(0)=Con_Form
Con_Def_Form(1)=Con_Form
Con_Def_Form(2)='log(v)'C
Con_Def_Form(3)='exp(v)'C
! 3D Grid transform Formula
Trns_Form(1)='add(x,mul(0.2,com(c1,x)))'C
Trns_Form(2)='add(y,mul(0.2,com(c1,y)))'C
Trns_Form(3)='z'C
Trns_Def_Form(0,1:3)=Trns_Form(1:3)
Trns_Def_Form(1,1:3)=Trns_Form(1:3)
Trns_Def_Form(2,1)='mul(x,p0)'C
Trns_Def_Form(2,2)='mul(y,p0)'C
Trns_Def_Form(2,3)='mul(z,p0)'C
Trns_Def_Form(2,1)='add(x,p1)'C
Trns_Def_Form(2,2)='add(y,p2)'C
Trns_Def_Form(2,3)='add(z,p3)'C
! Field definition Formula
idFld=0
iFFldE=1 ! auxiliary for the FField dialog
lExpFFD=.true. ! use expansions instead of formulae
lExcFFD=.false.! get MMP field including excitation
kExpFFD=0 ! use all expansions
kColFFD=0 ! with any color
kConFFD=0 ! in any connection
kDomFFD=0 ! in any domain
kParFFD=0 ! all parameters
LIQ=.false. ! always compute abbreviations
Q_Form(1,1)='inv(sub(log(0.25),log(0.95)))'C
Q_Form(2,1)='neg(mul(q1,log(0.95)))'C
Q_Form(3,1)='srt(add(sqr(x),sqr(y)))'C
Q_Form(4,1)=' 'C
Fld_Form(1:3,1:4)='0'C
Fld_Def_Form(0,1:3,1:4)=Fld_Form(1:3,1:4)
Fld_Def_Form(1,1:3,1:4)=Fld_Form(1:3,1:4)
Fld_Def_Form(2,1:3,1:4)='0'C
Fld_Def_Form(2,1,1)='neg(mul(q1,div(x,sqr(q3))))'C
Fld_Def_Form(2,2,1)='neg(mul(q1,div(y,sqr(q3))))'C
Fld_Def_Form(2,3,1)='0'C
Fld_Def_Form(2,1,3)='x'C
Fld_Def_Form(2,2,3)='y'C
Fld_Def_Form(2,3,3)='z'C
Fld_Def_Form(2,1,4)='add(mul(q1,log(q3)),q2)'C
Fld_Def_Form(3,1,1:4)='p0'C
Fld_Def_Form(3,2,1:4)='p6'C
Fld_Def_Form(3,3,1:4)='p7'C
! Field transformation Formula
iQFFD=1
literE=.true.
nIterPFD=10
dtrFld=1.d-10
Q_Form(5,2)='mul(mul(dx+,dx-),mul(dy+,dy-))'C
Q_Form(6,2)='add(mul(dx+,dx-),mul(dy+,dy-))'C
Q_Form(7,2)='div(q5,q6)'C
Q_Form(8,2)='mul(mul(dx+,dx-),add(dx+,dx-))'C
Q_Form(9,2)='mul(mul(dy+,dy-),add(dy+,dy-))'C
Q_Form(10,2)='add(inv(mul(dx+,dx-)),inv(mul(dy+,dy-)))'C
Q_Form(11,2)='inv(mul(dx+,add(dx+,dx-)))'C
Q_Form(12,2)='inv(mul(dy+,add(dy+,dy-)))'C
Q_Form(13,2)='inv(mul(dx-,add(dx+,dx-)))'C
Q_Form(14,2)='inv(mul(dy-,add(dy+,dy-)))'C
Q_Form(15,2)='sub(p6,mul(p8,dt))'C
Q_Form(16,2)='inv(add(p6,mul(p8,dt)))'C
Q_Form(17,2)='inv(p7)'C
Q_Form(18,2)='div(mul(2,dt),dx)'C
Q_Form(19,2)='div(mul(2,dt),dy)'C
Q_Form(20,2)='div(mul(2,dt),dz)'C
Q_Def_Form(0,1:20)=Q_Form(1:20,2)
Q_Def_Form(1,1:20)=Q_Form(1:20,2)
Q_Def_Form(2,1:20)=Q_Form(1:20,2)
Q_Def_Form(3,1:20)=Q_Form(1:20,2)
! Constants
pCForm(0:11)=DCmplx(1.0d0,0.0d0)
cForm(0)=1.0d0
cForm(1)=Pi
cForm(2)=Eps0
cForm(3)=Mue0
cForm(4)=Kw0
cForm(5)=Zw0
c678(1:3,1:3)=1.0d0
cForm(6:8)=c678(1:3,1)
cCForm=DCmplx(cForm,0.0d0)
cCForm(0)=(0.0d0,1.0d0)
! complex field
spacecFld(1,0)=-1.0d0 ! space occupied by the field: origin,x-tangent,y-tangent,z-tangent
spacecFld(2,0)=-1.0d0
spacecFld(3,0)=0.0d0
spacecFld(1,1)=2.0d0
spacecFld(2,1)=0.0d0
spacecFld(3,1)=0.0d0
spacecFld(1,2)=0.0d0
spacecFld(2,2)=2.0d0
spacecFld(3,2)=0.0d0
spacecFld(1,3)=0.0d0
spacecFld(2,3)=0.0d0
spacecFld(3,3)=2.0d0
lrGrd=.false. ! field on irregular grid
lxcFld=.true. ! x component is known
lycFld=.true. ! y component is known
lzcFld=.true. ! z component is known
lEcFld=.true. ! E field is known
lHcFld=.false. ! H field is unknown
lAcFld=.false. ! A field is unknown
lVcFld=.true. ! V field is known
iPlane=3 ! show the field in the xy(z=const) plane
nxcFld=11
nycFld=11
nzcFld=1
! real (derived) field
trFld=0.0d0 ! current time
prFld=0.0d0 ! current phase
itrFld=itV ! field type = V field
lxrFld=.true. ! show x components
lyrFld=.false.
lzrFld=.false.
larFld=.false. ! no average, i.e., time-dependent value
lprFld=.false. ! no phase, i.e., time-dependent value
rminFld=0.0d0 ! scaling limits
rmaxFld=1.0d0
rSumFld=0.0d0
rSum2Fld=0.0d0
ErrFld=0.0d0
Err2Fld=0.0d0
! View
viewPlane(1:3,0:3)=0.0d0 ! view plane = xy
viewPlane(1,1)=1.0d0
viewPlane(2,2)=1.0d0
viewPlane(3,3)=1.0d0
viewDist=1.0d10 ! view distance
nxrFld=nxcFld ! grid lines
nyrFld=nycFld
levPlane=1 ! level 1 of the grid
! Field representation
itIntensity=3 ! intensity type (iso lines etc.)
minCIntensity=16 ! color range
maxCIntensity=115
scaleIntensity=1.0d0 ! scaling
rIsoStep=0.1d0 ! step size of iso-lines
Grid3D=0.0d0 ! Max. grid dz
lGrid3D=.true. ! show Grid lines
lIsoFill=.true. ! show filled Iso lines
lIsoLine=.true. ! show Iso lines
itArrow=0 ! arrow type (don't show)
minCArrow=216 ! color range
maxCArrow=235
scaleArrow=10.0d0 ! arrow scaling
ArrowLength=0.1d0 ! max. length of the field arrows
nsFld=1 ! step for drawing arrows
lArrowFill=.true. ! show filled Arrows
PowerFld=1.0d0 ! power for derived field representation
FactorFld=1.0d0 ! scaling factor for derived field representation
! allocate memory and initialize field
if(.not.lgcFld) lGet3DMat=.true.
call AllocateGrd(ldum)
if(ldum) then
call AllocateIFld(ldum)
if(ldum) then
call AllocateFld(ldum)
if(ldum) then
call ClearGrid(.true.)
call ClearDomain(.true.)
call ClearField(.true.)
call GetrField(.false.)
end if
end if
end if
! PFD data
lPFDalloc=.false.
lPFDc=.false.
iPFDt=191_2 !159_2 ! PFD source type (soft, plane wave, E+H, X+Y+Z)
iPFDft=4_2 ! time function type: exp pulse
nPFDi=41_2 ! grid lines in i direction
nPFDj=41_2
nPFDk=41_2
nPFDil=5_2 ! PML layers low side of i direction
nPFDih=5_2
nPFDjl=5_2
nPFDjh=5_2
nPFDkl=5_2
nPFDkh=5_2
nPFDsLayers=0_2
nPFDiEff=2_2 ! effective material parameter computation type
nPFDcFld=0_4 ! Fourier integral additions performed
PFDxmin=-1.0 ! PDF array limits
PFDxmax=1.0
PFDymin=-1.0
PFDymax=1.0
PFDzmin=-1.0
PFDzmax=1.0
PFDdx=(PFDxmax-PFDxmin)/Dble(max(1,nPFDi-1))
PFDdy=(PFDymax-PFDymin)/Dble(max(1,nPFDj-1))
PFDdz=(PFDzmax-PFDzmin)/Dble(max(1,nPFDk-1))
PFDfTau=1.0d-9
PFDfTmax=3.0d-9
PFDpml=-0.33
PFDfmin=1.0d6 ! frequency range for DFT
PFDfmax=1.0d8
PFDwfact=0.0d0 ! stopping criterion
PFDdfact=3.0d0
PFDwmax=0.0d0
nPFDsource=1
kPFDsource=1
call AllocatePFDsource(ldum) ! PFD point sources
nPFDsens=1
kPFDsens=1
nPFDf=1 ! Frequency points for DFT
call AllocatePFDsens(ldum) ! PFD sensors
call Cursor(.false.,IDC_WAIT)
end Subroutine Field_Defaults
! threads
Subroutine TClrDom(lCheck)
Implicit none
Include 'resource.fd'
Logical(4), intent(in) :: lCheck
call WaitEndThread()
iThreadAction=1_4
call StartMAXThread(lCheck)
end Subroutine TClrDom
Subroutine TClrGrd(lCheck)
Implicit none
Include 'resource.fd'
Logical(4), intent(in) :: lCheck
call WaitEndThread()
iThreadAction=2_4
call StartMAXThread(lCheck)
end Subroutine TClrGrd
Subroutine TClrFld(lCheck)
Implicit none
Include 'resource.fd'
Logical(4), intent(in) :: lCheck
call WaitEndThread()
iThreadAction=3_4
call StartMAXThread(lCheck)
end Subroutine TClrFld
Subroutine TTransGrd(lCheck)
Implicit none
Include 'resource.fd'
Logical(4), intent(in) :: lCheck
call WaitEndThread()
iThreadAction=4_4
call StartMAXThread(lCheck)
end Subroutine TTransGrd
Subroutine TTransFld(lCheck)
Implicit none
Include 'resource.fd'
Logical(4), intent(in) :: lCheck
call WaitEndThread()
iThreadAction=5_4
call StartMAXThread(lCheck)
end Subroutine TTransFld
Subroutine TClrAll(lCheck)
Implicit none
Include 'resource.fd'
Logical(4), intent(in) :: lCheck
call WaitEndThread()
iThreadAction=6_4
call StartMAXThread(lCheck)
end Subroutine TClrAll
Subroutine StartMAXThread(ldi)
! start the MAX thread
Implicit none
Include 'resource.fd'
Integer(INT_PTR_KIND()) iThread
Integer(4), Save:: iArgument
Integer(4) iStack,iCreation,idum
Logical, intent(in) :: ldi
Logical(4) ldum
if(lThreadStarted) return
call OutTxt('t3','start MaX thread'C)
call OutTxt('n3',' 'C)
call OutTxt('m3',' 'C)
lThreadStarted=.true.
iStack=0
iArgument=0
iCreation=0
iThread=0
if(ldi) iArgument=1_4
if(iThreadHandle.ne.0) then
call OutTxt('t3','close thread handle'C)
ldum=CloseHandle(iThreadHandle)
if(.not.ldum) then
idum=MessageBoxQQ('Cannot close thread handle'C,'Start MaX thread'C, &
MB$OK.or.MB$ICONEXCLAMATION)
lThreadStarted=.false.
return
end if
iThreadHandle=0
endif
call OutTxt('t3','Start MaX thread'C)
iThreadHandle=CreateThread(NULL,iStack,Loc(MAXThread),Loc(iArgument),iCreation,iThread)
if(iThreadHandle.eq.0) then
idum=MessageBoxQQ('Cannot create thread'C,'Start MaX thread'C, &
MB$OK.or.MB$ICONEXCLAMATION)
lThreadStarted=.false.
end if
end Subroutine StartMAXThread
Integer(4) Function MAXThread(iWhat)
! MAX tread: calls.....
Implicit none
Include 'resource.fd'
Integer(4) iWhat
Logical ldum
lStopThread=.false.
ldum=.false.
if(iWhat.ne.0) ldum=.true.
MAXThread=0_4
if(.not.lgcFld) lGet3DMat=.true.
if(iThreadAction.eq.1) then
call ClearDomain(ldum)
else if(iThreadAction.eq.2) then
call ClearGrid(ldum)
else if(iThreadAction.eq.3) then
call ClearField(ldum)
else if(iThreadAction.eq.4) then
call TransformGrid(ldum)
else if(iThreadAction.eq.5) then
call TransformField(ldum)
else if(iThreadAction.eq.6) then
call ClearGrid(ldum)
call ClearDomain(ldum)
call ClearField(ldum)
call GetrField(.false.)
else
MAXThread=1_4
end if
call endThread()
end Function MAXThread
! I/O
Subroutine SaveFGrid(lCheck)
! save grid formula data in a file
Implicit none
Logical, intent(in) :: lCheck
Integer(4) iOk,ios,idum
if(.not.lCheck) then
call Open2write(-1,'Select grid formula file to be written!','Grid formula file ',GrfFileName,'GRF',ios)
if(ios.gt.0) return
end if
open(1,file=GrfFileName,iostat=ios)
if(ios.ne.0) then
idum=MessageBoxQQ('Error opening file!\rCannot save data!'C,'Save grid formula'C, &
MB$OK.or.MB$IconExclamation)
close(1)
return
end if
call WriteStr(1,CHGrfIdent,iOK)
rch(1:3)=c678(1:3,3)
call chwrit2(1,ich,0,rch,3,sch,0,iOK)
call WriteStr(1,Grd_Form(1),iOK)
call WriteStr(1,Grd_Form(2),iOK)
call WriteStr(1,Grd_Form(3),iOK)
sch(1:1)=' '
call chwrit2(1,ich,0,rch,0,sch,1,iOK)
EndFile(1)
close(1)
end Subroutine SaveFGrid
Subroutine OpenFGrid(lCheck)
! read grid formula data from a file
Implicit none
Logical, intent(in) :: lCheck
Logical lFileExist
Integer(4) iOk,ios,idum
Character(20) text
if(.not.lCheck) then
call Open2read(-1,'Select grid formula file to be read!','Grid formula file ',GrfFileName,'GRF',ios)
if(ios.gt.0) return
end if
inquire(file=GrfFileName,Exist=lFileExist)
if(.not.lFileExist) return
open(1,file=GrfFileName,status='old',iostat=ios)
if(ios.ne.0) then
if(.not.lCheck) idum=MessageBoxQQ('Error opening file!\rCannot read data!'C,'Open grid formula'C, &
MB$OK.or.MB$IconExclamation)
close(1)
return
end if
call ReadStr(1,text,iOK)
if(CHGrfIdent(1:18).ne.text(1:18)) then
idum=MessageBoxQQ('Wrong file Type!\rContinue reading?'C,'Open grid formula'C, &
MB$YesNo.or.MB$IconQuestion)
if(idum.eq.MB$IDNO) then
close(1)
return
end if
end if
call chread2(1,ich,0,rch,3,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(formula constants)'C,'Open grid formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
c678(1:3,3)=rch(1:3)
call ReadStr(1,Grd_Form(1),iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(grid formula 1)'C,'Open grid formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
call ReadStr(1,Grd_Form(2),iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(grid formula 2)'C,'Open grid formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
call ReadStr(1,Grd_Form(3),iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(grid formula 3)'C,'Open grid formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
close(1)
end Subroutine OpenFGrid
Subroutine SaveTGrid(lCheck)
! save grid transform formula data in a file
Implicit none
Logical, intent(in) :: lCheck
Integer(4) iOk,ios,idum
if(.not.lCheck) then
call Open2write(-1,'Select grid transform file to be written!','Grid transform file ',GrtFileName,'GRT',ios)
if(ios.gt.0) return
end if
open(1,file=GrtFileName,iostat=ios)
if(ios.ne.0) then
idum=MessageBoxQQ('Error opening file!\rCannot save data!'C,'Save grid transformation formula'C, &
MB$OK.or.MB$IconExclamation)
close(1)
return
end if
call WriteStr(1,CHGrtIdent,iOK)
rch(1)=Dble(pCForm(0))
rch(2)=DImag(pCForm(0))
call chwrit2(1,ich,0,rch,2,sch,0,iOK)
rch(1)=Dble(pCForm(1))
rch(2)=DImag(pCForm(1))
call chwrit2(1,ich,0,rch,2,sch,0,iOK)
rch(1)=Dble(pCForm(2))
rch(2)=DImag(pCForm(2))
call chwrit2(1,ich,0,rch,2,sch,0,iOK)
rch(1)=Dble(pCForm(3))
rch(2)=DImag(pCForm(3))
call chwrit2(1,ich,0,rch,2,sch,0,iOK)
call WriteStr(1,Con_Form,iOK)
rch(1:4)=pForm(0:3)
call chwrit2(1,ich,0,rch,4,sch,0,iOK)
call WriteStr(1,Trns_Form(1),iOK)
call WriteStr(1,Trns_Form(2),iOK)
call WriteStr(1,Trns_Form(3),iOK)
sch(1:1)=' '
call chwrit2(1,ich,0,rch,0,sch,1,iOK)
EndFile(1)
close(1)
end Subroutine SaveTGrid
Subroutine OpenTGrid(lCheck)
! read grid transform data from a file
Implicit none
Logical, intent(in) :: lCheck
Logical lFileExist
Integer(4) iOk,ios,i,idum
Character(20) text
if(.not.lCheck) then
call Open2read(-1,'Select grid transform file to be read!','Grid transform file ',GrtFileName,'GRT',ios)
if(ios.gt.0) return
end if
inquire(file=GrtFileName,Exist=lFileExist)
if(.not.lFileExist) return
open(1,file=GrtFileName,status='old',iostat=ios)
if(ios.ne.0) then
if(.not.lCheck) idum=MessageBoxQQ('Error opening file!\rCannot read data!'C,'Open grid transformation formula'C, &
MB$OK.or.MB$IconExclamation)
close(1)
return
end if
call ReadStr(1,text,iOK)
if(CHGrtIdent(1:18).ne.text(1:18)) then
idum=MessageBoxQQ('Wrong file Type!\rContinue reading?'C,'Open grid transformation formula'C, &
MB$YesNo.or.MB$IconQuestion)
if(idum.eq.MB$IDNO) then
close(1)
return
end if
end if
do i=0,3
call chread2(1,ich,0,rch,2,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(complex formula constants)'C,'Open grid transformation formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
pcForm(i)=DCmplx(rch(1),rch(2))
end do
call ReadStr(1,Con_Form,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(conformal mapping formula)'C,'Open grid transformation formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
call chread2(1,ich,0,rch,4,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(real formula constants)'C,'Open grid transformation formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
pForm(0:3)=rch(1:4)
call ReadStr(1,Trns_Form(1),iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(grid formula 1)'C,'Open grid transformation formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
call ReadStr(1,Trns_Form(2),iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(grid formula 2)'C,'Open grid transformation formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
call ReadStr(1,Trns_Form(3),iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(grid formula 3)'C,'Open grid transformation formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
close(1)
end Subroutine OpenTGrid
Subroutine SaveFField(lCheck)
! save field formula data in a file
Implicit none
Logical, intent(in) :: lCheck
Integer(4) iOk,ios,i,k,idum
if(.not.lCheck) then
call Open2write(-1,'Select field formula file to be written!','Field formula file ',FlfFileName,'FLF',ios)
if(ios.gt.0) return
end if
open(1,file=FlfFileName,iostat=ios)
if(ios.ne.0) then
idum=MessageBoxQQ('Error opening file!\rCannot save data!'C,'Save field formula'C, &
MB$OK.or.MB$IconExclamation)
close(1)
return
end if
call WriteStr(1,CHFlfIdent,iOK)
ich(1)=0
if(lExpFFD) ich(1)=1
if(lExcFFD) ich(1)=ich(1)+10
ich(2)=kExpFFD
ich(3)=0
if(LIQ) ich(3)=1
ich(4)=kColFFD
ich(5)=kConFFD
ich(6)=kDomFFD
ich(7)=kParFFD
call chwrit2(1,ich,7,rch,0,sch,0,iOK)
rch(1:3)=c678(1:3,1)
call chwrit2(1,ich,0,rch,3,sch,0,iOK)
call WriteStr(1,' abbreviations'C,iOK)
do i=1,20
call WriteStr(1,Q_Form(i,1),iOK)
end do
do k=1,4
if(k.eq.1) call WriteStr(1,' E-field'C,iOK)
if(k.eq.2) call WriteStr(1,' H-field'C,iOK)
if(k.eq.3) call WriteStr(1,' A-field'C,iOK)
if(k.eq.4) call WriteStr(1,' V-field'C,iOK)
do i=1,3
call WriteStr(1,Fld_Form(i,k),iOK)
end do
end do
sch(1:1)=' '
call chwrit2(1,ich,0,rch,0,sch,1,iOK)
EndFile(1)
close(1)
end Subroutine SaveFField
Subroutine OpenFField(lCheck)
! read field formula data from a file
Implicit none
Logical, intent(in) :: lCheck
Logical lFileExist
Integer(4) iOk,ios,i,k,iVers,iErr,idum
Character(20) text
if(.not.lCheck) then
call Open2read(-1,'Select field formula file to be read!','Field formula file ',FlfFileName,'FLF',ios)
if(ios.gt.0) return
end if
inquire(file=FlfFileName,Exist=lFileExist)
if(.not.lFileExist) return
open(1,file=FlfFileName,status='old',iostat=ios)
if(ios.ne.0) then
if(.not.lCheck) idum=MessageBoxQQ('Error opening file!\rCannot read data!'C,'Open field formula'C, &
MB$OK.or.MB$IconExclamation)
close(1)
return
end if
call ReadStr(1,text,iOK)
if(CHFlfIdent(1:14).ne.text(1:14)) then
idum=MessageBoxQQ('Wrong file Type!\rContinue reading?'C,'Open field formula'C, &
MB$YesNo.or.MB$IconQuestion)
if(idum.eq.MB$IDNO) then
close(1)
return
end if
end if
text(17:17)=text(18:18)
call StrToInt(text(16:17),iVers,iErr)
if(iErr.ne.0) iVers=0
if(iVers.gt.19) then
call chread2(1,ich,7,rch,0,iOK)
else if(iVers.gt.10) then
call chread2(1,ich,6,rch,0,iOK)
ich(7)=0
else
call chread2(1,ich,3,rch,0,iOK)
ich(4:7)=0
end if
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(logicals)'C,'Open field formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
lExcFFD=.false.
lExpFFD=.false.
if(ich(1).gt.9) then
lExcFFD=.true.
ich(1)=ich(1)-10
end if
if(ich(1).gt.0) lExpFFD=.true.
kExpFFD=ich(2)
LIQ=.false.
if(ich(3).gt.0) LIQ=.true.
kColFFD=ich(4)
kConFFD=ich(5)
kDomFFD=ich(6)
kParFFD=ich(7)
call chread2(1,ich,0,rch,3,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(formula constants)'C,'Open field formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
c678(1:3,1)=rch(1:3)
call ReadStr(1,text,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(dummy text)'C,'Open field formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
do i=1,20
call ReadStr(1,Q_Form(i,1),iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(abbreviations)'C,'Open field formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
end do
do k=1,4
call ReadStr(1,text,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(dummy text)'C,'Open field formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
do i=1,3
call ReadStr(1,Fld_Form(i,k),iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(field formula)'C,'Open field formula'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
end do
end do
close(1)
end Subroutine OpenFField
Subroutine SavePFD(lCheck)
! save FDTD data in a file
Implicit none
Logical, intent(in) :: lCheck
Integer(4) iOk,ios,k,idum
if(.not.lCheck) then
call Open2write(-1,'Select FDTD file to be written!','Field transform file ',PFDFileName,'PFD',ios)
if(ios.gt.0) return
end if
open(1,file=PFDFileName,iostat=ios)
if(ios.ne.0) then
idum=MessageBoxQQ('Error opening file!\rCannot save data!'C,'Save FDTD data'C, &
MB$OK.or.MB$IconExclamation)
close(1)
return
end if
call WriteStr(1,CHPFDIdent,iOK)
ich(1)=nIterPFD
rch(1)=dtrFld
sch(1:8)=' iter,dt'
call chwrit2(1,ich,1,rch,1,sch,8,iOK)
ich(1)=nPFDi
ich(2)=nPFDj
ich(3)=nPFDk
sch(1:6)=' i,j,k'
call chwrit2(1,ich,3,rch,0,sch,6,iOK)
rch(1)=PFDxmin
rch(2)=PFDxmax
call chwrit2(1,ich,0,rch,2,sch,0,iOK)
rch(1)=PFDymin
rch(2)=PFDymax
call chwrit2(1,ich,0,rch,2,sch,0,iOK)
rch(1)=PFDzmin
rch(2)=PFDzmax
call chwrit2(1,ich,0,rch,2,sch,0,iOK)
ich(1)=nPFDil
ich(2)=nPFDih
ich(3)=nPFDjl
ich(4)=nPFDjh
ich(5)=nPFDkl
ich(6)=nPFDkh
rch(1)=PFDpml
call chwrit2(1,ich,6,rch,1,sch,0,iOK)
ich(1)=iPFDt
ich(2)=iPFDft
rch(1)=PFDfTmax
rch(2)=PFDfTau
call chwrit2(1,ich,2,rch,2,sch,0,iOK)
ich(1)=nPFDsource
call chwrit2(1,ich,1,rch,0,sch,0,iOK)
do k=1,nPFDsource
rch(1)=Dble(PFDsourceA(k))
rch(2)=DImag(PFDsourceA(k))
ich(1)=iPFDs(k)
ich(2)=jPFDs(k)
ich(3)=kPFDs(k)
call chwrit2(1,ich,3,rch,2,sch,0,iOK)
end do
ich(1)=nPFDf
rch(1)=PFDfmin
rch(2)=PFDfmax
call chwrit2(1,ich,1,rch,2,sch,0,iOK)
ich(1)=nPFDsens
call chwrit2(1,ich,1,rch,0,sch,0,iOK)
do k=1,nPFDsens
rch(1)=PFDsensX(k)
rch(2)=PFDsensY(k)
rch(3)=PFDsensZ(k)
rch(4)=PFDsensT(k)
rch(5)=PFDsensD(k)
call chwrit2(1,ich,0,rch,5,sch,0,iOK)
end do
ich(1)=nPFDiEff
call chwrit2(1,ich,1,rch,0,sch,0,iOK)
ich(1)=nPFDsLayers
call chwrit2(1,ich,1,rch,0,sch,0,iOK)
sch(1:1)=' '
call chwrit2(1,ich,0,rch,0,sch,1,iOK)
EndFile(1)
close(1)
end Subroutine SavePFD
Subroutine OpenPFD(lCheck)
! read FDTD data from a file
Implicit none
Logical, intent(in) :: lCheck
Logical lFileExist,ldum
Integer(4) iOk,ios,k,idum
Character(20) text
if(.not.lCheck) then
call Open2read(-1,'Select FDTD file to be read!','Field transform file ',PFDFileName,'PFD',ios)
if(ios.gt.0) return
end if
inquire(file=PFDFileName,Exist=lFileExist)
if(.not.lFileExist) then ! try reading PFD data from FLT file (created by MaX-1)
call setNameExt(PFDFileName,'FLT',FltFileName)
call OpenTField(lCheck)
return
end if
open(1,file=PFDFileName,status='old',iostat=ios)
if(ios.ne.0) then
if(.not.lCheck) idum=MessageBoxQQ('Error opening file!\rCannot read data!'C,'Open FDTD data'C, &
MB$OK.or.MB$IconExclamation)
close(1)
return
end if
call ReadStr(1,text,iOK)
if(CHPFDIdent(1:15).ne.text(1:15)) then
idum=MessageBoxQQ('Wrong file Type!\rContinue reading?'C,'Open FDTD data'C, &
MB$YesNo.or.MB$IconQuestion)
if(idum.eq.MB$IDNO) then
close(1)
return
end if
end if
call chread2(1,ich,1,rch,1,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(iterations)'C,'Open FDTD data'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
nIterPFD=ich(1)
dtrFld=rch(1)
call chread2(1,ich,3,rch,0,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(PFD grid lines)'C,'Open FDTD data'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
nPFDi=ich(1)
nPFDj=ich(2)
nPFDk=ich(3)
call chread2(1,ich,0,rch,2,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(PFD x limits)'C,'Open FDTD data'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
PFDxmin=rch(1)
PFDxmax=rch(2)
call chread2(1,ich,0,rch,2,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(PFD y limits)'C,'Open FDTD data'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
PFDymin=rch(1)
PFDymax=rch(2)
call chread2(1,ich,0,rch,2,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(PFD z limits)'C,'Open FDTD data'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
PFDzmin=rch(1)
PFDzmax=rch(2)
PFDdx=(PFDxmax-PFDxmin)/Dble(max(1,nPFDi-1))
PFDdy=(PFDymax-PFDymin)/Dble(max(1,nPFDj-1))
PFDdz=(PFDzmax-PFDzmin)/Dble(max(1,nPFDk-1))
call chread2(1,ich,6,rch,1,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(PFD UPML)'C,'Open FDTD data'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
nPFDil=ich(1)
nPFDih=ich(2)
nPFDjl=ich(3)
nPFDjh=ich(4)
nPFDkl=ich(5)
nPFDkh=ich(6)
PFDpml=rch(1)
call chread2(1,ich,2,rch,2,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(PFD source)'C,'Open FDTD data'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
iPFDt=ich(1)
iPFDft=ich(2)
PFDfTmax=rch(1)
PFDfTau=rch(2)
call chread2(1,ich,1,rch,0,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(PFD sources)'C,'Open FDTD data'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
nPFDsource=max(1,ich(1))
call AllocatePFDsource(ldum)
do k=1,ich(1)
call chread2(1,ich,3,rch,2,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(PFD sources)'C,'Open FDTD data'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
PFDsourceA(k)=DCmplx(rch(1),rch(2))
iPFDs(k)=ich(1)
jPFDs(k)=ich(2)
kPFDs(k)=ich(3)
end do
call chread2(1,ich,1,rch,2,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(PFD DFT)'C,'Open FDTD data'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
nPFDf=max(1,ich(1))
PFDfmin=rch(1)
PFDfmax=rch(2)
call chread2(1,ich,1,rch,0,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(PFD sensors)'C,'Open FDTD data'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
nPFDsens=max(1,ich(1))
call AllocatePFDsens(ldum)
do k=1,ich(1)
call chread2(1,ich,0,rch,5,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(PFD sensors)'C,'Open FDTD data'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return