C Library Functions - uniq (3)
NAME
uniq(3f) - [M_io:QUERY] append a number to the end of filename to make
a unique name if name exists
(LICENSE:PD)
CONTENTS
Synopsis
Description
Options
Returns
Examples
Author
License
SYNOPSIS
Usage
character(len=:),allocatable function uniq(name,istart,verbose,create)
character(len=*),intent(in) :: name
integer,intent(in),optional :: istart
logical,intent(in),optional :: verbose
logical,intent(in),optional :: create
DESCRIPTION
Given a filename test if it is in use or exists. If it is, or if it
ends in a period add a number to the end of the name and
test if the new name exists. If necessary, increment the number and
try again up to the value 9999999. By default an empty file is created
if an unused name is found.
OPTIONS
|
name |
base input name used to create output filename
If name ends in "." a numeric suffix is always added.
|
|
istart |
number to start with as a suffix. Default is 1. Must be a
positive integer less than 9999999.
|
|
verbose |
| |
writes extra messages to stdout. Defaults to .false.
|
|
create |
create file if a new unused name is successfully
found. Defaults to .true. .
|
|
RETURNS
|
uniq |
A unique filename that is the same as the NAME input parameter
except with a number appended at the end if needed. If could
not find a unique name a blank is returned.
|
|
EXAMPLES
Sample program
program demo_uniq
use M_io, only : uniq
implicit none
character(len=4096) :: myname
integer :: i
myname=uniq(does_not_exist)
write(*,*)name stays the same :,trim(myname)
open(unit=10,file=does_exist)
myname=uniq(does_exist)
write(*,*)name has suffix added :,trim(myname)
do i=1,10
myname=uniq(does_exist)
write(*,*) FILENAME:,trim(myname)
open(unit=20+i,file=myname)
enddo
end program demo_uniq
Expected output
name stays the same does_not_exist
name has suffix added does_exist0001
FILENAME:does_exist0002
FILENAME:does_exist0003
FILENAME:does_exist0004
FILENAME:does_exist0005
FILENAME:does_exist0006
FILENAME:does_exist0007
FILENAME:does_exist0008
FILENAME:does_exist0009
FILENAME:does_exist0010
FILENAME:does_exist0011
AUTHOR
John S. Urban, 1993
LICENSE
Public Domain
| Nemo Release 3.1 | uniq (3) | June 29, 2025 |
Generated by manServer 1.08 from 30a1b3c7-cb53-4329-a2a8-9f0e17bc8ea0 using man macros.