OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
met_reverse.c
Go to the documentation of this file.
1 #include "hio.h"
2 
3 int main(int argc, char *argv[])
4 /*******************************************************************
5 
6  met_reverse
7 
8  purpose: reverse the lines of a met file in the latitude direction - to fix
9  a problem in ancnrt that happened starting Jul 2009
10 
11  Returns type: status of 0 is all good
12 
13  Parameters: (in calling order)
14  Type Name I/O Description
15  ---- ---- --- -----------
16  int argc I count of arguments
17  char *[] argv I [1] is the met file to reverse
18  the fields of
19 
20  Modification history:
21  Programmer Date Description of change
22  ---------- ---- ---------------------
23  W. Robinson 18-Sep-2009 Original development,
24 
25  *******************************************************************/ {
26  hio_struct hinfo;
27  float *data, *xfr_arr;
28  int nlin = 181, npix = 360, ilin, iret = 0, irc, ifld, nfld = 5;
29  char *b_data, *b_xfr;
30  char *met_fields[] = {"z_wind", "m_wind", "press", "p_water", "rel_hum"};
31  char *qc_fields[] = {"z_wind_QC", "m_wind_QC", "press_QC",
32  "p_water_QC", "rel_hum_QC"};
33  /*
34  * open the file
35  */
36  if (hio_open(argv[1], DFACC_RDWR, &hinfo) != 0) {
37  printf("%s: hio_open failure\n", __FILE__);
38  iret = 1;
39  exit(iret);
40  }
41  /*
42  * do all fields, parm and QC
43  */
44  irc = 0;
45  if ((xfr_arr = (float *) malloc(npix * sizeof ( float))) == NULL)
46  irc++;
47  if ((b_xfr = (char *) malloc(npix * sizeof ( char))) == NULL)
48  irc++;
49  if ((data = (float *) malloc(npix * nlin * sizeof ( float))) == NULL)
50  irc++;
51  if ((b_data = (char *) malloc(npix * nlin * sizeof ( char))) == NULL)
52  irc++;
53  if (irc != 0) {
54  printf("%s: Transfer space allocation failed\n", __FILE__);
55  iret = 1;
56  } else {
57  for (ifld = 0; ifld < nfld; ifld++) {
58  /*
59  * read a SDS
60  */
61  if (hio_r_sds(hinfo, met_fields[ifld],
62  DFNT_FLOAT32, (void *) data) != 0) {
63  printf("%s: hio_r_sds failure\n", __FILE__);
64  iret = 1;
65  exit(iret);
66  }
67  /*
68  * reverse the data
69  */
70  for (ilin = 0; ilin < nlin / 2; ilin++) {
71  memcpy((void *) xfr_arr, (void *) (data + ilin * npix),
72  npix * sizeof ( float));
73  memcpy((void *) (data + ilin * npix),
74  (void *) (data + (nlin - 1 - ilin) * npix),
75  npix * sizeof ( float));
76  memcpy((void *) (data + (nlin - 1 - ilin) * npix),
77  (void *) xfr_arr, npix * sizeof ( float));
78  }
79  /*
80  * write it out again
81  */
82  if (hio_i_sds(hinfo, met_fields[ifld],
83  DFNT_FLOAT32, (void *) data) != 0) {
84  printf("%s: hio_i_sds failure\n", __FILE__);
85  iret = 1;
86  exit(iret);
87  }
88  /*
89  * do the same for the QC byte arrays
90  */
91  if (hio_r_sds(hinfo, qc_fields[ifld],
92  DFNT_INT8, (void *) b_data) != 0) {
93  printf("%s: hio_r_sds failure\n", __FILE__);
94  iret = 1;
95  exit(iret);
96  }
97 
98  for (ilin = 0; ilin < nlin / 2; ilin++) {
99  memcpy((void *) b_xfr, (void *) (b_data + ilin * npix),
100  npix * sizeof ( char));
101  memcpy((void *) (b_data + ilin * npix),
102  (void *) (b_data + (nlin - 1 - ilin) * npix),
103  npix * sizeof ( char));
104  memcpy((void *) (b_data + (nlin - 1 - ilin) * npix),
105  (void *) b_xfr, npix * sizeof ( char));
106  }
107 
108  if (hio_i_sds(hinfo, qc_fields[ifld],
109  DFNT_INT8, (void *) b_data) != 0) {
110  printf("%s: hio_i_sds failure\n", __FILE__);
111  iret = 1;
112  exit(iret);
113  }
114  }
115  }
116  /*
117  * close the file
118  */
119  if (hio_close(hinfo) != 0) {
120  printf("%s: hio_close failure\n", __FILE__);
121  iret = 1;
122  }
123  free(xfr_arr);
124  free(b_xfr);
125  free(data);
126  free(b_data);
127 
128  exit(iret);
129 }
#define NULL
Definition: decode_rs.h:63
int32 hio_i_sds(hio_struct, char *, int32, void *)
Definition: hio_i_sds.c:4
int nlin
Definition: get_cmp.c:28
int32 hio_close(hio_struct)
Definition: hio_close.c:3
int main(int argc, char *argv[])
Definition: met_reverse.c:3
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
int32 hio_open(char *, int32, hio_struct *)
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_FLOAT32
int32 hio_r_sds(hio_struct, char *, int32, void *)
Definition: hio_r_sds.c:4
int npix
Definition: get_cmp.c:27