OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
oisst_info.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #include "genutils.h"
6 
7 
8 /* ----------------------------------------------------------------------------------- */
9 /* oisst_info() - echo meta-data from flat binary Reynolds OIV2 SST */
10 /* */
11 /* The files were written in IEEE binary (big-endian). Each file contains four FORTRAN */
12 /* records described as follows: */
13 /* */
14 /* rec 1: date and version number (8 4-byte integer words) */
15 /* rec 2: gridded sst values in degC (360*180 4-byte real words) */
16 /* rec 3: normalized error variance (360*180 4-byte real words) */
17 /* rec 4: gridded ice concentration (360*180 1-byte integer words) */
18 /* */
19 /* B. Franz, SAIC, May 2004. */
20 
21 /* ----------------------------------------------------------------------------------- */
22 
23 int main(int argc, char *argv[]) {
24  char *sstfile = argv[1];
25  FILE *fp = NULL;
26  int32_t syear, smon, sday;
27  int32_t eyear, emon, eday;
28  int32_t ndays, version;
29 
30  if ((fp = fopen(sstfile, "r")) == NULL) {
31  printf("Error opening SST reference file %s for reading.\n", sstfile);
32  exit(1);
33  }
34 
35  if (fseek(fp, 4, SEEK_SET) < 0) {
36  printf("Error reading SST reference file %s.\n", sstfile);
37  exit(1);
38  }
39  if (fread(&syear, sizeof (int32_t), 1, fp) != 1) {
40  printf("Error reading SST reference file %s.\n", sstfile);
41  exit(1);
42  }
43  fread(&smon, sizeof (int32_t), 1, fp);
44  fread(&sday, sizeof (int32_t), 1, fp);
45  fread(&eyear, sizeof (int32_t), 1, fp);
46  fread(&emon, sizeof (int32_t), 1, fp);
47  fread(&eday, sizeof (int32_t), 1, fp);
48  fread(&ndays, sizeof (int32_t), 1, fp);
49  fread(&version, sizeof (int32_t), 1, fp);
50  fseek(fp, 4, SEEK_CUR);
51 
52  if (endianess() == 1) {
53  swapc_bytes((char *) &syear, sizeof (int32_t), 1);
54  swapc_bytes((char *) &smon, sizeof (int32_t), 1);
55  swapc_bytes((char *) &sday, sizeof (int32_t), 1);
56  swapc_bytes((char *) &eyear, sizeof (int32_t), 1);
57  swapc_bytes((char *) &emon, sizeof (int32_t), 1);
58  swapc_bytes((char *) &eday, sizeof (int32_t), 1);
59  swapc_bytes((char *) &ndays, sizeof (int32_t), 1);
60  swapc_bytes((char *) &version, sizeof (int32_t), 1);
61  }
62 
63  printf("OI Reynolds SST file %s\n", sstfile);
64  printf("start_date=%.4d-%.2d-%.2d 00:00:00\n", syear, smon, sday);
65  printf("end_date=%.4d-%.2d-%.2d 23:59:59\n", eyear, emon, eday);
66 
67  exit(0);
68 }
69 
int16 eday
Definition: l1_czcs_hdf.c:17
int main(int argc, char *argv[])
Definition: oisst_info.c:23
#define NULL
Definition: decode_rs.h:63
int16 eyear
Definition: l1_czcs_hdf.c:17
int syear
Definition: l1_czcs_hdf.c:15
int endianess(void)
determine endianess
Definition: endianess.c:10
int swapc_bytes(char *in, int nbyte, int ntime)
Definition: swapc_bytes.c:4
int sday
Definition: l1_czcs_hdf.c:15
version
Definition: setup.py:15