#include #include #include #include #include "sqlca.h" #include /* A preprocessor definition of the maximum number of arguments this program will except from the browser. This constant is used to set up an array of structures that will hold the decoded arguments. There will never be more than 20 arguments passed into tempV2.ghcncgi. (See the switch statements in function "main.") */ #define MAX_ENTRIES 30 /*structure for storing CGI arguments */ typedef struct {char *name; char *val; }entry; /* Define constants for string lengths. */ #define UNAME_LEN 20 #define PWD_LEN 40 #define MAX_LEN 50 #define NUMBER_LEN 10 /* Define a host structure for the output values of query of station metadata. */ struct region_data { char region[MAX_LEN]; char country_name[MAX_LEN]; }; struct meta_data { char restricted; char region[MAX_LEN]; char country_name[MAX_LEN]; char station_name[MAX_LEN]; char wmo_no[NUMBER_LEN]; char latitude[NUMBER_LEN]; char longitude[NUMBER_LEN]; int country_code; int start_year; int end_year; }; /* Define an indicator struct to correspond to the output for station metadata queries. */ struct meta_data_ind { short restricted_ind; short region_ind; short country_name_ind; short wmo_no_ind; short station_name_ind; short latitude_ind; short longitude_ind; short country_code_ind; short start_year_ind; short end_year_ind; }; /* struct data_year { int country_code; int wmo_no; int current_year; int jan; int feb; int mar; int apr; int may; int jun; int jul; int aug; int sep; int oct; int nov; int dec; }; */ struct data_year { int wmo_no; int current_year; int pres_lvl; int lvl_type; int hr_group; int jan; int feb; int mar; int apr; int may; int jun; int jul; int aug; int sep; int oct; int nov; int dec; }; struct data_month { char wmo_no[10]; int current_year; int data; }; /* Function prototypes for the decoding functions. These functions are in the "util.c" file and are responsible for actually decoding the arguments passed into tempV2.ghcncgi from the browser. */ char *makeword(char *line, char stop); char *fmakeword(FILE *f, char stop, int *cl); char x2c(char *what); void unescape_url(char *url); void plustospace(char *str); void showError(char *path); /* Prototypes for functions used by the CGI to perform different tasks. */ /* A debugging funtion. Use this to write information to a file when the CGI is fouled up. The "string" argument is the infor to be written to the file "filename" at "path" location. The mode argument is a single character either 'a' or 'w' for "append" or "write over" mode.*/ void writeTestInfo(char* path, char* filename, char *string, char mode); /*------------------------------- ParamName ------------------------------- A simple function that returns the full name of a parameter. e.g. - the name from "max" becomes "Maximum." */ char* ParamName(char *sname); /*--------------------------- CARDSFileFailure ------------------------------ This function prints an error message to the browser if one of the files tempV2.ghcncgi tries to access cannot be opened. The full path to the offending file is displayed as part of the message. It also gives the user an immediate opportunity to contact the webmaster by e-mail. */ void CARDSFileFailure(char *path); /*------------------------------- CheckDates ------------------------------- "CheckDates" verifys that the user has not entered year and month information that is either not reasonable or outside the range of all recorded data. */ void CheckDates(int graph, int start, int end, int startData1, int startData2); /*------------------------------ RemoveSpaces ------------------------------- "RemoveSpaces" removes all extra spaces from the end of a character string. */ void RemoveSpaces(char *string); /*--------------------------- PrintMonthOptions ---------------------------- "PrintMonthOption" writes to stdout (the browser) an html select list of months with their corresponding numerical calendar numbers as return values. The argument "choice" is used to decided whether or not the optiong "all months" will be included in the list. This feature allows the user to select a certain month over a period of years, or all months available over a period of years. */ void PrintMonthOptions(int choice, int Dec); /*----------------------------- PrintLatLong ------------------------------- "PrintLatLong" appends the letters N(orth) or S(outh) to the latitude passed to it as well as E(ast) or W(est) to the longitude while removing the minus sign in front of each if necessary. (Negative latitudes and longitudes represent "South" and "West" respectively.) The resulting numbers with their appropriate letters appended are then written to a string and copied over the string passed as an argument by the calling function. This function is used to print the location of a given station to the station select window as well as to the final graph itself. */ void PrintLatLong(float Lat, float Long, char *string); /*--------------------------------- 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); /*----------------------------- 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); /*----------------------------- MakeXTicks --------------------------------- "MakeXTicks" is responsible for writing to the XMGR parameter file the tick specifications necessary for creating graphs of type 3 or 4. (The "time series" or "period of record" graphs.) "MakeXTicks" returns the total number of months that will be included in the graph. This is written to the parameter file as the "XMax" parameter. */ int MakeXTicks(FILE *param,int startyear,int endyear,int month, int month2, int pic); /*----------------------------- MakeYTicks --------------------------------- "MakeYTicks" is a function for setting the tick spacing on the y-axis. The highest and lowest values obtained from the data set constructed is broken down into its respective tenths, ones, tens, and hundreds. These values are used to create 10 evenly spaced major Y-ticks and five evenly spaced minor Y-ticks. The maximum valuon the graph is always a little higher than the highest value while the minimum is always a little lower than the lowest value. This arrangement keeps the graphs all looking similar to one another, no matter which units or type of data is graphed. */ void MakeYTicks(int iunits, int ihighest, int ilowest, FILE *param); /*----------------------------- 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 local, 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); /*----------------------------- CountHits --------------------------------- This function simply updates the hit counters found in /WWW/httpd/cgi-bin/info. There is a separate counter for each type of graph, as well as a total counter. These files are automatically updated and hold only a single integer each. A file is also present showing the host name, host address, and browser type for each hit. (File is named .v2.users) Each time a new month comes around, the last months total hits are mailed to intereseted parties via the script "ghcn.mailhits.sh".*/ void CountHits(int graph); /*----------------------------- ShowError ---------------------------------- A generalized error message that can be used to output errors to as HTML. When errors occur opening files, use CARDSFileFailure() instead. */ void showError(char *message); /*----------------------------- getPaths ------------------------------------ This function reads into the program the paths to the CGI itself, and the path to the temporary files that are created. The file storing this path information must currently be located at /WWW/oracle-web/cgi-bin/climvis/ghcn/paths. This file must be at least readable by user "nobody" and must contain first the ful path to the ghcn temporary area (where pictures and text files will be created for viewing) followed by white space and the full path the the CGI itself. */ void getPaths(char *temporary, char *cgi_root); /*----------------------------- getOracleAccess ------------------------------- This function reads in the username and password combination from the file called "access" in the cgi_root directory. (See "getPaths" info above for information about the cgi_root directory.) The user name and password must be all one word separated by a single slash (e.g. scott/tiger) */ void getOracleAccess(char *path, char *info); void RegionIsValid(char *region); int GetData(int index, struct data_year *data);