OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
mkmeta.c
Go to the documentation of this file.
1 /* -------------------------------------------------------------- */
2 /* mkmeta() - creates the meta file associated with each L1A file */
3 /* */
4 /* Synopsis: */
5 /* */
6 /* int status = mkmeta(char *dir, swl0scene *scene) */
7 /* */
8 /* status error status (-1 = error) */
9 /* dir output directory */
10 /* scene fully loaded scene structure */
11 /* */
12 /* Description: */
13 /* */
14 /* Creates a file in dir with using the L1A naming convention */
15 /* and an additional .meta suffix. This function assumes the */
16 /* scene structure has been fully loaded, including navigation */
17 /* fields, and the L1A file has been created. The L1A file */
18 /* must exist for the file_size field of the meta data to be */
19 /* correct. */
20 /* */
21 /* Modification History: */
22 /* */
23 /* 30 Oct 1997, B. A. Franz, Original development */
24 /* */
25 /* -------------------------------------------------------------- */
26 
27 #include <stdio.h>
28 #include <time.h>
29 #include <libgen.h>
30 #include <stdlib.h>
31 #include <sys/param.h>
32 #include "swl0_parms.h"
33 #include "swl0_proto.h"
34 #include "swl1_hdf.h"
35 #include <timeutils.h>
36 
37 int mkmeta(const char *metaFile, const char *l1aFile, swl0scene *scene, swl0ctl *l0ctl) {
38 
39  BYTE dataType;
40  FILE *fp;
41  INT16 year;
42  INT16 day;
43  FLOAT64 sec;
44  char fullname[MAXPATHLEN];
45  char *tmppath;
46  int navstat = 0;
47 
48  if ((fp = fopen(metaFile, "w")) == NULL) {
49  fprintf(stderr,
50  "-E- %s line %d: error opening %s for writing.\n",
51  __FILE__, __LINE__, metaFile);
52  return (1);
53  }
54 
55  unix2yds(scene->stime, &year, &day, &sec);
56 
57  fprintf(fp, "%s_version=%s\n", l0ctl->progname, L01VERSION);
58 
59  tmppath = strdup(l1aFile);
60  fprintf(fp, "l1_filename=%s\n", basename(tmppath));
61  free(tmppath);
62 
63  tmppath = strdup(l1aFile);
64  fprintf(fp, "l1_pathname=%s\n", realpath(dirname(tmppath), fullname));
65  free(tmppath);
66 
67  fprintf(fp, "file_size=%d\n", filesize(l1aFile));
68 
69  if (scene->type == HRPT)
70  dataType = 16;
71  else
72  dataType = scene->mnftype;
73  fprintf(fp, "datatype=%s\n", DTypeString(dataType));
74 
75  if (scene->lower_left_lat < -90.0)
76  navstat = 1;
77 
78  fprintf(fp, "format=LEVEL_1\n");
79  fprintf(fp, "scan_line_count=%d\n", scene->nscan);
80  fprintf(fp, "filled_scan_count=%d\n", 0);
81  fprintf(fp, "start_time=%s\n", unix2timeStr(scene->stime));
82  fprintf(fp, "stop_time=%s\n", unix2timeStr(scene->etime));
83  fprintf(fp, "orbit_number=%d\n", scene->orbnum);
84 
85  fprintf(fp, "navstat=%d\n", navstat);
86  fprintf(fp, "lower_left_lat=%.2f\n", scene->lower_left_lat);
87  fprintf(fp, "lower_left_lon=%.2f\n", scene->lower_left_lon);
88  fprintf(fp, "lower_right_lat=%.2f\n", scene->lower_right_lat);
89  fprintf(fp, "lower_right_lon=%.2f\n", scene->lower_right_lon);
90  fprintf(fp, "upper_left_lat=%.2f\n", scene->upper_left_lat);
91  fprintf(fp, "upper_left_lon=%.2f\n", scene->upper_left_lon);
92  fprintf(fp, "upper_right_lat=%.2f\n", scene->upper_right_lat);
93  fprintf(fp, "upper_right_lon=%.2f\n", scene->upper_right_lon);
94 
95  tmppath = strdup(scene->l0file);
96  fprintf(fp, "raw_filename=%s\n", basename(scene->l0file));
97  free(tmppath);
98 
99  tmppath = strdup(scene->l0file);
100  fprintf(fp, "raw_pathname=%s\n", realpath(dirname(tmppath), fullname));
101  free(tmppath);
102 
103  fprintf(fp, "dataday1=%4d%03d\n", year, day);
104  fprintf(fp, "dataday2=%d\n", 0);
105  fprintf(fp, "day_night_scene=D\n");
106 
107  fclose(fp);
108 
109  return (1);
110 }
111 
112 
double FLOAT64
Definition: elements.h:8
int32_t day
int mkmeta(const char *metaFile, const char *l1aFile, swl0scene *scene, swl0ctl *l0ctl)
Definition: mkmeta.c:37
#define NULL
Definition: decode_rs.h:63
unsigned char BYTE
Definition: elements.h:4
short int INT16
Definition: elements.h:5
#define HRPT
Definition: l1stat.h:35
char * strdup(const char *)
void unix2yds(double usec, short *year, short *day, double *secs)
#define L01VERSION
Definition: swl0_parms.h:4
#define basename(s)
Definition: l0chunk_modis.c:29
char * DTypeString(unsigned char dataType)
Definition: swl1_hdf.c:1275
INT32 filesize(const char *filename)
Definition: swl0_utils.c:93
char * unix2timeStr(FLOAT64 usec)
Definition: swl0_utils.c:55