Changeset 1236 for trunk/GSASIIpy3.py


Ignore:
Timestamp:
Mar 5, 2014 1:51:53 PM (8 years ago)
Author:
toby
Message:

Add FXYE & XYE exporters; allow multiple powder exports; fix formatting of float32 intensities (which should be gone); minor sequential refinement changes; remove old export patterns items; new padded format routine

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpy3.py

    r1183 r1236  
    3939    return val
    4040
     41def FormatPadValue(val,maxdigits=None):
     42    '''Format a float to fit in ``maxdigits[0]`` spaces with maxdigits[1] after decimal.
     43
     44    :param float val: number to be formatted.
     45
     46    :param list maxdigits: the number of digits & places after decimal to be used for display of the
     47      number (defaults to [10,2]).
     48
     49    :returns: a string with exactly maxdigits[0] characters (except under error conditions),
     50      but last character will always be a space
     51    '''
     52    if maxdigits is None:
     53        digits = [10,2]
     54    else:
     55        digits = maxdigits
     56    fmt = '{:'+str(digits[0])+'}'
     57    s = fmt.format(FormatValue(val,digits))
     58    if s[-1] == ' ':
     59        return s
     60    else:
     61        return s+' '
     62   
     63
    4164def FormatValue(val,maxdigits=None):
    4265    '''Format a float to fit in ``maxdigits[0]`` spaces with maxdigits[1] after decimal.
     
    4770      number (defaults to [10,2]).
    4871
    49     :returns: a string with <= maxdigits characters (I hope). 
     72    :returns: a string with <= maxdigits characters (usually). 
    5073    '''
    5174    if maxdigits is None:
     
    78101        fmt = "{" + (":{:d}.{:d}g".format(digits[0],decimals))+"}"
    79102    try:
    80         return fmt.format(val).strip()
     103        return fmt.format(float(val)).strip()
    81104    except ValueError as err:
    82105        print 'FormatValue Error with val,maxdigits,fmt=',val,maxdigits,fmt
     
    125148        if decimals == 0: fmt += "." # force a decimal place
    126149    try:
    127         return fmt.format(val).strip()
     150        return fmt.format(float(val)).strip()
    128151    except ValueError as err:
    129152        print 'FormatValue Error with val,maxdigits, sigfigs, fmt=',val, maxdigits,sigfigs, fmt
Note: See TracChangeset for help on using the changeset viewer.