NCEPLIBS-g2  3.4.5
gribcreate.f
Go to the documentation of this file.
1 
6 
46 
47  subroutine gribcreate(cgrib,lcgrib,listsec0,listsec1,ierr)
48 
49  character(len=1),intent(inout) :: cgrib(lcgrib)
50  integer,intent(in) :: listsec0(*),listsec1(*)
51  integer,intent(in) :: lcgrib
52  integer,intent(out) :: ierr
53 
54  character(len=4),parameter :: grib='GRIB'
55  integer,parameter :: zero=0,one=1
56  integer,parameter :: mapsec1len=13
57  integer,parameter ::
58  & mapsec1(mapsec1len)=(/ 2,2,1,1,1,2,1,1,1,1,1,1,1 /)
59  integer lensec0,iofst,ibeg
60 
61  ierr=0
62 !
63 ! Currently handles only GRIB Edition 2.
64 !
65  if (listsec0(2).ne.2) then
66  print *,'gribcreate: can only code GRIB edition 2.'
67  ierr=1
68  return
69  endif
70 !
71 ! Pack Section 0 - Indicator Section
72 ! ( except for total length of GRIB message )
73 !
74 ! cgrib=' '
75  cgrib(1)=grib(1:1) ! Beginning of GRIB message
76  cgrib(2)=grib(2:2)
77  cgrib(3)=grib(3:3)
78  cgrib(4)=grib(4:4)
79  call g2_sbytec(cgrib,zero,32,16) ! reserved for future use
80  call g2_sbytec(cgrib,listsec0(1),48,8) ! Discipline
81  call g2_sbytec(cgrib,listsec0(2),56,8) ! GRIB edition number
82  lensec0=16 ! bytes (octets)
83 !
84 ! Pack Section 1 - Identification Section
85 !
86  ibeg=lensec0*8 ! Calculate offset for beginning of section 1
87  iofst=ibeg+32 ! leave space for length of section
88  call g2_sbytec(cgrib,one,iofst,8) ! Store section number ( 1 )
89  iofst=iofst+8
90  !
91  ! Pack up each input value in array listsec1 into the
92  ! the appropriate number of octets, which are specified in
93  ! corresponding entries in array mapsec1.
94  !
95  do i=1,mapsec1len
96  nbits=mapsec1(i)*8
97  call g2_sbytec(cgrib,listsec1(i),iofst,nbits)
98  iofst=iofst+nbits
99  enddo
100  !
101  ! Calculate length of section 1 and store it in octets
102  ! 1-4 of section 1.
103  !
104  lensec1=(iofst-ibeg)/8
105  call g2_sbytec(cgrib,lensec1,ibeg,32)
106 !
107 ! Put current byte total of message into Section 0
108 !
109  call g2_sbytec(cgrib,zero,64,32)
110  call g2_sbytec(cgrib,lensec0+lensec1,96,32)
111 
112  return
113  end
g2_sbytec
subroutine g2_sbytec(OUT, IN, ISKIP, NBYTE)
This subrountine is to put arbitrary size values into a packed bit string, taking the low order bits ...
Definition: g2_gbytesc.f:39
gribcreate
subroutine gribcreate(cgrib, lcgrib, listsec0, listsec1, ierr)
This subroutine initializes a new GRIB2 message and packs GRIB2 sections 0 (Indicator Section) and 1 ...
Definition: gribcreate.f:48