[UP]


Manual Reference Pages  - uniq (3)

NAME

uniq(3f) - [M_io] append a number to the end of filename to make a unique name if name exists (LICENSE:MIT)

CONTENTS

Synopsis
Description
Options
Returns
Example
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 four-digit 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.
o relatively non-generic;
o does not try to detect io errors

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 new 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.

EXAMPLE

Sample program

      program demo_uniq
      use M_io, only : uniq
      implicit none
      character(len=4096) :: myname
      integer             :: i
         myname=uniq(’does_not_exist’)
         open(unit=10,file=’does_exist’)
         write(*,*)’name stays the same ’,trim(myname)
         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

MIT License


uniq (3) November 13, 2019
Generated by manServer 1.08 from f97b918a-da06-484d-9204-1496d94c7066 using man macros.