Skip to content

Commit ff80d01

Browse files
committed
Fix file%close and update file routines/docs.
1 parent 056ebc6 commit ff80d01

File tree

9 files changed

+280
-113
lines changed

9 files changed

+280
-113
lines changed

API-doc-FORD-file.md

+5-12
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ exclude: forlab_.f95
66
output_dir: API-doc
77
page_dir: doc/
88
media_dir: doc/media
9-
fpp_extensions: fypp
10-
preprocess: true
11-
macro: MAXRANK=3
12-
preprocessor: fypp
139
display: public
1410
protected
1511
source: true
@@ -24,23 +20,20 @@ extra_mods: iso_fortran_env:https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fFORT
2420
iso_c_binding:https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fC_005fBINDING.html#ISO_005fC_005fBINDING
2521
print_creation_date: true
2622
creation_date: %Y-%m-%d %H:%M %z
27-
project_github: https://github.com/zoziha/forlab
28-
project_download: https://github.com/zoziha/forlab
23+
project_github: https://github.com/fortran-fans/forlab
24+
project_download: https://github.com/fortran-fans/forlab
2925
favicon: doc/media/favicon.png
3026
license: by-sa
3127
author: forlab v1.0 contributors
32-
author_pic: null
3328
author_email: [email protected]
34-
github: https://github.com/zoziha/forlab
35-
twitter: null
36-
website: https://github.com/zoziha/forlab
29+
github: https://github.com/fortran-fans
3730
dbg: true
3831
parallel: 4
3932
---
4033

4134
[TOC]
4235

43-
@warning This API documentation for the zoziha/forlab v1.0 is a work in progress
36+
@warning This API documentation for the fortran-fans/forlab v1.0 is a work in progress
4437

4538
@note
4639
Use the navigation bar at the top of the screen to browse modules, procedures, source files, etc.
@@ -54,7 +47,7 @@ The documentation for comment markup in source code, running [FORD] and the [FOR
5447

5548
[FORD]: https://github.com/Fortran-FOSS-Programmers/ford#readme
5649
[FORD wiki]: https://github.com/Fortran-FOSS-Programmers/ford/wiki
57-
[FORD project file]: https://github.com/fortran-lang/stdlib/blob/master/API-doc-FORD-file.md
50+
[FORD project file]: https://github.com/fortran-fans/forlab/blob/master/API-doc-FORD-file.md
5851

5952
Goals and Motivation
6053
====================

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Fortran forlab Makefile
1+
# Fortran forlab Makefile, only for developement.
22
FYPPFLAGS=
33

44
export FYPPFLAGS

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ Forlab uses [stdlib](https://github.com/fortran-lang/stdlib) as an upstream pack
77
|:-:|---|
88
| **Version:** | 1.0.1 |
99
| **Author:** | Forlab Contributors |
10-
| **Web site:** | https://github.com/zoziha/forlab |
10+
| **Web site:** | https://github.com/fortran-fans/forlab |
1111
| **API-Doc Web site:** | https://zoziha.github.io/forlab-API-doc/ |
1212
| **Copyright:** | _This document_ has been placed in the public domain. |
1313
| **License:** | _Forlab_ is released under the MIT License. |
1414

1515
## Getting Started
1616
### Get the code
1717
```bash
18-
git clone https://github.com/zoziha/forlab.git
18+
git clone https://github.com/fortran-fans/forlab.git
1919
cd forlab
2020
```
2121
### Supported Compilers
@@ -27,7 +27,7 @@ The following combinations are tested on the default branch of `forlab`:
2727
To use `forlab` within your fpm project, add the following to `fpm.toml` file:
2828
```toml
2929
[dependencies]
30-
forlab = { git = "https://github.com/zoziha/forlab.git" }
30+
forlab = { git = "https://github.com/fortran-fans/forlab.git" }
3131
```
3232
You can build using provided `fpm.toml`:
3333
```bash
@@ -38,7 +38,6 @@ fpm test
3838
```bash
3939
ford API-doc-FORD-file.md # todo
4040
```
41-
[forlab-API-doc](https://zoziha.github.io/forlab-API-doc/) is alse in here.
4241

4342
---
4443
## More informations

doc/specs/forlab_io.md

+210-20
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,33 @@ title: IO
66

77
[TOC]
88

9-
## `file` - File Constructor and File Derived Type
9+
### `file` - File Constructor and File Derived Type
1010

11-
### Status
11+
#### Status
1212

1313
Experimental
1414

15-
### Description
15+
#### Class
16+
17+
Impure function.
18+
19+
#### Description
20+
1621
`file` function constructs a file entity of `file` type, including some file operation methods.
1722

18-
### Syntax
23+
#### Syntax
1924

2025
`ofile = [[forlab_io(module):file(interface)]](filename [, mode])`
2126

22-
### Arguments
27+
#### Arguments
2328

24-
`filename`: Shall be a character expression containing the file name.
29+
`filename`: Shall be a `character(len=*)` scalar.
30+
This argument is `intent(in)`.
31+
Contains the file name.
2532

26-
`mode` (optional): Shall be a character expression containing characters describing the way in which the file will be used. The available modes are:
33+
`mode`: Shall be a `character(len=*)` scalar.
34+
This argument is `intent(in)` and `optional`.
35+
Contains characters describing the way in which the file will be used (see [stdlib_io:open](https://stdlib.fortran-lang.org/page/specs/stdlib_io.html#description_1)). The available modes are:
2736

2837
| Character | Meaning |
2938
| --------- | ------- |
@@ -38,40 +47,221 @@ Experimental
3847

3948
The default `mode` is `'rt'` (i.e. construct a file for reading a text file). The `mode` may include one of the four different methods for opening a file (i.e., `'r'`, `'w'`, `'x'`, and `'a'`). These four methods can be associated with the character `'+'` to open the file for updating. In addition, it can be specified if the file should be handled as a binary file (`'b'`) or a text file (`'t'`).
4049

41-
`ofile`: a file entity of `file` type.
42-
43-
### Return value
50+
#### Return value
4451

4552
Returns a file entity of `file` type, in which the following are defined:
4653

4754
```fortran
4855
type file
49-
integer :: unit
5056
character(:), allocatable :: filename
5157
character(3) :: mode
58+
integer :: unit
5259
integer :: lines
5360
contains
54-
procedure :: exist => file_exist1
55-
procedure :: open => open_file
56-
procedure :: countlines => countlines1
61+
procedure :: exist
62+
procedure :: open
63+
procedure :: countlines
5764
procedure :: close
5865
end type file
5966
```
6067

61-
### Example
68+
#### Examples
6269

6370
```fortran
64-
program test_io_file
71+
program demo_io_file_1
6572
use forlab_io, only: file, disp
66-
use stdlib_error, only: error_stop
73+
use stdlib_error, only: check
6774
type(file) :: infile
6875
6976
infile = file('DP.txt', 'r')
70-
if(.not.infile%exist()) call error_stop('Error: File not exist, '//infile%filename)
77+
call check(infile%exist(), msg="File not exist, "//infile%filename)
78+
call infile%open()
79+
call infile%countlines()
80+
call disp(infile%lines, 'Linenumber in file is: ')
81+
call infile%close() !! `infile` is closed, `infile%filename` is deallocated.
82+
83+
end program demo_io_file_1
84+
```
85+
86+
```fortran
87+
program demo_io_file_2
88+
use forlab_io, only: file, disp
89+
use stdlib_error, only: check
90+
type(file), allocatable :: infile
91+
92+
!! To create a `file` type scalar to read:
93+
!!
94+
!!```fortran
95+
!! infile = file("somefile.txt") ! The default `mode` is "rt"
96+
!! infile = file("somefile.txt", "r")
97+
!!```
98+
!!
99+
!! To create a `file` type scalar to write:
100+
!! infile = file("somefile.txt", "w")
101+
!!
102+
!! To append to the end of the file if it exists:
103+
!!
104+
!! infile = file("somefile.txt", "a")
105+
106+
infile = file('DP.txt', 'r')
107+
call check(infile%exist(), msg="File not exist, "//infile%filename)
71108
call infile%open()
72109
call infile%countlines()
73110
call disp(infile%lines, 'Linenumber in file is: ')
74-
call infile%close()
111+
call infile%close() !! It is optional. `infile` is closed, `infile%filename` is deallocated.
112+
deallocate(infile) !! `infile` is deallocated.
113+
114+
end program demo_io_file_2
115+
```
116+
117+
### `file%exist`
118+
119+
#### Description
120+
121+
Checks the `file` is exist or not.
122+
123+
#### Status
124+
125+
Experimental.
126+
127+
#### Class
128+
129+
Impure function.
130+
131+
#### Syntax
132+
133+
`result = self % [[file(type):exist(bound)]]()`
134+
135+
#### Arguments
136+
137+
None.
138+
139+
#### Return value
140+
141+
Returns a `logical` scalar: the file exists as `.true.`, the file does not exist as `.false.`.
142+
143+
#### Example
144+
145+
```fortran
146+
program demo_io_file_exist
147+
use forlab_io, only: file
148+
use stdlib_error, only: check
149+
type(file), allocatable :: infile
150+
151+
infile = file("filename.txt", "r")
152+
call check(infile%exist(), msg="File not exist: "//infile%filename)
153+
deallocate(infile)
154+
155+
end program demo_io_file_exist
156+
```
157+
158+
### `file%open`
159+
160+
#### Description
161+
162+
Open the `file` object.
163+
164+
#### Status
165+
166+
Experimental.
167+
168+
#### Class
169+
170+
Impure function.
171+
172+
#### Syntax
173+
174+
`call self % [[file(type):open(bound)]]()`
175+
176+
#### Arguments
177+
178+
None.
179+
180+
#### Example
181+
182+
```fortran
183+
program demo_io_file_open
184+
use forlab_io, only: file
185+
use stdlib_error, only: check
186+
type(file), allocatable :: infile
187+
188+
infile = file("filename.txt", "r")
189+
call check(infile%exist(), msg="File not exist: "//infile%filename)
190+
call infile%open() !! Open file operation
191+
deallocate(infile)
192+
193+
end program demo_io_file_open
194+
```
195+
196+
### `file%countlines`
197+
198+
#### Description
199+
200+
Counts the number of lines in a txt file, the number of file lines is stored in `file%lines`.
201+
202+
#### Status
203+
204+
Experimental.
205+
206+
#### Class
207+
208+
Impure function.
209+
210+
#### Syntax
211+
212+
`call self % [[file(type):countlines(bound)]]()`
213+
214+
#### Arguments
215+
216+
None.
217+
218+
#### Example
219+
220+
```fortran
221+
program demo_io_file_countlines
222+
use forlab_io, only: file, disp
223+
type(file), allocatable :: infile
224+
225+
infile = file("filename.txt", "r")
226+
call infile%countlines() !! Counts the number of lines in a txt file, the number of file lines is stored in `infile%lines`.
227+
call disp(infile%lines, "The number of file lines : ")
228+
deallocate(infile)
229+
230+
end program demo_io_file_countlines
231+
```
232+
233+
### `file%close`
234+
235+
#### Description
236+
237+
Closes the `file` object, deallocate `file%filename`.
238+
239+
#### Status
240+
241+
Experimental.
242+
243+
#### Class
244+
245+
Impure function.
246+
247+
#### Syntax
248+
249+
`call self % [[file(type):close(bound)]]()`
250+
251+
#### Arguments
252+
253+
None.
254+
255+
#### Example
256+
257+
```fortran
258+
program demo_io_file_close
259+
use forlab_io, only: file, disp
260+
type(file) :: infile
261+
262+
infile = file("filename.txt", "r")
263+
call infile%open()
264+
call infile%close() !! Closes the `infile` object, deallocate `infile%filename`.
75265
76-
end program test_io_file
266+
end program demo_io_file_close
77267
```

fpm.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "forlab"
22
version = "1.0.1"
33
license = "MIT"
44
author = "forlab contributors"
5-
maintainer = "https://github.com/zoziha/forlab"
5+
maintainer = "https://github.com/fortran-fans/forlab"
66
copyright = "2016-2021 forlab contributors"
77
description = "A Fortran module that provides a lot of functions for scientific computing"
88
categories = ["numerical"]

meta-src/Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ $(SRCGEN): %.f90: %.fypp common.fypp
2626
fypp $(FYPPFLAGS) $< $(FPMSRCDIR)/$@
2727

2828
# COPY F90 files to `fpm/`
29-
CPF90: $(SRCF90)
30-
@mkdir -p $(FPMSRCDIR)
31-
cp -u $^ $(FPMSRCDIR)
29+
# CPF90: $(SRCF90)
30+
# @mkdir -p $(FPMSRCDIR)
31+
# cp -u $^ $(FPMSRCDIR)
3232

33-
# COPY canag files to `fpm/`
33+
# COPY clang files to `fpm/`
3434
CPC: $(SRCC)
3535
@mkdir -p $(FPMSRCDIR)
3636
cp -u $^ $(FPMSRCDIR)

0 commit comments

Comments
 (0)