51 logical :: exist = .false.
55 character(len=256) :: fn
57 character(len=256) :: fnloc
61 procedure,
public, pass :: init =>
fn_init
63 procedure,
public, pass :: kill =>
fn_kill
87 function ioerr(lun, errno, call_proc, add_msg, add_int)
result(rc)
89 integer,
intent(in) :: lun
90 integer,
intent(in) :: errno
91 character(len=*),
intent(in) :: call_proc
92 character(len=*),
intent(in),
optional :: add_msg
93 integer,
intent(in),
optional :: add_int
96 character(len=256) :: msg
99 if (
present(add_msg))
then
101 if (
present(add_int))
then
111 write (lun, *)
' *************'
112 if (errno .gt. 100)
then
113 write (lun, fmt=100)
' SEVERE ERROR:'
114 write (lun, fmt=101)
' in procedure: ', trim(call_proc)
115 write (lun, fmt=101) trim(
errmsg(errno, trim(msg), int))
116 stop
'EXECUTION TERMINATED IN PROC IOerr'
117 else if (errno .gt. 0)
then
118 write (lun, fmt=100)
' WARNING ERROR:'
119 write (lun, fmt=101)
'in procedure: ', trim(call_proc)
120 write (lun, fmt=101)
etb((
errmsg(errno, trim(msg), int)))
123 write (lun, fmt=100)
' IO ERROR NUMBER not found'
124 stop
'EXECUTION TERMINATED IN PROC IOerr'
127100
format(1x, a, 1x, i5)
140 function errmsg(errno, addmsg, addint)
result(msg)
142 integer,
intent(in) :: errno
143 character(len=*),
intent(in) :: addmsg
144 integer,
intent(in) :: addint
145 character(len=256) :: msg
147 character(len=5) :: rdwr
149 if (addint .eq. 0)
then
152 write (rdwr,
'(i5)') addint
157 msg =
'File or Directory '//trim(addmsg)//
' (unit '//rdwr//
') does not exist.'
159 msg =
'Error Reading File '//trim(addmsg)//
' (unit '//rdwr//
')'
161 msg =
'Error Writing File '//trim(addmsg)//
' (unit '//rdwr//
')'
163 msg =
'Error In Input/Output Parameter '//trim(addmsg)//
' (info='//rdwr//
')'
165 msg =
'Error In Input Parameter '//trim(addmsg)//rdwr//
')'
167 msg =
'Error In Output Parameter '//trim(addmsg)//rdwr//
')'
169 msg =
'File or Directory '//trim(addmsg)//
' (unit '//rdwr//
') does not exist.'
171 msg =
' ...error reading file '//trim(addmsg)//
' (iostat='//rdwr//
')'
173 msg =
' ...error writing file '//trim(addmsg)//
' (iostat='//rdwr//
')'
175 msg =
'Error In Input Parameter '//trim(addmsg)//
' ( '//rdwr//
' )'
177 msg =
'Error In Output Parameter '//trim(addmsg)
179 msg =
' ...alloc fail var '//trim(addmsg)//
' (stat='//rdwr//
')'
181 msg =
' ...dealloc fail var '//trim(addmsg)//
' (stat='//rdwr//
')'
183 msg =
' ...VTK library: '//trim(addmsg)//rdwr
185 msg =
' ...wrong parameter value: '//trim(addmsg)//rdwr
187 msg =
' no known error number'
204 character(len=*),
intent(in) :: strin
205 character(len=len(strIn)) :: strout
210 select case (strin(i:i))
212 strout(i:i) = achar(iachar(strin(i:i)) - 32)
229 character(len=*),
intent(in) :: strin
230 character(len=len(strIn)) :: strout
235 select case (strin(i:i))
237 strout(i:i) = achar(iachar(strin(i:i)) + 32)
239 strout(i:i) = strin(i:i)
250 function etb(strIn)
result(strOut)
252 character(len=*),
intent(in) :: strin
253 character(len=len_trim(adjustl(strIn))) :: strout
255 strout = trim(adjustl(strin))
272 character(len=*),
intent(in) :: strin
273 character(len=len_trim(adjustl(strIn))) :: strout
275 character(len=1) :: strloc
278 do i = 1, len_trim(adjustl(strin))
280 if (strloc .eq.
'!' .or. strloc .eq.
'%' .or. strloc .eq.
'#')
then
281 do j = i, len_trim(adjustl(strin))
304 function avg_vec3(avg_type, vecA, vecB, vecC)
result(res_avg)
306 integer,
intent(in) :: avg_type
307 real(kind=
double),
intent(in) :: veca(3)
308 real(kind=
double),
intent(in) :: vecb(3)
309 real(kind=
double),
intent(in),
optional :: vecc(3)
310 real(kind=
double) :: res_avg(3)
314 if (
present(vecc))
then
316 select case (avg_type)
319 res_avg(i) =
avg_scal(avg_type, veca(i), vecb(i), vecc(i))
324 select case (avg_type)
327 res_avg(i) =
avg_scal(avg_type, veca(i), vecb(i))
346 function avg_scal(avg_type, A, B, C)
result(res_avg)
348 integer,
intent(in) :: avg_type
349 real(kind=
double),
intent(in) :: a
350 real(kind=
double),
intent(in) :: b
351 real(kind=
double),
intent(in),
optional :: c
352 real(kind=
double) :: res_avg
358 select case (avg_type)
364 select case (avg_type)
379 function cross(vecA, vecB)
result(res_cross)
381 real(kind=
double),
intent(in) :: veca(3)
382 real(kind=
double),
intent(in) :: vecb(3)
383 real(kind=
double) :: res_cross(3)
385 res_cross(1) = veca(2)*vecb(3) - veca(3)*vecb(2)
386 res_cross(2) = veca(3)*vecb(1) - veca(1)*vecb(3)
387 res_cross(3) = veca(1)*vecb(2) - veca(2)*vecb(1)
401 integer,
intent(in) :: narray
402 integer,
intent(inout) :: array(narray)
405 integer :: i, j, indx, isgn
407 if (narray .lt. 2)
return
415 if (indx .gt. 0)
then
420 else if (indx .lt. 0)
then
423 if (array(i) .lt. array(j)) isgn = -1
424 if (array(i) .gt. array(j)) isgn = +1
425 else if (indx .eq. 0)
then
442 integer,
intent(in) :: n_elements
443 integer,
intent(inout) :: elements(n_elements)
444 integer,
intent(inout) :: nunique
446 integer :: unique_index, unique_element, current_element, i
449 if (n_elements <= 1)
return
452 unique_element = elements(1)
455 current_element = elements(i)
456 if (current_element .ne. unique_element)
then
459 nunique = nunique + 1
460 elements(nunique) = current_element
461 unique_element = current_element
479 integer,
intent(in) :: n
480 integer,
intent(in) :: a(n)
481 integer,
intent(in) :: b(n)
482 logical :: a_before_b
488 if (a(i) .gt. b(i))
then
491 else if (a(i) .lt. b(i))
then
602 integer(kind=4),
save :: i_save = 0
606 integer(kind=4),
save :: j_save = 0
607 integer(kind=4),
save :: k = 0
608 integer(kind=4),
save :: k1 = 0
610 integer(kind=4),
save :: n1 = 0
624 else if (indx < 0)
then
672 else if (indx == 1)
then
682 if (i_save == n1)
then
689 else if (i_save <= n1)
then
728 function ifind(narray, array, tobefound)
result(i)
730 integer,
intent(in) :: narray
731 integer,
intent(in) :: tobefound
732 integer,
intent(in) :: array(narray)
738 found = (array(i) .eq. tobefound)
739 do while ((.not. found) .and. (i .lt. narray))
741 found = (array(i) .eq. tobefound)
743 if (.not. found) i = 0
814 real(kind=
double),
allocatable :: a_temp(:)
819 integer(kind=4) istart
824 allocate (a_temp(m), stat=res)
825 if (res .ne. 0)
write (*, *)
' Error allocation double double_col_permute'
829 if (p(istart) < 0)
then
833 else if (p(istart) == istart)
then
835 p(istart) = -p(istart)
840 a_temp(1:m) = a(1:m, istart)
852 if (iget < 1 .or. n < iget)
then
854 write (*,
'(a)')
'R8COL_PERMUTE - Fatal error!'
855 write (*,
'(a)')
' A permutation index is out of range.'
856 write (*,
'(a,i8,a,i8)')
' P(', iput,
') = ', iget
860 if (iget == istart)
then
861 a(1:m, iput) = a_temp(1:m)
865 a(1:m, iput) = a(1:m, iget)
879 deallocate (a_temp, stat=res)
880 if (res .ne. 0)
write (*, *)
' Error deallocation double double_col_permute'
951 integer(kind=4) :: a(m, n)
952 integer(kind=4),
allocatable :: a_temp(:)
957 integer(kind=4) istart
962 allocate (a_temp(m), stat=res)
963 if (res .ne. 0)
write (*, *)
' Error allocation double double_col_permute'
967 if (p(istart) < 0)
then
971 else if (p(istart) == istart)
then
973 p(istart) = -p(istart)
978 a_temp(1:m) = a(1:m, istart)
990 if (iget < 1 .or. n < iget)
then
992 write (*,
'(a)')
'integer COL_PERMUTE - Fatal error!'
993 write (*,
'(a)')
' A permutation index is out of range.'
994 write (*,
'(a,i8,a,i8)')
' P(', iput,
') = ', iget
998 if (iget == istart)
then
999 a(1:m, iput) = a_temp(1:m)
1003 a(1:m, iput) = a(1:m, iget)
1017 deallocate (a_temp, stat=res)
1018 if (res .ne. 0)
write (*, *) &
1019 ' Error deallocation double double_col_permute'
1032 function p_norm(ndata, power, data, weight)
result(total)
1034 integer,
intent(in) :: ndata
1035 real(kind=
double),
intent(in) :: power
1036 real(kind=
double),
intent(in) ::
data(ndata)
1037 real(kind=
double),
intent(in),
optional :: weight(ndata)
1038 real(kind=
double) :: total
1041 real(kind=
double) :: ddot
1043 if (abs(power) <
small)
then
1044 total = maxval(abs(data))
1046 if (
present(weight))
then
1048 total = ddot(ndata, abs(data), 1, weight, 1)
1052 total = total + abs(
data(i))**power*weight(i)
1054 total = total**(
one/power)
1058 total = sum(abs(data))
1062 total = total + abs(
data(i))**power
1064 total = total**(
one/power)
1082 integer,
intent(in) :: dim
1083 integer,
intent(in) :: nvectors
1084 real(kind=
double),
intent(in) :: vectors(dim, nvectors)
1085 real(kind=
double),
intent(inout) :: x(dim)
1088 real(kind=
double) :: ddot, alpha, beta
1091 beta = ddot(dim, vectors(1, i), 1, x, 1)
1092 alpha = -beta/ddot(dim, vectors(1, i), 1, vectors(1, i), 1)
1094 call daxpy(dim, alpha, vectors(1, i), 1, x, 1)
1110 integer,
intent(in) :: ndim
1111 real(kind=
double),
intent(in) :: vector(ndim)
1112 real(kind=
double),
intent(in) :: normal(ndim)
1113 real(kind=
double),
intent(out) :: res_proj(ndim)
1115 real(kind=
double) :: alpha, beta
1116 real(kind=
double) :: ddot
1118 beta = ddot(ndim, vector, 1, normal, 1)
1119 alpha = -beta/ddot(ndim, normal, 1, normal, 1)
1121 call dcopy(ndim, vector, 1, res_proj, 1)
1122 call daxpy(ndim, alpha, normal, 1, res_proj, 1)
1135 class(
file),
intent(in) :: this
1136 integer,
intent(in) :: lun
1138 write (lun,
'(a,a,a,i3)')
' filename ',
etb(this%fn), &
1139 ' linked to lun ', this%lun
1151 character(len=*),
intent(in) :: str_file
1152 character(len=len_trim(adjustl(str_file))) :: str_dir
1154 integer :: nstr, pbar
1158 nstr = len(
etb(str_file))
1159 pbar = scan(
etb(str_file),
"/", back=.true.)
1160 if (pbar .eq. 0)
then
1163 str_dir(1:pbar) = str_file(1:pbar)
1192 subroutine fn_init(this, lun_err, fn, lun, io_flag, &
1193 mandatory_input, folder, verbose, info)
1195 class(
file),
intent(inout) :: this
1196 integer,
intent(in) :: lun_err
1197 character(len=*),
intent(in) :: fn
1198 integer,
intent(in) :: lun
1199 character(len=*),
intent(in) :: io_flag
1200 logical,
intent(in),
optional :: mandatory_input
1201 logical,
intent(in),
optional :: folder
1202 logical,
intent(in),
optional :: verbose
1203 integer,
intent(inout),
optional :: info
1205 logical :: exist, file_exist, rc, mandatory, open_unit, printmsg
1212 if (
present(mandatory_input)) mandatory = mandatory_input
1215 if (
present(verbose)) printmsg = verbose
1217 if (
present(info)) info = 0
1221 if (
present(folder)) open_unit = .not. folder
1226 if (io_flag .eq.
'in')
then
1227 inquire (
file=this%fn, exist=exist)
1229 if (.not. exist)
then
1232 file_exist =
ioerr(lun_err,
err_io,
'file%init', &
1233 ' mandatory named :'//
etb(this%fn)//
' not found', lun)
1236 file_exist =
ioerr(lun_err,
wrn_io,
'file%init', &
1237 ' optional named : '//
etb(this%fn)//
' not found', lun)
1239 if (
present(info)) info = -1
1247 open (lun,
file=this%fn, iostat=res)
1250 'err opening file '//
etb(this%fn), lun)
1263 class(
file),
intent(inout) :: this
1264 integer,
intent(in) :: lun_err
1266 logical :: rc, is_open
1269 inquire (this%lun, opened=is_open)
1271 close (this%lun, iostat=res)
1274 'err closing file '//
etb(this%fn), res)
1275 this%exist = .false.
character(len=256) function errmsg(errno, addmsg, addint)
Return message depending on input number.
real(kind=double) function, dimension(3) cross(veca, vecb)
Function that calculates cross-products.
subroutine integer_col_permute(m, n, p, a)
integer_col_permute
real(kind=double) function, dimension(3) avg_vec3(avg_type, veca, vecb, vecc)
Function that calculates vectors averages.
integer, parameter err_val
Error in parameter value.
integer, parameter err_alloc
Error allocation failed.
integer, parameter err_vtk
Error VTK library.
subroutine global_heapsort(n, indx, i, j, isgn)
global_heapsort
subroutine fn_init(this, lun_err, fn, lun, io_flag, mandatory_input, folder, verbose, info)
Static constructor for globals::file.
subroutine fn_kill(this, lun_err)
Static destructor for globals::file.
character(len=len_trim(adjustl(strin))) function erase_comment(strin)
Erase comments from a string.
subroutine fn_print(this, lun)
Info procedure for globals::file.
real(kind=double) function avg_scal(avg_type, a, b, c)
Function that calculates scalar averages.
integer, parameter err_write
Error writing file.
integer, parameter wrn_io
File or directory does not exist.
character(len=len_trim(adjustl(strin))) function etb(strin)
Return string strin with no preceding and trailing spaces.
character(len=len(strin)) function to_upper(strin)
Transform string to upper case.
logical function lexicographic_order(n, a, b)
Check if the first array is in lexicographic order with respect to the second.
integer, parameter wrn_inp
Error in input parameter.
subroutine double_col_permute(m, n, p, a)
double_col_permute
integer, parameter err_inp
Error in input parameter.
real(kind=double) function p_norm(ndata, power, data, weight)
Evaluates the weighted p-norm.
subroutine orthogonal_projection(ndim, vector, normal, res_proj)
Procedure that computes the projection of a vector onto the plane orthogonal to another vector (norma...
integer, parameter wrn_out
Error in outour parameter.
integer, parameter err_dealloc
Error deallocation failed.
subroutine ortogonalize(dim, nvectors, vectors, x)
Procedure orthogonalizing a vector w.r.t. a a set of vectors.
integer, parameter wrn_write
Error writing file.
integer, parameter err_out
Error in outour parameter.
character(len=len(strin)) function to_lower(strin)
Transform string to lowercase case.
logical function ioerr(lun, errno, call_proc, add_msg, add_int)
Handle and write alert I/O warnings and errors.
integer function ifind(narray, array, tobefound)
ifind
subroutine unique_of_sorted(n_elements, elements, nunique)
Given a sorted array, it is returned with the list of uniques elements in the first positions.
character(len=len_trim(adjustl(str_file))) function get_dirname(str_file)
integer, parameter err_read
Error reading file.
integer, parameter wrn_read
Error reading file.
subroutine isort(narray, array)
Simple sort algorithm to sort in increasing order an integer array. To be used only for small array....
integer, parameter wrn_val
Error in input/outour parameter.
integer, parameter err_io
File or directory does not exist.
This module contains global variables and utility functions. Detailed description of the module.
real(kind=double), parameter onehalf
real(kind=double), parameter onethird
real(kind=double), parameter small
real(kind=double), parameter zero
integer, parameter double
Double precision parameter for real variables.
real(kind=double), parameter one