source: LMDZ5/branches/LF-private/tools/Max_diff_nc_with_lib/NR_util/reallocate.f90

Last change on this file was 1765, checked in by lguez, 11 years ago

A tool to compare NetCDF files.

File size: 2.4 KB
Line 
1MODULE reallocate_m
2
3  IMPLICIT NONE
4
5  INTERFACE reallocate
6     MODULE PROCEDURE reallocate_rv, reallocate_rm, reallocate_iv, &
7          reallocate_im, reallocate_hv
8  END INTERFACE
9
10  private
11  public reallocate
12
13CONTAINS
14
15  FUNCTION reallocate_rv(p, n)
16    REAL, POINTER:: p(:), reallocate_rv(:)
17    INTEGER, INTENT(IN):: n
18    INTEGER nold
19    !-----------------------------------------------
20    allocate(reallocate_rv(n))
21    if (.not. associated(p)) RETURN
22    nold = size(p)
23    reallocate_rv(:min(nold, n)) = p(:min(nold, n))
24    deallocate(p)
25  END FUNCTION reallocate_rv
26
27  !***********************************************************
28
29  FUNCTION reallocate_iv(p, n)
30    INTEGER, POINTER:: p(:), reallocate_iv(:)
31    INTEGER, INTENT(IN):: n
32    INTEGER nold
33    !-----------------------------------------------
34    allocate(reallocate_iv(n))
35    if (.not. associated(p)) RETURN
36    nold = size(p)
37    reallocate_iv(:min(nold, n)) = p(:min(nold, n))
38    deallocate(p)
39  END FUNCTION reallocate_iv
40
41  !***********************************************************
42
43  FUNCTION reallocate_hv(p, n)
44    CHARACTER, POINTER:: p(:), reallocate_hv(:)
45    INTEGER, INTENT(IN):: n
46    INTEGER nold
47    !-----------------------------------------------
48    allocate(reallocate_hv(n))
49    if (.not. associated(p)) RETURN
50    nold = size(p)
51    reallocate_hv(:min(nold, n)) = p(:min(nold, n))
52    deallocate(p)
53  END FUNCTION reallocate_hv
54
55  !***********************************************************
56
57  FUNCTION reallocate_rm(p, n, m)
58    REAL, DIMENSION(:, :), POINTER:: p, reallocate_rm
59    INTEGER, INTENT(IN):: n, m
60    INTEGER nold, mold
61    !-----------------------------------------------
62    allocate(reallocate_rm(n, m))
63    if (.not. associated(p)) RETURN
64    nold = size(p, 1)
65    mold = size(p, 2)
66    reallocate_rm(:min(nold, n), :min(mold, m)) &
67         = p(:min(nold, n), :min(mold, m))
68    deallocate(p)
69  END FUNCTION reallocate_rm
70
71  !***********************************************************
72
73  FUNCTION reallocate_im(p, n, m)
74    INTEGER, DIMENSION(:, :), POINTER:: p, reallocate_im
75    INTEGER, INTENT(IN):: n, m
76    INTEGER nold, mold
77    !-----------------------------------------------
78    allocate(reallocate_im(n, m))
79    if (.not. associated(p)) RETURN
80    nold = size(p, 1)
81    mold = size(p, 2)
82    reallocate_im(:min(nold, n), :min(mold, m)) &
83         = p(:min(nold, n), :min(mold, m))
84    deallocate(p)
85  END FUNCTION reallocate_im
86
87END MODULE reallocate_m
Note: See TracBrowser for help on using the repository browser.