static void edit_files(char **fnms,int nfiles,real *readtime, real *timestep,
		       real *settime, int *cont_type, bool bSetTime,bool bSort)
{
    int i;
    bool ok;
    char inputstring[STRLEN],*chptr;
    
    if(bSetTime) {
	fprintf(stderr,"\n\nEnter the new start time (%s) for each file.\n"
		"There are two special options, both disable sorting:\n\n"
		"c (continue) - The start time is taken from the end\n"
		"of the previous file. Use it when your continuation run\n"
		"restarts with t=0.\n\n"
		"l (last) - The time in this file will be changed the\n"
		"same amount as in the previous. Use it when the time in the\n"
		"new run continues from the end of the previous one,\n"
		"since this takes possible overlap into account.\n\n",
		time_unit() );
	
	  fprintf(stderr,
	  "          File             Current start (%s)  New start (%s)\n"
		  "---------------------------------------------------------\n",
		  time_unit(), time_unit() );
	  
	  for(i=0;i<nfiles;i++) {
	      fprintf(stderr,"%25s   %10.3f %s          ",
		      fnms[i],convert_time(readtime[i]), time_unit());
	      ok=FALSE;
	      do {
		  if(NULL==fgets(inputstring,STRLEN-1,stdin))
		  {
		      gmx_fatal(FARGS,"Error reading user input");
	          }
 
		  inputstring[strlen(inputstring)-1]=0;

		  if(inputstring[0]=='c' || inputstring[0]=='C') {
		    cont_type[i]=TIME_CONTINUE;
		    bSort=FALSE;
		    ok=TRUE;
		    settime[i]=FLT_MAX;
		  }
		  else if(inputstring[0]=='l' ||
			  inputstring[0]=='L') {
		    cont_type[i]=TIME_LAST;
		    bSort=FALSE;
		    ok=TRUE;
		    settime[i]=FLT_MAX;			  
		  }
		  else {
		    settime[i]=strtod(inputstring,&chptr)*time_invfactor();
		    if(chptr==inputstring) {
		      fprintf(stderr,"'%s' not recognized as a floating point number, 'c' or 'l'. "
			      "Try again: ",inputstring);
		    }
		    else {
		      cont_type[i]=TIME_EXPLICIT;
		      ok=TRUE;
		    }
		  }
	      } while (!ok);
	  }
	  if(cont_type[0]!=TIME_EXPLICIT) {
	      cont_type[0]=TIME_EXPLICIT;
	      settime[0]=0;
	  }
    }
    else 
	for(i=0;i<nfiles;i++)
	    settime[i]=readtime[i];
    
    if(!bSort) 
	fprintf(stderr,"Sorting disabled.\n");
    else 
	sort_files(fnms,settime,nfiles);
    
    
    /* Write out the new order and start times */
    fprintf(stderr,"\nSummary of files and start times used:\n\n"
	    "          File                Start time       Time step\n"
	    "---------------------------------------------------------\n");
    for(i=0;i<nfiles;i++)
	switch(cont_type[i]) {
	case TIME_EXPLICIT:
	  fprintf(stderr,"%25s   %10.3f %s   %10.3f %s",
		  fnms[i],
		  convert_time(settime[i]),time_unit(),
		  convert_time(timestep[i]),time_unit());
	  if ( i>0 && 
	       cont_type[i-1]==TIME_EXPLICIT && settime[i]==settime[i-1] )
	    fprintf(stderr," WARNING: same Start time as previous");
	  fprintf(stderr,"\n");
	  break;
	case TIME_CONTINUE:
	  fprintf(stderr,"%25s        Continue from last file\n",fnms[i]);
	  break;	      
	case TIME_LAST:
	  fprintf(stderr,"%25s        Change by same amount as last file\n",
		  fnms[i]);
	  break;
	}
    fprintf(stderr,"\n");

    settime[nfiles]=FLT_MAX;
    cont_type[nfiles]=TIME_EXPLICIT;
    readtime[nfiles]=FLT_MAX;
}
Beispiel #2
0
static void edit_files(char **fnms, int nfiles, real *readtime,
                       real *settime, int *cont_type, gmx_bool bSetTime, gmx_bool bSort)
{
    int      i;
    gmx_bool ok;
    char     inputstring[STRLEN], *chptr;

    if (bSetTime)
    {
        if (nfiles == 1)
        {
            fprintf(stderr, "\n\nEnter the new start time:\n\n");
        }
        else
        {
            fprintf(stderr, "\n\nEnter the new start time for each file.\n"
                    "There are two special options, both disables sorting:\n\n"
                    "c (continue) - The start time is taken from the end\n"
                    "of the previous file. Use it when your continuation run\n"
                    "restarts with t=0 and there is no overlap.\n\n"
                    "l (last) - The time in this file will be changed the\n"
                    "same amount as in the previous. Use it when the time in the\n"
                    "new run continues from the end of the previous one,\n"
                    "since this takes possible overlap into account.\n\n");
        }

        fprintf(stderr, "          File             Current start       New start\n"
                "---------------------------------------------------------\n");

        for (i = 0; i < nfiles; i++)
        {
            fprintf(stderr, "%25s   %10.3f             ", fnms[i], readtime[i]);
            ok = FALSE;
            do
            {
                if (NULL == fgets(inputstring, STRLEN-1, stdin))
                {
                    gmx_fatal(FARGS, "Error reading user input");
                }
                inputstring[std::strlen(inputstring)-1] = 0;

                if (inputstring[0] == 'c' || inputstring[0] == 'C')
                {
                    cont_type[i] = TIME_CONTINUE;
                    bSort        = FALSE;
                    ok           = TRUE;
                    settime[i]   = FLT_MAX;
                }
                else if (inputstring[0] == 'l' ||
                         inputstring[0] == 'L')
                {
                    cont_type[i] = TIME_LAST;
                    bSort        = FALSE;
                    ok           = TRUE;
                    settime[i]   = FLT_MAX;
                }
                else
                {
                    settime[i] = strtod(inputstring, &chptr);
                    if (chptr == inputstring)
                    {
                        fprintf(stderr, "Try that again: ");
                    }
                    else
                    {
                        cont_type[i] = TIME_EXPLICIT;
                        ok           = TRUE;
                    }
                }
            }
            while (!ok);
        }
        if (cont_type[0] != TIME_EXPLICIT)
        {
            cont_type[0] = TIME_EXPLICIT;
            settime[0]   = 0;
        }
    }
    else
    {
        for (i = 0; i < nfiles; i++)
        {
            settime[i] = readtime[i];
        }
    }

    if (bSort && (nfiles > 1))
    {
        sort_files(fnms, settime, nfiles);
    }
    else
    {
        fprintf(stderr, "Sorting disabled.\n");
    }


    /* Write out the new order and start times */
    fprintf(stderr, "\nSummary of files and start times used:\n\n"
            "          File                Start time\n"
            "-----------------------------------------\n");
    for (i = 0; i < nfiles; i++)
    {
        switch (cont_type[i])
        {
            case TIME_EXPLICIT:
                fprintf(stderr, "%25s   %10.3f\n", fnms[i], settime[i]);
                break;
            case TIME_CONTINUE:
                fprintf(stderr, "%25s        Continue from end of last file\n", fnms[i]);
                break;
            case TIME_LAST:
                fprintf(stderr, "%25s        Change by same amount as last file\n", fnms[i]);
                break;
        }
    }
    fprintf(stderr, "\n");

    settime[nfiles]   = FLT_MAX;
    cont_type[nfiles] = TIME_EXPLICIT;
    readtime[nfiles]  = FLT_MAX;
}
Beispiel #3
0
// The main() function.  Inits OpenGL.  Calls our own init function,
// then passes control onto OpenGL.
int main(int argc,char **argv)
{
    if (argc < 2)
    {
        printf("Usage: %s <directory>\n", argv[0]);
        return 1;
    }

    strcpy(dirString, argv[1]);

    DIR  *dip, *dic;
    struct dirent *dit;
    int n;
    char *dir_and_file[MAX_PIC];

    if ((dip = opendir(argv[1])) == NULL || (dic = opendir(".")) == NULL)
    {
        fprintf(stderr, "can't open directory %s\n", argv[1]);
        return 1;
    }

    printid = 0;

    while((dit = readdir(dic)) != NULL)
    {
        if(strstr(dit->d_name, "out_") != NULL)
        {
            printid++;
        }
    }
    closedir(dic);

    NUM_PIC = 0;

    while ((dit = readdir(dip)) != NULL)
    {
        if(strstr(dit->d_name, ".JPG") != NULL || strstr(dit->d_name, ".jpg") != NULL || strstr(dit->d_name, ".jpeg") != NULL || strstr(dit->d_name, ".JPEG") != NULL)
        {
            dir_and_file[NUM_PIC] = malloc(100);
            strcpy(dir_and_file[NUM_PIC], argv[1]);
            strcat(dir_and_file[NUM_PIC], "/");
            strcat(dir_and_file[NUM_PIC], dit->d_name);
//       fd[NUM_PIC] = fopen(dir_and_file, "rb"); // Opens up the files in arbitiary order, no good
            NUM_PIC++;
//       printf("READ %s %d\n", dir_and_file[NUM_PIC-1], NUM_PIC - 1);
        }

    }

    n = 0;

    sort_files(dir_and_file, NUM_PIC);

//  for(n=0; n<NUM_PIC; n++);
    while(n<NUM_PIC)
    {
        fd[n] = fopen(dir_and_file[n], "rb");
//     printf("OPEN %s %d\n", dir_and_file[n], n);
        n++;
    }
    closedir(dip);


    glutInit(&argc, argv);

    // To see OpenGL drawing, take out the GLUT_DOUBLE request.
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(Window_Width, Window_Height);

    // Open a window
    Window_ID = glutCreateWindow( PROGRAM_TITLE );

    // Register the callback function to do the drawing.
    glutDisplayFunc(&cbRenderScene);

    // If there's nothing to do, draw.
    glutIdleFunc(&cbRenderScene);

    // It's a good idea to know when our window's resized.
    glutReshapeFunc(&cbResizeScene);

    // And let's get some keyboard input.
    glutKeyboardFunc(&cbKeyPressed);
    glutSpecialFunc(&cbSpecialKeyPressed);

    // Process mouse input
    glutMotionFunc(&cbMouseHeldMoving);
    glutMouseFunc(&cbMouseClick);
    glutPassiveMotionFunc(&cbMouseMoving);

    // OK, OpenGL's ready to go.  Let's call our own init function.
    ourInit(Window_Width, Window_Height);

    // Print out a bit of help dialog.
    printf("\n" PROGRAM_TITLE "\n\n\
Use arrow keys to move.\n\
Page up/down will move away from/towards camera.\n\n\
Use first letter of shown display mode settings to alter.\n\n\
Q or [Esc] to quit; OpenGL window must have focus for input.\n");

    // Pass off control to OpenGL.
    // Above functions are called as appropriate.
    glutMainLoop();

    return 1;
}
Beispiel #4
0
int main(int argc,char **argv)
{

   
   DIR  *dip, *dic;
   struct dirent *dit;
   int n,i;
   char *dir_and_file[2][MAX_PIC];
   
   for (i = 0; i< 2; i ++)
   {
     switch(i)
     {
     case 0: strcpy(dirString, "lf/"); break;
     case 1: strcpy(dirString, "land/"); break;
     case 2: strcpy(dirString, "path/"); break;
     default: strcpy(dirString, "lf/"); break;
     }
     
   if ((dip = opendir(dirString)) == NULL || (dic = opendir(".")) == NULL)
   {
     fprintf(stderr, "can't open directory %s\n", dirString);
     return 1;
   }
   
   
   NUM_PIC[i] = 0;
   
   while ((dit = readdir(dip)) != NULL)
   {
     if(strstr(dit->d_name, ".JPG") != NULL || strstr(dit->d_name, ".jpg") != NULL || strstr(dit->d_name, ".jpeg") != NULL || strstr(dit->d_name, ".JPEG") != NULL)
     {
       int index = NUM_PIC[i];
       dir_and_file[i][index] = malloc(100);
       strcpy(dir_and_file[i][index], dirString);
       strcat(dir_and_file[i][index], dit->d_name);
//       fd[NUM_PIC] = fopen(dir_and_file, "rb"); // Opens up the files in arbitiary order, no good
       NUM_PIC[i]++;
//       printf("READ %s %d\n", dir_and_file[NUM_PIC-1], NUM_PIC - 1);
     }

   }

   n = 0;

  sort_files(dir_and_file[i], NUM_PIC[i]);

//  for(n=0; n<NUM_PIC; n++);
   while(n<NUM_PIC[i])
   {
     fd[i][n] = fopen(dir_and_file[i][n], "rb");
//     printf("OPEN %s %d\n", dir_and_file[n], n);
     n++;
   }
   closedir(dip);

//   printf("%s %d\n", "done", NUM_PIC - 1);
 }
    
   glutInit(&argc, argv);
  

   // To see OpenGL drawing, take out the GLUT_DOUBLE request.
   glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
   glutInitWindowSize(Window_Width, Window_Height);

   // Open a window
   Window_ID = glutCreateWindow( "Light Field Viewer" );

   // Register the callback function to do the drawing.
   glutDisplayFunc(&cbRenderScene);

   // If there's nothing to do, draw.
   glutIdleFunc(&cbRenderScene);

   // It's a good idea to know when our window's resized.
   glutReshapeFunc(&cbResizeScene);


   //glutSpecialFunc(&cbSpecialKeyPressed);
   glutMouseFunc(&cbMouseClick);

   // OK, OpenGL's ready to go.  Let's call our own init function.
   ourInit(Window_Width, Window_Height);

   // Print out a bit of help dialog.
   printf("Light Field Viewer\n");

   // Pass off control to OpenGL.
   // Above functions are called as appropriate.
   glutMainLoop();

   return 1;
}