Debian Codegraph @

src/pagecolours.f90

raw
1 !-----------------------------------------------------------------
2 !
3 ! This file is (or was) part of SPLASH, a visualisation tool
4 ! for Smoothed Particle Hydrodynamics written by Daniel Price:
5 !
6 ! http://users.monash.edu.au/~dprice/splash
7 !
8 ! SPLASH comes with ABSOLUTELY NO WARRANTY.
9 ! This is free software; and you are welcome to redistribute
10 ! it under the terms of the GNU General Public License
11 ! (see LICENSE file for details) and the provision that
12 ! this notice remains intact. If you modify this file, please
13 ! note section 2a) of the GPLv2 states that:
14 !
15 ! a) You must cause the modified files to carry prominent notices
16 ! stating that you changed the files and the date of any change.
17 !
18 ! Copyright (C) 2005-2010 Daniel Price. All rights reserved.
19 ! Contact: [email protected]
20 !
21 !-----------------------------------------------------------------
22
23 !----------------------------------------------------------
24 ! module handling page colour schemes, for generic
25 ! plotting library
26 !----------------------------------------------------------
27 module pagecolours
28 implicit none
29 integer, parameter :: maxpagecolours = 2
30
31 contains
32
33 !----------------------------------------------------------
34 ! query function for the colour scheme
35 !----------------------------------------------------------
36 function pagecolourscheme(ischeme,short)
37 integer, intent(in) :: ischeme
38 character(len=21) :: pagecolourscheme
39 logical, intent(in), optional :: short
40 logical :: use_short
41
42 use_short = .false.
43 if (present(short)) use_short = short
44
45 select case(ischeme)
46 case(2)
47 pagecolourscheme = 'white-on-black'
48 case(1)
49 pagecolourscheme = 'black-on-white'
50 case default
51 if (use_short) then
52 pagecolourscheme = 'default'
53 else
54 pagecolourscheme = 'plot library default'
55 endif
56 end select
57
58 end function pagecolourscheme
59
60 !----------------------------------------------------------
61 ! set the colour index 1 and 0 of the plotting library
62 ! corresponding to the foreground and background colours
63 ! (must be called after the plot library is initialised)
64 !----------------------------------------------------------
65 subroutine set_pagecolours(ischeme)
66 use plotlib, only:plot_scr
67 integer, intent(in) :: ischeme
68
69 select case(ischeme)
70 case(2) !--white-on-black
71 call plot_scr(0,0.,0.,0.)
72 call plot_scr(1,1.,1.,1.)
73 case(1) !--black-on-white
74 call plot_scr(0,1.,1.,1.)
75 call plot_scr(1,0.,0.,0.)
76 end select
77
78 end subroutine set_pagecolours
79
80 !----------------------------------------------------------
81 ! query function for the name of the foreground colour
82 !----------------------------------------------------------
83 function colour_fore(ischeme)
84 integer, intent(in) :: ischeme
85 character(len=5) :: colour_fore
86
87 select case(ischeme)
88 case(2)
89 colour_fore = 'white'
90 case(1)
91 colour_fore = 'black'
92 case default
93 colour_fore = ' '
94 end select
95
96 end function colour_fore
97
98 !----------------------------------------------------------
99 ! query function for the name of the background colour
100 !----------------------------------------------------------
101 function colour_back(ischeme)
102 integer, intent(in) :: ischeme
103 character(len=5) :: colour_back
104
105 select case(ischeme)
106 case(2)
107 colour_back = 'black'
108 case(1)
109 colour_back = 'white'
110 case default
111 colour_back = ' '
112 end select
113
114 end function colour_back
115
116 !----------------------------------------------------------
117 ! write line colours to file
118 !----------------------------------------------------------
119 subroutine write_coloursfile(filename,nc,linecolours)
120 character(len=*), intent(in) :: filename
121 integer, intent(in) :: nc
122 real, intent(in) :: linecolours(3,nc)
123 integer :: i,ierr
124 integer, parameter :: lu = 37
125
126 open(unit=lu,file=trim(filename),status='replace',iostat=ierr)
127 do i=1,nc
128 write(lu,"(3(f8.3,1x))") linecolours(:,i)
129 enddo
130 close(lu)
131
132 end subroutine write_coloursfile
133
134 !----------------------------------------------------------
135 ! read line colours from file
136 !----------------------------------------------------------
137 subroutine read_coloursfile(filename,maxc,linecolours,nc,ierr)
138 character(len=*), intent(in) :: filename
139 integer, intent(in) :: maxc
140 real, intent(out) :: linecolours(3,maxc)
141 integer, intent(out) :: nc,ierr
142 integer :: i
143 integer, parameter :: lu = 38
144
145 ierr = 0
146 nc = 0
147 open(unit=lu,file=trim(filename),status='old',iostat=ierr)
148 if (ierr /= 0) return
149 do i=1,maxc
150 read(lu,*,iostat=ierr) linecolours(:,i)
151 if (ierr==0) nc = nc + 1
152 enddo
153 if (nc > 0) ierr = 0 ! this is successful
154 close(lu)
155
156 end subroutine read_coloursfile
157
158 !----------------------------------------------------------
159 ! read line colours from file
160 !----------------------------------------------------------
161 subroutine set_linecolours(linepalette,filename,maxc,linecolours)
162 use plotlib, only:plot_scr,plot_set_palette,plotlib_maxpalette
163 character(len=*), intent(in) :: filename
164 integer, intent(in) :: linepalette,maxc
165 real, intent(out) :: linecolours(3,maxc)
166 integer :: i,nc,ierr
167
168 if (linepalette > 0 .and. linepalette <= plotlib_maxpalette) then
169 call plot_set_palette(linepalette)
170 elseif (linepalette < 0) then
171 call read_coloursfile(filename,maxc,linecolours,nc,ierr)
172 do i=1,nc
173 call plot_scr(i+1,linecolours(1,i),linecolours(2,i),linecolours(3,i))
174 enddo
175 endif
176
177 end subroutine set_linecolours
178
179 end module pagecolours