NCEPLIBS-g2 4.0.0
Loading...
Searching...
No Matches
grb2index.F90
Go to the documentation of this file.
1
4
15program grb2index
16 implicit none
17 integer narg, iargc
18 character cgb * 256, cgi * 256
19 character cidxver * 1
20 integer :: idxver = 2
21 integer :: lugb = 11, lugi = 12
22 integer :: ncgb, ncgb1
23 integer :: iret, ios, ncbase, argnum = 0
24
25 interface
26 subroutine g2_create_index(lugb, lugi, idxver, filename, iret)
27 implicit none
28 integer, intent(in) :: lugb, lugi, idxver
29 character*(*) :: filename
30 integer, intent(out) :: iret
31 end subroutine g2_create_index
32 end interface
33
34 ! Get arguments.
35 narg = iargc()
36 if (narg .ne. 2 .and. narg .ne. 3) then
37 call errmsg('grb2index: Incorrect usage')
38 call errmsg('Usage: grb2index gribfile indexfile')
39 call errmsg('or: grb2index idxver gribfile indexfile')
40 call exit(2)
41 endif
42 if (narg .eq. 3) then
43 call getarg(1, cidxver)
44 read(cidxver, '(i1)') idxver
45 argnum = 1
46 end if
47 call getarg(argnum + 1, cgb)
48 call getarg(argnum + 2, cgi)
49
50 ! Open binary GRIB2 file for input.
51 call baopenr(lugb, trim(cgb), ios)
52 if (ios .ne. 0) then
53 print *, 'grb2index: Error accessing file ', trim(cgb)
54 call exit(8)
55 endif
56
57 ! Open index file for output.
58 call baopenw(lugi, trim(cgi), ios)
59 if (ios .ne. 0) then
60 print *, 'grb2index: Error accessing file ', trim(cgi)
61 call exit(1)
62 endif
63
64 ! Locate base name of file.
65 ncgb = len(cgb)
66 ncgb1 = ncbase(cgb,ncgb)
67
68 ! Create the index file and write it to lugi.
69 call g2_create_index(lugb, lugi, idxver, cgb(ncgb1:ncgb), iret)
70 if (iret .ne. 0) then
71 call exit(1)
72 endif
73
74 ! Close our files.
75 call baclose(lugb,iret)
76 if (iret .ne. 0) stop 9
77 call baclose(lugi,iret)
78 if (iret .ne. 0) stop 9
79
80end program grb2index
81
94integer function ncbase(c,n)
95 implicit none
96 character c*(*)
97 integer :: n
98 integer :: k
99
100 k = n
101 do while (k .ge. 1 .and. c(k:k) .ne. '/')
102 k = k - 1
103 enddo
104 ncbase = k + 1
105
106end function ncbase
subroutine g2_create_index(lugb, lugi, idxver, filename, iret)
Create a version 1 or 2 index file for a GRIB2 file.
Definition g2index.F90:21
program grb2index
This program creates an index file from a GRIB2 file.
Definition grb2index.F90:15
integer function ncbase(c, n)
Locate basename of a file.
Definition grb2index.F90:95