\hypertarget{historycopyvariable_8f90}{}\section{gtool/gtool\+\_\+history/historycopyvariable.f90 File Reference}
\label{historycopyvariable_8f90}\index{gtool/gtool\+\_\+history/historycopyvariable.\+f90@{gtool/gtool\+\_\+history/historycopyvariable.\+f90}}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine \hyperlink{historycopyvariable_8f90_a6d9278ad53eb8247be8158b46cd3a6d2}{historycopyvariable1} (file, varname, history, overwrite)
\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{historycopyvariable_8f90_a6d9278ad53eb8247be8158b46cd3a6d2}\label{historycopyvariable_8f90_a6d9278ad53eb8247be8158b46cd3a6d2}} 
\index{historycopyvariable.\+f90@{historycopyvariable.\+f90}!historycopyvariable1@{historycopyvariable1}}
\index{historycopyvariable1@{historycopyvariable1}!historycopyvariable.\+f90@{historycopyvariable.\+f90}}
\subsubsection{\texorpdfstring{historycopyvariable1()}{historycopyvariable1()}}
{\footnotesize\ttfamily subroutine historycopyvariable1 (\begin{DoxyParamCaption}\item[{character(len = $\ast$), intent(in)}]{file,  }\item[{character(len = $\ast$), intent(in)}]{varname,  }\item[{type(gt\+\_\+history), intent(inout), optional, target}]{history,  }\item[{logical, intent(in), optional}]{overwrite }\end{DoxyParamCaption})}



Definition at line 11 of file historycopyvariable.\+f90.



References dc\+\_\+types\+::dp, dc\+\_\+url\+::gt\+\_\+atmark, dc\+\_\+types\+::string, and dc\+\_\+types\+::token.


\begin{DoxyCode}
11     \textcolor{comment}{!}
12     \textcolor{comment}{!== 変数定義 (別ファイルの変数コピー)}
13     \textcolor{comment}{!}
14     \textcolor{comment}{! gtool4 データ内の変数の定義を行います。 他の gtool4 データの}
15     \textcolor{comment}{! ファイル名とその中の変数名を指定することで、 自動的のその変数の}
16     \textcolor{comment}{! 構造や属性をコピーして変数定義します。このサブルーチンを}
17     \textcolor{comment}{! 用いる前に、 HistoryCreate による初期設定が必要です。}
18     \textcolor{comment}{!}
19     \textcolor{comment}{! 構造や属性を手動で設定する場合には HistoryAddVariable}
20     \textcolor{comment}{! を用いて下さい。}
21     \textcolor{comment}{!}
22     \textcolor{keywordtype}{use }\hyperlink{namespacegtool__history__types}{gtool\_history\_types}\textcolor{keywordtype}{, only}: gt\_history, gt\_history\_axis, gt\_history\_varinfo, 
      gt\_history\_attr, gt\_history\_avrdata
23     \textcolor{keywordtype}{use }gtool\_history\_internal\textcolor{keywordtype}{, only}: default
24     \textcolor{keywordtype}{use }gtdata\_generic\textcolor{keywordtype}{, only}: \hyperlink{interfacedc__date__generic_1_1create}{create}, \hyperlink{interfacegtdata__netcdf__generic_1_1inquire}{inquire}, \hyperlink{interfacegtdata__netcdf__generic_1_1open}{open}, slice, 
      \hyperlink{interfacegtdata__netcdf__generic_1_1close}{close}
25     \textcolor{keywordtype}{use }\hyperlink{namespacegtdata__types}{gtdata\_types}\textcolor{keywordtype}{, only}: gt\_variable
26     \textcolor{keywordtype}{use }dc\_present\textcolor{keywordtype}{, only}: present\_and\_false
27     \textcolor{keywordtype}{use }\hyperlink{namespacedc__url}{dc\_url}\textcolor{keywordtype}{, only}: urlmerge, \hyperlink{namespacedc__url_a3157f15c35d09732b55dfb0f4f52397d}{gt\_atmark}, urlresolve
28     \textcolor{keywordtype}{use }\hyperlink{namespacedc__date}{dc\_date}\textcolor{keywordtype}{, only}: \hyperlink{interfacedc__date__generic_1_1dcdifftimecreate}{dcdifftimecreate}
29     \textcolor{keywordtype}{use }\hyperlink{namespacedc__date__types}{dc\_date\_types}\textcolor{keywordtype}{, only}: dc\_difftime
30     \textcolor{keywordtype}{use }\hyperlink{namespacedc__types}{dc\_types}\textcolor{keywordtype}{, only}: \hyperlink{namespacedc__types_adb76910ff05e3b9fe3436567f8f8dac6}{string}, \hyperlink{namespacedc__types_a6d28eb015ba84292a06f4ff25165b376}{token}, \hyperlink{namespacedc__types_ac74a34430fcd3d0eb2344f19d536c086}{dp}
31     \textcolor{keywordtype}{use }dc\_trace\textcolor{keywordtype}{, only}: beginsub, endsub, dbgmessage
32     \textcolor{keywordtype}{implicit none}
33     \textcolor{keywordtype}{character(len = *)}, \textcolor{keywordtype}{intent(in)}:: file
34                               \textcolor{comment}{! コピーしようとする変数が格納された}
35                               \textcolor{comment}{! netCDF ファイル名}
36                               \textcolor{comment}{! }
37     \textcolor{keywordtype}{character(len = *)}, \textcolor{keywordtype}{intent(in)}:: varname
38                               \textcolor{comment}{! コピー元となる変数の名前}
39                               \textcolor{comment}{!}
40                               \textcolor{comment}{! 定義される変数名もこれと}
41                               \textcolor{comment}{! 同じになります。}
42                               \textcolor{comment}{! 最大文字数は dc\_types#TOKEN 。}
43                               \textcolor{comment}{!}
44                               \textcolor{comment}{! 依存する次元が存在しない}
45                               \textcolor{comment}{! 場合は自動的にその次元に関する}
46                               \textcolor{comment}{! 変数情報も元のファイルから}
47                               \textcolor{comment}{! コピーします。}
48                               \textcolor{comment}{! この場合に「同じ次元」と見}
49                               \textcolor{comment}{! なされるのは、(1) 無制限次}
50                               \textcolor{comment}{! 元 (自動的に「時間」と認識}
51                               \textcolor{comment}{! される)、}
52                               \textcolor{comment}{! (2) サイズと単位が同じ次元、}
53                               \textcolor{comment}{! です。}
54                               \textcolor{comment}{! }
55     \textcolor{keywordtype}{type}(gt\_history), \textcolor{keywordtype}{intent(inout)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{target}:: history
56                               \textcolor{comment}{! 出力ファイルの設定に関する情報を}
57                               \textcolor{comment}{! 格納した構造体}
58                               \textcolor{comment}{! }
59                               \textcolor{comment}{! ここに指定するものは、}
60                               \textcolor{comment}{! HistoryCreate によって初期設定}
61                               \textcolor{comment}{! されていなければなりません。}
62                               \textcolor{comment}{!}
63     \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(in)}, \textcolor{keywordtype}{optional}:: overwrite
64                               \textcolor{comment}{! 上書きの可否の設定}
65                               \textcolor{comment}{!}
66                               \textcolor{comment}{! この引数に .false. を渡すと、}
67                               \textcolor{comment}{! 既存のファイルを上書きしません。}
68                               \textcolor{comment}{! デフォルトは上書きします。}
69                               \textcolor{comment}{! }
70 
71     \textcolor{keywordtype}{type}(gt\_history),  \textcolor{keywordtype}{pointer}:: hst =>null()
72     \textcolor{keywordtype}{type}(gt\_variable), \textcolor{keywordtype}{pointer}:: vwork(:) =>null(), dimvars(:) =>null()
73     \textcolor{keywordtype}{type}(gt\_variable):: copyfrom
74     \textcolor{keywordtype}{character(STRING)}:: fullname, url, copyurl
75     \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{pointer}:: count\_work(:) =>null()
76     \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{pointer}:: var\_avr\_count\_work(:) =>null()
77     \textcolor{keywordtype}{integer}:: var\_avr\_length
78     \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{pointer}:: var\_avr\_firstput\_work(:) =>null()
79     \textcolor{keywordtype}{real(DP)}, \textcolor{keywordtype}{pointer}:: var\_avr\_coefsum\_work(:) =>null()
80     \textcolor{keywordtype}{real(DP)}, \textcolor{keywordtype}{pointer}:: var\_avr\_baseint\_work(:) =>null()
81     \textcolor{keywordtype}{real(DP)}, \textcolor{keywordtype}{pointer}:: var\_avr\_prevtime\_work(:) =>null()
82 \textcolor{comment}{!!$    type(DC\_DIFFTIME), pointer:: var\_avr\_baseint\_work(:) =>null()}
83 \textcolor{comment}{!!$    type(DC\_DIFFTIME), pointer:: var\_avr\_prevtime\_work(:) =>null()}
84     \textcolor{keywordtype}{type}(gt\_history\_avrdata), \textcolor{keywordtype}{pointer}:: var\_avr\_data\_work(:) =>null()
85     \textcolor{keywordtype}{integer}:: nvars, numdims, i
86     \textcolor{keywordtype}{logical}:: growable, overwrite\_required
87     \textcolor{keywordtype}{character(*)}, \textcolor{keywordtype}{parameter}:: subname = \textcolor{stringliteral}{"HistoryCopyVariable1"}
88   \textcolor{keywordflow}{continue}
89     \textcolor{keyword}{call }beginsub(subname, \textcolor{stringliteral}{'file=%c varname=%c'}, &
90       & c1=trim(file), c2=trim(varname))
91     \textcolor{comment}{!----- 操作対象決定 -----}
92     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(history)) \textcolor{keywordflow}{then}
93       hst => history
94     \textcolor{keywordflow}{else}
95       hst => default
96 \textcolor{keywordflow}{    endif}
97 
98     \textcolor{comment}{!----- 変数表拡張 -----}
99     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(hst % vars)) \textcolor{keywordflow}{then}
100       nvars = \textcolor{keyword}{size}(hst % vars(:))
101       vwork => hst % vars
102       count\_work => hst % count
103       \textcolor{keyword}{nullify}(hst % vars, hst % count)
104       \textcolor{keyword}{allocate}(hst % vars(nvars + 1), hst % count(nvars + 1))
105       hst % vars(1:nvars) = vwork(1:nvars)
106       hst % count(1:nvars) = count\_work(1:nvars)
107       \textcolor{keyword}{deallocate}(vwork, count\_work)
108       count\_work => hst % growable\_indices
109       \textcolor{keyword}{nullify}(hst % growable\_indices)
110       \textcolor{keyword}{allocate}(hst % growable\_indices(nvars + 1))
111       hst % growable\_indices(1:nvars) = count\_work(1:nvars)
112       \textcolor{keyword}{deallocate}(count\_work)
113 
114       \textcolor{comment}{!}
115       \textcolor{comment}{! 平均値出力のための変数表コピー}
116       \textcolor{comment}{! Copy table of variables for average value output}
117       \textcolor{comment}{!}
118       var\_avr\_count\_work => hst % var\_avr\_count
119       \textcolor{keyword}{nullify}( hst % var\_avr\_count )
120       \textcolor{keyword}{allocate}( hst % var\_avr\_count(nvars + 1) )
121       hst % var\_avr\_count(1:nvars) = var\_avr\_count\_work(1:nvars)
122       \textcolor{keyword}{deallocate}( var\_avr\_count\_work )
123 
124       var\_avr\_data\_work => hst % var\_avr\_data
125       \textcolor{keyword}{nullify}(hst % var\_avr\_data)
126       \textcolor{keyword}{allocate}(hst % var\_avr\_data(nvars + 1))
127       \textcolor{keywordflow}{do} i = 1, nvars
128         hst % var\_avr\_data(i) % length = var\_avr\_data\_work(i) % length
129         \textcolor{keyword}{allocate}(hst % var\_avr\_data(i) % &
130           & a\_dataavr(var\_avr\_data\_work(i) % length))
131         hst % var\_avr\_data(i) % a\_DataAvr = var\_avr\_data\_work(i) % a\_DataAvr
132 \textcolor{keywordflow}{      end do}
133       \textcolor{keyword}{deallocate}( var\_avr\_data\_work )
134 
135       var\_avr\_firstput\_work => hst % var\_avr\_firstput
136       \textcolor{keyword}{nullify}( hst % var\_avr\_firstput )
137       \textcolor{keyword}{allocate}( hst % var\_avr\_firstput(nvars + 1) )
138       hst % var\_avr\_firstput(1:nvars) = var\_avr\_firstput\_work(1:nvars)
139       \textcolor{keyword}{deallocate}( var\_avr\_firstput\_work )
140 
141       var\_avr\_coefsum\_work => hst % var\_avr\_coefsum
142       \textcolor{keyword}{nullify}( hst % var\_avr\_coefsum )
143       \textcolor{keyword}{allocate}( hst % var\_avr\_coefsum(nvars + 1) )
144       hst % var\_avr\_coefsum(1:nvars) = var\_avr\_coefsum\_work(1:nvars)
145       \textcolor{keyword}{deallocate}( var\_avr\_coefsum\_work )
146 
147       var\_avr\_baseint\_work => hst % var\_avr\_baseint
148       \textcolor{keyword}{nullify}( hst % var\_avr\_baseint )
149       \textcolor{keyword}{allocate}( hst % var\_avr\_baseint(nvars + 1) )
150       hst % var\_avr\_baseint(1:nvars) = var\_avr\_baseint\_work(1:nvars)
151       \textcolor{keyword}{deallocate}( var\_avr\_baseint\_work )
152 
153       var\_avr\_prevtime\_work => hst % var\_avr\_prevtime
154       \textcolor{keyword}{nullify}( hst % var\_avr\_prevtime )
155       \textcolor{keyword}{allocate}( hst % var\_avr\_prevtime(nvars + 1) )
156       hst % var\_avr\_prevtime(1:nvars) = var\_avr\_prevtime\_work(1:nvars)
157       \textcolor{keyword}{deallocate}( var\_avr\_prevtime\_work )
158     \textcolor{keywordflow}{else}
159       \textcolor{comment}{! トリッキーだが、ここで count だけ 2 要素確保するのは、}
160       \textcolor{comment}{! HistorySetTime による巻き戻しに備えるため。}
161       \textcolor{keyword}{allocate}(hst % vars(1), hst % count(2), hst % growable\_indices(1))
162       hst % count(2) = 0
163       \textcolor{keyword}{allocate}(hst % var\_avr\_count(1), hst % var\_avr\_data(1))
164       \textcolor{keyword}{allocate}(hst % var\_avr\_firstput(1), hst % var\_avr\_coefsum(1))
165       \textcolor{keyword}{allocate}(hst % var\_avr\_baseint(1), hst % var\_avr\_prevtime(1))
166 \textcolor{keywordflow}{    endif}
167     nvars = \textcolor{keyword}{size}(hst % vars(:))
168     hst % growable\_indices(nvars) = 0
169     hst % count(nvars) = 0
170     hst % var\_avr\_count(nvars) = -1
171     hst % var\_avr\_firstput = .true.
172     hst % var\_avr\_coefsum(nvars) = 0.0\_dp
173     hst % var\_avr\_baseint(nvars) = 0.0\_dp
174 \textcolor{comment}{!!$    call DCDiffTimeCreate( &}
175 \textcolor{comment}{!!$      & hst % var\_avr\_baseint(nvars), & ! (out)}
176 \textcolor{comment}{!!$      & sec = 0.0\_DP )                   ! (in)}
177     hst % var\_avr\_prevtime(nvars) = hst % var\_avr\_baseint(nvars)
178 
179     \textcolor{comment}{!----- コピー元ファイルの変数 ID 取得 -----}
180     copyurl = urlmerge(file, varname)
181     \textcolor{keyword}{call }\hyperlink{interfacegtdata__netcdf__generic_1_1open}{open}(copyfrom, copyurl)
182 
183     \textcolor{comment}{!----- 変数コピー -----}
184     \textcolor{keyword}{call }\hyperlink{interfacegtdata__netcdf__generic_1_1inquire}{inquire}(hst % dimvars(1), url=url)
185     fullname = urlresolve((\hyperlink{namespacedc__url_a3157f15c35d09732b55dfb0f4f52397d}{gt\_atmark} // trim(varname)), trim(url))
186     overwrite\_required = .true.
187     \textcolor{keywordflow}{if} (present\_and\_false(overwrite)) overwrite\_required = .false.
188     \textcolor{keyword}{call }\hyperlink{interfacedc__date__generic_1_1create}{create}(hst % vars(nvars), trim(fullname), copyfrom, &
189       &      copyvalue=.false., overwrite=overwrite\_required)
190 
191     \textcolor{comment}{!----- 無制限次元の添字を探査 -----}
192     \textcolor{keyword}{call }\hyperlink{interfacegtdata__netcdf__generic_1_1inquire}{inquire}(hst % vars(nvars), alldims=numdims)
193     \textcolor{keyword}{allocate}(dimvars(numdims))
194     \textcolor{comment}{! 各次元毎に情報を取得し, growable == .TRUE. のもの (つまりは時間)}
195     \textcolor{comment}{! の添字番号を取得する}
196     \textcolor{keywordflow}{do}, i = 1, numdims
197       \textcolor{keyword}{call }\hyperlink{interfacegtdata__netcdf__generic_1_1open}{open}(var=dimvars(i), source\_var=hst % vars(nvars), &
198         &    dimord=i, count\_compact=.true.)
199       \textcolor{comment}{! 各次元変数の growable を調べる}
200       \textcolor{keyword}{call }\hyperlink{interfacegtdata__netcdf__generic_1_1inquire}{inquire}(var=dimvars(i), growable=growable)
201       \textcolor{keywordflow}{if} (growable) \textcolor{keywordflow}{then}
202         hst % growable\_indices(nvars) = i
203 \textcolor{keywordflow}{      endif}
204 \textcolor{keywordflow}{    enddo}
205 
206     \textcolor{comment}{!----- 拡張可能次元があったらそれをサイズ 1 に拡張しておく -----}
207     \textcolor{keywordflow}{if} (hst % growable\_indices(nvars) /= 0) \textcolor{keywordflow}{then}
208       \textcolor{keyword}{call }slice(hst % vars(nvars), hst % growable\_indices(nvars), &
209         & start=1, count=1, stride=1)
210 \textcolor{keywordflow}{    endif}
211 
212     \textcolor{keyword}{deallocate}(dimvars)
213 
214     \textcolor{keyword}{call }\hyperlink{interfacegtdata__netcdf__generic_1_1inquire}{inquire}( hst % vars(nvars), \textcolor{keyword}{size} = var\_avr\_length )
215     \textcolor{keyword}{allocate}( hst % var\_avr\_data(nvars) % a\_DataAvr(var\_avr\_length) )
216     hst % var\_avr\_data(nvars) % length = var\_avr\_length
217     hst % var\_avr\_data(nvars) % a\_DataAvr = 0.0\_dp
218 
219     \textcolor{keyword}{call }\hyperlink{interfacegtdata__netcdf__generic_1_1close}{close}(copyfrom)
220     \textcolor{keyword}{call }endsub(subname)
\end{DoxyCode}
