source: XIOS/trunk/src/test/test_basic_2D.f90 @ 833

Last change on this file since 833 was 815, checked in by mhnguyen, 9 years ago

Fixing the bug in ticket 72

+) The distributed axis on client side send info to correct corresponding server
+) Improve serverdistributiondescription class to make it more flexible
+) Create new test_basic_2D only for test cases of 2-d grid

Test
+) On Curie
+) All tests pass

File size: 4.5 KB
Line 
1PROGRAM test_basic_2D
2  USE xios
3  USE mod_wait
4  IMPLICIT NONE
5  INCLUDE "mpif.h"
6
7  TYPE(xios_duration)  :: dtime
8  TYPE(xios_context) :: ctx_hdl
9  INTEGER,PARAMETER :: ni_glo=100
10  INTEGER,PARAMETER :: nj_glo=100
11
12  INTEGER :: i,j,n,ts
13  INTEGER :: ibegin,jbegin,ni,nj,nbi,nbj,iend,jend
14  INTEGER :: ierr, rank, size
15  INTEGER :: comm
16
17  DOUBLE PRECISION,DIMENSION(ni_glo,nj_glo) :: lon_glo,lat_glo
18  DOUBLE PRECISION :: field_glo(ni_glo,nj_glo)
19  DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),field_domain(:,:), field_axis(:,:)
20
21  ! Initialize MPI
22  CALL MPI_INIT(ierr)
23
24  CALL init_wait
25
26  ! Initialize XIOS
27  CALL xios_initialize('client', return_comm=comm)
28
29  CALL MPI_COMM_SIZE(comm, size, ierr)
30  CALL MPI_COMM_RANK(comm, rank, ierr)
31
32  ! Initialize all global values
33  DO j=1,nj_glo
34    DO i=1,ni_glo
35      lon_glo(i,j)=(i-1)+(j-1)*ni_glo
36      lat_glo(i,j)=1000+(i-1)+(j-1)*ni_glo
37      field_glo(i,j)=(i-1)+(j-1)*ni_glo
38    ENDDO
39  ENDDO
40  ni=ni_glo ; ibegin=0
41
42  nbi = 1
43  ! Specify how we distributed domain
44  DO i=1,int(sqrt(real(size)))+1
45    IF (0 == MOD(size,i)) nbi = i
46  ENDDO
47  nbj = size/nbi
48
49  jbegin=0;
50  LOOP1: DO j=1,nbj
51    nj=nj_glo/nbj
52    if (nj<MOD(nj_glo,nbj)) nj=nj+1
53    ibegin=0
54    DO i=1,nbi
55      n=(j-1)*nbi+i-1
56      ni=ni_glo/nbi
57      if (ni<MOD(ni_glo,nbi)) ni=ni+1
58      IF (n==rank) exit LOOP1
59      IF (i/=nbi) ibegin=ibegin+ni
60    ENDDO
61    IF (j/=nbj) jbegin=jbegin+nj
62  ENDDO LOOP1
63  iend=ibegin+ni-1; jend=jbegin+nj-1
64
65!  if (rank == 0) print *, ni_glo, ni, nj_glo, nj
66  print *, ni, nj, ibegin, jbegin, iend, jend
67
68  ALLOCATE(lon(ni,nj),lat(ni,nj),field_domain(0:ni+1,-1:nj+2),field_axis(ni,nj))
69  lon(:,:)=lon_glo(ibegin+1:iend+1,jbegin+1:jend+1)
70  lat(:,:)=lat_glo(ibegin+1:iend+1,jbegin+1:jend+1)
71  field_domain(1:ni,1:nj)=field_glo(ibegin+1:iend+1,jbegin+1:jend+1)
72  field_axis(1:ni,1:nj)=field_glo(ibegin+1:iend+1,jbegin+1:jend+1)
73
74  ! Test 2-dimension domain
75  ! Initialize the context
76  CALL xios_context_initialize('test_domain', comm)
77  CALL xios_get_handle('test_domain', ctx_hdl)
78  CALL xios_set_current_context(ctx_hdl)
79
80  CALL xios_define_calendar(type="Gregorian", &
81                            start_date=xios_date(2000, 01, 01, 00, 00, 00), &
82                            time_origin=xios_date(1999, 01, 01, 15, 00, 00))
83
84  CALL xios_set_domain_attr("domain",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj, type='curvilinear')
85  CALL xios_set_domain_attr("domain",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
86  CALL xios_set_domain_attr("domain",lonvalue_2D=lon,latvalue_2D=lat)
87
88  CALL xios_get_domain_attr("domain",lonvalue_2D=lon)
89!  PRINT *,"lonvalue",lon
90
91  dtime%second=3600
92  CALL xios_set_timestep(timestep=dtime)
93  ! Close domain context
94  CALL xios_close_context_definition()
95
96  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
97  ! Test 2-dimension grid composed of 2 distributed axis
98  ! Initialize the context
99  CALL xios_context_initialize('test_axis', comm)
100  CALL xios_get_handle('test_axis', ctx_hdl)
101  CALL xios_set_current_context(ctx_hdl)
102
103  CALL xios_define_calendar(type="Gregorian", &
104                            start_date=xios_date(2000, 01, 01, 00, 00, 00), &
105                            time_origin=xios_date(1999, 01, 01, 15, 00, 00))
106
107  CALL xios_set_axis_attr("x", n_glo=ni_glo, n=ni, begin=ibegin, value=(/(real(i,kind=8), i=ibegin,ibegin+ni-1)/))
108  CALL xios_set_axis_attr("y", n_glo=nj_glo, n=nj, begin=jbegin, value=(/(real(i,kind=8), i=jbegin,jbegin+nj-1)/))
109
110  dtime%second=3600
111  CALL xios_set_timestep(timestep=dtime)
112
113  ! Close axis context
114  CALL xios_close_context_definition()
115
116  DO ts=1,24*10
117    ! Domain context
118    CALL xios_get_handle("test_domain",ctx_hdl)
119    CALL xios_set_current_context(ctx_hdl)
120    CALL xios_update_calendar(ts)
121    CALL xios_send_field("field_domain_1",field_domain)
122    CALL xios_send_field("field_domain_2",field_domain)
123
124    ! Switch to axis context
125    CALL xios_get_handle("test_axis",ctx_hdl)
126    CALL xios_set_current_context(ctx_hdl)
127    CALL xios_update_calendar(ts)
128    CALL xios_send_field("field_axis",field_axis)
129
130    CALL wait_us(500) ;
131  ENDDO
132
133  ! Clean-ups
134  CALL xios_get_handle("test_domain",ctx_hdl)
135  CALL xios_set_current_context(ctx_hdl)
136  CALL xios_context_finalize()
137  CALL xios_get_handle("test_axis",ctx_hdl)
138  CALL xios_set_current_context(ctx_hdl)
139  CALL xios_context_finalize()
140
141  DEALLOCATE(lon, lat, field_domain, field_axis)
142
143  CALL MPI_COMM_FREE(comm, ierr)
144  CALL xios_finalize()
145  CALL MPI_FINALIZE(ierr)
146
147END PROGRAM test_basic_2D
148
149
150
151
152
Note: See TracBrowser for help on using the repository browser.