diff --git a/src/addon/esmpy/doc/api.rst b/src/addon/esmpy/doc/api.rst index d10194e6e0..f28c2f8582 100644 --- a/src/addon/esmpy/doc/api.rst +++ b/src/addon/esmpy/doc/api.rst @@ -941,7 +941,7 @@ MPI.Spawn raise ValueError('Could not connect to parent - ' + usage) # worker code goes here, regridding etc.. - print "Hello World from PET #"+str(rank) + print("Hello World from PET #"+str(rank)) # Shutdown comm.Disconnect() diff --git a/src/addon/esmpy/examples/mpi_spawn_regrid.py b/src/addon/esmpy/examples/mpi_spawn_regrid.py index 10d5bedf11..8d4cd4b6ff 100644 --- a/src/addon/esmpy/examples/mpi_spawn_regrid.py +++ b/src/addon/esmpy/examples/mpi_spawn_regrid.py @@ -11,6 +11,7 @@ from esmpy.util.cache_data import DATA_DIR from esmpy.util.exceptions import DataMissing +from functools import reduce # The data files can be retrieved from the ESMF data repository by uncommenting the # following block of code: @@ -94,8 +95,8 @@ def compute_error(dstfield, xctfield): meanrelerr = relerr / num_nodes meanrelerr = relerr / num_nodes - print "ESMPy regridding as a spawned MPI process:" - print " interpolation mean relative error = {0}".format(meanrelerr) + print("ESMPy regridding as a spawned MPI process:") + print(" interpolation mean relative error = {0}".format(meanrelerr)) ########################################### MAIN ############################# diff --git a/src/addon/esmpy/src/esmpy/fragments/dump_esmf_internal_info.py b/src/addon/esmpy/src/esmpy/fragments/dump_esmf_internal_info.py index ed9b5f33b1..4175b0324e 100644 --- a/src/addon/esmpy/src/esmpy/fragments/dump_esmf_internal_info.py +++ b/src/addon/esmpy/src/esmpy/fragments/dump_esmf_internal_info.py @@ -1,3 +1,4 @@ +from functools import reduce # This file contains old routines to dump internal ESMF info from ESMPy Grid and Field objects # This code is likely obsolete, but was useful in the original development process .. # so it is being kept for a rainy day situation @@ -6,11 +7,11 @@ def dump_gridinfo(self, stagger): [x,y,z] = [0,1,2] - print "bounds - low, high" - print self.lower_bounds[stagger], \ - self.upper_bounds[stagger] - print "shape - [x, y, z] or [lat, lon]" - print self.coords[stagger][0].shape + print("bounds - low, high") + print(self.lower_bounds[stagger], \ + self.upper_bounds[stagger]) + print("shape - [x, y, z] or [lat, lon]") + print(self.coords[stagger][0].shape) if self.rank == 2: return [self.coords[stagger][x], self.coords[stagger][y]] @@ -20,11 +21,11 @@ def dump_gridinfo(self, stagger): def dump_gridinfo_lower(self, stagger): [x, y, z] = [0, 1, 2] - print "bounds - low, high" - print self.lower_bounds[stagger], \ - self.upper_bounds[stagger] - print "shape - [x, y, z] or [lat, lon]" - print self.coords[stagger][0].shape + print("bounds - low, high") + print(self.lower_bounds[stagger], \ + self.upper_bounds[stagger]) + print("shape - [x, y, z] or [lat, lon]") + print(self.coords[stagger][0].shape) # retrieve buffers to esmf coordinate memory gridptrX = self.get_grid_coords_from_esmc(x, stagger) @@ -67,10 +68,10 @@ def dump_gridinfo_ctypes(self, stagger, dim=2): np.dtype(constants._ESMF2PythonType[self.type]).itemsize*size) ycoords = np.frombuffer(ybuffer, constants._ESMF2PythonType[self.type]) - print "DIAGNOSTICS:" - print "self.type = ", self.type - print "constants._ESMF2PythonType", constants._ESMF2PythonType[self.type] - print "constants._ESMF2PythonType.itemsize", constants._ESMF2PythonType[self.type].itemsize + print("DIAGNOSTICS:") + print("self.type = ", self.type) + print("constants._ESMF2PythonType", constants._ESMF2PythonType[self.type]) + print("constants._ESMF2PythonType.itemsize", constants._ESMF2PythonType[self.type].itemsize) # find the size of the local coordinates at this stagger location @@ -80,12 +81,12 @@ def dump_gridinfo_ctypes(self, stagger, dim=2): # these appear to both return bounds information only lb, ub = ESMP_GridGetCoordBounds(self, staggerloc=stagger) - print "Bounds:" - print " ESMPy.Grid: ", size - print " ESMPy.ctypes1: ", lb, ub + print("Bounds:") + print(" ESMPy.Grid: ", size) + print(" ESMPy.ctypes1: ", lb, ub) - print "Coordinates:" + print("Coordinates:") I = ub[x]-lb[x] J = ub[y]-lb[y] if dim == 3: @@ -103,7 +104,7 @@ def dump_gridinfo_ctypes(self, stagger, dim=2): (ycoords[ind] > -1e-10 and 1e-10 > ycoords[ind] and ycoords[ind] != 0) or \ ycoords[ind] > 90: - print "[", i, ", ", j, "] = [", xcoords[ind], ", ", ycoords[ind], "]" + print("[", i, ", ", j, "] = [", xcoords[ind], ", ", ycoords[ind], "]") coordcount += 1 elif dim == 3: @@ -113,9 +114,9 @@ def dump_gridinfo_ctypes(self, stagger, dim=2): np.dtype(constants._ESMF2PythonType[self.type]).itemsize*size) zcoords = np.frombuffer(zbuffer, constants._ESMF2PythonType[self.type]) - for i in xrange(I): - for j in xrange(J): - for k in xrange(K): + for i in range(I): + for j in range(J): + for k in range(K): ind = i*I + j*J + k if (1e-10 > xcoords[ind] and xcoords[ind] != 0) or \ xcoords[ind] > 360 or \ @@ -123,10 +124,10 @@ def dump_gridinfo_ctypes(self, stagger, dim=2): (ycoords[ind] > -1e-10 and 1e-10 > ycoords[ind] and ycoords[ind] != 0) or \ ycoords[ind] > 90: - print "[", i, ", ", j, "] = [", xcoords[ind], ", ", ycoords[ind], "]" + print("[", i, ", ", j, "] = [", xcoords[ind], ", ", ycoords[ind], "]") coordcount += 1 - print "Coordcount = ", coordcount + print("Coordcount = ", coordcount) ''' # create a numpy array to point to the ESMF allocation # reshape the numpy array of coordinates using Fortran ordering in Grid @@ -148,4 +149,4 @@ def _dump_field_coords_(self): np.dtype(constants._ESMF2PythonType[self.type]).itemsize*size) esmf_coords = np.frombuffer(buffer, constants._ESMF2PythonType[self.type]) - print esmf_coords + print(esmf_coords) diff --git a/src/addon/esmpy/src/esmpy/fragments/extras.py b/src/addon/esmpy/src/esmpy/fragments/extras.py index 9d357fceb2..f247f586b0 100644 --- a/src/addon/esmpy/src/esmpy/fragments/extras.py +++ b/src/addon/esmpy/src/esmpy/fragments/extras.py @@ -112,11 +112,11 @@ def ESMP_ArraySpecSet(arrayspec, rank, typekind): if rc != _ESMP_SUCCESS: raise NameError('ESMC_ArraySpecSet() failed with rc = '+str(rc)) arrayspec.shallowMem = las.value - print 'sizeof(arrayspec) = '+str(sizeof(arrayspec)) - print 'arrayspec = '+str(arrayspec) - print 'sizeof(las) = '+str(sizeof(las)) - print 'las = '+str(las) - print "\n" + print('sizeof(arrayspec) = '+str(sizeof(arrayspec))) + print('arrayspec = '+str(arrayspec)) + print('sizeof(las) = '+str(sizeof(las))) + print('las = '+str(las)) + print("\n") return arrayspec diff --git a/src/addon/esmpy/src/esmpy/fragments/remap.py b/src/addon/esmpy/src/esmpy/fragments/remap.py index 8484f17b88..6dce0f167d 100755 --- a/src/addon/esmpy/src/esmpy/fragments/remap.py +++ b/src/addon/esmpy/src/esmpy/fragments/remap.py @@ -101,7 +101,7 @@ def remap(srcgrid, dstgrid, weights, method='bilinear'): if os.environ.get('ESMF_NUM_PROCS'): NUM_PROCS = os.environ.get('ESMF_NUM_PROCS') else: - print "ESMF_NUM_PROCS not defined in user environment, using default ESMF_NUM_PROCS=1" + print("ESMF_NUM_PROCS not defined in user environment, using default ESMF_NUM_PROCS=1") NUM_PROCS = "1" # read the esmf.mk and get the location of the executable and the OS for @@ -109,7 +109,7 @@ def remap(srcgrid, dstgrid, weights, method='bilinear'): if os.environ.get('ESMFMKFILE'): esmfmkfile = open(os.environ.get('ESMFMKFILE')) else: - print "ESMFMKFILE is not defined!" + print("ESMFMKFILE is not defined!") sys.exit for line in esmfmkfile: @@ -137,7 +137,7 @@ def remap(srcgrid, dstgrid, weights, method='bilinear'): options = '-m conserve' file = 'c' else: - print 'Method: '+method+' is not supported!' + print('Method: '+method+' is not supported!') sys.exit # TODO: what is this cruft?