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