%usage: val = get_num(str) %This program extracts a number from the NanoScope header line in str. %Jennifer R. Hampton 2/16/09 function val = get_num(str) %Information based on Appendix B "Data File Format" from the NanoScope %Command Reference Manual (Section B.6.3) %CAIO header lines start with '\@' and have the following format %\@X:Param: V [Soft-Scale] (Hard-Scale U) Hard-Value U %X is single-digit number (group number) %Param is the parameter label (may contain spaces) %V stands for value parameter %Soft-Scale is the soft-scale name %Hard-Scale and Hard-Value are numbers with units (usually V/LSB and V %respectively) %The group number, the soft-scale and/or the hard-scale may be missing %In these two cases of value parameters, the program will read the %hard-value into val %Case 1 (Hard-Scale U) is present in the line %Case 2 [Soft-Scale] (Hard-Scale U) are absent in the line %Non-CAIO parameters start with '\' and have the following format %\Param: Value U %Param is the parameter label (may contain spaces) %Value is the value (with or without units) %In this case (Case 3), the program will read the number into val lim1a = findstr(str,'('); lim1b = findstr(str,')'); lim2 = findstr(str,'V'); lim3 = findstr(str,':'); if length(lim1a)>0 %Case 1 -- extract number after ')' %substr = str(lim1a+1:lim1b-1); %valp = sscanf(substr,'%f %*s'); substr = str(lim1b+1:length(str)); val = sscanf(substr,'%f %*s'); elseif length(lim2)>0 %Case 2 -- extract number after 'V' substr = str(lim2+1:length(str)); val = sscanf(substr,'%f %*s'); else %Case 3 -- extract number after ':' substr = str(lim3+1:length(str)); val = sscanf(substr,'%f %*s'); end