1 | PROGRAM test_client |
---|
2 | |
---|
3 | USE xios |
---|
4 | USE mod_wait |
---|
5 | IMPLICIT NONE |
---|
6 | INCLUDE "mpif.h" |
---|
7 | INTEGER :: rank |
---|
8 | INTEGER :: size |
---|
9 | INTEGER :: ierr |
---|
10 | |
---|
11 | CHARACTER(len=*),PARAMETER :: id="client" |
---|
12 | INTEGER :: comm |
---|
13 | TYPE(xios_duration) :: dtime |
---|
14 | TYPE(xios_context) :: ctx_hdl |
---|
15 | INTEGER,PARAMETER :: ni_glo=100 |
---|
16 | INTEGER,PARAMETER :: nj_glo=100 |
---|
17 | INTEGER,PARAMETER :: llm=5 |
---|
18 | DOUBLE PRECISION :: lval(llm)=1 |
---|
19 | TYPE(xios_field) :: field_hdl |
---|
20 | TYPE(xios_fieldgroup) :: fieldgroup_hdl |
---|
21 | TYPE(xios_file) :: file_hdl |
---|
22 | LOGICAL :: ok |
---|
23 | |
---|
24 | DOUBLE PRECISION,DIMENSION(ni_glo,nj_glo) :: lon_glo,lat_glo |
---|
25 | DOUBLE PRECISION :: field_A_glo(ni_glo,nj_glo,llm) |
---|
26 | DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),field_A(:,:,:), lonvalue(:) ; |
---|
27 | INTEGER :: ni,ibegin,iend,nj,jbegin,jend |
---|
28 | INTEGER :: i,j,l,ts,n |
---|
29 | |
---|
30 | !!! MPI Initialization |
---|
31 | |
---|
32 | CALL MPI_INIT(ierr) |
---|
33 | |
---|
34 | CALL init_wait |
---|
35 | |
---|
36 | !!! XIOS Initialization (get the local communicator) |
---|
37 | |
---|
38 | CALL xios_initialize(id,return_comm=comm) |
---|
39 | |
---|
40 | CALL MPI_COMM_RANK(comm,rank,ierr) |
---|
41 | CALL MPI_COMM_SIZE(comm,size,ierr) |
---|
42 | |
---|
43 | DO j=1,nj_glo |
---|
44 | DO i=1,ni_glo |
---|
45 | lon_glo(i,j)=(i-1)+(j-1)*ni_glo |
---|
46 | lat_glo(i,j)=1000+(i-1)+(j-1)*ni_glo |
---|
47 | DO l=1,llm |
---|
48 | field_A_glo(i,j,l)=(i-1)+(j-1)*ni_glo+10000*l |
---|
49 | ENDDO |
---|
50 | ENDDO |
---|
51 | ENDDO |
---|
52 | ni=ni_glo ; ibegin=1 |
---|
53 | |
---|
54 | jbegin=1 |
---|
55 | DO n=0,size-1 |
---|
56 | nj=nj_glo/size |
---|
57 | IF (n<MOD(nj_glo,size)) nj=nj+1 |
---|
58 | IF (n==rank) exit |
---|
59 | jbegin=jbegin+nj |
---|
60 | ENDDO |
---|
61 | |
---|
62 | iend=ibegin+ni-1 ; jend=jbegin+nj-1 |
---|
63 | |
---|
64 | ALLOCATE(lon(ni,nj),lat(ni,nj),field_A(0:ni+1,-1:nj+2,llm),lonvalue(ni*nj)) |
---|
65 | lon(:,:)=lon_glo(ibegin:iend,jbegin:jend) |
---|
66 | lat(:,:)=lat_glo(ibegin:iend,jbegin:jend) |
---|
67 | field_A(1:ni,1:nj,:)=field_A_glo(ibegin:iend,jbegin:jend,:) |
---|
68 | |
---|
69 | CALL xios_context_initialize("test",comm) |
---|
70 | CALL xios_get_handle("test",ctx_hdl) |
---|
71 | CALL xios_set_current_context(ctx_hdl) |
---|
72 | |
---|
73 | CALL xios_set_context_attr("test",calendar_type="Gregorian") |
---|
74 | CALL xios_set_axis_attr("axis_A",size=llm ,value=lval) ; |
---|
75 | CALL xios_set_domain_attr("domain_A",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj) |
---|
76 | CALL xios_set_domain_attr("domain_A",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4) |
---|
77 | CALL xios_set_domain_attr("domain_A",lonvalue=RESHAPE(lon,(/ni*nj/)),latvalue=RESHAPE(lat,(/ni*nj/))) |
---|
78 | CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.) |
---|
79 | |
---|
80 | CALL xios_get_handle("field_definition",fieldgroup_hdl) |
---|
81 | CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B") |
---|
82 | CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B") |
---|
83 | |
---|
84 | CALL xios_get_handle("output",file_hdl) |
---|
85 | CALL xios_add_child(file_hdl,field_hdl) |
---|
86 | CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_C") |
---|
87 | |
---|
88 | |
---|
89 | dtime%second=3600 |
---|
90 | CALL xios_set_context_attr("test", timestep=dtime) |
---|
91 | |
---|
92 | ni=0 ; lonvalue(:)=0 |
---|
93 | CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue=lonvalue) |
---|
94 | |
---|
95 | print *,"ni",ni |
---|
96 | print *,"lonvalue",lonvalue ; |
---|
97 | |
---|
98 | CALL xios_is_defined_field_attr("field_A",enabled=ok) |
---|
99 | PRINT *,"field_A : attribute enabled is defined ? ",ok |
---|
100 | CALL xios_close_context_definition() |
---|
101 | |
---|
102 | PRINT*,"field field_A is active ? ",xios_field_is_active("field_A") |
---|
103 | DO ts=1,24*10 |
---|
104 | CALL xios_update_calendar(ts) |
---|
105 | CALL xios_send_field("field_A",field_A) |
---|
106 | CALL wait_us(5000) ; |
---|
107 | ENDDO |
---|
108 | |
---|
109 | CALL xios_context_finalize() |
---|
110 | CALL xios_finalize() |
---|
111 | |
---|
112 | CALL MPI_FINALIZE(ierr) |
---|
113 | |
---|
114 | END PROGRAM test_client |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | |
---|