-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmake_mask.f90
74 lines (53 loc) · 1.55 KB
/
make_mask.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
program make_mask
use iso_fortran_env
use netcdf
use runoff_modules
implicit none
type(nc_info_type) :: source_info
character(len=128) :: carg, carg1, outfile
character(len=32) :: var_name
integer :: i, nargs
var_name = 'runoff'
nargs=command_argument_count()
if ( nargs < 2 ) then
write(*,*) 'ERROR: Usage :: process_runoff [-v varname] [-o outfile] -f runoff_file'
stop 1
endif
var_name = 'runoff'
outfile = 'runoff_mask.nc'
do i = 1,nargs,2
call get_command_argument(i,carg)
call get_command_argument(i+1,carg1)
select case(trim(carg))
case('-f')
source_info%fname=trim(carg1)
case('-v')
var_name=trim(carg1)
case('-o')
outfile=trim(carg1)
case DEFAULT
write(*,*) 'Unknown argument',trim(carg)
stop
end select
enddo
write(*,*) 'Reading source info'
call get_source_info(source_info, var_name)
call write_mask(source_info, outfile)
call handle_error(nf90_close(source_info%ncid))
contains
subroutine write_mask(source_info, outfile)
! Interface variables
type(nc_info_type),intent(in) :: source_info
character(len=*) :: outfile
! Local variables
logical :: mask(source_info%idim,source_info%jdim)
integer :: i
mask = .false.
do i = 1,source_info%nrecs
mask = mask .or. read_record(source_info,i) > 0
end do
print *,'Number of runoff pixels: ',count(mask)
write(*,*) 'Setting up output file'
call write_mask_file(outfile, mask)
end subroutine write_mask
end program make_mask