File: c_f_pointer_complex.f03

package info (click to toggle)
gcc-arm-none-eabi 15%3A12.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 959,712 kB
  • sloc: cpp: 3,275,382; ansic: 2,061,766; ada: 840,956; f90: 208,513; makefile: 76,132; asm: 73,433; xml: 50,448; exp: 34,146; sh: 32,436; objc: 15,637; fortran: 14,012; python: 11,991; pascal: 6,787; awk: 4,779; perl: 3,054; yacc: 338; ml: 285; lex: 201; haskell: 122
file content (59 lines) | stat: -rw-r--r-- 2,573 bytes parent folder | download | duplicates (3)
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
! { dg-do run }
! { dg-additional-sources c_f_pointer_complex_driver.c }
! { dg-options "-std=gnu -w" }
! Test c_f_pointer for the different types of interoperable complex values.
module c_f_pointer_complex
  use, intrinsic :: iso_c_binding, only: c_float_complex, c_double_complex, &
       c_long_double_complex, c_f_pointer, c_ptr, c_long_double, c_int
  implicit none

contains
  subroutine test_complex_scalars(my_c_float_complex, my_c_double_complex, &
       my_c_long_double_complex) bind(c)
    type(c_ptr), value :: my_c_float_complex
    type(c_ptr), value :: my_c_double_complex
    type(c_ptr), value :: my_c_long_double_complex
    complex(c_float_complex), pointer :: my_f03_float_complex
    complex(c_double_complex), pointer :: my_f03_double_complex
    complex(c_long_double_complex), pointer :: my_f03_long_double_complex
    
    call c_f_pointer(my_c_float_complex, my_f03_float_complex)
    call c_f_pointer(my_c_double_complex, my_f03_double_complex)
    call c_f_pointer(my_c_long_double_complex, my_f03_long_double_complex)

    if(my_f03_float_complex /= (1.0, 0.0)) STOP 1
    if(my_f03_double_complex /= (2.0d0, 0.0d0)) STOP 2
    if(my_f03_long_double_complex /= (3.0_c_long_double, &
         0.0_c_long_double)) STOP 3
  end subroutine test_complex_scalars

  subroutine test_complex_arrays(float_complex_array, double_complex_array, &
       long_double_complex_array, num_elems) bind(c)
    type(c_ptr), value :: float_complex_array
    type(c_ptr), value :: double_complex_array
    type(c_ptr), value :: long_double_complex_array    
    complex(c_float_complex), pointer, dimension(:) :: f03_float_complex_array
    complex(c_double_complex), pointer, dimension(:) :: &
         f03_double_complex_array
    complex(c_long_double_complex), pointer, dimension(:) :: &
         f03_long_double_complex_array
    integer(c_int), value :: num_elems
    integer :: i

    call c_f_pointer(float_complex_array, f03_float_complex_array, &
         (/ num_elems /))
    call c_f_pointer(double_complex_array, f03_double_complex_array, &
         (/ num_elems /))
    call c_f_pointer(long_double_complex_array, &
         f03_long_double_complex_array, (/ num_elems /))

    do i = 1, num_elems
       if(f03_float_complex_array(i) &
            /= (i*(1.0, 0.0))) STOP 4
       if(f03_double_complex_array(i) &
            /= (i*(1.0d0, 0.0d0))) STOP 5
       if(f03_long_double_complex_array(i) &
            /= (i*(1.0_c_long_double, 0.0_c_long_double))) STOP 6
    end do
  end subroutine test_complex_arrays
end module c_f_pointer_complex