/* 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("All Months\n");
printf(" January\n");
printf(" February\n");
printf(" March\n");
printf(" April\n");
printf(" May\n");
printf(" June\n");
printf(" July\n");
printf(" August\n");
printf(" September\n");
printf(" October\n");
printf(" November\n");
if(Dec)
printf(" December\n");
else
printf(" December\n");
}
/*----------------------------- PrintLatLong -----------------------------*/
void PrintLatLong(float Lat, float Long, char *string)
{
char latoutput[10],longoutput[10],output[22];
/* Any negative Latitudes and Longitudes must have the minus sign removed
and a S or W printed after them. */
if(Lat < 0)
{
/* Removes the negative sign and adds the "S." */
Lat = -Lat;
sprintf(latoutput,"%7.2fS",Lat);
}
else
sprintf(latoutput,"%7.2fN",Lat);
if(Long < 0)
{
/* Removes the negative sign and adds the "W." */
Long = -Long;
sprintf(longoutput, "%7.2fW",Long);
}
else
sprintf(longoutput,"%7.2fE",Long);
/* Print both latitude and longitude as a temporary string and then copy this temporary string over the string passed in from the calling function.*/
sprintf(output, "%s %s",latoutput,longoutput);
strcpy(string,output);
}
/*--------------------------------- MonthName --------------------------------
"MonthName" returns the name of a month when the corresponding month number is passed in as an argument.
*/
char *MonthName(int number, char style)
{
/* 'F' here means 'Full-length'. Calling function wants the entire word. */
if(style == 'F')
switch(number)
{
case 1:
return "January";
case 2:
return "February";
case 3:
return "March";
case 4:
return "April";
case 5:
return "May";
case 6:
return "June";
case 7:
return "July";
case 8:
return "August";
case 9:
return "September";
case 10:
return "October";
case 11:
return "November";
case 12:
return "December";
}
else
if(style == 'A') /* 'A' here means 'Abbreviated'. */
switch(number)
{
case 1:
return "jan";
case 2:
return "feb";
case 3:
return "mar";
case 4:
return "apr";
case 5:
return "may";
case 6:
return "jun";
case 7:
return "jul";
case 8:
return "aug";
case 9:
return "sep";
case 10:
return "oct";
case 11:
return "nov";
case 12:
return "dec";
}
}
/*----------------------------- GetRegion ---------------------------------
"GetRegion" is the function responsible for indicating where the user clicked on the image map that appears on the first HTML page (ghcn.html). "GetRegion" will return a string constant representing the name of one of the 13 regions the user selected on the image map.
*/
char *GetRegion(int xval, int yval)
{
if (((xval >= 0) && (xval <= 50)) && ((yval >= 76) && (yval <= 327)))
{
/*Pacific Ocean -- south of Alaska */
return "PAC-OCEAN";
}
else if (((xval >= 51) && (xval <= 70)) && ((yval >= 120) && (yval <= 327)))
{
/*Pacific Ocean -- west of Canada and U.S.A.*/
return "PAC-OCEAN";
}
else if (((xval >= 71) && (xval <= 90)) && ((yval >= 150) && (yval <= 327)))
{
/*Pacific Ocean -- west of Mexico/Central America */
return "PAC-OCEAN";
}
else if (((xval >= 91) && (xval <= 110)) && ((yval >= 160) && (yval <= 327)))
{
/*Pacific Ocean -- west of Mexico/Central America*/
return "PAC-OCEAN";
}
else if (((xval >= 111) && (xval <= 125)) && ((yval >= 180) && (yval <= 327)))
{
/*Pacific Ocean -- west of South America*/
return "PAC-OCEAN";
}
else if (((xval >= 126) && (xval <= 140)) && ((yval >= 220) && (yval <= 327)))
{
/*Pacific Ocean -- west of South America*/
return "PAC-OCEAN";
}
else if (((xval >= 141) && (xval <= 159)) && ((yval >= 317) && (yval <= 327)))
{
/*Pacific Ocean -- connection with Atlantic at Cape Horn*/
return "PAC-OCEAN";
}
else if (((xval >= 430) && (xval <= 492)) && ((yval >= 281) && (yval <= 327)))
{
/* Pacific Ocean -- south of Australia. Edge of the IO*/
return "PAC-OCEAN";
}
else if (((xval >= 529) && (xval <= 547)) && ((yval >= 275) && (yval <= 296)))
{
/* Pacific Ocean -- east of New Zealand */
return "PAC-OCEAN";
}
else if (((xval >= 508) && (xval <= 547)) && ((yval >= 297) && (yval <= 327)))
{
/* Pacific Ocean -- south of New Zealand */
return "PAC-OCEAN";
}
else if (((xval >= 493) && (xval <= 507)) && ((yval >= 220) && (yval <= 327)))
{
/* Pacific Ocean -- between New Zealand and Australia*/
return "PAC-OCEAN";
}
else if (((xval >= 508) && (xval <= 547)) && ((yval >= 220) && (yval <= 274)))
{
/* Pacific Ocean -- north of New Zealand */
return "PAC-OCEAN";
}
else if (((xval >= 476) && (xval <= 547)) && ((yval >= 73) && (yval <= 192)))
{
/* Pacific Ocean -- about a third of the whole PO east of Asia */
return "PAC-OCEAN";
}
else if (((xval >= 500) && (xval <= 547)) && ((yval >= 193) && (yval <= 274)))
{
/* Pacific Ocean -- east of New Guinea */
return "PAC-OCEAN";
}
else if (((xval >= 450) && (xval <= 474)) && ((yval >= 126) && (yval <= 192)))
{
/* Pacific Ocean -- east of Phillipines, south of Japan, north of NG */
return "PAC-OCEAN";
}
else if (((xval >= 0) && (xval <= 44)) && ((yval >= 0) && (yval <= 76)))
{
/* United States */
return "US";
}
else if (((xval >= 51) && (xval <= 127)) && ((yval >= 82) && (yval <= 118)))
{
/* United States */
return "US";
}
else if (((xval >= 128) && (xval <= 147)) && ((yval >= 96) && (yval <= 122)))
{
/* United States */
return "US";
}
else if (((xval >= 141) && (xval <= 158)) && ((yval >= 89) && (yval <= 97)))
{
/* United States */
return "US";
}
else if (((xval >= 98) && (xval <= 131)) && ((yval >= 119) && (yval <= 123)))
{
/* United States */
return "US";
}
else if (((xval >= 105) && (xval <= 138)) && ((yval >= 123) && (yval <= 128)))
{
/* United States */
return "US";
}
else if (((xval >= 128) && (xval <= 137)) && ((yval >= 129) && (yval <= 137)))
{
/* United States */
return "US";
}
else if (((xval >= 142) && (xval <= 182)) && ((yval >= 166) && (yval <= 180)))
{
/* South America */
return "SOUTH-AMERICA";
}
else if (((xval >= 121) && (xval <= 212)) && ((yval >= 179) && (yval <= 315)))
{
/* South America */
return "SOUTH-AMERICA";
}
else if (((xval >= 0) && (xval <= 547)) && ((yval >= 326) && (yval <= 365)))
{
/* Antarctica */
return "ANTARCTICA";
}
else if (((xval >= 231) && (xval <= 241)) && ((yval >= 121) && (yval <= 180)))
{
/* Africa -- extreme west coast*/
return "AFRICA";
}
else if (((xval >= 242) && (xval <= 305)) && ((yval >= 110) && (yval <= 180)))
{
/* Africa -- northern Africa*/
return "AFRICA";
}
else if (((xval >= 270) && (xval <= 320)) && ((yval >= 180) && (yval <= 270)))
{
/* Africa -- South Africa*/
return "AFRICA";
}
else if (((xval >= 321) && (xval <= 335)) && ((yval >= 165) && (yval <= 193)))
{
/* Africa -- Somalia*/
return "AFRICA";
}
else if (((xval >= 306) && (xval <= 320)) && ((yval >= 150) && (yval <= 179)))
{
/* Africa -- near Red Sea*/
return "AFRICA";
}
else if (((xval >= 306) && (xval <= 315)) && ((yval >= 141) && (yval <= 149)))
{
/* Africa -- near Red Sea*/
return "AFRICA";
}
else if (((xval >= 321) && (xval <= 335)) && ((yval >= 249) && (yval <= 327)))
{
/* Indian Ocean -- south of Madagascar */
return "IND-OCEAN";
}
else if (((xval >= 336) && (xval <= 395)) && ((yval >= 161) && (yval <= 327)))
{
/* Indian Ocean -- south of India, most of the IO */
return "IND-OCEAN";
}
else if (((xval >= 396) && (xval <= 429)) && ((yval >= 221) && (yval <= 327)))
{
/* Indian Ocean -- south of Indonesia, west of Australia */
return "IND-OCEAN";
}
else if (((xval >= 396) && (xval <= 450)) && ((yval >= 161) && (yval <= 220)))
{
/* South Pacific -- Phillipines, Indonesia, Borneo*/
return "S. E. ASIA";
}
else if (((xval >= 451) && (xval <= 500)) && ((yval >= 192) && (yval <= 220)))
{
/* South Pacific -- New Guinea*/
return "S. E. ASIA";
}
else if (((xval >= 430) && (xval <= 492)) && ((yval >= 221) && (yval <= 280)))
{
/* South Pacific -- Australia*/
return "S. E. ASIA";
}
else if (((xval >= 508) && (xval <= 528)) && ((yval >= 275) && (yval <= 296)))
{
/* South Pacific -- New Zealand*/
return "S. E. ASIA";
}
else if (((xval >= 242) && (xval <= 258)) && ((yval >= 0) && (yval <= 110)))
{
/* Europe */
return "EUROPE";
}
else if (((xval >= 256) && (xval <= 275)) && ((yval >= 8) && (yval <= 105)))
{
/* Europe */
return "EUROPE";
}
else if (((xval >= 277) && (xval <= 304)) && ((yval >= 8) && (yval <= 110)))
{
/* Europe */
return "EUROPE";
}
else if (((xval >= 304) && (xval <= 325)) && ((yval >= 97) && (yval <= 108)))
{
/* Europe */
return "EUROPE";
}
else if (((xval >= 304) && (xval <= 372)) && ((yval >= 68) && (yval <= 100)))
{
/* USSR */
return "ASIA";
}
else if (((xval >= 366) && (xval <= 383)) && ((yval >= 69) && (yval <= 98)))
{
/* USSR */
return "ASIA";
}
else if (((xval >= 301) && (xval <= 547)) && ((yval >= 1) && (yval <= 72)))
{
/* USSR -- all of northern Russia */
return "ASIA";
}
else if (((xval >= 385) && (xval <= 394)) && ((yval >= 69) && (yval <= 84)))
{
/* USSR */
return "ASIA";
}
else if (((xval >= 393) && (xval <= 441)) && ((yval >= 60) && (yval <= 76)))
{
/* USSR */
return "ASIA";
}
else if (((xval >= 451) && (xval <= 475)) && ((yval >= 73) && (yval <= 79)))
{
/* USSR */
return "ASIA";
}
else if (((xval >= 461) && (xval <= 475)) && ((yval >= 79) && (yval <= 98)))
{
/* USSR -- Kamchatka */
return "ASIA";
}
else if (((xval >= 45) && (xval <= 177)) && ((yval >= 0) && (yval <= 85)))
{
/* Canada */
return "CANADA";
}
else if (((xval >= 127) && (xval <= 140)) && ((yval >= 80) && (yval <= 95)))
{
/* Canada */
return "CANADA";
}
else if (((xval >= 141) && (xval <= 177)) && ((yval >= 80) && (yval <= 89)))
{
/* Canada */
return "CANADA";
}
else if (((xval >= 178) && (xval <= 241)) && ((yval >= 0) && (yval <= 55)))
{
/* Canada */
return "CANADA";
}
else if (((xval >= 179) && (xval <= 241)) && ((yval >= 56) && (yval <= 122)))
{
/* Atlantic Ocean -- between Canada and Britain*/
return "ATL-OCEAN";
}
else if (((xval >= 148) && (xval <= 241)) && ((yval >= 97) && (yval <= 122)))
{
/* Atlantic Ocean -- east coast of the U.S.A.*/
return "ATL-OCEAN";
}
else if (((xval >= 139) && (xval <= 147)) && ((yval >= 118) && (yval <= 122)))
{
/* Atlantic Ocean -- east coast of U.S.A. at Florida/Carolinas*/
return "ATL-OCEAN";
}
else if (((xval >= 148) && (xval <= 168)) && ((yval >= 138) && (yval <= 123)))
{
/* Atlantic Ocean -- off of the Bahamas*/
return "ATL-OCEAN";
}
else if (((xval >= 168) && (xval <= 230)) && ((yval >= 123) && (yval <= 170)))
{
/* Atlantic Ocean -- Between Africa and South America */
return "ATL-OCEAN";
}
else if (((xval >= 168) && (xval <= 205)) && ((yval >= 171) && (yval <= 189)))
{
/* Atlantic Ocean -- Between Africa and South America/Lesser Antilles*/
return "ATL-OCEAN";
}
else if (((xval >= 206) && (xval <= 230)) && ((yval >= 171) && (yval <= 327)))
{
/* Atlantic Ocean -- Down eastern coast of South America */
return "ATL-OCEAN";
}
else if (((xval >= 231) && (xval <= 269)) && ((yval >= 181) && (yval <= 327)))
{
/* Atlantic Ocean -- Down eastern coast of South America*/
return "ATL-OCEAN";
}
else if (((xval >= 187) && (xval <= 205)) && ((yval >= 247) && (yval <= 327)))
{
/* Atlantic Ocean -- Down eastern coast of South America*/
return "ATL-OCEAN";
}
else if (((xval >= 172) && (xval <= 186)) && ((yval >= 270) && (yval <= 327)))
{
/* Atlantic Ocean -- Down eastern coast of South America*/
return "ATL-OCEAN";
}
else if (((xval >= 160) && (xval <= 171)) && ((yval >= 280) && (yval <= 327)))
{
/* Atlantic Ocean -- Down eastern coast of South America*/
return "ATL-OCEAN";
}
else if (((xval >= 271) && (xval <= 319)) && ((yval >= 270) && (yval <= 327)))
{
/* Atlantic Ocean -- connection with Pacific Ocean, Cape of Good Hope*/
return "ATL-OCEAN";
}
else if (((xval >= 324) && (xval <= 352)) && ((yval >= 104) && (yval <= 109)))
{
/* Middle East */
return "MIDDLE EAST";
}
else if (((xval >= 305) && (xval <= 354)) && ((yval >= 109) && (yval <= 128)))
{
/* Middle East */
return "MIDDLE EAST";
}
else if (((xval >= 313) && (xval <= 353)) && ((yval >= 128) && (yval <= 138)))
{
/* Middle East */
return "MIDDLE EAST";
}
else if (((xval >= 317) && (xval <= 353)) && ((yval >= 139) && (yval <= 150)))
{
/* Middle East */
return "MIDDLE EAST";
}
else if (((xval >= 322) && (xval <= 352)) && ((yval >= 149) && (yval <= 160)))
{
/* Middle East -- Southern Arabian Peninsula/Indian Ocean */
return "MIDDLE EAST";
}
else if (((xval >= 353) && (xval <= 395)) && ((yval >= 97) && (yval <= 160)))
{
/* Asia -- India*/
return "ASIA";
}
else if (((xval >= 396) && (xval <= 450)) && ((yval >= 112) && (yval <= 160)))
{
/* Asia -- Thailand, Vietnam, Phillipines*/
return "ASIA";
}
else if (((xval >= 451) && (xval <= 475)) && ((yval >= 99) && (yval <= 125)))
{
/* Asia -- Japan*/
return "ASIA";
}
else if (((xval >= 373) && (xval <= 450)) && ((yval >= 99) && (yval <= 113)))
{
/* Asia -- across China*/
return "ASIA";
}
else if (((xval >= 385) && (xval <= 450)) && ((yval >= 85) && (yval <= 101)))
{
/* Asia -- northern China, Mongolia */
return "ASIA";
}
else if (((xval >= 392) && (xval <= 453)) && ((yval >= 77) && (yval <= 86)))
{
/* Asia -- Mongolia */
return "ASIA";
}
else if (((xval >= 454) && (xval <= 462)) && ((yval >= 81) && (yval <= 88)))
{
/* Asia -- EXTREME northeast China*/
return "ASIA";
}
else if (((xval >= 442) && (xval <= 452)) && ((yval >= 72) && (yval <= 75)))
{
/* Asia -- EXTREME northeast China*/
return "ASIA";
}
else if (((xval >= 138) && (xval <= 147)) && ((yval >= 123) && (yval <= 137)))
{
/* Central America */
return "CENT-AMERICA";
}
else if (((xval >= 71) && (xval <= 98)) && ((yval >= 120) && (yval <= 138)))
{
/* Central America */
return "CENT-AMERICA";
}
else if (((xval >= 98) && (xval <= 107)) && ((yval >= 123) && (yval <= 138)))
{
/* Central America */
return "CENT-AMERICA";
}
else if (((xval >= 107) && (xval <= 113)) && ((yval >= 128) && (yval <= 138)))
{
/* Central America */
return "CENT-AMERICA";
}
else if (((xval >= 71) && (xval <= 167)) && ((yval >= 137) && (yval <= 165)))
{
/* Central America */
return "CENT-AMERICA";
}
else if (((xval >= 117) && (xval <= 141)) && ((yval >= 159) && (yval <= 176)))
{
/* Central America */
return "CENT-AMERICA";
}
else
{
/* This will be here just in case the user finds a seam between the
areas mapped out above. NOT likely */
printf("CARDS Failure \n");
printf("You seem to have found an area on the map the program does");
printf(" not recognize. Click on the \'Back\' button on your browser ");
printf("and select another location. \n");
printf("");
exit(0);
}
}
/*----------------------------- MakeXTicks -------------------------------*/
int MakeXTicks(FILE *param,int startyear,int endyear,int month, int month2, int pic)
{
int i,j=1,totalmonths,totalyears,subend,counter=0,year,monthnum,run;
/* Get totoal number of years involved */
totalyears = endyear - startyear;
/* Include the first year also*/
totalyears++;
/* Find out how many months from the end of the endyear the graph
data will no longer be taken */
subend = 12 - month2;
/* Total number of months in the period of years to graph. . .*/
totalmonths = totalyears * 12;
/* . . . minus the months that won't be graphed during this time frame,
equals the total number of months to graph */
totalmonths -= (subend + (month-1));
/* Get the year number (e.g. '45, '46, etc) */
year = startyear % 100;
/* Get the month number */
monthnum = month;
fprintf(param, "xaxis tick type spec\n");
for(i=0; i < totalmonths; )
{
/* Value of pic decides what time frame to graph as specified by the calling function. */
switch(pic)
{
case 1:
{
/* Make a tick mark for every piece of data. Case 1 is only accessed if the time period to graph is not greater than 24 months.*/
fprintf(param, "xaxis tick %d, %d\n",counter,counter);
/* This If/else tree is within every case. It simply adds a leading zero in front of every year and month number that is less than 10. XMGR has to have them listed in a two digit field.*/
if(monthnum < 10)
if(year < 10)
fprintf(param, "xaxis ticklabel %d,\"0%d0%d\"\n",counter++,year,monthnum);
else
fprintf(param, "xaxis ticklabel %d,\"%d0%d\"\n",counter++,year,monthnum);
else
if(year < 10)
fprintf(param, "xaxis ticklabel %d,\"0%d%d\"\n",counter++,year,monthnum);
else
fprintf(param, "xaxis ticklabel %d,\"%d%d\"\n",counter++,year,monthnum);
i++;
break;
}
case 2:
{
/* Case 2 is only accessed if the time period to graph is greater than 24 months but less than 120. (Between 2 and 10 years.) Case 2 will make a tick mark for every Jan, May, and Sept.*/
if((monthnum == 1)||(monthnum == 5)||(monthnum == 9))
{
fprintf(param, "xaxis tick %d, %d\n",counter,i);
if(monthnum < 10)
if(year < 10)
fprintf(param, "xaxis ticklabel %d,\"0%d0%d\"\n",counter++,year,monthnum);
else
fprintf(param, "xaxis ticklabel %d,\"%d0%d\"\n",counter++,year,monthnum);
else
if(year < 10)
fprintf(param, "xaxis ticklabel %d,\"0%d%d\"\n",counter++,year,monthnum);
else
fprintf(param, "xaxis ticklabel %d,\"%d%d\"\n",counter++,year,monthnum);
}
i++;
break;
}
case 3:
{
/* Case 3 is used when the period to graph is between 10 and 15 years (121 to 180 months). A major tick mark will be made for each January and July. */
if((monthnum == 1)||(monthnum == 7))
{
fprintf(param, "xaxis tick %d, %d\n",counter,i);
if(monthnum < 10)
if(year < 10)
fprintf(param, "xaxis ticklabel %d,\"0%d0%d\"\n",counter++,year,monthnum);
else
fprintf(param, "xaxis ticklabel %d,\"%d0%d\"\n",counter++,year,monthnum);
else
if(year < 10)
fprintf(param, "xaxis ticklabel %d,\"0%d%d\"\n",counter++,year,monthnum);
else
fprintf(param, "xaxis ticklabel %d,\"%d%d\"\n",counter++,year,monthnum);
}
i++;
break;
}
case 4:
{
/* Case 4 is used when the period to graph is between 15 and 35 years (181 to 420 months). A major tick mark will be made for January of each year.*/
if((monthnum == 1))
{
fprintf(param, "xaxis tick %d, %d\n",counter,i);
if(year < 10)
fprintf(param, "xaxis ticklabel %d,\"0%d0%d\"\n",counter++,year,monthnum);
else
fprintf(param, "xaxis ticklabel %d,\"%d0%d\"\n",counter++,year,monthnum);
}
i++;
break;
}
case 5:
{
/* Case 5 is used when the period to graph is between 35 and 50 years (421 to 600 months). A major tick mark will be placed for January of every even year.*/
/* If run is 0, this is a year divisible by two. */
run = year % 2;
if((run == 0) && (monthnum == 1))
{
fprintf(param, "xaxis tick %d, %d\n",counter,i);
monthnum = 1;
if(year < 10)
fprintf(param, "xaxis ticklabel %d,\"0%d0%d\"\n",counter++,year,monthnum);
else
fprintf(param, "xaxis ticklabel %d,\"%d0%d\"\n",counter++,year,monthnum);
/* Increment year to next value: either 0 (turn of century) or plus 2.*/
if(year == 98)
year = 0;
else
year+=2;
/* Set month to 1, increment month counter (i) by 24, and set j=0; Now the loop is ready to run again. */
monthnum = 1;
i+=24;
j=0;
}
else
{
/* If year is not evenly divided by two, increment i and set j to 1. "J" signals the if else tree near the bottom (outside switch) to be run. */
i++;
j=1;
}
break;
}
case 6:
{
/* Case 6 is used when the period to graph is between 50 and 100 years (601 to 1200 months). A major tick mark will be placed for January of every year divisible by five.*/
run = year % 5;
if((run == 0) && (monthnum == 1))
{
fprintf(param, "xaxis tick %d, %d\n",counter,i);
if(year < 10)
fprintf(param, "xaxis ticklabel %d,\"0%d0%d\"\n",counter++,year,monthnum);
else
fprintf(param, "xaxis ticklabel %d,\"%d0%d\"\n",counter++,year,monthnum);
/* Increment year to next value: either 0 (turn of century) or plus 5. */
if(year == 95)
year = 0;
else
year += 5;
/* Set month to 1, increment month counter (i) by 60, and set j=0; Now the loop is ready to run again. */
i+=60;
monthnum = 1;
j=0;
}
else
{
/* The program still hasn't reached the first month of a year
that is evenly divisable by five. So increment i and go
into the if/else tree below. */
i++;
j=1;
}
break;
}
case 7:
{
/* Case 7 is used when the period to graph is between 100 and 300 years (1201 to 3600 months). A major tick mark will be placed for January of every year divisible by ten.*/
run = year % 10;
if((run == 0) && (monthnum == 1))
{
fprintf(param, "xaxis tick %d, %d\n",counter,i);
if(year < 10)
fprintf(param, "xaxis ticklabel %d,\"0%d0%d\"\n",counter++,year,monthnum);
else
fprintf(param, "xaxis ticklabel %d,\"%d0%d\"\n",counter++,year,monthnum);
/* Increment year to next value: either 0 (turn of century) or plus 10. */
if(year == 90)
year = 0;
else
year += 10;
/* Set month to 1, increment month counter (i) by 120, and set j=0; Now the loop is ready to run again. */
i+=120;
monthnum = 1;
j=0;
}
else
{
i++;
j=1;
}
break;
}
case 8:
{
/* Case 8 is used when the period to graph is greater than 300 years (greater than 3601 months). A major tick mark will be placed for January of every year divisible by 25.*/
run = year % 25;
if((run == 0) && (monthnum == 1))
{
fprintf(param, "xaxis tick %d, %d\n",counter,i);
if(year < 10)
fprintf(param, "xaxis ticklabel %d,\"0%d0%d\"\n",counter++,year,monthnum);
else
fprintf(param, "xaxis ticklabel %d,\"%d0%d\"\n",counter++,year,monthnum);
/* Increment year to next value: either 0 (turn of century) or plus 25. */
if(year == 75)
year = 0;
else
year += 25;
/* Set month to 1, increment month counter (i) by 300, and set j=0; Now the loop is ready to run again. */
i+=300;
monthnum = 1;
j=0;
}
else
{
i++;
j=1;
}
break;
}
}
/* This small if/else tree moves monthnum and year along together.
Sometimes this is not necessary after a particular year is reached.
This is the case in the graphs with 2,5, and 10 year major ticks.
Once January of a year divisable by 2,5, or 10 is reached, each case
increments i and years on its own and sets the monthnum = 1 and this
small tree is no longer needed. The value of j indicates whether or
not these statements should be executed. "j" is set to 1 at the top
of the function so that these statements will be run only until one
of the 2,5,or 10 year graphs is created. */
if(j)
if(monthnum == 12)
{
monthnum = 1;
if(year == 99)
year = 0;
else
year++;
}
else
monthnum++;
}
/* The value of counter will be the x-axis maximum */
fprintf(param, "xaxis tick spec %d\n",counter);
return totalmonths;
}
/*----------------------------- MakeYTicks -------------------------------*/
void MakeYTicks(int iunits, int ihighest, int ilowest, FILE *param)
{
int add,hundreds,tens,ones,tenths,ineg=0;
float fmax,fmin,celsius,fahrenheit,fconvert,frange;
if(iunits)
{
if(ihighest < 0)
{
ihighest = (-ihighest);
ineg=1;
}
celsius = ihighest / 10;
hundreds = celsius / 100;
celsius -= (hundreds * 100);
tens = celsius / 10;
celsius -= (tens * 10);
ones = celsius;
tenths = ihighest % 10;
}
else
{
fconvert = ((((float)ihighest*9)/50)+32);
fconvert *= 10;
if(fconvert < 0.0)
{
fconvert = (-fconvert);
ineg=1;
}
fahrenheit = ((((float)ihighest*9)/50)+32);
hundreds = fahrenheit / 100;
fahrenheit -= (hundreds * 100);
tens = fahrenheit / 10;
fahrenheit -= (tens * 10);
ones = fahrenheit;
tenths = (int)fconvert % 10;
}
/* If the highest value is over a hundred, use the values of "tens" and "ones" to create a y-max value that is a little higher than the highest hundred. */
if(hundreds)
{
if(tens)
add = (((tens * 10) + ones) * 1.25);
else
add = ones + 5;
if(ineg)
fmax = (float)((hundreds * 100) - add);
else
fmax = (float)((hundreds * 100) + add);
}
else
if(tens)
{
if(ones)
if(ones > 4)
add = ones - 2;
else
if(ones > 2)
add = ones * 1.5;
else
add = ones * 2;
else
add = 3;
if(ineg)
fmax = (float)(((tens * 10) + ones) - add);
else
fmax = (float)(((tens * 10) + ones) + add);
}
else
if(ones)
{
if(tenths)
add = tenths * 1.25;
else
add = 2;
if(ineg)
fmax = (float)(ones - add);
else
fmax = (float)(ones + add);
}
else
fmax = 2;
if(ineg)
fmax = -fmax;
ineg=0;
/* Calculate minimum value */
if(iunits)
{
if(ilowest < 0)
{
ilowest = (-ilowest);
ineg=1;
}
celsius = ilowest / 10;
hundreds = celsius / 100;
celsius -= (hundreds * 100);
tens = celsius / 10;
celsius -= (tens * 10);
ones = celsius;
tenths = ilowest % 10;
}
else
{
fahrenheit = ((((float)ilowest*9)/50)+32);
fconvert = fahrenheit * 10;
if(fahrenheit < 0.000)
{
fahrenheit = (-fahrenheit);
ineg=1;
}
hundreds = fahrenheit / 100;
fahrenheit -= (hundreds * 100);
tens = fahrenheit / 10;
fahrenheit -= (tens * 10);
ones = fahrenheit;
tenths = (int)fconvert % 10;
}
if(hundreds)
{
add = (((tens * 10) + ones) * 1.5);
if(ineg)
fmin = (float)((hundreds * 100) + add);
else
fmin = (float)((hundreds * 100) - add);
}
else
if(tens)
{
if(ones)
if(ones > 4)
add = ones - 2;
else
if(ones > 2)
add = ones * 1.5;
else
add = ones * 2;
else
add = 3;
if(ineg)
fmin = (float)(((tens * 10) + ones) + add);
else
fmin = (float)(((tens * 10) + ones) - add);
}
else
if(ones)
{
if(tenths > 6)
add = tenths - 4;
else
if(tenths > 2)
add = tenths * 1.25;
else
add = 2;
if(ineg)
fmin = (float)(ones + add);
else
fmin = (float)(ones - add);
}
else
fmin = 2;
if(ineg)
fmin = -fmin;
/* Write y-max and tick spacing values to paramter file. */
fprintf(param,"world ymax %6.0f\n",fmax);
fprintf(param,"world ymin %6.0f\n",fmin);
if(ineg)
frange = fmax + (-fmin);
else
frange = fmax - fmin;
/* Set ten major ticks and five minor ticks. */
fprintf(param,"yaxis tick major %6.3f\n",frange /= 10.0);
fprintf(param,"yaxis tick minor %6.3f\n",frange / 5.0);
fprintf(param,"yaxis ticklabel prec 0\n");
}
/*----------------------------- MakeParam ---------------------------------
MakeParam creates a temporary paramter file containing the parameter settings necessary for the particular dataset or sets being graphed. */
void MakeParam(char* region1, int igraphType, char remote_user, char* pscountry1, char* pscountry2, char* psname1, char* psname2, int istartYear, int iendYear, int ihigh, int ilow, float fmissing1, float fmissing2, int imonth1, int imonth2, int ipid, char* psparam1, char* psparam2, int iunits, char* pslocation1, char* pslocation2,char* pstimeStamp,int Ihr_group, int Ipres_lvl, int Iparm_type)
{
FILE *param;
char *monthname,*monthname2,parampath[100],c;
int years,totalmonths,pic,ones,hundreds,tens;
int i=0,celsius,fahrenheit;
int Ppres_lvl=0;
char Spres_lvl[11];
char Sparm_type[5];
/* set name of parameter type: 1=wind; 2=temp */
if(Iparm_type==1)
strcpy(Sparm_type,"wind");
if(Iparm_type==2)
strcpy(Sparm_type,"temp");
/* Set Print Pres Level value */
/* Ppres_lvl=(Ipres_lvl*.1); */
if( (Ipres_lvl==26) || (Ipres_lvl==31) )
{
if(Ipres_lvl==31)
strcpy(Spres_lvl,"Surface");
if(Ipres_lvl==26)
strcpy(Spres_lvl,"Tropopause");
}
else
{
Ppres_lvl=(Ipres_lvl*.1);
sprintf(Spres_lvl,"%dmb",Ppres_lvl);
}
/* Find the period of time being graphed */
years = iendYear-istartYear;
/*open path to temporary parameter file*/
sprintf(parampath,"/WWW/htdocs/ol/climvis/temp/temp.%d.par",ipid);
param = fopen(parampath,"w");
if(param == NULL)
CARDSFileFailure(parampath);
fflush(param);
psparam1=ParamName(psparam1);
psparam2=ParamName(psparam2);
if(iunits==1)
{
if(Iparm_type==1)
{
fprintf(param, "yaxis label \"Meters per Second\"\n");
}
if(Iparm_type==2)
{
fprintf(param, "yaxis label \"Celsius\"\n");
}
}
else
{
fprintf(param, "yaxis label \"Fahrenheit\"\n");
}
/* Write the correct y-axis tick spacing to the parameter file */
MakeYTicks(iunits,ihigh,ilow,param);
/* Check to see if the user is accessing the system from inside or outside the building. If they are from the outside, print the time and the commercial warning on the graph, otherwise print only the time on the graph. */
if(remote_user == 'Y')
{
/* Print time and warning on graph */
fprintf(param,"with string\nstring on\nstring loctype view\n");
fprintf(param,"string 0.065, 0.010\nstring linewidth 1\n");
fprintf(param,"string color 1\nstring rot 0\nstring font 4\n");
fprintf(param,"string just 0\nstring char size 0.750\n");
fprintf(param,"string def \"**Note** This graph, and the datasets associated with it, are not for commercial distribution. Created: %s\"\n",pstimeStamp);
}
else
{
fprintf(param,"with string\nstring on\nstring loctype view\n");
fprintf(param,"string 0.065, 0.015\nstring linewidth 1\n");
fprintf(param,"string color 1\nstring rot 0\nstring font 4\n");
fprintf(param,"string just 0\nstring char size 0.750\n");
fprintf(param,"string def \"Created: %s\"\n",pstimeStamp);
}
/* The "if" sets up parameters for graph selections 1,2, and 3 for a particular month. The associated "else" sets up the paramters for 1,2, and 3 all months and type 4, user selected time period. */
if((imonth1) && (igraphType != 4))
{
fprintf(param,"legend x1 0.070\nlegend y1 0.085\n");
/* Print lat/long string to graph */
fprintf(param,"with string\nstring on\nstring loctype view\n");
fprintf(param,"string 0.685, 0.085\nstring linewidth 1\n");
fprintf(param,"string color 1\nstring rot 0\nstring font 4\n");
fprintf(param,"string just 0\nstring char size 1.000\n");
fprintf(param,"string def \"Location: %s\"\n",pslocation1);
/* For graph options 2 and 3 a second "location" string is necessary for the second station */
if((igraphType == 2) || (igraphType == 3))
{
fprintf(param,"with string\nstring on\nstring loctype view\n");
fprintf(param,"string 0.685, 0.05\nstring linewidth 1\n");
fprintf(param,"string color 1\nstring rot 0\nstring font 4\n");
fprintf(param,"string just 0\nstring char size 1.000\n");
fprintf(param,"string def \"Location: %s\"\n",pslocation2);
}
monthname = MonthName(imonth1,'F');
/* Set up the appropriate title for the graph. Type 1 will be a single station two paramters so it will have a different titling scheme. */
if(igraphType == 1)
{
fprintf(param,"title \"%s %s\"\n",psname1,pscountry1);
}
else
fprintf(param,"title \"%s Temperature\"\n",psparam1);
fprintf(param, "xaxis label \"Year\"\n");
/* Set the xmax and xmin to be the starting and ending years */
fprintf(param, "world xmin %d\n",istartYear);
fprintf(param, "world xmax %d\n",iendYear);
switch(igraphType)
{
case 1:
{
/* Settings for graph type 1: Display Two parameters for one station */
if(Iparm_type==1)
{
fprintf(param, "subtitle \"%s Monthly Avg Wind Speed for %s: %d to %d -- %2.2dZ\"\n",Spres_lvl, monthname,istartYear,iendYear,Ihr_group);
}
if(Iparm_type==2)
{
fprintf(param, "subtitle \"%s Monthly Avg Temperature for %s: %d to %d -- %2.2dZ\"\n",Spres_lvl, monthname,istartYear,iendYear,Ihr_group);
}
/* Indicate on the legend what the colored lines on the graph stand for */
fprintf(param,"legend string 0 \"%s: %6.1f%c missing\"\n",psparam1,fmissing1,'%');
fprintf(param,"legend string 1 \"%s: %6.1f%c missing\"\n",psparam2,fmissing2,'%');
break;
}
case 2:
{
if(strcmp(region1,"US")!=0)
pscountry2 = pscountry1;
/* Settings for graph type 2: One parameter for two station in a region.*/
fprintf(param, "subtitle \"%s: %d to %d\"\n",monthname,istartYear,iendYear);
/* Indicate on the legend what the colored lines on the graph stand for */
fprintf(param,"legend string 0 \"%s, %s: %6.1f%c missing\"\n",psname1,pscountry1,fmissing1,'%');
fprintf(param,"legend string 1 \"%s, %s: %6.1f%c missing\"\n",psname2,pscountry2,fmissing2,'%');
break;
}
case 3:
{
/* Option 3: Display one paramter from two stations in two separate regions. */
fprintf(param, "subtitle \"%s: %d to %d\"\n",monthname,istartYear,iendYear);
/* Indicate on the legend what the colored lines on the graph stand for */
fprintf(param,"legend string 0 \"%s, %s: %6.1f%c missing\"\n",psname1,pscountry1,fmissing1,'%');
fprintf(param,"legend string 1 \"%s, %s: %6.1f%c missing\"\n",psname2,pscountry2,fmissing2,'%');
break;
}
case 4:
{
/* Print "percent missing" string to graph */
fprintf(param,"with string\nstring on\nstring loctype view\n");
fprintf(param,"string 0.75, 0.075\nstring linewidth 1\n");
fprintf(param,"string color 1\nstring rot 0\nstring font 4\n");
fprintf(param,"string just 0\nstring char size 1.000\n");
fprintf(param,"string def \"%6.1f%c missing\"\n",fmissing1,'%');
break;
}
}
/* Set x-axis ticks for monthly graphs */
fprintf(param, "xaxis ticklabel prec 0\n");
if(years <= 15)
{
fprintf(param,"xaxis tick major 1\n");
fprintf(param,"xaxis tick minor 0\n");
}
else
if(years <= 50)
{
fprintf(param,"xaxis tick major 5\n");
fprintf(param,"xaxis tick minor 1\n");
}
else
if(years <= 100)
{
fprintf(param,"xaxis tick major 10\n");
fprintf(param,"xaxis tick minor 1\n");
}
else
{
fprintf(param,"xaxis tick major 25\n");
fprintf(param,"xaxis tick minor 5\n");
fprintf(param,"s0 symbol 0\ns1 symbol 0\n");
}
}
else
{
/* Settings for graph of ALL MONTHS with in a period of years */
/* Set first and last months to 1 and 12 for all graph types except 4 */
if(igraphType != 4)
{
imonth1=1;
imonth2=12;
}
monthname = MonthName(imonth1,'F');
monthname2 = MonthName(imonth2,'F');
/* Print the legend string at this location*/
fprintf(param,"legend x1 .075\n");
fprintf(param,"legend y1 .2\n");
/* Print lat/long string to graph */
fprintf(param,"with string\nstring on\nstring loctype view\n");
fprintf(param,"string 0.685, 0.2\nstring linewidth 1\n");
fprintf(param,"string color 1\nstring rot 0\nstring font 4\n");
fprintf(param,"string just 0\nstring char size 1.000\n");
fprintf(param,"string def \"Location: %s\"\n",pslocation1);
if((igraphType == 2) || (igraphType == 3))
{
fprintf(param,"with string\nstring on\nstring loctype view\n");
fprintf(param,"string 0.685, 0.1675\nstring linewidth 1\n");
fprintf(param,"string color 1\nstring rot 0\nstring font 4\n");
fprintf(param,"string just 0\nstring char size 1.000\n");
fprintf(param,"string def \"Location: %s\"\n",pslocation2);
}
/* Print the correct title, subtitle, and legend string according to the graph type */
switch(igraphType)
{
case 1:
{
fprintf(param,"title \"%s %s\"\n",psname1,pscountry1);
if(Iparm_type==1)
{
fprintf(param, "subtitle \"%s Monthly Avg Wind Speed %s %d to %s %d -- %2.2dZ\"\n",Spres_lvl,monthname,istartYear,monthname2,iendYear,Ihr_group);
}
if(Iparm_type==2)
{
fprintf(param, "subtitle \"%s Monthly Avg Temperature %s %d to %s %d -- %2.2dZ\"\n",Spres_lvl,monthname,istartYear,monthname2,iendYear,Ihr_group);
}
/* fprintf(param, "subtitle \"Temperature %s %d to %s %d\"\n",monthname,istartYear,monthname2,iendYear); */
fprintf(param,"legend string 0 \"%s: %6.1f%c missing\"\n",psparam1,fmissing1,'%');
fprintf(param,"legend string 1 \"%s: %6.1f%c missing\"\n",psparam2,fmissing2,'%');
break;
}
case 2:
{
if(strcmp(region1,"US")!=0)
pscountry2 = pscountry1;
fprintf(param,"title \"%s Temperature\"\n",psparam1);
fprintf(param, "subtitle \"%s %d to %s %d\"\n",monthname,istartYear,monthname2,iendYear);
fprintf(param,"legend string 0 \"%s, %s: %6.1f%c missing\"\n",psname1,pscountry1,fmissing1,'%');
fprintf(param,"legend string 1 \"%s, %s: %6.1f%c missing\"\n",psname2,pscountry2,fmissing2,'%');
break;
}
case 3:
{
fprintf(param,"title \"%s Temperature\"\n",psparam1);
fprintf(param, "subtitle \"%s %d to %s %d\"\n",monthname,istartYear,monthname2,iendYear);
fprintf(param,"legend string 0 \"%s, %s: %6.1f%c missing\"\n",psname1,pscountry1,fmissing1,'%');
fprintf(param,"legend string 1 \"%s, %s: %6.1f%c missing\"\n",psname2,pscountry2,fmissing2,'%');
break;
}
case 4:
{
fprintf(param,"title \"%s, %s\"\n",psname1,pscountry1);
fprintf(param, "subtitle \"%s Temperature %s %d to %s %d\"\n",psparam1,monthname,istartYear,monthname2,iendYear);
/* Print "percent missing" string to graph */
fprintf(param,"with string\nstring on\nstring loctype view\n");
fprintf(param,"string 0.675, 0.165\nstring linewidth 1\n");
fprintf(param,"string color 1\nstring rot 0\nstring font 4\n");
fprintf(param,"string just 0\nstring char size 1.000\n");
fprintf(param,"string def \"%6.1f%c missing\"\n",fmissing1,'%');
break;
}
}
/* Print "Month" title as a string. The placement of the regular xaxis
title is too close to the tick labels. */
fprintf(param,"with string\nstring on\nstring loctype view\n");
fprintf(param,"string 0.50, 0.25\nstring linewidth 2\n");
fprintf(param,"string color 4\nstring rot 0\nstring font 4\n");
fprintf(param,"string just 0\nstring char size 1.25000\n");
fprintf(param,"string def \"Month\"\n");
/* Set up the xaxis tick labeling scheme. For graphs of all months or of a specific period of time, it is necessary to specifiy all the labels manually. */
fprintf(param,"xaxis label \"\"\n");
fprintf(param,"xaxis tick minor off\n");
fprintf(param,"xaxis tick minor grid off\n");
fprintf(param,"yaxis tick minor off\n");
fprintf(param,"yaxis tick minor grid off\n");
fprintf(param,"xaxis ticklabel type spec\n");
fprintf(param,"xaxis ticklabel layout spec\n");
fprintf(param,"xaxis ticklabel angle 45\n");
fprintf(param,"xaxis tick out\n");
fprintf(param,"xaxis tick major color 14\n");
fprintf(param,"yaxis tick major color 14\n");
fprintf(param,"view ymin 0.35\n");
fprintf(param,"view ymax 0.75\n");
if(years <= 2)
{
pic = 1;
totalmonths=MakeXTicks(param,istartYear,iendYear,imonth1,imonth2,pic);
}
else
if(years <= 10)
{
pic=2;
totalmonths=MakeXTicks(param,istartYear,iendYear,imonth1,imonth2,pic);
}
else
if(years <= 15)
{
pic=3;
totalmonths=MakeXTicks(param,istartYear,iendYear,imonth1,imonth2,pic);
}
else
if(years <= 35)
{
pic=4;
totalmonths=MakeXTicks(param,istartYear,iendYear,imonth1,imonth2,pic);
}
else
if(years <= 50)
{
pic = 5;
totalmonths=MakeXTicks(param,istartYear,iendYear,imonth1,imonth2,pic);
}
else
if(years <= 100)
{
pic = 6;
totalmonths=MakeXTicks(param,istartYear,iendYear,imonth1,imonth2,pic);
}
else
if(years <= 300)
{
pic = 7;
totalmonths=MakeXTicks(param,istartYear,iendYear,imonth1,imonth2,pic);
}
else
{
pic = 8;
totalmonths=MakeXTicks(param,istartYear,iendYear,imonth1,imonth2,pic);
}
fprintf(param,"world xmin 0\n");
fprintf(param, "world xmax %d\n",totalmonths-1);
/* Remove dots at data points on graph if number of years being graphed is greater than 5 */
if(years > 5)
fprintf(param,"s0 symbol 0\ns1 symbol 0\n");
}
fclose(param);
}
/*----------------------------- CountHits --------------------------------*/
void CountHits(int graph)
{
FILE *users, *fmonth, *hits;
char *agent,*host,*addr,timestring[30],newmon[8],mon[8];
char *infopath="/WWW/oracle-web/cgi-bin/climvis/ghcn/info";
char path[120],junk1[10],junk2[10],day[4],mailhits[75];
int hitcount,year,call;
struct tm *ptr;
time_t lt;
lt = time(NULL);
ptr = localtime(<);
/* Get user information
sprintf(agent, "%s",getenv("HTTP_USER_AGENT"));
sprintf(host, "%s",getenv("REMOTE_HOST"));
sprintf(addr, "%s",getenv("REMOTE_ADDR")); */
agent = getenv("HTTP_USER_AGENT");
if(agent == NULL)
{
agent = "UNKNOWN_AGENT";
}
host = getenv("REMOTE_HOST");
if(host == NULL)
{
host = "UNKNOWN_HOST";
}
addr = getenv("REMOTE_ADDR");
if(addr == NULL)
{
addr = "UNKNOWN_ADDR";
}
sprintf(timestring,asctime(ptr));
/* Get rid of the \n at the end of this string */
timestring[24]='\0';
sscanf(timestring, "%s %s %s %s %d",day,newmon,junk1,junk2,&year);
/* Prepare a call to the system to mail the hits to interested parties if it's the end of the month */
sprintf(path,"/WWW/oracle-web/cgi-bin/climvis/ghcn/info/monthV2");
fmonth=fopen(path,"r");
fflush(fmonth);
if(fmonth == NULL)
{
fmonth=fopen(path,"w");
if(fmonth == NULL)
CARDSFileFailure(path);
fflush(fmonth);
fprintf(fmonth,"%s",newmon);
fclose(fmonth);
strcpy(mon,newmon);
}
else
{
fscanf(fmonth,"%s",mon);
fclose(fmonth);
}
/* Set up path to user info file and write new month if there is one
to write */
if(strcmp(newmon,mon) == 0)
{
sprintf(path,"%s/%s.v2.users",infopath,mon);
}
else
{
sprintf(path,"%s/%s.v2.users",infopath,newmon);
fmonth=fopen("/WWW/oracle-web/cgi-bin/climvis/ghcn/info/monthV2","w");
if(fmonth == NULL)
CARDSFileFailure(path);
fflush(fmonth);
fprintf(fmonth,"%s \n",newmon);
fclose(fmonth);
}
/* if the users file exists for this month, append to it. Othewise start a new one and write to it. */
users=fopen(path,"a");
if(users==NULL)
users=fopen(path,"w");
if(users==NULL)
CARDSFileFailure(path);
fflush(users);
fprintf(users, "%s\nagent: %s\nhost: %s at %s\n\n",timestring,agent,host,addr);
fclose(users);
/* depending which graph was created, write the appropriate */
switch(graph)
{
case 1:
{
if(strcmp(newmon,mon) == 0)
{
sprintf(path,"%s/%s.v2.1.hits",infopath,mon);
}
else
{
sprintf(path,"%s/%s.v2.1.hits",infopath,newmon);
fmonth=fopen("/WWW/oracle-web/cgi-bin/climvis/ghcn/info/monthV2","w");
if(fmonth==NULL)
CARDSFileFailure("/WWW/oracle-web/cgi-bin/climvis/ghcn/info/monthV2");
fflush(fmonth);
fprintf(fmonth,"%s \n",newmon);
fclose(fmonth);
}
hits=fopen(path,"r");
if(hits==NULL)
{
hits=fopen(path,"w");
if(hits==NULL)
CARDSFileFailure(path);
fflush(hits);
fprintf(hits,"1\n");
fclose(hits);
}
else
{
fflush(hits);
fscanf(hits,"%d",&hitcount);
fclose(hits);
hits=fopen(path,"w");
if(hits==NULL)
CARDSFileFailure(path);
fflush(hits);
fprintf(hits,"%d",++hitcount);
fclose(hits);
}
break;
}
case 2:
{
if(strcmp(newmon,mon) == 0)
{
sprintf(path,"%s/%s.v2.2.hits",infopath,mon);
}
else
{
sprintf(path,"%s/%s.v2.2.hits",infopath,newmon);
fmonth=fopen("/WWW/oracle-web/cgi-bin/climvis/ghcn/info/monthV2","w");
if(fmonth==NULL)
CARDSFileFailure("/WWW/oracle-web/cgi-bin/climvis/ghcn/info/monthV2");
fflush(fmonth);
fprintf(fmonth,"%s \n",newmon);
fclose(fmonth);
}
hits=fopen(path,"r");
if(hits==NULL)
{
hits=fopen(path,"w");
if(hits==NULL)
CARDSFileFailure(path);
fflush(hits);
fprintf(hits,"1\n");
fclose(hits);
}
else
{
fflush(hits);
fscanf(hits,"%d",&hitcount);
fclose(hits);
hits=fopen(path,"w");
if(hits==NULL)
CARDSFileFailure(path);
fflush(hits);
fprintf(hits,"%d",++hitcount);
fclose(hits);
}
break;
}
case 3:
{
if(strcmp(newmon,mon) == 0)
{
sprintf(path,"%s/%s.v2.3.hits",infopath,mon);
}
else
{
sprintf(path,"%s/%s.v2.3.hits",infopath,newmon);
fmonth=fopen("/WWW/oracle-web/cgi-bin/climvis/ghcn/info/monthV2","w");
if(fmonth==NULL)
CARDSFileFailure("/WWW/oracle-web/cgi-bin/climvis/ghcn/info/monthV2");
fflush(fmonth);
fprintf(fmonth,"%s \n",newmon);
fclose(fmonth);
}
hits=fopen(path,"r");
if(hits==NULL)
{
hits=fopen(path,"w");
if(hits==NULL)
CARDSFileFailure(path);
fflush(hits);
fprintf(hits,"1\n");
fclose(hits);
}
else
{
fflush(hits);
fscanf(hits,"%d",&hitcount);
fclose(hits);
hits=fopen(path,"w");
if(hits==NULL)
CARDSFileFailure(path);
fflush(hits);
fprintf(hits,"%d",++hitcount);
fclose(hits);
}
break;
}
case 4:
{
if(strcmp(newmon,mon) == 0)
{
sprintf(path,"%s/%s.v2.4.hits",infopath,mon);
}
else
{
sprintf(path,"%s/%s.v2.4.hits",infopath,newmon);
fmonth=fopen("/WWW/oracle-web/cgi-bin/climvis/ghcn/info/monthV2","w");
if(fmonth==NULL)
CARDSFileFailure("/WWW/oracle-web/cgi-bin/climvis/ghcn/info/monthV2");
fflush(fmonth);
fprintf(fmonth,"%s \n",newmon);
fclose(fmonth);
}
hits=fopen(path,"r");
if(hits==NULL)
{
hits=fopen(path,"w");
if(hits==NULL)
CARDSFileFailure(path);
fflush(hits);
fprintf(hits,"1\n");
fclose(hits);
}
else
{
fflush(hits);
fscanf(hits,"%d",&hitcount);
fclose(hits);
hits=fopen(path,"w");
if(hits==NULL)
CARDSFileFailure(path);
fflush(hits);
fprintf(hits,"%d",++hitcount);
fclose(hits);
}
}
break;
}
if(strcmp(newmon,mon) == 0)
{
sprintf(path,"%s/%s.v2.hits",infopath,mon);
}
else
{
sprintf(path,"%s/%s.v2.hits",infopath,mon);
hits=fopen(path,"r");
if(hits==NULL)
CARDSFileFailure(path);
fflush(hits);
fscanf(hits,"%d",&hitcount);
fclose(hits);
sprintf(mailhits,"/WWW/oracle-web/cgi-bin/climvis/ghcn/ghcn.mailhits.sh %d %s %d V2",year,mon,hitcount);
/* Mail info on hits*/
call=system(mailhits);
if(call != 0)
CARDSFileFailure(mailhits);
sprintf(path,"%s/%s.v2.hits",infopath,newmon);
fmonth=fopen("/WWW/oracle-web/cgi-bin/climvis/ghcn/info/monthV2","w");
if(fmonth==NULL)
CARDSFileFailure("/WWW/oracle-web/cgi-bin/climvis/ghcn/info/monthV2");
fflush(fmonth);
fprintf(fmonth,"%s \n",newmon);
fclose(fmonth);
}
hits=fopen(path,"r");
if(hits==NULL)
{
hits=fopen(path,"w");
if(hits==NULL)
CARDSFileFailure(path);
fflush(hits);
fprintf(hits,"1\n");
fclose(hits);
}
else
{
fflush(hits);
fscanf(hits,"%d",&hitcount);
fclose(hits);
hits=fopen(path,"w");
if(hits==NULL)
CARDSFileFailure(path);
fflush(hits);
fprintf(hits,"%d",++hitcount);
fclose(hits);
}
}
/******************************* CGI DECODING FUNCITONS **********************/
#define LF 10
#define CR 13
void getword(char *word, char *line, char stop) {
int x = 0,y;
for(x=0;((line[x]) && (line[x] != stop));x++)
word[x] = line[x];
word[x] = '\0';
if(line[x]) ++x;
y=0;
while(line[y++] = line[x++]);
}
char *makeword(char *line, char stop) {
int x = 0,y;
char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1));
for(x=0;((line[x]) && (line[x] != stop));x++)
word[x] = line[x];
word[x] = '\0';
if(line[x]) ++x;
y=0;
while(line[y++] = line[x++]);
return word;
}
char *fmakeword(FILE *f, char stop, int *cl) {
int wsize;
char *word;
int ll;
wsize = 102400;
ll=0;
word = (char *) malloc(sizeof(char) * (wsize + 1));
while(1) {
word[ll] = (char)fgetc(f);
if(ll==wsize) {
word[ll+1] = '\0';
wsize+=102400;
word = (char *)realloc(word,sizeof(char)*(wsize+1));
}
--(*cl);
if((word[ll] == stop) || (feof(f)) || (!(*cl))) {
if(word[ll] != stop) ll++;
word[ll] = '\0';
return word;
}
++ll;
}
}
char x2c(char *what) {
register char digit;
digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
digit *= 16;
digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
return(digit);
}
void unescape_url(char *url) {
register int x,y;
for(x=0,y=0;url[y];++x,++y) {
if((url[x] = url[y]) == '%') {
url[x] = x2c(&url[y+1]);
y+=2;
}
}
url[x] = '\0';
}
void plustospace(char *str) {
register int x;
for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' ';
}
int rind(char *s, char c) {
register int x;
for(x=strlen(s) - 1;x != -1; x--)
if(s[x] == c) return x;
return -1;
}
int getline(char *s, int n, FILE *f) {
register int i=0;
while(1) {
s[i] = (char)fgetc(f);
if(s[i] == CR)
s[i] = fgetc(f);
if((s[i] == 0x4) || (s[i] == LF) || (i == (n-1))) {
s[i] = '\0';
return (feof(f) ? 1 : 0);
}
++i;
}
}
void send_fd(FILE *f, FILE *fd)
{
int num_chars=0;
char c;
while (1) {
c = fgetc(f);
if(feof(f))
return;
fputc(c,fd);
}
}