Merge branch 'release-v4.6.0'
[WPS.git] / ungrib / src / ngl / g2 / gf_unpack2.f
blob6a18b5f7c74c63aee0d0f1b7a5fda202452a04be
1 subroutine gf_unpack2(cgrib,lcgrib,iofst,lencsec2,csec2,ierr)
2 !$$$ SUBPROGRAM DOCUMENTATION BLOCK
3 ! . . . .
4 ! SUBPROGRAM: gf_unpack2
5 ! PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-04-09
7 ! ABSTRACT: This subroutine unpacks Section 2 (Local Use Section)
8 ! as defined in GRIB Edition 2.
10 ! PROGRAM HISTORY LOG:
11 ! 2002-04-09 Gilbert
13 ! USAGE: CALL gf_unpack2(cgrib,lcgrib,iofst,lencsec2,csec2,ierr)
14 ! INPUT ARGUMENT LIST:
15 ! cgrib - Character array containing Section 2 of the GRIB2 message
16 ! lcgrib - Length (in bytes) of GRIB message array cgrib.
17 ! iofst - Bit offset of the beginning of Section 2.
19 ! OUTPUT ARGUMENT LIST:
20 ! iofst - Bit offset at the end of Section 2, returned.
21 ! lencsec2 - Length (in octets) of Local Use data
22 ! csec2() - Pointer to a character*1 array containing local use data
23 ! ierr - Error return code.
24 ! 0 = no error
25 ! 2 = Array passed is not section 2
26 ! 6 = memory allocation error
28 ! REMARKS: None
30 ! ATTRIBUTES:
31 ! LANGUAGE: Fortran 90
32 ! MACHINE: IBM SP
34 !$$$
36 character(len=1),intent(in) :: cgrib(lcgrib)
37 integer,intent(in) :: lcgrib
38 integer,intent(inout) :: iofst
39 integer,intent(out) :: lencsec2
40 integer,intent(out) :: ierr
41 character(len=1),pointer,dimension(:) :: csec2
43 ierr=0
44 lencsec2=0
45 nullify(csec2)
47 call gbyte(cgrib,lensec,iofst,32) ! Get Length of Section
48 iofst=iofst+32
49 lencsec2=lensec-5
50 call gbyte(cgrib,isecnum,iofst,8) ! Get Section Number
51 iofst=iofst+8
52 ipos=(iofst/8)+1
54 if ( isecnum.ne.2 ) then
55 ierr=6
56 print *,'gf_unpack2: Not Section 2 data. '
57 return
58 endif
60 allocate(csec2(lencsec2),stat=istat)
61 if (istat.ne.0) then
62 ierr=6
63 nullify(csec2)
64 return
65 endif
67 csec2(1:lencsec2)=cgrib(ipos:ipos+lencsec2-1)
68 iofst=iofst+(lencsec2*8)
70 return ! End of Section 2 processing
71 end