xref: /phasta/phSolver/common/test/phIOwrite.f (revision c8c8de9b7a8f23dcd281133cb6bdca0b1f43e90b)
15be7d1a3SCameron Smith      program readheaderFtn
25be7d1a3SCameron Smith      use iso_c_binding
35be7d1a3SCameron Smith      use phio
4ab645d52SCameron Smith      use syncio
5ab645d52SCameron Smith      use posixio
65be7d1a3SCameron Smith      include "mpif.h"
75be7d1a3SCameron Smith
8ab645d52SCameron Smith      integer, target :: rank, ierror, one, ppf, peers, fish, nfiles
9ab645d52SCameron Smith      type(c_ptr), dimension(2) :: handle
105be7d1a3SCameron Smith      character(len=30) :: dataDbl, iotype
115be7d1a3SCameron Smith      character(len=256) :: phrase
125be7d1a3SCameron Smith      character(len=256), dimension(2) :: fname
13ab645d52SCameron Smith      integer, target, dimension(2) :: fishweight, numFish
145be7d1a3SCameron Smith
155be7d1a3SCameron Smith      call MPI_Init(ierror)
165be7d1a3SCameron Smith      call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierror)
175be7d1a3SCameron Smith      call MPI_Comm_size(MPI_COMM_WORLD, peers, ierror)
185be7d1a3SCameron Smith
195be7d1a3SCameron Smith      phrase = c_char_"number of fishes"//c_null_char
205be7d1a3SCameron Smith      dataDbl = c_char_"double"//c_null_char
215be7d1a3SCameron Smith      iotype =  c_char_"binary"//c_null_char
225be7d1a3SCameron Smith      one = 1
235be7d1a3SCameron Smith      fish = 2
245be7d1a3SCameron Smith
255be7d1a3SCameron Smith      fishweight(1) = 1.23
265be7d1a3SCameron Smith      fishweight(2) = 1.23
275be7d1a3SCameron Smith
285be7d1a3SCameron Smith      fname(1) = c_char_"fortranWater-dat."//c_null_char
295be7d1a3SCameron Smith      fname(2) = c_char_"fortranWater.dat."//c_null_char
30ab645d52SCameron Smith      nfiles = 2
31ab645d52SCameron Smith      ppf = peers/nfiles
32ab645d52SCameron Smith      call syncio_setup_write(nfiles, one, ppf, handle(1))
33ab645d52SCameron Smith      call posixio_setup(handle(2), c_char_"w"//c_null_char)
345be7d1a3SCameron Smith      do i=1,2
35*c8c8de9bSCameron Smith        call phio_openfile(fname(i), handle(i))
36*c8c8de9bSCameron Smith        call phio_writeheader(handle(i), phrase, c_loc(fish), one, one,
375be7d1a3SCameron Smith     &      dataDbl, iotype)
38*c8c8de9bSCameron Smith        call phio_writedatablock(handle(i), phrase, c_loc(fishweight(i)),
395be7d1a3SCameron Smith     &      one, dataDbl, iotype)
40*c8c8de9bSCameron Smith        call phio_closefile(handle(i))
415be7d1a3SCameron Smith      end do
42ab645d52SCameron Smith      call syncio_setup_read(nfiles, handle(1))
43ab645d52SCameron Smith      call posixio_setup(handle(2), c_char_"r"//c_null_char)
445be7d1a3SCameron Smith      do i=1,2
45*c8c8de9bSCameron Smith        call phio_openfile(fname(i), handle(i))
46*c8c8de9bSCameron Smith        call phio_readheader(handle(i), phrase, c_loc(numFish(i)),
475be7d1a3SCameron Smith     &      one, dataDbl, iotype)
48*c8c8de9bSCameron Smith        call phio_readdatablock(handle(i), phrase, c_loc(fishweight(i)),
495be7d1a3SCameron Smith     &      one, dataDbl, iotype)
50*c8c8de9bSCameron Smith        call phio_closefile(handle(i))
515be7d1a3SCameron Smith      end do
525be7d1a3SCameron Smith      if( numFish(1) .ne. numFish(2) .or.
535be7d1a3SCameron Smith     &    fishweight(1) .ne. fishweight(2) ) then
545be7d1a3SCameron Smith        write (*,*) "fish don\'t match"
555be7d1a3SCameron Smith        stop 1
565be7d1a3SCameron Smith      end if
575be7d1a3SCameron Smith      call MPI_Finalize(ierror)
585be7d1a3SCameron Smith      end
59