xref: /phasta/phSolver/common/test/phIOwrite.f (revision ab645d527a403248f92b1511f47c35aaadb4947d)
15be7d1a3SCameron Smith      program readheaderFtn
25be7d1a3SCameron Smith      use iso_c_binding
35be7d1a3SCameron Smith      use phio
4*ab645d52SCameron Smith      use syncio
5*ab645d52SCameron Smith      use posixio
65be7d1a3SCameron Smith      include "mpif.h"
75be7d1a3SCameron Smith
8*ab645d52SCameron Smith      integer, target :: rank, ierror, one, ppf, peers, fish, nfiles
9*ab645d52SCameron 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
13*ab645d52SCameron 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
30*ab645d52SCameron Smith      nfiles = 2
31*ab645d52SCameron Smith      ppf = peers/nfiles
32*ab645d52SCameron Smith      call syncio_setup_write(nfiles, one, ppf, handle(1))
33*ab645d52SCameron Smith      call posixio_setup(handle(2), c_char_"w"//c_null_char)
345be7d1a3SCameron Smith      do i=1,2
35*ab645d52SCameron Smith        call phio_openfile(fname(i), handle)
365be7d1a3SCameron Smith        call phio_writeheader(handle, phrase, c_loc(fish), one, one,
375be7d1a3SCameron Smith     &      dataDbl, iotype)
385be7d1a3SCameron Smith        call phio_writedatablock(handle, phrase, c_loc(fishweight(i)),
395be7d1a3SCameron Smith     &      one, dataDbl, iotype)
40*ab645d52SCameron Smith        call phio_closefile(handle)
415be7d1a3SCameron Smith      end do
42*ab645d52SCameron Smith      call syncio_setup_read(nfiles, handle(1))
43*ab645d52SCameron Smith      call posixio_setup(handle(2), c_char_"r"//c_null_char)
445be7d1a3SCameron Smith      do i=1,2
45*ab645d52SCameron Smith        call phio_openfile(fname(i), handle)
465be7d1a3SCameron Smith        call phio_readheader(handle, phrase, c_loc(numFish(i)),
475be7d1a3SCameron Smith     &      one, dataDbl, iotype)
485be7d1a3SCameron Smith        call phio_readdatablock(handle, phrase, c_loc(fishweight(i)),
495be7d1a3SCameron Smith     &      one, dataDbl, iotype)
50*ab645d52SCameron Smith        call phio_closefile(handle)
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