[cig-commits] [commit] devel, master: Modify topography loader to use binary. (df73113)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Thu Nov 6 08:25:22 PST 2014


Repository : https://github.com/geodynamics/specfem3d_globe

On branches: devel,master
Link       : https://github.com/geodynamics/specfem3d_globe/compare/bc58e579b3b0838a0968725a076f5904845437ca...be63f20cbb6f462104e949894dbe205d2398cd7f

>---------------------------------------------------------------

commit df7311371d25ce266eb8563e63ee2c0a429de18c
Author: Elliott Sales de Andrade <esalesde at physics.utoronto.ca>
Date:   Sun Jul 6 18:49:45 2014 -0400

    Modify topography loader to use binary.
    
    This expects a file containing signed 16-bit integers, as generated
    using the ascii2bin.py script in DATA/topo_bathy/. Byte swapping should
    be handled automatically if necessary.


>---------------------------------------------------------------

df7311371d25ce266eb8563e63ee2c0a429de18c
 setup/constants.h.in            | 16 ++++++++--------
 src/meshfem3D/rules.mk          |  1 +
 src/shared/model_topo_bathy.f90 | 37 +++++++++++++++++--------------------
 src/shared/write_c_binary.c     |  3 ++-
 4 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/setup/constants.h.in b/setup/constants.h.in
index d178771..394de9d 100644
--- a/setup/constants.h.in
+++ b/setup/constants.h.in
@@ -104,8 +104,8 @@
 ! resolution of topography file in minutes
   integer, parameter :: RESOLUTION_TOPO_FILE = 4
 ! pathname of the topography file
-! character (len=*), parameter :: PATHNAME_TOPO_FILE = 'DATA/topo_bathy/topo_bathy_etopo4_from_etopo2_subsampled.dat'
-  character (len=*), parameter :: PATHNAME_TOPO_FILE = 'DATA/topo_bathy/topo_bathy_etopo4_smoothed_window_7.dat'
+! character (len=*), parameter :: PATHNAME_TOPO_FILE = 'DATA/topo_bathy/topo_bathy_etopo4_from_etopo2_subsampled.bin'
+  character (len=*), parameter :: PATHNAME_TOPO_FILE = 'DATA/topo_bathy/topo_bathy_etopo4_smoothed_window_7.bin'
 
 !--- ETOPO2 2-minute model
 ! size of topography and bathymetry file
@@ -114,11 +114,11 @@
 ! integer, parameter :: RESOLUTION_TOPO_FILE = 2
 ! pathname of the topography file
 ! character (len=*), parameter :: PATHNAME_TOPO_FILE = &
-!                      'DATA/topo_bathy/topo_bathy_etopo1_ice_c_resampled_at_2minutes_original_unmodified_unsmoothed.dat'
+!                      'DATA/topo_bathy/topo_bathy_etopo1_ice_c_resampled_at_2minutes_original_unmodified_unsmoothed.bin'
 ! character (len=*), parameter :: PATHNAME_TOPO_FILE = &
-!                      'DATA/topo_bathy/topo_bathy_etopo1_ice_c_resampled_at_2minutes_smoothed_window_3.dat'
-! character (len=*), parameter :: PATHNAME_TOPO_FILE = 'DATA/topo_bathy/topo_bathy_etopo2v2c_original_unmodified_unsmoothed.dat'
-! character (len=*), parameter :: PATHNAME_TOPO_FILE = 'DATA/topo_bathy/topo_bathy_etopo2v2c_smoothed_window_3.dat'
+!                      'DATA/topo_bathy/topo_bathy_etopo1_ice_c_resampled_at_2minutes_smoothed_window_3.bin'
+! character (len=*), parameter :: PATHNAME_TOPO_FILE = 'DATA/topo_bathy/topo_bathy_etopo2v2c_original_unmodified_unsmoothed.bin'
+! character (len=*), parameter :: PATHNAME_TOPO_FILE = 'DATA/topo_bathy/topo_bathy_etopo2v2c_smoothed_window_3.bin'
 
 !--- ETOPO1 1-minute model
 ! size of topography and bathymetry file
@@ -126,8 +126,8 @@
 ! resolution of topography file in minutes
 ! integer, parameter :: RESOLUTION_TOPO_FILE = 1
 ! pathname of the topography file
-! character (len=*), parameter :: PATHNAME_TOPO_FILE = 'DATA/topo_bathy/topo_bathy_etopo1_ice_c_original_unmodified_unsmoothed.dat'
-! character (len=*), parameter :: PATHNAME_TOPO_FILE = 'DATA/topo_bathy/topo_bathy_etopo1_ice_c_smoothed_window_3.dat'
+! character (len=*), parameter :: PATHNAME_TOPO_FILE = 'DATA/topo_bathy/topo_bathy_etopo1_ice_c_original_unmodified_unsmoothed.bin'
+! character (len=*), parameter :: PATHNAME_TOPO_FILE = 'DATA/topo_bathy/topo_bathy_etopo1_ice_c_smoothed_window_3.bin'
 
 
 ! For the reference ellipsoid to convert geographic latitudes to geocentric:
diff --git a/src/meshfem3D/rules.mk b/src/meshfem3D/rules.mk
index 2f5cb11..d28eefd 100644
--- a/src/meshfem3D/rules.mk
+++ b/src/meshfem3D/rules.mk
@@ -185,6 +185,7 @@ meshfem3D_SHARED_OBJECTS = \
 	$O/save_header_file.shared.o \
 	$O/sort_array_coordinates.shared.o \
 	$O/spline_routines.shared.o \
+	$O/write_c_binary.cc.o \
 	$O/write_VTK_file.shared.o \
 	$(EMPTY_MACRO)
 
diff --git a/src/shared/model_topo_bathy.f90 b/src/shared/model_topo_bathy.f90
index 6f9ac9d..766a47e 100644
--- a/src/shared/model_topo_bathy.f90
+++ b/src/shared/model_topo_bathy.f90
@@ -80,35 +80,32 @@
   integer, dimension(NX_BATHY,NY_BATHY) :: ibathy_topo
 
   ! local parameters
-  real :: val
-  integer :: ival
-  integer :: itopo_x,itopo_y,ier
+  integer(kind=8) :: filesize
+  integer(kind=2) :: ival
+  integer :: indx,itopo_x,itopo_y
+  logical :: byteswap
 
   ! reads in topography values from file
-  open(unit=13,file=trim(PATHNAME_TOPO_FILE),status='old',action='read',iostat=ier)
-  if( ier /= 0 ) then
-    print*,'error opening:',trim(PATHNAME_TOPO_FILE)
-    call exit_mpi(0,'error opening topography data file')
-  endif
+  filesize = NX_BATHY * NY_BATHY * 2 + 2
+  call open_file_abs_r(10, trim(PATHNAME_TOPO_FILE), len_trim(PATHNAME_TOPO_FILE), filesize)
+
+  ! checks byte ordering
+  indx = 1
+  call read_abs(10, ival, 2, indx)
+  byteswap = (ival == z'3412')
 
   ! reads in topography array
   do itopo_y=1,NY_BATHY
     do itopo_x=1,NX_BATHY
-      read(13,*,iostat=ier) val
-
-      ! checks
-      if( ier /= 0 ) then
-        print*,'error read topo_bathy: ix,iy = ',itopo_x,itopo_y,val
-        print*,'topo_bathy dimension: nx,ny = ',NX_BATHY,NY_BATHY
-        call exit_mpi(0,'error reading topo_bathy file')
+      indx = indx + 1
+      call read_abs(10, ival, 2, indx)
+      if (byteswap) then
+        ival = ishftc(ival, 8, 16)
       endif
 
-      ! converts to integer
-      ival = nint(val)
-
       ! checks values
       if( ival < TOPO_MINIMUM .or. ival > TOPO_MAXIMUM ) then
-        print*,'error read topo_bathy: ival = ',ival,val,'ix,iy = ',itopo_x,itopo_y
+        print*,'error read topo_bathy: ival = ',ival,'ix,iy = ',itopo_x,itopo_y
         print*,'topo_bathy dimension: nx,ny = ',NX_BATHY,NY_BATHY
         call exit_mpi(0,'error reading topo_bathy file')
       endif
@@ -118,7 +115,7 @@
 
     enddo
   enddo
-  close(13)
+  call close_file_abs(10)
 
   ! user output
   write(IMAIN,*) "  topography/bathymetry: min/max = ",minval(ibathy_topo),maxval(ibathy_topo)
diff --git a/src/shared/write_c_binary.c b/src/shared/write_c_binary.c
index 1724795..73822ce 100644
--- a/src/shared/write_c_binary.c
+++ b/src/shared/write_c_binary.c
@@ -151,7 +151,8 @@ achieved with 16 KB buffers: */
 //                          first 0 - 3 indices for crust mantle files
 //                          last 4 - 8 indices for outer core files
 //                          index 9 - for NOISE_TOMOGRAPHY (SURFACE_MOVIE)
-#define ABS_FILEID 10
+//                          index 10 - for topography file
+#define ABS_FILEID 11
 
 // file points
 static FILE * fp_abs[ABS_FILEID];



More information about the CIG-COMMITS mailing list