#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define beta 0.1			
#define m 120000 			/* Number of rows*/
#define n 2                             /* number of columns*/
#define d 1	                /* number of processors*/
#define alpha1 -0.016
void main()
{	
/*------------------------Generation of Grid-------------------------------*/

int i,j, count, count2 , hd=1, s, p;
static float x2[m][n],x3[m][n], We[m], Fr[m], x4[m][n];
static double x1[m][n],  xmin;
double   beta1, rad, t_vis, rol, rog, beta2, alpha2, viscl, viscg, sten,g, t=0.000000,t_cap;
double  timet, x_non, y_non, t_non,t_non2, rom, t_nond, velo, Oh=20.0, ar=10;
        velo = 26.75;
        x1[1][1]=1 ;

  char name[80], name1[80];
for(s=1; ;s++){ 
//for (p=0; p<d; p++)
//{
  sprintf (name, "interface/interface_%0.6f_0.dat", t);
  sprintf (name1, "velo_at_x_10_t-%f.dat", t);
  printf ("%d \t %s \t %s \n", s, name, name1);



//FILE*	r1=fopen("volux.dat","r+");
 FILE*	r1=fopen(name,"r+");
//	r2=fopen("s0002200.dat","r+");
// FILE*	w1=fopen("visc_velo_Oh_20_l_h_10.dat","w+");
// FILE*	w2=fopen("velo_theoritical_l_h_10.dat","w+");
// FILE*	w3=fopen("velo_theory_modified_l_h_10.dat","w+");
 //FILE*   w1=fopen(name1,"w+");
  FILE*      w1=fopen("zmin_r_t.dat","a");
/*-------Reading----------------------------------*/
        count=1;
        count2=0;
        for(i=1;i<=m ;i++)
        {
         for(j=1;j<=n;j++)
	 {
            fscanf(r1,"%lf ", & x1[i][j]);
//             printf("%d \t %d \t %f \n",i,j, x1[i][j]);
            count=i;
            if (feof(r1)){ 
     printf("\n End of file reached. \n");
        printf("%d \t Count=%d \n", s, count);
        goto loop;
         } 
         }
        }
        loop:printf("Count=%d \n", count);

/*-----------Operation_to_Data-------------------------*/
//       alpha1 = -0.5 ;
/*       timet  =  2.52415806315*pow(10,-4);
       beta1  =  0.3 ;
       rad    =  6.3*pow(10,-4);
       viscl  =  pow(10,-3);
       viscg  =  1.82*pow(10,-5);
       rol    =  1376.85;
       rog    =  1.2;
       sten   =  14.62*pow(10,-3);
       g      =  9.81;
       t_cap  = sqrt((rol*rad*rad*rad)/sten);
       t_vis = ((4.0*rad*rad*(rol+rog))/(viscl+viscg));
       t_nond = 2*rad/velo;
              t_non = timet/t_vis;
              t_non = pow(t_non,alpha1); */
//      printf("%f \t%f \t %f \t %f \t %f \t %f \n",rol, rog, timet, viscl, viscg, t_cap);
   xmin=2;
    for(i=1;i<=count;i++)
        {
         if (x1[i][1] <  xmin ){
         count2 = i ;
	 xmin=x1[i][1];
        }
       }
printf("Row=%f \t %d \t %f \n", t, count2, xmin);
/*---------------------------------------------------*/

/*------------ Printing -----------------------------*/
	x1[count2][1] = 2.0*(x1[count2][1]/1);
	x1[count2][2] = x1[count2][2]/1;
        x1[count2][1]= (x1[count2][1] < 0.00000001*1) ? 0.00000001*1 : x1[count2][1] ; // to avoid zero value of xmin
        fprintf(w1, "%f \t %0.8f \t %0.8f", t, x1[count2][1], x1[count2][2]);
        fprintf(w1, "\n");
  if (x1[count2][1] <= 0.00000001) break;


fclose(r1);
fclose(w1);
//fclose(w2);
//fclose(w3);
//}
  t= t+0.000200;
  if (t>1.00) break;
}
}































