[6331] | 1 | # pyOASIS - A Python wrapper for OASIS |
---|
| 2 | # Authors: Philippe Gambron, Rupert Ford |
---|
| 3 | # Copyright (C) 2019 UKRI - STFC |
---|
| 4 | |
---|
| 5 | # This program is free software: you can redistribute it and/or modify |
---|
| 6 | # it under the terms of the GNU Lesser General Public License as |
---|
| 7 | # published by the Free Software Foundation, either version 3 of the |
---|
| 8 | # License, or any later version. |
---|
| 9 | |
---|
| 10 | # This program is distributed in the hope that it will be useful, |
---|
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | # GNU Lesser General Public License for more details. |
---|
| 14 | |
---|
| 15 | # A copy of the GNU Lesser General Public License, version 3, is supplied |
---|
| 16 | # with this program, in the file lgpl-3.0.txt. It is also available at |
---|
| 17 | # <https://www.gnu.org/licenses/lgpl-3.0.html>. |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | import pyoasis |
---|
| 21 | import numpy |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | def asarray(data, dtype=numpy.float64): |
---|
| 25 | """ |
---|
| 26 | Numpy array of double precision floating point numbers in Fortran ordering |
---|
| 27 | |
---|
| 28 | :param data: any object that can be used to initialise a numpy array |
---|
| 29 | |
---|
| 30 | :param dtype: the numpy datatype of the returned array |
---|
| 31 | |
---|
| 32 | :raises PyOasisException: if a Numpy array cannot be initialised |
---|
| 33 | """ |
---|
| 34 | if dtype != numpy.float64 and dtype != numpy.float32: |
---|
| 35 | raise pyoasis.PyOasisException("Array dtype can only be float32 or float64") |
---|
| 36 | try: |
---|
| 37 | return numpy.asfortranarray(data, dtype=dtype) |
---|
| 38 | except: |
---|
| 39 | raise pyoasis.PyOasisException("Unable to initialise the Numpy array") |
---|