#! /usr/bin/env python

import numpy as np
import matplotlib.pyplot as plt

# Here we load the topography data file
ttt = '>i2' # MSB_INTEGER 16-bit
a = np.fromfile(open("ETOPO5.DAT", "r"), dtype=ttt)
dt = np.dtype((ttt, (2160, 4320)))
print np.shape(a)
# Here we calibrate the size of the topography data file
x = np.squeeze(np.frombuffer(a,dt))

# Here we define the longitude/latitude grid
lat=2160
lon=4320
latitude=np.zeros(lat,dtype='f')
longitude=np.zeros(lon,dtype='f')
for i in range(0,lon,1):
   longitude[i]=-180.+i/12.
for j in range(0,lat,1):
   latitude[j]=90.-j/12.
# Here we make the histogram
plt.figure(1)
plt.hist(x.flatten()/1000.,bins=30)
plt.ylabel('Number of bins')
plt.xlabel('elevation (km)')

# Here we plot the map of the topography
plt.figure(2)
plt.xlabel('longitude')
plt.ylabel('latitude')
plt.contourf(longitude,latitude,x/1000.)
plt.colorbar()
plt.show()
