summaryrefslogtreecommitdiff
path: root/map65/libm65/datcom_ptrs_mod.f90
blob: a507168eaebf1989e65092ba05721c6ca0971313 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
module datcom_ptrs_mod
  use iso_c_binding
  implicit none

  ! Fortran pointer targets
  real(c_float), pointer, contiguous :: dd(:,:) => null()      ! [4, 5760000]
  real(c_float), pointer, contiguous :: ss(:,:,:) => null()     ! [4, 322, NFFT]
  real(c_float), pointer, contiguous :: savg(:,:) => null()     ! [4, NFFT]
  real(c_float), pointer, contiguous :: dd_old(:,:) => null()      ! [4, 5760000]
  real(c_float), pointer, contiguous :: ss_old(:,:,:) => null()     ! [4, 322, NFFT]
  real(c_float), pointer, contiguous :: savg_old(:,:) => null()     ! [4, NFFT]

  ! Pointers used by decode0 / narrowband decoder
  real(c_float), pointer, contiguous :: dd_use(:,:)  => null()
  real(c_float), pointer, contiguous :: ss_use(:,:,:)=> null()
  real(c_float), pointer, contiguous :: savg_use(:,:)=> null()

  ! Scalar values
  integer, parameter :: NFFT=32768              !Length of FFTs
  integer(c_int) :: junk1 = 0, junk2 = 0, quitid = 0
  
contains

  subroutine snapshot_buffers() bind(C)
    dd_old(:,:)      = dd(:,:)
    ss_old(:,:,:)    = ss(:,:,:)
    savg_old(:,:)    = savg(:,:)
  end subroutine

  ! Helper subroutine to copy fixed-length Fortran string to C buffer
  subroutine move_chars(dest, dest_len, src)
    integer(c_int), intent(in) :: dest_len
    character(kind=c_char), intent(out) :: dest(dest_len)
    character(len=*), intent(in) :: src
    integer :: i, n

    n = min(len(src), dest_len)
    do i = 1, n
      dest(i) = src(i:i)
    end do
  end subroutine move_chars
  
  subroutine set_dd_ptr(ptr, dim1, dim2) bind(C, name="set_dd_ptr")
    use iso_c_binding
    implicit none
    type(c_ptr), value :: ptr
    integer(c_int), value :: dim1, dim2
    call c_f_pointer(ptr, dd, [dim1, dim2])
    print *, "Fortran: dd pointer associated with dimensions", dim1, dim2
  end subroutine

  subroutine set_ss_ptr(ptr, dim1, dim2, dim3) bind(C, name="set_ss_ptr")
    use iso_c_binding
    implicit none
    type(c_ptr), value :: ptr
    integer(c_int), value :: dim1, dim2, dim3
    call c_f_pointer(ptr, ss, [dim1, dim2, dim3])
    print *, "Fortran: ss pointer associated with dimensions", dim1, dim2, dim3
  end subroutine

  subroutine set_savg_ptr(ptr, dim1, dim2) bind(C, name="set_savg_ptr")
    use iso_c_binding
    implicit none
    type(c_ptr), value :: ptr
    integer(c_int), value :: dim1, dim2
    call c_f_pointer(ptr, savg, [dim1, dim2])
    print *, "Fortran: savg pointer associated with dimensions", dim1, dim2
  end subroutine 
  
  subroutine set_dd_old_ptr(ptr, dim1, dim2) bind(C, name="set_dd_old_ptr")
    use iso_c_binding
    implicit none
    type(c_ptr), value :: ptr
    integer(c_int), value :: dim1, dim2
    call c_f_pointer(ptr, dd_old, [dim1, dim2])
    print *, "Fortran: dd_old pointer associated with dimensions", dim1, dim2
  end subroutine

  subroutine set_ss_old_ptr(ptr, dim1, dim2, dim3) bind(C, name="set_ss_old_ptr")
    use iso_c_binding
    implicit none
    type(c_ptr), value :: ptr
    integer(c_int), value :: dim1, dim2, dim3
    call c_f_pointer(ptr, ss_old, [dim1, dim2, dim3])
    print *, "Fortran: ss_old pointer associated with dimensions", dim1, dim2, dim3
  end subroutine

  subroutine set_savg_old_ptr(ptr, dim1, dim2) bind(C, name="set_savg_old_ptr")
    use iso_c_binding
    implicit none
    type(c_ptr), value :: ptr
    integer(c_int), value :: dim1, dim2
    call c_f_pointer(ptr, savg_old, [dim1, dim2])
    print *, "Fortran: savg_old pointer associated with dimensions", dim1, dim2
  end subroutine 
  
  function get_junk1() bind(C, name="get_junk1")
    integer(c_int) :: get_junk1
    get_junk1 = junk1
  end function

  function get_junk2() bind(C, name="get_junk2")
    integer(c_int) :: get_junk2
    get_junk2 = junk2
  end function
  
subroutine set_quitid(val) bind(C, name="set_quitid")
    use iso_c_binding
    integer(c_long_long), value :: val
    quitid = val
    ! print*,'DATCOM_PTRS_MOD QUITID is:',quitid
  end subroutine

  subroutine set_junk1(val) bind(C, name="set_junk1")
    use iso_c_binding
    integer(c_int), value :: val
    junk1 = val
  end subroutine

  subroutine set_junk2(val) bind(C, name="set_junk2")
    use iso_c_binding
    integer(c_int), value :: val
    junk2 = val
  end subroutine

end module datcom_ptrs_mod