/*----------------------------------------------------------------------*\ | Program to extract GEOMET data. This is the user interface for X11 | | | | Peter N. Schweitzer (U.S. Geological Survey, Reston, VA 22092) | \*----------------------------------------------------------------------*/ #include #include #include #include #include "cvtdate.h" #include #include #include #include #include #include #include #include #include #include #include #include extern void extract_geomet_data (char *station_code, struct tm *begin_tm, struct tm *end_tm, char **selected_item, int number_selected, char *data_path, char *output_file, char *format_name, int warn_missing); #define min(a,b) (((a) < (b)) ? (a) : (b)) #define max(a,b) (((a) > (b)) ? (a) : (b)) /*----------------------------------------------------------------------*\ | Application resources | \*----------------------------------------------------------------------*/ typedef struct { Boolean autoHighlight; Boolean selectAll; Boolean warnMissing; String stationName; String beginDate; String beginTime; String endDate; String endTime; String outputFile; String outputFormat; String helpFile; String infoFile; String dataPath; } AppData, *AppDataPtr; #define XtNautoHighlight "autoHighlight" #define XtCAutoHighlight "AutoHighlight" #define XtNselectAll "selectAll" #define XtCSelectAll "SelectAll" #define XtNwarnMissing "warnMissing" #define XtCWarnMissing "WarnMissing" #define XtNstationName "stationName" #define XtCStationName "StationName" #define XtNbeginDate "beginDate" #define XtCBeginDate "BeginDate" #define XtNbeginTime "beginTime" #define XtCBeginTime "BeginTime" #define XtNendDate "endDate" #define XtCEndDate "EndDate" #define XtNendTime "endTime" #define XtCEndTime "EndTime" #define XtNoutputFile "outputFile" #define XtCOutputFile "OutputFile" #define XtNoutputFormat "outputFormat" #define XtCOutputFormat "OutputFormat" #define XtNhelpFile "helpFile" #define XtCHelpFile "HelpFile" #define XtNinfoFile "infoFile" #define XtCInfoFile "InfoFile" #define XtNdataPath "dataPath" #define XtCDataPath "DataPath" static XtResource resources[] = { {XtNautoHighlight, XtCAutoHighlight, XtRBoolean, sizeof(Boolean), XtOffset(AppDataPtr,autoHighlight), XtRImmediate, (XtPointer) FALSE}, {XtNselectAll, XtCSelectAll, XtRBoolean, sizeof(Boolean), XtOffset(AppDataPtr,selectAll), XtRImmediate, (XtPointer) FALSE}, {XtNwarnMissing, XtCWarnMissing, XtRBoolean, sizeof(Boolean), XtOffset(AppDataPtr,selectAll), XtRImmediate, (XtPointer) FALSE}, {XtNstationName, XtCStationName, XtRString, sizeof(String), XtOffset(AppDataPtr,stationName), XtRImmediate, (XtPointer) "Gold Spring"}, {XtNbeginDate, XtCBeginDate, XtRString, sizeof(String), XtOffset(AppDataPtr,beginDate), XtRImmediate, (XtPointer) ""}, {XtNbeginTime, XtCBeginTime, XtRString, sizeof(String), XtOffset(AppDataPtr,beginTime), XtRImmediate, (XtPointer) ""}, {XtNendDate, XtCEndDate, XtRString, sizeof(String), XtOffset(AppDataPtr,endDate), XtRImmediate, (XtPointer) ""}, {XtNendTime, XtCEndTime, XtRString, sizeof(String), XtOffset(AppDataPtr,endTime), XtRImmediate, (XtPointer) ""}, {XtNoutputFile, XtCOutputFile, XtRString, sizeof(String), XtOffset(AppDataPtr,outputFile), XtRImmediate, (XtPointer) "geomet.dat"}, {XtNoutputFormat, XtCOutputFormat, XtRString, sizeof(String), XtOffset(AppDataPtr,outputFormat), XtRImmediate, (XtPointer) "Tab-delimited ASCII"}, {XtNhelpFile, XtCHelpFile, XtRString, sizeof(String), XtOffset(AppDataPtr,helpFile), XtRImmediate, (XtPointer) "geomet.hlp"}, {XtNinfoFile, XtCInfoFile, XtRString, sizeof(String), XtOffset(AppDataPtr,infoFile), XtRImmediate, (XtPointer) "geomet.txt"}, {XtNdataPath, XtCDataPath, XtRString, sizeof(String), XtOffset(AppDataPtr,dataPath), XtRImmediate, (XtPointer) "/pdd/cdrom"} }; /*----------------------------------------------------------------------*\ \*----------------------------------------------------------------------*/ #define DEFAULT_OUTPUT_FILE "geomet.dat" #define DEFAULT_OUTPUT_FORMAT 0 static char *station_name [] = { "Gold Spring", "Desert Wells", "Yuma", "Owens Lake", "Jornada", NULL }; static int station_count = 5; static int station = 0; static char *station_code[] = { "gs","dw","yu","ol","jo" }; #define ITEM_COUNT 14 static char *available_item [ITEM_COUNT] = { "wind speed at 6.1m", "wind speed at 2.7m", "wind speed at 1.2m", "peak gust at 6.1m", "peak gust at 1.2m", "wind direction", "precipitation", "air temperature at 6.1m", "air temperature at 1.2m", "humidity", "barometric pressure", "soil temperature at 4cm", "soil temperature at 10cm", "soil temperature at 20cm" }; static int number_available = ITEM_COUNT; static char *selected_item [1 + ITEM_COUNT] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; static int number_selected = 0; static int auto_highlight = 0; static char data_path [FILENAME_MAX]; static char begin_date_string[12]; static char begin_time_string[6]; static struct tm *begin_tm; static char end_date_string[12]; static char end_time_string[6]; static struct tm *end_tm; static char output_file [FILENAME_MAX]; static char *output_format_name[] = { "Tab-delimited ASCII", "Comma-delimited ASCII", "Desert Winds project", "WKS (Lotus 123)", NULL }; static int output_format_count = 4; static int output_format = 0; static char *help_message = NULL; static long help_message_length = 0; static char **info_list = NULL; static int warn_missing = 0; /*----------------------------------------------------------------------*\ \*----------------------------------------------------------------------*/ static void station_chosen (Widget w, XtPointer client_data, XtPointer call_data) { Widget p; station = (int) client_data; p = XtParent (w); p = XtParent (p); XtVaSetValues (p,XtNlabel,station_name[station],NULL); } /*----------------------------------------------------------------------*\ \*----------------------------------------------------------------------*/ static Widget available_list,selected_list; static void available_list_callback (Widget w, XtPointer client_data, XtPointer call_data) { if (!auto_highlight) XawListUnhighlight (selected_list); } static void selected_list_callback (Widget w, XtPointer client_data, XtPointer call_data) { if (!auto_highlight) XawListUnhighlight (available_list); } static void add_item (Widget w, XtPointer client_data, XtPointer call_data) { int i; XawListReturnStruct *item; item = XawListShowCurrent (available_list); if (item->list_index != XAW_LIST_NONE) { /*--------------------------------------------------------------*\ | Check to determine whether this item is already in the list. | | If it is, just return, don't add it again. | \*--------------------------------------------------------------*/ for (i=0; i < number_selected; i++) if (selected_item[i] == item->string) return; /*--------------------------------------------------------------*\ | Add this item to the list if there is room in the list. | \*--------------------------------------------------------------*/ if (number_selected < number_available) { selected_item [number_selected] = available_item [item->list_index]; number_selected++; XawListChange (selected_list,selected_item,number_selected,0,True); if (auto_highlight) { XawListHighlight (selected_list,number_selected-1); /*------------------------------------------------------*\ | Highlight the next list element if there is one. | \*------------------------------------------------------*/ if (item->list_index < number_available - 1) XawListHighlight (available_list,item->list_index+1); } else { XawListUnhighlight (available_list); } } } } static void add_all_items (Widget w, XtPointer client_data, XtPointer call_data) { int i; for (i=0; i < number_available; i++) selected_item[i] = available_item[i]; number_selected = number_available; XawListChange (selected_list,selected_item,number_selected,0,True); if (auto_highlight) { XawListHighlight (selected_list,number_selected-1); } else { XawListUnhighlight (available_list); } } static void remove_all_items (Widget w, XtPointer client_data, XtPointer call_data) { int i; for (i=0; i < number_available; i++) selected_item[i] = NULL; number_selected = 0; XawListChange (selected_list,selected_item,number_selected,0,True); } static void remove_item (Widget w, XtPointer client_data, XtPointer call_data) { int i; XawListReturnStruct *item; item = XawListShowCurrent (selected_list); if (item->list_index != XAW_LIST_NONE) { if (number_selected > 0) { selected_item [item->list_index] = NULL; for (i=item->list_index; i < number_selected; i++) selected_item[i] = selected_item[i+1]; number_selected--; XawListChange (selected_list,selected_item,number_selected,0,True); if (auto_highlight) { /*------------------------------------------------------*\ | Highlight the previous list element if there is one. | \*------------------------------------------------------*/ if (item->list_index > 0) XawListHighlight (selected_list,item->list_index-1); } } } } /*----------------------------------------------------------------------*\ \*----------------------------------------------------------------------*/ static void output_format_chosen (Widget w, XtPointer client_data, XtPointer call_data) { Widget p; output_format = (int) client_data; p = XtParent (w); p = XtParent (p); XtVaSetValues (p,XtNlabel,output_format_name[output_format],NULL); } /*----------------------------------------------------------------------*\ | Info dialog actions. | \*----------------------------------------------------------------------*/ static Widget topLevel,pshell,info_text; static void show_info (char *label) { Position x,y; Dimension width,height; XtVaSetValues ( info_text, XtNlabel,label, NULL); XtVaGetValues ( topLevel, XtNwidth,&width, XtNheight,&height, NULL); XtTranslateCoords ( topLevel, (Position) width/2, (Position) height/2, &x,&y); XtVaSetValues ( pshell, XtNx,x, XtNy,y, NULL); XtPopup (pshell,XtGrabNone); } static void info_done (Widget w, XtPointer client_data, XtPointer call_data) { XtPopdown (pshell); } static void get_info (Widget w, XtPointer client_data, XtPointer call_data) { XawListReturnStruct *item; item = XawListShowCurrent (available_list); if (item->list_index != XAW_LIST_NONE) show_info (info_list[item->list_index]); } static void help (Widget w, XtPointer client_data, XtPointer call_data) { show_info ((char *) client_data); } /*----------------------------------------------------------------------*\ | Confirm dialog actions. | \*----------------------------------------------------------------------*/ static Widget confirm_shell, confirm_text; static char *confirm_label = NULL; static size_t confirm_label_length = 0; static void show_confirm (void) { Position x,y; Dimension width,height; XtVaSetValues ( confirm_text, XtNlabel,confirm_label, NULL); XtVaGetValues ( topLevel, XtNwidth,&width, XtNheight,&height, NULL); XtTranslateCoords ( topLevel, (Position) width/2, (Position) height/2, &x,&y); XtVaSetValues ( confirm_shell, XtNx,x, XtNy,y, NULL); XtPopup (confirm_shell,XtGrabNonexclusive); } static void confirm_done (Widget w, XtPointer client_data, XtPointer call_data) { XtPopdown (confirm_shell); if (confirm_label) free (confirm_label); confirm_label = NULL; confirm_label_length = 0; extract_geomet_data ( station_code [station], begin_tm, end_tm, selected_item, number_selected, data_path, output_file, output_format_name[output_format], warn_missing ); fprintf (stderr,"USGS GEOMET data extracted\n"); } static void cancel_done (Widget w, XtPointer client_data, XtPointer call_data) { XtPopdown (confirm_shell); if (confirm_label) free (confirm_label); confirm_label = NULL; confirm_label_length = 0; fprintf (stderr,"USGS GEOMET data not extracted\n"); } static int add_string (char *string) { int m,n; size_t size; if (confirm_label) m = strlen (confirm_label); else { size = 4096; if (confirm_label = (char *) malloc (4096L)) confirm_label_length = size; m = 0; } n = strlen (string); if (n + m + 1 > confirm_label_length) { size = confirm_label_length + 4096; confirm_label = (char *) realloc (confirm_label,size); if (confirm_label == NULL) return (0); else confirm_label_length += 4096; } strcat (confirm_label + m, string); return (1); } static unsigned long output_size (long n) { unsigned long size = 0L; switch (output_format) { case 0: case 1: size = n * (number_selected * 8 + 11); break; case 2: size = (n + 3) * 116; break; case 3: size = 6 + /* BOF */ number_selected * (24 + 11) + /* labels */ n * number_selected * 17 + /* numbers */ 4; /* EOF */ break; default: size = n * number_selected * 8; break; } return (size); } static void extract (Widget w, XtPointer client_data, XtPointer call_data) { int i; char string[128]; time_t tb,te; double duration; long n; FILE *in; sprintf (string,"DESCRIPTION OF REQUESTED OUTPUT\n\n"); add_string (string); sprintf (string," GEOMET station name: %s\n\n",station_name[station]); add_string (string); add_string (" Selected sensors:\n"); for (i=0; i < number_selected; i++) { sprintf (string," %s\n",selected_item[i]); add_string (string); } add_string ("\n"); begin_tm = get_tm (begin_date_string,begin_time_string); end_tm = get_tm (end_date_string, end_time_string); sprintf (string," Beginning %s",asctime(begin_tm)); add_string (string); sprintf (string," Ending %s",asctime(end_tm)); add_string (string); tb = mktime (begin_tm); te = mktime (end_tm); duration = difftime (te,tb); n = (long) (duration/360.0); if (n <= 0) add_string ("Warning: beginning time follows ending time\n"); sprintf (string," Output file name: %s\n",output_file); add_string (string); sprintf (string," Output file format: %s\n",output_format_name[output_format]); add_string (string); sprintf (string," Estimated file size: %.1lfk\n",((double)output_size(n))/1024.0); add_string (string); if (in = fopen (output_file,"rb")) { fclose (in); sprintf (string," WARNING: OUTPUT FILE ALREADY EXISTS\n"); add_string (string); sprintf (string," PRESS OK TO WRITE OVER IT\n"); add_string (string); sprintf (string," PRESS CANCEL TO PRESERVE IT\n"); add_string (string); } show_confirm (); } /*----------------------------------------------------------------------*\ \*----------------------------------------------------------------------*/ static void quit (Widget w, XtPointer client_data, XtPointer call_data) { fprintf (stderr,"Thank you for using USGS GEOMET data.\n"); exit (0); } /*----------------------------------------------------------------------*\ \*----------------------------------------------------------------------*/ static char **parse_info (char *buffer) { int i,j,k,m,n; char **heading,**value,**list; char **h,**L; char *b,*e,*s,*t; char *next; int tab_count,line_count,head_count,value_count; /*------------------------------------------------------------------*\ | Count tabs in each line to determine the maximum number of tabs | | on any one line. Allocate for each pointer array one more | | pointer than this number . | \*------------------------------------------------------------------*/ tab_count = 0; line_count = 0; k = 0; for (s=buffer; *s; s++) { if (*s == '\t') k++; if (*s == '\n') { line_count++; if (k > tab_count) tab_count = k; k = 0; } } if (k > tab_count) tab_count = k; tab_count++; line_count++; if (list = (char **) malloc (line_count*sizeof(char *))) memset (list,0,line_count*sizeof(char*)); else { fprintf (stderr,"Error: could not allocate space for %d list pointers\n",line_count); return (NULL); } if (heading = (char **) malloc (tab_count*sizeof(char *))) memset (list,0,line_count*sizeof(char*)); else { fprintf (stderr,"Error: could not allocate space for %d heading pointers\n",tab_count); free (list); return (NULL); } if (value = (char **) malloc (tab_count*sizeof(char *))) memset (list,0,line_count*sizeof(char*)); else { fprintf (stderr,"Error: could not allocate space for %d value pointers\n",tab_count); free (list); free (heading); return (NULL); } /*------------------------------------------------------------------*\ | Parse the first line, storing addresses of tab-delimited labels | | in the array heading, and the number of labels in head_count. | \*------------------------------------------------------------------*/ if (s = strchr (buffer,'\n')) *s++ = 0; h = heading; b = buffer; while (*b) { e = b; while (*e && *e != '\t') e++; *h++ = b; b = e; if (*e) b++; *e = 0; } head_count = h - heading; b++; /*------------------------------------------------------------------*\ | Find the length of the longest heading (add one space for colon) | \*------------------------------------------------------------------*/ m = 0; for (i=0; i < head_count; i++) if ((n = 1 + strlen (heading[i])) > m) m = n; m++; /* add one more space for aesthetics */ /*------------------------------------------------------------------*\ | Each succeeding line is a record, whose report should be pointed | | to by an element of list. | \*------------------------------------------------------------------*/ L = list; next = b+1; while (*next) { /*--------------------------------------------------------------*\ | Locate the end of the current line, and point next to its | | first character. If this is the last line, next points to | | the NUL at the end. | \*--------------------------------------------------------------*/ if (next = strchr (next,'\n')) *next++ = 0; else next = b + strlen (b); /*--------------------------------------------------------------*\ | Parse the current line, storing pointers to the tab-delimited| | values in the array values, and the number in value_count. | | At the end, b points to the first character of the next line | \*--------------------------------------------------------------*/ h = value; while (*b) { e = b; while (*e && *e != '\t') e++; *h++ = b; b = e; if (*e) b++; *e = 0; } if (h == value) return (NULL); value_count = h - value; b++; /*--------------------------------------------------------------*\ | Compose a report for the current line, consisting of the | | heading, a colon, spaces sufficient to line up the values, | | and the value. If there is no value, just add a newline. | | If there is no heading, fill with spaces. | | | | The report is allocated dynamically. Its length is obtained | | by adding the lengths of all of the headings to the lengths | | of all the values, plus one for the terminating NUL. | \*--------------------------------------------------------------*/ k = max (head_count,value_count); n = k * m; for (i=0; i < value_count; i++) n += strlen (value[i]) + 1; if (*L = (char *) malloc (1+n)) { t = *L; for (i=0; i < k; i++) { if (i < head_count) { strcpy (t,heading[i]); strcat (t,":"); } else *t = 0; j = strlen (t); while (j < m) t[j++] = ' '; t += j; if (i < value_count) { strcpy (t,value[i]); t += strlen (value[i]); } *t++ = '\n'; *t = 0; } L++; *L = NULL; } } free (heading); free (value); return (list); } /*----------------------------------------------------------------------*\ \*----------------------------------------------------------------------*/ #ifndef HAVE_STRICMP int stricmp (char *s, char *t) { int d = toupper (*s) - toupper(*t); while (*s && *t && !d) d = toupper(*s++) - toupper(*t++); return (d); } #endif /*----------------------------------------------------------------------*\ \*----------------------------------------------------------------------*/ main (int argc, char **argv) { int i,j,k,n; char string[128]; char *s,*t; FILE *in; XtAppContext app_context; AppData app_data; Widget /* topLevel, */ paned, station_menu_box, station_menu_label, station_menu_button, station_menu, sensor_box, list_box, available_box, available_label, /* available_list, */ selected_box, selected_label, /* selected_list, */ list_button_box, get_info_button, add_button, add_all_button, space_label, remove_button, remove_all_button, time_date_box, time_date_box_label, begin_box, begin_date_box, begin_date_label, begin_date_text, begin_time_box, begin_time_label, begin_time_text, end_box, end_date_box, end_date_label, end_date_text, end_time_box, end_time_label, end_time_text, file_name_box, file_name_label, file_name_text, output_format_menu_box, output_format_menu_label, output_format_menu_button, output_format_menu, main_button_box, help_button, extract_button, quit_button, /* pshell, */ info_box, /* info_text, */ info_button_box, info_button, /* confirm_shell, */ confirm_box, confirm_button_box, confirm_button, cancel_button /* confirm_text */ ; /*------------------------------------------------------------------*\ | Initialize the application and interpret its resources. | \*------------------------------------------------------------------*/ topLevel = XtVaAppInitialize ( &app_context, "Geomet", NULL,0, &argc,argv, NULL, NULL); XtGetApplicationResources ( topLevel, &app_data, resources, XtNumber(resources), NULL, 0); if (app_data.autoHighlight == TRUE) auto_highlight = 1; else auto_highlight = 0; if (app_data.selectAll == TRUE) { for (i=0; i < number_available; i++) selected_item[i] = available_item[i]; number_selected = number_available; } else { for (i=0; i < number_available; i++) selected_item[i] = NULL; number_selected = 0; } if (app_data.warnMissing == TRUE) warn_missing = 1; else warn_missing = 0; for (i=0; i < station_count; i++) if (stricmp (app_data.stationName,station_name[i]) == 0) { station = i; break; } strcpy (begin_date_string,app_data.beginDate); strcpy (begin_time_string,app_data.beginTime); strcpy (end_date_string,app_data.endDate); strcpy (end_time_string,app_data.endTime); strcpy (output_file,app_data.outputFile); for (i=0; i < output_format_count; i++) if (stricmp (app_data.outputFormat,output_format_name[i]) == 0) { output_format = i; break; } if (in = fopen (app_data.helpFile,"rb")) { long len; if (fseek (in,0L,SEEK_END) == 0) { len = ftell (in); rewind (in); if (help_message = (char *) malloc (1+len)) { len = fread (help_message,1,len,in); help_message[len] = 0; help_message_length = len; } else fprintf (stderr,"Error: could not allocate %ld bytes for help text.\n",1+len); } fclose (in); } else fprintf (stderr,"Warning: could not open help file \"%s\"\n",app_data.helpFile); if (in = fopen (app_data.infoFile,"rb")) { long len; char *info_buffer = NULL; if (fseek (in,0L,SEEK_END) == 0) { len = ftell (in); rewind (in); if (info_buffer = (char *) malloc (1+len)) { len = fread (info_buffer,1,len,in); info_buffer[len] = 0; info_list = parse_info (info_buffer); } else fprintf (stderr,"Error: could not allocate %ld bytes for info text.\n",1+len); } fclose (in); } else fprintf (stderr,"Warning: could not open info file \"%s\"\n",app_data.infoFile); strcpy (data_path,app_data.dataPath); /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ paned = XtVaCreateManagedWidget ( "paned", boxWidgetClass, topLevel, XtNorientation,XtorientVertical, NULL); /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ station_menu_box = XtVaCreateManagedWidget ( "station_menu_box", boxWidgetClass, paned, XtNborderWidth,0, XtNorientation,XtorientHorizontal, NULL); t = "GEOMET station name:"; station_menu_label = XtVaCreateManagedWidget ( "station_menu_label", commandWidgetClass, station_menu_box, XtNborderWidth,0, XtNlabel,t, NULL); for (s=help_message; s < help_message + help_message_length; s++) if (*s == '\n') if (memcmp (s+1,t,strlen (t)) == 0) { if (s > help_message) *s = 0; break; } XtAddCallback (station_menu_label,XtNcallback,help,(XtPointer)(s+1)); station_menu_button = XtVaCreateManagedWidget ( "station_menu_button", menuButtonWidgetClass, station_menu_box, XtNlabel,station_name[station], XtNmenuName,"station_menu", NULL); station_menu = XtVaCreatePopupShell ( "station_menu", simpleMenuWidgetClass, station_menu_button, NULL); for (i=0; i < station_count; i++) { char wname[32]; Widget entry; sprintf (wname,"station_name_menu_%d",i); entry = XtVaCreateManagedWidget ( wname, smeBSBObjectClass, station_menu, XtNlabel,station_name[i], NULL); XtAddCallback (entry,XtNcallback,station_chosen,(XtPointer)i); } /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ sensor_box = XtVaCreateManagedWidget ( "sensor_box", boxWidgetClass, paned, XtNorientation,XtorientVertical, NULL); list_box = XtVaCreateManagedWidget ( "list_box", boxWidgetClass, sensor_box, XtNorientation,XtorientHorizontal, XtNborderWidth,0, NULL); available_box = XtVaCreateManagedWidget ( "available_box", boxWidgetClass, list_box, XtNborderWidth,0, NULL); t = "Available sensors:"; available_label = XtVaCreateManagedWidget ( "available_label", commandWidgetClass, available_box, XtNborderWidth,0, XtNlabel,t, NULL); for (s=help_message; s < help_message + help_message_length; s++) if (*s == '\n') if (memcmp (s+1,t,strlen (t)) == 0) { if (s > help_message) *s = 0; break; } XtAddCallback (available_label,XtNcallback,help,(XtPointer)(s+1)); available_list = XtVaCreateManagedWidget ( "available_list", listWidgetClass, available_box, XtNborderWidth,0, XtNdefaultColumns,1, XtNforceColumns,TRUE, NULL); XawListChange (available_list,available_item,number_available,0,True); XtAddCallback (available_list,XtNcallback,available_list_callback,NULL); selected_box = XtVaCreateManagedWidget ( "SelectedBox", boxWidgetClass, list_box, XtNborderWidth,0, NULL); /*------------------------------------------------------------------*\ | Make the label for the list of selected sensors as long as the | | longest item in the list of available sensors. This will not be | | necessary if you initially select all available sensors. But if | | you initially have no sensors selected, the selected list widget | | won't be large enough to hold the longer-named sensors, and only | | action by the window manager will resize the widget. | \*------------------------------------------------------------------*/ t = "Selected sensors:"; strcpy (string,t); k = n = strlen (string); for (i=0; i < number_available; i++) if ((j = strlen (available_item[i])) > n) n = j; n++; while (k < n) string[k++] = ' '; string[n] = 0; selected_label = XtVaCreateManagedWidget ( "SelectedLabel", commandWidgetClass, selected_box, XtNborderWidth,0, XtNlabel,string, NULL); for (s=help_message; s < help_message + help_message_length; s++) if (*s == '\n') if (memcmp (s+1,t,strlen (t)) == 0) { if (s > help_message) *s = 0; break; } XtAddCallback (selected_label,XtNcallback,help,(XtPointer)(s+1)); selected_list = XtVaCreateManagedWidget ( "selected_list", listWidgetClass, selected_box, XtNborderWidth,0, XtNdefaultColumns,1, XtNforceColumns,TRUE, NULL); XawListChange (selected_list,selected_item,number_selected,0,True); XtAddCallback (selected_list,XtNcallback,selected_list_callback,NULL); /*------------------------------------------------------------------*/ list_button_box = XtVaCreateManagedWidget ( "AvailMenuBox", boxWidgetClass, sensor_box, XtNborderWidth,0, XtNorientation,XtorientHorizontal, XtNresize,FALSE, NULL); get_info_button = XtVaCreateManagedWidget ( "get_info_button", commandWidgetClass, list_button_box, XtNlabel,"Get Info", NULL); XtAddCallback (get_info_button,XtNcallback,get_info,NULL); add_button = XtVaCreateManagedWidget ( "add_button", commandWidgetClass, list_button_box, XtNlabel,"Add", NULL); XtAddCallback (add_button,XtNcallback,add_item,NULL); add_all_button = XtVaCreateManagedWidget ( "add_all_button", commandWidgetClass, list_button_box, XtNlabel,"Add All", NULL); XtAddCallback (add_all_button,XtNcallback,add_all_items,NULL); space_label = XtVaCreateManagedWidget ( "space_label", labelWidgetClass, list_button_box, XtNborderWidth,0, XtNlabel," ", NULL); remove_button = XtVaCreateManagedWidget ( "remove_button", commandWidgetClass, list_button_box, XtNlabel,"Remove", NULL); XtAddCallback (remove_button,XtNcallback,remove_item,NULL); remove_all_button = XtVaCreateManagedWidget ( "remove_all_button", commandWidgetClass, list_button_box, XtNlabel,"Remove All", NULL); XtAddCallback (remove_all_button,XtNcallback,remove_all_items,NULL); /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ time_date_box = XtVaCreateManagedWidget ( "time_date_box", boxWidgetClass, paned, XtNorientation,XtorientVertical, NULL); t = "Output information:"; time_date_box_label = XtVaCreateManagedWidget ( "time_date_box_label", commandWidgetClass, time_date_box, XtNborderWidth,0, XtNlabel,t, NULL); for (s=help_message; s < help_message + help_message_length; s++) if (*s == '\n') if (memcmp (s+1,t,strlen (t)) == 0) { if (s > help_message) *s = 0; break; } XtAddCallback (time_date_box_label,XtNcallback,help,(XtPointer)(s+1)); begin_box = XtVaCreateManagedWidget ( "begin_box", boxWidgetClass, time_date_box, XtNorientation,XtorientHorizontal, XtNborderWidth,0, NULL); begin_date_box = XtVaCreateManagedWidget ( "begin_date_box", boxWidgetClass, begin_box, XtNorientation,XtorientHorizontal, XtNborderWidth,0, NULL); begin_date_label = XtVaCreateManagedWidget ( "begin_date_label", labelWidgetClass, begin_date_box, XtNborderWidth,0, XtNlabel,"Beginning date:", NULL); begin_date_text = XtVaCreateManagedWidget ( "begin_date_text", asciiTextWidgetClass, begin_date_box, XtNstring,begin_date_string, XtNuseStringInPlace,TRUE, XtNlength,12, XtNeditType,XawtextEdit, NULL); begin_time_box = XtVaCreateManagedWidget ( "begin_time_box", boxWidgetClass, begin_box, XtNorientation,XtorientHorizontal, XtNborderWidth,0, NULL); begin_time_label = XtVaCreateManagedWidget ( "begin_time_label", labelWidgetClass, begin_time_box, XtNborderWidth,0, XtNlabel,"time:", NULL); begin_time_text = XtVaCreateManagedWidget ( "begin_time_text", asciiTextWidgetClass, begin_time_box, XtNstring,begin_time_string, XtNuseStringInPlace,TRUE, XtNlength,6, XtNeditType,XawtextEdit, NULL); end_box = XtVaCreateManagedWidget ( "end_box", boxWidgetClass, time_date_box, XtNorientation,XtorientHorizontal, XtNborderWidth,0, NULL); end_date_box = XtVaCreateManagedWidget ( "end_date_box", boxWidgetClass, end_box, XtNorientation,XtorientHorizontal, XtNborderWidth,0, NULL); end_date_label = XtVaCreateManagedWidget ( "end_date_label", labelWidgetClass, end_date_box, XtNborderWidth,0, XtNlabel,"Ending date: ", NULL); end_date_text = XtVaCreateManagedWidget ( "end_date_text", asciiTextWidgetClass, end_date_box, XtNstring,end_date_string, XtNuseStringInPlace,TRUE, XtNlength,12, XtNeditType,XawtextEdit, NULL); end_time_box = XtVaCreateManagedWidget ( "end_time_box", boxWidgetClass, end_box, XtNorientation,XtorientHorizontal, XtNborderWidth,0, NULL); end_time_label = XtVaCreateManagedWidget ( "end_time_label", labelWidgetClass, end_time_box, XtNborderWidth,0, XtNlabel,"time:", NULL); end_time_text = XtVaCreateManagedWidget ( "end_time_text", asciiTextWidgetClass, end_time_box, XtNstring,end_time_string, XtNuseStringInPlace,TRUE, XtNlength,6, XtNeditType,XawtextEdit, NULL); file_name_box = XtVaCreateManagedWidget ( "file_name_box", boxWidgetClass, time_date_box, XtNorientation,XtorientHorizontal, XtNborderWidth,0, NULL); file_name_label = XtVaCreateManagedWidget ( "file_name_label", labelWidgetClass, file_name_box, XtNborderWidth,0, XtNlabel,"File name: ", NULL); file_name_text = XtVaCreateManagedWidget ( "file_name_text", asciiTextWidgetClass, file_name_box, XtNstring,output_file, XtNuseStringInPlace,TRUE, XtNlength,FILENAME_MAX, XtNeditType,XawtextEdit, XtNresize,XawtextResizeWidth, NULL); /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ output_format_menu_box = XtVaCreateManagedWidget ( "output_format_menu_box", boxWidgetClass, time_date_box, XtNborderWidth,0, XtNorientation,XtorientHorizontal, NULL); output_format_menu_label = XtVaCreateManagedWidget ( "output_format_menu_label", labelWidgetClass, output_format_menu_box, XtNborderWidth,0, XtNlabel,"File format:", NULL); output_format_menu_button = XtVaCreateManagedWidget ( "output_format_menu_button", menuButtonWidgetClass, output_format_menu_box, XtNlabel,output_format_name[output_format], XtNmenuName,"output_format_menu", NULL); output_format_menu = XtVaCreatePopupShell ( "output_format_menu", simpleMenuWidgetClass, output_format_menu_button, NULL); for (i=0; i < output_format_count; i++) { char wname[32]; Widget entry; sprintf (wname,"output_format_name_menu_%d",i); entry = XtVaCreateManagedWidget ( wname, smeBSBObjectClass, output_format_menu, XtNlabel,output_format_name[i], NULL); XtAddCallback (entry,XtNcallback,output_format_chosen,(XtPointer)i); } /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ main_button_box = XtVaCreateManagedWidget ( "box", boxWidgetClass, paned, XtNorientation,XtorientHorizontal, XtNborderWidth,0, NULL); help_button = XtVaCreateManagedWidget ( "help_button", commandWidgetClass, main_button_box, XtNlabel,"Help", NULL); XtAddCallback (help_button,XtNcallback,help,help_message); extract_button = XtVaCreateManagedWidget ( "extract_button", commandWidgetClass, main_button_box, XtNlabel,"Extract", NULL); XtAddCallback (extract_button,XtNcallback,extract,NULL); quit_button = XtVaCreateManagedWidget ( "quit_button", commandWidgetClass, main_button_box, XtNlabel,"Quit", NULL); XtAddCallback (quit_button,XtNcallback,quit,NULL); /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ pshell = XtVaCreatePopupShell ( "pshell", transientShellWidgetClass, topLevel, NULL); info_box = XtVaCreateManagedWidget ( "info_box", panedWidgetClass, pshell, XtNorientation,XtorientVertical, NULL); info_button_box = XtVaCreateManagedWidget ( "info_button_box", boxWidgetClass, info_box, XtNborderWidth,0, NULL); info_button = XtVaCreateManagedWidget ( "info_button", commandWidgetClass, info_button_box, XtNlabel,"OK", NULL); XtAddCallback (info_button,XtNcallback,info_done,NULL); info_text = XtVaCreateManagedWidget ( "info_text", labelWidgetClass, info_box, XtNlabel,help_message, XtNresize,TRUE, XtNallowResize,TRUE, XtNshowGrip,FALSE, NULL); /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ confirm_shell = XtVaCreatePopupShell ( "confirm_shell", transientShellWidgetClass, topLevel, NULL); confirm_box = XtVaCreateManagedWidget ( "confirm_box", panedWidgetClass, confirm_shell, XtNorientation,XtorientVertical, NULL); confirm_button_box = XtVaCreateManagedWidget ( "confirm_button_box", boxWidgetClass, confirm_box, XtNborderWidth,0, NULL); confirm_button = XtVaCreateManagedWidget ( "confirm_button", commandWidgetClass, confirm_button_box, XtNlabel,"OK", NULL); XtAddCallback (confirm_button,XtNcallback,confirm_done,NULL); cancel_button = XtVaCreateManagedWidget ( "cancel_button", commandWidgetClass, confirm_button_box, XtNlabel,"Cancel", NULL); XtAddCallback (cancel_button,XtNcallback,cancel_done,NULL); confirm_text = XtVaCreateManagedWidget ( "confirm_text", labelWidgetClass, confirm_box, XtNresize,TRUE, XtNallowResize,TRUE, XtNlabel,"(none)", XtNshowGrip,FALSE, NULL); /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ XtRealizeWidget (topLevel); XtAppMainLoop (app_context); }