-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathDataCollection.F90
142 lines (111 loc) · 4.13 KB
/
DataCollection.F90
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "MAPL_ErrLog.h"
module MAPL_DataCollectionMod
use pFIO
use MAPL_FileMetadataUtilsVectorMod
use MAPL_FileMetadataUtilsMod
use MAPL_GridManagerMod
use MAPL_AbstractGridFactoryMod
use gFTL2_StringIntegerMap
use esmf
use mapl_ErrorHandlingMod
implicit none
private
public :: MAPLDataCollection
public :: new_MAPLDataCollection
type :: MAPLDataCollection
character(len=:), allocatable :: template
logical :: use_file_coords
type (FileMetadataUtilsVector) :: metadatas
type (StringIntegerMap) :: file_ids
type(ESMF_Grid), allocatable :: src_grid
contains
procedure :: find => find_
end type MAPLDataCollection
interface MAPLDataCollection
module procedure new_MAPLDataCollection
end interface MAPLDataCollection
integer, parameter :: MAX_FORMATTERS = 2
contains
function new_MAPLDataCollection(template,use_file_coords) result(collection)
type (MAPLDataCollection) :: collection
character(len=*), intent(in) :: template
logical, optional, intent(in) :: use_file_coords
collection%template = template
if (present(use_file_coords)) then
collection%use_file_coords=use_file_coords
else
collection%use_file_coords=.false.
end if
end function new_MAPLDataCollection
function find_(this, file_name, rc) result(metadata)
type (FileMetadataUtils), pointer :: metadata
class (MAPLDataCollection), target, intent(inout) :: this
character(len=*), intent(in) :: file_name
integer, optional, intent(out) :: rc
type (NetCDF4_FileFormatter) :: formatter
type (FileMetadata) :: basic_metadata
integer, pointer :: file_id
type (StringIntegerMapIterator) :: iter
class (AbstractGridFactory), allocatable :: factory
integer :: status
type(StringIntegerMap), pointer :: dimensions
integer, pointer :: tile_size
logical :: skip_grid
file_id => this%file_ids%at(file_name)
if (associated(file_id)) then
metadata => this%metadatas%at(file_id)
else
if (this%metadatas%size() >= MAX_FORMATTERS) then
metadata => this%metadatas%front()
call this%metadatas%erase(this%metadatas%begin())
nullify(metadata)
iter = this%file_ids%begin()
do while (iter /= this%file_ids%end())
file_id => iter%second()
if (file_id == 1) then
iter = this%file_ids%erase(iter)
exit
end if
call iter%next()
end do
! Fix the old file_id's accordingly
iter = this%file_ids%begin()
do while (iter /= this%file_ids%end())
file_id => iter%second()
file_id = file_id -1
call iter%next()
end do
end if
allocate(metadata)
call formatter%open(file_name, pFIO_READ,rc=status)
_VERIFY(status)
basic_metadata = formatter%read(_RC)
call formatter%close(rc=status)
_VERIFY(status)
call metadata%create(basic_metadata,file_name)
call this%metadatas%push_back(metadata)
deallocate(metadata)
metadata => this%metadatas%back()
dimensions => metadata%get_dimensions()
tile_size => dimensions%at("tile_index")
skip_grid = associated(tile_size)
if ( (.not. allocated(this%src_grid)) .and. (.not. skip_grid)) then
allocate(factory, source=grid_manager%make_factory(trim(file_name),force_file_coordinates=this%use_file_coords))
this%src_grid = grid_manager%make_grid(factory)
end if
! size() returns 64-bit integer; cast to 32 bit for this usage.
call this%file_ids%insert(file_name, int(this%metadatas%size()))
end if
_RETURN(_SUCCESS)
end function find_
end module MAPL_DataCollectionMod
module MAPL_CollectionVectorMod
use pFIO
use MAPL_DataCollectionMod
! Create a map (associative array) between names and pFIO_Attributes.
#define _type type (MAPLDataCollection)
#define _vector MAPLCollectionVector
#define _iterator MAPLCollectionVectorIterator
#define _FTL_THROW pFIO_throw_exception
#include "templates/vector.inc"
end module MAPL_CollectionVectorMod