! nob: number of observations
! no_it: number of ideal types
! no_cv: number of context variables
! no_des: number of design variables
      real config_c(10,15),config_d(10,15),xc(3000,15),xd(3000,15),fit(3000)
	  open (unit=7, file='d:\FitCalculate\ideal_type\itfout.txt')
	  open (unit=8, file='d:\FitCalculate\ideal_type\itfin.txt')
	  read (8,*) nob,no_it,no_cv,no_des
	  do 10 i=1,no_it
	     read(8,*) (config_c(i,j),j=1,no_cv),(config_d(i,j),j=1,no_des)
10 	  continue
      do 20 i=1,nob
	  	 read(8,*) (xc(i,j),j=1,no_cv),(xd(i,j),j=1,no_des)
		 sumt=99999999.
		 do 25 k=1,no_it
		    sc=0.
			sd=0.
		    do 30 k1=1,no_cv
			   sc= sc+ (xc(i,k1)-config_c(k,k1))**2.
30          continue
            do 40 k2=1,no_des
			   sd = sd +  (xd(i,k2)-config_d(k,k2))**2.
40          continue
            st= sc+sd
			if (st .lt. sumt)  sumt=st
25        continue			 
          fit(i)= -(sumt**0.5)
20    continue
      do 60 i=1,nob
	    write(7,66) fit(i)
66      format(1x,f10.4)
60    continue
	  end
