source: XIOS/xios_training/hands-on-5/answer/test_tp5.f90_2 @ 2357

Last change on this file since 2357 was 2046, checked in by ymipsl, 4 years ago
File size: 3.6 KB
Line 
1PROGRAM test_tp5
2
3  USE XIOS
4  IMPLICIT NONE
5  INCLUDE "mpif.h"
6  INTEGER :: rank
7  INTEGER :: size
8  INTEGER :: ierr
9
10  INTEGER :: comm
11  TYPE(xios_duration) :: dtime
12
13  TYPE(xios_date) :: dorigin
14  CHARACTER(len=20) :: dorigin_str
15
16  TYPE(xios_date) :: dstart
17  CHARACTER(len=20) :: dstart_str
18
19  INTEGER :: axis_size
20  DOUBLE PRECISION, ALLOCATABLE :: axis_value(:)
21
22  CHARACTER(len=20) :: domain_type
23  INTEGER :: ni_glo, nj_glo
24  DOUBLE PRECISION, ALLOCATABLE :: lonvalue(:), latvalue(:)
25 
26  INTEGER :: i, j
27 
28  DOUBLE PRECISION, ALLOCATABLE :: field_A(:,:,:)
29  DOUBLE PRECISION, ALLOCATABLE :: field_B(:,:,:)
30  DOUBLE PRECISION, ALLOCATABLE :: field_C(:,:,:)
31 
32  INTEGER :: ts
33 
34  INTEGER :: ni, nj, ibegin, jbegin
35 
36  CALL MPI_INIT(ierr)
37
38  CALL xios_initialize("client",return_comm=comm)
39
40  CALL MPI_COMM_RANK(comm,rank,ierr)
41  CALL MPI_COMM_SIZE(comm,size,ierr)
42 
43  print*, "Hello XIOS from proc", rank
44 
45  CALL xios_context_initialize("test",comm)
46
47  !CALL xios_define_calendar(type="Gregorian")
48  !We define the calendar type in xml
49
50  CALL xios_get_time_origin(dorigin)
51  CALL xios_date_convert_to_string(dorigin, dorigin_str)
52  if (rank .EQ. 0) print*, "calendar time_origin = ", dorigin_str
53
54  CALL xios_get_start_date(dstart)
55  CALL xios_date_convert_to_string(dstart, dstart_str)
56  if (rank .EQ. 0) print*, "calendar start_date = ", dstart_str
57
58  dtime%second = 3600
59  CALL xios_set_timestep(dtime)
60
61  CALL xios_get_axis_attr("axis_A", n_glo = axis_size)
62  ALLOCATE(axis_value(axis_size))
63  CALL xios_get_axis_attr("axis_A", value = axis_value)
64  if (rank .EQ. 0) print*, "axis value = ", axis_value(:)
65
66  CALL xios_get_domain_attr("domain_A", type = domain_type)
67  CALL xios_get_domain_attr("domain_A", ni_glo = ni_glo, nj_glo=nj_glo)
68  if(rank.EQ.0) print*, "domain type = ", domain_type
69  if(rank.EQ.0) print*, "domain size = ", ni_glo, "*", nj_glo
70
71  ni=ni_glo/size
72  nj=nj_glo
73
74  ibegin=ni*rank
75  jbegin=0
76
77  CALL xios_set_domain_attr("domain_A", ni=ni, nj=nj, ibegin=ibegin,jbegin=jbegin)
78  print*, "Proc ",rank, "occupies subdomain",ibegin,"->",ibegin+ni,"X",jbegin,"->",jbegin+nj
79
80
81  ALLOCATE(lonvalue(ni))
82  ALLOCATE(latvalue(nj))
83
84  DO i=1,ni
85    lonvalue(i) = -180 + (rank*ni+i) * 360/ni_glo
86  ENDDO
87
88  DO j=1,nj
89    latvalue(j) = -90 + j * 180/nj_glo
90  ENDDO
91
92  CALL xios_set_domain_attr("domain_A", lonvalue_1d=lonvalue,latvalue_1d=latvalue)
93 
94  !--- Case 2 ---!
95  ! CALL xios_set_domain_attr("domain_A", data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-1, data_nj=nj+2)
96 
97  !--- Case 3 ---!
98  !CALL xios_set_domain_attr("domain_A", data_dim=2, data_ibegin=1, data_ni=ni-2, data_jbegin=0, data_nj=nj/2)
99
100  CALL xios_set_domain_attr("domain_read", type="curvilinear", ni_glo=10, nj_glo=10)
101  CALL xios_set_domain_attr("domain_read", ni=10, ibegin=0, nj=10,jbegin=0)
102 
103  CALL xios_close_context_definition()
104
105  !--- Case 1 ---!
106  ALLOCATE(field_A(ni, nj, axis_size))
107  field_A(:,:,:)=rank
108
109  !--- Case 2 ---!
110  ! ALLOCATE(field_A(ni+2, nj+2, axis_size))
111  ! field_A(:,:,:)=rank
112
113  !--- Case 3 ---!
114  ! ALLOCATE(field_A(ni-2, nj/2, axis_size))
115  ! field_A(:,:,:)=rank
116
117  ALLOCATE(field_B(ni, nj, axis_size))
118  ALLOCATE(field_C(ni, nj, axis_size))
119  field_B(:,:,:)=-1 * rank
120  field_C(:,:,:)=rank*rank
121 
122  DO ts=1,4
123    CALL xios_update_calendar(ts)
124    CALL xios_send_field("field_A", field_A)
125    CALL xios_send_field("field_B", field_B)
126    CALL xios_send_field("field_C", field_C)
127  ENDDO
128
129  CALL xios_context_finalize()
130
131  DEALLOCATE(axis_value)
132  DEALLOCATE(lonvalue, latvalue)
133  DEALLOCATE(field_A)
134  DEALLOCATE(field_B)
135  DEALLOCATE(field_C)
136
137  CALL MPI_COMM_FREE(comm, ierr)
138
139  CALL xios_finalize()
140
141  CALL MPI_FINALIZE(ierr)
142
143END PROGRAM test_tp5
144
Note: See TracBrowser for help on using the repository browser.