36 character,
intent(in) :: message*(*)
38 write(*,
'(//,A)')
' '//trim(message)
39 write(*,
'(A,/)')
' Exiting...'
55 character,
intent(in) :: message*(*)
56 integer,
intent(in) :: status
58 write(*,
'(//,A)')
' * Warning: '//trim(
program_name)//
': '//trim(message)//
' *'
60 write(*,
'(A,/)')
' Exiting...'
63 write(*,
'(A)', advance=
'no')
' * '
80 character,
intent(in) :: message*(*)
81 integer,
intent(in) :: status
83 write(0,
'(//,A)')
' *** ERROR: '//trim(
program_name)//
': '//trim(message)//
' ***'
85 write(0,
'(A,/)')
' Exiting...'
88 write(0,
'(A)', advance=
'no')
' *** '
106 character,
intent(in) :: command*(*)
107 logical,
intent(in),
optional :: wait, quit_on_error
108 integer,
intent(in),
optional :: status
110 integer :: exitstat, cmdstat, lstatus
111 character :: cmdmsg*(1024)
112 logical :: lwait, lquit_on_error
117 lquit_on_error = .false.
118 if(
present(wait)) lwait = wait
119 if(
present(status)) lstatus = status
120 if(
present(quit_on_error)) lquit_on_error = quit_on_error
124 call execute_command_line(command, lwait, exitstat, cmdstat, cmdmsg)
126 if(lwait .and. exitstat.ne.0)
then
127 if(lquit_on_error)
then
128 call quit_program_error(
'the command "'//trim(command)//
'" was not executed correctly', lstatus)
130 call error(
'the command "'//trim(command)//
'" was not executed correctly')
134 if(cmdstat.ne.0)
then
135 if(lquit_on_error)
then
136 call quit_program_error(
'the command "'//trim(command)//
'" could not be executed: '//trim(cmdmsg), lstatus)
138 call error(
'the command "'//trim(command)//
'" could not be executed: '//trim(cmdmsg))
155 character,
intent(in) :: command*(*)
156 logical,
intent(in),
optional :: wait
157 integer,
intent(in),
optional :: status
165 if(
present(wait)) lwait = wait
166 if(
present(status)) lstatus = status
188 character,
intent(in) :: command*(*)
189 logical,
intent(in),
optional :: wait
190 integer,
intent(in),
optional :: status
193 integer :: seed,ip,ln, lstatus, iostat
195 character :: line*(1024), ranfile*(128), iomsg*(128)
201 if(
present(wait)) lwait = wait
202 if(
present(status)) lstatus = status
207 write(ranfile,
'(A,I8.8,A)') trim(
homedir)//
'/.libsufr-system-file-', nint(randble*1.d8),
'.temp'
214 open(unit=ip,form=
'formatted', status=
'old', action=
'read', position=
'rewind', file=trim(ranfile), iostat=iostat)
224 read(ip,
'(A)',iostat=iostat, iomsg=iomsg) line
256 character,
intent(in) :: command*(*)
257 logical,
intent(in),
optional :: wait
258 integer,
intent(in),
optional :: status
260 character :: return_str*(1024*10), iomsg*(1024)
262 integer :: lstatus, iostat
268 if(
present(wait)) lwait = wait
269 if(
present(status)) lstatus = status
276 if(iostat.ne.0)
call quit_program_error(
'the command "'//trim(command)//
'" did not return an integer: '//trim(iomsg), lstatus)
291 character,
intent(in) :: syntax*(*)
292 character,
intent(in),
optional :: descr*(*)
295 if(
present(descr))
write(0,
'(A)') trim(descr)
297 write(0,
'(A,/)')
'Syntax: '//trim(
program_name)//
' '//trim(syntax)
313 character,
intent(in) :: syntax*(*)
314 integer,
intent(in),
optional :: status
315 character,
intent(in),
optional :: descr*(*)
319 if(
present(descr))
write(0,
'(A)') trim(descr)
321 write(0,
'(A,/)')
'Syntax: '//trim(
program_name)//
' '//trim(syntax)
324 if(
present(status)) lstatus = status
326 if(lstatus.eq.0)
then
329 write(0,
'(A)', advance=
'no')
' *** '
348 character,
intent(in) :: filename*(*)
349 integer,
intent(in) :: filetype
350 integer,
intent(in),
optional :: ioStat
351 character,
intent(in),
optional :: ioMsg*(*)
353 select case(filetype)
355 write(0,
'(A)')
' *** '//trim(
program_name)//
': Error opening output file '//trim(filename)//
' ***'
357 write(0,
'(A)')
' *** '//trim(
program_name)//
': Error opening input file '//trim(filename)//
' ***'
359 write(0,
'(A)')
' *** '//trim(
program_name)//
', file_open_error_quit(): filetype must be 0 or 1 ***'
363 if(
present(iostat))
then
365 write(0,
'(A,I0,A)', advance=
'no')
'Error ', iostat,
' occurred'
366 if(
present(iomsg))
then
367 write(0,
'(A)')
': '//trim(iomsg)
372 else if(
present(iomsg))
then
373 if(len_trim(iomsg).gt.0)
write(0,
'(A)')
': '//trim(iomsg)
390 character,
intent(in) :: filename*(*)
391 integer,
intent(in) :: filetype
392 integer,
intent(in),
optional :: ioStat
393 character,
intent(in),
optional :: ioMsg*(*)
395 character :: ioMsgL*(999)
398 if(
present(iostat)) iostatl = iostat
400 if(
present(iomsg)) iomsgl = trim(iomsg)
404 if(iostatl.eq.0)
then
407 write(0,
'(A)', advance=
'no')
' *** '
428 character,
intent(in) :: filename*(*)
429 integer,
intent(in) :: line
430 character,
intent(in),
optional :: procedure*(*)
431 integer,
intent(in),
optional :: ioStat
432 character,
intent(in),
optional :: ioMsg*(*)
434 write(0,
'(/,A)', advance=
'no')
' *** '//trim(
program_name)
435 if(
present(procedure))
then
436 if(len_trim(procedure).gt.0)
write(0,
'(A)', advance=
'no')
', '//trim(procedure)
438 write(0,
'(A)', advance=
'no')
': Error reading input file '//trim(filename)
439 if(line.gt.0)
write(0,
'(A,I0)', advance=
'no')
', line ', line
440 if(
present(iostat))
then
441 if(iostat.ne.0)
write(0,
'(A,I0)', advance=
'no')
', status code ',iostat
443 if(
present(iomsg))
then
444 if(len_trim(iomsg).gt.0)
write(0,
'(A)', advance=
'no')
': '//trim(iomsg)
446 write(*,
'(A,/)')
' ***'
464 character,
intent(in) :: filename*(*)
465 integer,
intent(in) :: line, status
466 character,
intent(in),
optional :: procedure*(*), ioMsg*(*)
467 integer,
intent(in),
optional :: ioStat
469 character :: procedureL*(999), ioMsgL*(999)
472 if(
present(procedure)) procedurel = trim(procedure)
474 if(
present(iostat)) iostatl = iostat
476 if(
present(iomsg)) iomsgl = trim(iomsg)
483 write(0,
'(A)', advance=
'no')
' *** '
500 character,
intent(in) :: filename*(*)
501 integer,
intent(in) :: line
505 write(0,
'(/,A,/)')
' *** '//trim(
program_name)//
': Error writing input file '//trim(filename)//
' ***'
507 write(0,
'(/,A,I0,A/)')
' *** '//trim(
program_name)//
': Error writing input file '//trim(filename)//
', line ',line, &
525 character,
intent(in) :: filename*(*)
526 integer,
intent(in) :: line, status
530 write(0,
'(/,A,/)')
' *** '//trim(
program_name)//
': Error writing input file '//trim(filename)//
', aborting ***'
532 write(0,
'(/,A,I0,A/)')
' *** '//trim(
program_name)//
': Error writing input file '//trim(filename)//
', line ',line, &
539 write(0,
'(A)', advance=
'no')
' *** '
555 character,
intent(in) :: filename*(*)
557 write(0,
'(/,A,/)')
' *** '//trim(
program_name)//
': Error while reading input file '//trim(filename)// &
558 ': reached the end of the file ***'
573 character,
intent(in) :: filename*(*)
574 integer,
intent(in) :: status
576 write(0,
'(/,A,/)')
' *** '//trim(
program_name)//
': Error while reading input file '//trim(filename)// &
577 ': reached the end of the file ***'
582 write(0,
'(A)', advance=
'no')
' *** '
603 character,
intent(in) :: filename*(*)
604 integer,
intent(in) :: line, readstatus, stopcode, exitstatus
605 character,
intent(in),
optional :: message*(*)
607 select case(readstatus)
609 if(stopcode.eq.0)
then
615 if(stopcode.eq.0)
then
616 if(
present(message))
then
622 if(
present(message))
then
648 character,
intent(in) :: message*(*)
649 integer,
intent(in),
optional :: unit
654 if(
present(unit)) lunit = unit
655 if(lunit.ne.6) lunit = 0
657 write(lunit,
'(/,A,/)')
' * Warning: '//trim(
program_name)//
': '//trim(message)//
' *'
673 character,
intent(in) :: message*(*)
674 integer,
intent(in),
optional :: unit
679 if(
present(unit)) lunit = unit
680 if(lunit.ne.0) lunit = 6
682 write(lunit,
'(/,A,/)')
' *** ERROR: '//trim(
program_name)//
': '//trim(message)//
' ****'
708 integer,
intent(out) :: year,month,day, hour,minute
709 real(double),
intent(out) :: second
710 real(double),
intent(out),
optional :: tz
719 if(
present(tz)) tz = dble(dt(4))/60.d0
723 second = dble(dt(7)) + dble(dt(8))*1.d-3
748 jd =
ymdhms2jd( dt(1), dt(2), dt(3), dt(5), dt(6)-dt(4), dble(dt(7))+dble(dt(8))/1.d3 )
749 djd = jd -
ymdhms2jd(1970, 1, 1, 0, 0, 0.d0)
767 integer,
parameter :: nsteps = 100
768 real(double),
intent(in) :: frac
769 real(double),
intent(in),
optional :: timestamp0
774 perc = nint(frac*nsteps)
775 write(*,
'(A,I3,A)',advance=
'no')
' Progress: ',perc,
'% ['
778 write(*,
'(A1)',advance=
'no')
'#'
780 write(*,
'(A1)',advance=
'no')
' '
784 if(
present(timestamp0))
then
785 write(*,
'(A,A9)')
'] Est.time left:',
tms((
timestamp()-timestamp0)*(1.d0-frac)/frac/3600.d0)
804 real(
double),
intent(in) :: t
807 character ::
tms*(8),ss*(4)
811 s = (a-m/60.d0)*3600.d0
814 if(nint(s*10).lt.100)
write(ss,
'(A1,F3.1)')
'0',s
815 write(
tms,
'(I2.2,A1,A4,A1)') m,
'm',ss,
's'
833 integer,
intent(in),
optional :: calltype, sp, dec
834 integer :: loc_calltype, loc_sp, loc_dec
836 integer,
save :: firstcall
837 real(double),
save :: oldcputime,oldwalltime
839 integer(long) :: count, count_rate, count_max
840 real(double) :: cputime, walltime
841 character :: fmt*(99)
845 if(firstcall.eq.213546879) loc_calltype = 3
846 if(
present(calltype)) loc_calltype = calltype
849 if(
present(sp)) loc_sp = sp
852 if(
present(dec)) loc_dec = dec
856 call cpu_time(cputime)
859 call system_clock(count, count_rate, count_max)
860 if(count_rate.gt.0.d0)
then
861 walltime = dble(count)/dble(count_rate)
867 if(loc_calltype.ge.2)
then
868 if(firstcall.ne.213546879)
then
869 call warn(
'libSUFR print_runtime(): loc_calltype should be 1 on the first call', 0)
874 write(fmt,
'(A,I0,A)')
'(A,2(F0.',max(0,loc_dec),
',A))'
876 write(fmt,
'(A,I0,A,I0,A)')
'(',max(0,loc_sp),
'x,A,2(F0.',max(0,loc_dec),
',A))'
878 write(*,trim(fmt))
'Program took ',walltime-oldwalltime,
' seconds of wall time and ',cputime-oldcputime, &
879 ' seconds of CPU time.'
883 if(loc_calltype.le.2)
then
885 oldwalltime = walltime
887 firstcall = 213546879
904 integer,
intent(in),
optional :: sp, dec, unit
905 integer :: loc_sp, loc_dec, loc_unit
907 real(double) :: cputime
908 character :: fmt*(99)
912 if(
present(sp)) loc_sp = sp
915 if(
present(dec)) loc_dec = dec
918 if(
present(unit)) loc_unit = max(unit, 0)
921 call cpu_time(cputime)
925 write(fmt,
'(A,I0,A)')
'(A,2(F0.',max(0,loc_dec),
',A))'
927 write(fmt,
'(A,I0,A,I0,A)')
'(',max(0,loc_sp),
'x,A,2(F0.',max(0,loc_dec),
',A))'
930 if(loc_unit.eq.6)
then
931 write(*,trim(fmt))
'Program took ',cputime,
' seconds of CPU time.'
933 write(unit,trim(fmt))
'Program took ',cputime,
' seconds of CPU time.'
952 integer,
intent(out) :: unit
955 do unit=101,huge(unit)-1
956 inquire(unit=unit, opened=status)
974 integer,
intent(in) :: unit, nLines
995 integer,
intent(inout) :: int1,int2
1015 real,
intent(inout) :: rl1,rl2
1036 real(
double),
intent(inout) :: dbl1,dbl2
1055 character,
intent(inout) :: str1*(*),str2*(*)
1056 character :: str0*(max(len(str1),len(str2)))
1058 if(len_trim(str1).gt.len(str2) .or. len_trim(str2).gt.len(str1)) &
1059 call warn(
'libSUFR - swapstr(): partial loss of characters when swapping strings', 0)
Provides all constants in the library, and routines to define them.
character, dimension(4), parameter, public cursorup
Print this to move the cursor up one line on screen (need 2 lines since print gives a hard return)
character, dimension(2), parameter, public newline
Newline character: ASCII Carriage Return (13) + Line Feed (10)
character, dimension(199), public program_name
Name of the currently running program, without the path.
character, dimension(199), public homedir
Current user's home directory (= $HOME, will contain e.g. '/home/user')
Procedures for manipulation of date and time.
elemental real(double) function ymdhms2jd(yy, mmo, dd, h, m, s)
Convert date and time (y,m,d, h,m,s) to JD. Input and output in UT.
Module containing dummy variables for all kinds.
character dumstr
Dummy character.
character, dimension(99) dumstr99
Dummy string of length 99.
Provides kinds and related constants/routines.
integer, parameter double
Double-precision float. Precision = 15, range = 307.
integer, parameter long
Long integer.
Procedures to generate random numbers.
integer function get_ran_seed(degree, date_array)
Use the system clock to get a random initialisation seed (i.e., negative integer) for a random-numbed...
real(double) function ran_unif(seed)
Generate a pseudo-random number from a uniform distribution 0 < r < 1.
System-related procedures.
subroutine print_runtimes(calltype, sp, dec)
Print run times: wall time and CPU time.
subroutine file_read_error(filename, line, procedure, iostat, iomsg)
Print a message to StdErr on file read error.
subroutine error(message, unit)
Print an error to StdOut or StErr.
subroutine quit_program_error(message, status)
Print an error message to StdErr and stop the execution of the current program.
subroutine file_read_end_error(filename, line, readstatus, stopcode, exitstatus, message)
Print a message to StdErr on read error or reaching the end of a file while reading,...
subroutine file_read_error_quit(filename, line, status, procedure, iostat, iomsg)
Print a message to StdErr on file read error, and stop the execution of the current program.
subroutine find_free_io_unit(unit)
Find the first unused I/O unit larger than 100.
subroutine file_end_quit(filename, status)
Print a message to StdErr on reaching the end of a file while reading, and stop the code.
subroutine warn(message, unit)
Print a warning to StdOut or StErr.
subroutine file_open_error(filename, filetype, iostat, iomsg)
Print a message to StdErr upon file open error.
pure character function, dimension(8) tms(t)
Print time as mm:ss.s string, input in hours.
real(double) function timestamp()
Return the time stamp in seconds since 1970-01-01 00:00:00 UTC.
subroutine file_end_error(filename)
Print a message to StdErr on reaching the end of a file while reading.
subroutine quit_program_warning(message, status)
Print a warning to StdOut and stop the execution of the current program.
subroutine execute_command_line_quit_on_error(command, wait, status)
Execute a shell command. Upon error, print a message and stop the execution of the current program.
subroutine quit_program(message)
Print a message to StdOut and stop the execution of the current program.
character function, dimension(1024 *10) execute_command_line_and_return_str(command, wait, status)
Execute a shell command and return the result as a string.
subroutine print_cputime(sp, dec, unit)
Print CPU time since the first execution of the program.
subroutine execute_command_line_verbose(command, wait, status, quit_on_error)
Execute a shell command and print a message upon error. Optionally stop the execution of the current ...
subroutine file_write_error_quit(filename, line, status)
Print a message to StdErr on file write error, and stop the execution of the current program.
subroutine syntax_print(syntax, descr)
Print a syntax message to StdErr.
subroutine printprogressbar(frac, timestamp0)
Print a text progress bar to the screen, optionally with estimated time left.
subroutine syntax_quit(syntax, status, descr)
Print a syntax message to StdErr and stop the execution of the current program.
pure subroutine swapint(int1, int2)
Swap two integer variables.
integer function execute_command_line_and_return_int(command, wait, status)
Execute a shell command and return the result as an integer.
subroutine file_open_error_quit(filename, filetype, iostat, iomsg)
Print a message to StdErr on file open error, and stop the execution of the current program.
subroutine swapstr(str1, str2)
Swap two strings.
subroutine file_write_error(filename, line)
Print a message to StdErr on file write error.
pure subroutine swapreal(rl1, rl2)
Swap two single-precision real variables.
pure subroutine swapdbl(dbl1, dbl2)
Swap two double-precision real variables.
subroutine file_skip_header(unit, nlines)
Skip the next (e.g. first) lines of a file.
subroutine system_time(year, month, day, hour, minute, second, tz)
Get date and time from the system clock.