/* File w2see_db.c Author: J.Brewer, June 1998 email: jbrewer@eso.org The see_db C-shell scripts will read data from the TCS, the telescope focus unit, and the meteomonitor. The data read from these sources are stored in separate files. This program will read in these data files and write the data out along with the program arguments to a database file. */ #include #include #include #include #include #define NARGS 8 /* Number of program arguments */ main(int argc, char *argv[]) { /* Function Prototypes */ double jdate(); /* Files */ FILE *fopen(), *ipfile, *opfile; /* Data read from files */ char buff[200]; float dome,zd; float en1,en2,en3,en4,en5,en6,en7,en8,en9,en10,en11, \ en12,en13,en14,en15,en16; float foc; float t1,t2,t3,rh,td,pr,qnh,ws1,ws2,ws3,wd1,wd2,wd3; float see; /* Check command line arguments, and process */ if (argc != NARGS) { char usage[]="DFfilt FAfiltA FAfiltB vents fans fwhm_x fwhm_y"; fprintf(stderr, "Usage: %s %s\n", argv[0], usage); exit(1); } /* Read the TCS and focus data... */ if ((ipfile = fopen("/home/meteolog/public/see_tmp.dat1","r"))==NULL) { printf("%s: Could not open `see_tmp.dat1'\n", argv[0]); exit(1); } fgets(buff, 150, ipfile); sscanf(buff, "%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f", &dome,&zd,&en1,&en2,&en3,&en4,&en5,&en6,&en7,&en8,&en9,\ &en10,&en11,&en12,&en13,&en14,&en15,&en16,&foc); fclose(ipfile); /* Read the meteomonitor and DIMM data... */ if ((ipfile = fopen("/home/meteolog/public/see_tmp.dat2","r"))==NULL) { printf("%s: Could not open `see_tmp.dat2'\n", argv[0]); exit(1); } fgets(buff, 150, ipfile); sscanf(buff, "%f%f%f%f%f%f%f%f%f%f%f%f%f%f", \ &t1,&t2,&t3,&rh,&td,&pr,&qnh,&ws1,&ws2,&ws3,&wd1,&wd2,&wd3,&see); fclose(ipfile); /* Create see_db.dat file if it doesn't exist */ if ((opfile = fopen("/home/meteolog/public/see_db.dat","r"))==NULL) { if ((opfile = fopen("/home/meteolog/public/see_db.dat","w"))==NULL) { printf("%s: Could not create `see_db.dat'\n", argv[0]); exit(1); } fprintf(opfile, "#date---- fi1 fi2 fi3 f p fwx- fwy- "); fprintf(opfile, "dome--- zd---- "); fprintf(opfile, "focus "); fprintf(opfile, "t1-- rh-- ws1- wd1-- dimm "); fprintf(opfile, "en1- en2- en3- en4- en5- en6- en7- en8- "); fprintf(opfile, "en9- en10 en11 en12 en13 en14 en15 en16\n"); } fclose(opfile); /* Append the data to the see_db.dat file... */ if ((opfile = fopen("/home/meteolog/public/see_db.dat","a"))==NULL) { printf("%s: Could not append to `see_db.dat'\n", argv[0]); exit(1); } /* Write JulianDate + program arguments to database */ fprintf(opfile, "%9.4f %3s %3s %3s %1s %1s %4s %4s", \ jdate(),argv[1],argv[2],argv[3],argv[4],argv[5],argv[6],argv[7]); /* Write TCS information to database */ fprintf(opfile, " %7.0f %6.0f", dome, zd); /* Write Telescope Focus value to database */ fprintf(opfile, " %5.0f", foc); /* Write Meteo values to database */ fprintf(opfile, " %4.1f %4.1f %4.1f %5.1f", t1,rh,ws1,wd1); /* Write DIMM value to database */ fprintf(opfile, " %4.2f", see); /* Write enviro data to database */ fprintf(opfile, " %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f", \ en1,en2,en3,en4,en5,en6,en7,en8); fprintf(opfile, " %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f\n", \ en9,en10,en11,en12,en13,en14,en15,en16); fclose(opfile); } double jdate() { double secs,date; struct timeval tp; struct timezone tzp; gettimeofday(&tp, &tzp); secs = ((double) tp.tv_sec + (double) tp.tv_usec / 1000000.0); date = 1970. + secs/31557600.; return(date); }