Ejemplo n.º 1
0
    def readOP4(self, op4Name, matrixNames=None, precision='default'):
        """
        Reads a NASTRAN OUTPUT4 file, regular or sparse, and stores the
        matrices as the output arguments of the function.  The number of matrices
        read is defined by the list matrixNames.  By default, all matrices will
        be read.  The resulting output is a dictionary of matrices that are
        accessed by their name.

		@code
        from pyNastran.op4.op4 import OP4
        op4 = OP4()
        #alternative way to get all the matrices
        matrices = op4.readOP4(op4Name)
        (formA,A) = matrices['A']
        (formB,B) = matrices['B']
        (formC,C) = matrices['C']

        # or to reduce memory usage
        matrices = op4.readOP4(op4Name,matrixNames=['A','B'])
        (formA,A) = matrices['A']
        (formB,B) = matrices['B']

        # or because you only want A
        matrices = op4.readOP4(op4Name,matrixNames='A')
        (formA,A) = matrices['A']
		@endcode

        @param op4Name an OP4 filename.  Type=STRING.
        @param matrixNames list of matrix names (or None); Type=LIST OF STRINGS / NONE.
        @param floatType specifies if the matrices are in single or double precsion
               (values='default','single','double') which means the format will be whatever the file is in

        @retval dictionary of matrices where the key is the name and the value is a matrix:
            Dense Type:  NUMPY.NDARRAY
            Sparse Type: SCIPY.SPARSE.COO_MATRIX

        @note based off the MATLAB code SAVEOP4 developed by ATA-E and later UCSD.
        @note it's strongly recommended that you convert sparse matrices to another
         format before doing math on them.  This is standard with sparse matrices.
        @warning sparse binary is buggy right now        """
        assert precision in [
            'default', 'single', 'double'
        ], "precison=|%s| valid=['default','single','double']"
        if isinstance(matrixNames, str):
            matrixNames = [matrixNames]

        if not os.path.exists(op4Name):
            raise IOError('cannot find op4FileName=|%s|' % (op4Name))
        if is_binary(op4Name):
            return self.readOP4Binary(op4Name, matrixNames, precision)
        else:
            return self.readOP4Ascii(op4Name, matrixNames, precision)
Ejemplo n.º 2
0
    def readOP4(self, op4Name, matrixNames=None, precision='default'):
        """
        Reads a NASTRAN OUTPUT4 file, regular or sparse, and stores the
        matrices as the output arguments of the function.  The number of matrices
        read is defined by the list matrixNames.  By default, all matrices will
        be read.  The resulting output is a dictionary of matrices that are
        accessed by their name.

		@code
        from pyNastran.op4.op4 import OP4
        op4 = OP4()
        #alternative way to get all the matrices
        matrices = op4.readOP4(op4Name)
        (formA,A) = matrices['A']
        (formB,B) = matrices['B']
        (formC,C) = matrices['C']

        # or to reduce memory usage
        matrices = op4.readOP4(op4Name,matrixNames=['A','B'])
        (formA,A) = matrices['A']
        (formB,B) = matrices['B']

        # or because you only want A
        matrices = op4.readOP4(op4Name,matrixNames='A')
        (formA,A) = matrices['A']
		@endcode

        @param op4Name an OP4 filename.  Type=STRING.
        @param matrixNames list of matrix names (or None); Type=LIST OF STRINGS / NONE.
        @param floatType specifies if the matrices are in single or double precsion
               (values='default','single','double') which means the format will be whatever the file is in

        @retval dictionary of matrices where the key is the name and the value is a matrix:
            Dense Type:  NUMPY.NDARRAY
            Sparse Type: SCIPY.SPARSE.COO_MATRIX

        @note based off the MATLAB code SAVEOP4 developed by ATA-E and later UCSD.
        @note it's strongly recommended that you convert sparse matrices to another
         format before doing math on them.  This is standard with sparse matrices.
        @warning sparse binary is buggy right now        """
        assert precision in ['default', 'single', 'double'], "precison=|%s| valid=['default','single','double']"
        if isinstance(matrixNames, str):
            matrixNames = [matrixNames]

        if not os.path.exists(op4Name):
            raise IOError('cannot find op4FileName=|%s|' % (op4Name))
        if is_binary(op4Name):
            return self.readOP4Binary(op4Name, matrixNames, precision)
        else:
            return self.readOP4Ascii(op4Name, matrixNames, precision)
Ejemplo n.º 3
0
def genericCart3DReader(infileName, log=None, debug=False):
    print "infileName = ", infileName
    f = open(infileName, 'rb')
    data = f.read(4)
    f.close()

    if is_binary(infileName):

    #eight, = unpack('>i',data)
    #if eight==8:  # is binary
        #print "Binary eight = ",eight
        obj = Cart3DBinaryReader(log, debug)
    else:
        #print "Ascii eight = ",eight
        obj = Cart3DAsciiReader(log, debug)

    return obj