local path = pathtofile() -- initially we try to extract bf1 from the Bruker files local last = 1 while true do local slash = string.find( path, "/", last + 1 ) if not slash then break end last = slash end path = string.sub( path, 1, last ) -- path to the folder io.input( path.."acqus" ) local line, parameter repeat line = io.read("*line") parameter = string.sub( line, 1, 7 ) until parameter == "##$BF1=" -- unit = MHz local bf1 = tonumber( string.sub( line, 8, -1 ) ) -- we ask the other parameters to the user local xref = tonumber( ask "reference peak X frequency ?" ) local yref = tonumber( ask "reference peak Y frequency ?" ) local gammaB1 = tonumber( ask "gamma B1 ?" ) local r_ref = tonumber( ask "reference distance ?" ) local scale = getf() -- we get the central frequency from iNMR local w0 = scale.start + 0.5 * scale.width local N = intreg() -- number of integrals local val = {} local refval = 1 local wx = {} local wy = {} local A = {} gammaB1 = gammaB1 / bf1 -- we optimize by taking this division out of the next loop for i = 1,N do local area, left, right, bottom, top = intreg( i ) wx[i] = 0.5 * (left + right) wy[i] = 0.5 * (bottom + top) local ax = math.atan( gammaB1 / (wx[i] - w0) ) local ay = math.atan( gammaB1 / (wy[i] - w0) ) ax = math.sin( ax ) * math.sin( ay ) A[i] = area if area > 0 then val[i] = ( area / (ax * ax) )^(1/6) if xref < left and xref > right and yref < bottom and yref > top then refval = val[i] end end end clear() print "#\tx\ty\tarea\tdistance\n" local TAB = "\t" r_ref = r_ref * refval for i = 1,N do local distance = (A[i] <= 0) and 0 or r_ref / val[i] print( i, wx[i], wy[i], A[i], distance ) end