def determine_dytpe_nfloat_endian_from_ugrid_filename(ugrid_filename=None): """figures out what the format of the binary data is based on the filename""" if ugrid_filename is None: from pyNastran.utils.gui_io import load_file_dialog wildcard_wx = "AFLR3 UGRID (*.ugrid)|" \ "*.ugrid|" \ "All files (*.*)|*.*" wildcard_qt = "AFLR3 UGRID (*.ugrid);;All files (*)" title = 'Please select an AFLR3 UGRID to load' ugrid_filename = load_file_dialog(title, wildcard_wx, wildcard_qt)[0] assert ugrid_filename is not None, ugrid_filename try: unused_base, file_format, ext = os.path.basename(ugrid_filename).split( '.') except ValueError: msg = ('expected file of the form "model.b8.ugrid" ' 'or "model.lb4.ugrid"; actual=%r' % ugrid_filename) raise ValueError(msg) assert ext == 'ugrid', 'extension=%r' % ext if '8' in file_format: ndarray_float = 'float64' float_fmt = 'd' nfloat = 8 elif '4' in file_format: ndarray_float = 'float32' float_fmt = 'f' nfloat = 4 else: # ??? msg = 'file_format=%r ugrid_filename=%s' % (file_format, ugrid_filename) raise NotImplementedError(msg) if 'lb' in file_format: # C binary, little endian endian = '<' elif 'b' in file_format: # C binary, big endian endian = '>' #elif 'lr' in file_format: # Fortran unformatted binary, little endian #endian = '>' #elif 'r' in file_format: # Fortran unformatted binary, big endian #endian = '>' else: # fortran unformatted msg = 'file_format=%r ugrid_filename=%s' % (file_format, ugrid_filename) raise NotImplementedError(msg) return ndarray_float, float_fmt, nfloat, endian, ugrid_filename
def determine_dytpe_nfloat_endian_from_ugrid_filename(ugrid_filename=None): """figures out what the format of the binary data is based on the filename""" if ugrid_filename is None: from pyNastran.utils.gui_io import load_file_dialog wildcard_wx = "AFLR3 UGRID (*.ugrid)|" \ "*.ugrid|" \ "All files (*.*)|*.*" wildcard_qt = "AFLR3 UGRID (*.ugrid);;All files (*)" title = 'Please select an AFLR3 UGRID to load' ugrid_filename = load_file_dialog(title, wildcard_wx, wildcard_qt)[0] assert ugrid_filename is not None, ugrid_filename try: base, file_format, ext = os.path.basename(ugrid_filename).split('.') except ValueError: msg = ('expected file of the form "model.b8.ugrid" ' 'or "model.lb4.ugrid"; actual=%r' % ugrid_filename) raise ValueError(msg) assert ext == 'ugrid', 'extension=%r' % ext if '8' in file_format: ndarray_float = 'float64' float_fmt = 'd' nfloat = 8 elif '4' in file_format: ndarray_float = 'float32' float_fmt = 'f' nfloat = 4 else: # ??? msg = 'file_format=%r ugrid_filename=%s' % (file_format, ugrid_filename) raise NotImplementedError(msg) if 'lb' in file_format: # C binary, little endian endian = '<' elif 'b' in file_format: # C binary, big endian endian = '>' #elif 'lr' in file_format: # Fortran unformatted binary, little endian #endian = '>' #elif 'r' in file_format: # Fortran unformatted binary, big endian #endian = '>' else: # fortran unformatted msg = 'file_format=%r ugrid_filename=%s' % (file_format, ugrid_filename) raise NotImplementedError(msg) return ndarray_float, float_fmt, nfloat, endian, ugrid_filename
def read_f06(self, f06_filename=None): """ Reads the F06 file :self: the object pointer :f06FileName: the file to be parsed (None -> GUI) """ if f06_filename is None: from pyNastran.utils.gui_io import load_file_dialog wildcard_wx = "Nastran F06 (*.f06)|*.f06|" \ "All files (*.*)|*.*" wildcard_qt = "Nastran F06 (*.f06);;All files (*)" title = 'Please select a F06 to load' f06_filename = load_file_dialog(title, wildcard_wx, wildcard_qt) assert f06_filename is not None, f06_filename else: if not os.path.exists(f06_filename): msg = 'cant find f06_filename=%r\n%s' \ % (f06_filename, print_bad_path(f06_filename)) raise RuntimeError(msg) if is_binary(f06_filename): raise IOError('f06_filename=%r is not a binary F06.' % f06_filename) if os.path.getsize(f06_filename) == 0: raise IOError('f06_filename=%r is empty.' % f06_filename) self.log.debug('f06_filename = %r' % f06_filename) self.f06_filename = f06_filename blank = 0 self.infile = open(self.f06_filename, 'r') while 1: #if self.i % 1000 == 0: #print("i=%i" % (self.i)) line = self.infile.readline() marker = line[1:].strip() if 'FATAL' in marker and 'IF THE FLAG IS FATAL' not in marker: msg = '\n' + marker fatal_count = 0 while 1: line = self.infile.readline().rstrip() #print("blank = %s" % blank) fatal_count += 1 if fatal_count == 20 or '* * * END OF JOB * * *' in line: break #else: #blank = 0 msg += line + '\n' raise FatalError(msg.rstrip()) if(marker != '' and 'SUBCASE' not in marker and 'PAGE' not in marker and 'FORTRAN' not in marker and 'USER INFORMATION MESSAGE' not in marker and 'TOTAL DATA WRITTEN FOR DATA BLOCK' not in marker and marker not in self.markers and marker != self._subtitle): #print("marker = %r" % marker) pass #print('Title = %r' % self.subtitle) if marker in self.markers: blank = 0 #print("\n1*marker = %r" % marker) self._marker_map[marker]() if(self._stop_after_reading_mass and marker in 'O U T P U T F R O M G R I D P O I N T W E I G H T G E N E R A T O R'): break self.stored_lines = [] elif 'R E A L E I G E N V E C T O R N O' in marker: blank = 0 #print("\n2*marker = %r" % marker) self._line_marker_map['R E A L E I G E N V E C T O R N O'](marker) #print('done with real eigenvector') self.stored_lines = [] elif 'C O M P L E X E I G E N V E C T O R NO' in marker: blank = 0 #print("\n2*marker = %r" % marker) self._line_marker_map['C O M P L E X E I G E N V E C T O R NO'](marker) self.stored_lines = [] elif 'News file -' in marker: blank = 0 self._line_marker_map['News file -']() self.stored_lines = [] elif marker == '': blank += 1 if blank == 20: break elif self._is_marker(marker): # marker with space in it (e.g. Model Summary) print("***marker = %r" % marker) else: blank = 0 self.stored_lines.append(line) self.i += 1 #print("i=%i" % self.i) self.infile.close() self._process_f06() if hasattr(self, '_ieigenvalue'): del self._ieigenvalue self.build_vectorization()