libSUFR
a LIBrary of Some Useful Fortran Routines
All Classes Namespaces Files Functions Variables Pages
pgplot.f90
Go to the documentation of this file.
1!> \file pgplot.f90 Procedures to handle PGPlot (screen) settings
2
3
4! Copyright (c) 2002-2025 Marc van der Sluys - Nikhef/Utrecht University - marc.vandersluys.nl
5!
6! This file is part of the libSUFR package,
7! see: http://libsufr.sourceforge.net/
8!
9! This is free software: you can redistribute it and/or modify it under the terms of the European Union
10! Public Licence 1.2 (EUPL 1.2). This software is distributed in the hope that it will be useful, but
11! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12! PURPOSE. See the EU Public Licence for more details. You should have received a copy of the European
13! Union Public Licence along with this code. If not, see <https://www.eupl.eu/1.2/en/>.
14!
15!
16
17
18
19
20!***********************************************************************************************************************************
21!> \brief Procedures to handle PGPlot (screen) settings
22
24 implicit none
25 save
26 integer :: screen_size_h !< Horizontal screen size (pixels)
27 integer :: screen_size_v !< Vertical screen size (pixels)
28 real :: screen_dpi !< Screen resolution (DPI)
29contains
30
31
32 !*********************************************************************************************************************************
33 !> \brief Read/create PGPlot settings file ~/.PGPlot
34 !!
35 !! \param scrsz Horizontal screen size (pixels)
36 !! \param scrrat Screen ratio (height/width)
37
38 subroutine pgplot_settings(scrsz,scrrat)
39 use sufr_constants, only: homedir
41
42 implicit none
43 real, intent(out) :: scrsz,scrrat
44 integer :: io,ip,op
45 logical :: ex
46 character :: filename*(199)
47
48 ! Define namelist, file name:
49 namelist /screen_settings/ screen_size_h,screen_size_v,screen_dpi
50 filename = trim(homedir)//'/.PGPlot'
51 inquire(file=trim(filename), exist=ex)
52
53 call find_free_io_unit(ip)
54
55 if(ex) then ! Settings file exists
56
57 ! Read the settings file:
58 open(unit=ip,form='formatted',status='old',action='read',position='rewind',file=trim(filename),iostat=io)
59 if(io.ne.0) then
60 write(0,'(A,/)')' Error opening settings file '//trim(filename)//' for reading.'
61 return
62 end if
63 read(ip, nml=screen_settings, iostat=io)
64 close(ip)
65
66 if(io.ne.0) then
67 write(0,*)
68 write(0,'(A)')' An error occured when reading the settings file '//trim(filename)// &
69 ', using default settings.'
70 write(0,'(A)')' The format of your settings file may be outdated.'
71 write(0,'(A)')' Consider renaming the existing file and rerunning this program to generate a new settings file.'
72 write(0,*)
73 end if
74
75 else ! Settings file doesn't exist
76
77 ! Set default values:
78 screen_size_h = 1024
79 screen_size_v = 768
80 screen_dpi = 96. ! 96 dpi for most PCs? 72 for Macs?
81
82 write(*,*)
83 write(*,'(A)') '############################################################'
84 write(*,'(A)') '# #'
85 write(*,'(A)') '# No PGPlot settings file found. #'
86 write(*,'(A)') '# Creating '//trim(filename)//' with default settings, #'
87 write(*,'(A)') '# please edit it to set your preferences. #'
88 write(*,'(A)') '# #'
89 write(*,'(A)') '############################################################'
90 write(*,*)
91
92 end if
93
94 ! Write settings file (do this always, to update in case variables are added):
95 call find_free_io_unit(op)
96 open(unit=op,form='formatted',status='unknown',action='write',position='rewind',file=trim(filename),iostat=io)
97 if(io.ne.0) then
98 write(0,'(A,/)')' Error opening settings file '//trim(filename)//' for writing.'
99 return
100 end if
101 write(op, nml=screen_settings, iostat=io)
102 close(op)
103 if(io.ne.0) write(0,'(A)')' An error occured when writing the settings file '//trim(filename)
104
106
107 end subroutine pgplot_settings
108 !*********************************************************************************************************************************
109
110
111
112
113 !*********************************************************************************************************************************
114 !> \brief Convert PGPlot horizontal and vertical dimensions to paper size and ratio for bitmap
115 !!
116 !! \param horiz Horizontal plot size in pixels
117 !! \param vert Vertical plot size in pixels
118 !! \param size PGPlot plot size (output)
119 !! \param ratio PGPlot plot ratio (output)
120
121 pure subroutine pghv2szrat_bitmap(horiz,vert, size,ratio)
122 implicit none
123 integer, intent(in) :: horiz,vert
124 real, intent(out) :: size,ratio
125
126 size = real(horiz-1)/85.
127 ratio = real(vert-1)/real(horiz-1)
128
129 end subroutine pghv2szrat_bitmap
130 !*********************************************************************************************************************************
131
132
133 !*********************************************************************************************************************************
134 !> \brief Convert PGPlot bitmap size and ratio to horizontal and vertical dimensions in pixels
135 !!
136 !! \param size PGPlot plot size
137 !! \param ratio PGPlot plot ratio
138 !! \param horiz Horizontal plot size in pixels (output)
139 !! \param vert Vertical plot size in pixels (output)
140
141 pure subroutine pgszrat2hv_bitmap(size,ratio, horiz,vert)
142 implicit none
143 real, intent(in) :: size,ratio
144 integer, intent(out) :: horiz,vert
145
146 horiz = nint(size*85) + 1
147 vert = nint(size*ratio*85) + 1
148
149 end subroutine pgszrat2hv_bitmap
150 !*********************************************************************************************************************************
151
152
153
154 !*********************************************************************************************************************************
155 !> \brief Convert x,y screen dimensions to PGPlot paper size and ratio for a screen
156 !!
157 !! \param horiz Horizontal screen size (pixels)
158 !! \param vert Vertical screen size (pixels)
159 !! \param dpi Screen resolution in dots per inch
160 !! \param size PGPlot screen size (output)
161 !! \param ratio PGPlot screen ratio (output)
162
163 pure subroutine pghv2szrat_screen(horiz,vert, dpi, size,ratio)
164 implicit none
165 integer, intent(in) :: horiz,vert
166 real, intent(in) :: dpi
167 real, intent(out) :: size,ratio
168
169 size = real(horiz-48) / dpi
170 ratio = real(vert -48) / real(horiz-48)
171
172 end subroutine pghv2szrat_screen
173 !*********************************************************************************************************************************
174
175
176 !*********************************************************************************************************************************
177 !> \brief Convert PGPlot paper size and ratio to screen dimensions
178 !!
179 !! \param size PGPlot screen size
180 !! \param ratio PGPlot screen ratio
181 !! \param dpi Screen resolution in dots per inch
182 !! \param horiz Horizontal screen size (pixels) (output)
183 !! \param vert Vertical screen size (pixels) (output)
184
185 pure subroutine pgszrat2hv_screen(size,ratio, dpi, horiz,vert)
186 implicit none
187 real, intent(in) :: size,ratio, dpi
188 integer, intent(out) :: horiz,vert
189
190 horiz = nint(dpi*size) + 48
191 vert = nint(dpi*size*ratio) + 48
192
193 end subroutine pgszrat2hv_screen
194 !*********************************************************************************************************************************
195
196
197
198
199end module sufr_pgplot
200!***********************************************************************************************************************************
201
Provides all constants in the library, and routines to define them.
Definition constants.f90:23
character, dimension(199), public homedir
Current user's home directory (= $HOME, will contain e.g. '/home/user')
Procedures to handle PGPlot (screen) settings.
Definition pgplot.f90:23
pure subroutine pgszrat2hv_bitmap(size, ratio, horiz, vert)
Convert PGPlot bitmap size and ratio to horizontal and vertical dimensions in pixels.
Definition pgplot.f90:142
subroutine pgplot_settings(scrsz, scrrat)
Read/create PGPlot settings file ~/.PGPlot.
Definition pgplot.f90:39
integer screen_size_h
Horizontal screen size (pixels)
Definition pgplot.f90:26
pure subroutine pghv2szrat_screen(horiz, vert, dpi, size, ratio)
Convert x,y screen dimensions to PGPlot paper size and ratio for a screen.
Definition pgplot.f90:164
integer screen_size_v
Vertical screen size (pixels)
Definition pgplot.f90:27
pure subroutine pghv2szrat_bitmap(horiz, vert, size, ratio)
Convert PGPlot horizontal and vertical dimensions to paper size and ratio for bitmap.
Definition pgplot.f90:122
real screen_dpi
Screen resolution (DPI)
Definition pgplot.f90:28
pure subroutine pgszrat2hv_screen(size, ratio, dpi, horiz, vert)
Convert PGPlot paper size and ratio to screen dimensions.
Definition pgplot.f90:186
System-related procedures.
Definition system.f90:23
subroutine find_free_io_unit(unit)
Find the first unused I/O unit larger than 100.
Definition system.f90:951