-
Notifications
You must be signed in to change notification settings - Fork 1
/
wwm_grid.F90
495 lines (478 loc) · 21.9 KB
/
wwm_grid.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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE SINGLE_READ_SPATIAL_GRID_TOTAL(eGrid, DimMode, LVAR1D, Lsphe, eGRD, iGridType)
USE DATAPOOL, only : rkind, istat, GridInformation, FILEDEF, DBG
#ifdef NCDF
USE NETCDF
#endif
IMPLICIT NONE
type(GridInformation), intent(out) :: eGrid
integer, intent(in) :: DimMode
logical, intent(in) :: LVAR1D
logical, intent(in) :: Lsphe
type(FILEDEF), intent(in) :: eGRD
integer, intent(in) :: iGridType
!
INTEGER :: I, IP, IE, ITMP, JTMP
REAL(rkind) :: XPDTMP, YPDTMP, ZPDTMP
REAL(rkind) DXP1, DXP2, DXP3, DYP1, DYP2, DYP3
INTEGER KTMP, LTMP, MTMP, NTMP, OTMP
CHARACTER(LEN=100) :: RHEADER
#ifdef NCDF
INTEGER :: ncid, dimidsB(2), dimidsA(1)
character (len=20) :: MNEstr, MNPstr
INTEGER var_id1, var_id2, var_id
character (len = *), parameter :: CallFct="SINGLE_READ_SPATIAL_GRID_TOTAL"
#endif
CALL TEST_FILE_EXIST_DIE('Missing grid file : ', eGRD % FNAME)
SELECT CASE (DimMode)
CASE (1)
!
! This code is broken.
! The np_total has not been assigned here
!
OPEN(eGRD % FHNDL, FILE = eGRD % FNAME, STATUS = 'OLD')
allocate(eGrid % XPtotal(eGrid % np_total), eGrid % DEPtotal(eGrid % np_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_input, allocate error 3')
DO IP = 1, eGrid % NP_TOTAL
READ(eGRD % FHNDL, *, IOSTAT = ISTAT) eGrid % XPtotal(IP), eGrid % DEPtotal(IP)
IF ( ISTAT /= 0 ) CALL WWM_ABORT('error in the grid configuration file')
END DO
IF (LVAR1D) THEN
eGrid % DX1total(0) = eGrid % XPtotal(2)- eGrid % XPtotal(1)
eGrid % DX1total(1) = eGrid % DX1total(0)
eGrid % DX1total(eGrid%np_total) = eGrid % XPtotal(eGrid%np_total) - eGrid % XPtotal(eGrid%np_total-1)
eGrid % DX1total(eGrid%np_total+1) = eGrid % DX1total(eGrid%np_total)
eGrid % DX2total(0) = eGrid % DX1total(0)
eGrid % DX2total(eGrid%np_total+1) = eGrid % DX1total(eGrid%np_total)
DO IP = 2, eGrid % NP_TOTAL-1 ! Bandwith at gridpoints
eGrid % DX1total(IP) = (eGrid % XPtotal(IP) - eGrid % XPtotal(IP-1))/2. + (eGrid % XPtotal(IP+1) - eGrid % XPtotal(IP))/2.
END DO
DO IP = 2, eGrid % NP_TOTAL ! Stepwidth between gridpoints K and K-1
eGrid % DX2total(IP) = eGrid % XPtotal(IP) - eGrid % XPtotal(IP-1)
END DO
eGrid % DX2total(1) = eGrid % DX1total(0)
END IF
CLOSE(eGRD % FHNDL)
CASE (2)
IF (IGRIDTYPE == 1) THEN ! system.dat format ... XFN
OPEN(eGRD % FHNDL, FILE = eGRD % FNAME, STATUS = 'OLD')
DO I = 1, 2
READ(eGRD % FHNDL, '(A)') RHEADER
END DO
READ(eGRD % FHNDL, *, IOSTAT = ISTAT) ITMP
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=1 error in read mnp/mne')
READ(eGRD % FHNDL, '(A)') RHEADER
READ(eGRD % FHNDL, *, IOSTAT = ISTAT) JTMP
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=1 error in read mnp/mne')
EGRID%NP_TOTAL = ITMP + JTMP
allocate(eGrid % XPtotal(eGrid%np_total), eGrid % YPtotal(eGrid%np_total), eGrid % DEPtotal(eGrid%np_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_input, allocate error 4')
DO I = 1, 7
READ(eGRD % FHNDL, '(A)') RHEADER
END DO
DO IP=1,EGRID%NP_TOTAL
READ(eGRD % FHNDL, *, IOSTAT = ISTAT) KTMP, eGrid % XPtotal(IP), eGrid % YPtotal(IP), eGrid % DEPtotal(IP)
IF (KTMP+1.ne.IP) THEN
CALL WWM_ABORT('IGRIDTYPE=1 error in grid read 3')
ENDIF
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=1 error in grid read 4')
END DO
DO I = 1, 2
READ(eGRD % FHNDL, '(A)') RHEADER
END DO
READ(eGRD % FHNDL, *, IOSTAT = ISTAT) eGrid % NE_TOTAL
allocate(eGrid % INEtotal(3, eGrid%ne_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_input, allocate error 5')
DO I = 1, 3
READ(eGRD % FHNDL, '(A)') RHEADER
END DO
DO IE=1,EGRID%NE_TOTAL
READ(eGRD % FHNDL, *, IOSTAT = ISTAT) KTMP, LTMP, MTMP, NTMP, OTMP
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=1 error in grid read 5')
eGrid % INEtotal(1,IE)=KTMP+1
eGrid % INEtotal(2,IE)=LTMP+1
eGrid % INEtotal(3,IE)=MTMP+1
END DO
CLOSE(eGRD % FHNDL)
ELSE IF (IGRIDTYPE == 2) THEN ! periodic grid written by mathieu dutour
OPEN(eGRD%FHNDL, FILE = eGRD%FNAME, STATUS = 'OLD')
READ(eGRD%FHNDL,*) EGRID%NE_TOTAL, EGRID%NP_TOTAL
allocate(eGrid % DEPtotal(EGRID%NP_TOTAL), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_input, allocate error 6')
DO IP = 1, EGRID%NP_TOTAL
READ(eGRD%FHNDL, *, IOSTAT = ISTAT) eGrid % DEPtotal(IP)
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=2 error in grid read 1')
END DO
allocate(eGrid%TRIAtotal(EGRID%NE_TOTAL), eGrid % INEtotal(3,eGrid%ne_total), eGrid % IENtotal(6,eGrid%ne_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_input, allocate error 7')
DO IE = 1, EGRID%NE_TOTAL
READ(eGRD%FHNDL, *, IOSTAT = ISTAT) eGrid % TRIAtotal(IE)
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=2 error in grid read 2')
READ(eGRD%FHNDL, *, IOSTAT = ISTAT) eGrid % INEtotal(:,IE)
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=2 error in grid read 3')
READ(eGRD%FHNDL, *, IOSTAT = ISTAT) DXP1, DXP2, DXP3
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=2 error in grid read 4')
READ(eGRD%FHNDL, *, IOSTAT = ISTAT) DYP1, DYP2, DYP3
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=2 error in grid read 5')
eGrid % IENtotal(1,IE) = -DYP2
eGrid % IENtotal(2,IE) = DXP2
eGrid % IENtotal(3,IE) = -DYP3
eGrid % IENtotal(4,IE) = DXP3
eGrid % IENtotal(5,IE) = -DYP1
eGrid % IENtotal(6,IE) = DXP1
END DO
CLOSE(eGRD%FHNDL)
ELSE IF (IGRIDTYPE == 3) THEN ! SCHISM gr3
OPEN(eGRD%FHNDL, FILE = eGRD%FNAME, STATUS = 'OLD')
READ(eGRD%FHNDL,*)
READ(eGRD%FHNDL,*, IOSTAT = ISTAT) EGRID%NE_TOTAL, EGRID%NP_TOTAL
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=3 error in read mnp/mne')
allocate(eGrid % XPtotal(eGrid%np_total), eGrid % YPtotal(eGrid%np_total), eGrid % DEPtotal(eGrid%np_total), eGrid % INEtotal(3, eGrid%ne_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_input, allocate error 8')
DO IP=1,EGRID%NP_TOTAL
READ(eGRD%FHNDL, *, IOSTAT = ISTAT) KTMP, XPDTMP, YPDTMP, ZPDTMP
eGrid % XPtotal(IP) = XPDTMP
eGrid % YPtotal(IP) = YPDTMP
eGrid % DEPtotal(IP) = ZPDTMP
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=3 error in grid reading 1')
END DO
DO IE = 1, EGRID%NE_TOTAL
READ(eGRD%FHNDL, *, IOSTAT = ISTAT) KTMP, LTMP, eGrid % INEtotal(:,IE)
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=3 error in grid reading 2')
END DO
CLOSE(eGRD%FHNDL)
ELSE IF (IGRIDTYPE == 4) THEN ! Old WWM format
OPEN(eGRD%FHNDL, FILE = eGRD%FNAME, STATUS = 'OLD')
READ(eGRD%FHNDL, *, IOSTAT = ISTAT) EGRID%NE_TOTAL
READ(eGRD%FHNDL, *, IOSTAT = ISTAT) EGRID%NP_TOTAL
allocate(eGrid % XPtotal(eGrid%np_total), eGrid % YPtotal(eGrid%np_total), eGrid % DEPtotal(eGrid%np_total), eGrid%INEtotal(3, eGrid%ne_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('allocate error 9')
DO IP=1,EGRID%NP_TOTAL
READ(eGRD%FHNDL, *, IOSTAT = ISTAT) eGrid % XPtotal(IP), eGrid % YPtotal(IP), eGrid % DEPtotal(IP)
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=4 error in grid read 1')
END DO
DO IE=1,EGRID%NE_TOTAL
READ(eGRD%FHNDL, *, IOSTAT = ISTAT) eGrid % INEtotal(:,IE)
IF ( ISTAT /= 0 ) CALL WWM_ABORT('IGRIDTYPE=4 error in grid read 2')
END DO
CLOSE(eGRD%FHNDL)
#ifdef NCDF
ELSE IF (IGRIDTYPE == 5) THEN ! Netcdf format
ISTAT = NF90_OPEN(eGRD%FNAME, NF90_NOWRITE, ncid)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 1, ISTAT)
ISTAT = nf90_inq_varid(ncid, 'ele', var_id)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 2, ISTAT)
ISTAT = nf90_inquire_variable(ncid, var_id, dimids=dimidsB)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 3, ISTAT)
ISTAT = nf90_inquire_dimension(ncid, dimidsB(2), name=MNEstr, len=eGrid%ne_total)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 4, ISTAT)
WRITE(DBG%FHNDL,*) 'EGRID%NE_TOTAL=', EGRID%NE_TOTAL
WRITE(DBG%FHNDL,*) 'MNEstr=', TRIM(MNEstr)
FLUSH(DBG%FHNDL)
ISTAT = nf90_inq_varid(ncid, 'depth', var_id)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 5, ISTAT)
ISTAT = nf90_inquire_variable(ncid, var_id, dimids=dimidsA)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 6, ISTAT)
ISTAT = nf90_inquire_dimension(ncid, dimidsA(1), name=MNPstr, len=eGrid%np_total)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 7, ISTAT)
WRITE(DBG%FHNDL,*) 'EGRID%NP_TOTAL=', EGRID%NP_TOTAL
WRITE(DBG%FHNDL,*) 'MNPstr=', TRIM(MNPstr)
FLUSH(DBG%FHNDL)
allocate(eGrid % XPtotal(eGrid%np_total), eGrid % YPtotal(eGrid%np_total), eGrid % DEPtotal(eGrid%np_total), eGrid%INEtotal(3, eGrid%ne_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('allocate error 9')
ISTAT = nf90_inq_varid(ncid, 'depth', var_id)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 8, ISTAT)
ISTAT = nf90_get_var(ncid, var_id, eGrid % DEPtotal)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 9, ISTAT)
ISTAT = nf90_inq_varid(ncid, 'ele', var_id)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 10, ISTAT)
ISTAT = nf90_get_var(ncid, var_id, eGrid % INEtotal)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 11, ISTAT)
IF (LSPHE) THEN
ISTAT = nf90_inq_varid(ncid, 'lon', var_id1)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 12, ISTAT)
ISTAT = nf90_inq_varid(ncid, 'lat', var_id2)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 13, ISTAT)
ELSE
ISTAT = nf90_inq_varid(ncid, 'x', var_id1)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 14, ISTAT)
ISTAT = nf90_inq_varid(ncid, 'y', var_id2)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 15, ISTAT)
END IF
ISTAT = nf90_get_var(ncid, var_id1, eGrid % XPtotal)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 16, ISTAT)
ISTAT = nf90_get_var(ncid, var_id2, eGrid % YPtotal)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 17, ISTAT)
ISTAT = NF90_CLOSE(ncid)
CALL GENERIC_NETCDF_ERROR_WWM(CallFct, 18, ISTAT)
#endif
ELSE
CALL WWM_ABORT('IGRIDTYPE WRONG')
END IF
DO IE=1,EGRID%NE_TOTAL
DO I=1,3
IP=eGrid % INEtotal(I,IE)
IF ((IP .lt. 1).or.(IP.gt.EGRID%NP_TOTAL)) THEN
Print *, 'IE=', IE, ' I=', I
Print *, 'IP=', IP, ' EGRID%NP_TOTAL=', EGRID%NP_TOTAL
CALL WWM_ABORT('INCOHERENCY IN INEtotal')
END IF
END DO
END DO
CASE DEFAULT
CALL WWM_ABORT('WRONG GRID DIMENSION')
END SELECT
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE READ_SPATIAL_GRID_TOTAL_KERNEL(eGrid, DimMode, LVAR1D, Lsphe, eGRD, iGridType)
USE DATAPOOL, only : rkind, istat, GridInformation, FILEDEF
IMPLICIT NONE
type(GridInformation), intent(out) :: eGrid
integer, intent(in) :: DimMode
logical, intent(in) :: LVAR1D
logical, intent(in) :: Lsphe
type(FILEDEF), intent(in) :: eGRD
integer, intent(in) :: iGridType
!
integer :: rbuf_int(2)
real(rkind), allocatable :: rbuf_real(:)
integer iProc, IP, IE, nb_real, idx
#ifdef MPI_PARALL_GRID
IF (MULTIPLE_IN_GRID) THEN
CALL SINGLE_READ_SPATIAL_GRID_TOTAL(eGrid, DimMode, LVAR1D, Lsphe, eGRD, iGridType)
ELSE
IF (DIMMODE .ne. 2) THEN
CALL WWM_ABORT('Parallel mode only for 2D')
ENDIF
IF (myrank .eq. 0) THEN
CALL SINGLE_READ_SPATIAL_GRID_TOTAL(eGrid, DimMode, LVAR1D, Lsphe, eGRD, iGridType)
rbuf_int(1)=eGrid % np_total
rbuf_int(2)=eGrid % ne_total
DO iProc=2,nproc
CALL MPI_SEND(rbuf_int,2,itype, iProc-1, 30, comm, ierr)
END DO
DO iProc=2,nproc
CALL MPI_SEND(INEtotal,3*eGrid % ne_total,itype, iProc-1, 32, comm, ierr)
END DO
IF (IGRIDTYPE .eq. 2) THEN
nb_real=eGrid % np_total + 7*eGrid % ne_total
allocate(rbuf_real(nb_real), stat=istat)
IF (istat/=0) CALL WWM_ABORT('allocate error 10')
idx=0
DO IP=1,NP_TOTAL
idx=idx+1
rbuf_real(idx)=eGrid % DEPtotal(IP)
END DO
DO IE=1,eGrid % NE_TOTAL
rbuf_real(idx+1)=eGrid % TRIAtotal(IE)
rbuf_real(idx+2)=eGrid % IENtotal(1,IE)
rbuf_real(idx+3)=eGrid % IENtotal(2,IE)
rbuf_real(idx+4)=eGrid % IENtotal(3,IE)
rbuf_real(idx+5)=eGrid % IENtotal(4,IE)
rbuf_real(idx+6)=eGrid % IENtotal(5,IE)
rbuf_real(idx+7)=eGrid % IENtotal(6,IE)
idx=idx+7
END DO
ELSE
nb_real=3*eGrid % np_total
allocate(rbuf_real(nb_real), stat=istat)
IF (istat/=0) CALL WWM_ABORT('allocate error 11')
idx=0
DO IP=1,NP_TOTAL
rbuf_real(idx+1)=eGrid % XPtotal(IP)
rbuf_real(idx+2)=eGrid % YPtotal(IP)
rbuf_real(idx+3)=eGrid % DEPtotal(IP)
idx=idx+3
END DO
END IF
DO iProc=2,nproc
CALL MPI_SEND(rbuf_real,nb_real,rtype, iProc-1, 34, comm, ierr)
END DO
deallocate(rbuf_real)
ELSE
CALL MPI_RECV(rbuf_int,2,itype, 0, 30, comm, istatus, ierr)
eGrid % np_total=rbuf_int(1)
eGrid % ne_total=rbuf_int(2)
allocate(eGrid % INEtotal(3,eGrid % ne_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('allocate error 12')
CALL MPI_RECV(eGrid % INEtotal,3*eGrid % ne_total,itype, 0, 32, comm, istatus, ierr)
IF (IGRIDTYPE .eq. 2) THEN
nb_real=eGrid % np_total + 7*eGrid % ne_total
allocate(rbuf_real(nb_real), stat=istat)
IF (istat/=0) CALL WWM_ABORT('allocate error 13')
CALL MPI_RECV(rbuf_real,nb_real,rtype, 0, 34, comm, istatus, ierr)
allocate(eGrid % DEPtotal(eGrid % np_total), eGrid % TRIAtotal(eGrid % ne_total), eGrid % IENtotal(6,eGrid % ne_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('allocate error 14')
idx=0
DO IP=1,eGrid % NP_TOTAL
idx=idx+1
eGrid % DEPtotal(IP)=rbuf_real(idx)
END DO
DO IE=1,eGrid % NE_TOTAL
eGrid % TRIAtotal(IE)=rbuf_real(idx+1)
eGrid % IENtotal(1,IE)=rbuf_real(idx+2)
eGrid % IENtotal(2,IE)=rbuf_real(idx+3)
eGrid % IENtotal(3,IE)=rbuf_real(idx+4)
eGrid % IENtotal(4,IE)=rbuf_real(idx+5)
eGrid % IENtotal(5,IE)=rbuf_real(idx+6)
eGrid % IENtotal(6,IE)=rbuf_real(idx+7)
idx=idx+7
END DO
ELSE
nb_real=3*np_total
allocate(rbuf_real(nb_real), stat=istat)
IF (istat/=0) CALL WWM_ABORT('allocate error 15')
allocate(eGrid % DEPtotal(np_total), eGrid % XPtotal(np_total), eGrid % YPtotal(np_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('allocate error 16')
CALL MPI_RECV(rbuf_real,nb_real,rtype, 0, 34, comm, istatus, ierr)
idx=0
DO IP=1,NP_TOTAL
eGrid % XPtotal(IP) = rbuf_real(idx+1)
eGrid % YPtotal(IP) = rbuf_real(idx+2)
eGrid % DEPtotal(IP)= rbuf_real(idx+3)
idx=idx+3
END DO
END IF
deallocate(rbuf_real)
END IF
END IF
#else
CALL SINGLE_READ_SPATIAL_GRID_TOTAL(eGrid, DimMode, LVAR1D, Lsphe, eGRD, iGridType)
#endif
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE READ_SPATIAL_GRID_TOTAL
USE DATAPOOL
IMPLICIT NONE
type(GridInformation) eGrid
integer IP, IE
CALL READ_SPATIAL_GRID_TOTAL_KERNEL(eGrid, DIMMODE, LVAR1D, LSPHE, GRD, IGRIDTYPE)
np_total = eGrid % np_total
ne_total = eGrid % ne_total
IF (DIMMODE .eq. 1) THEN
allocate(XPtotal(np_total), DEPtotal(np_total), DX1total(0:np_total+1), DX2total(0:np_total+1), stat=istat)
IF (istat/=0) CALL WWM_ABORT('allocate error')
DO IP=1,np_total
XPtotal(IP) = eGrid % XPtotal(IP)
DEPtotal(IP) = eGrid % DEPtotal(IP)
END DO
DO IP=0,np_total+1
DX1total(IP) = eGrid % DX1total(IP)
DX2total(IP) = eGrid % DX2total(IP)
END DO
ELSE
IF (IGRIDTYPE .eq. 2) THEN
allocate(DEPtotal(NP_TOTAL), TRIAtotal(NE_TOTAL), INEtotal(3,ne_total), IENtotal(6,ne_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_input, allocate error 6')
DO IP=1,np_total
DEPtotal(IP) = eGrid % DEPtotal(IP)
END DO
DO IE=1,ne_total
TRIAtotal(IE) = eGrid % TRIAtotal(IE)
INEtotal(:,IE) = eGrid % INEtotal(:,IE)
IENtotal(:,IE) = eGrid % IENtotal(:,IE)
END DO
ELSE
allocate(XPtotal(np_total), YPtotal(np_total), DEPtotal(np_total), INEtotal(3, eGrid%ne_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_input, allocate error 4')
DO IP=1,np_total
XPtotal(IP) = eGrid % XPtotal(IP)
YPtotal(IP) = eGrid % YPtotal(IP)
DEPtotal(IP) = eGrid % DEPtotal(IP)
END DO
DO IE=1,ne_total
INEtotal(:,IE) = eGrid % INEtotal(:,IE)
END DO
END IF
END IF
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE EXPORT_GRID_WW3_FORMAT
USE DATAPOOL
IMPLICIT NONE
INTEGER nbDirichlet, nbIsland
INTEGER :: MapDirect(np_total)
INTEGER :: MapRevert(np_total)
INTEGER, allocatable :: IPbound(:), IPisland(:), ACTIVE(:)
INTEGER IP, IE2, eVal, IE, idxDirichlet, idxIsland
#ifdef MPI_PARALL_GRID
IF (myrank .ne. 0) THEN
RETURN
END IF
#endif
nbDirichlet=0
nbIsland=0
DO IP=1,np_total
eVal=IOBPtotal(IP)
IF (eVal .eq. 2) THEN
nbDirichlet=nbDirichlet+1
END IF
IF ((eVal .eq. 1).or.(eVal .eq. 3).or.(eVal .eq. 4)) THEN
nbIsland=nbIsland+1
END IF
END DO
allocate(IPbound(nbDirichlet), IPisland(nbIsland), ACTIVE(nbDirichlet), stat=istat)
ACTIVE(:)=1 ! right now we are proceding this way. Maybe there is work here to improve
IF (istat/=0) CALL WWM_ABORT('allocate error 17')
idxDirichlet=0
idxIsland=0
DO IP=1,np_total
eVal=IOBPtotal(IP)
IF (eVal .eq. 2) THEN
idxDirichlet=idxDirichlet+1
IPbound(idxDirichlet)=IP
END IF
IF ((eVal .eq. 1).or.(eVal .eq. 3).or.(eVal .eq. 4)) THEN
idxIsland=idxIsland+1
IPisland(idxIsland)=IP
END IF
END DO
OPEN(FHNDL_EXPORT_GRID_WW3, FILE = 'mesh.msh', STATUS='unknown')
!
!*** write gmsh header
!
WRITE(FHNDL_EXPORT_GRID_WW3,'(A)') '$MeshFormat'
WRITE(FHNDL_EXPORT_GRID_WW3,'(A)') '2 0 8'
WRITE(FHNDL_EXPORT_GRID_WW3,'(A)') '$EndMeshFormat'
WRITE(FHNDL_EXPORT_GRID_WW3,'(A)') '$Nodes'
WRITE(FHNDL_EXPORT_GRID_WW3,*) np_total
DO IP = 1, np_total
WRITE(FHNDL_EXPORT_GRID_WW3,'(I10,3F30.20)') IP, XPtotal(IP), YPtotal(IP), DEPtotal(IP)
END DO
WRITE(FHNDL_EXPORT_GRID_WW3,'(A)') '$EndNodes'
WRITE(FHNDL_EXPORT_GRID_WW3,'(A)') '$Elements'
WRITE(FHNDL_EXPORT_GRID_WW3,*) ne_total + nbDirichlet + nbIsland
!
!*** write boundary
!
IE2=1
DO IP = 1, nbDirichlet
WRITE(FHNDL_EXPORT_GRID_WW3,'(6I10)') IE2, 15, 2, ACTIVE(IP), 0, IPbound(IP)
IE2=IE2+1
END DO
!
!*** write island
!
DO IP = 1, nbIsland
WRITE(FHNDL_EXPORT_GRID_WW3,'(6I10)') IE2, 15, 2, 0, IP, IPisland(IP)
IE2=IE2+1
END DO
!
!*** write gmsh elements
!
DO IE = 1, ne_total
WRITE(FHNDL_EXPORT_GRID_WW3,'(9I8)') IE2, 2, 3, 0, IE, 0, INE(1,IE), IEN(2,IE), IEN(3,IE)
IE2=IE2+1
END DO
WRITE(FHNDL_EXPORT_GRID_WW3,'(A)') '$EndElements'
CLOSE(FHNDL_EXPORT_GRID_WW3)
deallocate(IPbound, IPisland, ACTIVE)
END SUBROUTINE