@@ -320,16 +320,14 @@ subroutine add_hist(me, x, label, xlim, ylim, xscale, yscale, bins, normed, cumu
320320 logical , intent (in ), optional :: normed ! ! boolean flag that determines whether bin counts are normalized
321321 logical , intent (in ), optional :: cumulative ! ! boolean flag that determines whether histogram represents the cumulative density of dataset
322322
323+ character (len=* ), parameter :: xname = ' x' ! ! x variable name for script
323324 character (len= :), allocatable :: xstr ! ! x values stringified
324325 character (len= :), allocatable :: xlimstr ! ! xlim values stringified
325326 character (len= :), allocatable :: ylimstr ! ! ylim values stringified
326- character (len=* ), parameter :: xname = ' x' ! ! x variable name for script
327- character (len= :), allocatable :: extras ! ! optional stuff
328- character (len= 5 ) :: normedstr= ' ' ! !
329- character (len= 5 ) :: cumulativestr= ' ' ! !
327+ character (len= :), allocatable :: normedstr ! ! optional stuff
328+ character (len= :), allocatable :: cumulativestr ! !
330329 character (len= max_int_len) :: binsstr ! !
331330
332-
333331 if (allocated (me% str)) then
334332
335333 ! axis limits (optional):
@@ -345,21 +343,8 @@ subroutine add_hist(me, x, label, xlim, ylim, xscale, yscale, bins, normed, cumu
345343
346344 ! get optional inputs (if not present, set default value):
347345 call optional_int_to_string(bins, binsstr, ' 10' )
348-
349- ! optional arguments:
350- if (present (bins)) extras = extras// ' ,' // ' bins="' // binsstr// ' "'
351-
352- if (present (normed) .and. normed) then
353- normedstr = ' True'
354- else
355- normedstr = ' False'
356- end if
357-
358- if (present (cumulative) .and. cumulative) then
359- cumulativestr = ' True'
360- else
361- cumulativestr = ' False'
362- end if
346+ call optional_logical_to_string(normed, normedstr, ' False' )
347+ call optional_logical_to_string(cumulative, cumulativestr, ' False' )
363348
364349 ! write the plot statement:
365350 call me% add_str(' ax.hist(' // &
@@ -690,6 +675,31 @@ subroutine optional_int_to_string(int_value, string_value, default_value)
690675 end subroutine optional_int_to_string
691676! *****************************************************************************************
692677
678+ ! *****************************************************************************************
679+ ! > author: Jacob Williams
680+ !
681+ ! Logical to string, specifying the default value if
682+ ! the optional argument is not present.
683+
684+ subroutine optional_logical_to_string (logical_value , string_value , default_value )
685+
686+ logical ,intent (in ),optional :: logical_value
687+ character (len= :),allocatable ,intent (out ) :: string_value ! ! integer value stringified
688+ character (len=* ),intent (in ) :: default_value ! ! default integer value
689+
690+ if (present (logical_value)) then
691+ if (logical_value) then
692+ string_value = ' True'
693+ else
694+ string_value = ' False'
695+ end if
696+ else
697+ string_value = default_value
698+ end if
699+
700+ end subroutine optional_logical_to_string
701+ ! *****************************************************************************************
702+
693703! *****************************************************************************************
694704! > author: Jacob Williams
695705!
0 commit comments