\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 gtdata\+\_\+netcdf\+\_\+file\+\_\+internal\+::id\+\_\+head, gtdata\+\_\+netcdf\+\_\+file\+\_\+internal\+::id\+\_\+used, dc\+\_\+error\+::storeerror(), and dc\+\_\+types\+::string.


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