ROMS
Loading...
Searching...
No Matches
destroy.F
Go to the documentation of this file.
1#include "cppdefs.h"
3!
4!git $Id$
5!================================================== Hernan G. Arango ===
6! Copyright (c) 2002-2025 The ROMS Group !
7! Licensed under a MIT/X style license !
8! See License_ROMS.md !
9!=======================================================================
10! !
11! It releases the space allocated for pointer variable in ROMS !
12! kernel structures. After a variable has been deallocated, it !
13! cannot be defined or referenced until it is allocated or !
14! assigned again. !
15! !
16! On Input: !
17! !
18! ng Nested grid number (integer) !
19! Varray Pointer variable to deallocate (real) !
20! routine Calling routine (string) !
21! line Calling routine line (integer) !
22! Vstring Variable name (string) !
23! !
24! On Output: !
25! !
26! Lsuccess Deallocation error switch (logical) !
27! !
28!=======================================================================
29!
30 USE mod_kinds
31 USE mod_parallel, ONLY : master
32 USE mod_iounits, ONLY : stdout
33!
34 implicit none
35!
36 INTERFACE destroy
37 MODULE PROCEDURE destroy_1d_i ! 1D integer array
38 MODULE PROCEDURE destroy_1d_l ! 1D logical array
39#ifdef SINGLE_PRECISION
40 MODULE PROCEDURE destroy_1d_dp ! 1D real(dp) array
41 MODULE PROCEDURE destroy_2d_dp ! 2D real(dp) array
42 MODULE PROCEDURE destroy_3d_dp ! 3D real(dp) array
43 MODULE PROCEDURE destroy_4d_dp ! 4D real(dp) array
44 MODULE PROCEDURE destroy_5d_dp ! 5D real(dp) array
45#endif
46 MODULE PROCEDURE destroy_1d_r8 ! 1D real(r8) array
47 MODULE PROCEDURE destroy_2d_r8 ! 2D real(r8) array
48 MODULE PROCEDURE destroy_3d_r8 ! 3D real(r8) array
49 MODULE PROCEDURE destroy_4d_r8 ! 4D real(r8) array
50 MODULE PROCEDURE destroy_5d_r8 ! 5D real(r8) array
51 END INTERFACE destroy
52!
53 integer, parameter :: avar = 1
54 integer, parameter :: pvar = 2
55!
56 CONTAINS
57!
58!***********************************************************************
59 FUNCTION destroy_1d_i (ng, Varray, routine, line, Vstring) &
60 & result(lsuccess)
61!***********************************************************************
62!
63! Imported variable declarations.
64!
65 integer, intent(in) :: ng, line
66
67 integer, pointer, intent(inout) :: varray(:)
68!
69 character (len=*) :: vstring, routine
70!
71! Local variable declarations.
72!
73 logical :: lsuccess
74!
75 integer :: derror
76!
77 character (len=:), allocatable :: dmsg
78!
79!-----------------------------------------------------------------------
80! Deallocate 1D integer array.
81!-----------------------------------------------------------------------
82!
83 lsuccess=.true.
84 derror=0
85!
86#ifdef DISTRIBUTE
87 IF (associated(varray)) &
88 & deallocate ( varray, errmsg = dmsg, stat = derror )
89#else
90 IF (master) THEN
91 IF (associated(varray)) &
92 & deallocate ( varray, errmsg = dmsg, stat = derror )
93 END IF
94#endif
95!
96! Report if unsuccessful deallocation.
97!
98 IF (derror.ne.0) THEN
99 IF (master) THEN
100 WRITE (stdout,10) ng, vstring, routine, line, dmsg
101 END IF
102 lsuccess=.false.
103 END IF
104!
105 10 FORMAT (/,' DESTROY_1D_I - Grid ',i2.2, &
106 & ', error while deallocating: ''',a,''' in routine ''',a, &
107 & ''' at line = ',i0,/,16x,a)
108!
109 RETURN
110 END FUNCTION destroy_1d_i
111!
112!***********************************************************************
113 FUNCTION destroy_1d_l (ng, Varray, routine, line, Vstring) &
114 & result(lsuccess)
115!***********************************************************************
116!
117! Imported variable declarations.
118!
119 logical, pointer, intent(inout) :: varray(:)
120!
121 integer, intent(in) :: ng, line
122!
123 character (len=*) :: vstring, routine
124!
125! Local variable declarations.
126!
127 logical :: lsuccess
128!
129 integer :: derror
130!
131 character (len=:), allocatable :: dmsg
132!
133!-----------------------------------------------------------------------
134! Deallocate 1D logical array.
135!-----------------------------------------------------------------------
136!
137 lsuccess=.true.
138 derror=0
139!
140#ifdef DISTRIBUTE
141 IF (associated(varray)) &
142 & deallocate ( varray, errmsg = dmsg, stat = derror )
143#else
144 IF (master) THEN
145 IF (associated(varray)) &
146 & deallocate ( varray, errmsg = dmsg, stat = derror )
147 END IF
148#endif
149!
150! Report if unsuccessful deallocation.
151!
152 IF (derror.ne.0) THEN
153 IF (master) THEN
154 WRITE (stdout,10) ng, vstring, routine, line, dmsg
155 END IF
156 lsuccess=.false.
157 END IF
158!
159 10 FORMAT (/,' DESTROY_1D_L - Grid ',i2.2, &
160 & ', error while deallocating: ''',a,''' in routine ''',a, &
161 & ''' at line = ',i0,/,16x,a)
162!
163 RETURN
164 END FUNCTION destroy_1d_l
165!
166!***********************************************************************
167 FUNCTION destroy_1d_r8 (ng, Varray, routine, line, Vstring) &
168 & result(lsuccess)
169!***********************************************************************
170!
171! Imported variable declarations.
172!
173 integer, intent(in) :: ng, line
174!
175 real(r8), pointer, intent(inout) :: varray(:)
176!
177 character (len=*) :: vstring, routine
178!
179! Local variable declarations.
180!
181 logical :: lsuccess
182!
183 integer :: derror
184!
185 character (len=:), allocatable :: dmsg
186!
187!-----------------------------------------------------------------------
188! Deallocate 1D floating-point array (KIND=r8).
189!-----------------------------------------------------------------------
190!
191 lsuccess=.true.
192 derror=0
193!
194#ifdef DISTRIBUTE
195 IF (associated(varray)) &
196 & deallocate ( varray, errmsg = dmsg, stat = derror )
197#else
198 IF (master) THEN
199 IF (associated(varray)) &
200 & deallocate ( varray, errmsg = dmsg, stat = derror )
201 END IF
202#endif
203!
204! Report if unsuccessful deallocation.
205!
206 IF (derror.ne.0) THEN
207 IF (master) THEN
208 WRITE (stdout,10) ng, vstring, routine, line, dmsg
209 END IF
210 lsuccess=.false.
211 END IF
212!
213 10 FORMAT (/,' DESTROY_1D_R8 - Grid ',i2.2, &
214 & ', error while deallocating: ''',a,''' in routine ''',a, &
215 & ''' at line = ',i0,/,17x,a)
216!
217 RETURN
218 END FUNCTION destroy_1d_r8
219!
220!***********************************************************************
221 FUNCTION destroy_2d_r8 (ng, Varray, routine, line, Vstring) &
222 & result(lsuccess)
223!***********************************************************************
224!
225! Imported variable declarations.
226!
227 integer, intent(in) :: ng, line
228!
229 real(r8), pointer, intent(inout) :: varray(:,:)
230!
231 character (len=*) :: vstring, routine
232!
233! Local variable declarations.
234!
235 logical :: lsuccess
236!
237 integer :: derror
238!
239 character (len=:), allocatable :: dmsg
240!
241!-----------------------------------------------------------------------
242! Deallocate 2D floating-point array (KIND=r8).
243!-----------------------------------------------------------------------
244!
245 lsuccess=.true.
246 derror=0
247!
248#ifdef DISTRIBUTE
249 IF (associated(varray)) &
250 & deallocate ( varray, errmsg = dmsg, stat = derror )
251#else
252 IF (master) THEN
253 IF (associated(varray)) &
254 & deallocate ( varray, errmsg = dmsg, stat = derror )
255 END IF
256#endif
257!
258! Report if unsuccessful deallocation.
259!
260 IF (derror.ne.0) THEN
261 IF (master) THEN
262 WRITE (stdout,10) ng, vstring, routine, line, dmsg
263 END IF
264 lsuccess=.false.
265 END IF
266!
267 10 FORMAT (/,' DESTROY_2D_R8 - Grid ',i2.2, &
268 & ', error while deallocating: ''',a,''' in routine ''',a, &
269 & ''' at line = ',i0,/,17x,a)
270!
271 RETURN
272 END FUNCTION destroy_2d_r8
273!
274!***********************************************************************
275 FUNCTION destroy_3d_r8 (ng, Varray, routine, line, Vstring) &
276 & result(lsuccess)
277!***********************************************************************
278!
279! Imported variable declarations.
280!
281 integer, intent(in) :: ng, line
282!
283 real(r8), pointer, intent(inout) :: varray(:,:,:)
284!
285 character (len=*) :: vstring, routine
286!
287! Local variable declarations.
288!
289 logical :: lsuccess
290!
291 integer :: derror
292!
293 character (len=:), allocatable :: dmsg
294!
295!-----------------------------------------------------------------------
296! Deallocate 3D floating-point array (KIND=r8).
297!-----------------------------------------------------------------------
298!
299 lsuccess=.true.
300 derror=0
301!
302#ifdef DISTRIBUTE
303 IF (associated(varray)) &
304 & deallocate ( varray, errmsg = dmsg, stat = derror )
305#else
306 IF (master) THEN
307 IF (associated(varray)) &
308 & deallocate ( varray, errmsg = dmsg, stat = derror )
309 END IF
310#endif
311!
312! Report if unsuccessful deallocation.
313!
314 IF (derror.ne.0) THEN
315 IF (master) THEN
316 WRITE (stdout,10) ng, vstring, routine, line, dmsg
317 END IF
318 lsuccess=.false.
319 END IF
320!
321 10 FORMAT (/,' DESTROY_3D_R8 - Grid ',i2.2, &
322 & ', error while deallocating: ''',a,''' in routine ''',a, &
323 & ''' at line = ',i0,/,17x,a)
324!
325 RETURN
326 END FUNCTION destroy_3d_r8
327!
328!***********************************************************************
329 FUNCTION destroy_4d_r8 (ng, Varray, routine, line, Vstring) &
330 & result(lsuccess)
331!***********************************************************************
332!
333! Imported variable declarations.
334!
335 integer, intent(in) :: ng, line
336!
337 real(r8), pointer, intent(inout) :: varray(:,:,:,:)
338!
339 character (len=*) :: vstring, routine
340!
341! Local variable declarations.
342!
343 logical :: lsuccess
344!
345 integer :: derror
346!
347 character (len=:), allocatable :: dmsg
348!
349!-----------------------------------------------------------------------
350! Deallocate 4D floating-point array (KIND=r8).
351!-----------------------------------------------------------------------
352!
353 lsuccess=.true.
354 derror=0
355!
356#ifdef DISTRIBUTE
357 IF (associated(varray)) &
358 & deallocate ( varray, errmsg = dmsg, stat = derror )
359#else
360 IF (master) THEN
361 IF (associated(varray)) &
362 & deallocate ( varray, errmsg = dmsg, stat = derror )
363 END IF
364#endif
365!
366! Report if unsuccessful deallocation.
367!
368 IF (derror.ne.0) THEN
369 IF (master) THEN
370 WRITE (stdout,10) ng, vstring, routine, line, dmsg
371 END IF
372 lsuccess=.false.
373 END IF
374!
375 10 FORMAT (/,' DESTROY_4D_R8 - Grid ',i2.2, &
376 & ', error while deallocating: ''',a,''' in routine ''',a, &
377 & ''' at line = ',i0,/,17x,a)
378!
379 RETURN
380 END FUNCTION destroy_4d_r8
381!
382!***********************************************************************
383 FUNCTION destroy_5d_r8 (ng, Varray, routine, line, Vstring) &
384 & result(lsuccess)
385!***********************************************************************
386!
387! Imported variable declarations.
388!
389 integer, intent(in) :: ng, line
390!
391 real(r8), pointer, intent(inout) :: varray(:,:,:,:,:)
392!
393 character (len=*) :: vstring, routine
394!
395! Local variable declarations.
396!
397 logical :: lsuccess
398!
399 integer :: derror
400!
401 character (len=:), allocatable :: dmsg
402!
403!-----------------------------------------------------------------------
404! Deallocate 5D floating-point array (KIND=r8).
405!-----------------------------------------------------------------------
406!
407 lsuccess=.true.
408 derror=0
409!
410#ifdef DISTRIBUTE
411 IF (associated(varray)) &
412 & deallocate ( varray, errmsg = dmsg, stat = derror )
413#else
414 IF (master) THEN
415 IF (associated(varray)) &
416 & deallocate ( varray, errmsg = dmsg, stat = derror )
417 END IF
418#endif
419!
420! Report if unsuccessful deallocation.
421!
422 IF (derror.ne.0) THEN
423 IF (master) THEN
424 WRITE (stdout,10) ng, vstring, routine, line, dmsg
425 END IF
426 lsuccess=.false.
427 END IF
428!
429 10 FORMAT (/,' DESTROY_5D_R8 - Grid ',i2.2, &
430 & ', error while deallocating: ''',a,''' in routine ''',a, &
431 & ''' at line = ',i0,/,17x,a)
432!
433 RETURN
434 END FUNCTION destroy_5d_r8
435
436#ifdef SINGLE_PRECISION
437!
438!***********************************************************************
439 FUNCTION destroy_1d_dp (ng, Varray, routine, line, Vstring) &
440 & result(lsuccess)
441!***********************************************************************
442!
443! Imported variable declarations.
444!
445 integer, intent(in) :: ng, line
446!
447 real(dp), pointer, intent(inout) :: varray(:)
448!
449 character (len=*) :: vstring, routine
450!
451! Local variable declarations.
452!
453 logical :: lsuccess
454!
455 integer :: derror
456!
457 character (len=:), allocatable :: dmsg
458!
459!-----------------------------------------------------------------------
460! Deallocate 1D double precision array (KIND=dp).
461!-----------------------------------------------------------------------
462!
463 lsuccess=.true.
464 derror=0
465!
466# ifdef DISTRIBUTE
467 IF (associated(varray)) &
468 & deallocate ( varray, errmsg = dmsg, stat = derror )
469# else
470 IF (master) THEN
471 IF (associated(varray)) &
472 & deallocate ( varray, errmsg = dmsg, stat = derror )
473 END IF
474# endif
475!
476! Report if unsuccessful deallocation.
477!
478 IF (derror.ne.0) THEN
479 IF (master) THEN
480 WRITE (stdout,10) ng, vstring, routine, line, dmsg
481 END IF
482 lsuccess=.false.
483 END IF
484!
485 10 FORMAT (/,' DESTROY_1D_DP - Grid ',i2.2, &
486 & ', error while deallocating: ''',a,''' in routine ''',a, &
487 & ''' at line = ',i0,/,17x,a)
488!
489 RETURN
490 END FUNCTION destroy_1d_dp
491!
492!***********************************************************************
493 FUNCTION destroy_2d_dp (ng, Varray, routine, line, Vstring) &
494 & result(lsuccess)
495!***********************************************************************
496!
497! Imported variable declarations.
498!
499 integer, intent(in) :: ng, line
500!
501 real(dp), pointer, intent(inout) :: varray(:,:)
502!
503 character (len=*) :: vstring, routine
504!
505! Local variable declarations.
506!
507 logical :: lsuccess
508!
509 integer :: derror
510!
511 character (len=:), allocatable :: dmsg
512!
513!-----------------------------------------------------------------------
514! Deallocate 2D double precision array (KIND=dp).
515!-----------------------------------------------------------------------
516!
517 lsuccess=.true.
518 derror=0
519!
520# ifdef DISTRIBUTE
521 IF (associated(varray)) &
522 & deallocate ( varray, errmsg = dmsg, stat = derror )
523# else
524 IF (master) THEN
525 IF (associated(varray)) &
526 & deallocate ( varray, errmsg = dmsg, stat = derror )
527 END IF
528# endif
529!
530! Report if unsuccessful deallocation.
531!
532 IF (derror.ne.0) THEN
533 IF (master) THEN
534 WRITE (stdout,10) ng, vstring, routine, line, dmsg
535 END IF
536 lsuccess=.false.
537 END IF
538!
539 10 FORMAT (/,' DESTROY_2D_DP - Grid ',i2.2, &
540 & ', error while deallocating: ''',a,''' in routine ''',a, &
541 & ''' at line = ',i0,/,17x,a)
542!
543 RETURN
544 END FUNCTION destroy_2d_dp
545!
546!***********************************************************************
547 FUNCTION destroy_3d_dp (ng, Varray, routine, line, Vstring) &
548 & result(lsuccess)
549!***********************************************************************
550!
551! Imported variable declarations.
552!
553 integer, intent(in) :: ng, line
554!
555 real(dp), pointer, intent(inout) :: varray(:,:,:)
556!
557 character (len=*) :: vstring, routine
558!
559! Local variable declarations.
560!
561 logical :: lsuccess
562!
563 integer :: derror
564!
565 character (len=:), allocatable :: dmsg
566!
567!-----------------------------------------------------------------------
568! Deallocate 3D double precision array (KIND=dp).
569!-----------------------------------------------------------------------
570!
571 lsuccess=.true.
572 derror=0
573!
574# ifdef DISTRIBUTE
575 IF (associated(varray)) &
576 & deallocate ( varray, errmsg = dmsg, stat = derror )
577# else
578 IF (master) THEN
579 IF (associated(varray)) &
580 & deallocate ( varray, errmsg = dmsg, stat = derror )
581 END IF
582# endif
583!
584! Report if unsuccessful deallocation.
585!
586 IF (derror.ne.0) THEN
587 IF (master) THEN
588 WRITE (stdout,10) ng, vstring, routine, line, dmsg
589 END IF
590 lsuccess=.false.
591 END IF
592!
593 10 FORMAT (/,' DESTROY_3D_DP - Grid ',i2.2, &
594 & ', error while deallocating: ''',a,''' in routine ''',a, &
595 & ''' at line = ',i0,/,17x,a)
596!
597 RETURN
598 END FUNCTION destroy_3d_dp
599!
600!***********************************************************************
601 FUNCTION destroy_4d_dp (ng, Varray, routine, line, Vstring) &
602 & result(lsuccess)
603!***********************************************************************
604!
605! Imported variable declarations.
606!
607 integer, intent(in) :: ng, line
608!
609 real(dp), pointer, intent(inout) :: varray(:,:,:,:)
610!
611 character (len=*) :: vstring, routine
612!
613! Local variable declarations.
614!
615 logical :: lsuccess
616!
617 integer :: derror
618!
619 character (len=:), allocatable :: dmsg
620!
621!-----------------------------------------------------------------------
622! Deallocate 4D double precision array (KIND=dp).
623!-----------------------------------------------------------------------
624!
625 lsuccess=.true.
626 derror=0
627!
628# ifdef DISTRIBUTE
629 IF (associated(varray)) &
630 & deallocate ( varray, errmsg = dmsg, stat = derror )
631# else
632 IF (master) THEN
633 IF (associated(varray)) &
634 & deallocate ( varray, errmsg = dmsg, stat = derror )
635 END IF
636# endif
637!
638! Report if unsuccessful deallocation.
639!
640 IF (derror.ne.0) THEN
641 IF (master) THEN
642 WRITE (stdout,10) ng, vstring, routine, line, dmsg
643 END IF
644 lsuccess=.false.
645 END IF
646!
647 10 FORMAT (/,' DESTROY_4D_DP - Grid ',i2.2, &
648 & ', error while deallocating: ''',a,''' in routine ''',a, &
649 & ''' at line = ',i0,/,17x,a)
650!
651 RETURN
652 END FUNCTION destroy_4d_dp
653!
654!***********************************************************************
655 FUNCTION destroy_5d_dp (ng, Varray, routine, line, Vstring) &
656 & result(lsuccess)
657!***********************************************************************
658!
659! Imported variable declarations.
660!
661 integer, intent(in) :: ng, line
662!
663 real(dp), pointer, intent(inout) :: varray(:,:,:,:,:)
664!
665 character (len=*) :: vstring, routine
666!
667! Local variable declarations.
668!
669 logical :: lsuccess
670!
671 integer :: derror
672!
673 character (len=:), allocatable :: dmsg
674!
675!-----------------------------------------------------------------------
676! Deallocate 5D double precision array (KIND=dp).
677!-----------------------------------------------------------------------
678!
679 lsuccess=.true.
680 derror=0
681!
682# ifdef DISTRIBUTE
683 IF (associated(varray)) &
684 & deallocate ( varray, errmsg = dmsg, stat = derror )
685# else
686 IF (master) THEN
687 IF (associated(varray)) &
688 & deallocate ( varray, errmsg = dmsg, stat = derror )
689 END IF
690# endif
691!
692! Report if unsuccessful deallocation.
693!
694 IF (derror.ne.0) THEN
695 IF (master) THEN
696 WRITE (stdout,10) ng, vstring, routine, line, dmsg
697 END IF
698 lsuccess=.false.
699 END IF
700!
701 10 FORMAT (/,' DESTROY_5D_DP - Grid ',i2.2, &
702 & ', error while deallocating: ''',a,''' in routine ''',a, &
703 & ''' at line = ',i0,/,17x,a)
704!
705 RETURN
706 END FUNCTION destroy_5d_dp
707#endif
708!
709 END MODULE destroy_mod
integer, parameter avar
Definition destroy.F:53
logical function destroy_3d_r8(ng, varray, routine, line, vstring)
Definition destroy.F:277
logical function destroy_1d_r8(ng, varray, routine, line, vstring)
Definition destroy.F:169
logical function destroy_2d_dp(ng, varray, routine, line, vstring)
Definition destroy.F:495
logical function destroy_2d_r8(ng, varray, routine, line, vstring)
Definition destroy.F:223
logical function destroy_1d_i(ng, varray, routine, line, vstring)
Definition destroy.F:61
logical function destroy_3d_dp(ng, varray, routine, line, vstring)
Definition destroy.F:549
logical function destroy_5d_dp(ng, varray, routine, line, vstring)
Definition destroy.F:657
logical function destroy_5d_r8(ng, varray, routine, line, vstring)
Definition destroy.F:385
logical function destroy_4d_r8(ng, varray, routine, line, vstring)
Definition destroy.F:331
logical function destroy_1d_l(ng, varray, routine, line, vstring)
Definition destroy.F:115
logical function destroy_1d_dp(ng, varray, routine, line, vstring)
Definition destroy.F:441
integer, parameter pvar
Definition destroy.F:54
logical function destroy_4d_dp(ng, varray, routine, line, vstring)
Definition destroy.F:603
integer stdout
integer, parameter r8
Definition mod_kinds.F:28
integer, parameter dp
Definition mod_kinds.F:25
logical master