41 use dc_trace
, only: beginsub, endsub
45 type(gt_variable),
intent(out) :: var
46 character(len = *),
intent(in) :: url
47 type(gt_variable),
intent(inout) :: copyfrom
48 logical,
intent(in),
optional :: copyvalue
49 logical,
intent(in),
optional :: overwrite
50 logical,
intent(out),
optional :: err
51 type(gt_variable),
allocatable :: vdimsource(:)
52 type(gt_variable),
allocatable :: vdimdest(:)
53 integer :: i, nd, stat
55 character(STRING) :: vpart, upart, desturl
56 character(TOKEN) :: xtype
57 character(len = *),
parameter:: version = &
59 &
'$Id: gtvarcreatecopy.f90,v 1.1 2009-03-20 09:09:51 morikawa Exp $' 61 call beginsub(
'gtvarcreatecopy',
'url=%c copyfrom=%d', &
62 & c1=trim(url), i=(/copyfrom%mapid/), version=version)
69 call inquire(copyfrom, alldims=nd)
70 allocate(vdimsource(nd), vdimdest(nd), stat=stat)
71 if (stat /= 0)
goto 999
77 call open(vdimsource(i), copyfrom, dimord=i, &
78 & count_compact=.true., err=myerr)
86 call urlsplit(url, var=vpart)
88 call inquire(copyfrom, url=upart)
89 call urlsplit(upart, var=vpart)
90 desturl = trim(desturl) //
gt_atmark // trim(vpart)
93 call inquire(copyfrom, xtype=xtype)
94 call create(var, trim(desturl), dims=vdimdest, xtype=xtype, &
95 & overwrite=overwrite, err=myerr)
97 call copy_attr(to=var, from=copyfrom, err=myerr)
99 if (
present(copyvalue))
then 105 call close(vdimsource(i))
106 call close(vdimdest(i))
109 deallocate(vdimsource, vdimdest, stat=stat)
113 else if (
present(err))
then 118 call endsub(
'gtvarcreatecopy',
'result=%d', i=(/var%mapid/))
129 use dc_url, only: urlsplit, urlmerge,
operator(.onthesamefile.)
131 type(gt_variable),
intent(out):: to
132 type(gt_variable),
intent(inout):: from
133 character(len = *),
intent(in):: target
134 character(len = string):: url, file, dimname
135 character(len = token):: xtype
136 logical:: growable, myerr
139 call beginsub(
'gtvarcopydim',
'from=%d target=<%c>', &
140 & i=(/from%mapid/), c1=trim(
target))
142 call inquire(var=from, url=url)
143 if (trim(url) .onthesamefile. trim(
target))
then 144 call open(to, from, dimord=0)
145 call endsub(
'gtvarcopydim',
'dup-handle')
150 call urlsplit(
target, file=file)
153 call endsub(
'gtvarcopydim',
'equivalent-exists')
158 call inquire(var=from, growable=growable, allcount=length)
159 if (growable) length = 0
160 call inquire(var=from, xtype=xtype, name=dimname)
162 url = urlmerge(file, dimname)
163 call create(to, trim(url), length, xtype, err=myerr)
166 call create(to, trim(file), length, xtype)
170 call endsub(
'gtvarcopydim',
'created')
189 use dc_string
, only:
tochar 191 type(gt_variable),
intent(out):: to
192 type(gt_variable),
intent(in):: from
193 character(len = *),
intent(in):: file
194 character(len = string):: url, units1, units2, reason
195 logical:: end, growable1, growable2
197 character(len = *),
parameter:: subnam =
"lookupequivalent" 198 call beginsub(subnam,
'from=%d file=<%c>', &
199 & i=(/from%mapid/), c1=trim(file))
202 call inquire(from, allcount=len1, growable=growable1)
203 call get_attr(from,
'units', units1, default=
'')
206 call gtvarsearch(file)
208 call gtvarsearch(url, end)
210 call open(to, url, writable=.true., err=end)
215 call inquire(to, allcount=len2, growable=growable2)
218 if (.not. growable1 .or. .not. growable2)
then 221 if (len1 /= len2)
then 225 call get_attr(to,
'units', units2, default=
'')
227 if (units1 /= units2)
then 231 reason =
'length of from is ' // trim(
tochar(len1)) // &
232 &
'. units of from is ' //
"[" // &
233 & trim(units1) //
"]" // &
234 &
'. And file has same length and units.' 237 reason =
'from is UNLIMITED dimension, and file has it' 240 call endsub(subnam,
'found (%c)', c1=trim(reason))
243 call endsub(subnam,
'not found')
253 type(gt_variable),
intent(inout):: to
254 type(gt_variable),
intent(inout):: from
255 real,
allocatable:: rbuffer(:)
259 call beginsub(
'gtvarcopyvalue')
262 call slice(to, compatible=from)
264 allocate (rbuffer(siz))
267 if (err)
call dumperror()
269 if (err)
call dumperror()
270 call slice_next(from, stat=stat)
272 call slice_next(to, stat=stat)
275 call endsub(
'gtvarcopyvalue')
integer, parameter, public token
Character length for word, token.
logical function lookupequivalent(to, from, file)
character, parameter, public gt_atmark
subroutine gtvarputreal(var, value, nvalue, err)
integer, parameter, public gt_enomem
subroutine, public storeerror(number, where, err, cause_c, cause_i)
subroutine gtvarcopydim(to, from, target)
subroutine gtvarcopyvalue(to, from)
Provides kind type parameter values.
subroutine gtvargetreal(var, value, nvalue, err)
integer, parameter, public string
Character length for string.