forked from CEMPD/filesetapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloseset.f
executable file
·106 lines (88 loc) · 2.92 KB
/
closeset.f
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
LOGICAL FUNCTION CLOSESET( ROOTNAME )
!***********************************************************************
! Function body starts at line 41
!
! DESCRIPTION:
! Closes a file set
!
! PRECONDITIONS REQUIRED:
! File set has been opened with OPENSET
!
! SUBROUTINES AND FUNCTIONS CALLED:
! CLOSE3 - closes an individual file
! CLEANUP - cleans up internal memory structures
!
! REVISION HISTORY:
! Created 6/02 by C. Seppanen
!
!***************************************************************************
!
! Project Title: FileSetAPI
! File: @(#)$Id$
!
! COPYRIGHT (C) 2004, Environmental Modeling for Policy Development
! All Rights Reserved
!
! Carolina Environmental Program
! University of North Carolina at Chapel Hill
! 137 E. Franklin St., CB# 6116
! Chapel Hill, NC 27599-6116
!
!
! Pathname: $Source$
! Last updated: $Date$
!
!*************************************************************************
!........ Modules for public variables
USE MODFILESET
IMPLICIT NONE
!........ Include files
INCLUDE 'IODECL3.EXT' ! I/O API function declarations
!........ External functions
INTEGER, EXTERNAL :: INDEX1
!........ Function arguments
CHARACTER(*), INTENT(IN) :: ROOTNAME ! logical file name for file set
!........ Local variables
INTEGER I ! counter
INTEGER FILEIDX ! file index
CHARACTER(16) ROOTNAME16 ! fixed length root file name
CHARACTER(256) MESG ! message buffer
!---------------------------------
! Begin body of function CLOSESET
!---------------------------------
!........ Check length of file name
IF( LEN( ROOTNAME ) > 16 ) THEN
MESG = 'Max file name length (16) exceeded for "' //
& TRIM( ROOTNAME ) // '"'
CALL M3MSG2( MESG )
CLOSESET = .FALSE.
RETURN
END IF
!........ Get file index
ROOTNAME16 = ROOTNAME
FILEIDX = INDEX1( ROOTNAME16, MXFILE3, RNAMES )
!........ If file is not open, exit with error
IF( FILEIDX == 0 ) THEN
MESG = 'File set "' // TRIM( ROOTNAME ) // '" is not ' //
& 'currently open'
CALL M3MSG2( MESG )
CLOSESET = .FALSE.
RETURN
END IF
!........ Loop through individual files
DO I = 1, SIZE( FILE_INFO( FILEIDX )%LNAMES )
IF( .NOT. CLOSE3( FILE_INFO( FILEIDX )%LNAMES( I ) ) ) THEN
CLOSESET = .FALSE.
RETURN
END IF
END DO
!........ Write message only if file set contains more than one file
IF( SIZE( FILE_INFO( FILEIDX )%LNAMES ) > 1 ) THEN
MESG = 'Closing file set "' // TRIM( ROOTNAME ) // '"'
CALL M3MSG2( MESG )
END IF
CALL CLEANUP( FILEIDX )
NOPENSETS = NOPENSETS - 1
CLOSESET = .TRUE.
END FUNCTION CLOSESET