84 character(len = *),
intent(in) :: url
86 logical,
intent(in),
optional :: copyvalue
87 logical,
intent(in),
optional :: overwrite
88 logical,
intent(out),
optional :: err
91 integer :: i, nd, stat
93 character(STRING) :: vpart, upart, desturl
94 character(TOKEN) :: xtype
95 character(len = *),
parameter:: version = &
97 &
'$Id: gtvarcreatecopy.f90,v 1.1 2009-03-20 09:09:51 morikawa Exp $'
99 call beginsub(
'gtvarcreatecopy',
'url=%c copyfrom=%d', &
100 & c1=trim(url), i=(/copyfrom%mapid/), version=version)
107 call inquire(copyfrom, alldims=nd)
108 allocate(vdimsource(nd), vdimdest(nd), stat=stat)
109 if (stat /= 0)
goto 999
115 call open(vdimsource(i), copyfrom, dimord=i, &
116 & count_compact=.true., err=myerr)
125 if (vpart ==
"")
then
126 call inquire(copyfrom, url=upart)
128 desturl = trim(desturl) //
gt_atmark // trim(vpart)
131 call inquire(copyfrom, xtype=xtype)
132 call create(var, trim(desturl), dims=vdimdest, xtype=xtype, &
133 & overwrite=overwrite, err=myerr)
135 call copy_attr(to=var, from=copyfrom, err=myerr)
137 if (
present(copyvalue))
then
139 call gtvarcopyvalue(to=var, from=copyfrom)
143 call close(vdimsource(i))
144 call close(vdimdest(i))
147 deallocate(vdimsource, vdimdest, stat=stat)
151 else if (
present(err))
then
156 call endsub(
'gtvarcreatecopy',
'result=%d', i=(/var%mapid/))
171 character(len = *),
intent(in):: target
172 character(len = string):: url, file, dimname
173 character(len = token):: xtype
174 logical:: growable, myerr
177 call beginsub(
'gtvarcopydim',
'from=%d target=<%c>', &
178 & i=(/from%mapid/), c1=trim(
target))
180 call inquire(var=from, url=url)
181 if (trim(url) .onthesamefile. trim(
target))
then
182 call open(to, from, dimord=0)
183 call endsub(
'gtvarcopydim',
'dup-handle')
189 if (lookupequivalent(to, from, file))
then
191 call endsub(
'gtvarcopydim',
'equivalent-exists')
196 call inquire(var=from, growable=growable, allcount=length)
197 if (growable) length = 0
198 call inquire(var=from, xtype=xtype, name=dimname)
201 call create(to, trim(url), length, xtype, err=myerr)
204 call create(to, trim(file), length, xtype)
207 call gtvarcopyvalue(to, from)
208 call endsub(
'gtvarcopydim',
'created')
225 logical function lookupequivalent(to, from, file)
result(result)
229 type(gt_variable),
intent(out):: to
230 type(gt_variable),
intent(in):: from
231 character(len = *),
intent(in):: file
232 character(len = string):: url, units1, units2, reason
233 logical:: end, growable1, growable2
235 character(len = *),
parameter:: subnam =
"lookupequivalent"
236 call beginsub(subnam,
'from=%d file=<%c>', &
237 & i=(/from%mapid/), c1=trim(file))
240 call inquire(from, allcount=len1, growable=growable1)
241 call get_attr(from,
'units', units1, default=
'')
248 call open(to, url, writable=.true., err=
end)
253 call inquire(to, allcount=len2, growable=growable2)
256 if (.not. growable1 .or. .not. growable2)
then
259 if (len1 /= len2)
then
263 call get_attr(to,
'units', units2, default=
'')
265 if (units1 /= units2)
then
269 reason =
'length of from is ' // trim(tochar(len1)) // &
270 &
'. units of from is ' //
"[" // &
271 & trim(units1) //
"]" // &
272 &
'. And file has same length and units.'
275 reason =
'from is UNLIMITED dimension, and file has it'
278 call endsub(subnam,
'found (%c)', c1=trim(reason))
281 call endsub(subnam,
'not found')
282 end function lookupequivalent
286 subroutine gtvarcopyvalue(to, from)
293 real,
allocatable:: rbuffer(:)
297 call beginsub(
'gtvarcopyvalue')
300 call slice(to, compatible=from)
302 allocate (rbuffer(siz))
313 call endsub(
'gtvarcopyvalue')
314 end subroutine gtvarcopyvalue
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)