creating netcdf file

From: Oleksandr Huziy <guziy.sasha_at_nyahnyahspammersnyahnyah>
Date: Wed Jul 07 2010 - 11:10:32 MDT

Dear list,

I am trying to create netcdf file using Nio.
I cannot save the variable of type integer to the file. Get the following
exception:

fatal:FileWriteVar: Type mismatch, can't perform assignment

Traceback (most recent call last):
  File "/Users/huziy/Netbeans
Projects/Python/PlotWatrouteData/src/binary/test.py", line 35, in <module>
    test()
  File "/Users/huziy/Netbeans
Projects/Python/PlotWatrouteData/src/binary/test.py", line 28, in test
    the_var[:] = data.astype('i')
  File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyNIO/Nio.py",
line 334, in __setitem__
    self._obj[xsel] = value
SystemError: error return without exception set

The code which results in this error:
---------------------------------------------------------------
import Nio as nio
import os
import numpy as np

X_DIM = 'x'
Y_DIM = 'y'
def test():
    file_path = 'test1.nc'
    if os.path.isfile(file_path):
        os.remove(file_path)
    file = nio.open_file(file_path, 'c')
    nx = 10
    ny = 10
    file.create_dimension('x', nx)
    file.create_dimension('y', ny)

    the_var = file.create_variable('int_var', 'i', (X_DIM, Y_DIM))
    data = np.zeros((nx, ny))
    the_var[:] = data.astype('i')

    file.close()

if __name__ == "__main__":
    test()

If I change file.create_variable('int_var', 'i', (X_DIM, Y_DIM)) to
                  file.create_variable('int_var', 'd', (X_DIM, Y_DIM))
it works. Any help is appreciated, thank you.

--
Oleksandr Huziy

_______________________________________________
pyngl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Wed Jul 7 11:10:41 2010

This archive was generated by hypermail 2.1.8 : Wed Aug 04 2010 - 09:35:05 MDT