Skip to content

Commit

Permalink
Fixed issue where non-numpy NCL types weren't being set as NPY_OBJECT…
Browse files Browse the repository at this point in the history
…. This was causing Python 3 to segfault (it should have been crashing Python 2 as well, but wasn't due to luck). Added future declarations for the print function to python modules. All examples and tests now run.
  • Loading branch information
Bill Ladwig committed Sep 21, 2017
1 parent c425ef9 commit 45d2540
Show file tree
Hide file tree
Showing 7 changed files with 397 additions and 338 deletions.
2 changes: 1 addition & 1 deletion Nio.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
http://www.pyngl.ucar.edu/Nio.html
'''

from __future__ import print_function
from _nio import *

#
Expand Down
2 changes: 1 addition & 1 deletion _xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#@nl
#@<< xarray declarations >>
#@+node:schmidli.20080321230001.2:<< xarray declarations >>
from __future__ import division
from __future__ import division, print_function
import numpy as N
from numpy import asarray

Expand Down
12 changes: 7 additions & 5 deletions alt-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# may be required. See the following comments.
#

from __future__ import print_function

# Test to make sure we actually have NumPy.
try:
import numpy
except ImportError:
print "Error: Cannot import NumPy. Can't continue."
print ("Error: Cannot import NumPy. Can't continue.")
sys.exit()

#
Expand Down Expand Up @@ -74,14 +76,14 @@
# F2CLIBS_PREFIX /sw/lib
#

import os, sys, commands
import os, sys, subprocess

#
# This proceure tries to figure out which extra libraries are
# needed with curl.
#
def set_curl_libs():
curl_libs = commands.getstatusoutput('curl-config --libs')
curl_libs = subprocess.getstatusoutput('curl-config --libs')
if curl_libs[0] == 0:
#
# Split into individual lines so we can loop through each one.
Expand Down Expand Up @@ -113,7 +115,7 @@ def set_curl_libs():
#INC_DIRS = ['libsrc']

except:
print "NCARG_ROOT is not set; can't continue!"
print("NCARG_ROOT is not set; can't continue!")
sys.exit()

# These are the required NCL, HDF4, and NetCDF libraries.
Expand Down Expand Up @@ -342,7 +344,7 @@ def get_grib2_codetables():
# Here are the instructions for compiling the "nio.so" file.
#
#----------------------------------------------------------------------
print '====> Installing Nio to the "'+pynio_pkg_name+'" site packages directory.'
print('====> Installing Nio to the "'+pynio_pkg_name+'" site packages directory.')

module1 = [Extension('nio',
define_macros = DMACROS,
Expand Down
2 changes: 1 addition & 1 deletion coordsel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
index space selection object (correct dimensionality; xsel)
a basic numpy slice object
"""

from __future__ import print_function
import copy
import datetime
import time
Expand Down
8 changes: 5 additions & 3 deletions examples/wcomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
NUMCHARS = 80 # number of characters to use in fixed-length strings.
station_datatype = numpy.array([['latitude', 'f'],
['longitude', 'f'],
['location_name', 'S1', NUMCHARS],
#['location_name', 'S1', NUMCHARS],
['location_name', 'c', NUMCHARS],
['speed', 'f'],
['direction', 'i'],
['temp_sounding', 'f', 10],
Expand All @@ -47,6 +48,7 @@
print("station_datatype:")
print(station_datatype)


#now that station_datatype is defined, create the station data type.
station_data = file.create_compound('station_data', station_datatype, ('station',))

Expand Down Expand Up @@ -74,7 +76,7 @@
data['temp_sounding'] = [280.3,272.,270.,269.,266.,258.,254.1,250.,245.5,240.]
data['press_sounding'] = list(range(800,300,-50))

station = numpy.empty(2, object)
station = numpy.empty(2, "object")

#assign structured array to variable slice.
#station[0] = data
Expand Down Expand Up @@ -103,7 +105,7 @@
#stationobs_units['temp_sounding'] = stringtoarr('Kelvin',NUMCHARS)
#stationobs_units['press_sounding'] = stringtoarr('hPa',NUMCHARS)
#statdat.units = stationobs_units

print (station)
station_data[:] = station

print("file after add compounden:")
Expand Down
1 change: 1 addition & 0 deletions niodict.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
class nioDict (dict):
def __init__(self, *args, **kwargs):
self.update(*args, **kwargs)
Expand Down
Loading

0 comments on commit 45d2540

Please sign in to comment.