Source code for fudge.gnds.miscellaneous

# <<BEGIN-copyright>>
# <<END-copyright>>

import sys
import copy
import math

from fudge.core.math import *
from xData import standards as standardsModule
from xData import axes as axesModule

__metaclass__ = type

[docs]def setStringMember( self, memberName, value ) : if( not( isinstance( value, str ) ) ) : TypeError( 'value for member %s is not a string' % memberName ) exec( 'self.%s = "%s"' % ( memberName, value ) )
# BRB6 this is not used.
[docs]def find_gndsPath( reactionSuite, gndsPath ) : def find_gndsPath2( parent, paths, gndsPath ) : if( len( paths ) == 0 ) : return( parent ) current, others = paths[0], paths[1:] if( current[:6] == 'label:' ) : label = current[6:] for element in parent : if( element.getLabel( ) == label ) : return( find_gndsPath2( element, others, gndsPath ) ) raise Exception( 'Could not find path fragment = %s in gndsPath = %s' % ( '/'.join( paths ), gndsPath ) ) else : raise Exception( 'Finding element currently not supported for gndsPath = %s' % gndsPath ) return( find_gndsPath2( reactionSuite, gndsPath.split( '/' )[1:], gndsPath ) )
[docs]def floatToString( f, precision = 12 ) : """Returns the shortest string for the float from %f and %e conversion at precision.""" s = ( '%%.%df' % precision ) % f s = s.rstrip( '0' ) t = ( '%%.%de' % precision ) % f t2 = t.split( 'e' ) p = t2[0].rstrip( '0' ) t3 = p + 'e' + t2[1] e = int( t2[1] ) if( ( e < 0 ) and ( ( len( p ) - 2 - e ) > precision ) ) : s = t3 if( len( t3 ) <= len( s ) ) : s = t3 return( s )