-
Notifications
You must be signed in to change notification settings - Fork 1
/
LatLonOutput.f90
413 lines (365 loc) · 11.6 KB
/
LatLonOutput.f90
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
module LatLonOutputModule
!******************************************************************************
! Peter A. Bosler
! Department of Mathematics
! University of Michigan
!
!******************************************************************************
!
! Defines output data structures and methods for plotting Lagrangian meshes of the sphere.
!
! Bosler, P.A., "Particle Methods for Geophysical Flow on the Sphere," PhD Thesis; the University of Michigan, 2013.
!
!----------------
use NumberKindsModule
use SphereGeomModule
use IntegerListModule
use LoggerModule
use ParticlesModule
use EdgesModule
use PanelsModule
use SphereMeshModule
use STRIPACKInterfaceModule
use SSRFPACKInterfaceModule
implicit none
private
public LLSource
public New, Delete
public LLOutputMatlab, UpdateFilename
type LLSource
character(len = 256) :: filename
character(len = 128) :: title
type(STRIPACKData) :: delTri
type(SSRFPACKData) :: vectorSource
type(SSRFPACKData), pointer :: scalarSource => null()
integer(kint) :: nTracer
integer(kint) :: problemKind
type(SSRFPACKData), pointer :: tracerSource => null()
integer(kint) :: nLon
real(kreal), pointer :: lats(:) => null(),&
lons(:) => null()
end type
!
!----------------
! Logging
!----------------
!
logical(klog), save :: logInit = .FALSE.
type(Logger) :: log
character(len=28), save :: logKey = 'LatLonOutput'
integer(kint), parameter :: logLevel = DEBUG_LOGGING_LEVEL
character(len=28) :: formatString
character(len=128) :: logString
!
!----------------
! Interfaces
!----------------
!
interface New
module procedure NewPrivate
end interface
interface Delete
module procedure DeletePrivate
end interface
interface UpdateFilename
module procedure UpdateFilenameLL
end interface
contains
!
!----------------
! Standard methods : Constructor / Destructor, Copy
!----------------
!
subroutine NewPrivate(self,aMesh,filename,nLon)
type(LLSource), intent(out) :: self
type(SphereMesh), intent(in) :: aMesh
character(len=*), intent(in) :: filename
integer(kint), intent(in), optional :: nLon
! local variables
real(kreal) :: dLambda
integer(kint) :: j
if (.not. logInit) call InitLogger(log,procRank)
self%filename = filename
self%nLon = nLon
if ( present(nLon) ) then
dLambda = 2.0_kreal*PI/real(nLon,kreal)
else
dLambda = PI/180.0_kreal
endif
allocate(self%lons(nLon))
allocate(self%lats(nLon/2 + 1))
do j=1,nLon
self%lons(j) = (j-1)*dLambda
enddo
do j=1,nLon/2+1
self%lats(j) = -PI/2.0_kreal + (j-1)*dLambda
enddo
call New(self%delTri,aMesh)
call DelaunayTriangulation(self%delTri)
call New(self%vectorSource,self%delTri,.TRUE.)
self%problemKind = aMesh%problemKind
if ( self%problemKind /= ADVECTION_SOLVER ) then
allocate(self%scalarSource)
call New(self%scalarSource,self%delTri,.FALSE.)
endif
self%nTracer = aMesh%nTracer
if ( self%nTracer > 0 ) then
allocate(self%tracerSource)
call New(self%tracerSource, self%delTri, self%nTracer)
endif
end subroutine
subroutine DeletePrivate(self)
type(LLSource), intent(inout) :: self
deallocate(self%lats)
deallocate(self%lons)
call Delete(self%deltri)
call Delete(self%scalarSource)
call Delete(self%vectorSource)
if ( self%nTracer > 0 ) then
call Delete(self%tracerSource)
deallocate(self%tracerSource)
endif
if ( associated(self%scalarSource) ) then
call Delete(self%scalarSource)
deallocate(self%scalarSource)
endif
end subroutine
!
!----------------
! Public functions
!----------------
!
subroutine UpdateFileNameLL(self,filename)
type(LLSource), intent(inout) :: self
character(len=*), intent(in) :: filename
self%filename = trim(filename)
end subroutine
subroutine LLOutputMatlab(self,aMesh)
type(LLSource), intent(inout) :: self
type(SphereMesh), intent(in) :: aMesh
!
integer(kint) :: i, j, k, writeStat
real(kreal) :: interpVector(3), interpScalar, xyzLoc(3), lonUnitVector(3), latUnitVector(3)
real(kreal), allocatable :: llgrid1(:,:), llgrid2(:,:)
! open output file
open(unit = WRITE_UNIT_1, file = self%filename, status = 'REPLACE', action = 'WRITE', iostat = writeStat)
if ( writeStat /= 0 ) then
call LogMessage(log,ERROR_LOGGING_LEVEL,'LLOutputMatlab : ', 'ERROR opening output file.')
return
endif
! write lon/lat vectors
write(WRITE_UNIT_1,'(A)',ADVANCE = 'NO') 'lon = [ '
do i=1,self%nlon-1
write(WRITE_UNIT_1,'(F24.15,A)') self%lons(i), '; ...'
enddo
write(WRITE_UNIT_1,'(F24.15,A)') self%lons(self%nLon), ' ] ; '
write(WRITE_UNIT_1,'(A)',advance = 'NO') 'lat = [ '
do i=1,self%nlon/2
write(WRITE_UNIT_1,'(F24.15,A)') self%lats(i), '; ...'
enddo
write(WRITE_UNIT_1,'(F24.15,A)') self%lats(self%nlon/2+1), ' ] ;'
allocate(llgrid1(self%nLon/2+1,self%nLon))
llgrid1 = 0.0_kreal
allocate(llgrid2(self%nLon/2+1,self%nLon))
llgrid2 = 0.0_kreal
!
! Lagrangian parameter
!
call SetSourceLagrangianParameter(self%vectorSource,self%delTri)
do j=1,self%nLon
do i=1,self%nLon/2+1
xyzLoc = EARTH_RADIUS*[ cos(self%lats(i))*cos(self%lons(j)), &
cos(self%lats(i))*sin(self%lons(j)), sin(self%lats(i)) ]
interpVector = InterpolateVector(xyzLoc, self%vectorSource, self%delTri)
llgrid1(i,j) = Longitude(interpVector)
llgrid2(i,j) = Latitude(interpVector)
enddo
enddo
write(WRITE_UNIT_1,'(A)',advance = 'NO') ' alphaLongitude = [ '
do i=1,self%nLon/2
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid1(i,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid1(i,self%nLon), ' ; ...'
enddo
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid1(self%nLon/2+1,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid1(self%nLon/2+1,self%nLon), ' ] ; '
write(WRITE_UNIT_1,'(A)',advance = 'NO') ' alphaLatitude = [ '
do i=1,self%nLon/2
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid2(i,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid2(i,self%nLon), ' ; ...'
enddo
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid2(self%nLon/2+1,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid2(self%nLon/2+1,self%nLon), ' ] ; '
!
! velocity
!
call SetSourceVelocity(self%vectorSource,self%delTri)
llgrid1 = 0.0_kreal
llgrid2 = 0.0_kreal
do j=1,self%nLon
do i=2,self%nLon/2
xyzLoc = EARTH_RADIUS*[ cos(self%lats(i))*cos(self%lons(j)), &
cos(self%lats(i))*sin(self%lons(j)), sin(self%lats(i)) ]
interpVector = InterpolateVector(xyzLoc, self%vectorSource, self%delTri)
lonUnitVector = [ - xyzLoc(2), &
xyzLoc(1), 0.0_kreal ]
lonUnitVector = lonUnitVector/(EARTH_RADIUS*sqrt(EARTH_RADIUS*EARTH_RADIUS - xyzLoc(3)*xyzLoc(3)))
latUnitVector = [ -xyzLoc(1)*xyzLoc(3), &
-xyzLoc(2)*xyzLoc(3), &
EARTH_RADIUS*EARTH_RADIUS - xyzLoc(3)*xyzLoc(3) ]
latUnitVector = latUnitVector/(EARTH_RADIUS*EARTH_RADIUS*sqrt(EARTH_RADIUS*EARTH_RADIUS - xyzLoc(3)*xyzLoc(3)))
llgrid1(i,j) = sum(interpVector*lonUnitVector)
llgrid2(i,j) = sum(interpVector*latUnitVector)
enddo
enddo
write(WRITE_UNIT_1,'(A)',advance = 'NO') ' zonalVelocityU = [ '
do i=1,self%nLon/2
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid1(i,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid1(i,self%nLon), ' ; ...'
enddo
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid1(self%nLon/2+1,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid1(self%nLon/2+1,self%nLon), ' ] ; '
write(WRITE_UNIT_1,'(A)',advance = 'NO') ' meridionalVelocityV = [ '
do i=1,self%nLon/2
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid2(i,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid2(i,self%nLon), ' ; ...'
enddo
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid2(self%nLon/2+1,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid2(self%nLon/2+1,self%nLon), ' ] ; '
!
! tracers
!
if ( self%nTracer > 0 ) then
call SetSourceTracer(self%tracerSource, self%delTri)
llgrid1 = 0.0_kreal
do k = 1, self%nTracer
do j=1,self%nLon
do i=1,self%nLon/2 + 1
xyzLoc = EARTH_RADIUS*[ cos(self%lats(i))*cos(self%lons(j)), &
cos(self%lats(i))*sin(self%lons(j)), sin(self%lats(i)) ]
llgrid1(i,j) = InterpolateTracer(xyzLoc, self%tracerSource, self%delTri, k)
enddo
enddo
write(WRITE_UNIT_1,'(A,I1,A)',advance = 'NO') ' tracer', k,' = [ '
do i=1,self%nLon/2
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid1(i,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid1(i,self%nLon), ' ; ...'
enddo
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid1(self%nLon/2+1,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid1(self%nLon/2+1,self%nLon), ' ] ; '
enddo
endif
!
! bve variables
!
if ( self%problemKind == BVE_SOLVER) then
!
! absolute vorticity
!
llgrid1 = 0.0_kreal
call SetSourceAbsVort(self%scalarSource,self%delTri)
do j=1,self%nLon
do i=1,self%nLon/2 + 1
xyzLoc = EARTH_RADIUS*[ cos(self%lats(i))*cos(self%lons(j)), &
cos(self%lats(i))*sin(self%lons(j)), sin(self%lats(i)) ]
llgrid1(i,j) = InterpolateScalar(xyzLoc, self%scalarSource, self%delTri)
enddo
enddo
write(WRITE_UNIT_1,'(A)',advance = 'NO') ' absVort = [ '
do i=1,self%nLon/2
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid1(i,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid1(i,self%nLon), ' ; ...'
enddo
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid1(self%nLon/2+1,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid1(self%nLon/2+1,self%nLon), ' ] ; '
!
! relative vorticity
!
llgrid1 = 0.0_kreal
call SetSourceRelVort(self%scalarSource,self%delTri)
do j=1,self%nLon
do i=1,self%nLon/2 + 1
xyzLoc = EARTH_RADIUS*[ cos(self%lats(i))*cos(self%lons(j)), &
cos(self%lats(i))*sin(self%lons(j)), sin(self%lats(i)) ]
llgrid1(i,j) = InterpolateScalar(xyzLoc, self%scalarSource, self%delTri)
enddo
enddo
write(WRITE_UNIT_1,'(A)',advance = 'NO') ' relVort = [ '
do i=1,self%nLon/2
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid1(i,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid1(i,self%nLon), ' ; ...'
enddo
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid1(self%nLon/2+1,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid1(self%nLon/2+1,self%nLon), ' ] ; '
!
! kinetic energy
!
llgrid1 = 0.0_kreal
call SetSourceKineticEnergy(self%scalarSource,self%delTri)
do j=1,self%nLon
do i=1,self%nLon/2 + 1
xyzLoc = EARTH_RADIUS*[ cos(self%lats(i))*cos(self%lons(j)), &
cos(self%lats(i))*sin(self%lons(j)), sin(self%lats(i)) ]
llgrid1(i,j) = InterpolateScalar(xyzLoc, self%scalarSource, self%delTri)
enddo
enddo
write(WRITE_UNIT_1,'(A)',advance = 'NO') ' ke = [ '
do i=1,self%nLon/2
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid1(i,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid1(i,self%nLon), ' ; ...'
enddo
do j=1,self%nLon -1
write(WRITE_UNIT_1,'(F24.10)',advance='NO') llgrid1(self%nLon/2+1,j)
enddo
write(WRITE_UNIT_1,'(F24.10, A)',advance='YES') llgrid1(self%nLon/2+1,self%nLon), ' ] ; '
endif
!
! TO DO : SWE VARIABLES
!
deallocate(llgrid1)
deallocate(llgrid2)
close(WRITE_UNIT_1)
end subroutine
!
!----------------
! Module methods : type-specific functions
!----------------
!
subroutine InitLogger(aLog,rank)
type(Logger), intent(inout) :: aLog
integer(kint), intent(in) :: rank
write(logKey,'(A,A,I0.2,A)') trim(logKey),'_',rank,' : '
call New(aLog,logLevel)
logInit = .TRUE.
end subroutine
end module