# Question:Using plot in routine

## Question:Using plot in routine

Maple

Hi,

I have to filter a load of analysis data and have written the following

> restart:
> with(plots):
> currentdir("C:\\Documents and Settings/Barry/My Documents/Synchrotron"):#Type in home folder of files to be converted
> mkdir(Trimmed);#Make new folder (if it doesn't already exist)
> lst1:=FileTools[ListDirectory](currentdir(), 'all','returnonly'="*.xy"): #list of files with xy suffix
> fd := fopen("Filenames.a",WRITE,TEXT):
> for h from 1 to 4 do: #nops(ls1)-1 int this example 82 files
> writeline(fd,lst1[h]): #writes file names to file Filenames.a)
> od:
> fclose(fd):
>
>
> #At this point the filenames have to be manually sorted into pairs for display (Sorry)
>
> for k from 1 to 2 do:
> f1:= cat(currentdir(),"\\",l1):print(f1);
> f2:= cat(currentdir(),"\\",l2):print(f2);
> fle1:=cat(currentdir(),"\\Trimmed\\",l1):
> fle2:=cat(currentdir(),"\\Trimmed\\",l2):
> c:=2:
> for a from 1 to 20 do:
> c:=c+1:
> if c > 1271 and c < 1299 then c:=1300 fi:
> if c > 2550 and c < 2577 then c:=2578 fi:
> if c > 3829 and c < 3857 then c:=3858 fi:
> if c > 5109 and c < 5137 then c:=5138 fi:
> if c > 6388 and c < 6416 then c:=6417 fi:
> if c = 7562 then c:=7563 fi:
> if c > 7667 and c < 7695 then c:=7696 fi:
> if c > 8946 and c < 8976 then c:=8977 fi:
> if c > 10226 and c < 10252 then c:=10253 fi:
> if c > 11504 and c < 11533 then c:=11534 fi:
> if c > 12784 and c < 12812 then c:=12813 fi:
> if c > 14064 and c < 14092 then c:=14093 fi:
> if c = 14901 and c < 14902 then c:=14903 fi:
> if c = 15155 then c:=15156 fi:
> if c > 15340 and c < 15369 then c:=15370 fi:
> if c > 16620 and c < 16648 then c:=16649 fi:
> if c > 17899 and c < 17927 then c:=17928 fi:
> if c > 19179 and c < 19207 then c:=19208 fi:
> if c = nops(A) then break fi:
> F:=A[c,1]:Q:=A[c,2]:
> fd1 := fopen(fle1, APPEND):
> fprintf(fd1,"%f %d\n",F,Q):
> fclose(fd1):
> od:
> c:=2:
> for a from 1 to 20 do:
> c:=c+1:
> if c > 1271 and c < 1299 then c:=1300 fi:
> if c > 2550 and c < 2577 then c:=2578 fi:
> if c > 3829 and c < 3857 then c:=3858 fi:
> if c > 5109 and c < 5137 then c:=5138 fi:
> if c > 6388 and c < 6416 then c:=6417 fi:
> if c = 7562 then c:=7563 fi:
> if c > 7667 and c < 7695 then c:=7696 fi:
> if c > 8946 and c < 8976 then c:=8977 fi:
> if c > 10226 and c < 10252 then c:=10253 fi:
> if c > 11504 and c < 11533 then c:=11534 fi:
> if c > 12784 and c < 12812 then c:=12813 fi:
> if c > 14064 and c < 14092 then c:=14093 fi:
> if c = 14901 and c < 14902 then c:=14903 fi:
> if c = 15155 then c:=15156 fi:
> if c > 15340 and c < 15369 then c:=15370 fi:
> if c > 16620 and c < 16648 then c:=16649 fi:
> if c > 17899 and c < 17927 then c:=17928 fi:
> if c > 19179 and c < 19207 then c:=19208 fi:
> if c = nops(A) then break fi:
> F:=A[c,1]:Q:=A[c,2]:
> fd2 := fopen(fle2, APPEND):
> fprintf(fd2,"%f %d\n",F,Q+5000):
> fclose(fd2):
> od:
>
> oput:=cat(l1,l2,"\.","eps");
> plotsetup(cps, plotoutput= oput,plotoptions=`landscape,noboarder`);
> plot({fd1L,fd2L},title= cat(Synchrotron_Trimmed_Data_Set_,value(fle1[-25..-20]),value(fle1[-10..-9]),_and_, value(fle2[-25..-20]),value(fle2[-10..-9])), style=point,color=[blue,red], labels=["2 Theta","Counts"]);
> interface(plotdevice=inline);
> od:
> fclose(fd):

So to explain, the folder has multiple files of various suffix. The routine reads in the names of the files with the xy suffix, and writes them to another file called Filenames.a

So far so good. The next routine consists of one big loop (which contains the plot command) and two smaller loops that handle the filtering (the files are to be presented in pairs on the same axis).
It filters great and writes a filtered version of the original file to a sub directory.

The problem is that the final 8 lines where I command Maple to write the resulting plot to an eps file fails.

If I move that 8 lines (less the od:) outside the loop, Maple produces an eps for only the last evaluated pair of datastreams.

This is causing me some headaches and sleepless nights so any help would be greatfully accepted.

Thanks
Barry

﻿