Changeset 468
 Timestamp:
 01/29/14 16:14:10 (9 years ago)
 Location:
 XIOS/trunk
 Files:

 1 added
 1 edited
Legend:
 Unmodified
 Added
 Removed

XIOS/trunk/src/test/test_unstruct.f90
r452 r468 5 5 IMPLICIT NONE 6 6 INCLUDE "mpif.h" 7 INTEGER :: rank8 INTEGER :: size7 INTEGER :: mpi_rank 8 INTEGER :: mpi_size 9 9 INTEGER :: ierr 10 10 … … 13 13 TYPE(xios_time) :: dtime 14 14 TYPE(xios_context) :: ctx_hdl 15 INTEGER, PARAMETER :: nlon=60 16 INTEGER, PARAMETER :: nlat=30 15 17 INTEGER,PARAMETER :: ni_glo=100 16 18 INTEGER,PARAMETER :: nj_glo=100 … … 22 24 LOGICAL :: ok 23 25 24 DOUBLE PRECISION,DIMENSION(ni_glo,nj_glo) :: lon_glo,lat_glo 25 DOUBLE PRECISION,DIMENSION(4,ni_glo,nj_glo) :: bounds_lon_glo,bounds_lat_glo 26 DOUBLE PRECISION :: field_A_glo(ni_glo,nj_glo,llm) 27 DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),field_A(:,:,:), lonvalue(:) ; 28 DOUBLE PRECISION,ALLOCATABLE :: bounds_lon(:,:,:),bounds_lat(:,:,:) ; 26 DOUBLE PRECISION,ALLOCATABLE :: lon_glo(:),lat_glo(:) 27 DOUBLE PRECISION,ALLOCATABLE :: bounds_lon_glo(:,:),bounds_lat_glo(:,:) 28 DOUBLE PRECISION,ALLOCATABLE :: field_A_glo(:,:) 29 INTEGER,ALLOCATABLE :: i_index_glo(:) 30 INTEGER,ALLOCATABLE :: i_index(:) 31 LOGICAL,ALLOCATABLE :: mask_glo(:),mask(:) 32 DOUBLE PRECISION,ALLOCATABLE :: lon(:),lat(:),field_A(:,:), lonvalue(:) ; 33 DOUBLE PRECISION,ALLOCATABLE :: bounds_lon(:,:),bounds_lat(:,:) ; 29 34 INTEGER :: ni,ibegin,iend,nj,jbegin,jend 30 35 INTEGER :: i,j,l,ts,n 31 36 INTEGER :: ncell_glo,ncell,ind 37 REAL :: ilon,ilat 38 DOUBLE PRECISION, PARAMETER :: Pi=3.14159265359 39 INTEGER :: list_ind(nlon,nlat) 40 INTEGER :: rank,j1,j2,np,ncell_x 41 INTEGER :: data_n_index 42 INTEGER,ALLOCATABLE :: data_i_index(:) 43 DOUBLE PRECISION,ALLOCATABLE :: field_A_compressed(:,:) 44 32 45 CALL xios_initialize(id,return_comm=comm) 33 ! CALL MPI_INIT(ierr) 34 CALL MPI_COMM_RANK(comm,rank,ierr) 35 CALL MPI_COMM_SIZE(comm,size,ierr) 46 CALL MPI_COMM_RANK(comm,mpi_rank,ierr) 47 CALL MPI_COMM_SIZE(comm,mpi_size,ierr) 36 48 37 49 CALL init_wait 38 50 39 40 DO j=1,nj_glo 41 DO i=1,ni_glo 42 lon_glo(i,j)=(i1)+(j1)*ni_glo 43 lat_glo(i,j)=1000+(i1)+(j1)*ni_glo 44 bounds_lat_glo(1,i,j)=lat_glo(i,j)0.5 45 bounds_lat_glo(2,i,j)=lat_glo(i,j)0.5 46 bounds_lat_glo(3,i,j)=lat_glo(i,j)+0.5 47 bounds_lat_glo(4,i,j)=lat_glo(i,j)+0.5 48 bounds_lon_glo(1,i,j)=lon_glo(i,j)0.5 49 bounds_lon_glo(2,i,j)=lon_glo(i,j)0.5 50 bounds_lon_glo(3,i,j)=lon_glo(i,j)+0.5 51 bounds_lon_glo(4,i,j)=lon_glo(i,j)+0.5 52 DO l=1,llm 53 field_A_glo(i,j,l)=(i1)+(j1)*ni_glo+10000*l 51 ncell_glo=0 52 DO j=1,nlat 53 n = NINT(COS(Pi/2(j0.5)*PI/nlat)*nlon) 54 IF (n<8) n=8 55 ncell_glo=ncell_glo+n 56 ENDDO 57 58 ALLOCATE(lon_glo(ncell_glo)) 59 ALLOCATE(lat_glo(ncell_glo)) 60 ALLOCATE(bounds_lon_glo(4,ncell_glo)) 61 ALLOCATE(bounds_lat_glo(4,ncell_glo)) 62 ALLOCATE(i_index_glo(ncell_glo)) 63 ALLOCATE(field_A_glo(ncell_glo,llm)) 64 ALLOCATE(mask_glo(ncell_glo)) 65 66 ind=0 67 DO j=1,nlat 68 n = NINT(COS(Pi/2(j0.5)*PI/nlat)*nlon) 69 if (j==1) PRINT*," ",n 70 if (j==nlat) PRINT*," ",n 71 IF (n<8) n=8 72 73 DO i=1,n 74 ind=ind+1 75 list_ind(i,j)=ind 76 ilon=i0.5 77 ilat=j0.5 78 79 lat_glo(ind)= 90(ilat*180./nlat) 80 lon_glo(ind)= (ilon*360./n) 81 82 83 bounds_lat_glo(1,ind)= 90((ilat0.5)*180./nlat) 84 bounds_lon_glo(1,ind)=((ilon0.5)*360./n) 85 86 bounds_lat_glo(2,ind)= 90((ilat0.5)*180./nlat) 87 bounds_lon_glo(2,ind)=((ilon+0.5)*360./n) 88 89 bounds_lat_glo(3,ind)= 90((ilat+0.5)*180./nlat) 90 bounds_lon_glo(3,ind)=((ilon+0.5)*360./n) 91 92 bounds_lat_glo(4,ind)= 90((ilat+0.5)*180./nlat) 93 bounds_lon_glo(4,ind)=((ilon0.5)*360./n) 94 95 ENDDO 96 ENDDO 97 98 ! mpi_size=32 99 rank=(mpi_size1)/2 100 ncell_x=sqrt(ncell_glo*1./mpi_size) 101 102 j1=nlat/2 103 DO WHILE(rank>=0) 104 j2=MAX(j1ncell_x+1,1) 105 j=(j1+j2)/2 106 n=NINT(COS(Pi/2(j0.5)*PI/nlat)*nlon) 107 np = MIN(n/ncell_x,rank+1) ; 108 if (j2==1) np=rank+1 109 110 PRINT *,"domain ",j2,j1,rank,np ; 111 DO j=j2,j1 112 n=NINT(COS(Pi/2(j0.5)*PI/nlat)*nlon) 113 IF (n<8) n=8 114 DO i=1,n 115 ind=list_ind(i,j) 116 IF ( (i1) < MOD(n,np)*(n/np+1)) THEN 117 i_index_glo(ind) = rank  (i1)/(n/np+1) 118 ELSE 119 i_index_glo(ind) = rank(MOD(n,np)+ (i1MOD(n,np)*(n/np+1))/(n/np)) 120 ENDIF 54 121 ENDDO 55 122 ENDDO 56 ENDDO 57 ni=ni_glo ; ibegin=1 58 59 jbegin=1 60 DO n=0,size1 61 nj=nj_glo/size 62 IF (n<MOD(nj_glo,size)) nj=nj+1 63 IF (n==rank) exit 64 jbegin=jbegin+nj 65 ENDDO 66 67 iend=ibegin+ni1 ; jend=jbegin+nj1 68 69 ALLOCATE(lon(ni,nj),lat(ni,nj),field_A(ni,nj,llm),lonvalue(ni*nj)) 70 ALLOCATE(bounds_lon(4,ni,nj),bounds_lat(4,ni,nj)) 71 lon(:,:)=lon_glo(ibegin:iend,jbegin:jend) 72 lat(:,:)=lat_glo(ibegin:iend,jbegin:jend) 73 bounds_lon(:,:,:)=bounds_lon_glo(:,ibegin:iend,jbegin:jend) 74 bounds_lat(:,:,:)=bounds_lat_glo(:,ibegin:iend,jbegin:jend) 75 field_A(1:ni,1:nj,:)=field_A_glo(ibegin:iend,jbegin:jend,:) 76 77 123 rank=ranknp 124 j1=j21 125 ENDDO 126 127 rank=(mpi_size1)/2+1 128 ncell_x=sqrt(ncell_glo*1./mpi_size) 129 130 j1=nlat/2+1 131 DO WHILE(rank<=mpi_size1) 132 j2=MIN(j1+ncell_x1,nlat) 133 j=(j1+j2)/2 134 n=NINT(COS(Pi/2(j0.5)*PI/nlat)*nlon) 135 np = MIN(n/ncell_x,mpi_sizerank) ; 136 if (j2==nlat) np=mpi_sizerank 137 138 PRINT *,"domain ",j2,j1,rank,np ; 139 DO j=j1,j2 140 n=NINT(COS(Pi/2(j0.5)*PI/nlat)*nlon) 141 IF (n<8) n=8 142 DO i=1,n 143 ind=list_ind(i,j) 144 IF ( (i1) < MOD(n,np)*(n/np+1)) THEN 145 i_index_glo(ind) = rank + (i1)/(n/np+1) 146 ELSE 147 i_index_glo(ind) = rank+(MOD(n,np)+ (i1MOD(n,np)*(n/np+1))/(n/np)) 148 ENDIF 149 ENDDO 150 ENDDO 151 rank=rank+np 152 j1=j2+1 153 ENDDO 154 155 ncell=0 156 DO ind=1,ncell_glo 157 IF (i_index_glo(ind)==mpi_rank) ncell=ncell+1 158 ENDDO 159 ALLOCATE(i_index(ncell)) 160 ALLOCATE(lon(ncell)) 161 ALLOCATE(lat(ncell)) 162 ALLOCATE(bounds_lon(4,ncell)) 163 ALLOCATE(bounds_lat(4,ncell)) 164 ALLOCATE(field_A(ncell,llm)) 165 ALLOCATE(mask(ncell)) 166 ncell=0 167 data_n_index=0 168 DO ind=1,ncell_glo 169 IF (i_index_glo(ind)==mpi_rank) THEN 170 ncell=ncell+1 171 i_index(ncell)=ind1 172 lon(ncell)=lon_glo(ind) 173 lat(ncell)=lat_glo(ind) 174 bounds_lon(:,ncell)=bounds_lon_glo(:,ind) 175 bounds_lat(:,ncell)=bounds_lat_glo(:,ind) 176 field_A(ncell,:)=i_index_glo(ind) 177 IF (MOD(ind,8)>=0 .AND. MOD(ind,8)<2) THEN 178 mask(ncell)=.FALSE. 179 ELSE 180 mask(ncell)=.TRUE. 181 data_n_index=data_n_index+1 182 ENDIF 183 ENDIF 184 ENDDO 185 186 ALLOCATE(field_A_compressed(data_n_index,llm)) 187 ALLOCATE(data_i_index(data_n_index)) 188 189 data_n_index=0 190 DO ind=1,ncell 191 IF (mask(ind)) THEN 192 data_n_index=data_n_index+1 193 data_i_index(data_n_index)=ind 194 field_A_compressed(data_n_index,:)=field_A(ind,:) 195 ENDIF 196 ENDDO 197 198 199 78 200 CALL xios_context_initialize("test",comm) 79 201 CALL xios_get_handle("test",ctx_hdl) 80 202 CALL xios_set_current_context(ctx_hdl) 81 203 82 CALL xios_set_context_attr("test",calendar_type="Gregorian")83 CALL xios_set_context_attr("test",calendar_type="Gregorian")84 CALL xios_set_context_attr("test",calendar_type="Gregorian")85 ! CALL xios_set_context_attr("test",start_date="01/01/2000  00:00:00")86 CALL xios_set_context_attr("test",calendar_type="Gregorian")87 204 CALL xios_set_axis_attr("axis_A",size=llm ,value=lval) ; 88 ! CALL xios_set_domain_attr("domain_A",ni_glo=1, nj_glo=nj_glo*nj_glo, ibegin=1, ni=1,jbegin=(jbegin1)*ni_glo+1,nj=nj*ni_glo) 89 CALL xios_set_domain_attr("domain_A",ni_glo=ni_glo*nj_glo, ibegin=(jbegin1)*ni_glo+1, ni=nj*ni_glo) 90 !CALL xios_set_domain_attr("domain_A",zoom_ni=3,zoom_ibegin=3,zoom_nj=3,zoom_jbegin=6) 91 CALL xios_set_domain_attr("domain_A",data_dim=1,type='unstructured') 92 CALL xios_set_domain_attr("domain_A",lonvalue=RESHAPE(lon,(/ni*nj/)),latvalue=RESHAPE(lat,(/ni*nj/))) 93 CALL xios_set_domain_attr("domain_A", bounds_lon=RESHAPE(bounds_lon,(/4,ni*nj/)) ) 94 CALL xios_set_domain_attr("domain_A",bounds_lat=RESHAPE(bounds_lat,(/4,ni*nj/)) ) 95 CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.) 96 97 CALL xios_get_handle("field_definition",fieldgroup_hdl) 98 CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B") 99 CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B") 100 101 CALL xios_get_handle("output",file_hdl) 102 CALL xios_add_child(file_hdl,field_hdl,"field_C") 103 CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_C") 205 CALL xios_set_domain_attr("domain_A",ni_glo=ncell_glo, ni=ncell, ibegin=1, i_index=RESHAPE(i_index,(/ncell,1/) )) 206 CALL xios_set_domain_attr("domain_A",data_dim=1, data_ni=data_n_index, data_n_index=data_n_index, data_i_index=data_i_index, type='unstructured') 207 CALL xios_set_domain_attr("domain_A",lonvalue=lon,latvalue=lat) 208 CALL xios_set_domain_attr("domain_A", nvertex=4, bounds_lon=bounds_lon, bounds_lat=bounds_lat ) 104 209 105 210 106 dtime%second=3600 107 CALL xios_set_timestep(dtime) 108 109 ! ni=0 ; lonvalue(:)=0 110 ! CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue=lonvalue) 111 112 ! print *,"ni",ni 113 ! print *,"lonvalue",lonvalue ; 114 115 CALL xios_is_defined_field_attr("field_A",enabled=ok) 116 PRINT *,"field_A : attribute enabled is defined ? ",ok 117 IF (ok) THEN 118 CALL xios_get_field_attr("field_A",enabled=ok) 119 PRINT *,"field_A : attribute enabled = ",ok 120 ENDIF 121 CALL xios_is_defined_field_attr("field_C",enabled=ok) 122 PRINT *,"field_C : attribute enabled is defined ? ",ok 123 IF (ok) THEN 124 CALL xios_get_field_attr("field_C",enabled=ok) 125 PRINT *,"field_C : attribute enabled = ",ok 126 ENDIF 127 128 CALL xios_solve_inheritance() 129 CALL xios_is_defined_field_attr("field_C",enabled=ok) 130 PRINT *,"field_C : attribute enabled is defined ? ",ok 131 IF (ok) THEN 132 CALL xios_get_field_attr("field_C",enabled=ok) 133 PRINT *,"field_C : attribute enabled = ",ok 134 ENDIF 135 CALL xios_close_context_definition() 136 137 PRINT*,"field field_A is active ? ",xios_field_is_active("field_A") 138 DO ts=1,24*10 139 field_A=field_A+100000 140 CALL xios_update_calendar(ts) 141 CALL xios_send_field("field_A",RESHAPE(field_A,(/ni*nj,llm/))) 142 if (ts==12) CALL xios_send_field("field_once",RESHAPE(field_A,(/ni*nj,llm/))) 143 ! field_A=field_A+100000 144 ! CALL wait_us(5000) ; 211 dtime%second=3600 212 CALL xios_set_timestep(dtime) 213 CALL xios_close_context_definition() 214 215 DO ts=1,24*10 216 CALL xios_update_calendar(ts) 217 CALL xios_send_field("field_A",field_A_compressed) 145 218 ENDDO 146 219 … … 148 221 CALL xios_finalize() 149 222 150 ! CALL MPI_FINALIZE(ierr)151 152 223 END PROGRAM test_unstruct 153 224
Note: See TracChangeset
for help on using the changeset viewer.