OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
readgrib.f
Go to the documentation of this file.
1 C*****************************************************************
2 C* FILE: readgrib
3 C*
4 C* PURPOSE: read NMC produced data GRIBs.
5 C*
6 C* DESCRIPTION:
7 C* read 1 data record (360,181) and flip it.
8 C*
9 C* INPUT PARAMETERS:
10 C* char *(*) filename - file to read
11 C*
12 C* OUTPUT PARAMETERS:
13 C* real datrtn - array of return values
14 C* integer year, month, day, hour - temporal info of read data
15 C*
16 C* COMMON AREAS: none
17 C*
18 C* LOCAL VARIABLES:
19 C* pds - header string
20 C* data - full globe of data
21 C*
22 C* SUBROUTINES CALLED:
23 C* none
24 C*
25 C* HISTORY:
26 C*
27 C* AUTHOR: Brian D. Schieber, GSC, 6/92
28 C*
29 C* MODIFICATION HISTORY:
30 C* BDS, 9/18/96 Support NEW 1x1 deg GDAS1 data files
31 C*
32 C*****************************************************************
33 
34  subroutine readgrib(filename, datrtn, year, month, day, hour)
35 c
36 c Mods:
37 c
38  character*(*) filename
39  real datarr(65160)
40  real datrtn(65160)
41  real global(360,181)
42  integer i, j, jj, k
43  integer ipdsl, lenkgds, nwords
44  integer year, month, day, hour
45  integer kgds(200)
46 
47  character * 1 pds(50)
48 c
49 c equivalence nhem and shem so equator overlaps
50 c
51 c equivalence (shem(1),datarr(1))
52 c equivalence (nhem(1),datarr(5221))
53 
54 c equivalence datarr to global array to get lat/lon indices for image flip
55 c equivalence (datarr(1), global(360,181))
56 c
57 c open file
58 c
59  open(9, err=998, file=filename, type='unknown',
60  + form='unformatted')
61 c
62 c read grid
63 c
64  read (9) ipdsl, lenkgds, nwords
65  read (9) (pds(jj),jj=1,ipdsl)
66  IF (lenkgds.ne.0) read (9) (kgds(jj),jj=1,lenkgds)
67  read (9) (datarr(j),j=1,nwords)
68 
69  year = ichar(pds(13))
70 c print *,'year ', year
71  month = ichar(pds(14))
72 c print *,'month ', month
73  day = ichar(pds(15))
74 c print *,'day ', day
75  hour = ichar(pds(16))
76 c print *,'hour ', hour
77 c
78 c k = 0
79 c do j = 181, 1, -1
80 c do i = 1, 360
81 c k = k+1
82 c datrtn(k) = global(j,i)
83 c end do
84 c end do
85 
86  do i = 1, 65160
87  datrtn(i) = datarr(i)
88  end do
89 c
90  goto 1000
91 
92  998 print *, 'error opening file'
93  status = -1
94 
95 1000 continue
96  return
97  end
98 
int readgrib(char *file, int npix, int nlin, float *data, int *year, int *month, int *day, int *hour)
Definition: readgrib.c:6