NCEPLIBS-g2  3.4.5
realloc.f
Go to the documentation of this file.
1 
6 
13 
14  module re_alloc
15 
16  interface realloc
17  module procedure realloc_c1
18  module procedure realloc_r
19  module procedure realloc_i
20 !! subroutine realloc_c1(c,n,m,istat)
21 !! character(len=1),pointer,dimension(:) :: c
22 !! integer :: n,m
23 !! integer :: istat
24 !! end subroutine
25 !! subroutine realloc_r(c,n,m,istat)
26 !! real,pointer,dimension(:) :: c
27 !! integer :: n,m
28 !! integer :: istat
29 !! end subroutine
30 !! subroutine realloc_i(c,n,m,istat)
31 !! integer,pointer,dimension(:) :: c
32 !! integer :: n,m
33 !! integer :: istat
34 !! end subroutine
35  end interface
36 
37  contains
38 
47 
48  subroutine realloc_c1(c,n,m,istat)
49  character(len=1),pointer,dimension(:) :: c
50  integer,intent(in) :: n,m
51  integer,intent(out) :: istat
52  integer :: num
53  character(len=1),pointer,dimension(:) :: tmp
54 
55  istat=0
56  if ( (n<0) .OR. (m<=0) ) then
57  istat=10
58  return
59  endif
60 
61  if ( .not. associated(c) ) then
62  allocate(c(m),stat=istat) ! allocate new memory
63  return
64  endif
65 
66  tmp=>c ! save pointer to original mem
67  nullify(c)
68  allocate(c(m),stat=istat) ! allocate new memory
69  if ( istat /= 0 ) then
70  c=>tmp
71  return
72  endif
73  if ( n /= 0 ) then
74  num=min(n,m)
75  c(1:num)=tmp(1:num) ! copy data from orig mem to new loc.
76  endif
77  deallocate(tmp) ! deallocate original memory
78  return
79  end subroutine
80 
89 
90  subroutine realloc_r(c,n,m,istat)
91  real,pointer,dimension(:) :: c
92  integer,intent(in) :: n,m
93  integer,intent(out) :: istat
94  integer :: num
95  real,pointer,dimension(:) :: tmp
96 
97  istat=0
98  if ( (n<0) .OR. (m<=0) ) then
99  istat=10
100  return
101  endif
102 
103  if ( .not. associated(c) ) then
104  allocate(c(m),stat=istat) ! allocate new memory
105  return
106  endif
107 
108  tmp=>c ! save pointer to original mem
109  nullify(c)
110  allocate(c(m),stat=istat) ! allocate new memory
111  if ( istat /= 0 ) then
112  c=>tmp
113  return
114  endif
115  if ( n /= 0 ) then
116  num=min(n,m)
117  c(1:num)=tmp(1:num) ! copy data from orig mem to new loc.
118  endif
119  deallocate(tmp) ! deallocate original memory
120  return
121  end subroutine
122 
131 
132  subroutine realloc_i(c,n,m,istat)
133  integer,pointer,dimension(:) :: c
134  integer,intent(in) :: n,m
135  integer,intent(out) :: istat
136  integer :: num
137  integer,pointer,dimension(:) :: tmp
138 
139  istat=0
140  if ( (n<0) .OR. (m<=0) ) then
141  istat=10
142  return
143  endif
144 
145  if ( .not. associated(c) ) then
146  allocate(c(m),stat=istat) ! allocate new memory
147  return
148  endif
149 
150  tmp=>c ! save pointer to original mem
151  nullify(c)
152  allocate(c(m),stat=istat) ! allocate new memory
153  if ( istat /= 0 ) then
154  c=>tmp
155  return
156  endif
157  if ( n /= 0 ) then
158  num=min(n,m)
159  c(1:num)=tmp(1:num) ! copy data from orig mem to new loc.
160  endif
161  deallocate(tmp) ! deallocate original memory
162  return
163  end subroutine
164 
165  end module re_alloc
re_alloc::realloc_c1
subroutine realloc_c1(c, n, m, istat)
This subroutine reorganize character type data in memory into one one dimensional array.
Definition: realloc.f:49
re_alloc
This module contains three subroutines to reorganize the integer, real and character data in memory i...
Definition: realloc.f:14
re_alloc::realloc
Definition: realloc.f:16
re_alloc::realloc_i
subroutine realloc_i(c, n, m, istat)
This subroutine reorganize integer type data in memory into one one dimensional array.
Definition: realloc.f:133
re_alloc::realloc_r
subroutine realloc_r(c, n, m, istat)
This subroutine reorganize real type data in memory into one one dimensional array.
Definition: realloc.f:91