libSUFR
a LIBrary of Some Useful Fortran Routines
All Classes Namespaces Files Functions Variables Pages
time2string.f90
Go to the documentation of this file.
1
2!> \file time2string.f90 Procedures to convert time to formatted text strings
3
4
5! Copyright (c) 2002-2025 Marc van der Sluys - Nikhef/Utrecht University - marc.vandersluys.nl
6!
7! This file is part of the libSUFR package,
8! see: https://libsufr.sourceforge.net/
9!
10! This is free software: you can redistribute it and/or modify it under the terms of the European Union
11! Public Licence 1.2 (EUPL 1.2). This software is distributed in the hope that it will be useful, but
12! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13! PURPOSE. See the EU Public Licence for more details. You should have received a copy of the European
14! Union Public Licence along with this code. If not, see <https://www.eupl.eu/1.2/en/>.
15!
16!
17
18
19
20!Time:
21! hms: Returns time as hh:mm:ss string, input in hours (8)
22! hms2: Print time as string in hh:mm:ss, input in hours, output between -12 and 12 (9)
23! ums: Returns time as 00u11m22s string, input in hours (9)
24! hms_s: Print time as string in hms.s, input in hours (10)
25! hms_sss: Print time as string in hms.sss, input in hours (12)
26! hmm: Print time as string in hm.m, input in hours
27! umm: Print time as string in 00u11.2m, input in hours
28! hm: Returns time as string in hh:mm, input in hours (5)
29!
30! um: Returns time as string in 11u22m, input in hours (6)
31! wum: Returns time as HTML string in 11u22m, input in hours (28)
32! wumm: Returns time as HTML string in 11u22.3m, input in hours (30)
33! wums: Returns time as HTML string in 11u22m33s, input in hours (42)
34! wums_s: Returns time as HTML string in 11u22m33.4s, input in hours (44)
35! hm2: Returns time as string in +/-hh:mm, input in hours, between -12 and 12
36! hdm: Returns time as string in hh.mm, a . iso :, input in hours
37! tms: Returns time as mm:ss string, input in hours
38! tms2: Returns time as +/-mm:ss.s string, input in hours (9)
39! tmsss2: Returns time as m:ss.s string, input in hours (8)
40
41
42
43!***********************************************************************************************************************************
44!> \brief Procedures to convert time to formatted text strings
45
47 implicit none
48 save
49
50contains
51
52 !*********************************************************************************************************************************
53 !> \brief Print time as hh:mm:ss string, input in hours; Display '--:--:--' for t=0
54 !!
55 !! \param t Time (h)
56 !! \retval hms Time as hh:mm:ss string
57
58 elemental function hms(t)
59 use sufr_kinds, only: double
60 use sufr_constants, only: r2h,h2r
61 use sufr_angles, only: rev
62 use sufr_numerics, only: deq0
63
64 implicit none
65 real(double), intent(in) :: t
66 real(double) :: t1
67 integer :: h,m,s
68 character :: hms*(8)
69
70 t1 = rev(t*h2r)*r2h
71 h = int(t1)
72 m = int((t1-h)*60.d0)
73 s = nint((t1-h-m/60.d0)*3600.d0)
74
75 if(s.ge.60) then
76 s = s-60
77 m = m+1
78 end if
79 if(m.ge.60) then
80 m = m-60
81 h = h+1
82 end if
83 if(h.ge.24) h = h-24
84
85 write(hms,'(I2.2,2(A1,I2.2))') h,':',m,':',s
86 if(deq0(t)) write(hms,'(A8)') '--:--:--'
87
88 end function hms
89 !*********************************************************************************************************************************
90
91 !*********************************************************************************************************************************
92 !> \brief Print time as hh:mm:ss string, input in hours; No special output for t=0
93 !!
94 !! \param t Time (h)
95 !! \retval hhms Time as hh:mm:ss string
96
97 elemental function hhms(t)
98 use sufr_kinds, only: double
99 use sufr_constants, only: r2h,h2r
100 use sufr_angles, only: rev
101 use sufr_numerics, only: deq0
102
103 implicit none
104 real(double), intent(in) :: t
105 real(double) :: t1
106 integer :: h,m,s
107 character :: hhms*(8)
108
109 t1 = rev(t*h2r)*r2h
110 h = int(t1)
111 m = int((t1-h)*60.d0)
112 s = nint((t1-h-m/60.d0)*3600.d0)
113
114 if(s.ge.60) then
115 s = s-60
116 m = m+1
117 end if
118 if(m.ge.60) then
119 m = m-60
120 h = h+1
121 end if
122 if(h.ge.24) h = h-24
123
124 if(h.lt.10) then
125 write(hhms,'(I1, 2(A1,I2.2))') h,':',m,':',s
126 else
127 write(hhms,'(I2.2,2(A1,I2.2))') h,':',m,':',s
128 end if
129
130 end function hhms
131 !*********************************************************************************************************************************
132
133 !*********************************************************************************************************************************
134 !> \brief Print time as string in hh:mm, input in hours, output between -12 and 12
135 !!
136 !! \param t Time (h)
137 !! \retval hms2 Time as string in hh:mm
138
139 elemental function hms2(t)
140 use sufr_kinds, only: double
141 use sufr_angles, only: rv12
142
143 implicit none
144 real(double), intent(in) :: t
145 real(double) :: t1
146 integer :: h,m,s
147 character :: hms2*(9),hh*(2),mm*(2),ss*(2),sign
148
149 t1 = abs(rv12(t))
150 h = int(t1)
151 m = int((t1-h)*60.d0)
152 s = nint((t1-h-m/60.d0)*3600.d0)
153 !sign = '+'
154 sign = ' '
155 if(rv12(t).lt.0.d0) sign = '-'
156
157 if(s.ge.60) then
158 s = s-60
159 m = m+1
160 end if
161 if(m.eq.60) then
162 m = 0
163 h = h+1
164 end if
165
166 write(hh,'(I2.2)') h
167 write(mm,'(I2.2)') m
168 write(ss,'(I2.2)') s
169
170 write(hms2,'(A1,A2,2(A1,A2))') sign,hh,':',mm,':',ss
171
172 end function hms2
173 !*********************************************************************************************************************************
174
175
176
177
178
179
180 !*********************************************************************************************************************************
181 !> \brief Print time as 00u11m22s string, input in hours
182 !!
183 !! \param t Time (h)
184 !! \retval ums Time as 00u11m22s string
185
186 elemental function ums(t)
187 use sufr_kinds, only: double
188 use sufr_constants, only: r2h,h2r
189 use sufr_angles, only: rev
190 use sufr_numerics, only: deq0
191
192 implicit none
193 real(double), intent(in) :: t
194 real(double) :: t1
195 integer :: h,m,s
196 character :: ums*(9),hh*(2),mm*(2),ss*(2)
197
198 t1 = rev(t*h2r)*r2h
199 h = int(t1)
200 m = int((t1-h)*60.d0)
201 s = nint((t1-h-m/60.d0)*3600.d0)
202
203 if(s.ge.60) then
204 s = s-60
205 m = m+1
206 end if
207 if(m.ge.60) then
208 m = m-60
209 h = h+1
210 end if
211 if(h.ge.24) h = h-24
212
213 write(hh,'(I2.2)') h
214 write(mm,'(I2.2)') m
215 write(ss,'(I2.2)') s
216
217 write(ums,'(A2,2(A1,A2),A1)') hh,'u',mm,'m',ss,'s'
218 if(deq0(t)) write(ums,'(a9)') '--u--m--s'
219
220 end function ums
221 !*********************************************************************************************************************************
222
223
224
225
226 !*********************************************************************************************************************************
227 !> \brief Print time as string in hms.s, input in hours
228 !!
229 !! \param t Time (h)
230 !! \retval hms_s Time as string in hms.s
231
232 elemental function hms_s(t)
233 use sufr_kinds, only: double
234 use sufr_constants, only: r2h,h2r
235 use sufr_angles, only: rev
236 use sufr_numerics, only: deq0
237
238 implicit none
239 real(double), intent(in) :: t
240 real(double) :: t1,s
241 integer :: h,m
242 character :: hms_s*(10),hh*(2),mm*(2),ss*(4)
243
244 t1 = rev((t+1.d-10)*h2r)*r2h
245 h = int(t1)
246 m = int((t1-h)*60.d0)
247 s = (t1-h-m/60.d0)*3600.d0
248
249 if(s.ge.59.95d0) then
250 s = s-60.d0
251 m = m+1
252 end if
253 if(m.ge.60) then
254 m = m - 60
255 h = h+1
256 end if
257 if(h.ge.24) h = h-24
258
259 write(hh,'(I2.2)') h
260 write(mm,'(I2.2)') m
261 write(ss,'(F4.1)') s
262 if(s.lt.9.95d0) write(ss,'(A1,F3.1)') '0',s
263
264 write(hms_s,'(2(A2,A1),A4)') hh,':',mm,':',ss
265 if(deq0(t)) write(hms_s,'(A10)') '--:--:--.-'
266
267 end function hms_s
268 !*********************************************************************************************************************************
269
270
271
272
273 !*********************************************************************************************************************************
274 !> \brief Print time as string in hms.sss, input in hours
275 !!
276 !! \param t Time (h)
277 !! \retval hms_sss Time as string in hms.sss
278
279 elemental function hms_sss(t)
280 use sufr_kinds, only: double
281 use sufr_constants, only: r2h,h2r
282 use sufr_angles, only: rev
283 use sufr_numerics, only: deq0
284
285 implicit none
286 real(double), intent(in) :: t
287 real(double) :: t1,s
288 integer :: h,m
289 character :: hms_sss*(12),hh*(2),mm*(2),ss*(6)
290
291 t1 = rev((t+1.d-10)*h2r)*r2h
292 h = int(t1)
293 m = int((t1-h)*60.d0)
294 s = (t1-h-m/60.d0)*3600.d0
295
296 if(s.ge.59.9995d0) then
297 s = s-60.d0
298 m = m+1
299 end if
300 if(m.ge.60) then
301 m = m - 60
302 h = h+1
303 end if
304 if(h.ge.24) h = h-24
305
306 write(hh,'(I2.2)') h
307 write(mm,'(I2.2)') m
308 write(ss,'(F6.3)') s
309 if(s.lt.9.9995d0) write(ss,'(A1,F5.3)') '0',s
310
311 write(hms_sss,'(2(A2,A1),A6)') hh,':',mm,':',ss
312 if(deq0(t)) write(hms_sss,'(A12)') '--:--:--.---'
313
314 end function hms_sss
315 !*********************************************************************************************************************************
316
317
318
319
320 !*********************************************************************************************************************************
321 !> \brief Print time as string in hm.m, input in hours
322 !!
323 !! \param t Time (h)
324 !! \retval hmm Time as string in hm.m
325
326 elemental function hmm(t)
327 use sufr_kinds, only: double
328 use sufr_constants, only: r2h,h2r
329 use sufr_angles, only: rev
330 use sufr_numerics, only: deq0
331
332 implicit none
333 real(double), intent(in) :: t
334 real(double) :: t1,m
335 integer :: h
336 character :: hmm*(7)
337
338 t1 = rev(t*h2r)*r2h
339 h = int(t1)
340 m = (t1-h)*60.d0
341
342 if(m.ge.59.95d0) then
343 m = 0.d0
344 h = h+1
345 end if
346 if(h.eq.24) h=0
347
348 write(hmm,'(I2.2,A1,F4.1)') h,':',m
349 if(m.lt.9.95d0) write(hmm,'(I2.2,A2,F3.1)') h,':0',m
350 if(deq0(t)) write(hmm,'(A7)') '--:--.-'
351
352 end function hmm
353 !*********************************************************************************************************************************
354
355
356
357
358 !*********************************************************************************************************************************
359 !> \brief Print time as string in 00u11.2m, input in hours
360 !!
361 !! \param t Time (h)
362 !! \retval umm Time as string in 00u11.2m
363
364 elemental function umm(t)
365 use sufr_kinds, only: double
366 use sufr_constants, only: r2h,h2r
367 use sufr_angles, only: rev
368 use sufr_numerics, only: deq0
369
370 implicit none
371 real(double), intent(in) :: t
372 real(double) :: t1,m
373 integer :: h
374 character :: umm*(8)
375
376 t1 = rev(t*h2r)*r2h
377 h = int(t1)
378 m = (t1-h)*60.d0
379
380 if(m.ge.59.95d0) then
381 m = 0.d0
382 h = h+1
383 end if
384 if(h.eq.24) h=0
385
386 write(umm,'(I2.2,A1,F4.1,A1)') h,'u',m,'m'
387 if(m.lt.9.95d0) write(umm,'(I2.2,A2,F3.1,A1)') h,'u0',m,'m'
388 if(deq0(t)) write(umm,'(A8)') '--u--.-m'
389
390 end function umm
391 !*********************************************************************************************************************************
392
393
394
395
396 !*********************************************************************************************************************************
397 !> \brief Print time as string in hh:mm, input in hours.
398 !!
399 !! \param time Time (h)
400 !! \retval hm Time as string in hh:mm
401 !!
402 !! \note
403 !! - Prints '--:--' for time=0! Use hhm() to avoid this.
404
405 elemental function hm(time)
406 use sufr_kinds, only: double
407 use sufr_constants, only: r2h,h2r
408 use sufr_angles, only: rev
409 use sufr_numerics, only: deq0
410
411 implicit none
412 real(double), intent(in) :: time
413 real(double) :: ltime
414 integer :: hr,mn
415 character :: hm*(5)
416
417 ltime = rev(time*h2r)*r2h
418 hr = int(ltime)
419 mn = nint((ltime-hr)*60.d0)
420
421 if(mn.eq.60) then
422 mn = 0
423 hr = hr+1
424 end if
425 if(hr.ge.24) hr = hr-24
426
427 write(hm,'(I2.2,A1,I2.2)') hr,':',mn
428 if(deq0(time)) write(hm,'(A5)') '--:--'
429
430 end function hm
431 !*********************************************************************************************************************************
432
433
434
435
436 !*********************************************************************************************************************************
437 !> \brief Print time as string in hh:mm.mmm, input in hours
438 !!
439 !! \param time Time (h)
440 !! \retval hm_mmm Time as string in hh:mm.mmm
441
442 elemental function hm_mmm(time)
443 use sufr_kinds, only: double
444 use sufr_constants, only: r2h,h2r
445 use sufr_angles, only: rev
446
447 implicit none
448 real(double), intent(in) :: time
449 real(double) :: ltime, mn
450 integer :: hr
451 character :: hm_mmm*(9)
452
453 ltime = rev(time*h2r)*r2h
454 hr = int(ltime)
455 mn = (ltime-hr)*60.d0
456
457 if(mn.ge.59.9995d0) then
458 mn = 0.d0
459 hr = hr+1
460 end if
461 if(hr.ge.24) hr = hr-24
462
463 write(hm_mmm,'(I2.2,A1,F6.3)') hr,':',mn
464 if(mn.lt.9.9995d0) write(hm_mmm,'(I2.2,A2,F5.3)') hr,':0',mn
465
466 end function hm_mmm
467 !*********************************************************************************************************************************
468
469
470
471
472 !*********************************************************************************************************************************
473 !> \brief Print time as string in h:mm or hh:mm, input in hours; no special output for h=0
474 !!
475 !! \param t Time (h)
476 !! \retval hhm Time as string in h:mm or hh:mm
477
478 elemental function hhm(t)
479 use sufr_kinds, only: double
480 use sufr_constants, only: r2h,h2r
481 use sufr_angles, only: rev
482
483 implicit none
484 real(double), intent(in) :: t
485 real(double) :: t1
486 integer :: h,m
487 character :: hhm*(5)
488
489 t1 = rev(t*h2r)*r2h
490 h = int(t1)
491 m = nint((t1-h)*60.d0)
492
493 if(m.eq.60) then
494 m=0
495 h=h+1
496 end if
497 if(h.eq.24) h=0
498
499 if(h.lt.10) then
500 write(hhm,'(I1,A1,I2.2,A)') h,':',m,' '
501 else
502 write(hhm,'(I2.2,A1,I2.2)') h,':',m
503 end if
504
505 end function hhm
506 !*********************************************************************************************************************************
507
508
509
510
511 !*********************************************************************************************************************************
512 !> \brief Print time as string in 01u23m, input in hours
513 !!
514 !! \param t Time (h)
515 !! \retval um Time as string in 01u23m
516
517 elemental function um(t)
518 use sufr_kinds, only: double
519 use sufr_constants, only: r2h,h2r
520 use sufr_angles, only: rev
521 use sufr_numerics, only: deq0
522
523 implicit none
524 real(double), intent(in) :: t
525 real(double) :: t1
526 integer :: h,m
527 character :: um*(6),hh*(2),mm*(2)
528
529 t1 = rev(t*h2r)*r2h
530 h = int(t1)
531 m = nint((t1-h)*60.d0)
532
533 if(m.eq.60) then
534 m=0
535 h=h+1
536 end if
537 if(h.eq.24) h=0
538
539 write(hh,'(I2)') h
540 write(mm,'(I2)') m
541 if(h.lt.10) write(hh,'(A1,I1)') '0',h
542 if(m.lt.10) write(mm,'(A1,I1)') '0',m
543
544 write(um,'(2(A2,A1))') hh,'u',mm,'m'
545 if(deq0(t)) write(um,'(A6)') '--u--m'
546
547 end function um
548 !*********************************************************************************************************************************
549
550
551
552
553 !*********************************************************************************************************************************
554 !> \brief Print time as string in 01u23m, input in hours, web version (HTML superscripts)
555 !!
556 !! \param t Time (h)
557 !! \retval wum Time as HTML string in 01u23m
558
559 elemental function wum(t)
560 use sufr_kinds, only: double
561 use sufr_constants, only: r2h,h2r
562 use sufr_angles, only: rev
563 use sufr_numerics, only: deq0
564
565 implicit none
566 real(double), intent(in) :: t
567 real(double) :: t1
568 integer :: h,m
569 character :: wum*(28),hh*(2),mm*(2)
570
571 t1 = rev(t*h2r)*r2h
572 h = int(t1)
573 m = nint((t1-h)*60.d0)
574
575 if(m.eq.60) then
576 m=0
577 h=h+1
578 end if
579 if(h.eq.24) h=0
580
581 write(hh,'(I2)') h
582 write(mm,'(I2)') m
583 if(h.lt.10) write(hh,'(A1,I1)') '0',h
584 if(m.lt.10) write(mm,'(A1,I1)') '0',m
585
586 write(wum,'(2(A2,A12))') hh,'<sup>u</sup>',mm,'<sup>m</sup>'
587 if(deq0(t)) write(wum,'(A28)') '--<sup>u</sup>--<sup>m</sup>'
588
589 end function wum
590 !*********************************************************************************************************************************
591
592
593
594 !*********************************************************************************************************************************
595 !> \brief Print time as string in 01u23.1m, input in hours, web version (HTML superscripts)
596 !!
597 !! \param t Time (h)
598 !! \retval wumm Time as HTML string in 01u23.1m
599
600 elemental function wumm(t)
601 use sufr_kinds, only: double
602 use sufr_constants, only: r2h,h2r
603 use sufr_angles, only: rev
604 use sufr_numerics, only: deq0
605
606 implicit none
607 real(double), intent(in) :: t
608 real(double) :: t1
609 integer :: h
610 real :: m
611 character :: wumm*(30),hh*(2),mm*(4)
612
613 t1 = rev(t*h2r)*r2h
614 h = int(t1)
615 m = real(t1-h)*60.
616
617 if(m.ge.59.95d0) then
618 m = 0.d0
619 h = h+1
620 end if
621 if(h.eq.24) h=0
622
623 write(hh,'(I2.2)') h
624 write(mm,'(F4.1)') m
625 if(m.lt.9.95) write(mm,'(A1,F3.1)') '0',m
626
627 write(wumm,'(A2,A12,A4,A12)') hh,'<sup>u</sup>',mm,'<sup>m</sup>'
628 if(deq0(t)) write(wumm,'(A30)') '--<sup>u</sup>--.-<sup>m</sup>'
629
630 end function wumm
631 !*********************************************************************************************************************************
632
633
634
635 !*********************************************************************************************************************************
636 !> \brief Print time as 00u11m22s HTML string, input in hours
637 !!
638 !! \param t Time (h)
639 !! \retval wums Time as 00u11m22s HTML string
640
641 elemental function wums(t)
642 use sufr_kinds, only: double
643 use sufr_constants, only: r2h,h2r
644 use sufr_angles, only: rev
645 use sufr_numerics, only: deq0
646
647 implicit none
648 real(double), intent(in) :: t
649 real(double) :: t1
650 integer :: h,m,s
651 character :: wums*(42),hh*(2),mm*(2),ss*(2)
652
653 t1 = rev(t*h2r)*r2h
654 h = int(t1)
655 m = int((t1-h)*60.d0)
656 s = nint((t1-h-m/60.d0)*3600.d0)
657
658 if(s.ge.60) then
659 s = s-60
660 m = m+1
661 end if
662 if(m.ge.60) then
663 m = m-60
664 h = h+1
665 end if
666 if(h.ge.24) h = h-24
667
668 write(hh,'(I2.2)') h
669 write(mm,'(I2.2)') m
670 write(ss,'(I2.2)') s
671
672 write(wums,'(3(A2,A12))') hh,'<sup>u</sup>',mm,'<sup>m</sup>',ss,'<sup>s</sup>'
673 if(deq0(t)) write(wums,'(A42)') '--<sup>u</sup>--<sup>m</sup>--<sup>s</sup>'
674
675 end function wums
676 !*********************************************************************************************************************************
677
678
679
680 !*********************************************************************************************************************************
681 !> \brief Print time as a Dutch HTML string in 11u22m33.4s, input in hours. HTML equivalent of hms_s()
682 !!
683 !! \param t Time (h)
684 !! \retval wums_s Time as a Dutch HTML string in 11u22m33.4s
685
686 elemental function wums_s(t)
687 use sufr_kinds, only: double
688 use sufr_constants, only: r2h,h2r
689 use sufr_angles, only: rev
690 use sufr_numerics, only: deq0
691
692 implicit none
693 real(double), intent(in) :: t
694 real(double) :: t1,s
695 integer :: h,m
696 character :: wums_s*(44),hh*(2),mm*(2),ss*(4)
697
698 t1 = rev((t+1.d-10)*h2r)*r2h
699 h = int(t1)
700 m = int((t1-h)*60.d0)
701 s = (t1-h-m/60.d0)*3600.d0
702
703 if(s.ge.59.95d0) then
704 s = s-60.d0
705 m = m+1
706 end if
707 if(m.ge.60) then
708 m = m - 60
709 h = h+1
710 end if
711 if(h.ge.24) h = h-24
712
713 write(hh,'(I2.2)') h
714 write(mm,'(I2.2)') m
715 write(ss,'(F4.1)') s
716 if(s.lt.9.95d0) write(ss,'(A1,F3.1)') '0',s
717
718 write(wums_s,'(2(A2,A12),A4,A12)') hh,'<sup>u</sup>',mm,'<sup>m</sup>',ss,'<sup>s</sup>'
719 if(deq0(t)) write(wums_s,'(A44)') '--<sup>u</sup>--<sup>m</sup>--.-<sup>s</sup>'
720
721 end function wums_s
722 !*********************************************************************************************************************************
723
724
725
726
727
728
729
730
731
732 !*********************************************************************************************************************************
733 !> \brief Print time as string in +/-hh:mm, input in hours, between -12 and 12
734 !!
735 !! \param t Time (h)
736 !! \retval hm2 Time as string in +/-hh:mm
737
738 elemental function hm2(t)
739 use sufr_kinds, only: double
740 use sufr_angles, only: rv12
741
742 implicit none
743 real(double), intent(in) :: t
744 real(double) :: t1
745 integer :: h,m
746 character :: hm2*(6),hh*(2),mm*(2),sign
747
748 t1 = abs(rv12(t))
749 h = int(t1)
750 m = nint((t1-h)*60)
751
752 !sign = '+'
753 sign = ' '
754 if(rv12(t).lt.0.d0) sign = '-'
755
756 if(m.eq.60) then
757 m=0
758 h=h+1
759 end if
760
761 write(hh,'(I2.2)')h
762 write(mm,'(I2.2)')m
763
764 write(hm2,'(A1,A2,A1,A2)') sign,hh,':',mm
765
766 end function hm2
767 !*********************************************************************************************************************************
768
769
770
771
772 !*********************************************************************************************************************************
773 !> \brief Print time as a nice string in hh.mm, so with a . in stead of : Input in hours
774 !!
775 !! \param t Time (h)
776 !! \retval hdm Time as a nice string in hh.mm
777
778 elemental function hdm(t)
779 use sufr_kinds, only: double
780 use sufr_angles, only: rev
781 use sufr_constants, only: r2h,h2r
782 use sufr_numerics, only: deq0
783
784 implicit none
785 real(double), intent(in) :: t
786 real(double) :: t1
787 integer :: h,m
788 character :: hdm*(5),hh*(2),mm*(2)
789
790 t1 = rev(t*h2r)*r2h
791 h = int(t1)
792 m = nint((t1-h)*60.d0)
793
794 if(m.eq.60) then
795 m=0
796 h=h+1
797 end if
798 if(h.eq.24) h=0
799
800 write(hh,'(I2)') h
801 write(mm,'(I2)') m
802 if(h.lt.10) write(hh,'(A1,I1)') '0',h
803 if(m.lt.10) write(mm,'(A1,I1)') '0',m
804
805 write(hdm,'(A2,2(A1,A2))') hh,'.',mm
806 if(deq0(t)) write(hdm,'(A5)') '--.--'
807
808 end function hdm
809 !*********************************************************************************************************************************
810
811
812
813 !*********************************************************************************************************************************
814 !> \brief Print time as mm:ss.s string, input in hours
815 !!
816 !! \param t Time (h)
817 !! \retval tms Time as mm:ss.s string
818
819 elemental function tms(t)
820 use sufr_kinds, only: double
821 implicit none
822 real(double), intent(in) :: t
823 real(double) :: a,s
824 integer :: m
825 character :: tms*(8),ss*(4)
826
827 a = t
828 m = int((a)*60.d0)
829 s = (a-m/60.d0)*3600.d0
830
831 write(ss,'(F4.1)') s
832 if(nint(s*10).lt.100) write(ss,'(A1,F3.1)') '0',s
833 write(tms,'(I2.2,A1,A4,A1)') m,'m',ss,'s'
834
835 end function tms
836 !*********************************************************************************************************************************
837
838
839 !*********************************************************************************************************************************
840 !> \brief Print time as mm:ss.s string, input in hours
841 !!
842 !! \param t Time (h)
843 !! \retval tms2 Time as mm:ss.s string
844
845 elemental function tms2(t)
846 use sufr_kinds, only: double
847 implicit none
848 real(double), intent(in) :: t
849 real(double) :: a,s
850 integer :: m
851 character :: tms2*(9),ss*(4),sign
852
853 a = t
854
855 ! sign = '+'
856 sign = ' '
857 if(a.lt.0.d0) then
858 sign = '-'
859 a = -a
860 end if
861
862 m = int((a)*60.d0)
863 s = (a-m/60.d0)*3600.d0
864
865 write(ss,'(F4.1)') s
866 if(s.lt.9.95d0) write(ss,'(A1,F3.1)') '0',s
867 write(tms2,'(A1,I2.2,A1,A4,A1)') sign,m,'m',ss,'s'
868
869 end function tms2
870 !*********************************************************************************************************************************
871
872
873
874 !*********************************************************************************************************************************
875 !> \brief Print time as m:ss.s string, input in hours, like tms2, but t<10 min(!)
876 !!
877 !! \param t Time (h)
878 !! \retval tmsss2 Time as m:ss.s string
879
880 elemental function tmsss2(t)
881 use sufr_kinds, only: double
882 implicit none
883 real(double), intent(in) :: t
884 real(double) :: a,s
885 integer :: m
886 character :: tmsss2*(8),ss*(4),sign
887
888 a = t
889
890 ! sign = '+'
891 sign = ' '
892 if(a.lt.0.d0) then
893 sign = '-'
894 a = -a
895 end if
896
897 m = int((a)*60.d0)
898 s = (a-m/60.d0)*3600.d0
899
900 write(ss,'(F4.1)') s
901 if(s.lt.9.95d0) write(ss,'(A1,F3.1)') '0',s
902 write(tmsss2,'(A1,I1,A1,A4,A1)') sign,m,'m',ss,'s'
903
904 end function tmsss2
905 !*********************************************************************************************************************************
906
907
908
909
910
911
912end module sufr_time2string
913!***********************************************************************************************************************************
914
Procedures to handle angles.
Definition angles.f90:23
pure real(double) function rev(ang)
Returns angle in radians between 0 and 2pi.
Definition angles.f90:41
pure real(double) function rv12(tm)
Returns time in hours between -12 and 12.
Definition angles.f90:193
Provides all constants in the library, and routines to define them.
Definition constants.f90:23
real(double), parameter, public h2r
Hours to radians.
Definition constants.f90:45
real(double), parameter, public r2h
Radians to hours.
Definition constants.f90:44
real(double), parameter, public mm
millimeter in cgs (cm)
Provides kinds and related constants/routines.
Definition kinds.f90:26
integer, parameter double
Double-precision float. Precision = 15, range = 307.
Definition kinds.f90:35
Procedures for numerical operations.
Definition numerics.f90:23
elemental logical function deq0(x0, eps)
Test whether a double-precision variable is equal to zero better than a given value (default: 2x mach...
Definition numerics.f90:118
Procedures to convert time to formatted text strings.
elemental character function, dimension(6) hm2(t)
Print time as string in +/-hh:mm, input in hours, between -12 and 12.
elemental character function, dimension(9) hm_mmm(time)
Print time as string in hh:mm.mmm, input in hours.
elemental character function, dimension(8) hhms(t)
Print time as hh:mm:ss string, input in hours; No special output for t=0.
elemental character function, dimension(6) um(t)
Print time as string in 01u23m, input in hours.
elemental character function, dimension(8) tmsss2(t)
Print time as m:ss.s string, input in hours, like tms2, but t<10 min(!)
elemental character function, dimension(8) tms(t)
Print time as mm:ss.s string, input in hours.
elemental character function, dimension(9) hms2(t)
Print time as string in hh:mm, input in hours, output between -12 and 12.
elemental character function, dimension(44) wums_s(t)
Print time as a Dutch HTML string in 11u22m33.4s, input in hours. HTML equivalent of hms_s()
elemental character function, dimension(5) hhm(t)
Print time as string in h:mm or hh:mm, input in hours; no special output for h=0.
elemental character function, dimension(9) ums(t)
Print time as 00u11m22s string, input in hours.
elemental character function, dimension(10) hms_s(t)
Print time as string in hms.s, input in hours.
elemental character function, dimension(5) hm(time)
Print time as string in hh:mm, input in hours.
elemental character function, dimension(42) wums(t)
Print time as 00u11m22s HTML string, input in hours.
elemental character function, dimension(5) hdm(t)
Print time as a nice string in hh.mm, so with a . in stead of : Input in hours.
elemental character function, dimension(28) wum(t)
Print time as string in 01u23m, input in hours, web version (HTML superscripts)
elemental character function, dimension(9) tms2(t)
Print time as mm:ss.s string, input in hours.
elemental character function, dimension(8) hms(t)
Print time as hh:mm:ss string, input in hours; Display '–:–:–' for t=0.
elemental character function, dimension(7) hmm(t)
Print time as string in hm.m, input in hours.
elemental character function, dimension(30) wumm(t)
Print time as string in 01u23.1m, input in hours, web version (HTML superscripts)
elemental character function, dimension(12) hms_sss(t)
Print time as string in hms.sss, input in hours.
elemental character function, dimension(8) umm(t)
Print time as string in 00u11.2m, input in hours.