34 integer :: inver = 0, outver = 0, ipack = -1
35 character(len = 500) :: gfilein, gfileout, copt
36 character(len = 2) :: master_table_ver, curmastertab_ver
37 INTEGER(4) narg, iargc, table_ver, mastertab
38 logical :: usemiss = .false., uvvect = .true.
42 curmastertab_ver =
'2'
56 if (copt .eq.
'-h' .or. copt .eq.
'-help')
then
66 do while (j.le.narg-2)
103 case(
'-mastertable_ver_1')
105 master_table_ver =
'1'
106 case(
'-mastertable_ver_2')
108 master_table_ver =
'2'
109 case(
'-mastertable_ver_3')
111 master_table_ver =
'3'
112 case(
'-mastertable_ver_4')
114 master_table_ver =
'4'
115 case(
'-mastertable_ver_5')
117 master_table_ver =
'5'
118 case(
'-mastertable_ver_6')
120 master_table_ver =
'6'
121 case(
'-mastertable_ver_7')
123 master_table_ver =
'7'
124 case(
'-mastertable_ver_8')
126 master_table_ver =
'8'
127 case(
'-mastertable_ver_9')
129 master_table_ver =
'9'
130 case(
'-mastertable_ver_10')
132 master_table_ver =
'10'
133 case(
'-mastertable_ver_11')
135 master_table_ver =
'11'
136 case(
'-mastertable_ver_12')
138 master_table_ver =
'12'
139 case(
'-mastertable_ver_13')
141 master_table_ver =
'13'
142 case(
'-mastertable_ver_14')
144 master_table_ver =
'14'
145 case(
'-mastertable_ver_15')
147 master_table_ver =
'15'
148 case(
'-mastertable_ver_16')
150 master_table_ver =
'16'
151 case(
'-mastertable_ver_17')
153 master_table_ver =
'17'
154 case(
'-mastertable_ver_18')
156 master_table_ver =
'18'
157 case(
'-mastertable_ver_19')
159 master_table_ver =
'19'
160 case(
'-mastertable_ver_20')
162 master_table_ver =
'20'
163 case(
'-mastertable_ver_21')
165 master_table_ver =
'21'
166 case(
'-mastertable_ver_22')
168 master_table_ver =
'22'
175 if (table_ver .le. 1 .OR. &
176 table_ver .gt. mastertab)
then
179 call errmsg(
'cnvgrib: cannot change to master table '// &
180 'version ' // master_table_ver)
182 call errmsg(
'Current GRIB master table version is '// &
190 CALL getarg(narg-1, gfilein)
191 CALL getarg(narg, gfileout)
195 if ((ipack .ne. -1).and.(outver .eq. 1))
then
196 CALL errmsg(
'cnvgrib: -pxx option ignored when using -g21')
201 if ((inver .eq. 0).or.(outver .eq. 0))
then
202 CALL errmsg(
'cnvgrib: must use one -gxx option')
210 if ((usemiss).and.(ipack .ne. 2 .AND. ipack .ne. 31 .AND. &
212 CALL errmsg(
'cnvgrib: -m or -m0 option ignored when not '// &
213 'using -p2, -p31 or -p32.')
222 ncgb = len_trim(gfilein)
223 CALL baopenr(ifl1, gfilein(1:ncgb), ios)
225 call errmsg(
'cnvgrib: cannot open input GRIB file '// &
229 ncgb = len_trim(gfileout)
230 CALL baopenw(ifl2, gfileout(1:ncgb), ios)
232 call errmsg(
'cnvgrib: cannot open output GRIB file '// &
239 if ((inver .eq. 1).AND.(outver .eq. 2))
then
240 call cnv12(ifl1, ifl2, ipack, usemiss, imiss, uvvect, table_ver)
241 elseif ((inver .eq. 2).AND.(outver .eq. 1))
then
242 call cnv21(ifl1, ifl2)
243 elseif ((inver .eq. 2).AND.(outver .eq. 2))
then
244 call cnv22(ifl1, ifl2, ipack, usemiss, imiss, table_ver)
246 print *,
' Unknown conversion option.'
252 CALL baclose(ifl1, ios)
253 CALL baclose(ifl2, ios)
265 character(len = 15) :: cnvgrib_ver =
"cnvgrib-v3.1.1"
266 integer,
intent(in) :: iopt
268 if (iopt .eq. 0)
then
270 call errmsg(
'Usage: cnvgrib [-h] {-g12|-g21|-g22} [-m|-m0]'// &
271 ' [-nv] [-mastertable_ver_x]')
272 call errmsg(
' [{-p0|-p2|-p31|-p32|-p40'// &
273 '|-p41}] ingribfile outgribfile')
275 call errmsg(
'Usage: cnvgrib -h For helps and shows all'// &
280 if (iopt .eq. 1)
then
282 call errmsg(
'cnvgrib: version '//cnvgrib_ver)
284 call errmsg(
'Must use one of the following options:')
285 call errmsg(
' -g12 converts GRIB1 to GRIB2')
286 call errmsg(
' -g21 converts GRIB2 to GRIB1')
287 call errmsg(
' -g22 converts GRIB2 to GRIB2 '// &
288 ' (used to change packing option)')
290 call errmsg(
'Optional packing options: (for use with '// &
291 ' -g12 and -g22 only)')
292 call errmsg(
' -p0 simple packing')
293 call errmsg(
' -p2 complex packing')
294 call errmsg(
' -p31 complex pack with 1st order diffs')
295 call errmsg(
' -p32 complex pack with 2nd order diffs')
296 call errmsg(
' -p40 JPEG2000 encoding')
297 call errmsg(
' -p41 PNG encoding')
299 call errmsg(
'Other Optional options: ')
300 call errmsg(
' -nv Do not combine U, V wind components')
302 call errmsg(
' Use missing value management'// &
303 ' instead of bitmap')
304 call errmsg(
' (ONLY valid with Complex Packing options:'// &
305 ' -p2, -p31 or -p32)')
307 call errmsg(
' -m Primary missing values'// &
308 ' included within the data values')
309 call errmsg(
' -m0 No explicit missing values'// &
310 ' included within the data values')
311 call errmsg(
' -mastertable_ver_x Master Table version'// &
312 ' where x is number from 2 to 21')
subroutine cnv12(ifl1, ifl2, ipack, usemiss, imiss, uvvect, table_ver)
This subroutine converts every GRIB1 field in a file to a GRIB2 field.
subroutine cnv21(ifl1, ifl2)
This subroutine converts every GRIB2 field in a file to a GRIB1 field.
subroutine cnv22(ifl1, ifl2, ipack, usemiss, imiss, table_ver)
This subroutine converts every GRIB2 field in a file to another GRIB2 field, most likely one using a ...
program cnvgrib
This program converts every GRIB field in a file between GRIB1 and GRIB2.
subroutine usage(iopt)
This routine prints a brief description of the command line options.