#include #include #include #include #include #include #include "nrutil.c" #include "UVStruct.c" #include "UVFile.c" #include "UVCommon.c" void main(void) { int i, j; int n_col, n_file, n_row, ok; int hh, mm, ss, dd, yy; int day, year; float *wl, time, prev_time, x_in; char st[128], c, inst[8], hd_file[16]; char sch_file[20], in_file[20], out_file[20], wl_file[20]; struct tm date; struct scan_header USDA; FILE *fp_sch, *fp_in, *fp_out, *fp_data; wl = vector(1, 8); printf("Scan Schedule File: "); // schedule of scans scanf("%s", &sch_file); printf("Wavelength File: "); //wavelength file scanf("%s", &wl_file); sscanf(sch_file, "96S_Sch.%s", &inst); printf("%s\n", inst); fp_in = fopen(wl_file, "r"); do{ fscanf(fp_in, "%s", &st); } while(strcmp(st, "Number_of_rows") != 0); fscanf(fp_in, "%d", &n_row); do{ fscanf(fp_in, "%s", &st); } while(strcmp(st, "Data:") != 0); for(i = 1; i <= n_row; i++){ fscanf(fp_in, "%s%f", &st, wl + i); printf("%d\t%f\n", i, wl[i]); } fclose(fp_in); fp_sch = fopen(sch_file, "r"); sprintf(hd_file, "96FE.%s", inst); fp_data = fopen(hd_file, "w"); // compilation of header data fprintf(fp_data, "Header:\n"); fprintf(fp_data, "Number_of_columns\t21\n"); fprintf(fp_data, "Labels:\n"); fprintf(fp_data, "File\tInstrument\tSource\tLocation\tEnvironment\t"); fprintf(fp_data, "Year\tDay\tDate\tOperation\tMeasurement_type\t"); fprintf(fp_data, "Measurement_purpose\tNumber_of_scans\tNumber_of_columns\t"); fprintf(fp_data, "Number_of_rows\tStart_time\tStop_time\tNumber_of_channels\t"); fprintf(fp_data, "Comments\tData_file\tWavelength_file\tAnalysis_file\n"); fprintf(fp_data, "\t\t\t\t\t\t\t\t\t\t\t\t\t\t"); fprintf(fp_data, "[UTC]\t[UTC]\n"); fprintf(fp_data, "Data:\n"); fscanf(fp_sch, "%s %s %d", &st, &st, &n_col); // read schedule file header do{ fscanf(fp_sch, "%s", &st); } while(strcmp(st, "Data:") != 0); while(fscanf(fp_sch, "%s", &in_file) != EOF){ // read schedule file info. strcpy(USDA.data_file, in_file); fscanf(fp_sch, "%s", USDA.inst); fscanf(fp_sch, "%s", USDA.source); fscanf(fp_sch, "%s", USDA.locat); fscanf(fp_sch, "%s", USDA.envir); fscanf(fp_sch, "%s", USDA.operat); fscanf(fp_sch, "%s", USDA.meas_type); fscanf(fp_sch, "%s", USDA.meas_purp); fscanf(fp_sch, "%s", USDA.comments); fp_in = fopen(in_file, "r"); printf("%s\t", in_file); fp_out = fopen("temp.dat", "w"); n_row = 1; prev_time = 0; while(fscanf(fp_in, "%d", &mm) != EOF){ // read USDA month fscanf(fp_in, "%d %d", &dd, &yy); // read day and year if(n_row != 1) prev_time = time; fscanf(fp_in, "%f", &time); // read time fprintf(fp_out, "%.5f\t", time); // store time for(i = 1; i <= 7; i++){ fscanf(fp_in, "%f", &x_in); // read signal fprintf(fp_out, "%.0f\t", x_in); // store signal } for(i = 1; i <= 14; i++){ fscanf(fp_in, "%f", &x_in); // read other signal } fprintf(fp_out, "%.0f\n", (time - prev_time)*3600.0); // integration time if(n_row == 1) USDA.start_time = time; USDA.stop_time = time; n_row++; } n_row--; fclose(fp_in); fclose(fp_out); USDA.year = 1900 + yy; date.tm_sec = 0; date.tm_min = 0; date.tm_hour = 0; date.tm_mday = dd; date.tm_mon = mm - 1; date.tm_year = yy; mktime(&date); USDA.day = date.tm_yday + 1; day_to_date(USDA.year, USDA.day, USDA.date); n_file = 1; do{ // check if file exists sprintf(out_file, "96%03dF%02d.%s", USDA.day, n_file, inst); ok = file_exist(out_file); n_file++; } while(ok == 1); fp_in = fopen("temp.dat", "r"); fp_out = fopen(out_file, "w"); // store header info. printf("%s\n", out_file); fprintf(fp_data, "%s\t", out_file); fprintf(fp_out, "Header:\n"); fprintf(fp_out, "Instrument\t%s\n", USDA.inst); fprintf(fp_data, "%s\t", USDA.inst); fprintf(fp_out, "Source\t%s\n", USDA.source); fprintf(fp_data, "%s\t", USDA.source); fprintf(fp_out, "Location\t%s\n", USDA.locat); fprintf(fp_data, "%s\t", USDA.locat); fprintf(fp_out, "Environment\t%s\n", USDA.envir); fprintf(fp_data, "%s\t", USDA.envir); fprintf(fp_out, "Year\t%d\n", USDA.year); fprintf(fp_data, "%d\t", USDA.year); fprintf(fp_out, "Day\t%d\n", USDA.day); fprintf(fp_data, "%d\t", USDA.day); fprintf(fp_out, "Date\t%s\n", USDA.date); fprintf(fp_data, "%s\t", USDA.date); fprintf(fp_out, "Operation\t%s\n", USDA.operat); fprintf(fp_data, "%s\t", USDA.operat); fprintf(fp_out, "Measurement_type\t%s\n", USDA.meas_type); fprintf(fp_data, "%s\t", USDA.meas_type); fprintf(fp_out, "Measurement_purpose\t%s\n", USDA.meas_purp); fprintf(fp_data, "%s\t", USDA.meas_purp); fprintf(fp_out, "Number_of_scans\t1\n"); fprintf(fp_data, "1\t"); fprintf(fp_out, "Number_of_columns\t9\n"); fprintf(fp_data, "9\t"); fprintf(fp_out, "Number_of_rows\t%d\n", n_row); fprintf(fp_data, "%d\t", n_row); fprintf(fp_out, "Start_time\t%.5f\t[UTC]\n", USDA.start_time); fprintf(fp_data, "%.5f\t", USDA.start_time); fprintf(fp_out, "Stop_time\t%.5f\t[UTC]\n", USDA.stop_time); fprintf(fp_data, "%.5f\t", USDA.stop_time); fprintf(fp_out, "Number_of_channels\t7\n"); fprintf(fp_data, "7\t"); fprintf(fp_out, "Comments\t%s\n", USDA.comments); fprintf(fp_data, "%s\t", USDA.comments); fprintf(fp_out, "Data_file\t%s\n", USDA.data_file); fprintf(fp_data, "%s\t", USDA.data_file); fprintf(fp_out, "Wavelength_file\t%s\n", wl_file); fprintf(fp_data, "%s\t", wl_file); fprintf(fp_out, "Analysis_program\tFmt_96USDA_S.c\n"); fprintf(fp_data, "Fmt_96USDA_S.c\n"); fprintf(fp_out, "Labels:\n"); fprintf(fp_out, "Time\t"); for(i = 1; i <= 7; i++){ fprintf(fp_out, "Signal_%3.2f[nm]\t", wl[i]); } fprintf(fp_out, "Integration_time\n"); fprintf(fp_out, "[UTC]\t"); for(i = 1; i <= 7; i++){ fprintf(fp_out, "[mV]\t"); } fprintf(fp_out, "[s]\n"); fprintf(fp_out, "Data:\n"); while((c = fgetc(fp_in)) != EOF){ fputc(c, fp_out); } fclose(fp_in); fclose(fp_out); } fclose(fp_sch); fclose(fp_data); }