-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchformod.f90
2610 lines (2562 loc) · 73.5 KB
/
chformod.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 CHFOR
USE CHWIN
SAVE
CONTAINS
Subroutine GetFormulaParts(s,s1,s2,l1,l2)
Implicit none
Integer(4) lf,l,l1,l2
Character(*) s
Character(1151) s1,s2
lf=-1
call DelBlanks(s,lf)
l1=1
l2=1
do l=2,lf
if(s(l:l).eq.'/') Exit
s1(l1:l1)=s(l:l)
l1=l1+1
end do
s1(l1:l1)=char(0)
do l=l1+2,lf
if(s.eq.'/') Exit
s2(l2:l2)=s(l:l)
l2=l2+1
end do
s2(l2:l2)=char(0)
l1=l1-1
l2=l2-1
end Subroutine GetFormulaParts
Subroutine CheckFormula(s,lf,nc,np,nv,iErr)
! check the formula string s
Implicit none
Integer(4) nc,np,nv,iErr,lf,l1,l2,i1,i2
Character(*) s
Character(1151) s1,s2
pForm=1.0d0
vForm=1.0d0
if(s(1:1).eq.'/') then ! two formulae packed in one string with "/" delimiters!
iErr=0
call GetFormulaParts(s,s1,s2,l1,l2)
lf=l1+l2
call checkFormula1(s1,l1,nc,np,nv,i1)
if(i1.ne.0) then
iErr=1
s(1:1)='!'
end if
call checkFormula1(s2,l2,nc,np,nv,i2)
if(i1.ne.0) then
iErr=iErr+2
s(l1+2:l1+2)='!'
end if
else
lf=-1
dFormu=Formula(s,lf,cForm,pForm,vForm,nc,np,nv,1,1,1,iErr)
end if
end Subroutine CheckFormula
Subroutine CheckFormula1(s,lf,nc,np,nv,iErr)
! check the formula string s
Implicit none
Integer(4) nc,np,nv,iErr,lf
Character(*) s
pForm=1.0d0
vForm=1.0d0
if(s(1:1).eq.'/') return ! more than two formulae packed in one string with "/" delimiters!
lf=-1
dFormu=Formula(s,lf,cForm,pForm,vForm,nc,np,nv,1,1,1,iErr)
end Subroutine CheckFormula1
recursive Subroutine CheckCFormula(s,lf,nc,np,nv,iErr)
! check the formula string s of a complex formula
Implicit none
Integer(4) nc,np,nv,iErr,lf,l1,l2,i1,i2
Character(*) s
Character(1151) s1,s2
vCForm=DCmplx(1.0d0,0.0d0)
if(s(1:1).eq.'/') then ! two formulae packed in one string with "/" delimiters!
iErr=0
call GetFormulaParts(s,s1,s2,l1,l2)
lf=l1+l2
call checkCFormula1(s1,l1,nc,np,nv,i1)
if(i1.ne.0) then
iErr=1
s(1:1)='!'
end if
call checkCFormula1(s2,l2,nc,np,nv,i2)
if(i1.ne.0) then
iErr=iErr+2
s(l1+2:l1+2)='!'
end if
else
lf=-1
cFormu=CFormula(s,lf,cCForm,pCForm,vCForm,nc,np,nv,1,1,1,iErr)
end if
end Subroutine CheckCFormula
Subroutine CheckCFormula1(s,lf,nc,np,nv,iErr)
! check the formula string s of a complex formula
Implicit none
Integer(4) nc,np,nv,iErr,lf
Character(*) s
vCForm=DCmplx(1.0d0,0.0d0)
if(s(1:1).eq.'/') return ! more than two formulae packed in one string with "/" delimiters!
lf=-1
cFormu=CFormula(s,lf,cCForm,pCForm,vCForm,nc,np,nv,1,1,1,iErr)
end Subroutine CheckCFormula1
Function Formula(sFor,lFor,Cns,Par,Var,mC,mP,mV,nx,ny,nz,iErr,vArr,nArrOi,iArrVarOi,nArrVi) Result(aRes)
Implicit none
Integer(4) lFor,mC,mP,mV,nx,ny,nz,iErr,lf,nArr,nArrV,iArrVar,i
Integer(4), Optional :: nArrOi,nArrVi,iArrVarOi
Real(8) Cns(0:mC),Par(0:mP),Var(-10:mV)
Real(8), Optional :: vArr(mForA)
Real(8) aRes(mForA)
Logical l4in
Character(*) sFor
nArrV=1
nArr=1
iArrVar=1
if(Present(nArrVi)) nArrV=nArrVi
if(Present(nArrOi)) nArr=max(min(mForA/nArrV,nArrOi),1)
if(Present(iArrVarOi)) iArrVar=max(min(min(iArrVarOi,nArr),mV),-10)
if(sFor(1:1).eq.'!') then
aRes(1:nArr)=0.0d0
iErr=0
else
l4in=l4
l4=.false.
if(Present(vArr)) then
aRes(1:nArr)=Formul(sFor,lFor,Cns,Par,Var,mC,mP,mV,nx,ny,nz,iErr,vArr,nArr,iArrVar,nArrV)
else
aRes(1:nArr)=Formul(sFor,lFor,Cns,Par,Var,mC,mP,mV,nx,ny,nz,iErr)
end if
l4=l4in
if(iErr.ne.0) then
lf=-1
call DelBlanks(sFor,lf)
if(lf.ne.lFor) then
if(l4) write(*,*) 'String length error lf, lFor=',lf,lFor
end if
if(l4) write(*,*) 'Error in string X',sFor(1:lFor),'X'
if(l4) write(*,*) ' '
lFor=-1
if(Present(vArr)) then
aRes(1:nArr)=Formul(sFor,lFor,Cns,Par,Var,mC,mP,mV,nx,ny,nz,iErr,vArr,nArr,iArrVar,nArrV)
else
aRes(1:nArr)=Formul(sFor,lFor,Cns,Par,Var,mC,mP,mV,nx,ny,nz,iErr)
end if
end if
if(iErr.ne.0) then
aRes(1:nArr)=0.0d0
lFor=Min(lFor+1,1150)
do i=lFor,2,-1
sFor(i:i)=sFor(i-1:i-1)
end do
sFor(1:1)='!'
end if
end if
end Function Formula
Function CFormula(sFor,lFor,Cns,Par,Var,mC,mP,mV,nx,ny,nz,iErr,vArr,nArrOi,iArrVarOi,nArrVi) Result(aRes)
Implicit none
Integer(4) lFor,mC,mP,mV,nx,ny,nz,iErr,nArr,nArrV,iArrVar,i
Integer(4), Optional :: nArrOi,nArrVi,iArrVarOi
Complex(8) Cns(0:mC),Par(0:mP),Var(-10:mV)
Complex(8), Optional :: vArr(mForA)
Complex(8) aRes(mForA)
Character(*) sFor
nArrV=1
nArr=1
iArrVar=1
if(Present(nArrVi)) nArrV=nArrVi
if(Present(nArrOi)) nArr=max(min(mForA/nArrV,nArrOi),1)
if(Present(iArrVarOi)) iArrVar=max(min(min(iArrVarOi,nArr),mV),-10)
if(sFor(1:1).eq.'!') then
aRes(1:nArr)=(0.0d0,0.0d0)
iErr=0
else
if(Present(vArr)) then
aRes(1:nArr)=CFormul(sFor,lFor,Cns,Par,Var,mC,mP,mV,nx,ny,nz,iErr,vArr,nArr,iArrVar,nArrV)
else
aRes(1:nArr)=CFormul(sFor,lFor,Cns,Par,Var,mC,mP,mV,nx,ny,nz,iErr)
end if
if(iErr.ne.0) then
aRes(1:nArr)=(0.0d0,0.0d0)
lFor=Min(lFor+1,1150)
do i=lFor,2,-1
sFor(i:i)=sFor(i-1:i-1)
end do
sFor(1:1)='!'
end if
end if
end Function CFormula
Recursive Function Formul(sFor,lFor,Cns,Par,Var,mC,mP,mV,nx,ny,nz,iErr,vArr,nArrOi,iArrVarOi,nArrVi) Result(aRes)
Implicit none
Integer(4) mC,mP,mV,nx,ny,nz,iErr,i,k,nn1,lArg,lo,lArgs,lFor,nArrV,nArr,iArrVar,ls,li,nForA,nnz,iEr,ir,k0,ixyz, &
& ia,ib,ic
Complex(8) cwrk(1),cb(1)
Real(8) Val(mForA,mForA),Cns(0:mC),Par(0:mP),Var(-10:mV),aRes(mForA),r,r1,r2
Real(8), Optional :: vArr(mForA)
Real(8) Rando
Integer(4), Optional :: nArrOi,nArrVi,iArrVarOi
Logical lArr
Character(*) sFor
Character(1151) s,sArgs,sArg
Character(5) sPot
Character(4) sFkt
Character(1) sB
Integer(4) i1Rnd
Data i1Rnd/0_4/
nArrV=1
nArr=1
iArrVar=1
if(Present(nArrVi)) nArrV=nArrVi
if(Present(nArrOi)) nArr=max(min(mForA/nArrV,nArrOi),1)
if(Present(iArrVarOi)) iArrVar=max(min(min(iArrVarOi,nArr),mV),-10)
lArr=.false.
if(Present(vArr)) lArr=.true.
! default result
iErr=0
aRes(1:nArr)=0.0_8
if(lFor.gt.1150) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: string too long! max.length=',1150
if(l4) write(*,*) 'original string=',sFor
if(l4) write(*,*) 'lFor=',lFor
end if
iErr=1
return
end if
! prepare string
if(lFor.lt.1) then
call DelBlanks(sFor,lFor)
call ToLower(sFor,lFor)
end if
if(lFor.lt.1) return
ls=lFor
s(1:lFor)=sFor(1:lFor)
s(lFor+1:lFor+1)=Char(0)
! check if function or value
if(lFor.gt.4) then
sB(1:1)=sFor(4:4)
else
sB(1:1)='v'
end if
if(sB(1:1).eq.'(') then
! functions: determine Type and argument string, compute
sFkt(1:3)=sFor(1:3)
lArgs=lFor-5
sArgs(1:lArgs)=sFor(5:lFor-1)
sArgs(lArgs+1:lArgs+1)=char(0)
if(lArgs.lt.1) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: No argument found!'
if(l4) write(*,*) 'argument string=',sArgs(1:lArgs)
end if
iErr=1
return
end if
! user-defined operators
if(sFkt(1:1).eq.'u') then
call StrToInt(sFkt(2:3),kUserForm,iErr) ! get number of operator
if((kUserForm.gt.nUserForm).or.(kUserForm.lt.0)) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: user-defined formula not defined!'
if(l4) write(*,*) 'formula number=',kUserForm
end if
iErr=3
return
end if
if(lUserForm(kUserForm).lt.1) then
call DelBlanks(sUserForm(kUserForm),lUserForm(kUserForm))
call ToLower(sUserForm(kUserForm),lUserForm(kUserForm))
end if
lo=0 ! insert argument strings in the operator string
do li=1,lUserForm(kUserForm)
if(sUserForm(kUserForm)(li:li).eq.'?') then ! insert argument string
call GetArg1(sArgs,lArgs,sArg,lArg,iErr)
if(iErr.ne.0) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: GetArg1 returned error!'
if(l4) write(*,*) 'current argument string=',lArgs,sArgs(1:lArgs)
if(l4) write(*,*) 'original string=',lFor,'X',sFor(1:lFor),'X'
end if
iErr=1
return
end if
lo=lo+lArg
if(lo.gt.1150) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: user-defined formula too long!'
if(l4) write(*,*) 'formula string=',sUserForm(kUserForm)(1:lUserForm(kUserForm))
end if
iErr=3
return
end if
sUserFor(lo-lArg+1:lo)=sArg(1:lArg)
else
lo=lo+1 ! copy character
if(lo.gt.1150) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: user-defined formula too long!'
if(l4) write(*,*) 'formula string=',sUserForm(kUserForm)(1:lUserForm(kUserForm))
end if
iErr=3
return
end if
sUserFor(lo:lo)=sUserForm(kUserForm)(li:li)
end if
end do
lUserFor=lo ! evaluate operator
if(lArr) then
aRes=Formul(sUserFor,lUserFor,Cns,Par,Var,mC,mP,mV,nx,ny,nz,iErr,vArr,nArr,iArrVar,nArrV)
else
aRes=Formul(sUserFor,lUserFor,Cns,Par,Var,mC,mP,mV,nx,ny,nz,iErr)
end if
return
end if
! get all arguments of the formula and evaluate them -> Val
do i=1,mForA
Val(1:nArr,i)=0.0d0
call GetArg1(sArgs,lArgs,sArg,lArg,iErr)
if(iErr.ne.0) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: GetArg1 returned error!'
if(l4) write(*,*) 'current argument string=',lArgs,sArgs(1:lArgs)
if(l4) write(*,*) 'current argument number=',i
if(l4) write(*,*) 'original string=',lFor,'X',sFor(1:lFor),'X'
end if
iErr=1
return
end if
if(lArr) then
Val(1:nArr,i)=Formul(sArg,lArg,Cns,Par,Var,mC,mP,mV,nx,ny,nz,iErr,vArr,nArr,iArrVar,nArrV)
else
Val(1:nArr,i)=Formul(sArg,lArg,Cns,Par,Var,mC,mP,mV,nx,ny,nz,iErr)
end if
if(iErr.ne.0) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: Formula returned error!'
if(l4) write(*,*) 'current argument string=',lArgs,sArgs(1:lArgs)
if(l4) write(*,*) 'current argument number=',i
if(l4) write(*,*) 'original string=',lFor,sFor(1:lFor)
end if
iErr=1
return
end if
if(lArgs.eq.0) then
nForA=i
Exit
end if
end do
nn1=1_4
Select Case(sFkt(1:3))
! Cases with one argument
Case('abs')
do k=1,nArr
aRes(k)=dabs(Val(k,1))
end do
Case('acs')
do k=1,nArr
aRes(k)=dacos(Val(k,1))
end do
Case('asn')
do k=1,nArr
aRes(k)=dasin(Val(k,1))
end do
Case('atg')
do k=1,nArr
aRes(k)=datan(Val(k,1))
end do
Case('neg')
do k=1,nArr
aRes(k)=-Val(k,1)
end do
Case('inv')
do k=1,nArr
aRes(k)=.inv.Val(k,1)
end do
Case('sgn')
do k=1,nArr
aRes(k)=1.0_8
if(Val(k,1).lt.0.0_8) aRes(k)=-1.0_8
end do
Case('int')
do k=1,nArr
aRes(k)=.int.Val(k,1)
end do
Case('sqr')
do k=1,nArr
aRes(k)=Val(k,1).mul.Val(k,1)
end do
Case('srt')
do k=1,nArr
aRes(k)=.srt.Val(k,1)
end do
Case('log')
do k=1,nArr
aRes(k)=.log.Val(k,1)
end do
Case('exp')
do k=1,nArr
aRes(k)=.exp.Val(k,1)
end do
Case('sin')
do k=1,nArr
aRes(k)=.sin.Val(k,1)
end do
Case('cos')
do k=1,nArr
aRes(k)=.cos.Val(k,1)
end do
Case('tan')
do k=1,nArr
aRes(k)=dtan(Val(k,1))
end do
Case('ctg')
do k=1,nArr
aRes(k)=dcotan(Val(k,1))
end do
Case('csh')
do k=1,nArr
aRes(k)=dcosh(Val(k,1))
end do
Case('snh')
do k=1,nArr
aRes(k)=dsinh(Val(k,1))
end do
Case('tnh')
do k=1,nArr
aRes(k)=dtanh(Val(k,1))
end do
! Cases with two arguments
Case('at2')
do k=1,nArr
aRes(k)=datan2(Val(k,1),Val(k,2))
end do
Case('bit')
do k=1,nArr
if(BTEST(nint(Val(k,1),4),min(31,max(0,nint(Val(k,2),4)-1_4)))) then
aRes(k)=1.0d0
else
aRes(k)=0.0d0
end if
end do
Case('ran')
Rando=CHrnd(0.0d0,1.0d0,0_4)
do k=1,nArr
Rando=CHrnd(Val(k,1),Val(k,2))
aRes(k)=Rando
end do
Case('rnd')
if(i1Rnd.eq.0) then
Rando=CHrnd(0.0d0,1.0d0,0_4)
i1Rnd=1_4
end if
do k=1,nArr
Rando=CHrnd(Val(k,1),Val(k,2))
aRes(k)=Rando
end do
Case('sub')
do k=1,nArr
aRes(k)=Val(k,1).sub.Val(k,2)
end do
Case('div')
do k=1,nArr
aRes(k)=Val(k,1).div.Val(k,2)
end do
Case('pow')
do k=1,nArr
aRes(k)=Val(k,1).pow.Val(k,2)
end do
Case('lga')
do k=1,nArr
aRes(k)=(.log.Val(k,2)).div.(.log.Val(k,1))
end do
Case('ta1')
do k=1,nArr
aRes(k)=Val(k,1)
end do
Case('ta2')
do k=1,nArr
aRes(k)=Val(k,2)
end do
Case('zii')
do k=1,nArr
call zir(abs(Val(k,1)),DCmplx(Val(k,2),0.0d0),nn1,.false.,cb(1),nnz,ier)
aRes(k)=Dimag(cb(1))
end do
Case('zji')
do k=1,nArr
call zjr(abs(Val(k,1)),DCmplx(Val(k,2),0.0d0),nn1,.false.,cb(1),nnz,ier)
aRes(k)=Dimag(cb(1))
end do
Case('zki')
do k=1,nArr
call zkr(abs(Val(k,1)),DCmplx(Val(k,2),0.0d0),nn1,.false.,cb(1),nnz,ier)
aRes(k)=Dimag(cb(1))
end do
Case('zhi')
do k=1,nArr
call zhr(nn1,abs(Val(k,1)),DCmplx(Val(k,2),0.0d0),nn1,.false.,cb(1),nnz,ier)
aRes(k)=Dimag(cb(1))
end do
Case('zyi')
do k=1,nArr
call zyr(abs(Val(k,1)),DCmplx(Val(k,2),0.0d0),nn1,.false.,cb(1),nnz,cwrk(1),ier)
aRes(k)=Dimag(cb(1))
end do
Case('zir')
do k=1,nArr
call zir(abs(Val(k,1)),DCmplx(Val(k,2),0.0d0),nn1,.false.,cb(1),nnz,ier)
aRes(k)=Dble(cb(1))
end do
Case('zjr')
do k=1,nArr
call zjr(abs(Val(k,1)),DCmplx(Val(k,2),0.0d0),nn1,.false.,cb(1),nnz,ier)
aRes(k)=Dble(cb(1))
end do
Case('zkr')
do k=1,nArr
call zkr(abs(Val(k,1)),DCmplx(Val(k,2),0.0d0),nn1,.false.,cb(1),nnz,ier)
aRes(k)=Dble(cb(1))
end do
Case('zhr')
do k=1,nArr
call zhr(nn1,abs(Val(k,1)),DCmplx(Val(k,2),0.0d0),nn1,.false.,cb(1),nnz,ier)
aRes(k)=Dble(cb(1))
end do
Case('zyr')
do k=1,nArr
call zyr(abs(Val(k,1)),DCmplx(Val(k,2),0.0d0),nn1,.false.,cb(1),nnz,cwrk(1),ier)
aRes(k)=Dble(cb(1))
end do
! Cases with three arguments
Case('eps')
do k=1,nArr
aRes(k)=Dble(getcEps(Val(k,1),nx,ny,nz))
end do
Case('mue')
do k=1,nArr
aRes(k)=Dble(getcMue(Val(k,1),nx,ny,nz))
end do
Case('sig')
do k=1,nArr
aRes(k)=Dble(getcSig(Val(k,1),nx,ny,nz))
end do
Case('tau')
do k=1,nArr
aRes(k)=Dble(getcTau(Val(k,1),nx,ny,nz))
end do
Case('kap')
do k=1,nArr
aRes(k)=Dble(getcKap(Val(k,1),nx,ny,nz))
end do
Case('kkk')
do k=1,nArr
aRes(k)=Dble(getcK(Val(k,1),nx,ny,nz))
end do
Case('fex')
do k=1,nArr
aRes(k)=getdAuxFld(1,Val,nx,ny,nz)
end do
Case('fey')
do k=1,nArr
aRes(k)=getdAuxFld(2,Val,nx,ny,nz)
end do
Case('fez')
do k=1,nArr
aRes(k)=getdAuxFld(3,Val,nx,ny,nz)
end do
Case('fhx')
do k=1,nArr
aRes(k)=getdAuxFld(4,Val,nx,ny,nz)
end do
Case('fhy')
do k=1,nArr
aRes(k)=getdAuxFld(5,Val,nx,ny,nz)
end do
Case('fhz')
do k=1,nArr
aRes(k)=getdAuxFld(6,Val,nx,ny,nz)
end do
Case('fax')
do k=1,nArr
aRes(k)=getdAuxFld(7,Val,nx,ny,nz)
end do
Case('fay')
do k=1,nArr
aRes(k)=getdAuxFld(8,Val,nx,ny,nz)
end do
Case('faz')
do k=1,nArr
aRes(k)=getdAuxFld(9,Val,nx,ny,nz)
end do
Case('fvx')
do k=1,nArr
aRes(k)=getdAuxFld(10,Val,nx,ny,nz)
end do
Case('gex')
do k=1,nArr
aRes(k)=getdFld(1,Val,nx,ny,nz)
end do
Case('gey')
do k=1,nArr
aRes(k)=getdFld(2,Val,nx,ny,nz)
end do
Case('gez')
do k=1,nArr
aRes(k)=getdFld(3,Val,nx,ny,nz)
end do
Case('ghx')
do k=1,nArr
aRes(k)=getdFld(4,Val,nx,ny,nz)
end do
Case('ghy')
do k=1,nArr
aRes(k)=getdFld(5,Val,nx,ny,nz)
end do
Case('ghz')
do k=1,nArr
aRes(k)=getdFld(6,Val,nx,ny,nz)
end do
Case('gax')
do k=1,nArr
aRes(k)=getdFld(7,Val,nx,ny,nz)
end do
Case('gay')
do k=1,nArr
aRes(k)=getdFld(8,Val,nx,ny,nz)
end do
Case('gaz')
do k=1,nArr
aRes(k)=getdFld(9,Val,nx,ny,nz)
end do
Case('gvx')
do k=1,nArr
aRes(k)=getdFld(10,Val,nx,ny,nz)
end do
Case('lox')
do k=1,nArr
aRes(k)=getGrd(1,Val,nx,ny,nz)
end do
Case('loy')
do k=1,nArr
aRes(k)=getGrd(2,Val,nx,ny,nz)
end do
Case('loz')
do k=1,nArr
aRes(k)=getGrd(3,Val,nx,ny,nz)
end do
! Cases with four arguments
Case('if>')
do k=1,nArr
if(Val(k,1).gt.Val(k,2)) then
aRes(k)=Val(k,3)
else
aRes(k)=Val(k,4)
end if
end do
Case('if<')
do k=1,nArr
if(Val(k,1).lt.Val(k,2)) then
aRes(k)=Val(k,3)
else
aRes(k)=Val(k,4)
end if
end do
Case('if=')
do k=1,nArr
if(dabs(Val(k,1)-Val(k,2)).lt.pSmall) then
aRes(k)=Val(k,3)
else
aRes(k)=Val(k,4)
end if
end do
! cases with one or more arguments
Case('add')
do k=1,nArr
r=Val(k,1)
do i=2,nForA
r=r.add.Val(k,i)
end do
aRes(k)=r
end do
Case('cir') ! Ralf's function for deformend circles
do k=1,nArr
r=Val(k,1)
if(nForA.gt.3) then
aRes(k)=1.0d0-CircleDeform0(Val(k,1),Val(k,2),Val(k,3),nForA-3,Val(k,4:nForA))
else
aRes(k)=0.0d0
end if
end do
Case('com')
do k=1,nArr
r=Val(k,1)
do i=2,nForA
r=r.mul.Val(k,i)
end do
aRes(k)=.cos.r
end do
Case('fco') ! Fourier, only cosine terms
do k=1,nArr
r=Val(k,1)
aRes(k)=0.0d0
do i=2,nForA
aRes(k)=aRes(k)+Val(k,i)*cos(dble(i-2)*r)
end do
end do
Case('fsi') ! Fourier, only sine terms
do k=1,nArr
r=Val(k,1)
aRes(k)=0.0d0
do i=2,nForA
aRes(k)=aRes(k)+Val(k,i)*sin(dble(i-1)*r)
end do
end do
Case('fou') ! Fourier
do k=1,nArr
r=Val(k,1)
aRes(k)=0.0d0
if(nForA.gt.1) aRes(k)=aRes(k)+Val(k,2)
do i=3,nForA,2
aRes(k)=aRes(k)+Val(k,i)*cos(dble((i-1)/2)*r)
aRes(k)=aRes(k)+Val(k,i+1)*sin(dble((i-1)/2)*r)
end do
if((nForA-(2*(nForA/2))).gt.0) aRes(k)=aRes(k)+Val(k,nForA)*cos(dble((nForA-1)/2)*r)
end do
Case('max')
do k=1,nArr
r=Val(k,1)
do i=2,nForA
r=Max(r,Val(k,i))
end do
aRes(k)=r
end do
Case('min')
do k=1,nArr
r=Val(k,1)
do i=2,nForA
r=Min(r,Val(k,i))
end do
aRes(k)=r
end do
Case('mul')
do k=1,nArr
r=Val(k,1)
do i=2,nForA
r=r.mul.Val(k,i)
end do
aRes(k)=r
end do
Case('sim')
do k=1,nArr
r=Val(k,1)
do i=2,nForA
r=r.mul.Val(k,i)
end do
aRes(k)=.sin.r
end do
! cases with four or more arguments
Case('pro')
do k=1,nArr
r=Val(k,1)
aRes(k)=1.0
if(nForA.gt.1) aRes(k)=Val(k,2)
do i=4,nForA,2
r1=Val(k,i-1)
r2=Val(k,i)
if(r.gt.r1) aRes(k)=r2
end do
end do
Case Default
! unknown cases
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: unknown function!'
if(l4) write(*,*) 'function=',sFkt(1:3)
if(l4) write(*,*) 'original string=',s(1:ls)
end if
iErr=2
return
end Select
else
! value: check if constant, parameter, or variable and compute
if(lFor.eq.1) then
ir=0
else
call StrToInt(sFor(2:lFor),ir,iErr)
if((iErr.ne.0).and.(lFor.eq.3)) then
select case(sFor(1:3))
case('fre')
do k=1,nArr
aRes(k)=Dble(fcFld)
end do
iErr=0
return
case('gam')
do k=1,nArr
if(lzPer) then
aRes(k)=Dble(dcFld)
else
aRes(k)=Dble(gcFld)
end if
end do
iErr=0
return
case('ome')
do k=1,nArr
aRes(k)=Dble((2.0d0*Pi)*fcFld)
end do
iErr=0
return
end select
end if
end if
Select Case(sFor(1:1))
Case('c')
! constant
if((ir.lt.0).or.(ir.gt.mC).or.(iErr.ne.0)) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: Constant out of range!'
if(l4) write(*,*) 'original string=',s(1:ls)
if(l4) write(*,*) 'sFor=',sFor(1:lFor)
if(l4) write(*,*) 'iErr,ir,mC=',iErr,ir,mC
end if
iErr=1
return
end if
do k=1,nArr
aRes(k)=Cns(ir)
end do
Case('p')
! parameter
if((ir.lt.0).or.(ir.gt.mP).or.(iErr.ne.0)) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: Parameter out of range!'
if(l4) write(*,*) 'original string=',s(1:ls)
if(l4) write(*,*) 'sFor=',sFor(1:lFor)
if(l4) write(*,*) 'iErr,ir,mP=',iErr,ir,mP
end if
iErr=1
return
end if
do k=1,nArr
aRes(k)=Par(ir)
end do
Case('v')
! variable
if((ir.lt.0).or.(ir.gt.mV).or.(iErr.ne.0)) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: Variable V out of range!'
if(l4) write(*,*) 'original string=',s(1:ls)
if(l4) write(*,*) 'sFor=',sFor(1:lFor)
if(l4) write(*,*) 'iErr,ir,mV=',iErr,ir,mV
end if
iErr=1
return
end if
if(lArr.and.(ir.ge.iArrVar).and.(ir.lt.(iArrVar+nArrV))) then
k0=(ir-iArrVar)*nArr
do k=1,nArr
k0=k0+1
aRes(k)=vArr(k0)
end do
else
do k=1,nArr
aRes(k)=Var(ir)
end do
end if
Case('q')
! abbreviation
if((ir.lt.1).or.(ir+279.gt.mV).or.(iErr.ne.0)) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: Variable Q out of range!'
if(l4) write(*,*) 'original string=',s(1:ls)
if(l4) write(*,*) 'sFor=',sFor(1:lFor)
if(l4) write(*,*) 'iErr,ir,mV=',iErr,ir,mV
end if
iErr=1
return
end if
do k=1,nArr
aRes(k)=Var(ir+279)
end do
Case('t')
if((ir.lt.0).or.(ir.gt.mV).or.(iErr.ne.0)) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: Variable T out of range!'
if(l4) write(*,*) 'original string=',s(1:ls)
if(l4) write(*,*) 'sFor=',sFor(1:lFor)
if(l4) write(*,*) 'iErr,mV=',iErr,mV
end if
iErr=1
return
end if
if(lArr.and.(ir.ge.iArrVar).and.(ir.lt.(iArrVar+nArrV))) then
k0=(ir-iArrVar)*nArr
do k=1,nArr
k0=k0+1
aRes(k)=vArr(k0)
end do
else
do k=1,nArr
aRes(k)=Var(ir)
end do
end if
Case('x')
if((ir.lt.0).or.(ir.gt.mV-1).or.(iErr.ne.0)) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: Variable X out of range!'
if(l4) write(*,*) 'original string=',s(1:ls)
if(l4) write(*,*) 'sFor=',sFor(1:lFor)
if(l4) write(*,*) 'iErr,mV=',iErr,mV
end if
iErr=1
return
end if
if(lArr.and.((ir+1).ge.iArrVar).and.((ir+1).lt.(iArrVar+nArrV))) then
k0=(ir+1-iArrVar)*nArr
do k=1,nArr
k0=k0+1
aRes(k)=vArr(k0)
end do
else
do k=1,nArr
aRes(k)=Var(ir+1)
end do
end if
Case('y')
if((ir.lt.0).or.(ir.gt.mV-2).or.(iErr.ne.0)) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: Variable Y out of range!'
if(l4) write(*,*) 'original string=',s(1:ls)
if(l4) write(*,*) 'sFor=',sFor(1:lFor)
if(l4) write(*,*) 'iErr,mV=',iErr,mV
end if
iErr=1
return
end if
if(lArr.and.((ir+2).ge.iArrVar).and.((ir+2).lt.(iArrVar+nArrV))) then
k0=(ir+2-iArrVar)*nArr
do k=1,nArr
k0=k0+1
aRes(k)=vArr(k0)
end do
else
do k=1,nArr
aRes(k)=Var(ir+2)
end do
end if
Case('z')
if((ir.lt.0).or.(ir.gt.mV-3).or.(iErr.ne.0)) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: Variable Z out of range!'
if(l4) write(*,*) 'original string=',s(1:ls)
if(l4) write(*,*) 'sFor=',sFor(1:lFor)
if(l4) write(*,*) 'iErr,mV=',iErr,mV
end if
iErr=1
return
end if
if(lArr.and.((ir+3).ge.iArrVar).and.((ir+3).lt.(iArrVar+nArrV))) then
k0=(ir+3-iArrVar)*nArr
do k=1,nArr
k0=k0+1
aRes(k)=vArr(k0)
end do
else
do k=1,nArr
aRes(k)=Var(ir+3)
end do
end if
Case('d')
call getID(sFor(1:Min(3,Max(1,lFor))),lFor,mV,ixyz,ia,iErr)
if(iErr.ne.0) then
if(lForWarn) then
if(l4) write(*,*) 'ERROR in Formula: Variable D.. out of range!'
if(l4) write(*,*) 'original string=',s(1:ls)
if(l4) write(*,*) 'sFor=',sFor(1:lFor)
if(l4) write(*,*) 'iErr,mV=',iErr,mV