5 integer, external :: iargc
8 integer :: i, j, n_bins, we_dim, sn_dim
9 real, pointer, dimension(:,:) :: hgt
10 real, allocatable, dimension(:,:,:) :: topo_angle
11 character (len=1024) :: filename
13 if (iargc() /= 1) then
15 write(6,*) 'Usage: elev_angle.exe <geogrid output file>'
20 call getarg(1,filename)
23 ! Read in topography field from geogrid output file
25 call read_topo_field(filename, hgt, we_dim, sn_dim, istatus)
26 if (istatus /= 0) stop
28 write(6,*) 'Read HGT_M field dimensioned ',we_dim,sn_dim
31 write(6,'(a6,i3,a1,i3,a2,f13.5)') 'HGT_M(',i,',',j,')=',hgt(i,j)
36 allocate(topo_angle(we_dim, sn_dim, n_bins))
39 ! Compute elevation angles for each azimuth angle bin
44 ! Write elevation angle data to intermediate file
46 call write_elev_angles(topo_angle, we_dim, sn_dim, n_bins, istatus)
49 deallocate(topo_angle)
54 end program elev_angle
57 subroutine read_topo_field(filename, hgt, we_dim, sn_dim, istatus)
64 character (len=*), intent(in) :: filename
65 real, pointer, dimension(:,:) :: hgt
66 integer, intent(out) :: we_dim, sn_dim
67 integer, intent(out) :: istatus
70 integer :: ncid, topo_varid, we_dimid, sn_dimid
71 character (len=NF90_MAX_NAME) :: toponame, we_name, sn_name
74 istatus = nf90_open(trim(filename), 0, ncid)
75 if (istatus /= NF90_NOERR) then
77 write(6,*) 'Error: Could not open file '//trim(filename)
83 sn_name = 'south_north'
84 istatus = nf90_inq_dimid(ncid, sn_name, sn_dimid)
85 if (istatus /= NF90_NOERR) then
87 write(6,*) 'Error: Could not get ID of dimension south_north'
93 istatus = nf90_inquire_dimension(ncid, sn_dimid, sn_name, sn_dim)
94 if (istatus /= NF90_NOERR) then
96 write(6,*) 'Error: Could not get south_north dimension'
102 we_name = 'west_east'
103 istatus = nf90_inq_dimid(ncid, we_name, we_dimid)
104 if (istatus /= NF90_NOERR) then
106 write(6,*) 'Error: Could not get ID of dimension west_east'
112 istatus = nf90_inquire_dimension(ncid, we_dimid, we_name, we_dim)
113 if (istatus /= NF90_NOERR) then
115 write(6,*) 'Error: Could not get west_east dimension'
122 istatus = nf90_inq_varid(ncid, toponame, topo_varid)
123 if (istatus /= NF90_NOERR) then
125 write(6,*) 'Error: Could not get ID of variable HGT_M'
131 allocate(hgt(we_dim,sn_dim))
133 istatus = nf90_get_var(ncid, topo_varid, hgt)
134 if (istatus /= NF90_NOERR) then
136 write(6,*) 'Error: Could not read HGT_M field'
143 istatus = nf90_close(ncid)
147 end subroutine read_topo_field
150 subroutine write_elev_angles(field, we_dim, sn_dim, kdim, istatus)
157 real, dimension(we_dim, sn_dim, kdim), intent(in) :: field
158 integer, intent(in) :: we_dim, sn_dim, kdim
159 integer, intent(out) :: istatus
163 type (met_data) :: met_angle
165 call write_met_init('ELEVANGLES', .true., '0000-00-00_00:00:00', istatus)
167 if (istatus /= 0) then
169 write(6,*) 'Error opening output file ELEVANGLES'
175 met_angle%version = 5
176 met_angle%iproj = PROJ_MERC
177 met_angle%field = 'TOPO_ELEV'
178 met_angle%units = 'degrees'
179 met_angle%desc = 'Topography elevation'
180 ! met_angle%iproj = ...
181 ! met_angle%truelat1 = ...
182 ! met_angle%blah = ...
183 ! met_angle%blah2 = ...
185 allocate(met_angle%slab(we_dim, sn_dim))
189 met_angle%xlvl = real(i)
190 met_angle%slab(:,:) = field(:,:,i)
191 call write_next_met_field(met_angle, istatus)
193 if (istatus /= 0) then
194 write(6,*) 'Error writing data to output file ELEVANGLES'
196 deallocate(met_angle%slab)
202 call write_met_close()
206 end subroutine write_elev_angles