/*------scan sequences and prepare scores:-----------------------------------*/

/* Scan the reference sequence (horizontal scan): */
for (ref_residueI = ref_startI; ref_residueI <= ref_endI; ref_residueI++)
	{
	/* Scan the current working sequence (vertical scan): */
	for (residueI = startI; residueI <= endI; residueI++)
		{
		/* Reset score (the number of matching */
		/* residues in  the current  segment): */
		score = 0;

		/* Scan the current segment: */
		for (segmentI = 0; segmentI < segment_width; segmentI++)
			{
			/* Prepare and check shifted indices: */
			shifted_ref_residueI = ref_residueI + segmentI;
			if (shifted_ref_residueI > ref_endI) continue;
			shifted_residueI = residueI + segmentI;
			if (shifted_residueI > endI) continue;

			/* Prepare row and column index: */
			rowI = *(runtimeSP->residue_codeIP +
			       shifted_residueI);
			columnI = *(runtimeSP->reference_residue_codeIP +
				 shifted_ref_residueI);

			/* Compare codes: */
			if (!replacement_matrixAA[rowI][columnI]) continue;

			/* If this point is reached, increment score: */
			score++;
			}

		/* If the current score is lower than */
		/* the minimal score,  do not use it: */
		if (score < minimal_score) continue;

		/* If this point is reached, the current score is larger or */
		/* equal to the minimal score.  Compare new scores with old */
		/* scores associated with residues in  the current segment. */
		/* The NearestAtomS array is used as the buffer for scores. */
		for (segmentI = 0; segmentI < segment_width; segmentI++)
			{
			/* Prepare and check  the screen */
			/* position of the current pair: */
			screen_x0 = (int) square_width *
				    (ref_residueI + segmentI - ref_startI);
			if (screen_x0 > max_screen_x0) continue;
			screen_y0 = (int) square_height *
				    (residueI + segmentI - startI);
			if (screen_y0 > max_screen_y0) continue;

			/* Prepare and check the pixel index: */
			pixelI = guiSP->main_win_free_area_width * screen_y0 +
				 screen_x0;
			if (pixelI >= pixelsN) continue;

			/* Pointer to NearestAtomS structure */
			/* associated with the current pair: */
			curr_pixelSP = nearest_atomSP + pixelI;

			/* Compare scores: */
			if (curr_pixelSP->mol_complexI >= score) continue;

			/* If the new score  is better than */
			/* the old one it should be stored: */
			curr_pixelSP->mol_complexI = score;
			}
		}
	}

