source: issm/oecreview/Archive/19101-20495/ISSM-19943-19944.diff

Last change on this file was 20498, checked in by Mathieu Morlighem, 9 years ago

CHG: done with Archive/19101-20495

File size: 9.2 KB
RevLine 
[20498]1Index: ../trunk-jpl/src/m/classes/plotoptions.js
2===================================================================
3--- ../trunk-jpl/src/m/classes/plotoptions.js (revision 19943)
4+++ ../trunk-jpl/src/m/classes/plotoptions.js (revision 19944)
5@@ -5,170 +5,169 @@
6
7 function plotoptions(args) {
8 //methods
9- this.disp = function (){ // {{{
10- console.log(sprintf('\nplotoptions = \n'));
11- console.log(sprintf(' figurenumber: %i',this.figurenumber));
12- console.log(sprintf(' numberofplots: %i',this.numberofplots));
13- if (this.list.length){
14- for (var i=0;i<this.list.length;i++){
15- console.log(sprintf('\n options of plot number %i',i+1));
16- this.list[i].disp();
17- }
18- }
19- else{
20- console.log(sprintf(' list: empty'));
21- }
22- }
23- //}}}
24- this.constructor = function (args){ // {{{
25+ this.disp = function (){ // {{{
26+ console.log(sprintf('\nplotoptions = \n'));
27+ console.log(sprintf(' figurenumber: %i',this.figurenumber));
28+ console.log(sprintf(' numberofplots: %i',this.numberofplots));
29+ if (this.list.length){
30+ for (var i=0;i<this.list.length;i++){
31+ console.log(sprintf('\n options of plot number %i',i+1));
32+ this.list[i].disp();
33+ }
34+ }
35+ else{
36+ console.log(sprintf(' list: empty'));
37+ }
38+ }
39+ //}}}
40+ this.constructor = function (args){ // {{{
41
42- //check length of input
43- if (args.length % 2){
44- for (i=0;i<args.length;i+=2){
45- if (!(typeof args[i] === 'string')){
46- console.log('Last valid option: ' + args[i-2]);
47- break;
48- }
49- }
50- throw Error('plotoptions error message: invalid parameter/value pair arguments');
51- }
52+ //check length of input
53+ if (args.length % 2){
54+ for (i=0;i<args.length;i+=2){
55+ if (!(typeof args[i] === 'string')){
56+ console.log('Last valid option: ' + args[i-2]);
57+ break;
58+ }
59+ }
60+ throw Error('plotoptions error message: invalid parameter/value pair arguments');
61+ }
62
63- //go through varargin and build list (like pairoptions)
64- var rawoptions=new pairoptions(args);
65- numoptions=rawoptions.numoptions();
66+ //go through varargin and build list (like pairoptions)
67+ var rawoptions=new pairoptions(args);
68+ numoptions=rawoptions.numoptions();
69
70- var counter=0;
71- for (i=0;i<numoptions;i++){
72- if(typeof args[2*i] === 'string')counter++;
73- }
74- rawlist=Create2DArray(counter,2);
75- var counter=0;
76- for (i=0;i<numoptions;i++){
77- optionname=args[2*i];
78- optionval=args[2*i+1];
79- if(typeof optionname === 'string'){
80- rawlist[counter][0]=optionname;
81- rawlist[counter][1]=optionval;
82- counter++;
83- }
84- else{
85- //option is not a string, ignore it
86- console.log(sprintf("%s%i%s\n",'WARNING: option number ',i,' is not a string, it will be ignored'));
87- rawlist[counter]=[];
88- continue
89- }
90- }
91-
92-
93- //get number of data to be plotted
94- numberofplots=rawoptions.fieldoccurrences('data');
95- this.numberofplots=numberofplots;
96+ var counter=0;
97+ for (i=0;i<numoptions;i++){
98+ if(typeof args[2*i] === 'string')counter++;
99+ }
100+ rawlist=Create2DArray(counter,2);
101+ var counter=0;
102+ for (i=0;i<numoptions;i++){
103+ optionname=args[2*i];
104+ optionval=args[2*i+1];
105+ if(typeof optionname === 'string'){
106+ rawlist[counter][0]=optionname;
107+ rawlist[counter][1]=optionval;
108+ counter++;
109+ }
110+ else{
111+ //option is not a string, ignore it
112+ console.log(sprintf("%s%i%s\n",'WARNING: option number ',i,' is not a string, it will be ignored'));
113+ rawlist[counter]=[];
114+ continue
115+ }
116+ }
117+
118+
119+ //get number of data to be plotted
120+ numberofplots=rawoptions.fieldoccurrences('data');
121+ this.numberofplots=numberofplots;
122
123- //figure out wether alloptions flog is on
124- if (rawoptions.getfieldvalue('alloptions','off') === 'on') allflag=1;
125- else allflag=0;
126+ //figure out wether alloptions flog is on
127+ if (rawoptions.getfieldvalue('alloptions','off') === 'on') allflag=1;
128+ else allflag=0;
129
130- //initialize list
131- var list=new Array(numberofplots);
132- for (i=0;i<numberofplots;i++){
133- list[i]=new pairoptions([]);
134- }
135-
136+ //initialize list
137+ var list=new Array(numberofplots);
138+ for (i=0;i<numberofplots;i++){
139+ list[i]=new pairoptions([]);
140+ }
141+
142 //process plot options
143- for(var i=0;i<rawlist.length;i++){
144+ for(var i=0;i<rawlist.length;i++){
145
146- //If alloptions flag has is on, apply to all plots
147- if (allflag & !(rawlist[i][0] === 'data') & (rawlist[i][0].indexOf('#') == -1)){
148- for(var j=0;j<numberofplots;j++){
149- list[j].addfield(rawlist[i][0],rawlist[i][1]);
150- }
151- }
152- else if (rawlist[i][0].indexOf('#') != -1){ //option contains '#'
153+ //If alloptions flag has is on, apply to all plots
154+ if (allflag & !(rawlist[i][0] === 'data') & (rawlist[i][0].indexOf('#') == -1)){
155+ for(var j=0;j<numberofplots;j++){
156+ list[j].addfield(rawlist[i][0],rawlist[i][1]);
157+ }
158+ }
159+ else if (rawlist[i][0].indexOf('#') != -1){ //option contains '#'
160
161- //get suplot(s) associated
162- string=rawlist[i][0].split('#');
163- plotnums=string[1];
164- field=string[0];
165+ //get suplot(s) associated
166+ string=rawlist[i][0].split('#');
167+ plotnums=string[1];
168+ field=string[0];
169
170- //divide plotnums if there is a comma ','
171- plotnums=plotnums.split(',');
172+ //divide plotnums if there is a comma ','
173+ plotnums=plotnums.split(',');
174
175- //loop over plotnums
176- for (k=0;k<plotnums.length;k++){
177- plotnum=plotnums[k];
178+ //loop over plotnums
179+ for (k=0;k<plotnums.length;k++){
180+ plotnum=plotnums[k];
181
182- //Empty
183- if (plotnum === '') continue;
184+ //Empty
185+ if (plotnum === '') continue;
186
187- else if (plotnum === 'all'){ //pound all
188- for(var j=0;j<numberofplots;j++){
189- list[j].addfield(field,rawlist[i][1]);
190- }
191- }
192- else if (plotnum.indexOf('-')!=-1){ //pound i-j
193- nums=plotnum.split('-');
194- if (nums.length!=2) continue;
195- if ((nums[0] == '') | (nums[1] === '')){
196- throw Error(sprintf("%s%s\n",'the option #i-j is not set properly for ',field));
197- }
198- for (j=(Number(nums[0])-1);j<(Number(nums[1])); j++){
199- list[j].addfield(field,rawlist[i][1]);
200- }
201- }
202- else{ //pound i
203- //assign to subplot
204- if (Number(plotnum)>numberofplots){
205+ else if (plotnum === 'all'){ //pound all
206+ for(var j=0;j<numberofplots;j++){
207+ list[j].addfield(field,rawlist[i][1]);
208+ }
209+ }
210+ else if (plotnum.indexOf('-')!=-1){ //pound i-j
211+ nums=plotnum.split('-');
212+ if (nums.length!=2) continue;
213+ if ((nums[0] == '') | (nums[1] === '')){
214+ throw Error(sprintf("%s%s\n",'the option #i-j is not set properly for ',field));
215+ }
216+ for (j=(Number(nums[0])-1);j<(Number(nums[1])); j++){
217+ list[j].addfield(field,rawlist[i][1]);
218+ }
219+ }
220+ else{ //pound i
221+ //assign to subplot
222+ if (Number(plotnum)>numberofplots){
223 throw Error(sprintf("%s%s%s%i%s\n",'plotoptions error message: ',field,' cannot be assigned (',plotnum,' exceeds maximum number of plot)'));
224- }
225- list[Number(plotnum)-1].addfield(field,rawlist[i][1]);
226- }
227- }
228- }
229- else{ //assign option field to corresponding subplot
230+ }
231+ list[Number(plotnum)-1].addfield(field,rawlist[i][1]);
232+ }
233+ }
234+ }
235+ else{ //assign option field to corresponding subplot
236
237-
238- //go through all subplot and assign to the first one free
239- var inc=0;
240-
241- while (inc<numberofplots){
242+
243+ //go through all subplot and assign to the first one free
244+ var inc=0;
245+
246+ while (inc<numberofplots){
247
248- if (!list[inc].exist(rawlist[i][0])){
249- list[inc].addfield(rawlist[i][0],rawlist[i][1]);
250- break
251- }
252- else inc++;
253- }
254+ if (!list[inc].exist(rawlist[i][0])){
255+ list[inc].addfield(rawlist[i][0],rawlist[i][1]);
256+ break
257+ }
258+ else inc++;
259+ }
260
261- if (inc>numberofplots-1){
262- console.log(sprintf("%s%s%s\n",'plot info message: too many ',rawlist[i][0],' options'));
263- }
264- }
265- }
266+ if (inc>numberofplots-1){
267+ console.log(sprintf("%s%s%s\n",'plot info message: too many ',rawlist[i][0],' options'));
268+ }
269+ }
270+ }
271
272- //check that there is no duplicates
273- for (var i=0;i<numberofplots;i++) list[i].deleteduplicates();
274+ //check that there is no duplicates
275+ for (var i=0;i<numberofplots;i++) list[i].deleteduplicates();
276
277- //allocate canvasid automatically
278- console.log(list);
279- for (var i=0;i<numberofplots;i++) {
280+ //allocate canvasid automatically
281+ for (var i=0;i<numberofplots;i++) {
282 if (!list[i].exist('canvasid')) {
283 list[i].addfield('canvasid',i);
284 }
285 }
286
287- //Get figure number (should be in options for subplot 1)
288- this.figurenumber=list[0].getfieldvalue('figure',1);
289- list[0].removefield('figure',0);
290+ //Get figure number (should be in options for subplot 1)
291+ this.figurenumber=list[0].getfieldvalue('figure',1);
292+ list[0].removefield('figure',0);
293
294- //asign output
295- this.list=list;
296+ //asign output
297+ this.list=list;
298
299- } //}}}
300- //properties
301- // {{{
302- this.numberofplots = 0;
303- this.figurenumber = 1;
304- this.list = [];
305- this.constructor(args);
306- //}}}
307+ } //}}}
308+ //properties
309+ // {{{
310+ this.numberofplots = 0;
311+ this.figurenumber = 1;
312+ this.list = [];
313+ this.constructor(args);
314+ //}}}
315 }
Note: See TracBrowser for help on using the repository browser.