source: XIOS/dev/branch_openmp/src/test/test_client.f90 @ 1544

Last change on this file since 1544 was 1544, checked in by yushan, 6 years ago

bug fix for tests in prod mode

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 5.6 KB
Line 
1PROGRAM 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  CHARACTER(len=20) :: dtime_str
15  TYPE(xios_date) :: date
16  CHARACTER(len=20) :: date_str
17  CHARACTER(len=15) :: calendar_type
18  TYPE(xios_context) :: ctx_hdl
19  INTEGER,PARAMETER :: ni_glo=100
20  INTEGER,PARAMETER :: nj_glo=100
21  INTEGER,PARAMETER :: llm=5
22  DOUBLE PRECISION  :: lval(llm)=1, scalar = 5
23  TYPE(xios_field) :: field_hdl
24  TYPE(xios_fieldgroup) :: fieldgroup_hdl
25  TYPE(xios_file) :: file_hdl
26  LOGICAL :: ok
27
28  DOUBLE PRECISION,DIMENSION(ni_glo,nj_glo) :: lon_glo,lat_glo
29  DOUBLE PRECISION :: field_A_glo(ni_glo,nj_glo,llm)
30  DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),field_A(:,:,:), lonvalue(:,:), axisValue(:), field_domain(:,:) ;
31  INTEGER :: ni,ibegin,iend,nj,jbegin,jend
32  INTEGER :: i,j,l,ts,n
33
34!!! MPI Initialization
35
36  CALL MPI_INIT(ierr)
37
38  CALL init_wait
39 
40  CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr)
41  CALL MPI_COMM_SIZE(MPI_COMM_WORLD,size,ierr)
42  if(rank < size-2) then
43
44!!! XIOS Initialization (get the local communicator)
45
46  CALL xios_initialize(id,return_comm=comm)
47
48  CALL MPI_COMM_RANK(comm,rank,ierr)
49  CALL MPI_COMM_SIZE(comm,size,ierr)
50
51  DO j=1,nj_glo
52    DO i=1,ni_glo
53      lon_glo(i,j)=(i-1)+(j-1)*ni_glo
54      lat_glo(i,j)=1000+(i-1)+(j-1)*ni_glo
55      DO l=1,llm
56        field_A_glo(i,j,l)=(i-1)+(j-1)*ni_glo*100+10000*l
57      ENDDO
58    ENDDO
59  ENDDO
60  ni=ni_glo ; ibegin=0
61
62  jbegin=0
63  DO n=0,size-1
64    nj=nj_glo/size
65    IF (n<MOD(nj_glo,size)) nj=nj+1
66    IF (n==rank) exit
67    jbegin=jbegin+nj
68  ENDDO
69
70  iend=ibegin+ni-1 ; jend=jbegin+nj-1
71
72  ALLOCATE(lon(ni,nj),lat(ni,nj),field_A(0:ni+1,-1:nj+2,llm),lonvalue(ni,nj), axisValue(nj_glo), field_domain(0:ni+1,-1:nj+2))
73  lon(:,:)=lon_glo(ibegin+1:iend+1,jbegin+1:jend+1)
74  lat(:,:)=lat_glo(ibegin+1:iend+1,jbegin+1:jend+1)
75  field_A(1:ni,1:nj,:)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
76  field_domain(1:ni,1:nj) = field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,1)
77  axisValue(1:nj_glo)=field_A_glo(1,1:nj_glo,1);
78
79  CALL xios_context_initialize("test",comm)
80  CALL xios_get_handle("test",ctx_hdl)
81  CALL xios_set_current_context(ctx_hdl)
82
83  CALL xios_get_calendar_type(calendar_type)
84  PRINT *, "calendar_type = ", calendar_type
85
86  ! CALL xios_set_axis_attr("axis_A",n_glo=nj_glo ,value=axisValue, n=nj, begin=jbegin) ;
87  CALL xios_set_axis_attr("axis_A",n_glo=llm ,value=lval) ;
88  CALL xios_set_domain_attr("domain_A",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj,type='curvilinear')
89  CALL xios_set_domain_attr("domain_A",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
90  CALL xios_set_domain_attr("domain_A",lonvalue_2D=lon,latvalue_2D=lat)
91  CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.)
92
93  !CALL xios_get_handle("field_definition",fieldgroup_hdl)
94  !CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B")
95  !CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B")
96
97  !CALL xios_get_handle("output",file_hdl)
98  !CALL xios_add_child(file_hdl,field_hdl)
99  !CALL xios_set_attr(field_hdl,field_ref="field_A_zoom",name="field_C")
100
101  dtime%second = 3600
102  CALL xios_set_timestep(dtime)
103
104  ! The calendar is created as soon as the calendar type is defined. This way
105  ! calendar operations can be used before the context definition is closed
106  CALL xios_get_time_origin(date)
107  PRINT *, "--> year length = ", xios_get_year_length_in_seconds(date%year)
108  PRINT *, "--> day length = ", xios_get_day_length_in_seconds()
109  CALL xios_date_convert_to_string(date, date_str)
110  PRINT *, "time_origin = ", date_str
111  PRINT *, "xios_date_get_second_of_year(time_origin) = ", xios_date_get_second_of_year(date)
112  PRINT *, "xios_date_get_day_of_year(time_origin) = ", xios_date_get_day_of_year(date)
113  PRINT *, "xios_date_get_fraction_of_year(time_origin) = ", xios_date_get_fraction_of_year(date)
114  PRINT *, "xios_date_get_second_of_day(time_origin) = ", xios_date_get_second_of_day(date)
115  PRINT *, "xios_date_get_fraction_of_day(time_origin) = ", xios_date_get_fraction_of_day(date)
116  dtime%timestep = 1
117  dtime = 0.5 * dtime
118  CALL xios_duration_convert_to_string(dtime, dtime_str)
119  PRINT *, "duration = ", dtime_str
120  date = date + 3 * (dtime + dtime)
121  CALL xios_date_convert_to_string(date, date_str)
122  PRINT *, "date = time_origin + 3 * (duration + duration) = ", date_str
123  PRINT *, "xios_date_convert_to_seconds(date) = ", xios_date_convert_to_seconds(date)
124  PRINT *, "xios_date_convert_to_seconds(date - 2.5h) = ", xios_date_convert_to_seconds(date - 2.5 * xios_hour)
125
126  ni=0 ; lonvalue(:,:)=0;
127  CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue_2D=lonvalue)
128
129  print *,"ni",ni
130  print *,"lonvalue",lonvalue;
131
132  CALL xios_is_defined_field_attr("field_A",enabled=ok)
133  PRINT *,"field_A : attribute enabled is defined ? ",ok
134  CALL xios_close_context_definition()
135
136  PRINT*,"field field_A is active ? ",xios_field_is_active("field_A")
137  ! CALL xios_recv_field("field", scalar)
138  DO ts=1,4
139    CALL xios_update_calendar(ts)
140    CALL xios_send_field("field_A",field_A)
141    CALL xios_send_field("field_Axis",axisValue)
142    ! CALL xios_send_field("field_Axis",lval)
143    CALL xios_send_field("field_Domain",field_domain)
144    CALL xios_send_field("field_Scalar",scalar)
145    CALL wait_us(5000)
146  ENDDO
147
148  CALL xios_context_finalize()
149  CALL xios_finalize()
150
151  DEALLOCATE(lon, lat, field_A, lonvalue, axisValue, field_domain)
152
153  CALL MPI_COMM_FREE(comm, ierr)
154
155  else  !!server
156
157    CALL xios_init_server
158    print *, "Server : xios_finalize "
159 
160  endif
161   
162
163  CALL MPI_FINALIZE(ierr)
164
165END PROGRAM test_client
166
167
168
169
170
Note: See TracBrowser for help on using the repository browser.