File: stdlib_optval.md

package info (click to toggle)
fortran-stdlib 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,008 kB
  • sloc: f90: 24,178; ansic: 1,244; cpp: 623; python: 119; makefile: 13
file content (39 lines) | stat: -rw-r--r-- 828 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
---
title: optval
---

# Default values for optional arguments

[TOC]

## `optval` - fallback value for optional arguments

### Status

Experimental

### Description

Returns `x` if it is present, otherwise `default`. 

This function is intended to be called in a procedure with one or more `optional` arguments, in order to conveniently fall back to a default value if an `optional` argument is not present.

### Syntax

`result = ` [[stdlib_optval(module):optval(interface)]] `(x, default)`

### Arguments

`x`: Shall be of type `integer`, `real`, `complex`, or `logical`, or a scalar of type `character`.

`default`: Shall have the same type, kind, and rank as `x`.

### Return value

If `x` is present, the result is `x`, otherwise the result is `default`.

### Example

```fortran
{!example/optval/example_optval.f90!}
```