NCEPLIBS-g2 4.0.0
Loading...
Searching...
No Matches
cnv21.F90 File Reference

Convert every GRIB2 field to individual GRIB1 messages. More...

Go to the source code of this file.

Functions/Subroutines

subroutine cnv21 (ifl1, ifl2)
 This subroutine converts every GRIB2 field in a file to a GRIB1 field.
 
subroutine gdt2gds (igds, igdstmpl, idefnum, ideflist, kgds, igrid, iret)
 This routine converts grid information from a GRIB2 Grid Description Section as well as its Grid Definition Template to GRIB1 GDS info.
 
subroutine levelcnv (ipdstmpl, ltype, lval)
 This routine converts Level/layer information from a GRIB2 Product Definition Template to GRIB1 Level type and Level value.
 
subroutine makepds (idisc, idsect, ipdsnum, ipdstmpl, ibmap, idrsnum, idrstmpl, kpds, iret)
 This routine creates a GRIB1 PDS (Section 1) from appropriate information from a GRIB2 Product Definition Template.
 
subroutine makepdsens (ipdsnum, ipdstmpl, kpds, kens, kprob, xprob, kclust, kmembr, iret)
 This routine creates the GRIB1 NCEP Ensemble PDS extension information from appropriate information from a GRIB2 Product Definition Template.
 
subroutine putgbexn (lugb, kf, kpds, kgds, kens, kprob, xprob, kclust, kmembr, ibs, nbits, lb, f, iret)
 Pack and write a grib message.
 
subroutine setbit (ibm, ibs, ids, len, mg, g, gmin, gmax, nbit)
 The number of bits required to pack a given field for particular binary and decimal scalings is computed.
 

Detailed Description

Convert every GRIB2 field to individual GRIB1 messages.

Author
Stephen Gilbert
Date
2003-06-11

Definition in file cnv21.F90.

Function/Subroutine Documentation

◆ cnv21()

subroutine cnv21 ( integer, intent(in)  ifl1,
integer, intent(in)  ifl2 
)

This subroutine converts every GRIB2 field in a file to a GRIB1 field.

If a GRIB2 message contains more than one data field, then each field is saved in individual GRIB1 messages.

Program History Log

Date Programmer Comments
2003-06-11 Gilbert Initial
2008-05-14 Vuong Add option -m0 No explicit missing values included within data values.
Parameters
[in]ifl1Fortran unit number of input GRIB2 file.
[in]ifl2Fortran unit number of output GRIB1 file.
Author
Stephen Gilbert
Date
2003-06-11

Definition at line 19 of file cnv21.F90.

References gdt2gds(), getgb2(), gf_free(), makepds(), makepdsens(), putgbexn(), and rdieee().

Referenced by cnvgrib().

◆ gdt2gds()

subroutine gdt2gds ( integer, dimension(*), intent(in)  igds,
integer, dimension(*), intent(in)  igdstmpl,
integer, intent(in)  idefnum,
integer, dimension(*), intent(in)  ideflist,
integer, dimension(*), intent(out)  kgds,
integer, intent(out)  igrid,
integer, intent(out)  iret 
)

This routine converts grid information from a GRIB2 Grid Description Section as well as its Grid Definition Template to GRIB1 GDS info.

In addition, a check is made to determine if the grid is an NCEP predefined grid.

Program History Log

Date Programmer Comments
2003-06-17 Gilbert Initial.
2004-04-27 Gilbert Added support for gaussian grids.
2007-04-16 Vuong Added Curvilinear Orthogonal grids.
2007-05-29 Vuong Added Rotate Lat/Lon E-grid (203)
Parameters
[in]igdsContains information read from the appropriate GRIB Grid Definition Section 3 for the field being returned. Must be dimensioned >= 5.
  • igds(1) Source of grid definition (see Code Table 3.0)
  • igds(2) Number of grid points in the defined grid.
  • igds(3) Number of octets needed for each additional grid points definition. Used to define number of points in each row (or column) for non-regular grids. = 0, if using regular grid.
  • igds(4) Interpretation of list for optional points definition. (Code Table 3.11).
  • igds(5) Grid Definition Template Number (Code Table 3.1)
[in]igdstmplGrid Definition Template values for GDT 3.igds(5)
[in]idefnumThe number of entries in array ideflist. i.e. number of rows (or columns) for which optional grid points are defined.
[in]ideflistOptional integer array containing the number of grid points contained in each row (or column).
[out]kgdsGRIB1 GDS as described in w3fi63 format.
[out]igridNCEP predefined GRIB1 grid number set to 255, if not NCEP grid
[out]iretError return value:
  • 0 Successful
  • 1 Unrecognized GRIB2 GDT number 3.igds(5).
Author
Stephen Gilbert
Date
2003-06-17 &

Definition at line 906 of file cnv21.F90.

Referenced by cnv21(), and copygb2().

◆ levelcnv()

subroutine levelcnv ( integer, dimension(*), intent(in)  ipdstmpl,
integer, intent(out)  ltype,
integer, intent(out)  lval 
)

This routine converts Level/layer information from a GRIB2 Product Definition Template to GRIB1 Level type and Level value.

Program History Log

Date Programmer Comments
2003-06-12 Gilbert Initial
2007-10-24 Boi Vuong Added level 8 (Nominal top of atmosphere)
2011-01-13 Boi Vuong Added level/layer values from 235 to 239
Parameters
[in]ipdstmplGRIB2 Product Definition Template values
[out]ltypeGRIB1 level type (PDS octet 10)
[out]lvalGRIB1 level/layer value(s) (PDS octets 11 and 12)
Author
Stephen Gilbert
Date
2003-06-12

Definition at line 533 of file cnv21.F90.

Referenced by makepds().

◆ makepds()

subroutine makepds ( integer, intent(in)  idisc,
integer, dimension(*), intent(in)  idsect,
integer, intent(in)  ipdsnum,
integer, dimension(*), intent(in)  ipdstmpl,
integer, intent(in)  ibmap,
integer, intent(in)  idrsnum,
integer, dimension(*), intent(in)  idrstmpl,
integer, dimension(*), intent(out)  kpds,
integer, intent(out)  iret 
)

This routine creates a GRIB1 PDS (Section 1) from appropriate information from a GRIB2 Product Definition Template.

Note
Use pds2pdtens for ensemble related PDS.

Program History Log

Date Programmer Comments
2003-06-12 Gilbert Initial.
2005-04-19 Gilbert Changed scaling factor used with potential vorticity surfaces.
2007-05-08 VUONG Add Product Definition Template entries 120-124, 131, 88, 45, 47.
2007-05-14 Boi Vuong Added Time Range Indicator 51 (Climatological Mean Value)
2007-10-24 Boi Vuong Added level 8 (Nominal top of atmosphere)
2009-05-19 Boi Vuong Added levels 10(Entire Atmosphere), 11(Cumulonimbus Base),12(Cumulonimbus Top) and level 126(Isobaric Pa)
2009-12-14 Boi Vuong Added check for WAFS to use PDT 4.15 for Icing, Turbulence and Cumulonimbus
2010-08-10 Boi Vuong Added check for FNMOC to use TMP as TMAX and TMIN - Removed check WAFS MAX wind level
2011-10-24 Boi Vuong Added check for NAM (NMM-B) parameters to set statistical processing as MAX and MIN
2012-03-29 Boi Vuong Added check Time Range for APCP in FNMOC
2014-05-20 Boi Vuong Added check Time Range after F252
2014-11-14 Boi Vuong Added check Time Range for 15-hr or 18-hr or 21-hr or 24-hr Accumulation for APCP after F240
2018-07-26 Boi Vuong Added check Time Range for continuous accumulated APCP after F252 when convert from grib2 to grib1
Parameters
[in]idiscGRIB2 discipline from Section 0.
[in]idsectGRIB2 Section 1 info.
  • idsect(1) Id of orginating centre (Common Code Table C-1)
  • idsect(2) Id of orginating sub-centre (local table)
  • idsect(3) GRIB Master Tables Version Number (Code Table 1.0)
  • idsect(4) GRIB Local Tables Version Number (Code Table 1.1)
  • idsect(5) Significance of Reference Time (Code Table 1.2)
  • idsect(6) Reference Time - Year (4 digits)
  • idsect(7) Reference Time - Month
  • idsect(8) Reference Time - Day
  • idsect(9) Reference Time - Hour
  • idsect(10) Reference Time - Minute
  • idsect(11) Reference Time - Second
  • idsect(12) Production status of data (Code Table 1.3)
  • idsect(13) Type of processed data (Code Table 1.4)
[in]ipdsnumGRIB2 Product Definition Template Number
[in]ipdstmplGRIB2 Product Definition Template entries for PDT 4.ipdsnum
[in]ibmapGRIB2 bitmap indicator from octet 6, Section 6.
[in]idrsnumGRIB2 Data Representation Template Number
[in]idrstmplGRIB2 Data Representation Template entries
[out]kpdsGRIB1 PDS info as specified in W3FI63.
  • 1 id of center
  • 2 generating process id number
  • 3 grid definition
  • 4 gds/bms flag (right adj copy of octet 8)
  • 5 indicator of parameter
  • 6 type of level
  • 7 height/pressure , etc of level
  • 8 year including (century-1)
  • 9 month of year
  • 10 day of month
  • 11 hour of day
  • 12 minute of hour
  • 13 indicator of forecast time unit
  • 14 time range 1
  • 15 time range 2
  • 16 time range flag
  • 17 number included in average
  • 18 version nr of grib specification
  • 19 version nr of parameter table
  • 20 nr missing from average/accumulation
  • 21 century of reference time of data
  • 22 units decimal scale factor
  • 23 subcenter number
[out]iretError return value:
  • 0 Successful
  • 1 Don't know what to do with pre-defined bitmap.
  • 2 Unrecognized GRIB2 PDT 4.ipdsnum
Author
Stephen Gilbert
Date
2003-06-12

Definition at line 264 of file cnv21.F90.

References levelcnv(), and params::param_g2_to_g1().

Referenced by cnv21().

◆ makepdsens()

subroutine makepdsens ( integer, intent(in)  ipdsnum,
integer, dimension(*), intent(in)  ipdstmpl,
integer, dimension(*), intent(inout)  kpds,
integer, dimension(5), intent(out)  kens,
integer, dimension(2), intent(out)  kprob,
real, dimension(2), intent(out)  xprob,
integer, dimension(16), intent(out)  kclust,
integer, dimension(80), intent(out)  kmembr,
integer, intent(out)  iret 
)

This routine creates the GRIB1 NCEP Ensemble PDS extension information from appropriate information from a GRIB2 Product Definition Template.

Note
Use pds2pdtens for ensemble related PDS.

Program History Log

Date Programmer Comments
2003-06-12 Gilbert Initial
2007-05-14 Boi Vuong Corrected scale factor probabilities
2010-07-26 Boi Vuong Added two type of ensemblers (4 and 192)
Parameters
[in]ipdsnumGRIB2 Product Definition Template Number
[in]ipdstmplGRIB2 Product Definition Template entries for PDT 4.ipdsnum
[in,out]kpdsGRIB1 PDS info as specified in W3FI63.
  • 1 id of center
  • 2 generating process id number
  • 3 grid definition
  • 4 gds/bms flag (right adj copy of octet 8)
  • 5 indicator of parameter
  • 6 type of level
  • 7 height/pressure , etc of level
  • 8 year including (century-1)
  • 9 month of year
  • 10 day of month
  • 11 hour of day
  • 12 minute of hour
  • 13 indicator of forecast time unit
  • 14 time range 1
  • 15 time range 2
  • 16 time range flag
  • 17 number included in average
  • 18 version nr of grib specification
  • 19 version nr of parameter table
  • 20 nr missing from average/accumulation
  • 21 century of reference time of data
  • 22 units decimal scale factor
  • 23 subcenter number
[out]kensEnsemble identification for PDS octets 41-45
[out]kprobEnsemble probability info for PDS octets 46 47
[out]xprobEnsemble probability info for PDS octets 48-55
[out]kclustEnsemble cluster info for PDS octets 61-76
[out]kmembrEnsemble membership info for PDS octest 77-86
[out]iretError return value:
  • 0 Successful
  • 2 Unrecognized GRIB2 PDT 4.ipdsnum
Author
Stephen Gilbert
Date
2003-06-12

Definition at line 766 of file cnv21.F90.

Referenced by cnv21().

◆ putgbexn()

subroutine putgbexn (   lugb,
  kf,
integer, dimension(200)  kpds,
integer, dimension(200)  kgds,
integer, dimension(200)  kens,
integer, dimension(2)  kprob,
real, dimension(2)  xprob,
integer, dimension(16)  kclust,
integer, dimension(80)  kmembr,
  ibs,
  nbits,
logical*1, dimension(kf)  lb,
real, dimension(kf)  f,
  iret 
)

Pack and write a grib message.

This subprogram is nearly the inverse of getgbe.

Note
Subprogram can be called from a multiprocessing environment. Do not engage the same logical unit from more than one processor.

Program History Log

Date Programmer Comments
94-04-01 Iredell Initial.
95-10-31 Iredell Removed saves and prints
97-02-11 Y. Zhu Included probability and cluster arguments
2002-03-18 Gilbert Modified from putgbex to account for binary scale factors.
Parameters
[in]lugbteger unit of the unblocked grib data file
[in]kfteger number of data points
[in]kpdsteger (200) pds parameters
  • 1 id of center
  • 2 generating process id number
  • 3 grid definition
  • 4 gds/bms flag (right adj copy of octet 8)
  • 5 indicator of parameter
  • 6 type of level
  • 7 height/pressure , etc of level
  • 8 year including (century-1)
  • 9 month of year
  • 10 day of month
  • 11 hour of day
  • 12 minute of hour
  • 13 indicator of forecast time unit
  • 14 time range 1
  • 15 time range 2
  • 16 time range flag
  • 17 number included in average
  • 18 version nr of grib specification
  • 19 version nr of parameter table
  • 20 nr missing from average/accumulation
  • 21 century of reference time of data
  • 22 units decimal scale factor
  • 23 subcenter number
  • 24 pds byte 29, for nmc ensemble products, 128 if forecast field error, 64 if bias corrected fcst field, 32 if smoothed field, warning: can be combination of more than 1.
  • 25 pds byte 30, not used
[in]kgdsteger (200) gds parameters
  • 1 data representation type
  • 19 number of vertical coordinate parameters
  • 20 octet number of the list of vertical coordinate parameters or octet number of the list of numbers of points in each row or 255 if neither are present.
  • 21 for grids with pl, number of points in grid
  • 22 number of words in each row latitude/longitude grids
  • 2 n(i) nr points on latitude circle
  • 3 n(j) nr points on longitude meridian
  • 4 la(1) latitude of origin
  • 5 lo(1) longitude of origin
  • 6 resolution flag (right adj copy of octet 17)
  • 7 la(2) latitude of extreme point
  • 8 lo(2) longitude of extreme point
  • 9 di longitudinal direction of increment
  • 10 dj latitudinal direction increment
  • 11 scanning mode flag (right adj copy of octet 28) Gaussian grids:
  • 2 n(i) nr points on latitude circle
  • 3 n(j) nr points on longitude meridian
  • 4 la(1) latitude of origin
  • 5 lo(1) longitude of origin
  • 6 resolution flag (right adj copy of octet 17)
  • 7 la(2) latitude of extreme point
  • 8 lo(2) longitude of extreme point
  • 9 di longitudinal direction of increment
  • 10 n - nr of circles pole to equator
  • 11 scanning mode flag (right adj copy of octet 28)
  • 12 nv - nr of vert coord parameters
  • 13 pv - octet nr of list of vert coord parameters or pl - location of the list of numbers of points in each row (if no vert coord parameters are present or 255 if neither are present Polar Stereographic grids:
  • 2 n(i) nr points along lat circle
  • 3 n(j) nr points along lon circle
  • 4 la(1) latitude of origin
  • 5 lo(1) longitude of origin
  • 6 resolution flag (right adj copy of octet 17)
  • 7 lov grid orientation
  • 8 dx - x direction increment
  • 9 dy - y direction increment
  • 10 projection center flag
  • 11 scanning mode (right adj copy of octet 28) Spherical Harmonic Coefficients:
  • 2 j pentagonal resolution parameter
  • 3 k pentagonal resolution parameter
  • 4 m pentagonal resolution parameter
  • 5 representation type
  • 6 coefficient storage mode Mercator grids:
  • 2 n(i) nr points on latitude circle
  • 3 n(j) nr points on longitude meridian
  • 4 la(1) latitude of origin
  • 5 lo(1) longitude of origin
  • 6 resolution flag (right adj copy of octet 17)
  • 7 la(2) latitude of last grid point
  • 8 lo(2) longitude of last grid point
  • 9 latit - latitude of projection intersection
  • 10 reserved
  • 11 scanning mode flag (right adj copy of octet 28)
  • 12 longitudinal dir grid length
  • 13 latitudinal dir grid length Lambert Conformal Grids:
  • 2 nx nr points along x-axis
  • 3 ny nr points along y-axis
  • 4 la1 lat of origin (lower left)
  • 5 lo1 lon of origin (lower left)
  • 6 resolution (right adj copy of octet 17)
  • 7 lov - orientation of grid
  • 8 dx - x-dir increment
  • 9 dy - y-dir increment
  • 10 projection center flag
  • 11 scanning mode flag (right adj copy of octet 28)
  • 12 latin 1 - first lat from pole of secant cone inter
  • 13 latin 2 - second lat from pole of secant cone inter
[in]kensteger (200) ensemble pds parms
  • 1 application identifier
  • 2 ensemble type
  • 3 ensemble identifier
  • 4 product identifier
  • 5 smoothing flag
[in]kprobteger (2) probability ensemble parms
[in]xprobal (2) probability ensemble parms
[in]kclustteger (16) cluster ensemble parms
[in]kmembrteger (8) cluster ensemble parms
[in]ibsteger binary scale factor (0 to ignore)
[in]nbitsteger number of bits in which to pack (0 to ignore)
[in]lbgical*1 (kf) bitmap if present
[in]fal (kf) data
[out]iretteger return code
  • 0 Success
  • Other W3FI72 GRIB packer return code
Author
Mark Iredell
Date
94-04-01

Definition at line 1381 of file cnv21.F90.

References setbit().

Referenced by cnv21().

◆ setbit()

subroutine setbit (   ibm,
  ibs,
  ids,
  len,
dimension(len)  mg,
dimension(len)  g,
  gmin,
  gmax,
  nbit 
)

The number of bits required to pack a given field for particular binary and decimal scalings is computed.

The minimum and maximum rounded field values are also returned. GRIB bitmap masking for valid data is optionally used.

Parameters
[in]ibminteger bitmap flag (=0 for no bitmap).
[in]ibsinteger binary scaling (e.g. ibs=3 to round field to nearest eighth value).
[in]idsinteger decimal scaling (e.g. ids=3 to round field to nearest milli-value) (note that ids and ibs can both be nonzero, e.g. ids=1 and ibs=1 rounds to the nearest twentieth).
[in]leninteger length of the field and bitmap.
[in]mginteger (len) bitmap if ibm=1 (0 to skip, 1 to keep).
[in]greal (len) field.
[out]gminreal minimum valid rounded field value.
[out]gmaxreal maximum valid rounded field value.
[out]nbitinteger number of bits to pack.
Author
Mark Iredell
Date
92-10-31

Definition at line 1480 of file cnv21.F90.

Referenced by putgbexn().