#! /usr/bin/env python # def s_to_l4 ( s ): #*****************************************************************************80 # ## S_TO_L4 reads a logical value from a string. # # Discussion: # # There are several ways of representing logical data that this routine # recognizes: # # False True # ----- ---- # # 0 1 # F T # f t # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 21 November 2015 # # Author: # # John Burkardt # # Parameters: # # Input, string S, the string to be read. # # Output, bool L, the logical value read from the string. # from sys import exit s_length = len ( s ) for i in range ( 0, s_length ): if ( s[i] == '0' or s[i] == 'F' or s[i] == 'f' ): l = False return l elif ( s[i] == '1' or s[i] == 'T' or s[i] == 't' ): l = True return l print ( '' ) print ( 'S_TO_L4 - Fatal error!' ) print ( ' The input string did not contain logical data.' ) exit ( 'S_TO_L4 - Fatal error!' ) def s_to_l4_test ( ): #*****************************************************************************80 # ## S_TO_L4_TEST tests S_TO_L4. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 21 November 2015 # # Author: # # John Burkardt # test_num = 10 import numpy as np s_test = [ \ '0 ', \ 'F ', \ 'f ', \ '1 ', \ 'T ', \ 't ', \ ' 0 ', \ ' 1 0 ', \ ' 01 ', \ ' Talse' ] print ( '' ) print ( 'S_TO_L4_TEST' ) print ( ' S_TO_L4 reads logical data from a string.' ) print ( '' ) print ( ' S L4' ) print ( '' ) for test in range ( 0, test_num ): s = s_test[test] l4 = s_to_l4 ( s ) print ( ' "%7s" %s' % ( s, l4 ) ) # # Terminate. # print ( '' ) print ( 'S_TO_L4_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) s_to_l4_test ( ) timestamp ( )