function [obsdata wavevector]=trimdata(spectra,cutoff,wavevector,maxcut);
	% removes data according to cutoff. Cutoff dictates the first wavelength to be included
	% This module will fail unless the wavelengths are in increasing order (fixed in 5/7 version)
	% maxcut added in 26/11/2012 to further trim data (upper range)

	tmp_spectra=size(spectra); %another hack forced by matlab
	tmp_wavevector=size(wavevector); %another hack forced by matlab

	if (or( (cutoff<2),(cutoff<min(wavevector)) ) )
		firstwavelength=2
	else
		ptsperlambda=(max(wavevector)-min(wavevector))/tmp_wavevector(2)
		firstwavelength=floor((cutoff-wavevector(1))/ptsperlambda)
		lastwavelength=floor((maxcut-wavevector(1))/ptsperlambda)
	end

	%prepare data
	if (firstwavelength>0) 
		obsdata=spectra(2:tmp_spectra(1),2+firstwavelength:tmp_spectra(2));
		wavevector= wavevector(firstwavelength+1:tmp_wavevector(2));
	else
			firstwavelength=floor((wavevector(1)-cutoff)/ptsperlambda)
			lastwavelength=floor((wavevector(1)-maxcut)/ptsperlambda)
%			obsdata=spectra(2:rows(spectra),1:firstwavelength);
			obsdata=spectra(2:tmp_spectra(1),lastwavelength:firstwavelength);
			wavevector= wavevector(lastwavelength:firstwavelength);
	end
	size(wavevector), size(obsdata)


end
