source: XIOS/trunk/src/test/test_cs.f90 @ 313

Last change on this file since 313 was 313, checked in by ymipsl, 10 years ago

Fortran attribut interface are now automaticaly generated.
Add get attribut fonctionnality from fortran.

YM

File size: 3.5 KB
Line 
1PROGRAM test_cs
2IMPLICIT NONE
3  INCLUDE "mpif.h"
4  INTEGER :: rank
5  INTEGER :: size
6  INTEGER :: ierr
7 
8  CALL MPI_INIT(ierr)
9  CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr)
10  CALL MPI_COMM_SIZE(MPI_COMM_WORLD,size,ierr)
11 
12  IF (rank<3) THEN
13   CALL client("client",rank,3)
14  ELSE
15    CALL server
16  ENDIF
17 
18 
19  CALL MPI_FINALIZE(ierr)
20 
21END PROGRAM test_cs
22
23  SUBROUTINE client(id,rank,size)
24  USE xios
25  IMPLICIT NONE
26  INCLUDE 'mpif.h'
27  CHARACTER(len=*) :: id
28  INTEGER :: rank
29  INTEGER :: size
30  INTEGER :: comm
31  TYPE(xios_time)      :: dtime
32  TYPE(xios_context) :: ctx_hdl
33  INTEGER,PARAMETER :: ni_glo=10 
34  INTEGER,PARAMETER :: nj_glo=10 
35  TYPE(xios_field) :: field_hdl
36  TYPE(xios_fieldgroup) :: fieldgroup_hdl
37  TYPE(xios_file) :: file_hdl
38 
39 
40  DOUBLE PRECISION,DIMENSION(ni_glo,nj_glo) :: lon_glo,lat_glo,field_A_glo
41  DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),field_A(:,:), lonvalue(:) ;
42  INTEGER :: ni,ibegin,iend,nj,jbegin,jend
43  INTEGER :: i,j,ts,n
44 
45  DO j=1,nj_glo
46    DO i=1,ni_glo
47      lon_glo(i,j)=(i-1)+(j-1)*ni_glo
48      lat_glo(i,j)=1000+(i-1)+(j-1)*ni_glo
49      field_A_glo(i,j)=(i-1)+(j-1)*ni_glo
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),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
70  CALL xios_initialize(id,local_comm=MPI_COMM_WORLD,return_comm=comm)
71
72  CALL xios_context_initialize("test",comm)
73  CALL xios_get_handle("test",ctx_hdl)
74  CALL xios_set_current_context(ctx_hdl)
75 
76  CALL xios_set_context_attr("test",calendar_type="Gregorian") 
77  CALL xios_set_context_attr("test",calendar_type="Gregorian") 
78  CALL xios_set_context_attr("test",calendar_type="Gregorian") 
79  CALL xios_set_context_attr("test",start_date="01/01/2000 - 00:00:00")
80  CALL xios_set_context_attr("test",calendar_type="Gregorian") 
81  CALL xios_set_domain_attr("domain_A",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj)
82  CALL xios_set_domain_attr("domain_A",zoom_ni=3,zoom_ibegin=3,zoom_nj=3,zoom_jbegin=6)
83  CALL xios_set_domain_attr("domain_A",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
84  CALL xios_set_domain_attr("domain_A",lonvalue=RESHAPE(lon,(/ni*nj/)),latvalue=RESHAPE(lat,(/ni*nj/)))
85  CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.)
86 
87  CALL xios_get_handle("field_definition",fieldgroup_hdl)
88  CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B")
89  CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B")
90 
91  CALL xios_get_handle("output",file_hdl)
92  CALL xios_add_child(file_hdl,field_hdl)
93  CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_C")
94   
95 
96    dtime%second=3600
97    CALL xios_set_timestep(dtime) 
98   
99    ni=0 ; lonvalue(:)=0
100    CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue=lonvalue)
101   
102    print *,"ni",ni
103    print *,"lonvalue",lonvalue ;
104
105    CALL xios_close_context_definition()
106   
107    PRINT*,"field field_A is active ? ",xios_field_is_active("field_A")
108    DO ts=1,96
109      CALL xios_update_calendar(ts)
110      CALL xios_send_field("field_A",field_A)
111    ENDDO
112 
113    CALL xios_context_finalize()
114    CALL xios_finalize()
115     
116  END SUBROUTINE client
117 
118
119 
120  SUBROUTINE server
121  USE xios
122  IMPLICIT NONE
123 
124    CALL xios_init_server
125 
126  END SUBROUTINE server
127 
128
129 
Note: See TracBrowser for help on using the repository browser.