#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 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)); char st1[50]; char strr1[50]; // checking for invalid inputs. if ((strcmp(station, "LYR") == 0) || (strcmp(station, "NAL") == 0) || (strcmp(station, "UNH") == 0) || (strcmp(station, "IQA") == 0)) { strcpy(st1, "bash Process_Old_DAQ.sh "); } else if (strcmp(station, "SPA") == 0) { strcpy(st1, "bash snag_dat_spa.sh "); strcpy(strr1, "bash spaconverttest.sh "); } else if (strcmp(station, "MCM") == 0) { strcpy(st1, "bash snag_dat_mcm.sh "); strcpy(strr1, "bash mcmconverttest.sh "); } else if (strcmp(station, "VNA") == 0) { strcpy(st1, "bash snag_dat_vna.sh "); } else if (strcmp(station, "JBS") == 0) //write "elligeble" script for terminal command formatting { // do something else } else if (strcmp(station, "KSS") == 0) { // do something else } else if (strcmp(station, "AAL") == 0) { // do something else } else /* default: */ { printf("Invalid station "); exit(0); } if (startmonth > 12) { printf("Invalid date\n"); exit(0); } if (endmonth > 12) { printf("Invalid date\n"); exit(0); } // this was made with StringBuilder in mind. too bad this is C! // sorry for whoever needs to clean this up in the future. It just works! //todo: optimize bit allocation for the "stringbuilder" so it doesnt cause a memory leak. char st2[10]; //nth day of year //printf(station[2]); char* prestat; prestat = copyString(station); //printf("%s", prestat); sprintf(st2, "%d", daynum(startmonth, startday, startyear)); //replaces element station[2] with "1", SOMEHOW. char st3[10] = " "; char st4[10]; //start month sprintf(st4, "%d", startmonth); char st5[10] = " "; char st6[10]; //end month sprintf(st6, "%d", endmonth); char st7[10] = " "; char st8[10]; // year char st9[10] = " "; sprintf(st8, "%d", endyear); // "SCRIPT NAME" $1 $2 $3 $4 $5 // st1 daynum startmonth endmonth endyear station strcat(st1, st2); strcat(st1, st3); strcat(st1, st4); strcat(st1, st5); strcat(st1, st6); strcat(st1, st7); strcat(st1, st8); strcat(st1, st9); strcat(st1, prestat); //debug. st1 is what goes straight to the terminal //printf(st1); //printf("%s", prestat); system(st1); if ~((strcmp(station, "LYR") == 0) || (strcmp(station, "NAL") == 0) || (strcmp(station, "UNH") == 0) || (strcmp(station, "IQA") == 0)) { //1ST convert //i just copied the same code because it works fine //char strr1[40] = "bash spaconverttest.sh "; //CONVERSION SCRIPT NAME. MAKE SURE THIS IS CORRECT! char strr2[10]; //nth day of year sprintf(strr2, "%d", daynum(startmonth, startday, startyear)); char strr3[10] = " "; char strr4[10]; //start month sprintf(strr4, "%d", startmonth); char strr5[10] = " "; char strr6[10]; //end month sprintf(strr6, "%d", endmonth); char strr7[10] = " "; char strr8[10]; // year sprintf(strr8, "%d", endyear); strcat(strr1, strr2); strcat(strr1, strr3); strcat(strr1, strr4); strcat(strr1, strr5); strcat(strr1, strr6); strcat(strr1, strr7); strcat(strr1, strr8); //debug. str1 is what goes straight to the terminal //printf(strr1); system(strr1); } return 1; } /*make cdfs char str1[40] = "bash make_cdfstest.sh "; //CONVERSION SCRIPT NAME. MAKE SURE THIS IS CORRECT! char str2[10]; //nth day of year sprintf(str2, "%d", daynum(startmonth, startday, startyear)); char str3[10] = " "; char str4[10]; //start month sprintf(str4, "%d", startmonth); char str5[10] = " "; char str6[10]; //end month sprintf(str6, "%d", endmonth); char str7[10] = " "; char str8[10]; // year sprintf(str8, "%d", endyear); strcat(str1, str2); strcat(str1, str3); strcat(str1, str4); strcat(str1, str5); strcat(str1, str6); strcat(str1, str7); strcat(str1, str8); //debug. str1 is what goes straight to the terminal //printf(str1); system(str1); //make plots char s1[40] = "bash make_batchtest.sh "; //CONVERSION SCRIPT NAME. MAKE SURE THIS IS CORRECT! char s2[10]; //nth day of year sprintf(s2, "%d", daynum(startmonth, startday, startyear)); char s3[10] = " "; char s4[10]; //start month sprintf(s4, "%d", startmonth); char s5[10] = " "; char s6[10]; //end month sprintf(s6, "%d", endmonth); char s7[10] = " "; char s8[10]; // year sprintf(s8, "%d", endyear); strcat(s1, s2); strcat(s1, s3); strcat(s1, s4); strcat(s1, s5); strcat(s1, s6); strcat(s1, s7); strcat(s1, s8); //debug. s1 is what goes straight to the terminal //printf(s1); system(s1); return 0; } */