-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestloc.F90bkup
202 lines (173 loc) · 7.78 KB
/
testloc.F90bkup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
program testloc
use ESMF
use wav_shr_mod , only : write_meshdecomp
use projectLS , only : findmapped
implicit none
integer, parameter :: nele = 274659, ne1=137951, ne2=136708
!integer, parameter :: npts = 240
integer, parameter :: npts = 223
type(ESMF_VM) :: vm
type(ESMF_Mesh) :: Emesh, Emesh2
type(ESMF_DistGrid) :: distGrid
type(ESMF_Field) :: doffld
type(ESMF_LocStream) :: LS, LS2, ptsLS
integer :: localrc
integer :: petCount, localPet
integer :: i,ii,n,nn,iounit,iostat,iaproc,ierr
integer :: rc
integer :: elb, eub,ecnt
real(kind=4) :: x1,y1,id1,dpt
real(kind=4) :: x(npts),y(npts),id(npts)
real(kind=8), pointer :: xx(:), yy(:)
integer(kind=4), pointer :: obsid(:)
integer(kind=4), pointer :: dof(:)
character(len=20) :: cvalue
integer, allocatable :: gindex(:)
character(len=1) :: comstr
character(len=100) :: chead
logical :: mapstatus
logical, allocatable :: mapped(:,:)
real(ESMF_KIND_R8), pointer :: pntList(:)
integer, pointer :: petList(:)
call ESMF_Initialize(vm=vm, logkindflag=ESMF_LOGKIND_MULTI, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
call ESMF_VMGet(vm, petCount=petCount, localPet=localPet, rc=rc)
!print *,petcount,localpet
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
if (petCount /= 2) then
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
end if
iaproc = localpet+1
allocate(mapped(petCount,npts))
!-------------------------------------------------------
! recreate the ww3 decomp
cvalue = 'mesh.global_270k.nc'
if (iaproc == 1) then
allocate(gindex(ne1))
do i = 1,ne1
gindex(i) = i
end do
end if
if (iaproc == 2) then
allocate(gindex(ne2))
do i = 1,ne2
gindex(i) = i+ne1
end do
end if
!do i = 1,size(gindex)
! write(10+iaproc,*)iaproc,i,gindex(i)
!end do
DistGrid = ESMF_DistGridCreate(arbSeqIndexList=gindex, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
EMesh = ESMF_MeshCreate(filename='mesh.global_270k.nc', fileformat=ESMF_FILEFORMAT_ESMFMESH, &
elementDistgrid=Distgrid, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
doffld = ESMF_FieldCreate(EMesh, typekind=ESMF_TYPEKIND_I4, meshloc=ESMF_MESHLOC_ELEMENT, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
call ESMF_FieldGet(field=doffld, farrayPtr=dof, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
call ESMF_FieldRead(doffld, 'emesh.decomp.nc', variableName='dof', rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!do i = 1,size(dof)
! write(20+iaproc,*)iaproc,i,dof(i)
!end do
DistGrid = ESMF_DistGridCreate(arbSeqIndexList=dof, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
EMesh2 = ESMF_MeshCreate(EMesh, elementdistgrid=Distgrid, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
! check the decomp is the same
call write_meshdecomp(Emesh2, 'emesh2', iaproc, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!-------------------------------------------------------
! load the point list, knowing how many lines
open (newunit=iounit, file='ww3_points.allmapped.list', form='formatted', status='old', iostat=ierr)
do i = 1,npts
read (iounit,'(2f12.3,a)',iostat=ierr) x1,y1,chead
read(chead(2:8),*)id1
read(chead(35:40),*)dpt
x(i) = real(x1,8)
y(i) = real(y1,8)
id(i) = int(id1,4)
end do
close(iounit)
mapped = .true.
allocate(xx(1))
allocate(yy(1))
! bad: i=10,12,39,66,70,103,110,115,119,122,127,144,176,177,185,187,205
do i = 1,npts
xx(1) = x(i)
yy(1) = y(i)
!if(iaproc == 1)print '(a,i5,2f12.3)','working on point number ',i,xx(1),yy(1)
!if (ESMF_LocStreamIsCreated(LS)) print *,'LS is created'
! 1 point location at a time
LS = ESMF_LocStreamCreate(maxIndex=1, indexflag=ESMF_INDEX_GLOBAL, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
call ESMF_LocStreamAddKey(LS, keyName="ESMF:Lat", farray=yy, &
datacopyflag=ESMF_DATACOPY_REFERENCE, keyUnits="Degrees", keyLongName="Latitude", rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
call ESMF_LocStreamAddKey(LS, keyName="ESMF:Lon", farray=xx, &
datacopyflag=ESMF_DATACOPY_REFERENCE, keyUnits="Degrees", keyLongName="Longitude", rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
call ESMF_LocStreamGetBounds(LS, exclusiveLBound=elb, exclusiveUBound=eub, exclusiveCount=ecnt,rc=rc)
!print *,iaproc,ecnt
! allocate(pntlist(2*ecnt))
! allocate(petlist(ecnt))
! pntlist = 0.0
! petlist = 0
! if(ecnt == 1)then
! pntlist(1) = xx(1)
! pntlist(2) = yy(1)
! endif
! !print *,iaproc,pntlist
! call ESMF_MeshFindPnt(Emesh2, unmappedaction=ESMF_UNMAPPEDACTION_IGNORE, &
! pntDim=2, pntCount=ecnt, pntList=pntList, &
! petList=petList, rc=rc)
! if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
! ! print *,petlist
!if (ecnt > 0) then
do n = 1,petCount
!print '(i6,a,i6,2f12.2)',iaproc,' projecting ....',i,xx,yy
call findmapped(EMesh2,LS,xx,yy,i,iaproc,ecnt,mapstatus,rc)
mapped(n,i) = mapstatus
!if (.not. mapped(n,i)) cycle
print '(2i6,a,i6,2f12.2,l)',iaproc,ecnt,' findmapped ',i,xx,yy,mapstatus
end do
10 continue
!if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!if (.not. mapped(i)) continue
!end if
!project locstream onto mesh
!ptsLS = ESMF_LocstreamCreate(LS, background=Emesh2, rc=rc)
!ptsLS = ESMF_LocstreamCreate(LS2, background=Emesh2, unmappedaction = ESMF_UNMAPPEDACTION_ERROR, rc=rc)
! if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!if (rc /= ESMF_SUCCESS) unmapped(i) = .true.
!print *,iaproc,i,unmapped(i)
!call ESMF_LocStreamDestroy(ptsLS, noGarbage = .true., rc=rc)
call ESMF_LocStreamDestroy(LS, rc=rc)
!if (ESMF_LocStreamIsCreated(LS))call ESMF_LocStreamDestroy(LS, noGarbage = .true., rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!print *,'here0 ',i,mapped(i)
!call ESMF_LocStreamDestroy(LS2, rc=rc)
!if (ESMF_LocStreamIsCreated(LS2))call ESMF_LocStreamDestroy(LS2, noGarbage = .true., rc=rc)
!if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!print *,'here1'
!if (.not. unmapped(i))then
! if (ESMF_LocStreamIsCreated(ptsLS))call ESMF_LocStreamDestroy(ptsLS, noGarbage = .true., rc=rc)
!if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!print *,'here2'
!end if
end do
! call ESMF_LocStreamGetBounds(ptsLS, exclusiveLBound=elb, exclusiveUBound=eub, exclusiveCount=ecnt,rc=rc)
! if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
! print *,'bkgrd: pet=',iaproc,' elb,eub,ecnt= ',elb,eub,ecnt
!call ESMF_LocStreamGetKey(ptsLS, keyName="ESMF:Lat", farray=lsyy, rc=rc)
!if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!call ESMF_LocStreamGetKey(ptsLS, keyName="ESMF:Lon", farray=lsxx, rc=rc)
!if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!call ESMF_LocStreamGetKey(ptsLS, keyName="ESMF:ObsID", farray=lsid, rc=rc)
!if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!do i = elb,eub
! print '(2i6,3f12.2)',iaproc,i,lsxx(i),lsyy(i)
!end do
!end if
end program testloc