summaryrefslogtreecommitdiff
path: root/map65/libm65/chkmsg.f90
blob: 9bf86780582fe33b87a9f550bb5e78943a7dabae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
module chkmsg_mod
  implicit none
contains

subroutine chkmsg(message, cok, nspecial, flip)
  implicit none

  !--------------------------------------------------------------------
  ! Arguments
  !--------------------------------------------------------------------
  character(len=22), intent(inout) :: message   ! modified if OOO/OO removed
  character(len=3),  intent(out)   :: cok
  integer,      intent(out)   :: nspecial
  real,         intent(out)   :: flip

  !--------------------------------------------------------------------
  ! Locals
  !--------------------------------------------------------------------
  integer :: i

  !--------------------------------------------------------------------
  ! Initialization
  !--------------------------------------------------------------------
  nspecial = 0
  flip     = 1.0d0
  cok      = '   '

  !--------------------------------------------------------------------
  ! Find last non‑blank character
  !--------------------------------------------------------------------
  do i = 22, 1, -1
     if (message(i:i) .ne. ' ') exit
  enddo
  if (i == 0) i = 22   ! defensive fallback

  !--------------------------------------------------------------------
  ! Detect trailing OOO / OO shorthand
  !--------------------------------------------------------------------
  if (i >= 11) then
     if ( (message(i-3:i) == ' OOO') .or. (message(20:22) == ' OO') ) then
        cok  = 'OOO'
        flip = -1.0d0

        if (message(20:22) == ' OO') then
           message = message(1:19)
        else
           message = message(1:i-4)
        endif
     endif
  endif

  !--------------------------------------------------------------------
  ! Detect leading shorthand messages
  !--------------------------------------------------------------------
  if (message(1:3) == 'RO ')  nspecial = 2
  if (message(1:4) == 'RRR ') nspecial = 3
  if (message(1:3) == '73 ')  nspecial = 4

end subroutine chkmsg

end module chkmsg_mod