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: #undef __FUNCT__
8: /*@C
9: PetscStartMatlab - starts up Matlab with a Matlab script
11: Collective on MPI_Comm, but only processor zero in the communicator does anything
13: Input Parameters:
14: + comm - MPI communicator
15: . machine - optional machine to run Matlab on
16: - script - name of script (without the .m)
18: Output Parameter:
19: . fp - a file pointer returned from PetscPOpen()
21: Level: intermediate
23: Notes:
24: This overwrites your matlab/startup.m file
26: The script must be in your Matlab path or current directory
28: Assumes that all machines share a common file system
30: .seealso: PetscPOpen(), PetscPClose()
31: @*/
32: int PetscStartMatlab(MPI_Comm comm,char *machine,char *script,FILE **fp)
33: {
34: int ierr;
35: FILE *fd;
36: char command[512];
37: #if defined(PETSC_HAVE_UCBPS)
38: char buf[1024],*found;
39: int rank;
40: #endif
44: #if defined(PETSC_HAVE_UCBPS)
45: /* check if Matlab is not already running */
46: PetscPOpen(comm,machine,"/usr/ucb/ps -ugxww | grep matlab | grep -v grep","r",&fd);
47: MPI_Comm_rank(comm,&rank);
48: if (!rank) {
49: found = fgets(buf,1024,fd);
50: }
51: MPI_Bcast(&found,1,MPI_CHAR,0,comm);
52: PetscFClose(comm,fd);
53: if (found) return(0);
54: #endif
56: if (script) {
57: /* the remote machine won't know about current directory, so add it to Matlab path */
58: /* the extra " are to protect possible () in the script command from the shell */
59: sprintf(command,"echo "delete ${HOMEDIRECTORY}/matlab/startup.m ; path(path,'${WORKINGDIRECTORY}'); %s " > ${HOMEDIRECTORY}/matlab/startup.m",script);
60: PetscPOpen(comm,machine,command,"r",&fd);
61: PetscFClose(comm,fd);
62: }
64: PetscPOpen(comm,machine,"xterm -display ${DISPLAY} -e matlab -nosplash","r",fp);
66: return(0);
67: }