#include "stdio.h" #include "string.h" #include "astring.h" #include "flatfile.h" #include "misc.h" void main() { FILE *fpout, *fpin; char *list, *result; char sdate[80],edate[80],nave[80], infile[100], date[10]; char command[200], *uname, ufile[100], line[100]; double stime, etime, mtime; int itime[6], year, i, ndays, uc, que; uname = spawn("/usr/bin/whoami"); strcpy(uname,strmid(uname,0,strlen(uname)-1)); strcpy(ufile,"/galileo/d/ganglu/mags/tempfiles/user."); strcat(ufile,uname); uc = 0; fpin = fopen(ufile,"r"); i = 1; if (fpin == NULL) { uc = 1; printf("(no old dates found)\n"); } else { while (!feof(fpin)) { fgets(line, 100, fpin); if (!feof(fpin)) { printf("%2d. Process start date : %s\n",i,strmid(line,0,10)); i++; } } fclose(fpin); } printf("%2d. Start new processing\n",i); printf("\n"); printf("Enter Number : "); gets(line); que = atoi(line); if (que == i) { printf("\n"); printf("New date selected\n"); printf("\n"); printf("Enter start day of study (ex : 22-mar-95) : "); gets(sdate); printf("Enter end day of study (ex : 25-mar-95) : "); gets(edate); printf("Enter number of minutes to average data over : "); gets(nave); que = 1; } else { fpin = fopen(ufile,"r"); i = 1; while (!feof(fpin) && i <= que) { fgets(line, 100, fpin); if (!feof(fpin)) { i++; } } fclose(fpin); strcpy(sdate,strmid(line,0,9)); strcpy(edate,strmid(line,20,9)); strcpy(nave,strmid(line,40,strpos(line,"\n")-40)); printf("\n"); printf("Start date : %s\n",sdate); printf("End date : %s\n",edate); printf("Number of minutes to average over : %s\n",nave); que = 0; } stime = c_s_to_r(sdate); etime = c_s_to_r(edate) + 24.0*3600.0 - 1.0; ndays = (etime+1 - stime)/(24.0*3600.0); mtime = (stime+etime)/2.0; c_r_to_i(itime, mtime); year = itime[0] + 1900; if (itime[0] < 65) year = itime[0] + 2000; printf("process_mags: YY MON DD : %5li%3li%3li%3li \n",year,itime[0],itime[1],itime[2]); if (year < 1965) year = year + 100; strcpy(date, c_int_str(year,4)); strcat(date, "."); itime[0] = 1965; mtime = 100.0*c_i_to_r(itime)/(365.0*24.0*3600.0); strcat(date, c_int_str((int) mtime,2)); if (que) { if (uc) { printf("Creating storage file\n"); fpout = fopen(ufile,"w"); } else { printf("Adding new date to storage file\n"); fpout = fopen(ufile,"a"); } fprintf(fpout,"%s %s %s\n", sdate,edate,nave); fclose(fpout); strcpy(infile,"/galileo/d/ganglu/mags/tempfiles/master_dec."); strcat(infile,uname); strcat(infile,"."); strcat(infile,date); fpout = fopen( "/galileo/d/ganglu/mags/tempfiles/mkdecfile.temp.input","w"); fprintf(fpout,"/galileo/d/ganglu/mags/pfiles/master.stalist\n"); fprintf(fpout,"%s\n",infile); fprintf(fpout,"%s\n",date); fclose(fpout); strcpy(command,"/bin/rm "); strcat(command,infile); system(command); fpout = fopen( "/galileo/d/ganglu/mags/tempfiles/mkpsifile.temp.input","w"); strcpy(infile,"/galileo/d/ganglu/mags/tempfiles/master_psi."); strcat(infile,uname); strcat(infile,"."); strcat(infile,date); fprintf(fpout,"%s\n",infile); fprintf(fpout,"%s\n",sdate); fprintf(fpout,"%d\n",ndays); fprintf(fpout,"%s\n",nave); fprintf(fpout,"%s\n",date); printf("writing fpout2 : %s\n",fpout); fclose(fpout); strcpy(command,"/bin/rm "); strcat(command,infile); system(command); strcpy(command,"/galileo/d/ganglu/mags/bin/mkdecfile < "); strcat(command, "/galileo/d/ganglu/mags/tempfiles/mkdecfile.temp.input"); system(command); strcpy(command,"/bin/rm "); strcat(command, "/galileo/d/ganglu/mags/tempfiles/mkdecfile.temp.input"); system(command); strcpy(command,"/galileo/d/ganglu/mags/bin/mkpsifile < "); strcat(command, "/galileo/d/ganglu/mags/tempfiles/mkpsifile.temp.input"); system(command); strcpy(command,"/bin/rm "); strcat(command, "/galileo/d/ganglu/mags/tempfiles/mkpsifile.temp.input"); system(command); strcpy(infile,"/galileo/d/ganglu/mags/tempfiles/act.tim."); strcat(infile,uname); strcat(infile,"."); strcat(infile,sdate); fpout = fopen(infile,"w"); fprintf(fpout,"%s\n",sdate); fprintf(fpout,"%s\n",edate); fclose(fpout); strcpy(infile,"/galileo/d/ganglu/mags/tempfiles/nav."); strcat(infile,uname); strcat(infile,"."); strcat(infile,sdate); fpout = fopen(infile,"w"); fprintf(fpout,"%s\n",nave); fclose(fpout); strcpy(infile, "/galileo/d/ganglu/mags/tempfiles/mas.loc."); strcat(infile,uname); strcat(infile,"."); strcat(infile,sdate); fpout = fopen(infile,"w"); fprintf(fpout, "/galileo/d/ganglu/mags/tempfiles/master_dec.%s.%s\n", uname,date); fprintf(fpout, "/galileo/d/ganglu/mags/tempfiles/master_psi.%s.%s\n", uname,date); fclose(fpout); } printf("\n"); printf("At this point, data processing can begin.\n"); printf("You can either do all of the steps one at a time,\n"); printf("or all of them at once.\n"); que = 0; while (que != 10) { printf("\n"); printf(" 1. Convert files listed in 'file.list' to flatfiles\n"); printf(" 2. Create one flatfile for each magnetometer\n"); printf(" 3. Trim ALL flatfiles down to only specified dates (+3 days)\n"); printf(" 4. Despike ALL flatfiles\n"); printf(" 5. Average ALL flatfiles to specified resolution\n"); printf(" 6. Convert ALL flatfiles to AMIE format\n"); printf(" 7. Do all of the above in 1 step\n"); printf(" 8. Convert ALL flatfiles to WDC format\n"); printf(" 9. Remove curve from ALL flatfiles\n"); printf("10. Quit\n"); printf("\n"); printf("Enter choice : "); scanf("%d",&que); if ((que == 1) || (que == 7)) { strcpy(command,"process_all -d"); strcat(command,sdate); system(command); } if ((que == 2) || (que == 7)) { strcpy(command,"merge_all"); system(command); } if ((que == 3) || (que == 7)) { strcpy(command,"trim_all -d"); strcat(command,sdate); system(command); } if ((que == 4) || (que == 7)) { strcpy(command,"despike_all -d"); strcat(command,sdate); system(command); } if ((que == 5) || (que == 7)) { strcpy(command,"average_all -a -d"); strcat(command,sdate); system(command); } if ((que == 6) || (que == 7)) { strcpy(command,"mkamie_all"); system(command); } if (que == 8) { strcpy(command,"mkwdc_all"); system(command); } if (que == 9) { strcpy(command,"mkremca_all "); strcat(command,sdate); strcpy(command," "); strcat(command,edate); system(command); } } }