13 char ncdump[500000] =
"";
14 char tmpstr[1000] =
"";
15 char cmd_string[250] =
"";
17 char range_date[11] =
"";
18 char range_time[9] =
"";
30 char julian_str[4] =
"";
35 char date_stamp[15] =
"";
39 printf(
"\nUSAGE: %s MODIS_L1A_L1B_or_GEO_file [start|stop]\n", argv[0]);
42 if (!(fptr = fopen(argv[1],
"r"))) {
48 len = strlen(argv[1]);
49 ifile = malloc(1 + (len *
sizeof (
char)));
52 seadas = getenv(
"OCSSWROOT");
54 strcat(cmd_string,
"ncdump");
56 strcpy(cmd_string, seadas);
57 strcat(cmd_string,
"/run/bin3/ncdump");
58 if (!(testptr = fopen(cmd_string,
"r"))) {
59 strcpy(cmd_string, seadas);
60 strcat(cmd_string,
"/bin/ncdump");
61 if (!(testptr = fopen(cmd_string,
"r"))) {
62 printf(
"modis_timestamp: Error - ncdump must exist in $SEADAS/run/bin3/ or $SEADAS/bin/ to run this program.\n");
68 strcat(cmd_string,
" -h ");
69 strcat(cmd_string,
ifile);
71 fp =
popen(cmd_string,
"r");
72 while (fgets(tmpstr,
sizeof tmpstr, fp)) {
73 strcat(ncdump, tmpstr);
78 if (
argc == 2) argv[2] = argv[1];
79 if (strcmp(argv[2],
"stop") == 0) ptr = strstr(ncdump,
"RANGEENDINGDATE");
80 else ptr = strstr(ncdump,
"RANGEBEGINNINGDATE");
82 printf(
"modis_timestamp: Error - File doesn't appear to have a valid MODIS HDF header.\n");
85 ptr = strstr(ptr,
"VALUE");
87 printf(
"modis_timestamp: Error - File doesn't appear to have a valid MODIS HDF header.\n");
90 strncpy(range_date, ptr + 25, 10);
91 range_date[10] =
'\0';
94 if (strcmp(argv[2],
"stop") == 0) ptr = strstr(ncdump,
"RANGEENDINGTIME");
95 else ptr = strstr(ncdump,
"RANGEBEGINNINGTIME");
97 printf(
"modis_timestamp: Error - File doesn't appear to have a valid MODIS HDF header.\n");
100 ptr = strstr(ptr,
"VALUE");
102 printf(
"modis_timestamp: Error - File doesn't appear to have a valid MODIS HDF header.\n");
105 strncpy(range_time, ptr + 25, 8);
106 range_time[8] =
'\0';
109 ptr = strstr(ncdump,
" SHORTNAME");
111 printf(
"modis_timestamp: Error - File doesn't appear to have a valid MODIS HDF header.\n");
114 ptr = strstr(ptr,
"VALUE");
116 printf(
"modis_timestamp: Error - File doesn't appear to have a valid MODIS HDF header.\n");
125 }
else if (strcmp(
platform,
"MOD") == 0) {
128 printf(
"modis_timestamp: Error - Could not determine platform.\n");
132 strncpy(year, &range_date[0], 4);
134 strncpy(month, &range_date[5], 2);
140 sscanf(year,
"%d", &year_int);
148 sscanf(
day,
"%d", &day_int);
150 if (strcmp(month,
"01") == 0)
152 else if (strcmp(month,
"02") == 0)
154 else if (strcmp(month,
"03") == 0)
155 basedays = 59 + add_leap_day;
156 else if (strcmp(month,
"04") == 0)
157 basedays = 90 + add_leap_day;
158 else if (strcmp(month,
"05") == 0)
159 basedays = 120 + add_leap_day;
160 else if (strcmp(month,
"06") == 0)
161 basedays = 151 + add_leap_day;
162 else if (strcmp(month,
"07") == 0)
163 basedays = 181 + add_leap_day;
164 else if (strcmp(month,
"08") == 0)
165 basedays = 212 + add_leap_day;
166 else if (strcmp(month,
"09") == 0)
167 basedays = 243 + add_leap_day;
168 else if (strcmp(month,
"10") == 0)
169 basedays = 273 + add_leap_day;
170 else if (strcmp(month,
"11") == 0)
171 basedays = 304 + add_leap_day;
172 else if (strcmp(month,
"12") == 0)
173 basedays = 334 + add_leap_day;
175 julian_days = basedays + day_int;
177 if (julian_days < 10) {
178 strcpy(julian_str,
"00\0");
179 }
else if (julian_days < 100) {
180 strcpy(julian_str,
"0\0");
185 sprintf(jul_str,
"%d", julian_days);
186 strcat(julian_str, jul_str);
190 ptr = &range_time[3];
193 ptr = &range_time[6];
198 date_stamp[0] = first_letter;
199 date_stamp[1] =
'\0';
200 strcat(date_stamp, year);
201 strcat(date_stamp, julian_str);
202 strcat(date_stamp, hour);
203 strcat(date_stamp,
min);
204 strcat(date_stamp, sec);
205 date_stamp[14] =
'\0';
207 printf(
"%s", date_stamp);