43 INTEGER :: extent,entry_num
49 INTEGER :: num_entries = 0
84 INTEGER,
OPTIONAL,
INTENT(IN) :: n
87 print *,
"DEBUG INFO in marray_compound::CreateMArray_compound: creating new compound"
91 IF (new_cp%Init(n,0))
return
94 IF (new_cp%Init(0))
return
97 print *,
"ERROR in marray_compound::CreateMArray: compound initialization failed"
110 print *,
"DEBUG INFO in marray_compound::AssignPointers: restoring compound pointers"
113 success = this%marray_base%AssignPointers()
114 IF (success) success = this%AssignItemPointers()
125#if !defined(__GFORTRAN__) || (defined(__GFORTRAN__) && __GNUC__ >= 13)
129 LOGICAL :: LHS_initialized
132 print *,
"DEBUG INFO in marray_compound::AssignMArray_0: compound assignment called"
135 SELECT TYPE(src => ma)
139 IF (.NOT.
ASSOCIATED(p))
THEN
142 print *,
"DEBUG INFO in marray_compound::AssignMArray_0: empty compound on rhs"
144 IF (src%num_entries.GT.0.OR.
SIZE(src%data1d).GT.0)
THEN
145 print *,
"ERROR in marray_compound::AssignMArray_0: unassigned item list on rhs but compound not empty"
152 CALL this%marray_base%AssignMArray_0(src)
154 q => this%FirstItem()
156 lhs_initialized =
ASSOCIATED(q)
157 IF (.NOT.lhs_initialized)
THEN
161 print *,
"DEBUG INFO in marray_compound::AssignMArray_0: empty compound on lhs"
163 IF (this%num_entries.GT.0)
THEN
164 print *,
"ERROR in marray_compound::AssignMArray_0: empty compound on lhs expected"
172#if !defined(__GFORTRAN__) || (defined(__GFORTRAN__) && __GNUC__ > 12)
175 DO WHILE (
ASSOCIATED(p%item))
176 ALLOCATE(new_ma,source=p%item,stat=err)
179 print *,
"ERROR in marray_compound::AssignMArray_0: memory allocation failed for new_ma"
185 CALL this%AppendItem(new_ma)
187 IF (.NOT.
ASSOCIATED(p))
EXIT
191 this%num_entries = src%num_entries
192 this%list => src%list
195 CALL this%marray_base%AssignMArray_0(src)
198 IF (.NOT.this%AssignItemPointers())
THEN
200 print *,
"ERROR in marray_compound::AssignMArray_0: assignment of item pointers failed"
208 IF (.NOT.(this.match.ma))
THEN
210 print *,
"ERROR in marray_compound::AssignMArray_0: shape mismatch"
217 CALL this%marray_base%AssignMArray_0(src)
223 print *,
"ERROR in marray_compound::AssignMArray_0: rhs must be of class marray_compound"
241 res = this%marray_base%ShapesMatch(ma)
244 print *,
"WARNING in marray_compound::ShapesMatch: mismatch in marray_base"
248 SELECT TYPE(that => ma)
250 res = this%num_entries.EQ.that%num_entries
253 print *,
"DEBUG INFO in marray_compound::ShapesMatch: number of entries do not match"
258 p => this%FirstItem()
259 q => that%FirstItem()
261 DO WHILE (
ASSOCIATED(p))
262 res = res.AND.
ASSOCIATED(q)
264 res = res.AND.(p%extent.EQ.q%extent)
269 res = res.AND..NOT.
ASSOCIATED(q)
283 REAL,
DIMENSION(:),
POINTER,
CONTIGUOUS :: data1d
286 print *,
"DEBUG INFO in marray_compound::AppendMArray: appending marray to compound"
290 IF (.NOT.(
ASSOCIATED(ma%data1d).OR.
SIZE(ma%data1d).EQ.0))
THEN
292 print *,
"ERROR in marray_compound::AppendMArray: input marray not associated of empty"
297 IF (.NOT.
ASSOCIATED(this%data1d))
THEN
299 print *,
"ERROR in marray_compound::AppendMArray: compound uninitialized"
306 SELECT CASE(this%RANK)
308 this%DIMS(1) = this%DIMS(1) + ma%DIMS(1)*ma%DIMS(2)
315 IF (this%DIMS(1).NE.ma%DIMS(1))
THEN
317 print *,
"ERROR in marray_compound::AppendMArray: this%dims(1) != ma%dims(1)"
322 this%DIMS(2) = this%DIMS(2) + ma%DIMS(2)
328 print *,
"ERROR in marray_compound::AppendMArray: rank of compound marrays should be either 1 or 2"
334 m =
SIZE(this%data1d(:))
337 DEALLOCATE(this%data1d)
339 this%data1d(1:) => ma%data1d(1:)
341 CALL this%AppendItem(ma)
344 n =
SIZE(ma%data1d(:))
346 ALLOCATE(data1d(m+n),stat=err)
349 print *,
"ERROR in marray_compound::AppendMArray: memory allocation failed"
356 data1d(i) = this%data1d(i)
359 data1d(m+i) = ma%data1d(i)
362 CALL this%AppendItem(ma)
364 DEALLOCATE(ma%data1d,this%data1d)
366 this%data1d(1:) => data1d(1:)
369 IF (.NOT.this%AssignPointers())
THEN
371 print *,
"ERROR in marray_compound::AppendMArray: pointer assignment failed"
377 print *,
"DEBUG INFO in marray_compound::AppendMArray"
378 print
'(3(A,I2),I2)',
" item no. ",this%num_entries,
" appended to rank ",this%RANK, &
379 " compound with dims ",this%DIMS(1:2)
380 print
'(A,I10,A,I2,A,2(I3))',
" size ",
SIZE(this%data1d), &
381 " item%rank", ma%RANK, &
382 " item%dims", ma%DIMS(:)
383 SELECT CASE(this%RANK)
385 print
'(A,4(I6))',
" shape4d", shape(this%data4d)
387 print
'(A,5(I6))',
" shape5d", shape(this%data5d)
411 IF (.NOT.
ASSOCIATED(item))
RETURN
412 DO WHILE (
ASSOCIATED(item%next))
424 IF (
ASSOCIATED(item))
THEN
439 ma => list_entry%item
452 IF (
ASSOCIATED(ma).AND.
ASSOCIATED(ma%data1d).AND.
SIZE(ma%data1d).GT.0)
THEN
454 IF (.NOT.
ASSOCIATED(p))
THEN
457 print *,
"DEBUG INFO in marray_compound::AppendItem: creating new list"
459 ALLOCATE(this%list,stat=err)
462 print *,
"ERROR in marray_compound::AppendItem: memory allocation failed for new list"
471 print *,
"DEBUG INFO in marray_compound::AppendItem: appending item to list of elements"
473 ALLOCATE(p%next,stat=err)
476 print *,
"ERROR in marray_compound::AppendItem: memory allocation failed for new entry"
481 this%num_entries = this%num_entries + 1
485 p%extent =
SIZE(ma%data1d)
486 p%entry_num = this%num_entries
502 p => this%FirstItem()
506 DO WHILE (success.AND.
ASSOCIATED(p))
508 print
'(A,I2)',
" DEBUG INFO in marray_compound::AssignItemPointers: restoring entry no. ", p%entry_num
513 p%item%data1d(1:n) => this%data1d(m+1:m+n)
515 success = p%item%AssignPointers()
516 p => this%NextItem(p)
526 LOGICAL,
OPTIONAL :: called_from_finalize
531 print *,
"DEBUG INFO in marray_compound::Destroy: deallocating compound components"
534 p => this%FirstItem()
535 DO WHILE (
ASSOCIATED(p))
537 print
'(A,I2)',
" DEBUG INFO in marray_compound::Destroy: deleting entry no. ", p%entry_num
540 IF (
ASSOCIATED(p%item))
THEN
542 print
'(A,I2)',
" DEBUG INFO in marray_compound::Destroy: deallocating item data"
545 IF (
ASSOCIATED(p%item%data1d))
NULLIFY(p%item%data1d)
554 IF (
PRESENT(called_from_finalize))
THEN
555 IF (called_from_finalize)
RETURN
557 CALL this%marray_base%Destroy()
567 print *,
"DEBUG INFO in marray_compound::Finalize: automatic finalizer called"
569 CALL this%Destroy(.true.)
base class for mesh arrays
logical function assignpointers(this)
assign pointers of different shapes to the 1D data
subroutine finalize(this)
pure logical function shapesmatch(this, that)
subroutine assignmarray_0(this, ma)
assigns one mesh array to another mesh array
subroutine destroy(this, called_from_finalize)
basic destructor of mesh arrays - this is called automatically if deallocate is invoked
derived class for compound of mesh arrays
type(compound_item) function, pointer firstitem(this)
get the first item from the list of compound elements
type(compound_item) function, pointer lastitem(this)
get the last item from the list of compound elements
logical function appendmarray(this, ma)
type(compound_item) function, pointer nextitem(this, item)
get the next item from the list of compound elements
type(marray_base) function, pointer getitem(this, list_entry)
get pointer to the mesh array from a given item
logical function assignitempointers(this)
type(marray_compound) function createmarray_compound(n)
constructor for compound of mesh arrays
subroutine appenditem(this, ma)
append an item to the list of compound elements