\hypertarget{interfacedc__iounit_1_1fileopen}{}\section{dc\+\_\+iounit\+:\+:fileopen Interface Reference}
\label{interfacedc__iounit_1_1fileopen}\index{dc\+\_\+iounit\+::fileopen@{dc\+\_\+iounit\+::fileopen}}
\subsection*{Private Member Functions}
\begin{DoxyCompactItemize}
\item 
subroutine \hyperlink{interfacedc__iounit_1_1fileopen_a0e294de90cf7a53ef304e1d9735fc666}{fileopen} (unit, file, mode, err)
\end{DoxyCompactItemize}


\subsection{Detailed Description}


Definition at line 94 of file dc\+\_\+iounit.\+f90.



\subsection{Constructor \& Destructor Documentation}
\mbox{\Hypertarget{interfacedc__iounit_1_1fileopen_a0e294de90cf7a53ef304e1d9735fc666}\label{interfacedc__iounit_1_1fileopen_a0e294de90cf7a53ef304e1d9735fc666}} 
\index{dc\+\_\+iounit\+::fileopen@{dc\+\_\+iounit\+::fileopen}!fileopen@{fileopen}}
\index{fileopen@{fileopen}!dc\+\_\+iounit\+::fileopen@{dc\+\_\+iounit\+::fileopen}}
\subsubsection{\texorpdfstring{fileopen()}{fileopen()}}
{\footnotesize\ttfamily subroutine dc\+\_\+iounit\+::fileopen\+::fileopen (\begin{DoxyParamCaption}\item[{integer, intent(out)}]{unit,  }\item[{character($\ast$), intent(in)}]{file,  }\item[{character($\ast$), intent(in), optional}]{mode,  }\item[{logical, intent(out), optional}]{err }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Definition at line 103 of file dc\+\_\+iounit.\+f90.


\begin{DoxyCode}
103     \textcolor{comment}{!}
104     \textcolor{comment}{! ファイル名を *file* へ, オープンする際のモードを *mode* へと}
105     \textcolor{comment}{! 与えることで, ファイルをオープンし, 装置番号を *unit* に返します. }
106     \textcolor{comment}{! *mode* には以下の文字列を指定します. 省略時は "r" が指定されたもの}
107     \textcolor{comment}{! とみなします. }
108     \textcolor{comment}{!}
109     \textcolor{comment}{! "r"  :: ファイルを読み込みモードでオープンします.}
110     \textcolor{comment}{! "w"  :: ファイルを書き込みモードでオープンします. }
111     \textcolor{comment}{!         オープン時にファイルがすでに存在していればその内容を空にします.}
112     \textcolor{comment}{! "a"  :: ファイルを書き込みモードでオープンします. }
113     \textcolor{comment}{!         出力はファイルの末尾に追加されます.}
114     \textcolor{comment}{! "rw" :: ファイルを読み書き両用モードでオープンします. }
115     \textcolor{comment}{!         オープン時にファイルがすでに}
116     \textcolor{comment}{!         存在していればその内容を空にします.}
117     \textcolor{comment}{! "ra" :: ファイルを読み書き両用モードでオープンします. }
118     \textcolor{comment}{!         オープン時にファイルがすでに}
119     \textcolor{comment}{!         存在していれば読み書き位置がファイルの末尾にセットされます.}
120     \textcolor{comment}{!}
121     \textcolor{comment}{! ファイルが *mode* で指定されるモードで開けない場合, プログラムは}
122     \textcolor{comment}{! 強制終了します. 引数 *err* が与えられる場合, プログラムは強制終了せず, }
123     \textcolor{comment}{! 代わりに *err* に .true. が, *unit* に -1 が代入されます. }
124     \textcolor{comment}{!}
125     \textcolor{comment}{! Filename is given to *file*, and open mode is given to *mode*, }
126     \textcolor{comment}{! then the file is opened and unit number is returned.}
127     \textcolor{comment}{!}
128     \textcolor{comment}{! "r"  :: A file is opened with read-only mode}
129     \textcolor{comment}{! "w"  :: A file is opened with writable mode. }
130     \textcolor{comment}{!         If a file is exist already, the contest of the file is emptied.}
131     \textcolor{comment}{! "a"  :: A file is opened with writable mode.}
132     \textcolor{comment}{!         Output is appended at the end of the file.}
133     \textcolor{comment}{! "rw" :: A file is opened with read/write mode. }
134     \textcolor{comment}{!         If a file is exist already, the contest of the file is emptied. }
135     \textcolor{comment}{! "ra" :: A file is opened with read/write mode. }
136     \textcolor{comment}{!         If a file is exist already, }
137     \textcolor{comment}{!         a position of read/write is set at the end of the file.}
138     \textcolor{comment}{!}
139     \textcolor{comment}{! If the file can not be opened with the mode, the program aborts. }
140     \textcolor{comment}{! If this *err* argument is given, .true. is substituted to *err* and}
141     \textcolor{comment}{! -1 is substituted to *unit* and the program does not abort. }
142     \textcolor{comment}{!}
143     \textcolor{keywordtype}{use }\hyperlink{namespacedc__types}{dc\_types}\textcolor{keywordtype}{, only}: \hyperlink{namespacedc__types_adb76910ff05e3b9fe3436567f8f8dac6}{string}, \hyperlink{namespacedc__types_a6d28eb015ba84292a06f4ff25165b376}{token}
144     \textcolor{keywordtype}{use }\hyperlink{namespacedc__trace}{dc\_trace}\textcolor{keywordtype}{, only}: \hyperlink{namespacedc__trace_aca1efe8bae50b85f74980a8c4d704dd8}{beginsub}, \hyperlink{namespacedc__trace_ae44de97565a3bdd685789c7748b37e37}{endsub}
145     \textcolor{keywordtype}{use }\hyperlink{namespacedc__error}{dc\_error}\textcolor{keywordtype}{, only}: \hyperlink{namespacedc__error_a0104aee83ee5752b1a9f6152b11864a8}{storeerror}, \hyperlink{namespacedc__error_a64841a3c9e3ef7d5ddb175e5770f7dfe}{dc\_noerr}, &
146       & \hyperlink{namespacedc__error_aba5ad002b8647cc3f9846318d7200d52}{dc\_efilenameempty}, \hyperlink{namespacedc__error_a3e04908c009f08231076115a0776a1c6}{dc\_ebadfileopmode}, 
      \hyperlink{namespacedc__error_addf5e9b6a4ca81b6468763737679c0ef}{dc\_enounitnum}, &
147       & \hyperlink{namespacedc__error_ad5fd58b718dd9a9900d34510366870f1}{dc\_enofileexist}, \hyperlink{namespacedc__error_a8cf0aeb5a137428023c346d553ddec34}{dc\_enofileread}, 
      \hyperlink{namespacedc__error_ad3d25c404e7b8f58f34ea81674554f00}{dc\_enofilewrite}
148     \textcolor{keywordtype}{use }\hyperlink{namespacedc__present}{dc\_present}\textcolor{keywordtype}{, only}: \hyperlink{namespacedc__present_aae281a56bc41e9546908a72aeb042430}{present\_and\_not\_empty}
149     \textcolor{keywordtype}{use }\hyperlink{namespacedc__string}{dc\_string}\textcolor{keywordtype}{, only}: \hyperlink{interfacedc__string_1_1tochar}{tochar}, \hyperlink{interfacedc__string_1_1tolower}{tolower}
150     \textcolor{keywordtype}{implicit none}
151     \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(out)}:: unit
152     \textcolor{keywordtype}{character(*)}, \textcolor{keywordtype}{intent(in)}:: file
153     \textcolor{keywordtype}{character(*)}, \textcolor{keywordtype}{intent(in)}, \textcolor{keywordtype}{optional}:: mode
154     \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(out)}, \textcolor{keywordtype}{optional}:: err
155 
156     \textcolor{comment}{!-----------------------------------}
157     \textcolor{comment}{!  作業変数}
158     \textcolor{comment}{!  Work variables}
159     \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter}:: max\_unit = 99
160                               \textcolor{comment}{! NAMELIST ファイルをオープンするための}
161                               \textcolor{comment}{! 装置番号の最大値. Fortran で使用可能な}
162                               \textcolor{comment}{! 範囲 (0〜99) のうち, }
163                               \textcolor{comment}{! 最大値が設定されている.}
164                               \textcolor{comment}{! }
165                               \textcolor{comment}{! Maximum unit number for open of}
166                               \textcolor{comment}{! NAMELIST file. An maximum}
167                               \textcolor{comment}{! value within the bounds of available number}
168                               \textcolor{comment}{! in Fortran (0 - 99) is specified.}
169     \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter}:: min\_unit = 0
170                               \textcolor{comment}{! NAMELIST ファイルをオープンするための}
171                               \textcolor{comment}{! 装置番号の最小値. Fortran で使用可能な}
172                               \textcolor{comment}{! 範囲 (0〜99) のうち, }
173                               \textcolor{comment}{! 最小値が設定されている.}
174                               \textcolor{comment}{! }
175                               \textcolor{comment}{! Minimum unit number for open of}
176                               \textcolor{comment}{! NAMELIST file. An minimum}
177                               \textcolor{comment}{! value within the bounds of available number}
178                               \textcolor{comment}{! in Fortran (0 - 99) is specified.}
179     \textcolor{keywordtype}{character(TOKEN)}:: open\_mode
180     \textcolor{keywordtype}{integer}:: unit\_work
181     \textcolor{keywordtype}{logical}:: unit\_exist\_flag, unit\_opend\_flag
182     \textcolor{keywordtype}{logical}:: file\_exist\_flag
183     \textcolor{keywordtype}{integer}:: iostat
184     \textcolor{keywordtype}{integer}:: stat
185     \textcolor{keywordtype}{character(STRING)}:: cause\_c
186     \textcolor{keywordtype}{character(*)}, \textcolor{keywordtype}{parameter}:: subname = \textcolor{stringliteral}{'FileOpen'}
187   \textcolor{keywordflow}{continue}
188     \textcolor{keyword}{call }\hyperlink{namespacedc__trace_aca1efe8bae50b85f74980a8c4d704dd8}{beginsub}(subname, version)
189     stat = \hyperlink{namespacedc__error_a64841a3c9e3ef7d5ddb175e5770f7dfe}{dc\_noerr}
190     cause\_c = \textcolor{stringliteral}{''}
191     unit = -1
192 
193     \textcolor{comment}{!-----------------------------------------------------------------}
194     \textcolor{comment}{!  オプショナル引数のチェック}
195     \textcolor{comment}{!  Check optional arguments}
196     \textcolor{comment}{!-----------------------------------------------------------------}
197     \textcolor{keywordflow}{if} (\hyperlink{namespacedc__present_aae281a56bc41e9546908a72aeb042430}{present\_and\_not\_empty}(mode)) \textcolor{keywordflow}{then}
198       open\_mode = mode
199     \textcolor{keywordflow}{else}
200       open\_mode = \textcolor{stringliteral}{'r'}
201 \textcolor{keywordflow}{    end if}
202     \textcolor{keyword}{call }\hyperlink{interfacedc__string_1_1tolower}{tolower}(open\_mode)
203 
204     \textcolor{comment}{!-----------------------------------------------------------------}
205     \textcolor{comment}{!  引数の正当性のチェック}
206     \textcolor{comment}{!  Validation of arguments}
207     \textcolor{comment}{!-----------------------------------------------------------------}
208     \textcolor{keywordflow}{if} ( trim(file) == \textcolor{stringliteral}{''} ) \textcolor{keywordflow}{then}
209       stat = \hyperlink{namespacedc__error_aba5ad002b8647cc3f9846318d7200d52}{dc\_efilenameempty}
210       \textcolor{keywordflow}{goto} 999
211 \textcolor{keywordflow}{    end if}
212 
213     \textcolor{comment}{!----------------------------------------------------------------}
214     \textcolor{comment}{!  使用可能な装置番号の探査}
215     \textcolor{comment}{!  Search available unit number}
216     \textcolor{comment}{!----------------------------------------------------------------}
217     unit\_work = max\_unit
218     \textcolor{keywordflow}{do}
219       \textcolor{keyword}{inquire}(unit=unit\_work, exist=unit\_exist\_flag, opened=unit\_opend\_flag)
220       \textcolor{keywordflow}{if} (unit\_exist\_flag .and. .not. unit\_opend\_flag) \textcolor{keywordflow}{then}
221         \textcolor{keywordflow}{exit}
222 \textcolor{keywordflow}{      endif}
223       unit\_work = unit\_work - 1
224       \textcolor{keywordflow}{if} (unit\_work < min\_unit) \textcolor{keywordflow}{then}
225         cause\_c = \hyperlink{interfacedc__string_1_1tochar}{tochar}(min\_unit) // \textcolor{stringliteral}{' - '} // \hyperlink{interfacedc__string_1_1tochar}{tochar}(max\_unit)
226         stat = \hyperlink{namespacedc__error_addf5e9b6a4ca81b6468763737679c0ef}{dc\_enounitnum}
227         \textcolor{keywordflow}{goto} 999
228 \textcolor{keywordflow}{      end if}
229 \textcolor{keywordflow}{    enddo}
230 
231     \textcolor{comment}{!----------------------------------------------------------------}
232     \textcolor{comment}{!  モードの書式のチェック}
233     \textcolor{comment}{!  Check form of mode}
234     \textcolor{comment}{!----------------------------------------------------------------}
235     \textcolor{keywordflow}{select case}( trim(open\_mode) )
236     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'r'}, \textcolor{stringliteral}{'w'}, \textcolor{stringliteral}{'rw'}, \textcolor{stringliteral}{'a'}, \textcolor{stringliteral}{'ra'})
237 \textcolor{keywordflow}{    case default}
238       cause\_c = open\_mode
239       stat = \hyperlink{namespacedc__error_a3e04908c009f08231076115a0776a1c6}{dc\_ebadfileopmode}
240       \textcolor{keywordflow}{goto} 999
241 \textcolor{keywordflow}{    end select}
242 
243     \textcolor{comment}{!----------------------------------------------------------------}
244     \textcolor{comment}{!  ファイルの存在のチェック}
245     \textcolor{comment}{!  Check existance of a file}
246     \textcolor{comment}{!----------------------------------------------------------------}
247     \textcolor{keywordflow}{select case}( trim(open\_mode) )
248     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'r'})
249       \textcolor{keyword}{inquire}(file=file, exist=file\_exist\_flag)
250       \textcolor{keywordflow}{if} (.not. file\_exist\_flag) \textcolor{keywordflow}{then}
251         cause\_c = file
252         stat = \hyperlink{namespacedc__error_ad5fd58b718dd9a9900d34510366870f1}{dc\_enofileexist}
253         \textcolor{keywordflow}{goto} 999
254 \textcolor{keywordflow}{      end if}
255 \textcolor{keywordflow}{    end select}
256 
257     \textcolor{comment}{!----------------------------------------------------------------}
258     \textcolor{comment}{!  ファイルの読み込み可能のチェック}
259     \textcolor{comment}{!  Check readable of a file}
260     \textcolor{comment}{!----------------------------------------------------------------}
261     \textcolor{keywordflow}{select case}( trim(open\_mode) )
262     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'r'})
263       \textcolor{keyword}{open}(unit=unit\_work, iostat=iostat, &
264         & file=file, status=\textcolor{stringliteral}{'OLD'}, action=\textcolor{stringliteral}{'READ'})
265       \textcolor{keywordflow}{if} (.not. iostat == 0) \textcolor{keywordflow}{then}
266         cause\_c = file
267         stat = \hyperlink{namespacedc__error_a8cf0aeb5a137428023c346d553ddec34}{dc\_enofileread}
268         \textcolor{keywordflow}{goto} 999
269 \textcolor{keywordflow}{      end if}
270       \textcolor{keyword}{close}(unit=unit\_work)
271 \textcolor{keywordflow}{    end select}
272 
273     \textcolor{comment}{!----------------------------------------------------------------}
274     \textcolor{comment}{!  ファイルの書き込み可能のチェック}
275     \textcolor{comment}{!  Check writable of a file}
276     \textcolor{comment}{!----------------------------------------------------------------}
277     \textcolor{keywordflow}{select case}( trim(open\_mode) )
278     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'w'}, \textcolor{stringliteral}{'a'}, \textcolor{stringliteral}{'rw'}, \textcolor{stringliteral}{'ra'})
279       \textcolor{keyword}{open}(unit=unit\_work, iostat=iostat, &
280         & file=file, status=\textcolor{stringliteral}{'UNKNOWN'}, action=\textcolor{stringliteral}{'WRITE'})
281       \textcolor{keywordflow}{if} (.not. iostat == 0) \textcolor{keywordflow}{then}
282         cause\_c = file
283         stat = \hyperlink{namespacedc__error_ad3d25c404e7b8f58f34ea81674554f00}{dc\_enofilewrite}
284         \textcolor{keywordflow}{goto} 999
285 \textcolor{keywordflow}{      end if}
286       \textcolor{keyword}{close}(unit=unit\_work)
287 \textcolor{keywordflow}{    end select}
288 
289     \textcolor{comment}{!----------------------------------------------------------------}
290     \textcolor{comment}{!  ファイルオープン}
291     \textcolor{comment}{!  Open a file}
292     \textcolor{comment}{!----------------------------------------------------------------}
293     \textcolor{keywordflow}{select case}( trim(open\_mode) )
294     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'r'})
295       \textcolor{keyword}{open}(unit=unit\_work, file=file, &
296         & status=\textcolor{stringliteral}{'OLD'}, action=\textcolor{stringliteral}{'READ'})
297 
298     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'w'})
299       \textcolor{keyword}{open}(unit=unit\_work, file=file, &
300         & status=\textcolor{stringliteral}{'REPLACE'}, action=\textcolor{stringliteral}{'WRITE'})
301 
302     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'rw'})
303       \textcolor{keyword}{open}(unit=unit\_work, file=file, &
304         & status=\textcolor{stringliteral}{'REPLACE'}, action=\textcolor{stringliteral}{'READWRITE'})
305 
306     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'a'})
307       \textcolor{keyword}{open}(unit=unit\_work, file=file, &
308         & status=\textcolor{stringliteral}{'UNKNOWN'}, position=\textcolor{stringliteral}{'APPEND'}, action=\textcolor{stringliteral}{'WRITE'})
309 
310     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'ra'})
311       \textcolor{keyword}{open}(unit=unit\_work, file=file, &
312         & status=\textcolor{stringliteral}{'UNKNOWN'}, position=\textcolor{stringliteral}{'APPEND'}, action=\textcolor{stringliteral}{'READWRITE'})
313 
314 \textcolor{keywordflow}{    end select}
315 
316     unit = unit\_work
317 
318 999 \textcolor{keywordflow}{continue}
319     \textcolor{keyword}{call }\hyperlink{namespacedc__error_a0104aee83ee5752b1a9f6152b11864a8}{storeerror}(stat, subname, err, cause\_c)
320     \textcolor{keyword}{call }\hyperlink{namespacedc__trace_ae44de97565a3bdd685789c7748b37e37}{endsub}(subname)
\end{DoxyCode}


The documentation for this interface was generated from the following file\+:\begin{DoxyCompactItemize}
\item 
dc\+\_\+utils/\hyperlink{dc__iounit_8f90}{dc\+\_\+iounit.\+f90}\end{DoxyCompactItemize}
