OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
aer_io.c
Go to the documentation of this file.
1 /* =========================================================== */
2 /* Module aer_io.c */
3 /* */
4 /* Functions to open and read an aerosol specification file. */
5 /* */
6 /* Written By: */
7 /* */
8 /* B. A. Franz */
9 /* SAIC General Sciences Corp. */
10 /* NASA/SIMBIOS Project */
11 /* March 2001 */
12 /* */
13 /* =========================================================== */
14 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 
19 #include "filehdr_struc.h"
20 #include "filehandle.h"
21 #include "aer_struc.h"
22 
23 static FILE *fp = NULL;
24 static char current_file[FILENAME_MAX];
25 
26 
27 /* ----------------------------------------------------------- */
28 /* close_aer() - close aerosol file */
29 
30 /* ----------------------------------------------------------- */
31 void close_aer(void) {
32  fclose(fp);
33 }
34 
35 
36 /* ----------------------------------------------------------- */
37 /* read_aerhdr() - loads header info */
38 
39 /* ----------------------------------------------------------- */
40 int read_aerhdr(filehandle *file) {
41  filehdr hdr;
42 
43  fseek(fp, 0, SEEK_SET);
44 
45  if (fread(&hdr, 1, sizeof (hdr), fp) != sizeof (hdr)) {
46  printf("-E- %s: File read error.\n", __FILE__);
47  return (1);
48  }
49 
50  if (hdr.length < 0 || hdr.length > 1000000 ||
51  hdr.npix < 0 || hdr.npix > 10000) {
52  printf("-E- %s: Header values out of range.\n", __FILE__);
53  printf(" Record length = %d\n", hdr.length);
54  printf(" Pixels per scan = %d\n", hdr.npix);
55  return (1);
56  }
57 
58  file->sensorID = hdr.sensorID;
59  file->length = hdr.length;
60  file->npix = hdr.npix;
61  file->format = hdr.format;
62  file->nscan = hdr.nscan;
63  file->mode = READ;
64 
65  return (0);
66 }
67 
68 
69 /* ----------------------------------------------------------- */
70 /* open_aer() - opens file if not already opened */
71 
72 /* ----------------------------------------------------------- */
73 int open_aer(filehandle *file) {
74  if (fp == NULL || strcmp(file->name, current_file) != 0) {
75  if (fp != NULL) close_aer();
76  if ((fp = fopen(file->name, "r")) == NULL) {
77  printf("-E- %s: Error opening %s for reading.\n",
78  __FILE__, file->name);
79  return (1);
80  }
81  strcpy(current_file, file->name);
82  if (read_aerhdr(file) != 0) {
83  printf("-E- %s: Error reading header for %s.\n",
84  __FILE__, file->name);
85  return (1);
86  }
87  }
88 
89  return (0);
90 }
91 
92 
93 /* ----------------------------------------------------------- */
94 /* read_aer() - reads one aerosol record */
95 /* */
96 /* B. A. Franz, GSC, SIMBIOS Project, March 2001 */
97 
98 /* ----------------------------------------------------------- */
99 int read_aer(filehandle *file, int32_t recnum, aestr *aerec) {
100  /* */
101  /* Open the input file if it is not already open */
102  /* */
103  if (open_aer(file) != 0) {
104  printf("-E- %s: File open error.\n", __FILE__);
105  return (1);
106  }
107 
108  if (feof(fp)) {
109  printf("-I- %s: End of aer file %s reached.",
110  __FILE__, file->name);
111  return (1);
112  }
113 
114  if (fseek(fp, (recnum + 1) * file->length, SEEK_SET) != 0) {
115  printf("-E- %s: Error seeking record %d in %s.",
116  __FILE__, recnum, file->name);
117  return (1);
118  }
119 
120  if (fread(aerec->data, 1, file->length, fp) != file->length) {
121  return (1);
122  }
123 
124  aerec->length = file->length;
125  aerec->npix = file->npix;
126 
127  return (0);
128 }
129 
130 
131 
132 
133 
int read_aerhdr(filehandle *file)
Definition: aer_io.c:40
#define NULL
Definition: decode_rs.h:63
#define READ
Definition: l1c.h:32
int read_aer(filehandle *file, int32_t recnum, aestr *aerec)
Definition: aer_io.c:99
int open_aer(filehandle *file)
Definition: aer_io.c:73
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed file
Definition: HISTORY.txt:413
void close_aer(void)
Definition: aer_io.c:31
read recnum
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")