-
Notifications
You must be signed in to change notification settings - Fork 0
/
Point_info.f90
241 lines (240 loc) · 7.1 KB
/
Point_info.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
!
! Point_Info.f90 (c) Gottfried Harasek '04 - '17 11.11.2017
! This file is part of HCM.
!
! Point_Info.f90 is free software: you can redistribute it and/or modify
! it as long as this copyright notice is kept intact, the sourcecode is
! distributed with the final distributed product, mentioning the copyright.
!
! Point_Info.f90 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.
!
!
! Subroutine to read the info of a given point from the database.
!
!
! Input values:
! Long DOUBLE PRECISION longitude of point (-180.0....+180.0)
! Lat DOUBLE PRECISION latitude of point (-90.0...+90.0)
! Topo_path CHARACTER*63 path of terrain database, e.g. 'D:\TOPO'
! Morpho_path CHARACTER*63 path of morpho database, e.g. 'D:\MORPHO'
!
!
! Output values:
! Height INTEGER*2 height of point in meter
! M_Type INTEGER*2 type of morphologie
! Error INTEGER*4 error value
!
! Possible error values
! 0 no error
! 36 error opening file (no data)
! 220 error reading record
! 400 height is missing (-9999)
!
! Terrain-data location: Topo_path\Subdir\
! Morpho-data location: Morpho_path\Subdir\
! where Subdir is first 4 char of filename
!
! Topo_Path e.g. = D:\TOPO
! Morpho_Path e.g. = D:\MORPHO
!
! Filenames are (example) E009N50.63E or E012N45.33M where
! E009 or E012 is 9 or 12 degree east,
! N50 or N45 is 50 or 45 degree north,
! 33 or 63 is the resolution in east-west (3 or 6)
! and in north-south direction (always 3)
! in seconds and
! E for elevation-data,
! M for morphological-data.
!
! !!!! Longitudes are [0° - 360°[ !!!!!
!
! Filenames correspond to the south-west corner of a 1 * 1
! degree block in !both! hemispheres.
! allways the lowest long(0..360)/lat(-90..+90) = 1st record in file)
!
! Record-No. (R) in the files:
!
! 133 134 135 136 137 138 139 140 141 142 143 144
! 121 132
! 109 120
! 097 108
! 085 096
! (BV) 073 084
! 061 072
! 049 060
! 037 048
! 025 036
! 013 024
! 001 002 003 004 005 006 007 008 009 010 011 012
! (BH)
!
! one record:
! Field H_F_3(I,J)
!
! I=1,J=101 ********************* I=101,J=101
! *********************
! North *********************
! *********************
! (EV) *********************
! *********************
! *********************
! South *********************
! *********************
! I=1,J=1 ********************* I=101,J=1
! (EH)
! West East
!
!
! Field H_F_6(I,J)
!
! I=1,J=101 ********************* I=51,J=101
! *********************
! North *********************
! *********************
! *********************
! *********************
! *********************
! South *********************
! *********************
! I=1,J=1 ********************* I=51,J=1
!
! West East
!
!
! Heights surrounding point "P" :
!
! P3 P4
!
! P
!
!
! P1(E) P2
!
! **********************************************************************************
!
SUBROUTINE Point_info (Long, Lat, Height, M_Type)
!
IMPLICIT NONE
!
INCLUDE 'HCM_MS_V7_definitions.F90'
!
DOUBLE PRECISION Long, Lat
INTEGER(2) Height, M_Type
!
INTEGER(2) H1, H2, H3, H4
INTEGER(4) LOD, LAD, LOR, LAR, BH, BV, R, E
DOUBLE PRECISION EH, EV, LORR, LARR, H12, H34
CHARACTER(1) H_C(20402), M_C(20402)
CHARACTER(10) FN
!
EQUIVALENCE (H_I,H_C),(M_I,M_C)
! **********************************************************************************
!
Height = -9999
M_Type = 0
!
! convert Longitude, split in Integer and Remainder
LOD = FLOOR(Long)
LOR = IDNINT((Long-LOD)*3.599D3)
LAD = FLOOR(Lat)
LAR = IDNINT((Lat-LAD)*3.599D3)
!
IF ((O_LOD .NE. LOD) .OR. (O_LAD .NE. LAD)) THEN
FN = ' '
CLOSE(UNIT=5)
IF (LOD .GE. 0) THEN
FN(1:1) = 'e'
ELSE
FN(1:1) = 'w'
END IF
WRITE (FN(2:4), '(I3.3)') ABS(LOD)
!
IF (LAD .GE. 0) THEN
FN(5:5) = 'n'
ELSE
FN(5:5) = 's'
END IF
WRITE (FN(6:7), '(I2.2)') ABS(LAD)
!
IF (ABS(LAD) .LT. 50) THEN
RESH = 101
FN(8:10) = '.33'
ELSE
RESH = 51
FN(8:10) = '.63'
END IF
! open topo
OPEN (UNIT=5, FILE=TRIM(Topo_path) // '/' // FN(1:4) // '/' // FN // 'e', &
ACCESS='DIRECT',RECL=202*(RESH), STATUS='OLD', &
ERR=36, MODE='READ')
! open morpho
IF (with_morpho) THEN
CLOSE (UNIT=6)
OPEN (UNIT=6, FILE=TRIM(Morpho_path) // '/' // FN(1:4) // '/' // FN // 'm', &
ACCESS='DIRECT',RECL=202*(RESH), STATUS='OLD', IOSTAT=OLD_R, MODE='READ')
IF (OLD_R .NE. 0) THEN
Info(16) = .TRUE.
with_morpho = .FALSE.
D_sea_calculated = 0
END IF
END IF
OLD_R=-1
O_LOD=LOD
O_LAD=LAD
END IF
!
! coordinates of block containing P
BH = (LOR/300)
BV = (LAR/300)
! coordinates of point P in block
EH = DBLE(LOR-BH*3D2)/DBLE(300/(RESH-1))
EV = DBLE(LAR-BV*3D2)/3D0
!
R = 12*BV + BH + 1
!
IF (R .NE. OLD_R) THEN
! point in new file
!
READ (UNIT=5, ERR=220, REC=R) H_C(1:(202*RESH))
IF (with_morpho) READ (UNIT=6, ERR=220, REC=R) M_C(1:(202*RESH))
OLD_R = R
END IF
!
! get morpho
IF (with_morpho) M_Type=INT(M_I(IDNINT(EV)*RESH + IDNINT(EH) + 1))
!
E = IDINT(EV)*RESH + IDINT(EH) + 1
!
! get topo
H1=H_I(E)
H2=H_I(E+1)
H3=H_I(E+RESH)
H4=H_I(E+RESH+1)
!
IF (MIN(H1,H2,H3,H4) .EQ. -9999) THEN
HCM_Error = 400
RETURN
END IF
!
! coordinates of P relativ to P1
LORR = DMOD(EH,1D0)
LARR = DMOD(EV,1D0)
! calculate height P
H12 = DBLE(H1) + DBLE(H2 - H1) * LORR
H34 = DBLE(H3) + DBLE(H4 - H3) * LORR
Height = IIDNNT(H12 + (H34 - H12) * LARR)
!
RETURN
!
36 HCM_Error = 36
RETURN
!
220 HCM_Error = 220
RETURN
!
END SUBROUTINE Point_info
!
! **********************************************************************************
!