OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1io_open.c
Go to the documentation of this file.
1 #include "l1io.h"
2 #include <mfhdf.h>
3 
4 int32_t l1io_open(char *fname, l1info_struct *l1info,
5  int32_t *npix, int32_t *nlin)
6 /*******************************************************************
7 
8  get_l1a_open
9 
10  purpose: open the level 1 dataset and send back the # lines, pixels
11 
12  Returns type: int32 - return status: 0 is good
13 
14  Parameters: (in calling order)
15  Type Name I/O Description
16  ---- ---- --- -----------
17  char * fname I name of file to open
18  struct l1info_struct * l1info O information struct
19  about the opened file
20  int32 * npix O # of pixels in data
21  int32 * nlin O # of lines in data
22 
23  Modification history:
24  Programmer Date Description of change
25  ---------- ---- ---------------------
26  W. Robinson 16-Aug-1994 Original development
27 
28  *******************************************************************/
29  {
30 
31  int32 attr_index;
32  /* hopen will open the file and read data descriptor blocks
33  to memory
34  */
35  if ((l1info->fid = Hopen(fname, DFACC_RDONLY, 0)) < 0) {
36  printf("l1io_open: Failed on the Hopen of \n%s\n", fname);
37  return -1;
38  }
39 
40  /*
41  * SDstart opens the hdf interface and inits the SD interface, wierd.
42  * apparently, if both SD and HDF are used, both these need to
43  * be called.
44  */
45  if ((l1info->sdfid = SDstart(fname, DFACC_RDONLY)) < 0) {
46  printf("l1io_open: Failure at SDstart of \n%s\n", fname);
47  l1io_close(*l1info);
48  return -1;
49  }
50 
51  /*
52  * ok, it's open.
53  * the # samples and # lines are global attributes, get here
54  * first get the index for the name
55  */
56  /* for use before 15 Aug 94 I/O v3.0
57  if( ( attr_index = SDfindattr( l1info->sdfid, "Pixels per scan line" ) )
58  == -1 )
59  */
60 
61  /* for use after 15 Aug 94 I/O v3.0 */
62  if ((attr_index = SDfindattr(l1info->sdfid, "Pixels per Scan line"))
63  == -1)
64  /*
65  * Well, there is another possibility, and I don't wish to exclude
66  * the older name yet, so check for this possibility
67  */ {
68  if ((attr_index = SDfindattr(l1info->sdfid, "Pixels per Scan Line"))
69  == -1) {
70  printf("l1io_open: Error trying to get global attr Pixels per Scan line (or ...Line)\n");
71  l1io_close(*l1info);
72  return -1;
73  }
74  }
75  /*
76  * for an unknown attribute, you would call SDattrinfo so you
77  * could allocate the right type and space for the data but
78  * we know this already (sic) so
79  *
80  * read in the attribute
81  */
82  if (SDreadattr(l1info->sdfid, attr_index, npix) == -1) {
83  printf("l1io_open: Error trying to get data for: Pixels per Scan line\n");
84  l1io_close(*l1info);
85  return -1;
86  }
87 
88  /*
89  * get the # lines also the same way
90  */
91  /* for use after 15 Aug 94 I/O v3.0 */
92  if ((attr_index = SDfindattr(l1info->sdfid, "Number of Scan Lines"))
93  == -1)
94  /* for use before 15 Aug 94 I/O v3.0
95  if( ( attr_index = SDfindattr( l1info->sdfid, "Number of scan lines" ) )
96  == -1 )
97  */ {
98  printf("l1io_open: Error trying to get global attr: Number of Scan Lines\n");
99  l1io_close(*l1info);
100  return -1;
101  }
102 
103  if (SDreadattr(l1info->sdfid, attr_index, nlin) == -1) {
104  printf("l1io_open: Error trying to get data for Number of Scan Lines\n");
105  l1io_close(*l1info);
106  return -1;
107  }
108  /*
109  * and return successfully
110  */
111  return 0;
112 
113 }
int nlin
Definition: get_cmp.c:28
int32_t l1io_open(char *fname, l1info_struct *l1info, int32_t *npix, int32_t *nlin)
Definition: l1io_open.c:4
void l1io_close(l1info_struct)
Definition: l1io_close.c:4
int npix
Definition: get_cmp.c:27