/* Name: tempV2.ghcncgi.c Written by: Jeremy Gustrowsky, NCDC contract programmer Last revised: 9/14/98 */ #include "ua_climvis_cgi.h" /********* The only hardcoded path is here. ********/ void getPaths(char *temporary, char *cgi_root) { FILE *fpin; char pics[100],root[100]; if((fpin = fopen("/WWW/oracle-web/cgi-bin/climvis/cards/paths","r")) == NULL) CARDSFileFailure("/WWW/oracle-web/cgi-bin/climvis/cards/paths"); /* if((fpin = fopen("paths","r")) == NULL) CARDSFileFailure("paths"); */ /*showError("Couldn't find file containing paths.");*/ fscanf(fpin,"%s %s",pics,root); fclose(fpin); strcpy(temporary,pics); strcpy(cgi_root,root); } /* opens a file in the gateway root directory that contains the username and password information to connecting to the Oracle data base. */ void getOracleAccess(char *path, char *info) { FILE *fpin; char temp[100]; char user_info[35]; sprintf(temp,"%s/access",path); if((fpin = fopen(temp,"r")) == NULL) CARDSFileFailure(path); fscanf(fpin,"%s",user_info); fclose(fpin); strcpy(info,user_info); } void showError(char *message) { printf("ua_temp_cgi Error\n

"); printf("The program generated an error:

\n"); printf("%s\n

",message); printf("\n

\n"); printf(""); exit(1); } void writeTestInfo(char* path, char* filename, char *string, char mode) { FILE *fpout; char out_string[150]; sprintf(out_string,"%s/%s",path,filename); if(mode == 'a') { if((fpout = fopen(out_string,"a")) == NULL) CARDSFileFailure(out_string); } else if((fpout = fopen(out_string,"w")) == NULL) CARDSFileFailure(out_string); fprintf(fpout,"--%s--\n",string); fclose(fpout); } int GetData(int index, struct data_year *data) { switch(index) { case 0: { return data->jan; break; } case 1: { return data->feb; break; } case 2: { return data->mar; break; } case 3: { return data->apr; break; } case 4: { return data->may; break; } case 5: { return data->jun; break; } case 6: { return data->jul; break; } case 7: { return data->aug; break; } case 8: { return data->sep; break; } case 9: { return data->oct; break; } case 10: { return data->nov; break; } case 11: { return data->dec; break; } } } /*------------------------------- ParamName ------------------------------*/ char* ParamName(char *sname) { if(strcmp("max",sname) == 0) return "Maximum"; if(strcmp("min",sname) == 0) return "Minimum"; } /*--------------------------- CARDSFileFailure ----------------------------*/ void CARDSFileFailure(char *path) { printf("CARDS Failure\n

"); printf("

The CARDS software was unable to manipulate the file: %s\n",path); printf("

Please contact the "); printf("webmaster@ncdc.noaa.gov as soon as possible.\n

Thankyou."); printf("

\n"); exit(0); } /*------------------------------- CheckDates -----------------------------*/ void CheckDates(int graph, int start, int end, int startData1, int startData2) { /* If the start year entered by the user is greater than the corresponding end year, stop the CGI and notify the user that such a range is not reasonable.*/ if(start > end) { printf("CARDS Failure\n"); printf("

The \'Start Year\' cannot be larger than, the \'End Year.\'

\n"); printf("Click on the \'Back\' button on your browser and select another time period.\n

"); exit(0); } else /* If the user enters a year prior to 1600 or after 2010, stop the CGI and inform the user that a different range will be necessary in order to proceed.*/ if((start < 1600) || (end > 2010)) { printf("CARDS Failure\n"); printf("

The \'Start Year\' cannot be less than 1600 or greater than 2010.

\n"); printf("Click on the \'Back\' button on your browser and select another time period.\n

"); exit(0); } else if((graph == 2) || (graph == 3)) { if((end < startData1) || (end < startData2)) { printf("CARDS Failure\n"); printf("

The data sets you have attempted to access do not contain any data prior to %d and %d.

\n",startData1,startData2); printf("Click on the \'Back\' button on your browser and select another time period.\n

"); exit(0); } } else if(end < startData1) { printf("CARDS Failure\n"); printf("

The data sets you have attempted to access do not contain any data prior to %d.

\n",startData1); printf("Click on the \'Back\' button on your browser and select another time period.\n

"); exit(0); } } /*------------------------------- RegionIsValid ------------------------------ Makes sure region has something in it. */ void RegionIsValid(char *region) { if((strcmp(region,"SOUTH-AMERICA") == 0) || (strcmp(region,"CENT-AMERICA") == 0) || (strcmp(region,"ANTARCTICA") == 0) || (strcmp(region,"PAC-OCEAN") == 0) || (strcmp(region,"ATL-OCEAN") == 0) || (strcmp(region,"IND-OCEAN") == 0)) { printf("CARDS Failure\n"); printf("

There are no reporting stations in %s.

\n",region); printf("Click on the \'Back\' button on your browser and select another region.\n

"); exit(1); } } /*------------------------------ RemoveSpaces ------------------------------- "RemoveSpaces" removes all extra spaces from the end of a character string. */ void RemoveSpaces(char *string) { char temp[85]; int i,j=0; strcpy(temp,string); /* Get the length of the string.*/ i = strlen(temp); /* Subtract one space for the "NULL" character. */ i--; /* Back up until the first "non-space" character is encountered */ while(isspace(temp[i])) i--; /* Move past the first non-space*/ i++; /* Close off the string at the new location with a "NULL" character. */ temp[i]='\0'; /* Copy the new shortened string over the old one. */ strcpy(string,temp); } /*--------------------------- PrintMonthOptions -------------------------*/ void PrintMonthOptions(int choice, int Dec) { if(choice) printf("