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 36 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 171 of file conversions.F90.

171  class(*), pointer, intent(in) :: generic
172  logical, intent(in) :: makecopy
173  integer, intent(in) :: str_length
174  character(len=str_length), pointer :: generic_to_string, temporary_generic_ptr
175 
176  select type(generic)
177  type is (character(len=*))
178  if (makecopy) then
179  ! Need to do this to enforce string length information
180  temporary_generic_ptr=>generic
181  allocate(generic_to_string, source=temporary_generic_ptr)
182  else
183  generic_to_string=>generic
184  end if
185  class default
186  generic_to_string=>null()
187  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 194 of file conversions.F90.

194  integer, intent(in) :: input
195  character(len=15) :: integer_to_string
196 
197  write(integer_to_string, '(i15)' ) input
198  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 326 of file conversions.F90.

326  logical, intent(in) :: input
327  character(len=5) :: logical_to_string
328 
329  if (input) then
330  logical_to_string = "true"
331  else
332  logical_to_string = "false"
333  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 239 of file conversions.F90.

239  real(kind=DOUBLE_PRECISION), intent(in) :: input
240  character(len=30) :: real_double_to_string
241  integer, optional :: decimal_places
242  logical, optional :: exponent, exponent_small_numbers
243 
244  logical :: transformed
245  transformed=.false.
246 
247  if (present(exponent)) then
248  if (exponent) then
249  write(real_double_to_string, '(es30.10)' ) input
250  transformed=.true.
251  end if
252  end if
253  if (present(exponent_small_numbers)) then
254  if (exponent_small_numbers) then
255  write(real_double_to_string, '(g30.10)' ) input
256  transformed=.true.
257  end if
258  end if
259  if (.not. transformed) then
260  write(real_double_to_string, '(f30.10)' ) input
261  if (scan(real_double_to_string, "*") .ne. 0) write(real_double_to_string, '(es30.10)' ) input
262  end if
263  call trim_trailing_zeros(real_double_to_string, 2)
264  if (present(decimal_places)) then
265  call limit_to_decimal_places(real_double_to_string, decimal_places)
266  end if
267 
268  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 205 of file conversions.F90.

205  real(kind=SINGLE_PRECISION), intent(in) :: input
206  character(len=30) :: real_single_to_string
207  integer, optional :: decimal_places
208  logical, optional :: exponent, exponent_small_numbers
209 
210  logical :: transformed
211  transformed=.false.
212 
213  if (present(exponent)) then
214  if (exponent) then
215  write(real_single_to_string, '(es30.10)' ) input
216  transformed=.true.
217  end if
218  end if
219  if (present(exponent_small_numbers)) then
220  if (exponent_small_numbers) then
221  write(real_single_to_string, '(g30.10)' ) input
222  transformed=.true.
223  end if
224  end if
225  if (.not. transformed) then
226  write(real_single_to_string, '(f30.10)' ) input
227  if (scan(real_single_to_string, "*") .ne. 0) write(real_single_to_string, '(es30.10)' ) input
228  end if
229  call trim_trailing_zeros(real_single_to_string, 2)
230  if (present(decimal_places)) call limit_to_decimal_places(real_single_to_string, decimal_places)
231 
232  real_single_to_string = trim(adjustl(real_single_to_string))

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