Reading calculation grid¶
Reads a calculation grid from the CGNS file. iRIClib offers subroutines for reading structured grids only.
Subroutine |
Remarks |
---|---|
cg_iric_read_grid2d_str_size |
Reads size of 2D structured grid |
cg_iric_read_grid2d_coords |
Reads a 2D structured grid |
cg_iric_read_grid_integer_node |
Reads the integer attribute values defined for grid nodes |
cg_iric_read_grid_real_node |
Reads the double-precision attribute values defined for grid nodes |
cg_iric_read_grid_integer_cell |
Reads the integer attribute values defined for cells |
cg_iric_read_grid_real_cell |
Reads the double-precision attribute values defined for cells |
cg_iric_read_complex_count |
Reads the number of groups of complex type grid attribute |
cg_iric_read_complex_integer |
Reads the integer attribute values of complex type grid attribute |
cg_iric_read_complex_real |
Reads the double precision attribute values of complex type grid attribute |
cg_iric_read_complex_realsingle |
Reads the single precision attribute values of complex type grid attribute |
cg_iric_read_complex_string |
Reads the string attribute values of complex type grid attribute |
cg_iric_read_complex_functionalsize |
Checks the size of a f_functional-type attribute of complex type grid attribute |
cg_iric_read_complex_functional |
Reads f_functional attribute data of complex type grid attribute |
cg_iric_read_complex_functionalwithname |
Reads f_functional attribute of complex type grid attribute (with multiple values) |
cg_iric_read_complex_functional_realsingle |
Reads f_functional attribute data of complex type grid attribute |
cg_iric_read_grid_complex_node |
Reads the complex attribute values defined at grid nodes |
cg_iric_read_grid_complex_cell |
Reads the complex attribute values defined at grid cells |
cg_iric_read_grid_functionaltimesize |
Reads the number of values of dimension "Time" for f_functional grid attribute |
cg_iric_read_grid_functionaltime |
Reads the values of dimension "Time" for f_functional grid attribute |
cg_iric_read_grid_functionaldimensionsize |
Reads the number of values of dimension for f_functional grid attribute |
cg_iric_read_grid_functionaldimension_integer |
Reads the values of integer dimension for f_functional grid attribute |
cg_iric_read_grid_functionaldimension_real |
Reads the values of double-precision dimension for f_functional grid attribute |
cg_iric_read_grid_functional_integer_node |
Reads the values of f_functional integer grid attribute with dimension "Time" definied at grid nodes. |
cg_iric_read_grid_functional_real_node |
Reads the values of f_functional double-precision grid attribute with dimension "Time" definied at grid nodes. |
cg_iric_read_grid_functional_integer_cell |
Reads the values of f_functional integer grid attribute with dimension "Time" definied at grid cells. |
cg_iric_read_grid_functional_real_cell |
Reads the values of f_functional double-precision grid attribute with dimension "Time" definied at grid cells. |
The same subroutines for getting attributes such as cg_iric_read_grid_integer_node can be used both for two-dimensional structured grids and three-dimensional structured grids.
An example description for reading a two-dimensional structured grid is shown in List 162.
1program Sample3
2 use iric
3 implicit none
4
5 integer:: fin, ier, discharge_size, i, j
6 integer:: isize, jsize
7 double precision, dimension(:,:), allocatable:: grid_x, grid_y
8 double precision, dimension(:,:), allocatable:: elevation
9 integer, dimension(:,:), allocatable:: obstacle
10 integer:: rain_timeid
11 integer:: rain_timesize
12 double precision, dimension(:), allocatable:: rain_time
13 double precision, dimension(:,:), allocatable:: rain
14
15 ! Open CGNS file
16 call cg_iric_open('test.cgn', IRIC_MODE_MODIFY, fin, ier)
17 if (ier /=0) STOP "*** Open error of CGNS file ***"
18
19 ! Check the grid size
20 call cg_iric_read_grid2d_str_size(fin, isize, jsize, ier)
21
22 ! Allocate memory for loading the grid
23 allocate(grid_x(isize,jsize), grid_y(isize,jsize))
24 ! Read the grid into memory
25 call cg_iric_read_grid2d_coords(fin, grid_x, grid_y, ier)
26
27 if (ier /=0) STOP "*** No grid data ***"
28 ! (Output)
29 print *, 'grid x,y: isize, jsize=', isize, jsize
30 do i = 1, min(isize,5)
31 do j = 1, min(jsize,5)
32 print *, ' (',i,',',j,')=(',grid_x(i,j),',',grid_y(i,j),')'
33 end do
34 end do
35
36 ! Allocate memory for elevation attribute values that are defined for grid nodes.
37 allocate(elevation(isize, jsize))
38 ! Read the attribute values.
39 call cg_iric_read_grid_real_node(fin, 'Elevation', elevation, ier)
40 print *, 'Elevation: isize, jsize=', isize, jsize
41 do i = 1, min(isize,5)
42 do j = 1, min(jsize,5)
43 print *, ' (',i,',',j,')=(',elevation(i,j),')'
44 end do
45 end do
46
47 ! Allocate memory for the obstacle attribute that is defined for cells. The size is (isize-1) * (jsize-1) since it is cell attribute.
48 allocate(obstacle(isize-1, jsize-1))
49 ! Read the attribute values in.
50 call cg_iric_read_grid_integer_cell(fin, 'Obstacle', obstacle, ier)
51 print *, 'Obstacle: isize -1, jsize-1=', isize-1, jsize-1
52 do i = 1, min(isize-1,5)
53 do j = 1, min(jsize-1,5)
54 print *, ' (',i,',',j,')=(',obstacle(i,j),')'
55 end do
56 end do
57 ! Read the number of times for Rain
58 call cg_iric_read_grid_functionaltimesize(fin, 'Rain', rain_timesize);
59 ! Allocate memory for time values of Rain
60 allocate(rain_time(rain_timesize))
61
62 ! Allocate memory for the rain attribute that is defined for cells. The size is (isize-1) * (jsize-1) since it is cell attribute. allocate(rain(isize-1, jsize-1))
63 ! Read the attribute at Time = 1
64 rain_timeid = 1
65 call cg_iric_read_grid_functional_real_cell(fin, 'Rain', rain_timeid, rain, ier)
66 print *, 'Rain: isize -1, jsize-1=', isize-1, jsize-1
67 do i = 1, min(isize-1,5)
68 do j = 1, min(jsize-1,5)
69 print *, ' (',i,',',j,')=(',rain(i,j),')'
70 end do
71 end do
72
73 ! Deallocate memory that has been allocated
74 deallocate(grid_x, grid_y, elevation, obstacle, rain_time, rain)
75
76 ! Close CGNS file
77 call cg_iric_close(fin, ier)
78 stop
79end program Sample3
Processing for a three-dimensional grid can be described in the same manner.