MONC
Private Member Functions | List of all members
conversions_mod::conv_to_string Interface Reference

Converts data types to strings. More...

Private Member Functions

character(len=str_length) function, pointer generic_to_string (generic, makecopy, str_length)
 Converts a generic to a string. More...
 
character(len=15) function integer_to_string (input)
 Converts an integer to a string. More...
 
character(len=30) function real_single_to_string (input, decimal_places, exponent, exponent_small_numbers)
 Converts a single precision real to a string. More...
 
character(len=30) function real_double_to_string (input, decimal_places, exponent, exponent_small_numbers)
 Converts a double precision real to a string. More...
 
character(len=5) function logical_to_string (input)
 Converts a logical to a string. More...
 

Detailed Description

Converts data types to strings.

For the generic input then a flag indicating whether to make a copy of the underlying generic data and the length of the resulting string must be specified. For other conversions just the data is needed as the string length is assumed and the returned string does not point to the data provided

Parameters
dataThe data to convert into a string
copyflagFor generic data only: Whether to use a copy of the structured data or not
lengthFor generic data only: Length of the resulting string
Returns
A string. For generic data a pointer to the string or null if generic conversion not possible

Definition at line 38 of file conversions.F90.

Member Function/Subroutine Documentation

◆ generic_to_string()

character(len=str_length) function, pointer conversions_mod::conv_to_string::generic_to_string ( class(*), intent(in), pointer  generic,
logical, intent(in)  makecopy,
integer, intent(in)  str_length 
)
private

Converts a generic to a string.

Parameters
genericThe generic to convert into a string
makecopyWhether to use a copy of the generic data or not
str_lengthLength of the resulting string
Returns
A pointer to the string or null if generic conversion not possible

Definition at line 182 of file conversions.F90.

183  class(*), pointer, intent(in) :: generic
184  logical, intent(in) :: makecopy
185  integer, intent(in) :: str_length
186  character(len=str_length), pointer :: generic_to_string, temporary_generic_ptr
187 
188  select type(generic)
189  type is (character(len=*))
190  if (makecopy) then
191  ! Need to do this to enforce string length information
192  temporary_generic_ptr=>generic
193  allocate(generic_to_string, source=temporary_generic_ptr)
194  else
195  generic_to_string=>generic
196  end if
197  class default
198  generic_to_string=>null()
199  end select

◆ integer_to_string()

character(len=15) function conversions_mod::conv_to_string::integer_to_string ( integer, intent(in)  input)
private

Converts an integer to a string.

Parameters
inputThe integer to convert into a string
Returns
The string of length 15 characters

Definition at line 205 of file conversions.F90.

206  integer, intent(in) :: input
207  character(len=15) :: integer_to_string
208 
209  write(integer_to_string, '(i15)' ) input
210  integer_to_string = trim(adjustl(integer_to_string))

◆ logical_to_string()

character(len=5) function conversions_mod::conv_to_string::logical_to_string ( logical, intent(in)  input)
private

Converts a logical to a string.

Parameters
inputThe logical to convert into a string
Returns
The string of length 5 characters

Definition at line 337 of file conversions.F90.

338  logical, intent(in) :: input
339  character(len=5) :: logical_to_string
340 
341  if (input) then
342  logical_to_string = "true"
343  else
344  logical_to_string = "false"
345  end if

◆ real_double_to_string()

character(len=30) function conversions_mod::conv_to_string::real_double_to_string ( real(kind=double_precision), intent(in)  input,
integer, optional  decimal_places,
logical, optional  exponent,
logical, optional  exponent_small_numbers 
)
private

Converts a double precision real to a string.

Parameters
inputThe real to convert into a string
Returns
The string of length 30 characters

Definition at line 250 of file conversions.F90.

251  real(kind=double_precision), intent(in) :: input
252  character(len=30) :: real_double_to_string
253  integer, optional :: decimal_places
254  logical, optional :: exponent, exponent_small_numbers
255 
256  logical :: transformed
257  transformed=.false.
258 
259  if (present(exponent)) then
260  if (exponent) then
261  write(real_double_to_string, '(es30.10)' ) input
262  transformed=.true.
263  end if
264  end if
265  if (present(exponent_small_numbers)) then
266  if (exponent_small_numbers) then
267  write(real_double_to_string, '(g30.10)' ) input
268  transformed=.true.
269  end if
270  end if
271  if (.not. transformed) then
272  write(real_double_to_string, '(f30.10)' ) input
273  if (scan(real_double_to_string, "*") .ne. 0) write(real_double_to_string, '(es30.10)' ) input
274  end if
275  call trim_trailing_zeros(real_double_to_string, 2)
276  if (present(decimal_places)) then
277  call limit_to_decimal_places(real_double_to_string, decimal_places)
278  end if
279 
280  real_double_to_string = trim(adjustl(real_double_to_string))

◆ real_single_to_string()

character(len=30) function conversions_mod::conv_to_string::real_single_to_string ( real(kind=single_precision), intent(in)  input,
integer, optional  decimal_places,
logical, optional  exponent,
logical, optional  exponent_small_numbers 
)
private

Converts a single precision real to a string.

Parameters
inputThe real to convert into a string
Returns
The string of length 30 characters

Definition at line 216 of file conversions.F90.

217  real(kind=single_precision), intent(in) :: input
218  character(len=30) :: real_single_to_string
219  integer, optional :: decimal_places
220  logical, optional :: exponent, exponent_small_numbers
221 
222  logical :: transformed
223  transformed=.false.
224 
225  if (present(exponent)) then
226  if (exponent) then
227  write(real_single_to_string, '(es30.10)' ) input
228  transformed=.true.
229  end if
230  end if
231  if (present(exponent_small_numbers)) then
232  if (exponent_small_numbers) then
233  write(real_single_to_string, '(g30.10)' ) input
234  transformed=.true.
235  end if
236  end if
237  if (.not. transformed) then
238  write(real_single_to_string, '(f30.10)' ) input
239  if (scan(real_single_to_string, "*") .ne. 0) write(real_single_to_string, '(es30.10)' ) input
240  end if
241  call trim_trailing_zeros(real_single_to_string, 2)
242  if (present(decimal_places)) call limit_to_decimal_places(real_single_to_string, decimal_places)
243 
244  real_single_to_string = trim(adjustl(real_single_to_string))

The documentation for this interface was generated from the following file: