program test_prim c c - - Test fortran primitive calls of C i/o ,byteswap, is_big_endian functions. c - - ibe_f77 tests for big endian, byteswap_f77 does bytwswapping, c - - sdf_fopen_f77 provides an interface to the C fopen function, c - - sdf_fclose_f77 provides an interface to the C close function, c - - sdf_write_f77 provides an interface to the C fwrite function, c - - sdf_read_f77 provides an interface to tehe C fread function, and c - - sdf_ftc_f77 provides an interface to the SDF function sdf_file_truncate. c integer fp(2) real a double precision b integer c integer*8 d c integer*8 lengthf integer*8 lengthd integer*8 lengthi integer nppwf,nbpwd,nbpwi,nbpwi8 integer ibe,ise character*80 fname c fp(1)=0 fp(2)=0 fname="testprim.dat" lengthf=1 nbpwf=4 nbpwd=8 nbpwi=4 nbpwi8=8 a=5. b=dble(11) c=4829636 d=c d=d**2 c c - - determine whether we are on big or small endian machine c ise=1 call ibe_f77(ibe) if(ibe .eq. 1) ise=0 if(ise .eq. 1) write(6,*) "small endian: byteswapping needed" if(ise .eq. 0) write(6,*) "large endian: no byteswapping needed" c c - - byteswap before write if necessary c if(ise .eq. 1) then call byteswap_f77(a,lengthf,nbpwf) call byteswap_f77(b,lengthf,nbpwd) call byteswap_f77(c,lengthf,nbpwi) call byteswap_f77(d,lengthf,nbpwi8) endif c c - - write out data c call sdf_fopen_f77(fname,"wb+",fp) call sdf_fwrite_f77(a,nbpwf,lengthf,fp) call sdf_fwrite_f77(b,nbpwd,lengthf,fp) call sdf_fwrite_f77(c,nbpwi,lengthf,fp) call sdf_fwrite_f77(d,nbpwi8,lengthf,fp) c c - - truncate file and close c call sdf_ftc_f77(fp,lengthf*(nbpwf+nbpwd+nbpwi+nbpwi8)) call sdf_fclose_f77(fp) c c - - byteswap back if necessary, if calculations will then be done with c - - a,b,c,d. Otherwise, values of these variables will be completely c - - messed up c if(ise .eq. 1) then call byteswap_f77(a,lengthf,nbpwf) call byteswap_f77(b,lengthf,nbpwd) call byteswap_f77(c,lengthf,nbpwi) call byteswap_f77(d,lengthf,nbpwi8) endif c a=0. b=dble(0.) c=0 d=0 c call sdf_fopen_f77(fname,"rb",fp) call sdf_fread_f77(a,nbpwf,lengthf,fp) call sdf_fread_f77(b,nbpwd,lengthf,fp) call sdf_fread_f77(c,nbpwi,lengthf,fp) call sdf_fread_f77(d,nbpwi8,lengthf,fp) call sdf_fclose_f77(fp) c c - - byteswap if necessary, after reading in data c if(ise .eq. 1) then call byteswap_f77(a,lengthf,nbpwf) call byteswap_f77(b,lengthf,nbpwd) call byteswap_f77(c,lengthf,nbpwi) call byteswap_f77(d,lengthf,nbpwi8) endif write(6,*) "a = ",a write(6,*) "b = ",b write(6,*) "c = ",c write(6,*) "d = ",d c stop end