\hypertarget{gdncfileopen_8f90}{}\section{gtdata/gtdata\+\_\+netcdf/gtdata\+\_\+netcdf\+\_\+file/gdncfileopen.f90 File Reference}
\label{gdncfileopen_8f90}\index{gtdata/gtdata\+\_\+netcdf/gtdata\+\_\+netcdf\+\_\+file/gdncfileopen.\+f90@{gtdata/gtdata\+\_\+netcdf/gtdata\+\_\+netcdf\+\_\+file/gdncfileopen.\+f90}}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine \hyperlink{gdncfileopen_8f90_a4f95f1f240238c6a431b39ea8e7c6f47}{gdncfileopen} (fileid, filename, writable, overwrite, stat, err)
\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{gdncfileopen_8f90_a4f95f1f240238c6a431b39ea8e7c6f47}\label{gdncfileopen_8f90_a4f95f1f240238c6a431b39ea8e7c6f47}} 
\index{gdncfileopen.\+f90@{gdncfileopen.\+f90}!gdncfileopen@{gdncfileopen}}
\index{gdncfileopen@{gdncfileopen}!gdncfileopen.\+f90@{gdncfileopen.\+f90}}
\subsubsection{\texorpdfstring{gdncfileopen()}{gdncfileopen()}}
{\footnotesize\ttfamily subroutine gdncfileopen (\begin{DoxyParamCaption}\item[{integer, intent(out)}]{fileid,  }\item[{character(len = $\ast$), intent(in)}]{filename,  }\item[{logical, intent(in), optional}]{writable,  }\item[{logical, intent(in), optional}]{overwrite,  }\item[{integer, intent(out), optional}]{stat,  }\item[{logical, intent(out), optional}]{err }\end{DoxyParamCaption})}



Definition at line 2 of file gdncfileopen.\+f90.



References dc\+\_\+trace\+::beginsub(), dc\+\_\+trace\+::endsub(), gtdata\+\_\+netcdf\+\_\+file\+\_\+internal\+::id\+\_\+head, gtdata\+\_\+netcdf\+\_\+file\+\_\+internal\+::id\+\_\+used, dc\+\_\+error\+::storeerror(), and dc\+\_\+types\+::string.



Referenced by gdncvarcreate(), gdncvarcreated(), gdncvaropen(), and gdncvarsearchinit().


\begin{DoxyCode}
2   \textcolor{keywordtype}{use }\hyperlink{namespacegtdata__netcdf__file__types}{gtdata\_netcdf\_file\_types}\textcolor{keywordtype}{, only}: 
      \hyperlink{structgtdata__netcdf__file__types_1_1gd__nc__file__id__entry}{gd\_nc\_file\_id\_entry}
3   \textcolor{keywordtype}{use }\hyperlink{namespacegtdata__netcdf__file__internal}{gtdata\_netcdf\_file\_internal}\textcolor{keywordtype}{, only}: \hyperlink{namespacegtdata__netcdf__file__internal_adc425214d1fe0c8803e7b91f0d2074f8}{id\_head}, 
      \hyperlink{namespacegtdata__netcdf__file__internal_ad13ad75c1b2a9be6fd6f67d457dd710f}{id\_used}
4   \textcolor{keywordtype}{use }netcdf\textcolor{keywordtype}{, only}: &
5     & nf90\_write, &
6     & nf90\_nowrite, &
7     & nf90\_noerr, &
8     & nf90\_noclobber, &
9     & nf90\_clobber, &
10     & nf90\_open, &
11     & nf90\_create
12   \textcolor{keywordtype}{use }\hyperlink{namespacedc__message}{dc\_message}\textcolor{keywordtype}{, only}: \hyperlink{interfacedc__message_1_1messagenotify}{messagenotify}
13   \textcolor{keywordtype}{use }\hyperlink{namespacedc__error}{dc\_error}\textcolor{keywordtype}{, only}: \hyperlink{namespacedc__error_a0104aee83ee5752b1a9f6152b11864a8}{storeerror}
14   \textcolor{keywordtype}{use }\hyperlink{namespacedc__types}{dc\_types}\textcolor{keywordtype}{, only}: \hyperlink{namespacedc__types_adb76910ff05e3b9fe3436567f8f8dac6}{string}
15   \textcolor{keywordtype}{use }\hyperlink{namespacedc__trace}{dc\_trace}\textcolor{keywordtype}{, only}: \hyperlink{namespacedc__trace_aca1efe8bae50b85f74980a8c4d704dd8}{beginsub}, \hyperlink{namespacedc__trace_ae44de97565a3bdd685789c7748b37e37}{endsub}
16   \textcolor{keywordtype}{implicit none}
17   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(out)}:: fileid
18   \textcolor{keywordtype}{character(len = *)}, \textcolor{keywordtype}{intent(in)}:: filename
19   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(in)}, \textcolor{keywordtype}{optional}:: writable
20                                         \textcolor{comment}{! .TRUE. は書き込みモード、}
21                                         \textcolor{comment}{! .FALSE. は読込モード。}
22                                         \textcolor{comment}{! 読込モードの際にファイルが}
23                                         \textcolor{comment}{! ファイルが存在しないと}
24                                         \textcolor{comment}{! エラーになる。}
25                                         \textcolor{comment}{! デフォルトは読み込みモード}
26   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(in)}, \textcolor{keywordtype}{optional}:: overwrite
27                                         \textcolor{comment}{! writable が .TRUE. の}
28                                         \textcolor{comment}{! 場合のみ有効。}
29                                         \textcolor{comment}{! .TRUE. ならば上書きモード}
30                                         \textcolor{comment}{! .FALSE. の場合、既存の}
31                                         \textcolor{comment}{! ファイルが存在すると}
32                                         \textcolor{comment}{! エラーになる}
33   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(out)}, \textcolor{keywordtype}{optional}:: err
34   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(out)}, \textcolor{keywordtype}{optional}:: stat
35   \textcolor{keywordtype}{logical}:: writable\_required
36   \textcolor{keywordtype}{logical}:: overwrite\_required
37   \textcolor{keywordtype}{type}(\hyperlink{structgtdata__netcdf__file__types_1_1gd__nc__file__id__entry}{gd\_nc\_file\_id\_entry}), \textcolor{keywordtype}{pointer}:: identptr, prev
38   \textcolor{keywordtype}{integer}:: mystat, mode
39   \textcolor{keywordtype}{character(len = 256)}:: real\_filename
40   \textcolor{keywordtype}{character(len = STRING)}:: cause\_c
41   \textcolor{keywordtype}{character(*)}, \textcolor{keywordtype}{parameter}:: subname = \textcolor{stringliteral}{"GDNcFileOpen"}
42 \textcolor{keywordflow}{continue}
43   fileid = -1
44   \textcolor{comment}{!}
45   \textcolor{comment}{! オプションの解釈}
46   \textcolor{comment}{!}
47   writable\_required = .false.
48   overwrite\_required = .false.
49   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(writable)) writable\_required = writable
50   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(overwrite)) overwrite\_required = overwrite
51   \textcolor{keyword}{call }\hyperlink{namespacedc__trace_aca1efe8bae50b85f74980a8c4d704dd8}{beginsub}(subname, \textcolor{stringliteral}{'writable=%y overwrite=%y file=%c'}, &
52     & l=(/writable\_required, overwrite\_required/), c1=trim(filename))
53   \textcolor{comment}{!}
54   \textcolor{comment}{! 同じ名前で書込み可能性も適合していれば nf90\_open しないで済ませる}
55   \textcolor{comment}{!}
56   \textcolor{keywordflow}{if} (\hyperlink{namespacegtdata__netcdf__file__internal_ad13ad75c1b2a9be6fd6f67d457dd710f}{id\_used}) \textcolor{keywordflow}{then}
57     identptr => \hyperlink{namespacegtdata__netcdf__file__internal_adc425214d1fe0c8803e7b91f0d2074f8}{id\_head}
58     \textcolor{keyword}{nullify}(prev)
59     \textcolor{keywordflow}{do}
60       \textcolor{keywordflow}{if} ((identptr % filename == filename) &
61         & .and. (identptr % writable .or. .not. writable\_required)) \textcolor{keywordflow}{then}
62         fileid = identptr % id
63         identptr % count = identptr % count + 1
64         \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(err)) err = .false.
65         \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(stat)) stat = nf90\_noerr
66         mystat = nf90\_noerr
67         \textcolor{keywordflow}{goto} 999
68 \textcolor{keywordflow}{      endif}
69       prev => identptr
70       identptr => identptr % next
71       \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(identptr)) \textcolor{keywordflow}{exit}
72 \textcolor{keywordflow}{    enddo}
73     \textcolor{keyword}{allocate}(identptr)
74     prev%next => identptr
75   \textcolor{keywordflow}{else}
76     \textcolor{keyword}{nullify}(prev)
77     \textcolor{keyword}{allocate}(\hyperlink{namespacegtdata__netcdf__file__internal_adc425214d1fe0c8803e7b91f0d2074f8}{id\_head})
78     identptr => \hyperlink{namespacegtdata__netcdf__file__internal_adc425214d1fe0c8803e7b91f0d2074f8}{id\_head}
79     \hyperlink{namespacegtdata__netcdf__file__internal_ad13ad75c1b2a9be6fd6f67d457dd710f}{id\_used} = .true.
80 \textcolor{keywordflow}{  endif}
81   \textcolor{keyword}{nullify}(identptr % next)
82   identptr % filename = filename
83   identptr % writable = writable\_required
84   identptr % count = 1
85   \textcolor{comment}{!}
86   \textcolor{comment}{! URL の部分的サポート}
87   \textcolor{comment}{!}
88   real\_filename = filename
89   \textcolor{keywordflow}{if} (real\_filename(1:8) == \textcolor{stringliteral}{'file:///'}) \textcolor{keywordflow}{then}
90     real\_filename = real\_filename(8: )
91   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (real\_filename(1:5) == \textcolor{stringliteral}{'file:'} .AND. real\_filename(6:6) /= \textcolor{stringliteral}{'/'}) \textcolor{keywordflow}{then}
92     real\_filename = real\_filename(6: )
93 \textcolor{keywordflow}{  endif}
94   \textcolor{comment}{!}
95   \textcolor{comment}{! いざ nf90\_open}
96   \textcolor{comment}{!}
97   mode = nf90\_nowrite
98   \textcolor{keywordflow}{if} (writable\_required) mode = ior(mode, nf90\_write)
99   \textcolor{comment}{! 既に nc ファイルがあると思って開けてみる}
100   mystat = nf90\_open(real\_filename, mode, identptr % id)
101   \textcolor{comment}{!}
102   \textcolor{comment}{! ファイルが既に存在する場合}
103   \textcolor{comment}{!}
104   \textcolor{keywordflow}{if} (mystat == nf90\_noerr) \textcolor{keywordflow}{then}
105     \textcolor{comment}{! 書き込みモードの場合}
106     \textcolor{keywordflow}{if} (writable\_required) \textcolor{keywordflow}{then}
107       \textcolor{keywordflow}{if} (overwrite\_required) \textcolor{keywordflow}{then}
108         \textcolor{comment}{! 上書きモードの場合}
109         mode = nf90\_clobber
110         \textcolor{keyword}{call }\hyperlink{interfacedc__message_1_1messagenotify}{messagenotify}(\textcolor{stringliteral}{'M'}, subname, &
111           & \textcolor{stringliteral}{'"%c" is overwritten.'}, c1=trim(filename), rank\_mpi = -1)
112       \textcolor{keywordflow}{else}
113         \textcolor{comment}{! 上書き禁止モードの場合}
114         mode = nf90\_noclobber
115         \textcolor{keyword}{call }\hyperlink{interfacedc__message_1_1messagenotify}{messagenotify}(\textcolor{stringliteral}{'W'}, subname, &
116           & \textcolor{stringliteral}{'"%c" is opened in write-protect mode.'}, c1=trim(filename), rank\_mpi = -1)
117 \textcolor{keywordflow}{      end if}
118       mystat = nf90\_create(real\_filename, mode, identptr % id)
119       \textcolor{keywordflow}{if} (mystat /= nf90\_noerr) \textcolor{keywordflow}{then}
120         cause\_c=filename
121         \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(stat)) stat = mystat
122         \textcolor{keywordflow}{goto} 999
123 \textcolor{keywordflow}{      end if}
124 \textcolor{keywordflow}{    endif}
125     \textcolor{comment}{! 読み込みモードの場合は何もしない}
126   \textcolor{keywordflow}{else}
127     \textcolor{comment}{!}
128     \textcolor{comment}{! ファイルが無かった場合}
129     \textcolor{comment}{!}
130     \textcolor{keywordflow}{if} (.not. writable\_required) \textcolor{keywordflow}{then}
131       \textcolor{comment}{! 読み込みモードの場合}
132       \textcolor{comment}{!}
133       \textcolor{comment}{! 「無いよ」とエラーを吐いて終了}
134       \textcolor{keywordflow}{if} (mystat /= nf90\_noerr) \textcolor{keywordflow}{then}
135         cause\_c=filename
136         \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(stat)) stat = mystat
137         \textcolor{keywordflow}{goto} 999
138 \textcolor{keywordflow}{      end if}
139     \textcolor{keywordflow}{else}
140       \textcolor{comment}{! 書き込みモードの場合}
141       mode = nf90\_clobber
142       \textcolor{comment}{! ファイルを作成する}
143       mystat = nf90\_create(real\_filename, mode, identptr % id)
144       \textcolor{keywordflow}{if} (mystat /= nf90\_noerr) \textcolor{keywordflow}{then}
145         cause\_c=filename
146         \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(stat)) stat = mystat
147         \textcolor{keywordflow}{goto} 999
148 \textcolor{keywordflow}{      end if}
149 \textcolor{keywordflow}{    endif}
150 \textcolor{keywordflow}{  endif}
151 
152   fileid = identptr % id
153 
154   \textcolor{comment}{! 失敗したら消しておく}
155   \textcolor{keywordflow}{if} (mystat /= nf90\_noerr) \textcolor{keywordflow}{then}
156     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(prev)) \textcolor{keywordflow}{then}
157       prev%next => identptr % next
158     \textcolor{keywordflow}{else}
159       \hyperlink{namespacegtdata__netcdf__file__internal_adc425214d1fe0c8803e7b91f0d2074f8}{id\_head} => identptr % next
160       \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(\hyperlink{namespacegtdata__netcdf__file__internal_adc425214d1fe0c8803e7b91f0d2074f8}{id\_head})) \hyperlink{namespacegtdata__netcdf__file__internal_ad13ad75c1b2a9be6fd6f67d457dd710f}{id\_used} = .false.
161 \textcolor{keywordflow}{    endif}
162     \textcolor{keyword}{deallocate}(identptr)
163     fileid = -1
164 \textcolor{keywordflow}{  endif}
165 
166   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(stat)) \textcolor{keywordflow}{then}
167     stat = mystat
168     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(err)) err = (stat /= nf90\_noerr)
169   \textcolor{keywordflow}{else}
170     cause\_c=filename
171     \textcolor{keywordflow}{goto} 999
172 \textcolor{keywordflow}{  endif}
173 999 \textcolor{keywordflow}{continue}
174   \textcolor{keyword}{call }\hyperlink{namespacedc__error_a0104aee83ee5752b1a9f6152b11864a8}{storeerror}(mystat, subname, err, cause\_c)
175   \textcolor{keyword}{call }\hyperlink{namespacedc__trace_ae44de97565a3bdd685789c7748b37e37}{endsub}(subname, \textcolor{stringliteral}{'id=%d stat=%d'}, i=(/fileid, mystat/))
\end{DoxyCode}
Here is the call graph for this function\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{gdncfileopen_8f90_a4f95f1f240238c6a431b39ea8e7c6f47_cgraph}
\end{center}
\end{figure}
Here is the caller graph for this function\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=280pt]{gdncfileopen_8f90_a4f95f1f240238c6a431b39ea8e7c6f47_icgraph}
\end{center}
\end{figure}
