gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
gdncfileclose.f90
Go to the documentation of this file.
1!>
2!> @file gdncfileclose.f90
3!>
4!> @author Yasuhiro MORIKAWA, Eizi TOYODA
5!> @copyright Copyright (C) GFD Dennou Club, 2000-2026. All rights reserved. <br/>
6!> License is BSD-2-Clause. See [COPYRIGHT](@ref COPYRIGHT) in detail
7!>
8!> @en
9!> @brief Close a netCDF file
10!> @enden
11!>
12!> @ja
13!> @brief netCDF ファイルを閉じる
14!> @endja
15!>
16
17!>
18!> @en
19!> @brief Close a netCDF file
20!>
21!> Decrements the reference count of the specified file ID. When the
22!> reference count reaches zero, the file is actually closed using
23!> nf90_close and removed from the internal file list.
24!> @enden
25!>
26!> @ja
27!> @brief netCDF ファイルを閉じる
28!>
29!> 指定されたファイル ID の参照カウントを減算します。
30!> 参照カウントがゼロになると、nf90_close を使用して実際にファイルを閉じ、
31!> 内部ファイルリストから削除します。
32!> @endja
33!>
34!> @param[in] fileid @en netCDF file ID @enden @ja netCDF ファイル ID @endja
35!> @param[out] err @en Error flag (optional) @enden @ja エラーフラグ (省略可能) @endja
36!>
37subroutine gdncfileclose(fileid, err)
40 use netcdf, only: nf90_close, nf90_enotnc, nf90_noerr
41 use dc_error, only: storeerror
43 integer, intent(in):: fileid
44 logical, intent(out), optional:: err
45 type(gd_nc_file_id_entry), pointer:: identptr, prev
46 integer:: stat
47 character(*), parameter:: subname = "GDNcFileClose"
48continue
49 call beginsub(subname)
50 stat = nf90_enotnc
51 if (.not. id_used) goto 999
52 identptr => id_head
53 nullify(prev)
54 do
55 if (.not. associated(identptr)) goto 999
56 if (identptr % id == fileid) exit
57 prev => identptr
58 identptr => identptr % next
59 enddo
60 identptr % count = identptr % count - 1
61 if (identptr % count <= 0) then
62 stat = nf90_close(fileid)
63 if (associated(prev)) then
64 prev%next => identptr % next
65 else
66 id_head => identptr % next
67 if (.not. associated(id_head)) id_used = .false.
68 endif
69 call dbgmessage(subname // ': <%c> closed', c1=trim(identptr % filename))
70 deallocate(identptr)
71 else
72 call dbgmessage(subname // ': %d<%c> skipped for refcount=%d', &
73 & c1=trim(identptr % filename), i=(/fileid, identptr % count/))
74 stat = nf90_noerr
75 endif
76999 continue
77 call endsub(subname)
78 call storeerror(stat, 'GDNcFileClose', err)
79end subroutine gdncfileclose
subroutine gdncfileclose(fileid, err)
Error handling module.
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891
Debug tracing module.
Definition dc_trace.f90:150
subroutine, public dbgmessage(fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:661
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
Definition dc_trace.f90:457
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:580
logical, save id_used
Flag indicating whether id_head has been initialized
type(gd_nc_file_id_entry), pointer, save id_head
ID table for open/close of netCDF files