Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problem of plotting picture and video in Linux HPC

  1. Dec 3, 2015 #1


    User Avatar
    Gold Member

    I have a Matlab program that reads data file and then create avi. files and tiff pictures. It runs without problem in window OS using R2014a but cannot run in a Linux high performance computer(HPC).

    When the Matlab in Linux is started there are two warnings:
    Warning: No display specified. You will not be able to display graphics on the screen.
    Warning: No window system found. Java option 'Desktop' ignored.

    When I run my program there are two error messages:
    Error using getframe (line 53)
    getframe requires a valid figure window.

    Error in Density_3Dplot (line 93)
    writeVideo(vid, getframe(gcf)); %get the picture and put in the avi file with
    the handle "vid"

    When I run the program in window, pictures are displayed one by one and the command getframe and writeVideo are used to put the pictures into the avi file. However when I run it in a node in HPC nothing can be displayed. How can I modify my program so that it can be run in a system without display? Thanks a lot.

    I put my code here for your reference:
    clear; close all; clc;%clear all previous data
    fig = figure(1);%These two lines maximize the figure dialogue
    fig_color='w'; fig_colordef='white';
    cMap=jet(256);%set the colomap using the "jet" scale
    %The following defines an alternative colormap called cMap2 (from white to red)Nmap=64;
    cMin2 =[111];
    cMax2 =[100];
    cMap2 = zeros(Nmap,3);for i =1:Nmap;
    cMap2(i,:)= cMin2*(Nmap- i)/(Nmap-1)+ cMax2*(i -1)/(Nmap-1);end

    % cMap(1,:)=[111];
    edgeColor2='none';NumBoxX=100;%box number in x direction
    NumBoxY=100;%box number in y directionNumBoxZ=5;%box number in z directionFirstFile=0;%the number of the first file to be readFileInterval=400;%the number of intervals between filesLastFile=2000;%the number of the last file to be read34010ValCol=4;%indicate which column is used as value for plotting e.g. the 4th column is dis. density

    [MinDis,MaxDis]=Find_MaxMin(FirstFile,FileInterval,LastFile,ValCol);%Call the function to find min and max density,used to define the range of colorbar

    set(gcf,'Renderer','zbuffer');%eliminate unnecessary background and prevent stationary video -Important!
    vid =VideoWriter('Evolution.avi');%Create a avi file
    open(vid);%Open the avi file so that films can be put into it later on

    for ii=FirstFile:FileInterval:LastFile%Thisfor loop controls the sequential reading of data files
    ns = numel(num2str(ii));%Findout the number of digits of the number of file
    switch ns %The following converts the file name so that they can be used in fopen belowcase1%it's for one digit, 1,2 etc.
    filename = ['rho ' num2str(ii) '.dat'];
    case 2 %it's for two digits,10,20 etc.
    filename =['rho ' num2str(ii)'.dat'];case3%it's for three digits, 100,110 etc.
    filename = ['rho ' num2str(ii) '.dat'];
    case 4 %it's for4 digits
    filename =['rho ' num2str(ii)'.dat'];case5%it's for 5 digits
    filename = ['rho ' num2str(ii) '.dat'];

    fid = fopen(filename,'r');
    datacell = textscan(fid, '%f%f%f%f%f%f%f%f'); %There are 8 columns to be read so there are 8 %f

    all_data = cell2mat(datacell); %converted into a matrix containing all the dis. density info. for every simulation cell

    M=zeros(NumBoxX,NumBoxY,1); %create a matrix of 50x50x1,representing array of simulation cells M=zeros(NumBoxX,NumBoxY,NumBoxZ);
    % % the following loops assign the dislocation density from all_data to M
    for i=1:NumBoxX
    for j=1:NumBoxY
    for k=1:1 %for k=1:NumBoxZ Only the middle plate is shown
    % if all_data(num,ValCol)<1e13
    % all_data(num,ValCol)=0;
    % end
    M(i,j,k)=all_data(num,ValCol); %the ValCol column of all_data is dislocation density

    [F,V,C]=ind2patch(indPatch,M,'v'); %Call the function ind2patch in order to plot 3D cube with color
    title('adfdadasfdasf','fontsize',20);%set title \sigma_{xx}
    xlabel('y','fontsize',15);ylabel('x','fontsize',15); zlabel('z','fontsize',20); hold on;
    set(get(gca,'xlabel'),'Position',[50 -10 30]); %set position of axis label
    set(get(gca,'ylabel'),'Position',[-3 50 -15]);
    % set(get(gca,'zlabel'),'Position',[64 190 -60]);
    axis equal; view(90,-90); axis tight; axis vis3d; grid off;
    caxis([MinDis MaxDis]); %set the range of the colorbar MinDis MaxDis %caxis([min(M(:)) max(M(:))]); %range of the colorbar according to one file only
    cb = colorbar; % create the colorbar
    set(get(cb,'title'),'string','dfdfdfd(m^{-2})','fontsize',20); % label the colorbar Stress (MPa)

    lbpos = get(cb,'title'); % get the handle of the colorbar title

    writeVideo(vid, getframe(gcf)); %get the picture and put in the avi file with the handle "vid"

    title('aaaaa','fontsize',10);%set title \sigma_{xx}
    set(get(cb,'title'),'string','aaaaa(m^{-2})','fontsize',10); % label the colorbar Stress (MPa)
    picturename = ['aaaaa' num2str(ii) ]; % set the name of the picture with number
    print(fig,picturename,'-dtiff');%save the picture in choosen format '-djpeg' | '-dpng' | '-dtiff' | '-dpdf' | '-deps' | ...


    close(vid); %close the avi file after putting all the films into it
    Last edited: Dec 4, 2015
  2. jcsd
  3. Dec 4, 2015 #2
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook