1 program readheaderFtn 2 use iso_c_binding 3 use phio 4 use syncio 5 use posixio 6 include "mpif.h" 7 8 integer, target :: rank, ierror, one, ppf, peers, fish, nfiles 9 type(c_ptr), dimension(2) :: handle 10 character(len=30) :: dataDbl, iotype 11 character(len=256) :: phrase 12 character(len=256), dimension(2) :: fname 13 integer, target, dimension(2) :: fishweight, numFish 14 15 call MPI_Init(ierror) 16 call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierror) 17 call MPI_Comm_size(MPI_COMM_WORLD, peers, ierror) 18 19 phrase = c_char_"number of fishes"//c_null_char 20 dataDbl = c_char_"double"//c_null_char 21 iotype = c_char_"binary"//c_null_char 22 one = 1 23 fish = 2 24 25 fishweight(1) = 1.23 26 fishweight(2) = 1.23 27 28 fname(1) = c_char_"fortranWater-dat."//c_null_char 29 fname(2) = c_char_"fortranWater.dat."//c_null_char 30 nfiles = 2 31 ppf = peers/nfiles 32 call syncio_setup_write(nfiles, one, ppf, handle(1)) 33 call posixio_setup(handle(2), c_char_"w"//c_null_char) 34 do i=1,2 35 call phio_openfile(fname(i), handle) 36 call phio_writeheader(handle, phrase, c_loc(fish), one, one, 37 & dataDbl, iotype) 38 call phio_writedatablock(handle, phrase, c_loc(fishweight(i)), 39 & one, dataDbl, iotype) 40 call phio_closefile(handle) 41 end do 42 call syncio_setup_read(nfiles, handle(1)) 43 call posixio_setup(handle(2), c_char_"r"//c_null_char) 44 do i=1,2 45 call phio_openfile(fname(i), handle) 46 call phio_readheader(handle, phrase, c_loc(numFish(i)), 47 & one, dataDbl, iotype) 48 call phio_readdatablock(handle, phrase, c_loc(fishweight(i)), 49 & one, dataDbl, iotype) 50 call phio_closefile(handle) 51 end do 52 if( numFish(1) .ne. numFish(2) .or. 53 & fishweight(1) .ne. fishweight(2) ) then 54 write (*,*) "fish don\'t match" 55 stop 1 56 end if 57 call MPI_Finalize(ierror) 58 end 59