Reading calculation grid¶
Reads a calculation grid from the CGNS file. iRIClib offers subroutines for reading structured grids only.
Subroutine |
Remarks |
|---|---|
cg_iric_gotogridcoord2d_f |
Makes preparations for reading a 2D structured grid |
cg_iric_getgridcoord2d_f |
Reads a 2D structured grid |
cg_iric_gotogridcoord3d_f |
Makes preparations for reading a 3D structured grid |
cg_iric_getgridcoord3d_f |
Reads a 3D structured grid |
cg_iric_read_grid_integer_node_f |
Reads the integer attribute values defined for grid nodes |
cg_iric_read_grid_real_node_f |
Reads the double-precision attribute values defined for grid nodes |
cg_iric_read_grid_integer_cell_f |
Reads the integer attribute values defined for cells |
cg_iric_read_grid_real_cell_f |
Reads the double-precision attribute values defined for cells |
cg_iric_read_complex_count_f |
Reads the number of groups of complex type grid attribute |
cg_iric_read_complex_integer_f |
Reads the integer attribute values of complex type grid attribute |
cg_iric_read_complex_real_f |
Reads the double precision attribute values of complex type grid attribute |
cg_iric_read_complex_realsingle_f |
Reads the single precision attribute values of complex type grid attribute |
cg_iric_read_complex_string_f |
Reads the string attribute values of complex type grid attribute |
cg_iric_read_complex_functionalsize_f |
Checks the size of a functional-type attribute of complex type grid attribute |
cg_iric_read_complex_functional_f |
Reads functional attribute data of complex type grid attribute |
cg_iric_read_complex_functionalwithname_f |
Reads functional attribute of complex type grid attribute (with multiple values) |
cg_iric_read_complex_functional_realsingle_f |
Reads functional attribute data of complex type grid attribute |
cg_iric_read_grid_complex_node_f |
Reads the complex attribute values defined at grid nodes |
cg_iric_read_grid_complex_cell_f |
Reads the complex attribute values defined at grid cells |
cg_iric_read_grid_functionaltimesize_f |
Reads the number of values of dimension "Time" for functional grid attribute |
cg_iric_read_grid_functionaltime_f |
Reads the values of dimension "Time" for functional grid attribute |
cg_iric_read_grid_functionaldimensionsize_f |
Reads the number of values of dimension for functional grid attribute |
cg_iric_read_grid_functionaldimension_integer_f |
Reads the values of integer dimension for functional grid attribute |
cg_iric_read_grid_functionaldimension_real_f |
Reads the values of double-precision dimension for functional grid attribute |
cg_iric_read_grid_functional_integer_node_f |
Reads the values of functional integer grid attribute with dimension "Time" definied at grid nodes. |
cg_iric_read_grid_functional_real_node_f |
Reads the values of functional double-precision grid attribute with dimension "Time" definied at grid nodes. |
cg_iric_read_grid_functional_integer_cell_f |
Reads the values of functional integer grid attribute with dimension "Time" definied at grid cells. |
cg_iric_read_grid_functional_real_cell_f |
Reads the values of 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_f 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 95.
1program Sample3
2 implicit none
3 include 'cgnslib_f.h'
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_open_f('test.cgn', CG_MODE_MODIFY, fin, ier)
17 if (ier /=0) STOP "*** Open error of CGNS file ***"
18
19 ! Initialize iRIClib
20 call cg_iric_init_f(fin, ier)
21 if (ier /=0) STOP "*** Initialize error of CGNS file ***"
22
23 ! Check the grid size
24 call cg_iric_gotogridcoord2d_f(isize, jsize, ier)
25
26 ! Allocate memory for loading the grid
27 allocate(grid_x(isize,jsize), grid_y(isize,jsize))
28 ! Read the grid into memory
29 call cg_iric_getgridcoord2d_f(grid_x, grid_y, ier)
30
31 if (ier /=0) STOP "*** No grid data ***"
32 ! (Output)
33 print *, 'grid x,y: isize, jsize=', isize, jsize
34 do i = 1, min(isize,5)
35 do j = 1, min(jsize,5)
36 print *, ' (',i,',',j,')=(',grid_x(i,j),',',grid_y(i,j),')'
37 end do
38 end do
39
40 ! Allocate memory for elevation attribute values that are defined for grid nodes.
41 allocate(elevation(isize, jsize))
42 ! Read the attribute values.
43 call cg_iric_read_grid_real_node_f('Elevation', elevation, ier)
44 print *, 'Elevation: isize, jsize=', isize, jsize
45 do i = 1, min(isize,5)
46 do j = 1, min(jsize,5)
47 print *, ' (',i,',',j,')=(',elevation(i,j),')'
48 end do
49 end do
50
51 ! Allocate memory for the obstacle attribute that is defined for cells. The size is (isize-1) * (jsize-1) since it is cell attribute.
52 allocate(obstacle(isize-1, jsize-1))
53 ! Read the attribute values in.
54 call cg_iric_read_grid_integer_cell_f('Obstacle', obstacle, ier)
55 print *, 'Obstacle: isize -1, jsize-1=', isize-1, jsize-1
56 do i = 1, min(isize-1,5)
57 do j = 1, min(jsize-1,5)
58 print *, ' (',i,',',j,')=(',obstacle(i,j),')'
59 end do
60 end do
61 ! Read the number of times for Rain
62 call cg_iric_read_grid_functionaltimesize_f('Rain', rain_timesize);
63 ! Allocate memory for time values of Rain
64 allocate(rain_time(rain_timesize))
65
66 ! 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))
67 ! Read the attribute at Time = 1
68 rain_timeid = 1
69 call cg_iric_read_grid_functional_real_cell_f('Rain', rain_timeid, rain, ier)
70 print *, 'Rain: isize -1, jsize-1=', isize-1, jsize-1
71 do i = 1, min(isize-1,5)
72 do j = 1, min(jsize-1,5)
73 print *, ' (',i,',',j,')=(',rain(i,j),')'
74 end do
75 end do
76
77 ! Deallocate memory that has been allocated
78 deallocate(grid_x, grid_y, elevation, obstacle, rain_time, rain)
79
80 ! Close CGNS file
81 call cg_close_f(fin, ier)
82 stop
83end program Sample3
Processing for a three-dimensional grid can be described in the same manner.