Index: /issm/trunk/src/m/qmu/expandresponses.m
===================================================================
--- /issm/trunk/src/m/qmu/expandresponses.m	(revision 5487)
+++ /issm/trunk/src/m/qmu/expandresponses.m	(revision 5487)
@@ -0,0 +1,13 @@
+function dresp=expandresponses(md,responses)
+
+fnames=fieldnames(responses);
+
+for i=1:length(fnames)
+
+	fhandle=str2func([class(responses.(fnames{i})) '.empty']);
+	dresp.(fnames{i})=fhandle();
+	for j=1:length(responses.(fnames{i}))
+		%call setupdesign
+		dresp.(fnames{i})=QmuSetupResponses(md,dresp.(fnames{i}),responses.(fnames{i})(j));
+	end
+end
Index: /issm/trunk/src/m/qmu/expandvariables.m
===================================================================
--- /issm/trunk/src/m/qmu/expandvariables.m	(revision 5486)
+++ /issm/trunk/src/m/qmu/expandvariables.m	(revision 5487)
@@ -18,5 +18,5 @@
         for j=1:length(variables.(fnames{i}))
             %call setupdesign
-            dvar.(fnames{i})=QmuSetupDesign(md,dvar.(fnames{i}),variables.(fnames{i})(j));
+            dvar.(fnames{i})=QmuSetupVariables(md,dvar.(fnames{i}),variables.(fnames{i})(j));
         end
     end
Index: /issm/trunk/src/m/qmu/preqmu.m
===================================================================
--- /issm/trunk/src/m/qmu/preqmu.m	(revision 5486)
+++ /issm/trunk/src/m/qmu/preqmu.m	(revision 5487)
@@ -41,8 +41,10 @@
 responses=md.responses(options.iresp);
 
-%expand variables
+%expand variables and responses
 variables=expandvariables(md,md.variables);
+responses=expandresponses(md,md.responses);
 
-%go through variables, and check they don't have more than md.npart values
+%go through variables and responses, and check they don't have more than md.npart values. Also determine numvariables and numresponses{{{1
+numvariables=0;
 variable_fieldnames=fieldnames(variables);
 for i=1:length(variable_fieldnames),
@@ -52,18 +54,4 @@
 		error('preqmu error message: one of the expanded variables has more values than the number of partitions (setup in md.npart)');
 	end
-end
-
-%create m and in files for dakota
-dakota_in_data(md.qmu_method(options.imethod),variables,md.responses,md.qmu_params(options.iparams),options.qmufile);
-
-%in library mode, we only need the dakota in file
-system(['rm -rf ' md.name '.m']);
-
-%figure out number of variables and responses, it's not straightforwared
-numvariables=0;
-variable_fieldnames=fieldnames(variables);
-for i=1:length(variable_fieldnames),
-	field_name=variable_fieldnames{i};
-	fieldvariables=variables.(field_name);
 	numvariables=numvariables+numel(variables.(field_name));
 end
@@ -74,36 +62,30 @@
 	field_name=response_fieldnames{i};
 	fieldresponses=responses.(field_name);
+	if numel(fieldresponses)>md.npart,
+		error('preqmu error message: one of the expanded responses has more values than the number of partitions (setup in md.npart)');
+	end
 	numresponses=numresponses+numel(responses.(field_name));
 end
+%}}}}
 
-%ok, now, for this particular qmu analysis, iresp and ivar specifiy the variables and responses. 
-%The Qmu module will need a list of variable descriptors and response descriptors. 
-%For ease of use, we gather this list here.
+%create in file for dakota
+dakota_in_data(md.qmu_method(options.imethod),variables,responses,md.qmu_params(options.iparams),options.qmufile);
+system(['rm -rf ' md.name '.m']);
 
-count=0;
-variable_fieldnames=fieldnames(variables);
+%build a list of variables and responses descriptors. the list is not expanded. {{{1
 variabledescriptors={};
+variable_fieldnames=fieldnames(md.variables);
 for i=1:length(variable_fieldnames),
 	field_name=variable_fieldnames{i};
-	fieldvariables=variables.(field_name);
-	for j=1:length(fieldvariables),
-		descriptor=fieldvariables(j).descriptor;
-		variabledescriptors{end+1}=descriptor;
-		count=count+1;
-	end
+	variabledescriptors{end+1}=md.variables.(field_name).descriptor;
 end
 
-count=0;
-response_fieldnames=fieldnames(responses);
 responsedescriptors={};
+response_fieldnames=fieldnames(md.responses);
 for i=1:length(response_fieldnames),
 	field_name=response_fieldnames{i};
-	fieldresponses=responses.(field_name);
-	for j=1:length(fieldresponses),
-		descriptor=fieldresponses(j).descriptor;
-		responsedescriptors{end+1}=descriptor;
-		count=count+1;
-	end
+	responsedescriptors{end+1}=md.responses.(field_name).descriptor;
 end
+%}}}
 
 %register the fields that will be needed by the Qmu model.
@@ -112,4 +94,6 @@
 md.variabledescriptors=variabledescriptors;
 md.responsedescriptors=responsedescriptors;
+md.numvariabledescriptors=numel(md.variabledescriptors);
+md.numresponsedescriptors=numel(md.responsedescriptors);
 
 %now, we have to provide all the info necessary for the solutions to compute the responses. For ex, if mass_flux 
Index: /issm/trunk/src/m/qmu/process_qmu_response_data.m
===================================================================
--- /issm/trunk/src/m/qmu/process_qmu_response_data.m	(revision 5486)
+++ /issm/trunk/src/m/qmu/process_qmu_response_data.m	(revision 5487)
@@ -16,5 +16,5 @@
 
 	%Do we have to process  mass flux profiles?
-	if strncmpi(md.responsedescriptors{i},'MassFlux',8),
+	if strncmpi(md.responsedescriptors{i},'indexed_MassFlux',16),
 		num_mass_flux=num_mass_flux+1;
 		process_mass_flux_profiles=1;
Index: /issm/trunk/src/m/qmu/qmumarshall.m
===================================================================
--- /issm/trunk/src/m/qmu/qmumarshall.m	(revision 5486)
+++ /issm/trunk/src/m/qmu/qmumarshall.m	(revision 5487)
@@ -21,13 +21,11 @@
 end
 
-%write number of variables to disk
+%deal with variables
 WriteData(fid,md.numberofvariables,'Integer','numberofvariables');
-
-%now, for each variable, write descriptor
-for i=1:numel(md.variabledescriptors),
+WriteData(fid,md.numvariabledescriptors,'Integer','numvariabledescriptors');
+for i=1:md.numvariabledescriptors,
 	field_name=md.variabledescriptors{i};
 	WriteData(fid,field_name,'String',['variabledescriptor' num2str(i)]);
 end
-
 
 %deal with responses
@@ -35,11 +33,9 @@
 %write number of responses to disk
 WriteData(fid,md.numberofresponses,'Integer','numberofresponses');
-
-%now, for each response, write descriptor
-for i=1:numel(md.responsedescriptors),
+WriteData(fid,md.numresponsedescriptors,'Integer','numresponsedescriptors');
+for i=1:md.numresponsedescriptors,
 	field_name=md.responsedescriptors{i};
 	WriteData(fid,field_name,'String',['responsedescriptor' num2str(i)]);
 end
-
 
 %write response specific data
@@ -48,5 +44,5 @@
 for i=1:numel(md.responsedescriptors),
 	field_name=md.responsedescriptors{i};
-	if strncmpi(field_name,'MassFlux',8),
+	if strncmpi(field_name,'indexed_MassFlux',16),
 		qmu_segments=1;
 	end
