OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
rd_smmr_orb.c
Go to the documentation of this file.
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <unistd.h>
4 #include <stdlib.h>
5 #include "hdfio.h"
6 
7 int rd_smmr_orb(char *sfile, int *nrec, int *syear, int *sday,
8  double **orbvec, double **time, float **pos_err)
9 /*******************************************************************
10 
11  rd_smmr_orb
12 
13  purpose: read in all important smmr orbit file information
14 
15  Returns type: int - 0 if no problems
16  if no file exists, return nrec = 0 and don't allocate
17  orbvec, time
18 
19  Parameters: (in calling order)
20  Type Name I/O Description
21  ---- ---- --- -----------
22  char * sfile I name of smmr hdf file
23  int * nrec O # of orbit records
24  int * syear O year YYYY
25  int * sday O day of year DDD
26  double ** orbvec O pointer to
27  size [ nrec, 6 ] array of
28  position (0-2) and
29  velocity (3-5)
30  double ** time O pointer to
31  time tag, seconds of the day
32  float ** pos_err O extimated position error in m
33 
34  Modification history:
35  Programmer Date Description of change
36  ---------- ---- ---------------------
37  W. Robinson, SAIC 15-Sep-2005 Original development
38 
39  *******************************************************************/ {
40  int i, iret, yrday;
41  hdfio_struc hdf_info;
42  float *pos, *vel;
43  short *min;
44  int32 ntype, count;
45  struct stat buf;
46  /*
47  * open the file
48  */
49  ntype = DFNT_INT32;
50  count = 1;
51  iret = 0;
52 
53  if (stat(sfile, &buf) != 0) {
54  *nrec = 0;
55  return iret;
56  }
57  if (hdfio_open(sfile, &hdf_info) != 0) {
58  iret = 1;
59  return iret;
60  }
61  /*
62  * get the attributes first
63  */
64  if (hdfio_rd_gattr(hdf_info, "Number of values", ntype, count,
65  (void *) nrec) != 0) {
66  printf("Unable to read global attribute 'Number_of_values'\n");
67  printf("From file %s\n", sfile);
68  iret = 1;
69  return iret;
70  }
71  if (hdfio_rd_gattr(hdf_info, "Year Day", ntype, count,
72  (void *) &yrday) != 0) {
73  printf("Unable to read global attribute 'Year_Day'\n");
74  printf("From file %s\n", sfile);
75  iret = 1;
76  return iret;
77  }
78  *syear = yrday / 1000 + 1900;
79  *sday = yrday % 1000;
80  /*
81  * set up the position and velocity arrays and the final orbvec and time arrs
82  */
83  if ((pos = malloc(3 * *nrec * sizeof ( float))) == NULL) {
84  printf("Unable to allocate pos array\n");
85  iret = 1;
86  return iret;
87  }
88  if ((vel = malloc(3 * *nrec * sizeof ( float))) == NULL) {
89  printf("Unable to allocate pos array\n");
90  iret = 1;
91  return iret;
92  }
93  if ((min = malloc(*nrec * sizeof ( short))) == NULL) {
94  printf("Unable to allocate min array\n");
95  iret = 1;
96  return iret;
97  }
98  /* */
99  if ((*orbvec = malloc(6 * *nrec * sizeof ( double))) == NULL) {
100  printf("Unable to allocate orbvec array\n");
101  iret = 1;
102  return iret;
103  }
104  if ((*time = malloc(*nrec * sizeof ( double))) == NULL) {
105  printf("Unable to allocate time array\n");
106  iret = 1;
107  return iret;
108  }
109  if ((*pos_err = malloc(*nrec * sizeof ( float))) == NULL) {
110  printf("Unable to allocate pos_err array\n");
111  iret = 1;
112  return iret;
113  }
114  /*
115  * read in the time and set it up for output
116  NOTE that read_sd dosen't read anything but float, so be ready for enhancements!!
117  */
118  if (hdfio_rd_sd(hdf_info, "time", (void *) min) != 0) {
119  printf(" Unable to read sd 'time'\n");
120  iret = 1;
121  return iret;
122  }
123 
124  if (hdfio_rd_sd(hdf_info, "pos", (void *) pos) != 0) {
125  printf(" Unable to read sd 'pos'\n");
126  iret = 1;
127  return iret;
128  }
129  if (hdfio_rd_sd(hdf_info, "vel", (void *) vel) != 0) {
130  printf(" Unable to read sd 'pos'\n");
131  iret = 1;
132  return iret;
133  }
134  if (hdfio_rd_sd(hdf_info, "position error", (void *) (*pos_err)) != 0) {
135  printf(" Unable to read sd 'position_error'\n");
136  iret = 1;
137  return iret;
138  }
139  for (i = 0; i < *nrec; i++) {
140  *(*time + i) = ((double) *(min + i));
141  *(*orbvec + i * 6) = *(pos + i * 3);
142  *(*orbvec + i * 6 + 1) = *(pos + i * 3 + 1);
143  *(*orbvec + i * 6 + 2) = *(pos + i * 3 + 2);
144  *(*orbvec + i * 6 + 3) = *(vel + i * 3);
145  *(*orbvec + i * 6 + 4) = *(vel + i * 3 + 1);
146  *(*orbvec + i * 6 + 5) = *(vel + i * 3 + 2);
147  }
148  /*
149  * and end
150  */
151  hdfio_close(hdf_info);
152  return iret;
153 }
These are used to scale the SD before writing it to the HDF4 file The default is and which means the product is not scaled at all Since the product is usually stored as a float inside of this is a way to write the float out as a integer l2prod min
#define NULL
Definition: decode_rs.h:63
void hdfio_close(hdfio_struc hdfinfo)
Definition: hdfio.c:223
float32 * pos
Definition: l1_czcs_hdf.c:35
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT32
int syear
Definition: l1_czcs_hdf.c:15
int hdfio_rd_gattr(hdfio_struc hdfinfo, char *name, int32 n_type, int32 count, void *data)
Definition: hdfio.c:62
int sday
Definition: l1_czcs_hdf.c:15
int hdfio_open(char *fname, hdfio_struc *hdfinfo)
Definition: hdfio.c:16
int rd_smmr_orb(char *sfile, int *nrec, int *syear, int *sday, double **orbvec, double **time, float **pos_err)
Definition: rd_smmr_orb.c:7
this program makes no use of any feature of the SDP Toolkit that could generate such a then geolocation is calculated at that and then aggregated up to Resolved feature request Bug by adding three new int8 SDSs for each high resolution offsets between the high resolution geolocation and a bi linear interpolation extrapolation of the positions This can be used to reconstruct the high resolution geolocation Resolved Bug by delaying cumulation of gflags until after validation of derived products Resolved Bug by setting Latitude and Longitude to the correct fill resolving to support Near Real Time because they may be unnecessary if use of entrained ephemeris and attitude data is turned resolving bug report Corrected to filter out Aqua attitude records with missing status helping resolve bug MOD_PR03 will still correctly write scan and pixel data that does not depend upon the start time
Definition: HISTORY.txt:248
float32 * pos_err
Definition: l1_czcs_hdf.c:35
int i
Definition: decode_rs.h:71
int hdfio_rd_sd(hdfio_struc hdfinfo, char *arr_name, void *array)
Definition: hdfio.c:142
int count
Definition: decode_rs.h:79