BraWl
Loading...
Searching...
No Matches
command_line::get_arg Interface Reference

read arguments by name or number More...

Public Member Functions

logical function get_arg_num_logical (num, val, exists)
 read by number for logical values
 
logical function get_arg_name_logical (name, val, exists)
 Read by name for logical values.
 
logical function get_arg_num_int (num, val, exists)
 read by number for integer values
 
logical function get_arg_name_int (name, val, exists)
 read by name for integer values
 
logical function get_arg_num_long (num, val, exists)
 read by number for long integer values
 
logical function get_arg_name_long (name, val, exists)
 read by name for long integer values
 
logical function get_arg_num_float (num, val, exists)
 Read by number for single precision (float) values.
 
logical function get_arg_name_float (name, val, exists)
 read by name for single precision (float) values
 
logical function get_arg_num_dbl (num, val, exists)
 read by number for double precision values
 
logical function get_arg_name_dbl (name, val, exists)
 read by name for double precision values
 
logical function get_arg_num_str (num, val, exists)
 read by number for string/character values
 
logical function get_arg_name_str (name, val, exists)
 read by name for string values
 

Detailed Description

read arguments by name or number

Get arguments. if the first parameter is a string, this is interpreted as the name of the parameter, if an integer, it is the position of the argument in the input list.

Author
H. Ratcliffe
Date
2024
Parameters
nameName to look up (supply this or num)
numArg. number to look up (supply this or name)
valValue to read into, with type matching that to parse as
existsWhether the name was found
Returns
True if the name is found and parsed, false otherwise

Definition at line 73 of file command_line.f90.

Member Function/Subroutine Documentation

◆ get_arg_name_dbl()

logical function command_line::get_arg::get_arg_name_dbl ( character(len=*), intent(in) name,
real(kind=real64), intent(inout) val,
logical, intent(out), optional exists )

read by name for double precision values

Author
H. Ratcliffe
Date
2024
Parameters
nameargument name to look up
valvalue to read into
existswhether the name was found
Returns
true if the name is found and parsed, false otherwise

Definition at line 379 of file command_line.f90.

380
381 logical :: get_arg_name_dbl
382 character(len=*), intent(in) :: name
383 real(kind=real64), intent(inout) :: val
384 integer :: i
385 logical, intent(out), optional :: exists
386 logical :: found
387 integer :: ierr
388
389 call initial_parse
390
391 found = .false.
392 ! our cmd_arg type is already initialised to the sentinel
393 do i = 1, num_args
394 if(all_args(i)%name == trim(adjustl(name))) then
395 found = .true.
396 read(all_args(i)%value, *, iostat=ierr) val
397 exit
398 end if
399 end do
400
401 if(present(exists)) then
402 exists = found
403 end if
404
405 ! return value is whether value is found and correctly parsed
406 get_arg_name_dbl = (found .and. (ierr == 0))
407
Here is the call graph for this function:

◆ get_arg_name_float()

logical function command_line::get_arg::get_arg_name_float ( character(len=*), intent(in) name,
real(kind=real32), intent(inout) val,
logical, intent(out), optional exists )

read by name for single precision (float) values

Author
H. Ratcliffe
Date
2024
Parameters
nameargument name to look up
valvalue to read into
existswhether the name was found
Returns
true if the name is found and parsed, false otherwise

Definition at line 453 of file command_line.f90.

454 logical :: get_arg_name_float
455 character(len=*), intent(in) :: name
456 real(kind=real32), intent(inout) :: val
457 real(kind=real64) :: tmp
458 logical, intent(out), optional :: exists
459
460 get_arg_name_float = get_arg_name_dbl(name, tmp, exists)
461 if( abs(tmp) < huge(val)) then
462 !value in range. convert. note: there may be precision loss
463 val = real(tmp, kind=real32)
464 else
465 !value out of range, can't be parsed
466 get_arg_name_float = .false.
467 end if
468
Here is the call graph for this function:

◆ get_arg_name_int()

logical function command_line::get_arg::get_arg_name_int ( character(len=*), intent(in) name,
integer(kind=int32), intent(inout) val,
logical, intent(out), optional exists )

read by name for integer values

Author
H. Ratcliffe
Date
2024
Parameters
nameargument name to look up
valvalue to read into
existswhether the name was found
Returns
true if the name is found and parsed, false otherwise

Definition at line 521 of file command_line.f90.

522
523 logical :: get_arg_name_int
524 character(len=*), intent(in) :: name
525 integer(kind=int32), intent(inout) :: val
526 integer :: i
527 logical, intent(out), optional :: exists
528 logical :: found
529 integer :: ierr
530
531 call initial_parse
532
533 found = .false.
534 ! our cmd_arg type is already initialised to the sentinel
535 do i = 1, num_args
536 if(all_args(i)%name == trim(adjustl(name))) then
537 found = .true.
538 read(all_args(i)%value, *, iostat=ierr) val
539 exit
540 end if
541 end do
542
543 if(present(exists)) then
544 exists = found
545 end if
546
547 ! return value is whether value is found and correctly parsed
548 get_arg_name_int = (found .and. (ierr == 0))
549
Here is the call graph for this function:

◆ get_arg_name_logical()

logical function command_line::get_arg::get_arg_name_logical ( character(len=*), intent(in) name,
logical, intent(inout) val,
logical, intent(out), optional exists )

Read by name for logical values.

Note : a flag (name with no '=value' part) will parse as .true. if present, and .false. if not

Author
H. Ratcliffe
Date
2024
Parameters
nameArgument name to look up
valValue to read into
existsWhether the name was found
Returns
true if the name is found and parsed, false otherwise

Definition at line 291 of file command_line.f90.

292
293 logical :: get_arg_name_logical
294 character(len=*), intent(in) :: name
295 logical, intent(inout) :: val
296 integer :: i
297 logical, intent(out), optional :: exists
298 logical :: found
299 integer :: ierr
300
301 call initial_parse
302
303 found = .false.
304 val = .false.
305 ierr = 0
306 ! our cmd_arg type is already initialised to the sentinel
307 do i = 1, num_args
308 if(all_args(i)%name == trim(adjustl(name))) then
309 found = .true.
310 if(all_args(i)%has_value) then
311 read(all_args(i)%value, *, iostat=ierr) val
312 else
313 val = .true.
314 end if
315 exit
316 end if
317 end do
318
319 if(present(exists)) then
320 exists = found
321 end if
322
323 ! return value is whether value is found and correctly parsed
324 get_arg_name_logical = (found .and. (ierr == 0))
325
Here is the call graph for this function:

◆ get_arg_name_long()

logical function command_line::get_arg::get_arg_name_long ( character(len=*), intent(in) name,
integer(kind=int64), intent(inout) val,
logical, intent(out), optional exists )

read by name for long integer values

Author
H. Ratcliffe
Date
2024
Parameters
nameargument name to look up
valvalue to read into
existswhether the name was found
Returns
true if the name is found and parsed, false otherwise

Definition at line 601 of file command_line.f90.

602
603 logical :: get_arg_name_long
604 character(len=*), intent(in) :: name
605 integer(kind=int64), intent(inout) :: val
606 integer :: i
607 logical, intent(out), optional :: exists
608 logical :: found
609 integer :: ierr
610
611 call initial_parse
612
613 found = .false.
614 ! our cmd_arg type is already initialised to the sentinel
615 do i = 1, num_args
616 if(all_args(i)%name == trim(adjustl(name))) then
617 found = .true.
618 read(all_args(i)%value, *, iostat=ierr) val
619 exit
620 end if
621 end do
622
623 if(present(exists)) then
624 exists = found
625 end if
626
627 ! return value is whether value is found and correctly parsed
628 get_arg_name_long = (found .and. (ierr == 0))
629
Here is the call graph for this function:

◆ get_arg_name_str()

logical function command_line::get_arg::get_arg_name_str ( character(len=*), intent(in) name,
character(len=*), intent(inout) val,
logical, intent(out), optional exists )

read by name for string values

Note: if the string passed is shorter than the value, it will be truncated if the length is not known use get_arg_value to get an allocatable string

Author
H. Ratcliffe
Date
2024
Parameters
nameargument name to look up
valvalue to read into
existswhether the name was found - this is already contained in the return value, but is given for consistency with the other members
Returns
true if the name is found and parsed, false otherwise

Definition at line 686 of file command_line.f90.

687
688 logical :: get_arg_name_str
689 character(len=*), intent(in) :: name
690 character(len=*), intent(inout) :: val
691 integer :: i
692 logical, intent(out), optional :: exists
693 logical :: found
694
695 call initial_parse
696
697 found = .false.
698 do i = 1, num_args
699 if(all_args(i)%name == trim(adjustl(name))) then
700 found = .true.
701 val = all_args(i)%value
702 exit
703 end if
704 end do
705
706 if(present(exists)) then
707 exists = found
708 end if
709
710 ! return value is whether value is found and correctly parsed
711 get_arg_name_str = found
712
Here is the call graph for this function:

◆ get_arg_num_dbl()

logical function command_line::get_arg::get_arg_num_dbl ( integer, intent(in) num,
real(kind=real64), intent(inout) val,
logical, intent(out), optional exists )

read by number for double precision values

Author
H. Ratcliffe
Date
2024
Parameters
numargument number to read
valvalue to read into
existswhether the name was found
Returns
true if the name is found and parsed, false otherwise

Definition at line 340 of file command_line.f90.

341
342 logical :: get_arg_num_dbl
343 integer, intent(in) :: num
344 real(kind=real64), intent(inout) :: val
345 logical, intent(out), optional :: exists
346 logical :: found
347 integer :: ierr
348
349 call initial_parse
350
351 found = .false.
352 ! check requested number is in range
353 if(num <= num_args .and. num > 0) then
354 ! read it from string into value
355 read(all_args(num)%value, *, iostat=ierr) val
356 found = .true.
357 end if
358
359 if(present(exists)) then
360 exists = found
361 end if
362
363 ! return value is whether value is found and correctly parsed
364 get_arg_num_dbl = (found .and. (ierr == 0))
365
Here is the call graph for this function:

◆ get_arg_num_float()

logical function command_line::get_arg::get_arg_num_float ( integer, intent(in) num,
real(kind=real32), intent(inout) val,
logical, intent(out), optional exists )

Read by number for single precision (float) values.

Author
H. Ratcliffe
Date
2024
Parameters
numargument number to read
valvalue to read into
existswhether the name was found
Returns
true if the name is found and parsed, false otherwise

Definition at line 424 of file command_line.f90.

425 logical :: get_arg_num_float
426 integer, intent(in) :: num
427 real(kind=real32), intent(inout) :: val
428 real(kind=real64) :: tmp
429 logical, intent(out), optional :: exists
430
431 get_arg_num_float = get_arg_num_dbl(num, tmp, exists)
432 if( abs(tmp) < huge(val)) then
433 !value in range. convert. note: there may be precision loss
434 val = real(tmp, kind=real32)
435 else
436 !value out of range, can't be parsed
437 get_arg_num_float = .false.
438 end if
439
Here is the call graph for this function:

◆ get_arg_num_int()

logical function command_line::get_arg::get_arg_num_int ( integer, intent(in) num,
integer(kind=int32), intent(inout) val,
logical, intent(out), optional exists )

read by number for integer values

Author
H. Ratcliffe
Date
2024
Parameters
numargument number to read
valvalue to read into
existswhether the name was found
Returns
true if the name is found and parsed, false otherwise

Definition at line 482 of file command_line.f90.

483
484 logical :: get_arg_num_int
485 integer, intent(in) :: num
486 integer(kind=int32), intent(inout) :: val
487 logical, intent(out), optional :: exists
488 logical :: found
489 integer :: ierr
490
491 call initial_parse
492
493 found = .false.
494 ! check requested number is in range
495 if(num <= num_args .and. num > 0) then
496 ! read it from string into value
497 ! we don't need to specify the format in general
498 read(all_args(num)%value, *, iostat=ierr) val
499 found = .true.
500 end if
501
502 if(present(exists)) then
503 exists = found
504 end if
505
506 ! return value is whether value is found and correctly parsed
507 get_arg_num_int = (found .and. (ierr == 0))
508
Here is the call graph for this function:

◆ get_arg_num_logical()

logical function command_line::get_arg::get_arg_num_logical ( integer, intent(in) num,
logical, intent(inout) val,
logical, intent(out), optional exists )

read by number for logical values

Author
H. Ratcliffe
Date
2024
Parameters
numargument number to read
valvalue to read into
existswhether the name was found
Returns
true if the name is found and parsed, false otherwise

Definition at line 249 of file command_line.f90.

250
251 logical :: get_arg_num_logical
252 integer, intent(in) :: num
253 logical, intent(inout) :: val
254 logical, intent(out), optional :: exists
255 logical :: found
256 integer :: ierr
257
258 call initial_parse
259
260 found = .false.
261 ! check requested number is in range
262 if(num <= num_args .and. num > 0) then
263 ! read it from string into value
264 read(all_args(num)%value, *, iostat=ierr) val
265 found = .true.
266 end if
267
268 if(present(exists)) then
269 exists = found
270 end if
271
272 ! return value is whether value is found and correctly parsed
273 get_arg_num_logical = (found .and. (ierr == 0))
274
Here is the call graph for this function:

◆ get_arg_num_long()

logical function command_line::get_arg::get_arg_num_long ( integer, intent(in) num,
integer(kind=int64), intent(inout) val,
logical, intent(out), optional exists )

read by number for long integer values

Author
H. Ratcliffe
Date
2024
Parameters
numargument number to read
valvalue to read into
existswhether the name was found
Returns
true if the name is found and parsed, false otherwise

Definition at line 562 of file command_line.f90.

563
564 logical :: get_arg_num_long
565 integer, intent(in) :: num
566 integer(kind=int64), intent(inout) :: val
567 logical, intent(out), optional :: exists
568 logical :: found
569 integer :: ierr
570
571 call initial_parse
572
573 found = .false.
574 ! check requested number is in range
575 if(num <= num_args .and. num > 0) then
576 ! read it from string into value
577 ! we don't need to specify the format in general
578 read(all_args(num)%value, *, iostat=ierr) val
579 found = .true.
580 end if
581
582 if(present(exists)) then
583 exists = found
584 end if
585
586 ! return value is whether value is found and correctly parsed
587 get_arg_num_long = (found .and. (ierr == 0))
588
Here is the call graph for this function:

◆ get_arg_num_str()

logical function command_line::get_arg::get_arg_num_str ( integer, intent(in) num,
character(len=*), intent(inout) val,
logical, intent(out), optional exists )

read by number for string/character values

Author
H. Ratcliffe
Date
2024
Parameters
numargument number to read
valvalue to read into
existswhether the name was found - this is already contained in the return value, but is given for consistency with the other members
Returns
true if the name is found and parsed, false otherwise

Definition at line 643 of file command_line.f90.

644
645 logical :: get_arg_num_str
646 integer, intent(in) :: num
647 character(len=*), intent(inout) :: val
648 logical, intent(out), optional :: exists
649 logical :: found
650
651 call initial_parse
652
653 found = .false.
654 ! check requested number is in range
655 if(num <= num_args .and. num > 0) then
656 ! read it from string into value
657 ! we don't need to specify the format in general
658 val = all_args(num)%value
659 found = .true.
660 end if
661
662 if(present(exists)) then
663 exists = found
664 end if
665
666 ! return value is whether value is found and correctly parsed
667 get_arg_num_str = found
668
Here is the call graph for this function:

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