New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
iounits.f in branches/2014/dev_r4650_UKMO12_CFL_diags_take2/NEMOGCM/TOOLS/WEIGHTS/SCRIP1.4/source – NEMO

source: branches/2014/dev_r4650_UKMO12_CFL_diags_take2/NEMOGCM/TOOLS/WEIGHTS/SCRIP1.4/source/iounits.f @ 5947

Last change on this file since 5947 was 5947, checked in by timgraham, 8 years ago

Reinstate svn Id keywords before merge

  • Property svn:keywords set to Id
File size: 5.0 KB
Line 
1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2!
3!     This module is a dynamic I/O unit manager.  It keeps track of
4!     which units are in use and reserves units for stdin, stdout, and
5!     stderr.
6!
7!-----------------------------------------------------------------------
8!
9!     CVS:$Id$
10!
11!     Copyright (c) 1997, 1998 the Regents of the University of
12!       California.
13!
14!     This software and ancillary information (herein called software)
15!     called SCRIP is made available under the terms described here. 
16!     The software has been approved for release with associated
17!     LA-CC Number 98-45.
18!
19!     Unless otherwise indicated, this software has been authored
20!     by an employee or employees of the University of California,
21!     operator of the Los Alamos National Laboratory under Contract
22!     No. W-7405-ENG-36 with the U.S. Department of Energy.  The U.S.
23!     Government has rights to use, reproduce, and distribute this
24!     software.  The public may copy and use this software without
25!     charge, provided that this Notice and any statement of authorship
26!     are reproduced on all copies.  Neither the Government nor the
27!     University makes any warranty, express or implied, or assumes
28!     any liability or responsibility for the use of this software.
29!
30!     If software is modified to produce derivative works, such modified
31!     software should be clearly marked, so as not to confuse it with
32!     the version available from Los Alamos National Laboratory.
33!
34!***********************************************************************
35
36      module iounits
37
38!-----------------------------------------------------------------------
39
40      use kinds_mod   ! defines data types
41
42      implicit none
43
44!-----------------------------------------------------------------------
45
46      logical (kind=log_kind), dimension(99), save ::
47     &    unit_free   ! flags to determine whether unit is free for use
48
49      integer (kind=int_kind), parameter ::
50     &    stdin  = 5, ! reserves unit for standard input
51     &    stdout = 6, ! reserves unit for standard output
52     &    stderr = 6  ! reserves unit for standard error
53
54!***********************************************************************
55
56      contains
57
58!***********************************************************************
59
60      subroutine get_unit(iunit)
61
62!-----------------------------------------------------------------------
63!
64!     This routine returns the next available I/O unit number.
65!
66!-----------------------------------------------------------------------
67
68!-----------------------------------------------------------------------
69!
70!     output variables
71!
72!-----------------------------------------------------------------------
73
74      integer (kind=int_kind), intent(out) ::
75     &     iunit   ! next free I/O unit
76
77!-----------------------------------------------------------------------
78!
79!     local variables
80!
81!-----------------------------------------------------------------------
82
83      integer (kind=int_kind) :: n
84
85      logical (kind=log_kind), save :: first_call = .true.
86
87!-----------------------------------------------------------------------
88!
89!     if this is the first call, reserve stdout, stdin and stderr
90!
91!-----------------------------------------------------------------------
92
93      if (first_call) then
94        unit_free = .true.
95        unit_free(stdin)  = .false.
96        unit_free(stdout) = .false.
97        unit_free(stderr) = .false.
98        first_call = .false.
99      endif
100
101!-----------------------------------------------------------------------
102!
103!     search for next available unit
104!
105!-----------------------------------------------------------------------
106
107      srch_unit: do n=1,99
108        if (unit_free(n)) then
109          iunit = n
110          unit_free(n) = .false.
111          exit srch_unit
112        endif
113      end do srch_unit
114
115!-----------------------------------------------------------------------
116
117      end subroutine get_unit
118
119!***********************************************************************
120
121      subroutine release_unit(iunit)
122
123!-----------------------------------------------------------------------
124!
125!     This routine releases the specified unit and closes the file.
126!
127!-----------------------------------------------------------------------
128!-----------------------------------------------------------------------
129!
130!     input variables
131!
132!-----------------------------------------------------------------------
133
134      integer (kind=int_kind), intent(in) ::
135     &     iunit   ! I/O unit to release
136
137!-----------------------------------------------------------------------
138!
139!     closes I/O unit and declares it free
140!
141!-----------------------------------------------------------------------
142
143      unit_free(iunit) = .true.
144      close(iunit)
145
146!-----------------------------------------------------------------------
147
148      end subroutine release_unit
149
150!***********************************************************************
151
152      end module iounits
153
154!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Note: See TracBrowser for help on using the repository browser.