import numpy import os import random import subprocess import sys from pyhdf.SD import SD, SDC COLS = 3712 LINES = 3712 def do(c, l): popen = subprocess.Popen(('./ref', str(c), str(l)), stdout=subprocess.PIPE, stderr=subprocess.PIPE) rc = popen.wait() if rc != 0: print popen.stderr.read() raise Exception('ref return code %s' % rc) out = popen.stdout.read().split() lat = float(out[5]) if lat <= -999.0: lat = numpy.nan lon = float(out[7]) if lon <= -999.0: lon = numpy.nan print c, l lat_sds[c-1,l-1] = lat lon_sds[c-1,l-1] = lon if os.path.exists('ref.hdf'): sd = SD('ref.hdf', SDC.WRITE) lat_sds = sd.select('Latitude') lon_sds = sd.select('Longitude') else: sd = SD('ref.hdf', SDC.WRITE | SDC.CREATE | SDC.TRUNC) lat_sds = sd.create('Latitude', SDC.FLOAT64, (3712, 3712)) lon_sds = sd.create('Longitude', SDC.FLOAT64, (3712, 3712)) tmp = -999.0 * numpy.ones((3712, 3712)) lat_sds[:] = tmp lon_sds[:] = tmp while True: c = random.randint(1, COLS) l = random.randint(1, LINES) do(c, l)