[374] | 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 |
---|
[549] | 10 | |
---|
[374] | 11 | CHARACTER(len=*),PARAMETER :: id="client" |
---|
| 12 | INTEGER :: comm |
---|
[537] | 13 | TYPE(xios_duration) :: dtime |
---|
[794] | 14 | CHARACTER(len=20) :: dtime_str |
---|
[545] | 15 | TYPE(xios_date) :: date |
---|
[794] | 16 | CHARACTER(len=20) :: date_str |
---|
[550] | 17 | CHARACTER(len=15) :: calendar_type |
---|
[374] | 18 | TYPE(xios_context) :: ctx_hdl |
---|
[723] | 19 | INTEGER,PARAMETER :: ni_glo=100 |
---|
| 20 | INTEGER,PARAMETER :: nj_glo=100 |
---|
[549] | 21 | INTEGER,PARAMETER :: llm=5 |
---|
[432] | 22 | DOUBLE PRECISION :: lval(llm)=1 |
---|
[374] | 23 | TYPE(xios_field) :: field_hdl |
---|
| 24 | TYPE(xios_fieldgroup) :: fieldgroup_hdl |
---|
| 25 | TYPE(xios_file) :: file_hdl |
---|
[432] | 26 | LOGICAL :: ok |
---|
[549] | 27 | |
---|
[374] | 28 | DOUBLE PRECISION,DIMENSION(ni_glo,nj_glo) :: lon_glo,lat_glo |
---|
| 29 | DOUBLE PRECISION :: field_A_glo(ni_glo,nj_glo,llm) |
---|
[665] | 30 | DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),field_A(:,:,:), lonvalue(:,:) ; |
---|
[374] | 31 | INTEGER :: ni,ibegin,iend,nj,jbegin,jend |
---|
| 32 | INTEGER :: i,j,l,ts,n |
---|
| 33 | |
---|
[455] | 34 | !!! MPI Initialization |
---|
| 35 | |
---|
[374] | 36 | CALL MPI_INIT(ierr) |
---|
| 37 | CALL init_wait |
---|
[549] | 38 | |
---|
[1134] | 39 | CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr) |
---|
| 40 | if(rank < 2) then |
---|
| 41 | |
---|
[455] | 42 | !!! XIOS Initialization (get the local communicator) |
---|
| 43 | |
---|
| 44 | CALL xios_initialize(id,return_comm=comm) |
---|
| 45 | |
---|
| 46 | CALL MPI_COMM_RANK(comm,rank,ierr) |
---|
[549] | 47 | CALL MPI_COMM_SIZE(comm,size,ierr) |
---|
| 48 | |
---|
[374] | 49 | DO j=1,nj_glo |
---|
| 50 | DO i=1,ni_glo |
---|
| 51 | lon_glo(i,j)=(i-1)+(j-1)*ni_glo |
---|
| 52 | lat_glo(i,j)=1000+(i-1)+(j-1)*ni_glo |
---|
| 53 | DO l=1,llm |
---|
| 54 | field_A_glo(i,j,l)=(i-1)+(j-1)*ni_glo+10000*l |
---|
| 55 | ENDDO |
---|
| 56 | ENDDO |
---|
| 57 | ENDDO |
---|
[554] | 58 | ni=ni_glo ; ibegin=0 |
---|
[374] | 59 | |
---|
[554] | 60 | jbegin=0 |
---|
[374] | 61 | DO n=0,size-1 |
---|
| 62 | nj=nj_glo/size |
---|
| 63 | IF (n<MOD(nj_glo,size)) nj=nj+1 |
---|
[549] | 64 | IF (n==rank) exit |
---|
[374] | 65 | jbegin=jbegin+nj |
---|
| 66 | ENDDO |
---|
[549] | 67 | |
---|
[374] | 68 | iend=ibegin+ni-1 ; jend=jbegin+nj-1 |
---|
| 69 | |
---|
[665] | 70 | ALLOCATE(lon(ni,nj),lat(ni,nj),field_A(0:ni+1,-1:nj+2,llm),lonvalue(ni,nj)) |
---|
[554] | 71 | lon(:,:)=lon_glo(ibegin+1:iend+1,jbegin+1:jend+1) |
---|
| 72 | lat(:,:)=lat_glo(ibegin+1:iend+1,jbegin+1:jend+1) |
---|
| 73 | field_A(1:ni,1:nj,:)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:) |
---|
[549] | 74 | |
---|
[374] | 75 | CALL xios_context_initialize("test",comm) |
---|
[1134] | 76 | |
---|
[374] | 77 | CALL xios_get_handle("test",ctx_hdl) |
---|
| 78 | CALL xios_set_current_context(ctx_hdl) |
---|
[549] | 79 | |
---|
| 80 | CALL xios_get_calendar_type(calendar_type) |
---|
| 81 | PRINT *, "calendar_type = ", calendar_type |
---|
| 82 | |
---|
[666] | 83 | CALL xios_set_axis_attr("axis_A",n_glo=llm ,value=lval) ; |
---|
[664] | 84 | 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') |
---|
[374] | 85 | CALL xios_set_domain_attr("domain_A",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4) |
---|
[668] | 86 | CALL xios_set_domain_attr("domain_A",lonvalue_2D=lon,latvalue_2D=lat) |
---|
[374] | 87 | CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.) |
---|
[549] | 88 | |
---|
[374] | 89 | CALL xios_get_handle("field_definition",fieldgroup_hdl) |
---|
| 90 | CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B") |
---|
| 91 | CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B") |
---|
[549] | 92 | |
---|
[374] | 93 | CALL xios_get_handle("output",file_hdl) |
---|
| 94 | CALL xios_add_child(file_hdl,field_hdl) |
---|
[624] | 95 | CALL xios_set_attr(field_hdl,field_ref="field_A_zoom",name="field_C") |
---|
[549] | 96 | |
---|
[545] | 97 | dtime%second = 3600 |
---|
[549] | 98 | CALL xios_set_timestep(dtime) |
---|
[374] | 99 | |
---|
[549] | 100 | ! The calendar is created as soon as the calendar type is defined. This way |
---|
| 101 | ! calendar operations can be used before the context definition is closed |
---|
| 102 | CALL xios_get_time_origin(date) |
---|
| 103 | PRINT *, "--> year length = ", xios_get_year_length_in_seconds(date%year) |
---|
| 104 | PRINT *, "--> day length = ", xios_get_day_length_in_seconds() |
---|
[794] | 105 | CALL xios_date_convert_to_string(date, date_str) |
---|
| 106 | PRINT *, "time_origin = ", date_str |
---|
[549] | 107 | PRINT *, "xios_date_get_second_of_year(time_origin) = ", xios_date_get_second_of_year(date) |
---|
| 108 | PRINT *, "xios_date_get_day_of_year(time_origin) = ", xios_date_get_day_of_year(date) |
---|
| 109 | PRINT *, "xios_date_get_fraction_of_year(time_origin) = ", xios_date_get_fraction_of_year(date) |
---|
| 110 | PRINT *, "xios_date_get_second_of_day(time_origin) = ", xios_date_get_second_of_day(date) |
---|
| 111 | PRINT *, "xios_date_get_fraction_of_day(time_origin) = ", xios_date_get_fraction_of_day(date) |
---|
[545] | 112 | dtime%timestep = 1 |
---|
| 113 | dtime = 0.5 * dtime |
---|
[794] | 114 | CALL xios_duration_convert_to_string(dtime, dtime_str) |
---|
| 115 | PRINT *, "duration = ", dtime_str |
---|
[545] | 116 | date = date + 3 * (dtime + dtime) |
---|
[794] | 117 | CALL xios_date_convert_to_string(date, date_str) |
---|
| 118 | PRINT *, "date = time_origin + 3 * (duration + duration) = ", date_str |
---|
[545] | 119 | PRINT *, "xios_date_convert_to_seconds(date) = ", xios_date_convert_to_seconds(date) |
---|
| 120 | PRINT *, "xios_date_convert_to_seconds(date - 2.5h) = ", xios_date_convert_to_seconds(date - 2.5 * xios_hour) |
---|
[549] | 121 | |
---|
[665] | 122 | ni=0 ; lonvalue(:,:)=0; |
---|
[668] | 123 | CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue_2D=lonvalue) |
---|
[549] | 124 | |
---|
[545] | 125 | print *,"ni",ni |
---|
[668] | 126 | print *,"lonvalue",lonvalue; |
---|
[545] | 127 | |
---|
| 128 | CALL xios_is_defined_field_attr("field_A",enabled=ok) |
---|
| 129 | PRINT *,"field_A : attribute enabled is defined ? ",ok |
---|
[1134] | 130 | |
---|
[545] | 131 | CALL xios_close_context_definition() |
---|
[549] | 132 | |
---|
[545] | 133 | PRINT*,"field field_A is active ? ",xios_field_is_active("field_A") |
---|
[1134] | 134 | |
---|
| 135 | call MPI_Barrier(comm, ierr) |
---|
| 136 | |
---|
[545] | 137 | DO ts=1,24*10 |
---|
| 138 | CALL xios_update_calendar(ts) |
---|
| 139 | CALL xios_send_field("field_A",field_A) |
---|
[1134] | 140 | CALL wait_us(5000) |
---|
[545] | 141 | ENDDO |
---|
| 142 | |
---|
| 143 | CALL xios_context_finalize() |
---|
[654] | 144 | |
---|
| 145 | DEALLOCATE(lon, lat, field_A, lonvalue) |
---|
| 146 | |
---|
[655] | 147 | CALL MPI_COMM_FREE(comm, ierr) |
---|
| 148 | |
---|
[545] | 149 | CALL xios_finalize() |
---|
[1134] | 150 | print *, "Client : xios_finalize " |
---|
[549] | 151 | |
---|
[1134] | 152 | else |
---|
| 153 | |
---|
| 154 | CALL xios_init_server |
---|
| 155 | print *, "Server : xios_finalize " |
---|
| 156 | |
---|
| 157 | endif |
---|
| 158 | |
---|
| 159 | |
---|
[374] | 160 | CALL MPI_FINALIZE(ierr) |
---|
[549] | 161 | |
---|
[374] | 162 | END PROGRAM test_client |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | |
---|
[549] | 166 | |
---|
| 167 | |
---|