OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
rd_toms_ascii.c
Go to the documentation of this file.
1 #include <mfhdf.h>
2 #include "ancil.h"
3 #include "ancnrt_proto.h"
4 #include "o3_toms.h"
5 #include <stdio.h>
6 #include <ctype.h>
7 
8 int rd_toms_ascii(char *file, toms_txt_info_struc *toms_info)
9 /*******************************************************************
10 
11  rd_toms_ascii
12 
13  purpose: read the controls and data from a TOMS ascii text file
14 
15  Returns type: int - 0 if all is OK
16 
17  Parameters: (in calling order)
18  Type Name I/O Description
19  ---- ---- --- -----------
20  char * file I text file from TOMS project
21  toms_txt_info_struc * toms_info O structure containing all the
22  information and data
23 
24  Modification history:
25  Programmer Date Description of change
26  ---------- ---- ---------------------
27  W. Robinson, SAIC 6 Dec 2013 replacement for rdgrid.f and more
28  flexible
29 
30  *******************************************************************/ {
31  FILE *fid;
32  int32_t doy, year, asc_node_h, asc_node_m, nlon, nlat, toms_typ;
33  int32_t iv, ip, il, ilrev, end_ilin, end_olin, cptr;
34  float slon, elon, del_lon, slat, elat, del_lat;
35  char rstr[100];
36  char inst_str[27], asc_node_tod[4];
37  int16 *ptr;
38  char *upcase();
39  /*
40  * open the file and get the header information
41  */
42  if ((fid = fopen(file, "r")) == NULL) {
43  printf("%s, %d E: Could not open TOMS text file: %s\n",
44  __FILE__, __LINE__, file);
45  return 1;
46  }
47  if (fgets(rstr, 90, fid) == NULL) {
48  printf("%s, %d E: Unexpected end of grid file found, file: %s\n",
49  __FILE__, __LINE__, file);
50  return 1;
51  }
52  if ((sscanf(&rstr[6], "%3d", &doy) != 1) ||
53  (sscanf(&rstr[18], "%4d", &year) != 1) ||
54  (sscanf(&rstr[23], "%s", inst_str) != 1) ||
55  (sscanf(&rstr[50], "%s", toms_info->gen_str) != 1) ||
56  (sscanf(&rstr[71], "%2d", &asc_node_h) != 1) ||
57  (sscanf(&rstr[74], "%2d", &asc_node_m) != 1) ||
58  (sscanf(&rstr[77], "%s", asc_node_tod) != 1)) {
59  printf("%s, %d E: Trouble reading header 1 of text file: %s\n",
60  __FILE__, __LINE__, file);
61  return 1;
62  }
63  toms_typ = TOMS_TYP_UNKNOWN;
64  if (strcmp(inst_str, "OMI") == 0) toms_typ = TOMS_TYP_OMITOMS;
65  if (strcmp(inst_str, "NIMBUS-7/TOMS") == 0) toms_typ = TOMS_TYP_N7TOMS;
66  if (strcmp(inst_str, "EP/TOMS") == 0) toms_typ = TOMS_TYP_EPTOMS;
67 
68  toms_info->toms_typ = toms_typ;
69  toms_info->year = year;
70  toms_info->doy = doy;
71  /*
72  * make the ascending node string
73  */
74  if (strncmp(upcase(asc_node_tod), "PM", 2) == 0)
75  asc_node_h += 12;
76  sprintf(toms_info->node_time, "%04d%03d%02d%02d00000", year, doy,
77  asc_node_h, asc_node_m);
78  /*
79  * get 2nd line with longitude info
80  */
81  if (fgets(rstr, 90, fid) == NULL) {
82  printf("%s, %d E: Unexpected end of grid file found, file: %s\n",
83  __FILE__, __LINE__, file);
84  return 1;
85  }
86  if ((sscanf(&rstr[13], "%4d", &nlon) != 1) ||
87  (sscanf(&rstr[35], "%7f", &slon) != 1) ||
88  (sscanf(&rstr[48], "%7f", &elon) != 1) ||
89  (sscanf(&rstr[60], "%4f", &del_lon) != 1)) {
90  printf("%s, %d E: Trouble reading header 1 of text file: %s\n",
91  __FILE__, __LINE__, file);
92  return 1;
93  }
94 
95  slon = -slon;
96  toms_info->nlon = nlon;
97  toms_info->slon = slon;
98  toms_info->elon = elon;
99  toms_info->del_lon = del_lon;
100  /*
101  * assume W -> E but we can check what's in the file
102  * in various files of this sort, the 'W', 'E' characters may be located
103  * in duifferent columns - this handles both possibilities
104  */
105  if (((toupper(rstr[42]) != 'W') && (toupper(rstr[43]) != 'W')) ||
106  ((toupper(rstr[55]) != 'E') && (toupper(rstr[56]) != 'E'))) {
107  printf("%s, %d E: grid data is not W -> E %s\n",
108  __FILE__, __LINE__, file);
109  return 1;
110  }
111  /*
112  * get 3rd line with latitude info
113  */
114  if (fgets(rstr, 90, fid) == NULL) {
115  printf("%s, %d E: Unexpected end of grid file found, file: %s\n",
116  __FILE__, __LINE__, file);
117  return 1;
118  }
119  if ((sscanf(&rstr[13], "%4d", &nlat) != 1) ||
120  (sscanf(&rstr[35], "%7f", &slat) != 1) ||
121  (sscanf(&rstr[48], "%7f", &elat) != 1) ||
122  (sscanf(&rstr[60], "%4f", &del_lat) != 1)) {
123  printf("%s, %d E: Trouble reading header 1 of text file: %s\n",
124  __FILE__, __LINE__, file);
125  return 1;
126  }
127 
128  slat = -slat;
129  toms_info->nlat = nlat;
130  toms_info->slat = slat;
131  toms_info->elat = elat;
132  toms_info->del_lat = del_lat;
133  /*
134  * assume S -> N but we can check what's in the file
135  * and make the start lat, lon be (-)
136  */
137  if (((toupper(rstr[42]) != 'S') && (toupper(rstr[43]) != 'S')) ||
138  ((toupper(rstr[55]) != 'N') && (toupper(rstr[56]) != 'N'))) {
139  printf("%s, %d E: grid data is not S -> N %s\n",
140  __FILE__, __LINE__, file);
141  return 1;
142  }
143  /*
144  * allocate the space for the ozone and read it in
145  * reverse array in latitude so it goes N - S and W - E
146  */
147  if ((toms_info->datarr = (int16 *) malloc(nlat * nlon * sizeof (int16)))
148  == NULL) {
149  printf("%s, %d E: Unable to allocate space for the ozone storage\n",
150  __FILE__, __LINE__);
151  printf(" File: %s\n", file);
152  return 1;
153  }
154  for (il = 0; il < nlat; il++) {
155  ilrev = nlat - il - 1;
156  end_olin = 0;
157  end_ilin = 0;
158  ip = 0;
159  while (end_olin == 0) {
160  fgets(rstr, 90, fid);
161  /* this forces any space chars to be 0 except 1st */
162  /* so sscanf stays with right 3 char group */
163  for (iv = 1; iv < 89; iv++)
164  if (*(rstr + iv) == ' ') *(rstr + iv) = '0';
165  cptr = 1;
166  end_ilin = 0;
167  while (end_ilin == 0) {
168  ptr = &toms_info->datarr[ ip + nlon * ilrev ];
169  if (sscanf((rstr + cptr), "%3hd", ptr) != 1) {
170  end_ilin = 1;
171  } else {
172  cptr += 3;
173  if (ip == (nlon - 1)) {
174  end_ilin = 1;
175  end_olin = 1;
176  }
177  ip++;
178  }
179  }
180  }
181  }
182 
183  return 0;
184 }
integer, parameter int16
Definition: cubeio.f90:3
#define NULL
Definition: decode_rs.h:63
int rd_toms_ascii(char *file, toms_txt_info_struc *toms_info)
Definition: rd_toms_ascii.c:8
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
#define TOMS_TYP_OMITOMS
Definition: o3_toms.h:8
#define TOMS_TYP_EPTOMS
Definition: o3_toms.h:7
#define TOMS_TYP_UNKNOWN
Definition: o3_toms.h:5
char * upcase(char *instr)
Definition: upcase.c:10
#define TOMS_TYP_N7TOMS
Definition: o3_toms.h:6