OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
tec.c
Go to the documentation of this file.
1 /*****************************************************************
2  * File: tec.c
3  *
4  * Modification history:
5  *****************************************************************/
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <libgen.h>
11 #include "hdf5.h"
12 
13 int main(int argc, char *argv[]) {
14 
15  int32_t i, j, k, Y, M, D, H, offset;
16 
17  int16_t tec_in[73 * 71];
18  char junk[120], outfile[80];
19  FILE *fp;
20 
21  hsize_t dimsf[2]; /* dataset dimensions */
22 
23  /*
24  * Data and output buffer initialization.
25  */
26  hid_t file, dataset; /* handles */
27  hid_t dataspace;
28 
29  strcpy(outfile, "N20");
30  strcpy(junk, basename(argv[1]));
31 
32  memcpy(&outfile[3], &junk[9], 2);
33  memcpy(&outfile[5], &junk[4], 3);
34  memset(&outfile[8], 0, 1);
35  if (strncmp(junk, "igrg", 4) == 0)
36  strcat(outfile, "00_TEC_IGR_24h.h5");
37  if (strncmp(junk, "igsg", 4) == 0)
38  strcat(outfile, "00_TEC_IGS_24h.h5");
39  if (strncmp(junk, "CODG", 4) == 0)
40  strcat(outfile, "00_TEC_CODE_24h.h5");
41 
42  printf("Creating: %s\n", outfile);
43 
44  file = H5Fcreate(outfile, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
45 
46  // Switched 12/01/10 by JMG
47  dimsf[0] = 71;
48  dimsf[1] = 73;
49  dataspace = H5Screate_simple(2, dimsf, NULL);
50 
51 
52  fp = fopen(argv[1], "r");
53  while (1) {
54  if (fgets(junk, 120, fp) == NULL) {
55  printf("\"END OF HEADER\" not found.\n");
56  exit(1);
57  }
58  if (strstr(junk, "END OF HEADER") != NULL) break;
59  }
60 
61 
62  for (i = 0; i < 13; i++) {
63  fgets(junk, 120, fp); // START OF TEC MAP
64  if (strstr(junk, "START OF TEC MAP") == NULL) {
65  printf("\"START OF TEC MAP\" expected but not found.");
66  exit(1);
67  }
68 
69  fgets(junk, 120, fp); // EPOCH OF CURRENT MAP
70  if (strstr(junk, "EPOCH OF CURRENT MAP") == NULL) {
71  printf("\"EPOCH OF CURRENT MAP\" expected but not found.");
72  exit(1);
73  }
74  sscanf(junk, "%d%d%d%d", &Y, &M, &D, &H);
75 
76  if (H == 0 && i == 12) H = 24;
77 
78  for (k = 0; k < 71; k++) {
79  offset = 73 * k;
80 
81  fgets(junk, 120, fp); // LAT/LON1/LON2/DLON/H
82 
83  fgets(junk, 120, fp);
84  // Note: "%hd" for short int
85  for (j = 0; j < 16; j++) sscanf(&junk[5 * j], "%hd", &tec_in[offset + j]);
86 
87  fgets(junk, 120, fp);
88  for (j = 0; j < 16; j++) sscanf(&junk[5 * j], "%hd", &tec_in[offset + 16 + j]);
89 
90  fgets(junk, 120, fp);
91  for (j = 0; j < 16; j++) sscanf(&junk[5 * j], "%hd", &tec_in[offset + 32 + j]);
92 
93  fgets(junk, 120, fp);
94  for (j = 0; j < 16; j++) sscanf(&junk[5 * j], "%hd", &tec_in[offset + 48 + j]);
95 
96  fgets(junk, 120, fp);
97  for (j = 0; j < 9; j++) sscanf(&junk[5 * j], "%hd", &tec_in[offset + 64 + j]);
98  }
99 
100  fgets(junk, 120, fp); // END OF TEC MAP
101  if (strstr(junk, "END OF TEC MAP") == NULL) {
102  printf("\"END OF TEC MAP\" expected but not found.");
103  exit(1);
104  }
105 
106  /*
107  * Create a new dataset within the file using defined dataspace and
108  * default dataset creation properties.
109  */
110 
111  sprintf(junk, "%s%02d%s", "tec_", H, "h");
112  dataset = H5Dcreate1(file, junk, H5T_NATIVE_USHORT,
113  dataspace, H5P_DEFAULT);
114 
115  /*
116  * Write the data to the dataset using default transfer properties.
117  */
118  H5Dwrite(dataset, H5T_NATIVE_USHORT, H5S_ALL, H5S_ALL,
119  H5P_DEFAULT, tec_in);
120 
121  }
122 
123  /*
124  * Close/release resources.
125  */
126  H5Sclose(dataspace);
127  H5Dclose(dataset);
128  H5Fclose(file);
129 
130 
131  return 0;
132 }
int j
Definition: decode_rs.h:73
#define NULL
Definition: decode_rs.h:63
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
int M[]
Definition: Usds.c:107
but the philosophy of the MODIS L1 routines is that the output granule must be if it contains even a single packet of useable data Some of the spacecraft ancillary data in L0 datasets is available only on a cycle that repeates every seconds MOD_PR01 therefore looks backwards up to for such packets If the seconds preceeding the start of an MOD_PR01 run are covered by a different L0 dataset
Definition: MOD_PR01_pr.txt:33
#define basename(s)
Definition: l0chunk_modis.c:29
l2prod offset
int main(int argc, char *argv[])
Definition: tec.c:13
int i
Definition: decode_rs.h:71
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
int k
Definition: decode_rs.h:73