116 short startYear,
short startMonth,
short startDay,
short startJDay,
short endYear,
short endMonth,
short endDay,
short endJDay,
char *filter,
char **extensionList,
long extensions,
long tailsOnly,
long *files,
long increaseOrder) {
117 short iyear, iday, toYearEnd, jDayLimit, year0, month0, day0, iday0, istoday, listall;
118 long yearLists, fileLists, newLists, i, index, tmpLists, j, *sortedIndex;
119 char **fileList, **yearList, **newList, **tmpList;
120 char buffer[2056], tmpstr[2056], format[2056];
121 double startTime, endTime, startHour, endHour, time0, hour0;
125 fileLists = yearLists = newLists = tmpLists = 0;
126 fileList = yearList = newList = tmpList = NULL;
127 if (!directory || !rootname || !filter) {
128 fprintf(stderr,
"directory or rootname or filter for searching files is not given!\n");
131 startTime = endTime = 0;
132 startHour = endHour = 0;
135 if (endYear == year0) {
136 if (endJDay == iday0)
138 else if (endMonth == month0 && endDay == day0)
145 if (strcmp(filter,
"-??\??") == 0) {
147 sprintf(format,
"%s%s-%s", rootname,
"%d",
"%02d%02d%s");
149 sprintf(format,
"%s/%s%s-%s", directory, rootname,
"%d",
"%02d%02d%s");
150 }
else if (strcmp(filter,
"-??\?-??\??") == 0) {
152 sprintf(format,
"%s%s-%s-%s", rootname,
"%d",
"%03d",
"%02d%02d%s");
154 sprintf(format,
"%s/%s%s-%s-%s", directory, rootname,
"%d",
"%03d",
"%02d%02d%s");
156 SDDS_Bomb(
"invalid filter given, should be -???? or -??\?-????");
166 tmpList = (
char **)malloc(
sizeof(tmpList) * extensions);
167 for (i = 0; i < extensions; i++) {
169 sprintf(tmpstr,
"%s%s", suffix, extensionList[i]);
171 sprintf(tmpstr,
"%s", extensionList[i]);
174 tmpLists = extensions;
177 tmpList = (
char **)malloc(
sizeof(tmpList));
185 for (iyear = startYear; iyear <= endYear; iyear++) {
186 if (iyear != endYear) {
188 if (is_leap_year(iyear))
196 if (startJDay == 1 && (toYearEnd == 1 || istoday == 1))
201 for (i = 0; i < tmpLists; i++) {
202 sprintf(tmpstr,
"%s%d%s%s", rootname, iyear, filter, tmpList[i]);
203 yearList = ls_dir(directory, tmpstr, tailsOnly, &yearLists);
206 fileList =
SDDS_Realloc(fileList,
sizeof(*fileList) * (fileLists + yearLists));
207 for (j = 0; j < yearLists; j++)
209 fileLists += yearLists;
211 for (iday = startJDay; iday <= jDayLimit; iday++) {
214 if (year0 != iyear || iday0 != iday || hour0 != 1) {
215 fprintf(stderr,
"Error in getting the julian date!\n");
218 if (strcmp(filter,
"-??\??") == 0)
219 sprintf(buffer, format, iyear, month0, day0, tmpList[i]);
221 sprintf(buffer, format, iyear, iday0, month0, day0, tmpList[i]);
223 for (j = 0; j < yearLists; j++) {
225 newList =
SDDS_Realloc(newList,
sizeof(*newList) * (newLists + 1));
231 index =
match_string(buffer, yearList, yearLists, EXACT_MATCH);
233 newList =
SDDS_Realloc(newList,
sizeof(*newList) * (newLists + 1));
240 fileList =
SDDS_Realloc(fileList,
sizeof(*fileList) * (fileLists + newLists));
241 for (j = 0; j < newLists; j++) {
246 fileLists += newLists;
263 for (i = 0; i < tmpLists; i++)
char ** find_files_between_dates(char *directory, char *rootname, char *suffix, short startYear, short startMonth, short startDay, short startJDay, short endYear, short endMonth, short endDay, short endJDay, char *filter, char **extensionList, long extensions, long tailsOnly, long *files, long increaseOrder)
Finds files in a directory that match specified criteria within a date range.