1 subroutine gribcreate(cgrib,lcgrib,listsec0,listsec1,ierr)
2 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
4 ! SUBPROGRAM: gribcreate
5 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-04-28
7 ! ABSTRACT: This subroutine initializes a new GRIB2 message and packs
8 ! GRIB2 sections 0 (Indicator Section) and 1 (Identification Section).
9 ! This routine is used with routines "addlocal", "addgrid", "addfield",
10 ! and "gribend" to create a complete GRIB2 message. Subroutine
11 ! gribcreate must be called first to initialize a new GRIB2 message.
12 ! Also, a call to gribend is required to complete GRIB2 message
13 ! after all fields have been added.
15 ! PROGRAM HISTORY LOG:
18 ! USAGE: CALL gribcreate(cgrib,lcgrib,listsec0,listsec1,ierr)
19 ! INPUT ARGUMENT LIST:
20 ! cgrib - Character array to contain the GRIB2 message
21 ! lcgrib - Maximum length (bytes) of array cgrib.
22 ! listsec0 - Contains information needed for GRIB Indicator Section 0.
23 ! Must be dimensioned >= 2.
24 ! listsec0(1)=Discipline-GRIB Master Table Number
25 ! (see Code Table 0.0)
26 ! listsec0(2)=GRIB Edition Number (currently 2)
27 ! listsec1 - Contains information needed for GRIB Identification Section 1.
28 ! Must be dimensioned >= 13.
29 ! listsec1(1)=Id of orginating centre (Common Code Table C-1)
30 ! listsec1(2)=Id of orginating sub-centre (local table)
31 ! listsec1(3)=GRIB Master Tables Version Number (Code Table 1.0)
32 ! listsec1(4)=GRIB Local Tables Version Number (Code Table 1.1)
33 ! listsec1(5)=Significance of Reference Time (Code Table 1.2)
34 ! listsec1(6)=Reference Time - Year (4 digits)
35 ! listsec1(7)=Reference Time - Month
36 ! listsec1(8)=Reference Time - Day
37 ! listsec1(9)=Reference Time - Hour
38 ! listsec1(10)=Reference Time - Minute
39 ! listsec1(11)=Reference Time - Second
40 ! listsec1(12)=Production status of data (Code Table 1.3)
41 ! listsec1(13)=Type of processed data (Code Table 1.4)
43 ! OUTPUT ARGUMENT LIST:
44 ! cgrib - Character array to contain the GRIB2 message
45 ! ierr - Error return code.
47 ! 1 = Tried to use for version other than GRIB Edition 2
49 ! REMARKS: This routine is intended for use with routines "addlocal",
50 ! "addgrid", "addfield", and "gribend" to create a complete
54 ! LANGUAGE: Fortran 90
59 character(len=1),intent(inout) :: cgrib(lcgrib)
60 integer,intent(in) :: listsec0(*),listsec1(*)
61 integer,intent(in) :: lcgrib
62 integer,intent(out) :: ierr
64 character(len=4),parameter :: grib='GRIB'
65 integer,parameter :: zero=0,one=1
66 integer,parameter :: mapsec1len=13
68 & mapsec1(mapsec1len)=(/ 2,2,1,1,1,2,1,1,1,1,1,1,1 /)
69 integer lensec0,iofst,ibeg
73 ! Currently handles only GRIB Edition 2.
75 if (listsec0(2).ne.2) then
76 print *,'gribcreate: can only code GRIB edition 2.'
81 ! Pack Section 0 - Indicator Section
82 ! ( except for total length of GRIB message )
85 cgrib(1)=grib(1:1) ! Beginning of GRIB message
89 call g2lib_sbyte(cgrib,zero,32,16) ! reserved for future use
90 call g2lib_sbyte(cgrib,listsec0(1),48,8) ! Discipline
91 call g2lib_sbyte(cgrib,listsec0(2),56,8) ! GRIB edition number
92 lensec0=16 ! bytes (octets)
94 ! Pack Section 1 - Identification Section
96 ibeg=lensec0*8 ! Calculate offset for beginning of section 1
97 iofst=ibeg+32 ! leave space for length of section
98 call g2lib_sbyte(cgrib,one,iofst,8) ! Store section number ( 1 )
101 ! Pack up each input value in array listsec1 into the
102 ! the appropriate number of octets, which are specified in
103 ! corresponding entries in array mapsec1.
107 call g2lib_sbyte(cgrib,listsec1(i),iofst,nbits)
111 ! Calculate length of section 1 and store it in octets
114 lensec1=(iofst-ibeg)/8
115 call g2lib_sbyte(cgrib,lensec1,ibeg,32)
117 ! Put current byte total of message into Section 0
119 call g2lib_sbyte(cgrib,zero,64,32)
120 call g2lib_sbyte(cgrib,lensec0+lensec1,96,32)