43 new_files = (
char **)realloc(list->
files,
44 new_nalloced *
sizeof(
char *));
48 "Could not allocate memory for file list.\n");
53 list->
files = new_files;
59 "Could not allocate memory for file name.\n");
79 for (fi = 0; fi < list->
nfiles; ++fi) {
80 free(list->
files[fi]);
81 list->
files[fi] = (
char *)NULL;
102 "Failed to allocate memory for SasFileList structure.\n");
103 return ((
void *)NULL);
124 chrp = strchr(file_name,
'.');
125 if (!chrp)
return(0);
129 sscanf(++chrp,
"%4d%2d%2d", &YYYY, &MM, &DD);
146 const char *s1 = *(
const char **)str1;
147 const char *s2 = *(
const char **)str2;
151 if (t1 < t2) {
return(-1); }
152 if (t1 > t2) {
return(1); }
175 if (n < 2)
return(0);
181 if (v <= x[0])
return(0);
182 if (v >= x[n-1])
return(n-1);
184 while (ei > bi + 1) {
186 if (v < x[mi]) ei = mi;
190 return(((v - x[bi]) < (x[bi+1] - v)) ? bi : bi + 1);
196 if (v >= x[0])
return(0);
197 if (v <= x[n-1])
return(n-1);
199 while (ei > bi + 1) {
201 if (v > x[mi]) ei = mi;
205 return(((x[bi] - v) < (v - x[bi+1])) ? bi : bi + 1);
227 if (n < 2)
return(0);
233 if (v <= x[0])
return(0);
234 if (v >= x[n-1])
return(n-1);
236 while (ei > bi + 1) {
238 if (v < x[mi]) ei = mi;
242 return(((v - x[bi]) < (x[bi+1] - v)) ? bi : bi + 1);
248 if (v >= x[0])
return(0);
249 if (v <= x[n-1])
return(n-1);
251 while (ei > bi + 1) {
253 if (v > x[mi]) ei = mi;
257 return(((x[bi] - v) < (v - x[bi+1])) ? bi : bi + 1);
273 if (table->
cols[col]) free(table->
cols[col]);
309 for (i = 0; i < raw->
nrecs; ++i) {
352 const char *conf_dir,
361 "Loading config file list:\n"
373 "Could Not Create Configuration Files List For: %s\n",
385 "Could Not Get Configuration Files List For: %s\n",
391 else if (nfiles == 0) {
394 "Could Not Find Required Configuration Files:\n"
395 " -> search path: %s\n"
396 " -> search pattern: %s\n",
405 for (fi = 0; fi < dirlist->
nfiles; ++fi) {
407 " -> found: %s\n", dirlist->
file_list[fi]);
432 double *xcol = table->
cols[x_col];
433 double *ycol = table->
cols[y_col];
439 for (vi = 0; vi < x_nvals; vi++) {
446 else if (x >= xcol[table->
nrows-1]) {
449 else if (x > xcol[ri]) {
450 for (ri++; x >= xcol[ri]; ri++);
453 ri = ((x - x0) < (x1 - x)) ? ri - 1 : ri;
455 else if (x < xcol[ri]) {
456 for (ri--; x <= xcol[ri]; ri--);
459 ri = ((x - x0) < (x1 - x)) ? ri : ri + 1;
462 if (finite(ycol[ri])) {
463 y_vals[vi] = ycol[ri];
466 y_vals[vi] = -9999.0;
489 double *xcol = table->
cols[x_col];
490 double *ycol = table->
cols[y_col];
496 for (vi = 0; vi < x_nvals; vi++) {
498 x = (double)x_vals[vi];
503 else if (x >= xcol[table->
nrows-1]) {
506 else if (x > xcol[ri]) {
507 for (ri++; x >= xcol[ri]; ri++);
510 ri = ((x - x0) < (x1 - x)) ? ri - 1 : ri;
512 else if (x < xcol[ri]) {
513 for (ri--; x <= xcol[ri]; ri--);
516 ri = ((x - x0) < (x1 - x)) ? ri : ri + 1;
519 if (finite(ycol[ri])) {
520 y_vals[vi] = (float)ycol[ri];
523 y_vals[vi] = -9999.0;
546 double *xcol = table->
cols[x_col];
547 double *ycol = table->
cols[y_col];
548 double x, x0, x1, y0, y1;
551 x0 = x1 = y0 = y1 = 0;
554 for (vi = 0; vi < x_nvals; vi++) {
560 if (finite(ycol[ri])) {
561 y_vals[vi] = ycol[ri];
564 y_vals[vi] = -9999.0;
577 else if (x >= xcol[table->
nrows-1]) {
579 x0 = xcol[table->
nrows-2];
580 x1 = xcol[table->
nrows-1];
581 y0 = ycol[table->
nrows-2];
582 y1 = ycol[table->
nrows-1];
584 else if (x > xcol[ri]) {
585 for (ri++; x >= xcol[ri]; ri++);
591 else if (x < xcol[ri]) {
592 for (ri--; x <= xcol[ri]; ri--);
599 if (finite(y0) && finite(y1)) {
603 y_vals[vi] = -9999.0;
626 double *xcol = table->
cols[x_col];
627 double *ycol = table->
cols[y_col];
628 double x, x0, x1, y0, y1;
631 x0 = x1 = y0 = y1 = 0;
634 for (vi = 0; vi < x_nvals; vi++) {
636 x = (double)x_vals[vi];
640 if (finite(ycol[ri])) {
641 y_vals[vi] = (float)ycol[ri];
644 y_vals[vi] = -9999.0;
657 else if (x >= xcol[table->
nrows-1]) {
659 x0 = xcol[table->
nrows-2];
660 x1 = xcol[table->
nrows-1];
661 y0 = ycol[table->
nrows-2];
662 y1 = ycol[table->
nrows-1];
664 else if (x > xcol[ri]) {
665 for (ri++; x >= xcol[ri]; ri++);
671 else if (x < xcol[ri]) {
672 for (ri--; x <= xcol[ri]; ri--);
679 if (finite(y0) && finite(y1)) {
683 y_vals[vi] = -9999.0;
726 const char *conf_dir,
727 const char *conf_file,
731 int alloced_table = 0;
732 FILE *fp = (FILE *)NULL;
733 char full_path[PATH_MAX];
741 "Loading config file:\n"
744 conf_dir, conf_file);
750 if ((strcmp(table->
conf_dir, conf_dir) == 0) &&
751 (strcmp(table->
conf_file, conf_file) == 0)) {
761 if (!table)
goto MEMORY_ERROR;
770 table->
buffer = (
double *)realloc(table->
buffer, ncols *
sizeof(
double));
771 if (!table->
buffer)
goto MEMORY_ERROR;
773 table->
cols = (
double **)realloc(table->
cols, ncols *
sizeof(
double *));
774 if (!table->
cols)
goto MEMORY_ERROR;
777 table->
cols[col] = (
double *)NULL;
782 table->
cols[col] = (
double *)malloc(
785 if (!table->
cols[col]) {
794 table->
ncols = ncols;
799 snprintf(full_path, PATH_MAX,
"%s/%s", conf_dir, conf_file);
801 fp = fopen(full_path,
"r");
804 "Could Not Open Configuration File: %s\n"
805 " -> %s\n", full_path, strerror(errno));
813 while(fgets(line, 1024, fp)) {
819 if (line[0] ==
'!' ||
824 strcat(table->
header, line);
830 for (strp = line; *strp ==
' ' || *strp ==
'\t'; ++strp);
831 if (isspace(*strp) || *strp ==
'\0') {
841 "Bad Line Found In Configuration File",
842 "Bad line found on line %d in config file: %s\n"
843 " -> expected %d values but found: %d\n",
844 linenum, full_path, ncols, nvals);
861 table->
cols[col] = (
double *)realloc(table->
cols[col],
864 if (!table->
cols[col]) {
872 for (col = 0; col < ncols; ++col) {
882 "Could Not Read Configuration File: %s\n"
884 full_path, strerror(errno));
903 "Could not allocate memory for config table: %s\n", full_path);
927 fp = fopen(file,
"w");
930 "Could not open file: %s\n"
931 " -> %s\n", file, strerror(errno));
935 for (row = 0; row < table->
nrows; ++row) {
937 fprintf(fp,
"%g", table->
cols[0][row]);
939 for (col = 1; col < table->
ncols; ++col) {
940 fprintf(fp,
"\t%g", table->
cols[col][row]);
960 int YYYY, MM, DD, hh, mm, ss;
965 chrp = strrchr(file_name,
'.');
966 if (!chrp)
return(0);
968 if (chrp != file_name) {
969 for (--chrp; *chrp !=
'.' && chrp != file_name; --chrp);
972 YYYY = MM = DD = hh = mm = ss = 0;
974 sscanf(++chrp,
"%4d%2d%2d_%2d%2d%2d",
975 &YYYY, &MM, &DD, &hh, &mm, &ss);
992 const char *s1 = *(
const char **)str1;
993 const char *s2 = *(
const char **)str2;
997 if (t1 < t2) {
return(-1); }
998 if (t1 > t2) {
return(1); }
1000 if (strstr(s1,
"nir")) {
return(-1); }
1001 if (strstr(s2,
"nir")) {
return(1); }
1017 const char *var_name;
1022 const char *var_name;
1025 } default_limits[] = {
1027 {
"ad_temperature", 10.0, 20.0},
1028 {
"ad_temperature_nir", 10.0, 20.0},
1029 {
"ad_temperature_vis", 10.0, 20.0},
1030 {
"bench_temperature", 5.0, 15.0},
1031 {
"bench_temperature_nir", 5.0, 15.0},
1032 {
"bench_temperature_vis", 5.0, 15.0},
1033 {
"chiller_temperature", -10.0, 35.0},
1034 {
"collector_x_tilt", -2.0, 2.0},
1035 {
"collector_y_tilt", -2.0, 2.0},
1039 for (di = 0; (var_name = default_limits[di].var_name); ++di) {
1043 value = default_limits[di].min;
1051 value = default_limits[di].max;
1081 char *endp = (
char *)NULL;
1085 for (strp =
string; *strp !=
'\0'; ++strp) {
1087 value = strtod(strp, &endp);
1092 buffer[nvals] = value;
1096 if (*strp ==
'\0')
break;