! Fortran test: calling c functions from mapsetup.c
!   Miles V. Aronnax
program test_this
  integer idx
  real ground_state_energy
  character*32 nucleus_name
  character*200 storage_location

  write(*,*) "Begin program test_this..."

  ! Read nuclei.map file into c array struct numap.
  ! Note addition of null character to string. C expects strings
  ! to be null terminated...fortran doesn't do that automatically.
  call read_mapping_table("nuclei.map"//CHAR(0))
  write(*,*) "Call read_mapping_table done."

  ! Clear the fortran varables before trying to get values from c functions.
  ! This prevents strings from containing random data if the string length
  ! is less than the variable size.
  ground_state_energy = 0
  nucleus_name = ""
  storage_location = ""

  write(*,*) "Reading values in fortran using c functions..."

  ! There are 3 rows of the numap table.
  ! I was just lazy here. I could have made the numap table
  ! dynamically allocated and then had a function to return
  ! the number of entries, but I didn't so...*shrug*
  idx = 1
  do while (idx < 4)
    call mapget_name(idx, nucleus_name)
    call mapget_eabs(idx, ground_state_energy)
    call mapget_nloc(idx, storage_location)
    write(*,*) "  Nucleus ", idx, " = {", &
		&trim(nucleus_name), ", ", &
		&ground_state_energy, ", ", &
		&trim(storage_location), "}"
    idx = idx + 1
  enddo

  write(*,*) "End program test_this."
end program test_this

