-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_proj_wrf.f90
805 lines (705 loc) · 22.9 KB
/
map_proj_wrf.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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
!***********************************************************************
!* Copyright 2012,2013 *
!* Jerome Brioude, Delia Arnold, Andreas Stohl, Wayne Angevine, *
!* John Burkhart, Massimo Cassiani, Adam Dingwell, Richard C Easter, Sabine Eckhardt,*
!* Stephanie Evan, Jerome D Fast, Don Morton, Ignacio Pisso, *
!* Petra Seibert, Gerard Wotawa, Caroline Forster, Harald Sodemann, *
!* *
!* This file is part of FLEXPART WRF *
!* *
!* FLEXPART is free software: you can redistribute it and/or modify *
!* it under the terms of the GNU General Public License as published by*
!* the Free Software Foundation, either version 3 of the License, or *
!* (at your option) any later version. *
!* *
!* FLEXPART is distributed in the hope that it will be useful, *
!* but WITHOUT ANY WARRANTY; without even the implied warranty of *
!* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
!* GNU General Public License for more details. *
!* *
!* You should have received a copy of the GNU General Public License *
!* along with FLEXPART. If not, see <http://www.gnu.org/licenses/>. *
!***********************************************************************
!**********************************************************************
! FLEXPART_WRF SOURCE FILE MAP_PROJ_WRF - CONTAINS *
! subroutine xyindex_to_ll_wrf *
! subroutine xymeter_to_ll_wrf *
! subroutine ll_to_xyindex_wrf *
! subroutine ll_to_xymeter_wrf *
! subroutine test_xyindex_to_ll_wrf *
! *
!**********************************************************************
! *
! AUTHOR: R. Easter & J. Fast, PNNL *
! DATE: Dec 2005 *
! LAST UPDATE: same *
! *
!**********************************************************************
! *
! DESCRIPTION: *
! *
! Converts between "grid index" or "grid meter" coordinates *
! and latitude-longitude (degrees) *
! *
!**********************************************************************
!-----------------------------------------------------------------------
subroutine xyindex_to_ll_wrf( lgrid, x_i, y_j, x_lon, y_lat )
!
! calculates longitude/latitude from xy "grid index" coordinates
!
! arguments
! lgrid - input - grid identifier
! x_i, y_j - input = "grid index" coordinates on grid "lgrid".
! x_i ranges from 0 to nx-1. y_j ranges from 0 to nj-1.
! x_lon, y_lat - output = longitude and latitude in degrees
!
! *** note ***
! if x_i is outside [-grace, +grace+nx]
! or y_j is outside [-grace, +grace+ny]
! the routine writes an error message and halts
!
! include 'includepar'
! include 'includecom'
use par_mod
use com_mod
! arguments
implicit none
integer :: lgrid
real :: x_i, y_j, x_lon, y_lat
! local variables
integer :: ia, ib, ja, jb
real :: dumxi, dumyj
real :: fx, fy
real,parameter :: grace=2.01
! first check that x_i & y_j are "within bounds"
if (lgrid .le. 0) then
if ((x_i .lt. -grace) .or. (x_i .gt. grace+real(nx-1)) .or. &
(y_j .lt. -grace) .or. (y_j .gt. grace+real(ny-1))) then
write(*,'(/a/a,i4,1p,2e12.3)') &
'*** xyindex_to_ll_wrf error -- bad inputs', &
' lgrid, x_i, y_j =', lgrid, x_i, y_j
! stop
end if
else
if ((x_i .lt. -grace ) .or. &
(x_i .gt. grace+real(nxn(lgrid)-1)) .or. &
(y_j .lt. -grace ) .or. &
(y_j .gt. grace+real(nyn(lgrid)-1))) then
write(*,'(/a/a,i4,1p,2e12.3)') &
'*** xyindex_to_ll_wrf error -- bad inputs', &
' lgrid, x_i, y_j =', lgrid, x_i, y_j
! stop
end if
end if
if (map_proj_method .gt. 0) then
if (map_proj_id .eq. 1) goto 2000
if (map_proj_id .eq. 2) goto 2000
if (map_proj_id .eq. 3) goto 2000
if (map_proj_id .eq. 4) goto 2000
end if
if (lgrid .le. 0) then
goto 5000
else
goto 6000
end if
!
! use map projection routines in map_proj_wrf_subaa.f
!
2000 continue
if (lgrid .le. 0) then
dumxi = 1.0 + x_i
dumyj = 1.0 + y_j
else
dumxi = 1.0 + (x_i/xresoln(lgrid)) + xln(lgrid)
dumyj = 1.0 + (y_j/yresoln(lgrid)) + yln(lgrid)
end if
call ij_to_latlon( dumxi, dumyj, y_lat, x_lon )
return
!
! do interpolation using the outer grid xlon2d,ylat2d
!
5000 continue
if (x_i .le. 0.0) then
ia = 0
else if (x_i .ge. real(nxmin1)) then
ia = nxmin1
else
ia = ifix( x_i )
end if
fx = x_i - ia
fx = max( -2.0, min( fx, 3.0 ) )
ib = ia + 1
if (y_j .le. 0.0) then
ja = 0
else if (y_j .ge. real(nymin1)) then
ja = nymin1
else
ja = ifix( y_j )
end if
fy = y_j - ja
fy = max( -2.0, min( fy, 3.0 ) )
jb = ja + 1
x_lon = xlon2d(ia,ja)*(1.0-fx)*(1.0-fy) + &
xlon2d(ia,jb)*(1.0-fx)*fy + &
xlon2d(ib,ja)*fx*(1.0-fy) + &
xlon2d(ib,jb)*fx*fy
y_lat = ylat2d(ia,ja)*(1.0-fx)*(1.0-fy) + &
ylat2d(ia,jb)*(1.0-fx)*fy + &
ylat2d(ib,ja)*fx*(1.0-fy) + &
ylat2d(ib,jb)*fx*fy
return
!
! do interpolation using the nested grid xlon2dn,ylat2dn
!
6000 continue
if (x_i .le. 0.0) then
ia = 0
else if (x_i .ge. real(nxn(lgrid)-1)) then
ia = nxn(lgrid)-1
else
ia = ifix( x_i )
end if
fx = x_i - ia
fx = max( -2.0, min( fx, 3.0 ) )
ib = ia + 1
if (y_j .le. 0.0) then
ja = 0
else if (y_j .ge. real(nyn(lgrid)-1)) then
ja = nyn(lgrid)-1
else
ja = ifix( y_j )
end if
fy = y_j - ja
fy = max( -2.0, min( fy, 3.0 ) )
jb = ja + 1
x_lon = xlon2dn(ia,ja,lgrid)*(1.0-fx)*(1.0-fy) + &
xlon2dn(ia,jb,lgrid)*(1.0-fx)*fy + &
xlon2dn(ib,ja,lgrid)*fx*(1.0-fy) + &
xlon2dn(ib,jb,lgrid)*fx*fy
y_lat = ylat2dn(ia,ja,lgrid)*(1.0-fx)*(1.0-fy) + &
ylat2dn(ia,jb,lgrid)*(1.0-fx)*fy + &
ylat2dn(ib,ja,lgrid)*fx*(1.0-fy) + &
ylat2dn(ib,jb,lgrid)*fx*fy
return
end subroutine xyindex_to_ll_wrf
!-----------------------------------------------------------------------
subroutine xyindex_to_ll_wrf_out(lgrid,x_i,y_j,x_lon,y_lat)
!
! calculates longitude/latitude from xy "grid index" coordinates
!
! arguments
! lgrid - input - grid identifier
! x_i, y_j - input = "grid index" coordinates on grid "lgrid".
! x_i ranges from 0 to nx-1. y_j ranges from 0 to nj-1.
! x_lon, y_lat - output = longitude and latitude in degrees
!
! *** note ***
! if x_i is outside [-grace, +grace+nx]
! or y_j is outside [-grace, +grace+ny]
! the routine writes an error message and halts
!
! include 'includepar'
! include 'includecom'
use par_mod
use com_mod
! arguments
implicit none
integer :: lgrid
real :: x_i, y_j, x_lon, y_lat
! local variables
integer :: ia, ib, ja, jb
real :: dumxi, dumyj
real :: fx, fy
real,parameter :: grace=2.01
! first check that x_i & y_j are "within bounds"
! if (lgrid .le. 0) then
! if ((x_i .lt. -grace) .or. (x_i .gt. grace+real(nx-1)) .or.
! & (y_j .lt. -grace) .or. (y_j .gt. grace+real(ny-1))) then
! write(*,'(/a/a,i4,1p,2e12.3)')
! & '*** xyindex_to_ll_wrf error -- bad inputs',
! & ' lgrid, x_i, y_j =', lgrid, x_i, y_j
! stop
! end if
! else
! if ((x_i .lt. -grace ) .or.
! & (x_i .gt. grace+real(nxn(lgrid)-1)) .or.
! & (y_j .lt. -grace ) .or.
! & (y_j .gt. grace+real(nyn(lgrid)-1))) then
! write(*,'(/a/a,i4,1p,2e12.3)')
! & '*** xyindex_to_ll_wrf error -- bad inputs',
! & ' lgrid, x_i, y_j =', lgrid, x_i, y_j
! stop
! end if
! end if
if (map_proj_method .gt. 0) then
if (map_proj_id .eq. 1) goto 2000
if (map_proj_id .eq. 2) goto 2000
if (map_proj_id .eq. 3) goto 2000
if (map_proj_id .eq. 4) goto 2000
end if
if (lgrid .le. 0) then
goto 5000
else
goto 6000
end if
!
! use map projection routines in map_proj_wrf_subaa.f
!
2000 continue
if (lgrid .le. 0) then
dumxi = 1.0 + x_i
dumyj = 1.0 + y_j
else
dumxi = 1.0 + (x_i/xresoln(lgrid)) + xln(lgrid)
dumyj = 1.0 + (y_j/yresoln(lgrid)) + yln(lgrid)
end if
call ij_to_latlon( dumxi, dumyj, y_lat, x_lon )
return
!
! do interpolation using the outer grid xlon2d,ylat2d
!
5000 continue
if (x_i .le. 0.0) then
ia = 0
else if (x_i .ge. real(nxmin1)) then
ia = nxmin1
else
ia = ifix( x_i )
end if
fx = x_i - ia
fx = max( -2.0, min( fx, 3.0 ) )
ib = ia + 1
if (y_j .le. 0.0) then
ja = 0
else if (y_j .ge. real(nymin1)) then
ja = nymin1
else
ja = ifix( y_j )
end if
fy = y_j - ja
fy = max( -2.0, min( fy, 3.0 ) )
jb = ja + 1
x_lon = xlon2d(ia,ja)*(1.0-fx)*(1.0-fy) + &
xlon2d(ia,jb)*(1.0-fx)*fy + &
xlon2d(ib,ja)*fx*(1.0-fy) + &
xlon2d(ib,jb)*fx*fy
y_lat = ylat2d(ia,ja)*(1.0-fx)*(1.0-fy) + &
ylat2d(ia,jb)*(1.0-fx)*fy + &
ylat2d(ib,ja)*fx*(1.0-fy) + &
ylat2d(ib,jb)*fx*fy
return
!
! do interpolation using the nested grid xlon2dn,ylat2dn
!
6000 continue
if (x_i .le. 0.0) then
ia = 0
else if (x_i .ge. real(nxn(lgrid)-1)) then
ia = nxn(lgrid)-1
else
ia = ifix( x_i )
end if
fx = x_i - ia
fx = max( -2.0, min( fx, 3.0 ) )
ib = ia + 1
if (y_j .le. 0.0) then
ja = 0
else if (y_j .ge. real(nyn(lgrid)-1)) then
ja = nyn(lgrid)-1
else
ja = ifix( y_j )
end if
fy = y_j - ja
fy = max( -2.0, min( fy, 3.0 ) )
jb = ja + 1
x_lon = xlon2dn(ia,ja,lgrid)*(1.0-fx)*(1.0-fy) + &
xlon2dn(ia,jb,lgrid)*(1.0-fx)*fy + &
xlon2dn(ib,ja,lgrid)*fx*(1.0-fy) + &
xlon2dn(ib,jb,lgrid)*fx*fy
y_lat = ylat2dn(ia,ja,lgrid)*(1.0-fx)*(1.0-fy) + &
ylat2dn(ia,jb,lgrid)*(1.0-fx)*fy + &
ylat2dn(ib,ja,lgrid)*fx*(1.0-fy) + &
ylat2dn(ib,jb,lgrid)*fx*fy
return
end subroutine xyindex_to_ll_wrf_out
!-----------------------------------------------------------------------
subroutine xymeter_to_ll_wrf( xmeter, ymeter, x_lon, y_lat )
!
! calculates longitude/latitude from xy "grid meter" coordinates
!
! arguments
! xmeter, ymeter - input = "grid meter" coordinates on the mother grid.
! x_lon, y_lat - output = longitude and latitude in degrees
!
! include 'includepar'
! include 'includecom'
use par_mod
use com_mod
! arguments
implicit none
real :: xmeter, ymeter, x_lon, y_lat
! local variables
real :: x_i, y_j
x_i = (xmeter - xmet0)/dx
y_j = (ymeter - ymet0)/dy
call xyindex_to_ll_wrf( 0, x_i, y_j, x_lon, y_lat )
return
end subroutine xymeter_to_ll_wrf
subroutine xymeter_to_ll_wrf_out(xmeter,ymeter,x_lon,y_lat)
!
! calculates longitude/latitude from xy "grid meter" coordinates
!
! arguments
! xmeter, ymeter - input = "grid meter" coordinates on the mother grid.
! x_lon, y_lat - output = longitude and latitude in degrees
!
! include 'includepar'
! include 'includecom'
use par_mod
use com_mod
! arguments
implicit none
real :: xmeter, ymeter, x_lon, y_lat
! local variables
real :: x_i, y_j
x_i = (xmeter - xmet0)/dx
y_j = (ymeter - ymet0)/dy
call xyindex_to_ll_wrf_out(0,x_i, y_j,x_lon,y_lat )
return
end subroutine xymeter_to_ll_wrf_out
!-----------------------------------------------------------------------
subroutine ll_to_xyindex_wrf( x_lon, y_lat, x_i, y_j )
!
! calculates xy "grid index" coordinates from longitude/latitude
!
! arguments
! x_lon, y_lat - input - longitude and latitude in degrees
! x_i, y_j - output = "grid index" coordinates on the mother grid.
! x_i ranges from 0 to nx-1. y_j ranges from 0 to nj-1.
!
! include 'includepar'
! include 'includecom'
use par_mod
use com_mod
implicit none
! arguments
real :: x_i, y_j, x_lon, y_lat
! local variables
integer :: i, ii, ia, ib, ip, ipass, iijjlohi
integer :: j, jj, ja, jb, jp
real :: dumcos, dumlat, dumlon
real :: dumr2, dumr2min
real :: dumxi, dumyj
real :: flo, fhi
real :: glo, ghi
real,parameter :: grace=2.01
real :: xxcen, xxcenb, yycen, yycenb
real :: xxyydel, xxyydelmin
real :: x_lon_sv, y_lat_sv
x_lon_sv = x_lon
y_lat_sv = y_lat
if (map_proj_method .gt. 0) then
if (map_proj_id .eq. 1) goto 2000
if (map_proj_id .eq. 2) goto 2000
if (map_proj_id .eq. 3) goto 2000
if (map_proj_id .eq. 4) goto 2000
end if
goto 5000
!
! use map projection routines in map_proj_wrf_subaa.f
!
2000 continue
call latlon_to_ij( y_lat, x_lon, dumxi, dumyj )
x_i = dumxi - 1.0
y_j = dumyj - 1.0
goto 8000
!
! do it by search/minimization of distance,
! using the outer grid xlon2d/ylat2d values from WRF met file
!
5000 continue
!
! first locate the i,j for which the lon,lat at
! i+0.5,j+0.5 are closest to x_lon, y_lat
!
dumr2min = 1.0e30
dumcos = cos( y_lat )
do j = 0, ny-1
do i = 0, nx-1
dumlat = 0.25*( ylat2d(i,j ) + ylat2d(i+1,j ) + &
ylat2d(i,j+1) + ylat2d(i+1,j+1) )
dumlon = 0.25*( xlon2d(i,j ) + xlon2d(i+1,j ) + &
xlon2d(i,j+1) + xlon2d(i+1,j+1) )
dumr2 = (y_lat-dumlat)**2 + ((x_lon-dumlon)*dumcos)**2
if (dumr2 .lt. dumr2min) then
dumr2min = dumr2
ib = i
jb = j
end if
end do
end do
i = ib
j = jb
ip = i+1
jp = j+1
!
! next determine the position between i/i+1 & j/j+1
! that is closest x_lon, y_lat
!
xxyydelmin = 5.0e-8*max( abs(x_lon), abs(y_lat) )
xxyydel = 1.00
xxcen = 0.5
yycen = 0.5
iijjlohi = 3
ipass = 0
! write(*,9510)
! write(*,9520) 0, (i+xxcen), (j+yycen), x_lon, y_lat
9510 format( / 'll_to_xyindex' )
9520 format( 'ipass, x_i, y_j, lon, lat', i3, 4f14.7 )
5200 ipass = ipass + 1
dumr2min = 1.0e30
do jj = -iijjlohi, iijjlohi
do ii = -iijjlohi, iijjlohi
fhi = xxcen + ii*xxyydel
ghi = yycen + jj*xxyydel
flo = 1.0 - fhi
glo = 1.0 - ghi
dumlat = glo*(flo*ylat2d(i,j ) + fhi*ylat2d(ip,j )) + &
ghi*(flo*ylat2d(i,jp) + fhi*ylat2d(ip,jp))
dumlon = glo*(flo*xlon2d(i,j ) + fhi*xlon2d(ip,j )) + &
ghi*(flo*xlon2d(i,jp) + fhi*xlon2d(ip,jp))
dumr2 = (y_lat-dumlat)**2 + ((x_lon-dumlon)*dumcos)**2
if (dumr2 .lt. dumr2min) then
dumr2min = dumr2
xxcenb = fhi
yycenb = ghi
end if
end do
end do
xxcen = xxcenb
yycen = yycenb
! write(*,9520) ipass, (i+xxcen), (j+yycen), dumlon, dumlat
if (xxyydel .gt. xxyydelmin) then
xxyydel = xxyydel*0.5
if (ipass .eq. 4) iijjlohi = 2
goto 5200
end if
! write(*,9520) ipass, (i+xxcen), (j+yycen), dumlon, dumlat
x_i = i + xxcen
y_j = j + yycen
!
! check for x_i, y_j in bounds before returning
!
8000 continue
if ((x_i .lt. -grace) .or. (x_i .gt. grace+real(nx-1)) .or. &
(y_j .lt. -grace) .or. (y_j .gt. grace+real(ny-1))) then
write(*,'(/a/a,1p,2e12.3/a,1p,2e12.3)') &
'*** ll_to_xyindex_wrf error -- x_i, y_j out of bounds', &
' x_lon, y_lat =', x_lon_sv, y_lat_sv, &
' x_i, y_j =', x_i, y_j
! pause
! ylat2d(5000,2000)=0.
! stop
end if
return
end subroutine ll_to_xyindex_wrf
!-----------------------------------------------------------------------
subroutine ll_to_xymeter_wrf( x_lon, y_lat, xmeter, ymeter )
!
! calculates xy "grid meter" coordinates from longitude/latitude
!
! arguments
! x_lon, y_lat - input - longitude and latitude in degrees
! xmeter, ymeter - output = "grid meter" coordinates on the mother grid.
!
! include 'includepar'
! include 'includecom'
use par_mod
use com_mod
implicit none
! arguments
real :: xmeter, ymeter, x_lon, y_lat
! local variables
real :: x_i, y_j
call ll_to_xyindex_wrf( x_lon, y_lat, x_i, y_j )
xmeter = xmet0 + dx*x_i
ymeter = ymet0 + dy*y_j
return
end subroutine ll_to_xymeter_wrf
!-----------------------------------------------------------------------
subroutine test_xyindex_to_ll_wrf( lgrid )
!
! tests the map projection routines by comparing
! lat,lon from projection routine against the
! lat,lon from the WRF met. files
!
! arguments
! lgrid - input - grid identifier
!
! include 'includepar'
! include 'includecom'
use par_mod
use com_mod
! arguments
implicit none
integer :: lgrid
! local variables
integer :: idum, ix, jdum, jy
integer :: map_set_proj_code
real :: dumdx, dumxi, dumyj
real :: dumlat, dumlatb, dumlon, dumlonb
real :: err
real :: rmserr
!
! check if map projection is lambert conformal or polar stereographic
!
if (map_proj_id .eq. 1) then
map_set_proj_code = 3 ! lambert conformal
else if (map_proj_id .eq. 2) then
map_set_proj_code = 5 ! polar stereographic
else if (map_proj_id .eq. 3) then
map_set_proj_code = 1 ! mercator
else if (map_proj_id .eq. 4) then
map_set_proj_code = 0 ! lat/lon
else
write(*,'(/ 10(a/) )') &
'************************************************************', &
'* *', &
'* WARNING - map projection is not polar sterographic *', &
'* or lambert conformal *', &
'* *', &
'* x,y <--> lat,lon conversions will be done *', &
'* by interpolation & searching, and will *', &
'* have limited accuracy near poles *', &
'* *', &
'************************************************************'
map_proj_method = 0
return
end if
if (lgrid .gt. 0) goto 2000
!
! make call to map projection setup routine
!
! (The 0.999812 factor is due to different earth_radius
! values in wrfsi code (6370.0 vs 6371.2).)
dumdx = dx*0.999812 ! WA 2/11/10 is this right?
! dumdx = dx*0.9987242 ! WA 2/11/10 is this right?
! dumdx = dx*0.9979203 ! WA 2/11/10 is this right?
coefdx=0.999812
! write(*,'(/2a,2i5)') &
! 'test_xyindex_to_ll_wrf calling map_set -- ', &
! 'map_proj_id, map_set_proj_code =', &
! map_proj_id, map_set_proj_code
call map_set( map_set_proj_code, &
ylat2d(0,0), xlon2d(0,0), dumdx, &
map_stdlon, map_truelat1, map_truelat2, &
nx, ny )
map_proj_method = 1
!
! compute lat,lon from xi,jy at 9 points (center, 4 corners,
! and 4 boundary midpoints)
! compare to lon,lat read from the WRF met. file and report rmserr
!
2000 continue
rmserr = 0.0
do jdum = 0, 2
do idum = 0, 2
if (lgrid .le. 0) then
jy = nint( 0.5*real((ny-1)*jdum) )
ix = nint( 0.5*real((nx-1)*idum) )
dumyj = 1 + jy
dumxi = 1 + ix
dumlatb = ylat2d(ix,jy)
dumlonb = xlon2d(ix,jy)
else
jy = nint( 0.5*real((nyn(lgrid)-1)*jdum) )
ix = nint( 0.5*real((nxn(lgrid)-1)*idum) )
dumyj = 1.0 + (jy/yresoln(lgrid)) + yln(lgrid)
dumxi = 1.0 + (ix/xresoln(lgrid)) + xln(lgrid)
dumlatb = ylat2dn(ix,jy,lgrid)
dumlonb = xlon2dn(ix,jy,lgrid)
end if
call ij_to_latlon( dumxi, dumyj, dumlat, dumlon )
err = (dumlat-dumlatb)**2 + &
((dumlon-dumlonb)*cos(dumlatb))**2
! print*,'err',idum,jdum,dumlat,dumlatb,dumlon,dumlonb
rmserr = rmserr + err
! print*,dumxi, dumyj, dumlat, dumlon,dumlatb,dumlonb
end do
end do
rmserr = 111.2*sqrt( rmserr/9.0 )
! print*,'rmserr',rmserr
if (rmserr .le. 0.02*(1.0e-3*dumdx)) then
write(*,'(/a,i3,1pe10.2)') &
'test_xyindex_to_ll_wrf -- lgrid, rmserr (km) =', lgrid, rmserr
endif
!
! if rms error exceeds 0.02*dx, something is wrong
! do not use the map projection routines in this case
!
if (rmserr .gt. 0.02*(1.0e-3*dumdx)) then
! print*,'pb with rmserr. try an other earth radius'
dumdx = dx ! try another earth radius
coefdx=1.
write(*,'(/2a,2i5)') &
'test_xyindex_to_ll_wrf calling map_set -- ', &
'map_proj_id, map_set_proj_code =', &
map_proj_id, map_set_proj_code
call map_set( map_set_proj_code, &
ylat2d(0,0), xlon2d(0,0), dumdx, &
map_stdlon, map_truelat1, map_truelat2, &
nx, ny )
map_proj_method = 1
!
! compute lat,lon from xi,jy at 9 points (center, 4 corners,
! and 4 boundary midpoints)
! compare to lon,lat read from the WRF met. file and report rmserr
!
rmserr = 0.0
do jdum = 0, 2
do idum = 0, 2
if (lgrid .le. 0) then
jy = nint( 0.5*real((ny-1)*jdum) )
ix = nint( 0.5*real((nx-1)*idum) )
dumyj = 1 + jy
dumxi = 1 + ix
dumlatb = ylat2d(ix,jy)
dumlonb = xlon2d(ix,jy)
else
jy = nint( 0.5*real((nyn(lgrid)-1)*jdum) )
ix = nint( 0.5*real((nxn(lgrid)-1)*idum) )
dumyj = 1.0 + (jy/yresoln(lgrid)) + yln(lgrid)
dumxi = 1.0 + (ix/xresoln(lgrid)) + xln(lgrid)
dumlatb = ylat2dn(ix,jy,lgrid)
dumlonb = xlon2dn(ix,jy,lgrid)
end if
call ij_to_latlon( dumxi, dumyj, dumlat, dumlon )
err = (dumlat-dumlatb)**2 + &
((dumlon-dumlonb)*cos(dumlatb))**2
rmserr = rmserr + err
end do
end do
rmserr = 111.2*sqrt( rmserr/9.0 )
write(*,'(/a,i3,1pe10.2)') &
'test_xyindex_to_ll_wrf -- lgrid, rmserr (km) =', lgrid, rmserr
endif
!
! if rms error exceeds 0.02*dx, something is wrong
! do not use the map projection routines in this case
!
dumdx = dx
if (lgrid .gt. 0) dumdx = dxn(lgrid)
if (rmserr .gt. 0.02*(1.0e-3*dumdx)) then
map_proj_method = 0
write(*,'(/ 9(a/) )') &
'************************************************************', &
'* *', &
'* WARNING - the coordinate transfo error exceeds 0.02*dx *', &
'* *', &
'************************************************************'
! print*,'projection set to',map_proj_method
print*,'problem with the projection. wrf+flexpart stops'
stop
end if
return
end subroutine test_xyindex_to_ll_wrf