-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFieldExport.f90
1718 lines (1594 loc) · 83.4 KB
/
FieldExport.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
! -------------------------------------------------------------------------------------------------------------------------------------------------
! Field Operations Module
!
! ******************************************
! * Import / Export routines for 2D fields *
! ******************************************
!
! Export Routines:
! ----------------
! - SavePPM: Saves a field with dimensions nx,ny to a PPM image file by using a specified palette and scaling
! - SavePNG: Same as SavePPM, but converts the image file to PNG
! - SaveGIF: Directly writes a compressed GIF-imagefile. to be preferred!!!!!!!!!!!!!!
! - ConvertFieldToRGB: Generates a RGB array with the color values 0..255 out of the data array by using a specified palette and scaling.
! - FargePalette: Fills an array with the color tables used in ConvertFieldToRGB, where:
! 01: Farge Table blue-yellow-red
! 02: Farge Table gold-red-blue (pressure)
! 03: Farge Table gold-turquoise-purple
! 04: Farge Table gold-turquoise-red (sharp)
! 05: Farge Table blue-yellow-red
! 06: Farge Table gold-purple-turquoise
! 07: Farge Table gold-green-blue
! 08: Farge Table pink-yellow-light green
! 09: Farge Table red-b/w-green
! 10: Farge Table blue-yellow-red
! 11: Matlab Spring Table
! 12: Flameball Table
! 13: Matlab Standard (Jet) Table
! 14: Matlab Standard (Jet) Table, contours for pressure
!
! Import Routines:
! ----------------
! - LoadField: Loads a field from a specified file. There are two file formats: one contains only the data, the second one also the resultion.
! The latter can be obtained using GetSize. The array must be allocated, LoadField gets an assumed shaped array.
! - GetSize: extracts the resolution information from a file, if present. If not, it returns a flag indicating that the file has an old format without
! resolution in the file.
! - ResizeField: Sometimes, it may be nessesairy to load a field from a file with a different resolution, for example when computing a steady state
! flow. In this case, it is very convenient to take the final result from a lower resolution as starting point for higher resolutions. This routine
! resizes a field to an arbitrary new resolution, defined by the target array itself.
!
!
!
! -------------------------------------------------------------------------------------------------------------------------------------------------
!^ FILE FORMAT FOR RAW DATA
!
!
! -------------------------------------------------------------------------------------------------------------------------------------------------
module FieldExport
implicit none
contains
subroutine PolynomUpsampling(field_source,field_target)
use share_vars
implicit none
real (kind=pr), intent (in ) :: field_source (0:,0:)
real (kind=pr), intent (out) :: field_target (0:,0:)
real (kind=pr), dimension (:,:), allocatable :: field_source_k, field_target_k
integer :: nx1,nx2,ny1,ny2,ix,iy,i,j, nx_tmp,ny_tmp, ix2,iy2,R,RR,L,LL,K
write (*,*) "source:", shape(field_source)
write (*,*) "target:", shape(field_target)
nx1=size(field_source,1)
ny1=size(field_source,2)
nx2=size(field_target,1)
ny2=size(field_target,2)
field_target = 0.0
! fill matching points, the points where the finer grid matches the coarser one
field_target(0:nx2-1:2,0:ny2-1:2) = field_source
!+===========================================================================================
! PolynomUpsampling
!===========================================================================================
! then we do th elines
do iy=0,ny2-1, 2 ! gerade zahlen entlang y( hier gibts schon wert))
do ix=1,nx2-2, 2 ! ungrade zahlen entlang x (zwischen den org gitter))
if ((ix>=3).and.(ix<=nx2-1-3)) then
K = int( 0.5*real(ix) ) ! k
field_target(ix,iy)=(9.d0*(field_source(K,iy/2)+field_source(K+1,iy/2)) &
-field_source(K-1,iy/2)-field_source(K+2,iy/2) )/16.d0
elseif (ix==1) then
field_target(ix,iy)=(5.d0*field_source(0,iy/2)+15.d0*field_source(1,iy/2)&
-5.d0*field_source(2,iy/2)+ 1.d0*field_source(3,iy/2) )/16.d0
elseif (ix==nx2-2) then
field_target(ix,iy)=(5.d0*field_source(nx1-4,iy/2)+15.d0*field_source(nx1-3,iy/2)&
- 5.d0*field_source(nx1-2,iy/2)+ 1.d0*field_source(nx1-1,iy/2) )/16.d0
endif
enddo
enddo
! then we do th elines
do ix=0,nx2-1, 2 ! gerade zahlen entlang y( hier gibts schon wert))
do iy=1,ny2-2, 2 ! ungrade zahlen entlang x (zwischen den org gitter))
if ((iy>=3).and.(iy<+ny2-1-3)) then
K = int( 0.5*real(iy) ) ! k
field_target(ix,iy)=(9.d0*(field_source(ix/2,K)+field_source(ix/2,K+1)) &
-field_source(ix/2,K-1)-field_source(ix/2,K+2) )/16.d0
elseif (iy==1) then
field_target(ix,iy)=(5.d0*field_source(ix/2,0)+15.d0*field_source(ix/2,1)&
-5.d0*field_source(ix/2,2)+1.d0*field_source(ix/2,3))/16.d0
elseif (iy==ny2-2) then
field_target(ix,iy)=(+5.d0*field_source(ix/2,ny1-1)+15.d0*field_source(ix/2,ny1-2)&
-5.d0*field_source(ix/2,ny1-3)+ 1.d0*field_source(ix/2,ny1-4))/16.d0
endif
enddo
enddo
do iy=1,ny2-2, 2
do ix=1,nx2-2, 2
if ((ix>=3).and.(ix<+nx2-1-3)) then
field_target(ix,iy)=(9.d0*(field_target(ix-1,iy)+field_target(ix+1,iy)) &
-field_target(ix-3,iy)-field_target(ix+3,iy) )/16.d0
endif
enddo
enddo
!=========================================================================================
! linear
!=========================================================================================
! ! then we do th elines
! do iy=0,ny2-1, 2 ! gerade zahlen entlang y( hier gibts schon wert))
! do ix=1,nx2-2, 2 ! ungrade zahlen entlang x (zwischen den org gitter))
! L=ix/2
! LL = L-1 !left left
! R = L+1 ! right
! RR = L+2 !right right
! field_target(ix,iy)=0.5d0*(field_source( L, iy/2 )+field_source( R, iy/2 ) )
! enddo
! enddo
! do ix=0,nx2-1, 2 ! gerade zahlen entlang x( hier gibts schon wert))
! do iy=1,ny2-2, 2 ! ungrade zahlen entlang y (zwischen den org gitter))
! L=iy/2
! LL = L-1 !left left
! R = L+1 ! right
! RR = L+2 !right right
! field_target(ix,iy)=0.5d0*(field_source( ix/2,L )+field_source( ix/2,R ) )
! enddo
! enddo
! ! points that are in the center of the original grid cubes
! do ix=1,nx2-2,2
! do iy=1,ny2-2,2
! field_target(ix,iy) = 0.5d0*( field_target(ix,iy-1) + field_target(ix,iy+1) )
! enddo
! enddo
end subroutine PolynomUpsampling
!====================================================================================================
!subroutine SpectralInterpolation(field_source,field_target, field_target_k)
! use share_vars
! implicit none
! real (kind=pr), intent (in ) :: field_source (0:nxs-1,0:nys-1)
! real (kind=pr), intent (out) :: field_target (0:up*nxs-1,0:up*nys-1)
! real (kind=pr), intent (out) :: field_target_k (0:up*nxs-1,0:up*nys-1)
! real (kind=pr) :: field_source_k(0:nxs-1,0:nys-1)
! !--------------------------------------------
! ! perform FFT of original field ( size nx1 x ny1 )
! !--------------------------------------------
! call coftxy_small(field_source, field_source_k)
! !--------------------------------------------
! ! copy smaller FFT field into bigger one ( =upsampling )
! !--------------------------------------------
! field_target_k = 0.0
! field_target_k(0:nxs-1,0:nys-1)=field_source_k
! !--------------------------------------------
! ! perform iFFT of target field ( size nx2 x ny2 )
! !--------------------------------------------
! call cofitxy_big(field_target_k,field_target)
!end subroutine SpectralInterpolation
!====================================================================================================
!subroutine SpectralInterpolation(field_source,field_target)
! use share_vars
! implicit none
! real (kind=pr), intent (in ) :: field_source (:,:)
! real (kind=pr), intent (out) :: field_target (:,:)
! real (kind=pr), dimension (:,:), allocatable :: field_source_k, field_target_k
! integer :: nx1,nx2,ny1,ny2,ix,iy,i,j, nx_tmp,ny_tmp
! write (*,*) "source:", shape(field_source)
! write (*,*) "target:", shape(field_target)
! nx_tmp=nx ! because the fft works with nx, ny in the shared_vars, we will have to modify these
! ny_tmp=ny
! nx1=size(field_source,1)
! ny1=size(field_source,2)
! nx2=size(field_target,1)
! ny2=size(field_target,2)
! !--------------------------------------------
! ! perform FFT of original field ( size nx1 x ny1 )
! !--------------------------------------------
! nx=nx1 ! because the fft works with nx, ny in the shared_vars, we will have to modify these
! ny=ny1
! call fft_free
! call fft_initialize
! allocate( field_source_k(1:nx1,1:ny1) )
! field_source_k = 0.0
! call coftxy(field_source, field_source_k)
! !--------------------------------------------
! ! copy smaller FFT field into bigger one ( =upsampling )
! !--------------------------------------------
! allocate( field_target_k(1:nx2,1:ny2) )
! field_target = 0.0
! field_target_k(1:nx1,1:ny1)=field_source_k
! !--------------------------------------------
! ! perform iFFT of target field ( size nx2 x ny2 )
! !--------------------------------------------
! call fft_free
! nx=nx2
! ny=ny2
! call fft_initialize
! call cofitxy(field_target_k,field_target)
! call fft_free
! !--------------------------------------------
! ! put FFT memory back to the state it had before
! !--------------------------------------------
! nx=nx_tmp
! ny=ny_tmp
! call fft_initialize
! write(*,*) "fft",nx,ny
!end subroutine SpectralInterpolation
!====================================================================================================
subroutine SavePPM(field, filename, iPalette, minf, maxf)
! ---------------------------------------------------------
! SavePPM - converts a raw data field to PPM. You can, optionally, call SavePNG
! the latter calls "convert" in the linux system to convert the file directly.
! this does not work when running on DUKE
!
! How does it work? Basically, we first generate the FARGE color tables (and some more)
! these give a color table related to the intensity of the scalar field.
! The ConvertFieldToRGB routine then makes a RGB color table out of the raw field, by
! scaling the values. this routine here is actually only the storing of the ppm file.
! note that SavePPM uses a special format tick ("$") to write binary data.
! ---------------------------------------------------------
use share_vars
implicit none
character*1 :: rgb(3,nx,ny) ! RGB data array
character*(*) :: filename
real (kind=pr), dimension(1:nx,1:ny),intent (in) :: field
real (kind=pr), intent (in) :: minf,maxf
integer i, j, k,iPalette
integer itmp
character*14 frmtstr
character*2 str
call ConvertFieldToRGB(field,rgb,iPalette,minf,maxf)
open(unit=2,file=filename//".ppm",status='unknown')
! header
write(2,'(''P6'', 2(1x,i4),'' 255 '',$)') nx, ny
! image data
itmp = nx*ny*3
write(frmtstr,'(''('',i8.8,''A,$)'')') itmp ! make output "format"
write(2,fmt=frmtstr) (((rgb(k,i,j),k=1,3),i=1,nx),j=ny,1,-1) ! here, j (vertical address) runs from top to bottom.
close(2)
return
end subroutine SavePPM
subroutine SavePNG(field, filename, iPalette, minf, maxf)
use share_vars
implicit none
character*1 :: rgb(3,nx,ny) ! RGB data array
character*(*) :: filename
real (kind=pr), dimension(1:nx,1:ny),intent (in) :: field
real (kind=pr), intent (in) :: minf,maxf
character*12 fnameout
integer i, j, k,iPalette
integer itmp, icnt
character*14 frmtstr
character*54 headmsw
character*4 byt4
character*2 str
call SavePPM(field,filename,iPalette,minf,maxf)
call system("convert "//trim(filename)//".ppm "//trim(filename)//".png")
call system("rm "//trim(filename)//".ppm")
end subroutine SavePNG
subroutine SaveGIF(field, filename, iColorTable, color_min, color_max)
!-------------------------------------------------------------
! Save gif subroutine. What is the essential difference?
! the write_gif module works with a array for the color table, ColorMap.
! this contains the 256 possible colors in a gif. In the palettes (created in FargePalette)
! we create exactly this amount of different colors - perfect! now in the gif, we have a color table
! with the RGB values of all the 256 colors, and in the field we are left with an array of indices
! that indicate which color the pixel gets.
!
! IMPROVED 08 apr 2012: now indepedent of nx,ny, can save fields of any size
! IMPROVED: arguments iColorTable, color_min,color_max are now OPTIONAL
!
!-------------------------------------------------------------
use share_vars
use gif_util
implicit none
character*(*) :: filename
real (kind=pr), intent (in) :: field (:,:)
real (kind=pr), intent (in), optional :: color_min,color_max
integer, intent (in), optional :: iColorTable
real (kind=pr) :: minf,maxf
integer, dimension(1:nPalettes,1:256*3) :: palette !array for color values for FARGE palettes
integer, dimension(1:3,0:255) :: ColorMap
integer, allocatable :: Pixel(:,:) ! RGB data array
integer i, j, k,iPalette, intensity,nx1,ny1
integer itmp
character*14 frmtstr
character*2 str
nx1=size(field,1)
ny1=size(field,2)
allocate (Pixel(1:nx1,1:ny1))
!--------------------------------------------
! optional parameters
!--------------------------------------------
if ( present(color_min) ) then
minf=color_min
else
minf=minval(field)
end if
if ( present(color_max) ) then
maxf=color_max
else
maxf=maxval(field)
end if
if ( present(iColorTable) ) then
iPalette=iColorTable
else
iPalette=13
end if
!create palettes
call FargePalette(palette)
! fill colormap, the 256 colors for the gif.
do i=1,256
ColorMap(1,i-1) = palette(iPalette,i) !Red
ColorMap(2,i-1) = palette(iPalette,i+256)!green
ColorMap(3,i-1) = palette(iPalette,i+512)!blue
enddo
!loop over the field, intensity is the index of the color
do i = 1, nx1
do j = 1, ny1
!intensity is the index of the color place in the palette array
intensity = 1+nint(256.0*(field(i,1+ny1-j)-minf)/(maxf-minf)) !remember that we use inverse ordering in the code
intensity = 1+nint(255.0*(field(i,1+ny1-j)-minf)/(maxf-minf)) !remember that we use inverse ordering in the code
if (intensity<1) intensity=1
if (intensity>256) intensity=256
Pixel(i,j)=intensity-1
enddo
enddo
call writegif (trim(filename)//".gif", Pixel, ColorMap)
end subroutine SaveGIF
!==================================================================================================================================================
!==================================================================================================================================================
subroutine LoadField(field, filename)
!----------------------------------------------------------------
! Load a raw data field. in the new code versions, such a file contains a massive amount of comments (the PARAMS file used
! in the simulation). The beginning of the file is indicated by the string "%format1"
! then follows the resolution nx, ny, the domain size xl, yl and then three comments. the one in the middle
! is a string indicating the type of data, e.g. "% vorticity"
!
! summary file format:
! ==========================================================
! .
! .
! COMMENTS
! .
! .
! %format1
! nx
! ny
! xl
! yl
! COMMENT
! % vorticity (for example, there may be others)
! .
! .
! DATA
! .
! .
! ==========================================================
!----------------------------------------------------------------
use share_vars
implicit none
integer i,j,nx1,ny1,nx1_file,ny1_file
character*(*), intent(in) :: filename
character(len=15) :: format_identifier
character(len=256) :: dummy !to read from the file
real (kind=pr), intent (inout) :: field (:,:)
nx1=size(field,1)
ny1=size(field,2)
i=1
open(unit=2,file=filename,status='old')
do while ((dummy.ne."%format1").and.(i<150))
read (2,'(A)') dummy
i=i+1
end do
if (dummy.ne."%format1") then
close(2)
Write (*,*) "Unfortunately I did not find the string 'format1' in the file. This means it does NOT contain the resolution."
stop
endif
read (2,*) nx1_file
read (2,*) ny1_file
if ((nx1_file.ne.nx1).or.(ny1_file.ne.ny1)) then
write (*,*) "??? file resolution does not match the field you gave my to read in..."
write (*,'("file: ",i4,"x",i4," field: ",i4,"x",i4)') nx1_file,ny1_file, nx1,ny1
stop
endif
read (2,*) xl
read (2,*) yl
read (2,'(A)') dummy
read (2,'(A)') dummy
do j = ny1, 1, -1
do i = 1, nx1
read (2,*) field(i,j)
enddo
enddo
close(2)
end subroutine LoadField
!==================================================================================================================================================
subroutine GetSize(filename, FileContainsResolution)
use share_vars
implicit none
character*(*) :: filename
character(len=256) :: dummy !to read from the file
integer :: i=1
character(len=15) :: format_identifier
logical :: FileContainsResolution
open(unit=2,file=filename,status='old')
FileContainsResolution=.true.
do while ((dummy.ne."%format1").and.(i<150))
read (2,'(A)') dummy
i=i+1
end do
if (dummy.ne."%format1") then
close(2)
Write (*,*) "Unfortunately I did not find the string 'format1' in the file. This means it does NOT contain the resolution."
FileContainsResolution=.false.
else
read (2,*) nx
read (2,*) ny
read (2,*) xl
read (2,*) yl
endif
close(2)
end subroutine GetSize
!==================================================================================================================================================
!==================================================================================================================================================
subroutine ConvertFieldToRGB(field,rgb,n,minf,maxf)
use share_vars
implicit none
integer :: i,j, intensity,n
real (kind=pr) :: minf,maxf
real (kind=pr), dimension(1:nx,1:ny) :: field
character*1, dimension(1:3,1:nx,1:ny) :: rgb
integer, dimension(1:nPalettes,1:256*3) :: palette !array for color values for FARGE palettes
integer :: ixmin,ixmax,iymin,iymax
if ( (n<0).or.(n>nPalettes) ) then
write(*,*) n, "ConvertFieldToRGB:: Unknown Palette. Stop."
stop
endif
!create palettes
call FargePalette(palette)
!loop over the field
do i = 1, nx
do j = 1, ny
!intensity is the index of the color place in the palette array
intensity = 1+nint(256.0*(field(i,j)-minf)/(maxf-minf)) !indexing starts with 1 so add 1
if (intensity<1) intensity=1
if (intensity>255) intensity=255
rgb(3,i,j) = char(Palette(n,intensity+512) ) !blue
rgb(2,i,j) = char(Palette(n,intensity+256) ) !green
rgb(1,i,j) = char(Palette(n,intensity) ) !red
! !-------experimental
! if (mask(i,j)*eps>0.5) then
! rgb(3,i,j) = char(255) !blue
! rgb(2,i,j) = char(255) !green
! rgb(1,i,j) = char(255) !red
! endif
enddo
enddo
! do i = ixmin, ixmax
! do j = iymin, iymax
! iymax = int( (max( maxval(beam(:,2))+4.0*t_beam, LeadingEdge(2)+2.0*r_cylinder))/dy)
! iymin = int( (min( minval(beam(:,2))-4.0*t_beam, LeadingEdge(2)-2.0*r_cylinder))/dy)
! ! absolute upper limit for xmin is the leading edge - 4 times thickness
! ixmin = int( min( (LeadingEdge(1)-max(2.5*r_cylinder, 4.0*t_beam)), (minval(beam(:,1))-4.0*t_beam) ) /dx)
! ! even if the beam is hanging, its minimum x value is the leading edge
! ixmax = int( (maxval(beam(:,1))+4.0*t_beam) /dx)
! enddo
! enddo
end subroutine ConvertFieldToRGB
!=============================================================================================================================================
subroutine ResizeField(field_source, field_target,lx,ly)
! this subroutine resizes a field to another resolution.
! for simplicity, it uses only bi-linear interpolation, even if the grids match at most of the points.
! as it is usually called only once, its performance is not important
use share_vars
real (kind=pr), intent (inout) :: field_source (:,:)
real (kind=pr), intent (out) :: field_target (:,:)
real (kind=pr), intent (in) :: lx,ly
real (kind=pr) :: dx1,dx2,dy1,dy2,x,y,x1,y1,x2,y2,R1,R2, summe
integer :: nx1,nx2,ny1,ny2,ix,iy,i,j
write (*,*) "----------------- resize field --------------------"
write (*,*) "source:", shape(field_source)
write (*,*) "target:", shape(field_target)
! the size of assumed-shaped arrays is dynamic. remember that indices always start with 1!
nx1=size(field_source,1)
ny1=size(field_source,2)
nx2=size(field_target,1)
ny2=size(field_target,2)
write(*,'(4(i5,1x))') nx1,ny1,nx2,ny2
! determine lattice spacing. here, the domain is not periodic so its lx/nx-1
dx1=lx/real(nx1-1,kind=pr)
dy1=ly/real(ny1-1,kind=pr)
dx2=lx/real(nx2-1,kind=pr)
dy2=ly/real(ny2-1,kind=pr)
field_target = 9.0
write (*,'(4(F7.4,1x))') dx1,dy1,lx,ly
! fill target field
do ix=1,nx2
do iy=1,ny2
! coordinate in target field
x=real(ix,kind=pr)*dx2 !as indices start with one, subtract one
y=real(iy,kind=pr)*dy2
! coordinate in source field
i=int(x/dx1)
if (i==nx1) i=nx1-1 ! if the last column and row is reached, change interpolation so that it is not out of bounds
if (i==0) i=1
j=int(y/dy1)
if (j==ny1) j=ny1-1
if (j==0) j=1
! coordinates of interpolation points 1&2
x1=real(i,kind=pr) *dx1
y1=real(j,kind=pr) *dy1
x2=real(i+1,kind=pr)*dx1
y2=real(j+1,kind=pr)*dy1
! interpolation in x-direction
R1 = (x2-x)*field_source(i,j )/dx1 + (x-x1)*field_source(i+1,j )/dx1
R2 = (x2-x)*field_source(i,j+1)/dx1 + (x-x1)*field_source(i+1,j+1)/dx1
! interpolation in y-direction
field_target(ix,iy) = (y2-y)*R1/dy1 + (y-y1)*R2/dy1
enddo
enddo
write (*,*) "----------------- --------------------"
end subroutine ResizeField
!=============================================================================================================================================
subroutine SaveField(filename, field, NSave, lx,ly, fieldtype)
! SEE LOAD_FIELD for details on the format
use share_vars
implicit none
real (kind=pr), intent (in) :: field(:,:)
real (kind=pr), intent (in) :: lx,ly
integer, intent(in) :: NSave
integer :: ix,iy,nx1,ny1
character*(*), intent(in) :: filename
character*(*), intent(in) :: fieldtype
nx1=size(field,1)
ny1=size(field,2)
open (10, file=filename, form='formatted', status='replace')
call WriteHeaderToFile(10) ! at this point, the PARAMS file is written to the file.
write (10,'(A)') "%format1"
write (10,'(i5.5,3x,A)') nx1, "% nx"
write (10,'(i5.5,3x,A)') ny1, "% ny"
write (10,'(es11.4,3x,A)') lx, "% xl, domain size in x-direction"
write (10,'(es11.4,3x,A)') ly, "% yl, domain size in y-direction"
write (10,'(A)') "% The next entry can be used to identify the type of the field: "
write (10,'(A)') "% "//fieldtype
if (fieldtype == "precision") then
do iy = 0, ny1-1, NSave
write (10, '(es16.9)') (field(ix, ny1-iy) , ix=1,nx1, NSave)
end do
else
do iy = 0, ny1-1, NSave
write (10, '(es11.4)') (field(ix, ny1-iy) , ix=1,nx1, NSave)
end do
endif
close (10)
end subroutine SaveField
!=============================================================================================================================================
subroutine FargePalette(palette)
use share_vars
implicit none
integer palette(nPalettes,256*3)
integer i,sector, n,j
reaL :: intensity
Palette(1,:) = (/ Z'00', Z'00', Z'00', Z'00', Z'01', Z'01', Z'01', Z'01',& ! Rot */
Z'02', Z'02', Z'02', Z'02', Z'03', Z'03', Z'03', Z'03',&
Z'03', Z'04', Z'04', Z'04', Z'04', Z'04', Z'04', Z'05',&
Z'05', Z'05', Z'05', Z'05', Z'05', Z'06', Z'06', Z'06',&
Z'06', Z'06', Z'06', Z'06', Z'07', Z'07', Z'07', Z'07',&
Z'07', Z'07', Z'07', Z'08', Z'08', Z'08', Z'08', Z'08',&
Z'08', Z'08', Z'09', Z'09', Z'09', Z'09', Z'09', Z'09',&
Z'09', Z'0a', Z'0a', Z'0a', Z'0a', Z'0a', Z'0a', Z'0a',&
Z'0b', Z'0b', Z'0b', Z'0b', Z'0b', Z'0c', Z'0c', Z'0c',&
Z'0c', Z'0c', Z'0c', Z'0d', Z'0d', Z'0d', Z'0d', Z'0e',&
Z'0e', Z'0e', Z'0e', Z'0f', Z'0f', Z'0f', Z'0f', Z'10',&
Z'00', Z'04', Z'09', Z'0e', Z'12', Z'17', Z'1b', Z'1f',&
Z'23', Z'27', Z'2b', Z'2e', Z'32', Z'36', Z'39', Z'3c',&
Z'40', Z'43', Z'46', Z'49', Z'4c', Z'4f', Z'52', Z'55',&
Z'58', Z'5b', Z'5f', Z'62', Z'65', Z'68', Z'6b', Z'6d',&
Z'70', Z'72', Z'74', Z'76', Z'78', Z'7a', Z'fd', Z'fd',&
Z'fd', Z'fd', Z'84', Z'85', Z'87', Z'89', Z'8b', Z'8e',&
Z'90', Z'92', Z'95', Z'98', Z'9a', Z'9e', Z'a1', Z'a4',&
Z'a8', Z'ab', Z'ae', Z'b1', Z'b4', Z'b7', Z'ba', Z'bd',&
Z'c1', Z'c4', Z'c7', Z'cb', Z'cf', Z'd2', Z'd6', Z'da',&
Z'de', Z'e2', Z'e6', Z'eb', Z'ef', Z'f4', Z'f9', Z'fd',&
Z'40', Z'44', Z'47', Z'4a', Z'4d', Z'50', Z'53', Z'56',&
Z'58', Z'5b', Z'5e', Z'60', Z'63', Z'65', Z'68', Z'6a',&
Z'6d', Z'6f', Z'71', Z'73', Z'75', Z'77', Z'79', Z'7b',&
Z'7d', Z'7f', Z'81', Z'83', Z'85', Z'87', Z'89', Z'8a',&
Z'8c', Z'8e', Z'90', Z'91', Z'93', Z'95', Z'96', Z'98',&
Z'99', Z'9b', Z'9d', Z'9e', Z'a0', Z'a2', Z'a3', Z'a5',&
Z'a6', Z'a8', Z'aa', Z'ab', Z'ad', Z'af', Z'b0', Z'b2',&
Z'b4', Z'b6', Z'b7', Z'b9', Z'bb', Z'bd', Z'bf', Z'c1',&
Z'c3', Z'c5', Z'c7', Z'c9', Z'cb', Z'cd', Z'cf', Z'd2',&
Z'd4', Z'd6', Z'd9', Z'db', Z'de', Z'e0', Z'e3', Z'e6',&
Z'e9', Z'eb', Z'ee', Z'f1', Z'f4', Z'f7', Z'fb', Z'fe',&
Z'3f', Z'41', Z'42', Z'44', Z'45', Z'47', Z'48', Z'4a',& ! Gruen */
Z'4b', Z'4c', Z'4e', Z'4f', Z'50', Z'51', Z'53', Z'54',&
Z'55', Z'56', Z'57', Z'58', Z'59', Z'5a', Z'5b', Z'5c',&
Z'5d', Z'5e', Z'5f', Z'60', Z'61', Z'62', Z'63', Z'64',&
Z'65', Z'66', Z'66', Z'67', Z'68', Z'69', Z'6a', Z'6a',&
Z'6b', Z'6c', Z'6d', Z'6e', Z'6f', Z'6f', Z'70', Z'71',&
Z'72', Z'73', Z'73', Z'74', Z'75', Z'76', Z'77', Z'78',&
Z'78', Z'79', Z'7a', Z'7b', Z'7c', Z'7d', Z'7e', Z'7f',&
Z'80', Z'81', Z'82', Z'83', Z'84', Z'85', Z'86', Z'87',&
Z'89', Z'8a', Z'8b', Z'8c', Z'8d', Z'8f', Z'90', Z'91',&
Z'93', Z'94', Z'96', Z'97', Z'99', Z'9a', Z'9c', Z'9d',&
Z'00', Z'04', Z'09', Z'0e', Z'12', Z'17', Z'1b', Z'1f',&
Z'23', Z'27', Z'2b', Z'2e', Z'32', Z'36', Z'39', Z'3c',&
Z'40', Z'43', Z'46', Z'49', Z'4c', Z'4f', Z'52', Z'55',&
Z'58', Z'5b', Z'5f', Z'62', Z'65', Z'68', Z'6b', Z'6d',&
Z'70', Z'72', Z'74', Z'76', Z'78', Z'7a', Z'd8', Z'd8',&
Z'd8', Z'd8', Z'84', Z'85', Z'87', Z'89', Z'8b', Z'8e',&
Z'90', Z'92', Z'95', Z'98', Z'9a', Z'9e', Z'a1', Z'a4',&
Z'a8', Z'ab', Z'ae', Z'b1', Z'b4', Z'b7', Z'ba', Z'bd',&
Z'c1', Z'c4', Z'c7', Z'cb', Z'cf', Z'd2', Z'd6', Z'da',&
Z'de', Z'e2', Z'e6', Z'eb', Z'ef', Z'f4', Z'f9', Z'fd',&
Z'00', Z'02', Z'04', Z'06', Z'08', Z'0a', Z'0c', Z'0e',&
Z'10', Z'12', Z'14', Z'15', Z'17', Z'19', Z'1a', Z'1c',&
Z'1e', Z'1f', Z'21', Z'22', Z'23', Z'25', Z'26', Z'28',&
Z'29', Z'2a', Z'2c', Z'2d', Z'2e', Z'2f', Z'31', Z'32',&
Z'33', Z'34', Z'35', Z'36', Z'37', Z'39', Z'3a', Z'3b',&
Z'3c', Z'3d', Z'3e', Z'3f', Z'40', Z'41', Z'42', Z'44',&
Z'45', Z'46', Z'47', Z'48', Z'49', Z'4a', Z'4b', Z'4d',&
Z'4e', Z'4f', Z'50', Z'51', Z'53', Z'54', Z'55', Z'57',&
Z'58', Z'59', Z'5b', Z'5c', Z'5d', Z'5f', Z'60', Z'62',&
Z'64', Z'65', Z'67', Z'68', Z'6a', Z'6c', Z'6e', Z'70',&
Z'71', Z'73', Z'75', Z'77', Z'79', Z'7c', Z'7e', Z'80',&
Z'53', Z'56', Z'59', Z'5c', Z'5f', Z'62', Z'64', Z'67',& ! Blau */
Z'69', Z'6c', Z'6e', Z'70', Z'73', Z'75', Z'77', Z'79',&
Z'7b', Z'7e', Z'80', Z'81', Z'83', Z'85', Z'87', Z'89',&
Z'8b', Z'8d', Z'8e', Z'90', Z'92', Z'93', Z'95', Z'97',&
Z'98', Z'9a', Z'9b', Z'9d', Z'9e', Z'a0', Z'a1', Z'a3',&
Z'a4', Z'a6', Z'a7', Z'a9', Z'aa', Z'ac', Z'ad', Z'af',&
Z'b0', Z'b1', Z'b3', Z'b4', Z'b6', Z'b8', Z'b9', Z'bb',&
Z'bc', Z'be', Z'bf', Z'c1', Z'c3', Z'c4', Z'c6', Z'c8',&
Z'ca', Z'cc', Z'cd', Z'cf', Z'd1', Z'd3', Z'd5', Z'd7',&
Z'd9', Z'dc', Z'de', Z'e0', Z'e2', Z'e5', Z'e7', Z'e9',&
Z'ec', Z'ef', Z'f1', Z'f4', Z'f7', Z'fa', Z'fc', Z'ff',&
Z'00', Z'04', Z'09', Z'0e', Z'12', Z'17', Z'1b', Z'1f',&
Z'23', Z'27', Z'2b', Z'2e', Z'32', Z'36', Z'39', Z'3c',&
Z'40', Z'43', Z'46', Z'49', Z'4c', Z'4f', Z'52', Z'55',&
Z'58', Z'5b', Z'5f', Z'62', Z'65', Z'68', Z'6b', Z'6d',&
Z'70', Z'72', Z'74', Z'76', Z'78', Z'7a', Z'00', Z'00',&
Z'00', Z'00', Z'84', Z'85', Z'87', Z'89', Z'8b', Z'8e',&
Z'90', Z'92', Z'95', Z'98', Z'9a', Z'9e', Z'a1', Z'a4',&
Z'a8', Z'ab', Z'ae', Z'b1', Z'b4', Z'b7', Z'ba', Z'bd',&
Z'c1', Z'c4', Z'c7', Z'cb', Z'cf', Z'd2', Z'd6', Z'da',&
Z'de', Z'e2', Z'e6', Z'eb', Z'ef', Z'f4', Z'f9', Z'fd',&
Z'00', Z'02', Z'04', Z'06', Z'08', Z'0a', Z'0c', Z'0e',&
Z'10', Z'12', Z'14', Z'15', Z'17', Z'19', Z'1a', Z'1c',&
Z'1e', Z'1f', Z'21', Z'22', Z'23', Z'25', Z'26', Z'28',&
Z'29', Z'2a', Z'2c', Z'2d', Z'2e', Z'2f', Z'31', Z'32',&
Z'33', Z'34', Z'35', Z'36', Z'37', Z'39', Z'3a', Z'3b',&
Z'3c', Z'3d', Z'3e', Z'3f', Z'40', Z'41', Z'42', Z'44',&
Z'45', Z'46', Z'47', Z'48', Z'49', Z'4a', Z'4b', Z'4d',&
Z'4e', Z'4f', Z'50', Z'51', Z'53', Z'54', Z'55', Z'57',&
Z'58', Z'59', Z'5b', Z'5c', Z'5d', Z'5f', Z'60', Z'62',&
Z'64', Z'65', Z'67', Z'68', Z'6a', Z'6c', Z'6e', Z'70',&
Z'71', Z'73', Z'75', Z'77', Z'79', Z'7c', Z'7e', Z'80' /)
! ! Palette 2 */
Palette(2,:)=(/ Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00',& ! Rot */
Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00',&
Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00',&
Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00',&
Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00',&
Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00',&
Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00',&
Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00',&
Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00',&
Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00',&
Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00',&
Z'00', Z'04', Z'09', Z'0e', Z'12', Z'17', Z'1b', Z'1f',&
Z'23', Z'27', Z'2b', Z'2e', Z'32', Z'36', Z'39', Z'3c',&
Z'40', Z'43', Z'46', Z'49', Z'4c', Z'4f', Z'52', Z'55',&
Z'58', Z'5a', Z'5d', Z'60', Z'62', Z'65', Z'67', Z'6a',&
Z'6c', Z'6f', Z'71', Z'74', Z'76', Z'79', Z'fe', Z'fe',&
Z'fe', Z'82', Z'84', Z'87', Z'89', Z'8c', Z'8e', Z'91',&
Z'93', Z'96', Z'98', Z'9b', Z'9d', Z'a0', Z'a3', Z'a5',&
Z'a8', Z'ab', Z'ae', Z'b1', Z'b4', Z'b7', Z'ba', Z'bd',&
Z'c1', Z'c4', Z'c7', Z'cb', Z'cf', Z'd2', Z'd6', Z'da',&
Z'de', Z'e2', Z'e6', Z'eb', Z'ef', Z'f4', Z'f9', Z'fd',&
Z'53', Z'56', Z'59', Z'5c', Z'5f', Z'62', Z'64', Z'67',&
Z'69', Z'6c', Z'6e', Z'70', Z'73', Z'75', Z'77', Z'79',&
Z'7b', Z'7e', Z'80', Z'81', Z'83', Z'85', Z'87', Z'89',&
Z'8b', Z'8d', Z'8e', Z'90', Z'92', Z'93', Z'95', Z'97',&
Z'98', Z'9a', Z'9b', Z'9d', Z'9e', Z'a0', Z'a1', Z'a3',&
Z'a4', Z'a6', Z'a7', Z'a9', Z'aa', Z'ac', Z'ad', Z'af',&
Z'b0', Z'b1', Z'b3', Z'b4', Z'b6', Z'b8', Z'b9', Z'bb',&
Z'bc', Z'be', Z'bf', Z'c1', Z'c3', Z'c4', Z'c6', Z'c8',&
Z'ca', Z'cc', Z'cd', Z'cf', Z'd1', Z'd3', Z'd5', Z'd7',&
Z'd9', Z'dc', Z'de', Z'e0', Z'e2', Z'e5', Z'e7', Z'e9',&
Z'ec', Z'ef', Z'f1', Z'f4', Z'f7', Z'fa', Z'fc', Z'ff',&
Z'3f', Z'40', Z'42', Z'43', Z'44', Z'45', Z'47', Z'48',& ! Gruen */
Z'49', Z'4a', Z'4b', Z'4c', Z'4d', Z'4e', Z'4f', Z'50',&
Z'51', Z'52', Z'53', Z'54', Z'55', Z'56', Z'57', Z'57',&
Z'58', Z'59', Z'5a', Z'5b', Z'5b', Z'5c', Z'5d', Z'5e',&
Z'5e', Z'5f', Z'60', Z'60', Z'61', Z'62', Z'62', Z'63',&
Z'64', Z'64', Z'65', Z'66', Z'66', Z'67', Z'68', Z'68',&
Z'69', Z'6a', Z'6b', Z'6b', Z'6c', Z'6d', Z'6d', Z'6e',&
Z'6f', Z'6f', Z'70', Z'71', Z'72', Z'72', Z'73', Z'74',&
Z'75', Z'76', Z'77', Z'77', Z'78', Z'79', Z'7a', Z'7b',&
Z'7c', Z'7d', Z'7e', Z'7f', Z'80', Z'81', Z'82', Z'83',&
Z'85', Z'86', Z'87', Z'88', Z'89', Z'8b', Z'8c', Z'8d',&
Z'00', Z'04', Z'09', Z'0e', Z'12', Z'17', Z'1b', Z'1f',&
Z'23', Z'27', Z'2b', Z'2e', Z'32', Z'36', Z'39', Z'3c',&
Z'40', Z'43', Z'46', Z'49', Z'4c', Z'4f', Z'52', Z'55',&
Z'58', Z'5a', Z'5d', Z'60', Z'62', Z'65', Z'67', Z'6a',&
Z'6c', Z'6f', Z'71', Z'74', Z'76', Z'79', Z'00', Z'00',&
Z'00', Z'82', Z'84', Z'87', Z'89', Z'8c', Z'8e', Z'91',&
Z'93', Z'96', Z'98', Z'9b', Z'9d', Z'a0', Z'a3', Z'a5',&
Z'a8', Z'ab', Z'ae', Z'b1', Z'b4', Z'b7', Z'ba', Z'bd',&
Z'c1', Z'c4', Z'c7', Z'cb', Z'cf', Z'd2', Z'd6', Z'da',&
Z'de', Z'e2', Z'e6', Z'eb', Z'ef', Z'f4', Z'f9', Z'fd',&
Z'3c', Z'3f', Z'42', Z'46', Z'49', Z'4c', Z'4f', Z'51',&
Z'54', Z'57', Z'5a', Z'5c', Z'5f', Z'61', Z'64', Z'66',&
Z'68', Z'6b', Z'6d', Z'6f', Z'71', Z'73', Z'75', Z'77',&
Z'79', Z'7b', Z'7d', Z'7f', Z'81', Z'83', Z'85', Z'86',&
Z'88', Z'8a', Z'8c', Z'8d', Z'8f', Z'91', Z'92', Z'94',&
Z'96', Z'97', Z'99', Z'9b', Z'9c', Z'9e', Z'9f', Z'a1',&
Z'a3', Z'a4', Z'a6', Z'a8', Z'a9', Z'ab', Z'ad', Z'af',&
Z'b0', Z'b2', Z'b4', Z'b6', Z'b8', Z'b9', Z'bb', Z'bd',&
Z'bf', Z'c1', Z'c3', Z'c6', Z'c8', Z'ca', Z'cc', Z'ce',&
Z'd1', Z'd3', Z'd6', Z'd8', Z'db', Z'dd', Z'e0', Z'e3',&
Z'e5', Z'e8', Z'eb', Z'ee', Z'f1', Z'f4', Z'f8', Z'fb',&
Z'53', Z'56', Z'59', Z'5c', Z'5f', Z'61', Z'64', Z'67',& ! Blau */
Z'69', Z'6c', Z'6e', Z'70', Z'72', Z'75', Z'77', Z'79',&
Z'7b', Z'7d', Z'7f', Z'81', Z'83', Z'85', Z'87', Z'89',&
Z'8a', Z'8c', Z'8e', Z'8f', Z'91', Z'93', Z'94', Z'96',&
Z'98', Z'99', Z'9b', Z'9c', Z'9e', Z'9f', Z'a1', Z'a2',&
Z'a4', Z'a5', Z'a6', Z'a8', Z'a9', Z'ab', Z'ac', Z'ae',&
Z'af', Z'b1', Z'b2', Z'b4', Z'b5', Z'b7', Z'b8', Z'ba',&
Z'bb', Z'bd', Z'bf', Z'c0', Z'c2', Z'c3', Z'c5', Z'c7',&
Z'c9', Z'cb', Z'cc', Z'ce', Z'd0', Z'd2', Z'd4', Z'd6',&
Z'd8', Z'da', Z'dd', Z'df', Z'e1', Z'e3', Z'e6', Z'e8',&
Z'eb', Z'ed', Z'f0', Z'f3', Z'f5', Z'f8', Z'fb', Z'fe',&
Z'00', Z'04', Z'09', Z'0e', Z'12', Z'17', Z'1b', Z'1f',&
Z'23', Z'27', Z'2b', Z'2e', Z'32', Z'36', Z'39', Z'3c',&
Z'40', Z'43', Z'46', Z'49', Z'4c', Z'4f', Z'52', Z'55',&
Z'58', Z'5a', Z'5d', Z'60', Z'62', Z'65', Z'67', Z'6a',&
Z'6c', Z'6f', Z'71', Z'74', Z'76', Z'79', Z'00', Z'00',&
Z'00', Z'82', Z'84', Z'87', Z'89', Z'8c', Z'8e', Z'91',&
Z'93', Z'96', Z'98', Z'9b', Z'9d', Z'a0', Z'a3', Z'a5',&
Z'a8', Z'ab', Z'ae', Z'b1', Z'b4', Z'b7', Z'ba', Z'bd',&
Z'c1', Z'c4', Z'c7', Z'cb', Z'cf', Z'd2', Z'd6', Z'da',&
Z'de', Z'e2', Z'e6', Z'eb', Z'ef', Z'f4', Z'f9', Z'fd',&
Z'00', Z'00', Z'01', Z'01', Z'02', Z'02', Z'03', Z'03',&
Z'04', Z'04', Z'05', Z'05', Z'05', Z'06', Z'06', Z'07',&
Z'07', Z'07', Z'08', Z'08', Z'09', Z'09', Z'09', Z'0a',&
Z'0a', Z'0a', Z'0b', Z'0b', Z'0b', Z'0c', Z'0c', Z'0c',&
Z'0c', Z'0d', Z'0d', Z'0d', Z'0e', Z'0e', Z'0e', Z'0e',&
Z'0f', Z'0f', Z'0f', Z'0f', Z'10', Z'10', Z'10', Z'11',&
Z'11', Z'11', Z'11', Z'12', Z'12', Z'12', Z'13', Z'13',&
Z'13', Z'13', Z'14', Z'14', Z'14', Z'15', Z'15', Z'15',&
Z'16', Z'16', Z'16', Z'17', Z'17', Z'17', Z'18', Z'18',&
Z'19', Z'19', Z'19', Z'1a', Z'1a', Z'1b', Z'1b', Z'1c',&
Z'1c', Z'1d', Z'1d', Z'1d', Z'1e', Z'1f', Z'1f', Z'20' /)
! ! Palette 3 */
Palette(3,:)=(/ Z'39', Z'3b', Z'3d', Z'3e', Z'40', Z'41', Z'43', Z'44',& ! Rot */
Z'46', Z'47', Z'48', Z'4a', Z'4b', Z'4c', Z'4d', Z'4f',&
Z'50', Z'51', Z'52', Z'53', Z'54', Z'55', Z'56', Z'57',&
Z'58', Z'59', Z'5a', Z'5b', Z'5c', Z'5d', Z'5e', Z'5f',&
Z'60', Z'61', Z'61', Z'62', Z'63', Z'64', Z'65', Z'66',&
Z'67', Z'67', Z'68', Z'69', Z'6a', Z'6b', Z'6b', Z'6c',&
Z'6d', Z'6e', Z'6f', Z'70', Z'70', Z'71', Z'72', Z'73',&
Z'74', Z'75', Z'76', Z'77', Z'78', Z'78', Z'79', Z'7a',&
Z'7b', Z'7c', Z'7d', Z'7f', Z'80', Z'81', Z'82', Z'83',&
Z'84', Z'85', Z'87', Z'88', Z'89', Z'8a', Z'8c', Z'8d',&
Z'8f', Z'90', Z'91', Z'93', Z'95', Z'96', Z'98', Z'99',&
Z'00', Z'04', Z'09', Z'0e', Z'12', Z'17', Z'1b', Z'1f',&
Z'23', Z'27', Z'2b', Z'2e', Z'32', Z'36', Z'39', Z'3c',&
Z'40', Z'43', Z'46', Z'49', Z'4c', Z'4f', Z'52', Z'55',&
Z'58', Z'5a', Z'5d', Z'60', Z'62', Z'65', Z'67', Z'6a',&
Z'6c', Z'6f', Z'71', Z'74', Z'76', Z'79', Z'00', Z'00',&
Z'00', Z'82', Z'84', Z'87', Z'89', Z'8c', Z'8e', Z'91',&
Z'93', Z'96', Z'98', Z'9b', Z'9d', Z'a0', Z'a3', Z'a5',&
Z'a8', Z'ab', Z'ae', Z'b1', Z'b4', Z'b7', Z'ba', Z'bd',&
Z'c1', Z'c4', Z'c7', Z'cb', Z'cf', Z'd2', Z'd6', Z'da',&
Z'de', Z'e2', Z'e6', Z'eb', Z'ef', Z'f4', Z'f9', Z'fd',&
Z'33', Z'37', Z'3a', Z'3e', Z'41', Z'44', Z'47', Z'4a',&
Z'4d', Z'50', Z'53', Z'56', Z'59', Z'5b', Z'5e', Z'60',&
Z'63', Z'65', Z'68', Z'6a', Z'6c', Z'6f', Z'71', Z'73',&
Z'75', Z'77', Z'79', Z'7b', Z'7d', Z'7f', Z'81', Z'83',&
Z'85', Z'87', Z'89', Z'8a', Z'8c', Z'8e', Z'90', Z'92',&
Z'93', Z'95', Z'97', Z'99', Z'9a', Z'9c', Z'9e', Z'9f',&
Z'a1', Z'a3', Z'a5', Z'a7', Z'a8', Z'aa', Z'ac', Z'ae',&
Z'b0', Z'b2', Z'b4', Z'b6', Z'b7', Z'ba', Z'bc', Z'be',&
Z'c0', Z'c2', Z'c4', Z'c6', Z'c9', Z'cb', Z'cd', Z'd0',&
Z'd2', Z'd5', Z'd7', Z'da', Z'dd', Z'e0', Z'e3', Z'e5',&
Z'e8', Z'eb', Z'ef', Z'f2', Z'f5', Z'f8', Z'fc', Z'ff',&
Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00', Z'00',& ! Gruen */
Z'00', Z'00', Z'01', Z'01', Z'01', Z'01', Z'01', Z'01',&
Z'01', Z'01', Z'01', Z'01', Z'01', Z'01', Z'01', Z'01',&
Z'01', Z'02', Z'02', Z'02', Z'02', Z'02', Z'02', Z'02',&
Z'02', Z'02', Z'02', Z'02', Z'02', Z'02', Z'02', Z'02',&
Z'02', Z'02', Z'02', Z'02', Z'03', Z'03', Z'03', Z'03',&
Z'03', Z'03', Z'03', Z'03', Z'03', Z'03', Z'03', Z'03',&
Z'03', Z'03', Z'03', Z'03', Z'03', Z'03', Z'03', Z'04',&
Z'04', Z'04', Z'04', Z'04', Z'04', Z'04', Z'04', Z'04',&
Z'04', Z'04', Z'04', Z'04', Z'04', Z'04', Z'05', Z'05',&
Z'05', Z'05', Z'05', Z'05', Z'05', Z'05', Z'05', Z'05',&
Z'00', Z'04', Z'09', Z'0e', Z'12', Z'17', Z'1b', Z'1f',&
Z'23', Z'27', Z'2b', Z'2e', Z'32', Z'36', Z'39', Z'3c',&
Z'40', Z'43', Z'46', Z'49', Z'4c', Z'4f', Z'52', Z'55',&
Z'58', Z'5a', Z'5d', Z'60', Z'62', Z'65', Z'67', Z'6a',&
Z'6c', Z'6f', Z'71', Z'74', Z'76', Z'79', Z'fc', Z'fc',&
Z'fc', Z'82', Z'84', Z'87', Z'89', Z'8c', Z'8e', Z'91',&
Z'93', Z'96', Z'98', Z'9b', Z'9d', Z'a0', Z'a3', Z'a5',&
Z'a8', Z'ab', Z'ae', Z'b1', Z'b4', Z'b7', Z'ba', Z'bd',&
Z'c1', Z'c4', Z'c7', Z'cb', Z'cf', Z'd2', Z'd6', Z'da',&
Z'de', Z'e2', Z'e6', Z'eb', Z'ef', Z'f4', Z'f9', Z'fd',&
Z'0c', Z'0f', Z'12', Z'16', Z'19', Z'1c', Z'1e', Z'21',&
Z'24', Z'27', Z'29', Z'2c', Z'2f', Z'31', Z'34', Z'36',&
Z'38', Z'3b', Z'3d', Z'3f', Z'41', Z'43', Z'45', Z'47',&
Z'49', Z'4b', Z'4d', Z'4f', Z'51', Z'53', Z'54', Z'56',&
Z'58', Z'5a', Z'5b', Z'5d', Z'5f', Z'60', Z'62', Z'64',&
Z'65', Z'67', Z'69', Z'6a', Z'6c', Z'6e', Z'6f', Z'71',&
Z'72', Z'74', Z'76', Z'77', Z'79', Z'7b', Z'7d', Z'7e',&
Z'80', Z'82', Z'84', Z'85', Z'87', Z'89', Z'8b', Z'8d',&
Z'8f', Z'91', Z'93', Z'95', Z'97', Z'99', Z'9c', Z'9e',&
Z'a0', Z'a3', Z'a5', Z'a8', Z'aa', Z'ad', Z'af', Z'b2',&
Z'b5', Z'b8', Z'bb', Z'be', Z'c1', Z'c4', Z'c7', Z'ca',&
Z'7d', Z'7f', Z'81', Z'83', Z'85', Z'87', Z'89', Z'8b',& ! Blau */
Z'8d', Z'8f', Z'91', Z'93', Z'94', Z'96', Z'98', Z'99',&
Z'9b', Z'9c', Z'9e', Z'9f', Z'a1', Z'a2', Z'a3', Z'a5',&
Z'a6', Z'a7', Z'a9', Z'aa', Z'ab', Z'ac', Z'ae', Z'af',&
Z'b0', Z'b1', Z'b2', Z'b3', Z'b5', Z'b6', Z'b7', Z'b8',&
Z'b9', Z'ba', Z'bb', Z'bc', Z'bd', Z'bf', Z'c0', Z'c1',&
Z'c2', Z'c3', Z'c4', Z'c5', Z'c6', Z'c7', Z'c9', Z'ca',&
Z'cb', Z'cc', Z'cd', Z'cf', Z'd0', Z'd1', Z'd2', Z'd4',&
Z'd5', Z'd6', Z'd8', Z'd9', Z'db', Z'dc', Z'de', Z'df',&
Z'e1', Z'e2', Z'e4', Z'e6', Z'e7', Z'e9', Z'eb', Z'ed',&
Z'ee', Z'f0', Z'f2', Z'f4', Z'f6', Z'f9', Z'fb', Z'fd',&
Z'00', Z'04', Z'09', Z'0e', Z'12', Z'17', Z'1b', Z'1f',&
Z'23', Z'27', Z'2b', Z'2e', Z'32', Z'36', Z'39', Z'3c',&
Z'40', Z'43', Z'46', Z'49', Z'4c', Z'4f', Z'52', Z'55',&
Z'58', Z'5a', Z'5d', Z'60', Z'62', Z'65', Z'67', Z'6a',&
Z'6c', Z'6f', Z'71', Z'74', Z'76', Z'79', Z'8a', Z'8a',&
Z'8a', Z'82', Z'84', Z'87', Z'89', Z'8c', Z'8e', Z'91',&
Z'93', Z'96', Z'98', Z'9b', Z'9d', Z'a0', Z'a3', Z'a5',&
Z'a8', Z'ab', Z'ae', Z'b1', Z'b4', Z'b7', Z'ba', Z'bd',&
Z'c1', Z'c4', Z'c7', Z'cb', Z'cf', Z'd2', Z'd6', Z'da',&
Z'de', Z'e2', Z'e6', Z'eb', Z'ef', Z'f4', Z'f9', Z'fd',&
Z'00', Z'00', Z'01', Z'01', Z'02', Z'02', Z'03', Z'03',&
Z'04', Z'04', Z'05', Z'05', Z'05', Z'06', Z'06', Z'07',&
Z'07', Z'07', Z'08', Z'08', Z'09', Z'09', Z'09', Z'0a',&
Z'0a', Z'0a', Z'0b', Z'0b', Z'0b', Z'0c', Z'0c', Z'0c',&
Z'0c', Z'0d', Z'0d', Z'0d', Z'0e', Z'0e', Z'0e', Z'0e',&
Z'0f', Z'0f', Z'0f', Z'0f', Z'10', Z'10', Z'10', Z'11',&
Z'11', Z'11', Z'11', Z'12', Z'12', Z'12', Z'13', Z'13',&
Z'13', Z'13', Z'14', Z'14', Z'14', Z'15', Z'15', Z'15',&
Z'16', Z'16', Z'16', Z'17', Z'17', Z'17', Z'18', Z'18',&
Z'19', Z'19', Z'19', Z'1a', Z'1a', Z'1b', Z'1b', Z'1c',&
Z'1c', Z'1d', Z'1d', Z'1d', Z'1e', Z'1f', Z'1f', Z'20'/)
! ! Palette 4 */
Palette(4,:)=(/ Z'40', Z'44', Z'47', Z'4a', Z'4d', Z'50', Z'53', Z'56',& ! Rot */
Z'58', Z'5b', Z'5e', Z'60', Z'63', Z'65', Z'68', Z'6a',&
Z'6d', Z'6f', Z'71', Z'73', Z'75', Z'77', Z'79', Z'7b',&
Z'7d', Z'7f', Z'81', Z'83', Z'85', Z'87', Z'89', Z'8a',&
Z'8c', Z'8e', Z'90', Z'91', Z'93', Z'95', Z'96', Z'98',&
Z'99', Z'9b', Z'9d', Z'9e', Z'a0', Z'a2', Z'a3', Z'a5',&
Z'a6', Z'a8', Z'aa', Z'ab', Z'ad', Z'af', Z'b0', Z'b2',&
Z'b4', Z'b6', Z'b7', Z'b9', Z'bb', Z'bd', Z'bf', Z'c1',&
Z'c3', Z'c5', Z'c7', Z'c9', Z'cb', Z'cd', Z'cf', Z'd2',&
Z'd4', Z'd6', Z'd9', Z'db', Z'de', Z'e0', Z'e3', Z'e6',&
Z'e9', Z'eb', Z'ee', Z'f1', Z'f4', Z'f7', Z'fb', Z'fe',&
Z'00', Z'04', Z'09', Z'0e', Z'12', Z'17', Z'1b', Z'1f',&
Z'23', Z'27', Z'2b', Z'2e', Z'32', Z'36', Z'39', Z'3c',&
Z'40', Z'43', Z'46', Z'49', Z'4c', Z'4f', Z'52', Z'55',&
Z'58', Z'5a', Z'5d', Z'60', Z'62', Z'65', Z'67', Z'6a',&
Z'6c', Z'6f', Z'71', Z'74', Z'76', Z'79', Z'7b', Z'00',&
Z'80', Z'82', Z'84', Z'87', Z'89', Z'8c', Z'8e', Z'91',&
Z'93', Z'96', Z'98', Z'9b', Z'9d', Z'a0', Z'a3', Z'a5',&
Z'a8', Z'ab', Z'ae', Z'b1', Z'b4', Z'b7', Z'ba', Z'bd',&
Z'c1', Z'c4', Z'c7', Z'cb', Z'cf', Z'd2', Z'd6', Z'da',&
Z'de', Z'e2', Z'e6', Z'eb', Z'ef', Z'f4', Z'f9', Z'fd',&
Z'53', Z'56', Z'59', Z'5c', Z'5f', Z'61', Z'64', Z'67',&
Z'69', Z'6c', Z'6e', Z'70', Z'72', Z'75', Z'77', Z'79',&
Z'7b', Z'7d', Z'7f', Z'81', Z'83', Z'85', Z'87', Z'89',&
Z'8a', Z'8c', Z'8e', Z'8f', Z'91', Z'93', Z'94', Z'96',&
Z'98', Z'99', Z'9b', Z'9c', Z'9e', Z'9f', Z'a1', Z'a2',&
Z'a4', Z'a5', Z'a6', Z'a8', Z'a9', Z'ab', Z'ac', Z'ae',&
Z'af', Z'b1', Z'b2', Z'b4', Z'b5', Z'b7', Z'b8', Z'ba',&
Z'bb', Z'bd', Z'bf', Z'c0', Z'c2', Z'c3', Z'c5', Z'c7',&
Z'c9', Z'cb', Z'cc', Z'ce', Z'd0', Z'd2', Z'd4', Z'd6',&
Z'd8', Z'da', Z'dd', Z'df', Z'e1', Z'e3', Z'e6', Z'e8',&
Z'eb', Z'ed', Z'f0', Z'f3', Z'f5', Z'f8', Z'fb', Z'fe',&
Z'00', Z'02', Z'04', Z'06', Z'08', Z'0a', Z'0c', Z'0e',& ! Gruen */
Z'10', Z'12', Z'14', Z'15', Z'17', Z'19', Z'1a', Z'1c',&
Z'1e', Z'1f', Z'21', Z'22', Z'23', Z'25', Z'26', Z'28',&
Z'29', Z'2a', Z'2c', Z'2d', Z'2e', Z'2f', Z'31', Z'32',&
Z'33', Z'34', Z'35', Z'36', Z'37', Z'39', Z'3a', Z'3b',&
Z'3c', Z'3d', Z'3e', Z'3f', Z'40', Z'41', Z'42', Z'44',&
Z'45', Z'46', Z'47', Z'48', Z'49', Z'4a', Z'4b', Z'4d',&
Z'4e', Z'4f', Z'50', Z'51', Z'53', Z'54', Z'55', Z'57',&
Z'58', Z'59', Z'5b', Z'5c', Z'5d', Z'5f', Z'60', Z'62',&
Z'64', Z'65', Z'67', Z'68', Z'6a', Z'6c', Z'6e', Z'70',&
Z'71', Z'73', Z'75', Z'77', Z'79', Z'7c', Z'7e', Z'80',&
Z'00', Z'04', Z'09', Z'0e', Z'12', Z'17', Z'1b', Z'1f',&