1 SUBROUTINE SETUP (domain_check_h, IPROJ, PHIC, XLONC, &
4 DIS, XCNTR, YCNTR, XN, POLE, PSI1, C2)
6 MAXNES, NESTIX, NESTJX, DIS, NUMC, NESTI, NESTJ, &
7 IXC, JXC, XCNTR, YCNTR, XN, POLE, PSI1, C2, &
10 !------------------------------------------------------------------------------!
12 ! MAP PROJECTION FACTORS CALCULATION
16 ! IPROJ: PROJECTION TYPE
17 ! PHIC: CENTRAL LATITUDE
18 ! XLONC: CENTRAL LONGITUDE
19 ! TRUELAT1: TRUE LATITUDE 1
20 ! TRUELAT2: TRUE LATITUDE 2
21 ! MAXNES: NUMBER OF DOMAINS < 10
22 ! NESTIX (): HORIZONTAL DOMAINS DIMENSIONS IN I DIRECTION
23 ! NESTJX (): HORIZONTAL DOMAINS DIMENSIONS IN J DIRECTION
24 ! DIS (): HORIZONTAL DOMAINS GRID SPACES IN METERS
25 ! NUMC (): MOTHER DOMAIN ID (1= COARSE DOMAIN)
26 ! NESTI (): DOMAINS' I-INDECES OF LOW LEFT CORNER IN MOTHER DOMAIN
27 ! NESTJ (): DOMAINS' J-INDECES OF LOW LEFT CORNER IN MOTHER DOMAIN
31 ! IXC: COARSE DOMAIN GRID I DIMENSION
32 ! JXC: COARSE DOMAIN GRID J DIMENSION
33 ! XCNTR: X-COORDINATE OF COARSE DOMAIN CENTER
34 ! YCNTR: Y-COORDINATE OF COARSE DOMAIN CENTER
39 ! XIM11 (10): DOMAINS' INDECES OF LOW LEFT CORNER OF DOMAIN IDD
40 ! XJM11 (10): DOMAINS' INDECES OF LOW LEFT CORNER OF DOMAIN IDD
43 ! Y.-R. GUO, September 2000
44 ! F. VANDENBERGHE, March 2001
45 !------------------------------------------------------------------------------!
49 INTEGER, INTENT (inout) :: iproj
50 REAL, INTENT (inout) :: phic, xlonc, truelat1, truelat2
52 REAL, INTENT (out) :: pole, xn, psi1, c2, xcntr, ycntr
53 REAL, INTENT (inout), DIMENSION (3) :: dis
55 INTEGER, INTENT (in) :: maxnes
56 INTEGER, INTENT (in), DIMENSION (maxnes) :: nestix, nestjx, NUMC, &
58 REAL, INTENT (inout), DIMENSION (maxnes) :: dis
60 INTEGER, INTENT (out) :: ixc, jxc
62 REAL, INTENT (out) :: pole, xn
63 REAL, INTENT (out) :: xim11 (maxnes), xjm11 (maxnes)
64 REAL, INTENT (out) :: psi1, c2, xcntr, ycntr
66 !------------------------------------------------------------------------------!
68 REAL :: psx, cell, cell2, r, phictr, sign
70 INTEGER, DIMENSION (3) :: nproj
72 CHARACTER (LEN=80) :: project
76 REAL :: psx, cell, cell2, r, phictr, hdsize, sign
77 REAL :: xjc, xdis, yjc, ydis
79 REAL :: cntrj0, cntri0
80 INTEGER :: ixcmax, jxcmax
81 REAL, DIMENSION (maxnes) :: xsouth,xwest,xnorth,xeast
84 INTEGER :: m, nm, nmc, nd1, nd2, mismatch
85 INTEGER :: ioffst, joffst, iimxn, jjmxn
86 INTEGER :: iratio (maxnes), nratio (maxnes)
88 INTEGER, DIMENSION (3) :: nproj
90 CHARACTER (LEN=80) :: project
91 !------------------------------------------------------------------------------!
92 ! DATA conv / 57.29578 /
95 include 'constants.inc'
97 logical domain_check_h
98 DATA nproj / 1, 2, 3 /
99 ! DATA nproj / 'LAMCON', 'POLSTR', 'MERCAT' /
100 !------------------------------------------------------------------------------!
101 if (iproj == 0 ) then
105 ! DIS(1) = 2.0 * pi * a / (NESTJX (1)-1)
107 if (domain_check_h) STOP 'domain_check_h'
111 ! WRITE (0,'(A)') " SET UP MAP PARAMETERS"
114 ! DEFINE THE PARAMETERS OF MAP BASED ON THE IPROJ:
119 SIGN=-1. ! SOUTH HEMESPHERE
123 SIGN=1. ! NORTH HEMESPHERE
129 IF (IPROJ .EQ. NPROJ(1)) THEN
130 if (abs(TRUELAT1 - TRUELAT2) .gt. 0.1) then
131 XN = ALOG10 (COS (TRUELAT1 / CONV)) - &
132 ALOG10 (COS (TRUELAT2 / CONV))
134 XN = XN/(ALOG10 (TAN ((45.0 - SIGN*TRUELAT1/2.0) / CONV)) - &
135 ALOG10 (TAN ((45.0 - SIGN*TRUELAT2/2.0) / CONV)))
137 XN = sign*sin(truelat1 / conv)
140 PSI1 = 90.-SIGN*TRUELAT1
144 ELSE IF (IPROJ .EQ. NPROJ(2)) THEN
149 ! PSI1 IS THE PSEUDO-LATITUDE
151 PSI1 = 90.-SIGN*TRUELAT1
155 ELSE IF (IPROJ .EQ. NPROJ(3)) THEN
166 IF (PHIC .LT. 0.) THEN
174 IF (IPROJ .NE. NPROJ(3)) THEN
176 PSX = (POLE-PHIC)/CONV
178 IF (IPROJ .EQ. NPROJ(1)) THEN
180 CELL = A*SIN (PSI1)/XN
181 CELL2 = (TAN (PSX/2.)) / (TAN (PSI1/2.))
184 IF (IPROJ .EQ. NPROJ(2)) THEN
185 CELL = A*SIN (PSX)/XN
186 CELL2 = (1. + COS (PSI1))/(1. + COS (PSX))
196 !-----FOR MERCATOR PROJECTION, THE PROJECTION IS TRUE AT LAT AT PHI1
198 IF (IPROJ .EQ. NPROJ(3)) THEN
203 CELL = COS (PHICTR)/(1.0+SIN (PHICTR))
204 YCNTR = - C2*ALOG (CELL)
211 ! REMOVE DOMAIN EXTENSION IN MM5 INPUT/OUTPUT FILES
216 ! REMOVE INITIALIZATION OF TRUE LAT
221 ! DEFINE THE PARAMETERS OF MAP BASED ON THE IPROJ:
226 SIGN=-1. ! SOUTH HEMESPHERE
230 SIGN=1. ! NORTH HEMESPHERE
236 IF (IPROJ .EQ. NPROJ(1)) THEN
238 IF (ABS (TRUELAT1) .GT. 90.) THEN
241 TRUELAT1 = SIGN*TRUELAT1
242 TRUELAT2 = SIGN*TRUELAT2
245 IF (ABS(TRUELAT1 - TRUELAT2) .GT. 0.1) then
246 XN = ALOG10 (COS (TRUELAT1 / CONV)) - &
247 ALOG10 (COS (TRUELAT2 / CONV))
249 XN = XN/(ALOG10 (TAN ((45.0 - SIGN*TRUELAT1/2.0) / CONV)) - &
250 ALOG10 (TAN ((45.0 - SIGN*TRUELAT2/2.0) / CONV)))
252 XN = SIGN*SIN(TRUELAT1 / CONV)
255 PSI1 = 90.-SIGN*TRUELAT1
259 ELSE IF (IPROJ .EQ. NPROJ(2)) THEN
263 IF (ABS(TRUELAT1) .GT. 90.) THEN
268 TRUELAT1 = SIGN*TRUELAT1
269 TRUELAT2 = SIGN*TRUELAT2
274 ! PSI1 IS THE PSEUDO-LATITUDE
276 PSI1 = 90.-SIGN*TRUELAT1
280 ELSE IF (IPROJ .EQ. NPROJ(3)) THEN
284 IF (ABS (TRUELAT1) .GT. 90.) THEN
290 IF (TRUELAT1 .NE. 0.) THEN
292 "MERCATOR PROJECTION IS ONLY SUPPORTED AT 0 DEGREE TRUE LATITUDE."
294 "TRUELAT1 IS RESET TO 0"
306 IF (PHIC .LT. 0.) THEN
314 IF (IPROJ .NE. NPROJ(3)) THEN
316 PSX = (POLE-PHIC)/CONV
318 IF (IPROJ .EQ. NPROJ(1)) THEN
320 CELL = A*SIN (PSI1)/XN
321 CELL2 = (TAN (PSX/2.)) / (TAN (PSI1/2.))
324 IF (IPROJ .EQ. NPROJ(2)) THEN
325 CELL = A*SIN (PSX)/XN
326 CELL2 = (1. + COS (PSI1))/(1. + COS (PSX))
336 !-----FOR MERCATOR PROJECTION, THE PROJECTION IS TRUE AT LAT AT PHI1
338 IF (IPROJ .EQ. NPROJ(3)) THEN
343 CELL = COS (PHICTR)/(1.0+SIN (PHICTR))
344 YCNTR = - C2*ALOG (CELL)
350 WRITE (0,'(2(A,F8.1),A,2X,A,f10.3)') &
351 " COARSE GRID CENTER IS AT X = ",XCNTR," KM AND Y = ",YCNTR," KM.", &
355 ! CHECK THE COMPATIBILITY OF NEST DOMAINS WITH THE COARSE DOMAINS
356 ! AND CALCULATE THE IRATIOS, INORTHS, ISOUTHS, IWESTS AND IEASTS
358 ! A) EXTENDING THE COARSE DOMAIN IF IEXP = 1
366 IF (IEXP .EQ. 1) THEN
368 INCR = INT (AEXP/DIS (1) + 1.001)
370 IXC = NESTIX (1) + INCR*2
371 JXC = NESTJX (1) + INCR*2
376 WRITE (0,'(A,I3)') " GRID IS EXPANDED BY ",INCR, &
377 " GRID POINTS ON EACH EDGE."
378 ! WRITE (0,'(2(A,I3))') &
379 ! "EXTENDED IXC IS ",IXC," EXTENDED JXC IS ",JXC
383 !-----CENTER OF GRID IN THE COARSE DOMAIN
385 CNTRJ0 = FLOAT (JXC+1)/2.
386 CNTRI0 = FLOAT (IXC+1)/2.
388 ! WRITE (0,'(2(A,I5))') &
389 ! "COARSE DOMAIN SIZE IX = ",NESTIX(1)," JX = ", NESTJX(1)
390 ! MIX, MJX ARE USED IN SUB. TFUDGE:
396 IXCMAX = MAX0 (NESTIX(M),IXCMAX)
397 JXCMAX = MAX0 (NESTJX(M),JXCMAX)
400 ! PRINT 24, IXCMAX,JXCMAX
401 !24 FORMAT(' ++> THE MAXIMUM DIMENSION = (',2I5,') <++')
403 ! CHECK IF POLE IS INSIDE THE DOMAIN OR NOT FOR LAMBERT PROJECTION:
405 HDSIZE = (IXC-1)*DIS(1)/2.
407 ! IF (HDSIZE.GT.ABS(YCNTR) .AND. IPROJ.EQ.NPROJ(1))THEN
408 ! PRINT *,'-------------------------------------------------'
409 ! PRINT *,'HALF DOMAIN SIZE IN Y-DIRECTION = ',HDSIZE
410 ! PRINT *,' DISTANCE FROM CNTER TO POLE = ',ABS(YCNTR)
411 ! PRINT *,'NOT MAKE SENSE WITH THE POLE IS INSIDE THE DOMAIN '
412 ! PRINT *,' FOR LAMBERT CONFORMAL PROJECTION!'
413 ! PRINT *,'=== PLEASE RE-SPECIFY THE CENTER OR DOMAIN SIZE. ==='
417 ! B) CALCULATING THE IRATIOS, INORTHS AND IEASTS:
423 XNORTH (1) = FLOAT (IXC)
424 XEAST (1) = FLOAT (JXC)
426 XJC = (XEAST(1) + 1.0)/2.
428 ! PRINT 27,XSOUTH(1),XWEST(1),XNORTH(1),XEAST(1),DIS(1),&
429 ! IRATIO(1),NRATIO(1)
430 ! 27 FORMAT(1X,'XSOUTH(1)= ',F6.1,2X,'XWEST(1)= ',F6.1,2X, &
431 ! 'XNORTH(1)= ',F6.1,2X,'XEAST(1)= ',F6.1,2X,'DIS(1)= ',F6.1,&
432 ! 2X,'IRATIO(1)= ',I3,2X,'NRATIO(1)= ',I3)
438 ! DOMAINS' CONSISTENCY CHECK:
442 IF (AMOD ((DIS (NMC)+0.09),DIS (NM)) .GT. 0.1) THEN
444 MISMATCH = MISMATCH + 1
447 ! PRINT 31,NM,DIS(NM),NMC,DIS(NMC)
448 !29 FORMAT(2X,'DOMAIN ',I2,' HAS INCORRECT GRID SIZE ', &
449 ! ' IT HAS TO BE THE MULTIPLE OF DOMAIN ',I2)
450 !31 FORMAT(2X,'DOMAIN ',I2,' GRID SIZE= ',F6.1,' KM', &
451 ! ' DOMAIN ',I2,' GRID SIZE= ',F6.1,' KM')
457 IRATIO (NM) = NINT (DIS (NMC)/ DIS (NM))
458 NRATIO (NM) = NINT (DIS (1) / DIS (NM))
460 ! MAKE SURE THE 4 CORNER POINTS OF NEST DOMAINS ARE ON THE
461 ! PREVIOUS DOMAIN GRID-POINTS
463 IF (MOD((NESTIX(NM)-1),IRATIO(NM)).NE.0) THEN
465 MISMATCH = MISMATCH + 1
467 IIMXN = (INT(FLOAT(NESTIX(NM)-1)/IRATIO(NM))+1)*IRATIO(NM) + 1
469 ! PRINT 32,NM,NESTIX(NM),IRATIO(NM),IIMXN
470 !32 FORMAT(2X,'NESTIX(',I2,')=',I4,' AND IRATIO=',I2,&
471 ! ' DOES NOT MATCH, YOU MAY SET NESTIX TO ',I4)
475 IF (MOD ((NESTJX (NM)-1),IRATIO (NM)).NE.0) THEN
477 MISMATCH = MISMATCH + 1
479 JJMXN = (INT(FLOAT(NESTJX(NM)-1)/IRATIO(NM))+1)*IRATIO(NM) + 1
481 ! PRINT 33,NM,NESTJX(NM),IRATIO(NM),JJMXN
482 !33 FORMAT(2X,'NESTJX(',I2,')=',I4,' AND IRATIO=',I2,&
483 ! ' DOES NOT MATCH, YOU MAY SET NESTJX TO ',I4)
486 !-----REDEFINE LOCATION OF LOWER LEFT CORNER OF FINE MESH (IN TERMS
487 ! OF EXTENDED COARSE MESH - DOMAIN 1 INDICES) IF USING EXTENDED G
489 ! PRINT 34,NM,NESTIX(NM),NESTJX(NM),DIS(NM),NESTI(NM),NESTJ(NM),&
490 ! NUMC(NM),IRATIO(NM),NRATIO(NM),IEXP
491 !34 FORMAT(/1X,'DOMAIN ',I2,2X,'IX=',I3,2X,'JX=',I3,2X, &
492 ! 'DS= ',F6.1,2X,'ICNS=',I4,2X,'JCNS=',I4,2X,&
493 ! 'NUMC= ',I2,2X,'IRATIO= ',I2,2X,'NRATIO= ',I2,2X,&
503 XDIS = (NESTI(ND1)-1)*DIS(ND2) + XDIS
504 YDIS = (NESTJ(ND1)-1)*DIS(ND2) + YDIS
512 XSOUTH(NM) = XDIS/DIS(1) + FLOAT(IOFFST) + 1
513 XWEST(NM) = YDIS/DIS(1) + FLOAT(JOFFST) + 1
514 XNORTH(NM) = XSOUTH(NM) + FLOAT(NESTIX(NM)-1)*DIS(NM)/DIS(1)
515 XEAST(NM) = XWEST(NM) + FLOAT(NESTJX(NM)-1)*DIS(NM)/DIS(1)
518 ! PRINT 36,XSOUTH(NM),XWEST(NM),XNORTH(NM),XEAST(NM)
519 !35 FORMAT(2X,'COARSE MESH INDICES FOR THE 4 CORNER POINTS ARE')
520 !36 FORMAT(2X,'SOUTH=',F6.1,3X,'WEST=',F6.1,3X,'NORTH =',F6.1,3X, &
525 IF (MISMATCH.GT.0) THEN
528 ! 'TERRAIN STOP IN SUBROUTINE SETUP DUE TO INCORRECT NEST DOMAIN SET UP'