Actual source code: smatlab.c

  1: /* $Id: smatlab.c,v 1.12 2001/03/23 23:20:30 balay Exp $ */

 3:  #include petsc.h
 4:  #include petscsys.h

  6: /*@C
  7:     PetscStartMatlab - starts up Matlab with a Matlab script

  9:     Collective on MPI_Comm, but only processor zero in the communicator does anything

 11:     Input Parameters:
 12: +     comm - MPI communicator
 13: .     machine - optional machine to run Matlab on
 14: -     script - name of script (without the .m)

 16:     Output Parameter:
 17: .     fp - a file pointer returned from PetscPOpen()

 19:     Level: intermediate

 21:     Notes: 
 22:      This overwrites your matlab/startup.m file

 24:      The script must be in your Matlab path or current directory

 26:      Assumes that all machines share a common file system

 28: .seealso: PetscPOpen(), PetscPClose()
 29: @*/
 30: int PetscStartMatlab(MPI_Comm comm,char *machine,char *script,FILE **fp)
 31: {
 32:   int  ierr;
 33:   FILE *fd;
 34:   char command[512];
 35: #if defined(PETSC_HAVE_UCBPS)
 36:   char buf[1024],*found;
 37:   int  rank;
 38: #endif


 42: #if defined(PETSC_HAVE_UCBPS)
 43:   /* check if Matlab is not already running */
 44:   PetscPOpen(comm,machine,"/usr/ucb/ps -ugxww | grep matlab | grep -v grep","r",&fd);
 45:   MPI_Comm_rank(comm,&rank);
 46:   if (!rank) {
 47:     found = fgets(buf,1024,fd);
 48:   }
 49:   MPI_Bcast(&found,1,MPI_CHAR,0,comm);
 50:   PetscFClose(comm,fd);
 51:   if (found) return(0);
 52: #endif

 54:   if (script) {
 55:     /* the remote machine won't know about current directory, so add it to Matlab path */
 56:     /* the extra " are to protect possible () in the script command from the shell */
 57:     sprintf(command,"echo "delete ${HOMEDIRECTORY}/matlab/startup.m ; path(path,'${WORKINGDIRECTORY}'); %s  " > ${HOMEDIRECTORY}/matlab/startup.m",script);
 58:     PetscPOpen(comm,machine,command,"r",&fd);
 59:     PetscFClose(comm,fd);
 60:   }

 62:   PetscPOpen(comm,machine,"xterm -display ${DISPLAY} -e matlab -nosplash","r",fp);

 64:   return(0);
 65: }