-
Notifications
You must be signed in to change notification settings - Fork 1
/
input.f90
102 lines (67 loc) · 2.81 KB
/
input.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
! read set sizes from input
subroutine getSetSizes ( nnode, ncell, nedge, nbedge )
implicit none
integer(4), parameter :: MAX_PWD_LEN = 255
! formal parameters
integer(4), intent (out) :: nnode, ncell, nedge, nbedge
! file identifier (10 is arbitrary)
integer(4), parameter :: FILE_ID = 10
character(len=MAX_PWD_LEN) :: currDir
!call get_environment_variable ( "WORK", currDir )
call get_environment_variable ( "PWD", currDir )
currDir = 'new_grid.dat'
! open file
open ( FILE_ID, file = currDir )
! first line includes number of cells, nodes, edges and bedges
read ( FILE_ID, "(1x,I6,1x,I6,1x,I7,1x,I4)" ) nnode, ncell, nedge, nbedge
! not closing file because it will be used below
end subroutine getSetSizes
! fill up arrays from file
subroutine getSetInfo ( nnode, ncell, nedge, nbedge, cell, edge, ecell, bedge, becell, bound, x, q, qold, res, adt )
implicit none
! formal parameters
integer(4), intent (in) :: nnode, ncell, nedge, nbedge
integer(4), dimension( 4 * ncell ) :: cell
integer(4), dimension( 2 * nedge ) :: edge
integer(4), dimension( 2 * nedge ) :: ecell
integer(4), dimension( 2 * nbedge ) :: bedge
integer(4), dimension( nbedge ) :: becell
integer(4), dimension( nbedge ) :: bound
real(8), dimension( 2 * nnode ) :: x
real(8), dimension( 4 * ncell ) :: q
real(8), dimension( 4 * ncell ) :: qold
real(8), dimension( 4 * ncell ) :: res
real(8), dimension( ncell ) :: adt
! file identifier (10 is arbitrary)
integer(4), parameter :: FILE_ID = 10
integer(4) :: i, f_array
! the file is already open and the pointer in file is already at the correct position
do i = 1, nnode
read ( FILE_ID, * ) x( (2*i) - 1 ), x( 2*i )
end do
do i = 1, ncell
read ( FILE_ID, * ) cell(4 * i - 3), cell(4 * i + 1 - 3), cell(4 * i + 2 - 3), cell(4 * i + 3 - 3 )
! pointers are expressed for C arrays (from 0 to N-1), for Fortran we have to convert them in sets from 1 to N
cell(4 * i - 3) = cell(4 * i - 3) + 1
cell(4 * i + 1 - 3) = cell(4 * i + 1 - 3) + 1
cell(4 * i + 2 - 3) = cell(4 * i + 2 - 3) + 1
cell(4 * i + 3 - 3 ) = cell(4 * i + 3 - 3 ) + 1
enddo
do i = 1, nedge
read ( FILE_ID, * ) edge(2 * i - 1), edge(2 * i + 1 - 1), ecell(2 * i - 1), ecell(2 * i + 1 - 1)
! see above
edge(2 * i - 1) = edge(2 * i - 1) + 1
edge(2 * i + 1 - 1) = edge(2 * i + 1 - 1) + 1
ecell(2 * i - 1) = ecell(2 * i - 1) + 1
ecell(2 * i + 1 - 1) = ecell(2 * i + 1 - 1) + 1
enddo
do i = 1, nbedge
read ( FILE_ID, * ) bedge(2 * i - 1), bedge(2 * i + 1 - 1), becell(i), bound(i)
! see above
bedge(2 * i - 1) = bedge(2 * i - 1) + 1
bedge(2 * i + 1 - 1) = bedge(2 * i + 1 - 1) + 1
becell(i) = becell(i) + 1
enddo
! close file
close ( FILE_ID )
end subroutine getSetInfo