#!/usr/bin/python3

# The input files are xz planes generated by ExtractPlanes

import numpy as np
import struct
import matplotlib.pyplot as plt
import sys

nx1 = 2560 # number of points in Ox
nx2 = 2560 # number of points in Oz

threshold1 = 0.2
threshold2 = 1.9

# do not edit
if ( len(sys.argv) <= 1 ):
    print("Usage: python $0 list-of-files.")
    quit()

setoffiles = sorted(sys.argv[1:])

sizeofdata = 4 # Single precision

for file in setoffiles:
    print("Processing file %s ..." % file)
    fin = open(file, 'rb')
    raw = fin.read()
    a = np.array(struct.unpack('>{}f'.format(fin.tell()/sizeofdata), raw))
    a = a.reshape((nx2,nx1))
    fin.close()

    a_mk = np.ma.masked_where( (a < threshold1) | (a > threshold2), a)
    n = np.ma.MaskedArray.count(a_mk)
    print( 'Unmasked fraction: {:5.4f}'.format(float(n)/float(nx1*nx2)) )

    # plt.figure()
    # plt.pcolormesh(a)
    # plt.axis('equal')
    # plt.colorbar()
    # plt.title(file)

    # plt.show()
