#include #include #include char* copyString(char s[]) { char* s2; s2 = (char*)malloc(20); strcpy(s2, s); return (char*)s2; } int daynum (int m, int d, int y) { // some files include the day # in the file name so we need to calculate it here int num = 0; int IsLeapYear = 0; if ((y % 4 == 0 && y % 100 !=0) || (y % 400 == 0)) { IsLeapYear = 1; } //takes month int and uses it to calculate how many days have passed prior to current months start //now calculates leap year! switch(m) { case 1 : break; case 2 : num = num + 31; break; case 3 : num = num + IsLeapYear + 59; break; case 4 : num = num + IsLeapYear + 90; break; case 5 : num = num + IsLeapYear + 120; break; case 6 : num = num + IsLeapYear + 151; break; case 7 : num = num + IsLeapYear + 181; break; case 8 : num = num + IsLeapYear + 212; break; case 9 : num = num + IsLeapYear + 243; break; case 10 : num = num + IsLeapYear + 273; break; case 11 : num = num + IsLeapYear + 304; break; case 12 : num = num + IsLeapYear + 334; break; default : printf("Invalid date\n"); //printf(m, d, y, IsLeapYear); exit(0); } //adds the amount of days in each previous month and the day selected. num = num + d; return num; } int main() { int mud = 0; int startdate; int enddate; char station[2]; //thought it would look cool, got bored printf("+========================================+\n"); printf("|| ||\n"); printf("|| __ __ _____ _____ ||\n"); printf("|| | \\/ | /\\ / ____|_ _| ||\n"); printf("|| | \\ / | / \\ | | __ | | ||\n"); printf("|| | |\\/| | / /\\ \\| | |_ | | | ||\n"); printf("|| | | | |/ ____ \\ |__| |_| |_ ||\n"); printf("|| |_| |_/_/ \\_\\_____|_____| ||\n"); printf("|| ||\n"); printf("|| Refer to xxxxxxxxx for documentation ||\n"); printf("||______________________________________||\n"); printf("|| ||\n"); printf("|| ---------------------------------- ||\n"); printf("|| All dates MUST be in MMDDYYYY format ||\n"); printf("|| ---------------------------------- ||\n"); printf("|| ||\n"); printf("+========================================+\n"); printf("\n Please enter desired station\n"); printf("\n > "); scanf("%s", station); printf("\n Please enter the start date\n"); printf("\n > "); scanf("%d", &startdate); printf("\n \n Please enter the end date \n"); printf("\n > "); scanf("%d", &enddate); printf("\n"); //split up the dates into individiual ints int startmonth = startdate / 1000000; int startday = (startdate / 10000) % 100; int startyear = startdate % 10000; int endmonth = enddate / 1000000; int endday = (enddate / 10000) % 100; int endyear = enddate % 10000; //debug //printf("%02d\n", startmonth); //printf("%02d\n", startday); //printf("%02d\n", startyear); //printf("%02d\n", daynum(startmonth, startday, startyear)); //exit(0); char st1[90]; // checking for invalid inputs. if (strcmp(station, "UNH") == 0) { strcpy(st1, "bash Process_Old_DAQ.sh "); mud = 1; } else if (strcmp(station, "IQA") == 0) { strcpy(st1, "bash Process_Old_DAQ.sh "); mud = 1; } else if (strcmp(station, "LYR") == 0) { strcpy(st1, "bash Process_Old_DAQ.sh "); mud = 1; } else if (strcmp(station, "NAL") == 0) { strcpy(st1, "bash Process_Old_DAQ.sh "); mud = 1; } /////////////////////////////////////////////// else if (strcmp(station, "MCM") == 0) { strcpy(st1, "bash /media/mirl-ulf/4TB_HDD2/mirl/ULF/incoming/database/MCM/snag_mcm_dat.sh "); //year-month-day-daynum //xxxx-xx-xx-x //the mcmconvert_mwc.pro file must remain in the same directory as this program because //it is executing idl -e "mcmconvert_mwc, '${year}${month}${day}'" from THIS directory } else if (strcmp(station, "SPA") == 0) { strcpy(st1, "bash /media/mirl-ulf/4TB_HDD2/mirl/ULF/incoming/database/SPA/snag_spa_dat.sh "); //same formatting as MCM //the spaconvert_mwc.pro file must remain in the same directory as this program because //it is executing idl -e "spaconvert_mwc, '${year}${month}${day}'" from THIS directory } else if (strcmp(station, "JBS") == 0) { } else if (strcmp(station, "KSS") == 0) { } else if (strcmp(station, "VNA") == 0) { } else /* default: */ { printf("Invalid station "); exit(0); } if (startmonth > 12 || endmonth > 12) { printf("Invalid date\n"); exit(0); } //used for the UNH sites to make .MUD files if (mud == 1) { startyear = startyear % 100; char st2[10] = " "; char st3[10]; sprintf(st3, "%d", startyear); char st4[10]; sprintf(st4, "%02d", startmonth); char st5[10]; sprintf(st5, "%02d", endmonth); strcat(st1, station); strcat(st1, st2); strcat(st1, st3); strcat(st1, st2); strcat(st1, st4); strcat(st1, st2); strcat(st1, st5); system(st1); system("bash /home/mirl-ulf/ULF/Data_Files/MUD/sync_to_server.sh"); exit(0); } char st2[10] = " "; char st3[10]; sprintf(st3, "%d", startyear); char st4[10]; sprintf(st4, "%02d", startmonth); char st5[10]; sprintf(st5, "%02d", startday); char st6[10]; sprintf(st6, "%d", daynum(startmonth, startday, startyear)); strcat(st1, st3); strcat(st1, st2); strcat(st1, st4); strcat(st1, st2); strcat(st1, st5); strcat(st1, st2); strcat(st1, st6); //printf(st1); system(st1); exit(0); }