gnumeric r16814 - in trunk: . src/dialogs src/tools



Author: guelzow
Date: Sat Sep 20 21:55:48 2008
New Revision: 16814
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16814&view=rev

Log:
2008-09-20  Andreas J. Guelzow <aguelzow pyrshep ca>

	* analysis-tools.h (analysis_tools_data_sampling_t): add new fields
	* analysis-tools.c (cb_write_data): delete
	(write_data): delete
	(analysis_tool_sampling_engine_run): rewrite completely
	(analysis_tool_sampling_engine): calculate the correct dao height

2008-09-20  Andreas J. Guelzow <aguelzow pyrshep ca>

	* sampling.glade: add some entry fields and radio buttons, remove
	  apply button (which worked identically to the ok button).
	* dialog-analysis-tools.c (SamplingState): add fields
	(sampling_tool_update_sensitivity_cb): skip apply vutton
	(sampling_tool_ok_clicked_cb): handle new fields
	(sampling_method_toggled_cb): ditto
	(dialog_sampling_tool): ditto




Modified:
   trunk/NEWS
   trunk/src/dialogs/ChangeLog
   trunk/src/dialogs/dialog-analysis-tools.c
   trunk/src/dialogs/sampling.glade
   trunk/src/tools/ChangeLog
   trunk/src/tools/analysis-tools.c
   trunk/src/tools/analysis-tools.h

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Sat Sep 20 21:55:48 2008
@@ -14,6 +14,7 @@
 	* Improve histogram tool [#385458][#552161]
 	* Make external hyperlinks work. [#535015]
 	* Make more dialog buttons obey no-icon request. [#302883]
+	* Fix and improve the sampling tool. [#552975]
 
 Jean:
 	* Fix printing of rotated text. [#539734]

Modified: trunk/src/dialogs/dialog-analysis-tools.c
==============================================================================
--- trunk/src/dialogs/dialog-analysis-tools.c	(original)
+++ trunk/src/dialogs/dialog-analysis-tools.c	Sat Sep 20 21:55:48 2008
@@ -152,15 +152,20 @@
 
 typedef struct {
 	GenericToolState base;
+	GtkWidget *options_table;
+	GtkWidget *method_label;
 	GtkWidget *periodic_button;
 	GtkWidget *random_button;
-	GtkWidget *method_label;
 	GtkWidget *period_label;
 	GtkWidget *random_label;
 	GtkWidget *period_entry;
 	GtkWidget *random_entry;
-	GtkWidget *options_table;
 	GtkWidget *number_entry;
+	GtkWidget *offset_label;
+	GtkWidget *offset_entry;
+	GtkWidget *major_label;
+	GtkWidget *row_major_button;
+	GtkWidget *col_major_button;
 } SamplingState;
 
 typedef struct {
@@ -1742,7 +1747,6 @@
 
         if (input_range != NULL) range_list_destroy (input_range);
 
-	gtk_widget_set_sensitive (state->base.apply_button, ready);
 	gtk_widget_set_sensitive (state->base.ok_button, ready);
 }
 
@@ -1779,11 +1783,14 @@
 
         data->periodic = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (state->periodic_button));
 
-	if (data->periodic == 1) {
-		err = entry_to_int (GTK_ENTRY (state->period_entry), &data->size, TRUE);
-	} else {
+	if (data->periodic) {
+		err = entry_to_int (GTK_ENTRY (state->period_entry), &data->period, TRUE);
+		err = entry_to_int (GTK_ENTRY (state->offset_entry), &data->offset, TRUE);
+		data->row_major = gtk_toggle_button_get_active 
+			(GTK_TOGGLE_BUTTON (state->row_major_button));	
+	} else
 		err = entry_to_int (GTK_ENTRY (state->random_entry), &data->size, TRUE);
-	}
+
 	err = entry_to_int (GTK_ENTRY (state->number_entry), &data->number, TRUE);
 
 	if (!cmd_analysis_tool (WORKBOOK_CONTROL (state->base.wbcg), state->base.sheet,
@@ -1808,9 +1815,20 @@
 		gtk_widget_hide (state->random_entry);
 		gtk_widget_show (state->period_label);
 		gtk_widget_show (state->period_entry);
+		gtk_widget_show (state->offset_label);
+		gtk_widget_show (state->offset_entry);
+		gtk_widget_show (state->major_label);
+		gtk_widget_show (state->row_major_button);
+		gtk_widget_show (state->col_major_button);
 	} else {
 		gtk_widget_hide (state->period_label);
 		gtk_widget_hide (state->period_entry);
+		gtk_widget_hide (state->period_entry);
+		gtk_widget_hide (state->offset_label);
+		gtk_widget_hide (state->offset_entry);
+		gtk_widget_hide (state->major_label);
+		gtk_widget_hide (state->row_major_button);
+		gtk_widget_hide (state->col_major_button);
 		gtk_widget_show (state->random_label);
 		gtk_widget_show (state->random_entry);
 	}
@@ -1888,7 +1906,14 @@
 	state->period_entry = glade_xml_get_widget (state->base.gui, "period-entry");
 	state->random_entry = glade_xml_get_widget (state->base.gui, "random-entry");
 	state->number_entry = glade_xml_get_widget (state->base.gui, "number-entry");
+	state->offset_label = glade_xml_get_widget (state->base.gui, "offset-label");
+	state->offset_entry = glade_xml_get_widget (state->base.gui, "offset-entry");
+	state->major_label = glade_xml_get_widget (state->base.gui, "pdir-label");
+	state->row_major_button = glade_xml_get_widget (state->base.gui, "row-major-button");
+	state->col_major_button = glade_xml_get_widget (state->base.gui, "col-major-button");
+
 	int_to_entry (GTK_ENTRY (state->number_entry), 1);
+	int_to_entry (GTK_ENTRY (state->offset_entry), 0);
 
 	g_signal_connect_after (G_OBJECT (state->periodic_button),
 		"toggled",
@@ -1915,7 +1940,7 @@
 	gnumeric_editable_enters (GTK_WINDOW (state->base.dialog),
 				  GTK_WIDGET (state->number_entry));
 
-	gnm_dao_set_put (GNM_DAO (state->base.gdao), FALSE, FALSE);
+	gnm_dao_set_put (GNM_DAO (state->base.gdao), TRUE, TRUE);
 	sampling_tool_update_sensitivity_cb (NULL, state);
 	tool_load_selection ((GenericToolState *)state, TRUE);
 

Modified: trunk/src/dialogs/sampling.glade
==============================================================================
--- trunk/src/dialogs/sampling.glade	(original)
+++ trunk/src/dialogs/sampling.glade	Sat Sep 20 21:55:48 2008
@@ -1,554 +1,486 @@
-<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
-<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd";>
-
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
+<!--*- mode: xml -*-->
 <glade-interface>
-
-<widget class="GtkDialog" id="Sampling">
-  <property name="title" translatable="yes">Sampling</property>
-  <property name="type">GTK_WINDOW_TOPLEVEL</property>
-  <property name="window_position">GTK_WIN_POS_NONE</property>
-  <property name="modal">False</property>
-  <property name="resizable">True</property>
-  <property name="destroy_with_parent">False</property>
-  <property name="has_separator">False</property>
-
-  <child internal-child="vbox">
-    <widget class="GtkVBox" id="vbox1">
-      <property name="visible">True</property>
-      <property name="homogeneous">False</property>
-      <property name="spacing">8</property>
-
-      <child internal-child="action_area">
-	<widget class="GtkHButtonBox" id="hbuttonbox1">
-	  <property name="visible">True</property>
-	  <property name="layout_style">GTK_BUTTONBOX_END</property>
-
-	  <child>
-	    <widget class="GtkButton" id="helpbutton">
-	      <property name="visible">True</property>
-	      <property name="can_default">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="label">gtk-help</property>
-	      <property name="use_stock">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	      <property name="response_id">0</property>
-	    </widget>
-	  </child>
-
-	  <child>
-	    <widget class="GtkButton" id="applybutton">
-	      <property name="visible">True</property>
-	      <property name="can_default">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="label">gtk-apply</property>
-	      <property name="use_stock">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	      <property name="response_id">0</property>
-	    </widget>
-	  </child>
-
-	  <child>
-	    <widget class="GtkButton" id="cancelbutton">
-	      <property name="visible">True</property>
-	      <property name="can_default">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="label">gtk-cancel</property>
-	      <property name="use_stock">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	      <property name="response_id">0</property>
-	    </widget>
-	  </child>
-
-	  <child>
-	    <widget class="GtkButton" id="okbutton">
-	      <property name="visible">True</property>
-	      <property name="can_default">True</property>
-	      <property name="has_default">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="label">gtk-ok</property>
-	      <property name="use_stock">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	      <property name="response_id">0</property>
-	    </widget>
-	  </child>
-	</widget>
-	<packing>
-	  <property name="padding">0</property>
-	  <property name="expand">False</property>
-	  <property name="fill">True</property>
-	  <property name="pack_type">GTK_PACK_END</property>
-	</packing>
-      </child>
-
-      <child>
-	<widget class="GtkNotebook" id="notebook1">
-	  <property name="visible">True</property>
-	  <property name="can_focus">True</property>
-	  <property name="show_tabs">True</property>
-	  <property name="show_border">True</property>
-	  <property name="tab_pos">GTK_POS_TOP</property>
-	  <property name="scrollable">False</property>
-	  <property name="enable_popup">False</property>
-
-	  <child>
-	    <widget class="GtkTable" id="input-table">
-	      <property name="border_width">12</property>
-	      <property name="visible">True</property>
-	      <property name="n_rows">3</property>
-	      <property name="n_columns">2</property>
-	      <property name="homogeneous">False</property>
-	      <property name="row_spacing">6</property>
-	      <property name="column_spacing">12</property>
-
-	      <child>
-		<widget class="GtkLabel" id="var1-label">
-		  <property name="visible">True</property>
-		  <property name="label" translatable="yes">_Input range: </property>
-		  <property name="use_underline">True</property>
-		  <property name="use_markup">False</property>
-		  <property name="justify">GTK_JUSTIFY_RIGHT</property>
-		  <property name="wrap">False</property>
-		  <property name="selectable">False</property>
-		  <property name="xalign">0</property>
-		  <property name="yalign">0.5</property>
-		  <property name="xpad">5</property>
-		  <property name="ypad">0</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">0</property>
-		  <property name="right_attach">1</property>
-		  <property name="top_attach">0</property>
-		  <property name="bottom_attach">1</property>
-		  <property name="x_options">fill</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkLabel" id="label1">
-		  <property name="visible">True</property>
-		  <property name="label" translatable="yes">Grouped by:</property>
-		  <property name="use_underline">False</property>
-		  <property name="use_markup">False</property>
-		  <property name="justify">GTK_JUSTIFY_CENTER</property>
-		  <property name="wrap">False</property>
-		  <property name="selectable">False</property>
-		  <property name="xalign">0</property>
-		  <property name="yalign">0.5</property>
-		  <property name="xpad">5</property>
-		  <property name="ypad">0</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">0</property>
-		  <property name="right_attach">1</property>
-		  <property name="top_attach">1</property>
-		  <property name="bottom_attach">2</property>
-		  <property name="x_options">fill</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkHBox" id="hbox1">
-		  <property name="visible">True</property>
-		  <property name="homogeneous">True</property>
-		  <property name="spacing">0</property>
-
-		  <child>
-		    <widget class="GtkRadioButton" id="grouped_by_col">
-		      <property name="visible">True</property>
-		      <property name="can_focus">True</property>
-		      <property name="label" translatable="yes">_Columns</property>
-		      <property name="use_underline">True</property>
-		      <property name="relief">GTK_RELIEF_NORMAL</property>
-		      <property name="active">False</property>
-		      <property name="inconsistent">False</property>
-		      <property name="draw_indicator">True</property>
-		    </widget>
-		    <packing>
-		      <property name="padding">0</property>
-		      <property name="expand">False</property>
-		      <property name="fill">False</property>
-		    </packing>
-		  </child>
-
-		  <child>
-		    <widget class="GtkRadioButton" id="grouped_by_row">
-		      <property name="visible">True</property>
-		      <property name="can_focus">True</property>
-		      <property name="label" translatable="yes">_Rows</property>
-		      <property name="use_underline">True</property>
-		      <property name="relief">GTK_RELIEF_NORMAL</property>
-		      <property name="active">False</property>
-		      <property name="inconsistent">False</property>
-		      <property name="draw_indicator">True</property>
-		      <property name="group">grouped_by_col</property>
-		    </widget>
-		    <packing>
-		      <property name="padding">0</property>
-		      <property name="expand">False</property>
-		      <property name="fill">False</property>
-		    </packing>
-		  </child>
-
-		  <child>
-		    <widget class="GtkRadioButton" id="grouped_by_area">
-		      <property name="visible">True</property>
-		      <property name="can_focus">True</property>
-		      <property name="label" translatable="yes">_Areas</property>
-		      <property name="use_underline">True</property>
-		      <property name="relief">GTK_RELIEF_NORMAL</property>
-		      <property name="active">True</property>
-		      <property name="inconsistent">False</property>
-		      <property name="draw_indicator">True</property>
-		      <property name="group">grouped_by_col</property>
-		    </widget>
-		    <packing>
-		      <property name="padding">0</property>
-		      <property name="expand">False</property>
-		      <property name="fill">False</property>
-		    </packing>
-		  </child>
-		</widget>
-		<packing>
-		  <property name="left_attach">1</property>
-		  <property name="right_attach">2</property>
-		  <property name="top_attach">1</property>
-		  <property name="bottom_attach">2</property>
-		  <property name="y_options">fill</property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkCheckButton" id="labels_button">
-		  <property name="visible">True</property>
-		  <property name="can_focus">True</property>
-		  <property name="label" translatable="yes">_Labels</property>
-		  <property name="use_underline">True</property>
-		  <property name="relief">GTK_RELIEF_NORMAL</property>
-		  <property name="active">False</property>
-		  <property name="inconsistent">False</property>
-		  <property name="draw_indicator">True</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">0</property>
-		  <property name="right_attach">1</property>
-		  <property name="top_attach">2</property>
-		  <property name="bottom_attach">3</property>
-		  <property name="x_options">fill</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-	    </widget>
-	    <packing>
-	      <property name="tab_expand">False</property>
-	      <property name="tab_fill">True</property>
-	    </packing>
-	  </child>
-
-	  <child>
-	    <widget class="GtkLabel" id="label4">
-	      <property name="visible">True</property>
-	      <property name="label" translatable="yes">_Input</property>
-	      <property name="use_underline">True</property>
-	      <property name="use_markup">False</property>
-	      <property name="justify">GTK_JUSTIFY_LEFT</property>
-	      <property name="wrap">False</property>
-	      <property name="selectable">False</property>
-	      <property name="xalign">0.5</property>
-	      <property name="yalign">0.5</property>
-	      <property name="xpad">0</property>
-	      <property name="ypad">0</property>
-	    </widget>
-	    <packing>
-	      <property name="type">tab</property>
-	    </packing>
-	  </child>
-
-	  <child>
-	    <widget class="GtkTable" id="options-table">
-	      <property name="border_width">12</property>
-	      <property name="visible">True</property>
-	      <property name="n_rows">3</property>
-	      <property name="n_columns">3</property>
-	      <property name="homogeneous">False</property>
-	      <property name="row_spacing">6</property>
-	      <property name="column_spacing">12</property>
-
-	      <child>
-		<widget class="GtkLabel" id="method-label">
-		  <property name="visible">True</property>
-		  <property name="label" translatable="yes">Sampling method:</property>
-		  <property name="use_underline">False</property>
-		  <property name="use_markup">False</property>
-		  <property name="justify">GTK_JUSTIFY_RIGHT</property>
-		  <property name="wrap">False</property>
-		  <property name="selectable">False</property>
-		  <property name="xalign">0</property>
-		  <property name="yalign">0.5</property>
-		  <property name="xpad">5</property>
-		  <property name="ypad">0</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">0</property>
-		  <property name="right_attach">1</property>
-		  <property name="top_attach">0</property>
-		  <property name="bottom_attach">1</property>
-		  <property name="x_options">fill</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkRadioButton" id="periodic-button">
-		  <property name="visible">True</property>
-		  <property name="can_focus">True</property>
-		  <property name="label" translatable="yes">_Periodic</property>
-		  <property name="use_underline">True</property>
-		  <property name="relief">GTK_RELIEF_NORMAL</property>
-		  <property name="active">False</property>
-		  <property name="inconsistent">False</property>
-		  <property name="draw_indicator">True</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">1</property>
-		  <property name="right_attach">2</property>
-		  <property name="top_attach">0</property>
-		  <property name="bottom_attach">1</property>
-		  <property name="x_options">fill</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkRadioButton" id="random-button">
-		  <property name="visible">True</property>
-		  <property name="can_focus">True</property>
-		  <property name="label" translatable="yes">_Random</property>
-		  <property name="use_underline">True</property>
-		  <property name="relief">GTK_RELIEF_NORMAL</property>
-		  <property name="active">True</property>
-		  <property name="inconsistent">False</property>
-		  <property name="draw_indicator">True</property>
-		  <property name="group">periodic-button</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">2</property>
-		  <property name="right_attach">3</property>
-		  <property name="top_attach">0</property>
-		  <property name="bottom_attach">1</property>
-		  <property name="x_options">fill</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkLabel" id="period-label">
-		  <property name="visible">True</property>
-		  <property name="label" translatable="yes">Per_iod:</property>
-		  <property name="use_underline">True</property>
-		  <property name="use_markup">False</property>
-		  <property name="justify">GTK_JUSTIFY_RIGHT</property>
-		  <property name="wrap">False</property>
-		  <property name="selectable">False</property>
-		  <property name="xalign">0</property>
-		  <property name="yalign">0.5</property>
-		  <property name="xpad">5</property>
-		  <property name="ypad">0</property>
-		  <property name="mnemonic_widget">period-entry</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">0</property>
-		  <property name="right_attach">1</property>
-		  <property name="top_attach">1</property>
-		  <property name="bottom_attach">2</property>
-		  <property name="x_options">fill</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkEntry" id="period-entry">
-		  <property name="visible">True</property>
-		  <property name="can_focus">True</property>
-		  <property name="editable">True</property>
-		  <property name="visibility">True</property>
-		  <property name="max_length">0</property>
-		  <property name="text" translatable="yes"></property>
-		  <property name="has_frame">True</property>
-		  <property name="invisible_char" translatable="yes">*</property>
-		  <property name="activates_default">False</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">1</property>
-		  <property name="right_attach">3</property>
-		  <property name="top_attach">1</property>
-		  <property name="bottom_attach">2</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkLabel" id="random-label">
-		  <property name="visible">True</property>
-		  <property name="label" translatable="yes">Size of sample:</property>
-		  <property name="use_underline">False</property>
-		  <property name="use_markup">False</property>
-		  <property name="justify">GTK_JUSTIFY_RIGHT</property>
-		  <property name="wrap">False</property>
-		  <property name="selectable">False</property>
-		  <property name="xalign">0</property>
-		  <property name="yalign">0.5</property>
-		  <property name="xpad">5</property>
-		  <property name="ypad">0</property>
-		  <property name="mnemonic_widget">random-entry</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">0</property>
-		  <property name="right_attach">1</property>
-		  <property name="top_attach">1</property>
-		  <property name="bottom_attach">2</property>
-		  <property name="x_options">fill</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkEntry" id="random-entry">
-		  <property name="visible">True</property>
-		  <property name="can_focus">True</property>
-		  <property name="editable">True</property>
-		  <property name="visibility">True</property>
-		  <property name="max_length">0</property>
-		  <property name="text" translatable="yes"></property>
-		  <property name="has_frame">True</property>
-		  <property name="invisible_char" translatable="yes">*</property>
-		  <property name="activates_default">False</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">1</property>
-		  <property name="right_attach">3</property>
-		  <property name="top_attach">1</property>
-		  <property name="bottom_attach">2</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkLabel" id="label2">
-		  <property name="visible">True</property>
-		  <property name="label" translatable="yes">N_umber of samples:</property>
-		  <property name="use_underline">True</property>
-		  <property name="use_markup">False</property>
-		  <property name="justify">GTK_JUSTIFY_CENTER</property>
-		  <property name="wrap">False</property>
-		  <property name="selectable">False</property>
-		  <property name="xalign">0</property>
-		  <property name="yalign">0.5</property>
-		  <property name="xpad">5</property>
-		  <property name="ypad">0</property>
-		  <property name="mnemonic_widget">number-entry</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">0</property>
-		  <property name="right_attach">1</property>
-		  <property name="top_attach">2</property>
-		  <property name="bottom_attach">3</property>
-		  <property name="x_options">fill</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-
-	      <child>
-		<widget class="GtkEntry" id="number-entry">
-		  <property name="visible">True</property>
-		  <property name="can_focus">True</property>
-		  <property name="editable">True</property>
-		  <property name="visibility">True</property>
-		  <property name="max_length">0</property>
-		  <property name="text" translatable="yes">1</property>
-		  <property name="has_frame">True</property>
-		  <property name="invisible_char" translatable="yes">*</property>
-		  <property name="activates_default">False</property>
-		</widget>
-		<packing>
-		  <property name="left_attach">1</property>
-		  <property name="right_attach">3</property>
-		  <property name="top_attach">2</property>
-		  <property name="bottom_attach">3</property>
-		  <property name="y_padding">3</property>
-		  <property name="y_options"></property>
-		</packing>
-	      </child>
-	    </widget>
-	    <packing>
-	      <property name="tab_expand">False</property>
-	      <property name="tab_fill">True</property>
-	    </packing>
-	  </child>
-
-	  <child>
-	    <widget class="GtkLabel" id="label5">
-	      <property name="visible">True</property>
-	      <property name="label" translatable="yes">O_ptions</property>
-	      <property name="use_underline">True</property>
-	      <property name="use_markup">False</property>
-	      <property name="justify">GTK_JUSTIFY_LEFT</property>
-	      <property name="wrap">False</property>
-	      <property name="selectable">False</property>
-	      <property name="xalign">0.5</property>
-	      <property name="yalign">0.5</property>
-	      <property name="xpad">0</property>
-	      <property name="ypad">0</property>
-	    </widget>
-	    <packing>
-	      <property name="type">tab</property>
-	    </packing>
-	  </child>
-
-	  <child>
-	    <widget class="GtkHBox" id="dao">
-	      <property name="visible">True</property>
-	      <property name="homogeneous">False</property>
-	      <property name="spacing">0</property>
-
-	      <child>
-		<placeholder/>
-	      </child>
-	    </widget>
-	    <packing>
-	      <property name="tab_expand">False</property>
-	      <property name="tab_fill">True</property>
-	    </packing>
-	  </child>
-
-	  <child>
-	    <widget class="GtkLabel" id="label6">
-	      <property name="visible">True</property>
-	      <property name="label" translatable="yes">_Output</property>
-	      <property name="use_underline">True</property>
-	      <property name="use_markup">False</property>
-	      <property name="justify">GTK_JUSTIFY_LEFT</property>
-	      <property name="wrap">False</property>
-	      <property name="selectable">False</property>
-	      <property name="xalign">0.5</property>
-	      <property name="yalign">0.5</property>
-	      <property name="xpad">0</property>
-	      <property name="ypad">0</property>
-	    </widget>
-	    <packing>
-	      <property name="type">tab</property>
-	    </packing>
-	  </child>
-	</widget>
-	<packing>
-	  <property name="padding">0</property>
-	  <property name="expand">True</property>
-	  <property name="fill">True</property>
-	</packing>
-      </child>
-    </widget>
-  </child>
-</widget>
-
+  <widget class="GtkDialog" id="Sampling">
+    <property name="title" translatable="yes">Sampling</property>
+    <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <widget class="GtkVBox" id="vbox1">
+        <property name="visible">True</property>
+        <property name="spacing">8</property>
+        <child>
+          <widget class="GtkNotebook" id="notebook1">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <child>
+              <widget class="GtkTable" id="input-table">
+                <property name="visible">True</property>
+                <property name="border_width">12</property>
+                <property name="n_rows">3</property>
+                <property name="n_columns">2</property>
+                <property name="column_spacing">12</property>
+                <property name="row_spacing">6</property>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="var1-label">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">_Input range: </property>
+                    <property name="use_underline">True</property>
+                    <property name="justify">GTK_JUSTIFY_RIGHT</property>
+                  </widget>
+                  <packing>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">Grouped by:</property>
+                    <property name="justify">GTK_JUSTIFY_CENTER</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkHBox" id="hbox1">
+                    <property name="visible">True</property>
+                    <property name="homogeneous">True</property>
+                    <child>
+                      <widget class="GtkRadioButton" id="grouped_by_col">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="label" translatable="yes">_Columns</property>
+                        <property name="use_underline">True</property>
+                        <property name="response_id">0</property>
+                        <property name="draw_indicator">True</property>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkRadioButton" id="grouped_by_row">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="label" translatable="yes">_Rows</property>
+                        <property name="use_underline">True</property>
+                        <property name="response_id">0</property>
+                        <property name="draw_indicator">True</property>
+                        <property name="group">grouped_by_col</property>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkRadioButton" id="grouped_by_area">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="label" translatable="yes">_Areas</property>
+                        <property name="use_underline">True</property>
+                        <property name="response_id">0</property>
+                        <property name="active">True</property>
+                        <property name="draw_indicator">True</property>
+                        <property name="group">grouped_by_col</property>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="y_options">GTK_FILL</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkCheckButton" id="labels_button">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="label" translatable="yes">_Labels</property>
+                    <property name="use_underline">True</property>
+                    <property name="response_id">0</property>
+                    <property name="draw_indicator">True</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="label4">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Input</property>
+                <property name="use_underline">True</property>
+              </widget>
+              <packing>
+                <property name="type">tab</property>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkTable" id="options-table">
+                <property name="visible">True</property>
+                <property name="border_width">12</property>
+                <property name="n_rows">5</property>
+                <property name="n_columns">3</property>
+                <property name="column_spacing">12</property>
+                <property name="row_spacing">6</property>
+                <child>
+                  <widget class="GtkLabel" id="method-label">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">Sampling method:</property>
+                    <property name="justify">GTK_JUSTIFY_RIGHT</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkRadioButton" id="periodic-button">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="label" translatable="yes">_Periodic</property>
+                    <property name="use_underline">True</property>
+                    <property name="response_id">0</property>
+                    <property name="draw_indicator">True</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkRadioButton" id="random-button">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="label" translatable="yes">_Random</property>
+                    <property name="use_underline">True</property>
+                    <property name="response_id">0</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">periodic-button</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">2</property>
+                    <property name="right_attach">3</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="period-label">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">Per_iod:</property>
+                    <property name="use_underline">True</property>
+                    <property name="justify">GTK_JUSTIFY_RIGHT</property>
+                    <property name="mnemonic_widget">period-entry</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkEntry" id="period-entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">*</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">3</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="random-label">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">Size of sample:</property>
+                    <property name="justify">GTK_JUSTIFY_RIGHT</property>
+                    <property name="mnemonic_widget">random-entry</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkEntry" id="random-entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">*</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">3</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">N_umber of samples:</property>
+                    <property name="use_underline">True</property>
+                    <property name="justify">GTK_JUSTIFY_CENTER</property>
+                    <property name="mnemonic_widget">number-entry</property>
+                  </widget>
+                  <packing>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkEntry" id="number-entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">*</property>
+                    <property name="text" translatable="yes">1</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">3</property>
+                    <property name="y_options"></property>
+                    <property name="y_padding">3</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="offset-label">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">Offset:</property>
+                    <property name="justify">GTK_JUSTIFY_RIGHT</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkEntry" id="offset-entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="max_length">5</property>
+                    <property name="text" translatable="yes">0</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">3</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="pdir-label">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">Primary direction:</property>
+                    <property name="justify">GTK_JUSTIFY_RIGHT</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkRadioButton" id="row-major-button">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="label" translatable="yes">Row major</property>
+                    <property name="response_id">0</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkRadioButton" id="col-major-button">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="label" translatable="yes">Column major</property>
+                    <property name="response_id">0</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">row-major-button</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">2</property>
+                    <property name="right_attach">3</property>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="label5">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">O_ptions</property>
+                <property name="use_underline">True</property>
+              </widget>
+              <packing>
+                <property name="type">tab</property>
+                <property name="position">1</property>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkHBox" id="dao">
+                <property name="visible">True</property>
+                <child>
+                  <placeholder/>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="label6">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Output</property>
+                <property name="use_underline">True</property>
+              </widget>
+              <packing>
+                <property name="type">tab</property>
+                <property name="position">2</property>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkLabel" id="warnings">
+            <property name="visible">True</property>
+          </widget>
+          <packing>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <widget class="GtkHButtonBox" id="hbuttonbox1">
+            <property name="visible">True</property>
+            <property name="layout_style">GTK_BUTTONBOX_END</property>
+            <child>
+              <widget class="GtkButton" id="helpbutton">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="label">gtk-help</property>
+                <property name="use_stock">True</property>
+                <property name="response_id">0</property>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkButton" id="cancelbutton">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="label">gtk-cancel</property>
+                <property name="use_stock">True</property>
+                <property name="response_id">0</property>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkButton" id="okbutton">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="label">gtk-ok</property>
+                <property name="use_stock">True</property>
+                <property name="response_id">0</property>
+              </widget>
+              <packing>
+                <property name="position">2</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">GTK_PACK_END</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
 </glade-interface>

Modified: trunk/src/tools/analysis-tools.c
==============================================================================
--- trunk/src/tools/analysis-tools.c	(original)
+++ trunk/src/tools/analysis-tools.c	Sat Sep 20 21:55:48 2008
@@ -227,7 +227,7 @@
  *  @ignore_non_num: gboolean   whether simply to ignore non-numerical values
  *  @read_label: gboolean       whether the first entry contains a label
  */
-GPtrArray *
+static GPtrArray *
 new_data_set_list (GSList *ranges, group_by_t group_by,
 		   gboolean ignore_non_num, gboolean read_labels, Sheet *sheet)
 {
@@ -651,39 +651,6 @@
 	g_free (orig_copy);
 }
 
-#warning 2006/May/31  Review this.  Why are we pulling elements from the front of an array ??
-static GnmValue *
-cb_write_data (GnmCellIter const *iter, GArray* data)
-{
-	gnm_float  x;
-	GnmCell *cell;
-	if (data->len == 0)
-		return VALUE_TERMINATE;
-	if (NULL == (cell = iter->cell))
-		cell = sheet_cell_create (iter->pp.sheet,
-			iter->pp.eval.col, iter->pp.eval.row);
-	x = g_array_index (data, gnm_float, 0);
-	g_array_remove_index (data, 0);
-	sheet_cell_set_value (cell, value_new_float (x));
-	return NULL;
-}
-
-static void
-write_data (data_analysis_output_t *dao, GArray *data)
-{
-	gint st_row = dao->start_row + dao->offset_row;
-	gint end_row = dao->start_row + dao->rows - 1;
-	gint st_col = dao->start_col + dao->offset_col;
-	gint end_col = dao->start_col + dao->offset_col;
-
-	if (dao->cols <= dao->offset_col)
-		return;
-
-	sheet_foreach_cell_in_range (dao->sheet, CELL_ITER_ALL,
-		st_col, st_row, end_col, end_row,
-		(CellIterFunc)&cb_write_data, data);
-}
-
 gboolean
 analysis_tool_generic_clean (gpointer specs)
 {
@@ -1306,75 +1273,144 @@
 analysis_tool_sampling_engine_run (data_analysis_output_t *dao,
 					 analysis_tools_data_sampling_t *info)
 {
-	GPtrArray *data = NULL;
-
-	guint i, j, data_len;
-	guint n_sample;
-	guint n_data;
-	gnm_float x;
-
-	data = new_data_set_list (info->base.input, info->base.group_by,
-				  TRUE, info->base.labels, dao->sheet);
-
-	for (n_data = 0; n_data < data->len; n_data++) {
-		for (n_sample = 0; n_sample < info->number; n_sample++) {
-			GArray * sample = g_array_new (FALSE, FALSE,
-						       sizeof (gnm_float));
-			GArray * this_data = g_array_new (FALSE, FALSE,
-							  sizeof (gnm_float));
-			data_set_t * this_data_set;
-
-			this_data_set = g_ptr_array_index (data, n_data);
-			data_len = this_data_set->data->len;
-
-			dao_set_cell_printf (dao, 0, 0, this_data_set->label);
-			dao_set_italic (dao, 0, 0, 0, 0);
-			dao->offset_row = 1;
-
-			g_array_set_size (this_data, data_len);
-			g_memmove (this_data->data, this_data_set->data->data,
-				   sizeof (gnm_float) * data_len);
-
-			if (info->periodic) {
-				if ((info->size < 0) || (info->size > data_len)) {
-					destroy_data_set_list (data);
-					gnm_cmd_context_error_calc (GO_CMD_CONTEXT (info->base.wbc),
-						_("The requested sample size is too large for a periodic sample."));
-					return TRUE;
-				}
-				for (i = info->size - 1; i < data_len; i += info->size) {
-					x = g_array_index (this_data, gnm_float, i);
-					g_array_append_val (sample, x);
+	GSList *l;
+	gint col = 0;
+	guint ct;
+	GnmFunc *fd_index = NULL;
+	GnmFunc *fd_randdiscrete = NULL;
+	gint source;
+
+	if (info->base.labels || info->periodic) {
+		fd_index = gnm_func_lookup ("INDEX", NULL);
+		gnm_func_ref (fd_index);		
+	}
+	if (!info->periodic) {
+		fd_randdiscrete = gnm_func_lookup ("RANDDISCRETE", NULL);
+		gnm_func_ref (fd_randdiscrete);				
+	}
+
+	for (l = info->base.input, source = 1; l; l = l->next, source++) {
+		GnmValue *val = value_dup ((GnmValue *)l->data);
+		GnmValue *val_c = NULL;
+		GnmExpr const *expr_title = NULL;
+		GnmExpr const *expr_input = NULL;
+		char const *format = NULL;
+		guint offset = info->periodic ? ((info->offset == 0) ? info->period : info->offset): 0;
+
+
+		if (info->base.labels) {
+			val_c = value_dup (val);
+			switch (info->base.group_by) {
+			case GROUPED_BY_ROW:
+				val->v_range.cell.a.col++;
+				break;
+			case GROUPED_BY_COL:
+				val->v_range.cell.a.row++;
+				break;
+			default:
+				offset++;
+				break;
+			}
+			expr_title = gnm_expr_new_funcall1 (fd_index, 
+							    gnm_expr_new_constant (val_c));
+			for (ct = 0; ct < info->number; ct++)
+				dao_set_cell_expr (dao, col+ct, 0, gnm_expr_copy (expr_title));
+			gnm_expr_free (expr_title);			
+		} else {
+			switch (info->base.group_by) {
+ 			case GROUPED_BY_ROW:
+				format = _("Row %d");
+				break;
+			case GROUPED_BY_COL:
+				format = _("Column %d");
+				break;
+			default:
+				format = _("Area %d");
+				break;			
+			}	
+			for (ct = 0; ct < info->number; ct++)
+				dao_set_cell_printf (dao, col+ct, 0, format, source);
+		}
+			
+		expr_input = gnm_expr_new_constant (value_dup (val));
+		
+		
+		if (info->periodic) {
+			guint i;
+			gint height = value_area_get_height (val, NULL);
+			gint width = value_area_get_width (val, NULL);
+			GnmExpr const *expr_period;
+
+			for (i=0; i < info->size; i++, offset += info->period) {
+				gint x_offset;
+				gint y_offset;
+
+				if (info->row_major) {
+					y_offset = (offset - 1)/width + 1;
+					x_offset = offset - (y_offset - 1) * width; 
+				} else {
+					x_offset = (offset - 1)/height + 1;
+					y_offset = offset - (x_offset - 1) * height; 
 				}
-				write_data (dao, sample);
-			} else {
-				for (i = 0; i < info->size; i++) {
-					guint random_index;
 
-					if (0 == data_len)
-						break;
-					random_index = random_01 () * data_len;
-					if (random_index == data_len)
-						random_index--;
-					x = g_array_index (this_data, gnm_float, random_index);
-					g_array_remove_index_fast (this_data, random_index);
-					g_array_append_val (sample, x);
-					data_len--;
+				expr_period = gnm_expr_new_funcall3 
+					(fd_index, gnm_expr_copy (expr_input),
+					 gnm_expr_new_constant (value_new_int (y_offset)),
+					 gnm_expr_new_constant (value_new_int (x_offset)));
+
+				for (ct = 0; ct < info->number; ct += 2)
+					dao_set_cell_expr (dao, col + ct, i + 1, 
+							   gnm_expr_copy (expr_period));
+				gnm_expr_free (expr_period);
+
+				if (info->number > 1) {
+					if (!info->row_major) {
+						y_offset = (offset - 1)/width + 1;
+						x_offset = offset - (y_offset - 1) * width; 
+					} else {
+						x_offset = (offset - 1)/height + 1;
+						y_offset = offset - (x_offset - 1) * height; 
+					}
+					
+					expr_period = gnm_expr_new_funcall3 
+						(fd_index, gnm_expr_copy (expr_input),
+						 gnm_expr_new_constant (value_new_int (y_offset)),
+						 gnm_expr_new_constant (value_new_int (x_offset)));
+					
+					for (ct = 1; ct < info->number; ct += 2)
+						dao_set_cell_expr (dao, col + ct, i + 1, 
+								   gnm_expr_copy (expr_period));
+					gnm_expr_free (expr_period);
+					
 				}
-				write_data (dao, sample);
-				for (j = i; j < info->size; j++)
-					dao_set_cell_na (dao, 0, j);
 			}
-
-			g_array_free (this_data, TRUE);
-			g_array_free (sample, TRUE);
-      			dao->offset_col++;
-			dao->offset_row = 0;
+			col += info->number;
+		} else {
+			GnmExpr const *expr_random;
+			guint i;
+			
+			expr_random = gnm_expr_new_funcall1 (fd_randdiscrete, 
+							     gnm_expr_copy (expr_input));
+			
+			for (ct = 0; ct < info->number; ct++, col++)
+				for (i=0; i < info->size; i++)
+					dao_set_cell_expr (dao, col, i + 1, 
+							   gnm_expr_copy (expr_random));
+			gnm_expr_free (expr_random);
 		}
+		
+		value_release (val);
+		gnm_expr_free (expr_input);
+		
 	}
-
-	destroy_data_set_list (data);
-
+	
+	if (fd_index != NULL)
+		gnm_func_unref (fd_index);
+	if (fd_randdiscrete != NULL)
+		gnm_func_unref (fd_randdiscrete);
+	
+	dao_redraw_respan (dao);
+	
 	return FALSE;
 }
 
@@ -1389,10 +1425,32 @@
 		return (dao_command_descriptor (dao, _("Sampling (%s)"), result)
 			== NULL);
 	case TOOL_ENGINE_UPDATE_DAO:
+	{
+		GSList *l;
+	
 		prepare_input_range (&info->base.input, info->base.group_by);
+
+		if (info->periodic) {
+			info->size = 1;
+			for (l = info->base.input; l; l = l->next) {
+				GnmValue *val = ((GnmValue *)l->data);
+				gint size = (value_area_get_width (val, NULL) *  
+					     value_area_get_height (val, NULL));
+				guint usize = (size > 0) ? size : 1;
+
+				if (info->offset == 0)
+					usize = usize/info->period;
+				else
+					usize = (usize - info->offset)/info->period + 1;
+				if (usize > info->size)
+					info->size = usize;
+			}
+		}
+		
 		dao_adjust (dao, info->number * g_slist_length (info->base.input),
 			    1 + info->size);
 		return FALSE;
+	}
 	case TOOL_ENGINE_CLEAN_UP:
 		return analysis_tool_generic_clean (specs);
 	case TOOL_ENGINE_LAST_VALIDITY_CHECK:

Modified: trunk/src/tools/analysis-tools.h
==============================================================================
--- trunk/src/tools/analysis-tools.h	(original)
+++ trunk/src/tools/analysis-tools.h	Sat Sep 20 21:55:48 2008
@@ -123,7 +123,10 @@
 typedef struct {
 	analysis_tools_data_generic_t base;
 	gboolean periodic;
+	gboolean row_major;
+	guint offset;
 	guint size;
+	guint period;
 	guint number;
 } analysis_tools_data_sampling_t;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]