File: xawelm.f

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (865 lines) | stat: -rw-r--r-- 27,517 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
      subroutine xawelm
c     =============================================================
c     Primitives for scilab menus 
c     =============================================================
c     Copyright ENPC 
      include '../stack.h'
      external setmen, unsmen
      if (ddt .eq. 4) then
         write(buf(1:4),'(i4)') fin
         call basout(io,wte,' xawelm '//buf(1:4))
      endif
c     
      if(fin.eq.1) then
         call scidialog("x_dialog")
      endif
      if(fin.eq.2) then
         call scimess("x_message")
      endif
      if(fin.eq.3) then
         call scichoose("x_choose")
      endif
      if(fin.eq.4) then
         call scimdial("x_mdialog")
      endif
      if(fin.eq.7) then
         call scichoice("choices")
      endif
      if (fin .eq. 8) then
         call sciaddm("addmenu_old")
      endif
      if (fin .eq. 9) then
         call scidellm("delmenu_old")
      endif
      if (fin .eq. 10 ) then 
         call scisetum("setmenu_old",setmen)
      endif
      if (fin.eq.11) then 
         call scisetum("unsetmenu_old",unsmen)
      endif
      if (fin.eq.12) then
         call intsxgetfile("xgetfile")
      endif
      if (fin.eq.13) then
         call scimess1("x_message_modeless")
      endif
 9999 return
      end

      subroutine sciaddm(fname)
C     ================================================================
C     SCILAB function : addmenu
C     ================================================================ 
      character*(*) fname
c      implicit undefined (a-z)
      include '../stack.h'
      logical getsmat,getscalar,getwsmat
      logical full,checklhs,checkrhs
      logical getilist,getlistscalar,getlistsimat
      integer topk,lr,typ,verb,iwin,owin,iadr,sadr
      double precision dv 
      character*(nlgh+1) mname
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1

      call xscion(inxsci)
c      if (inxsci.eq.0) then
c         buf='synchronous actions are not supported with -nw option'
c         call error(1020)
c         return
c      endif
      if (.not.checkrhs(fname,1,4)) return
      if (.not.checklhs(fname,1,1)) return
      topk = top
c     checking last variable
      ill=iadr(lstk(top))
      if(istk(ill).eq.15) then
         full=.true.
c        .last variable is list(typ,mname)
         if(.not.getilist(fname,topk,top,n1,1,il1)) return
         if(n1.ne.2) then
            buf='Last argument of addmenu must be list(typ,mname)'
            call error(9990)
            return
         endif
c        --   list element number 1 typ(g) --
         if(.not.getlistscalar(fname,topk,top,1,lr1e1)) return
         typ = int(stk(lr1e1))
c        --   list element number 2 name(g) --
         if(.not.getlistsimat(fname,topk,top,2,m1e2,n1e2,1,1,
     $        lr1e2,nlr1e2)) return
         if( m1e2*n1e2.ne.1) then 
            buf='Last argument of addmenu must be list(typ,mname)'
            call error(9990)
            return
         endif
         if ( nlr1e2+1 .gt. nlgh ) then 
            buf = 'Last argument list(typ,mname) : mname too long'
            call error(9990)
            return
         endif
         call cvstr(nlr1e2,istk(lr1e2),mname,1)
         mname(nlr1e2+1:nlr1e2+1)=char(0)
      else
         typ=0
         full=.false.
      endif

c     checking variable win (number 1)

      il1 = iadr(lstk(top-rhs+1))
      if (istk(il1) .eq. 1) then
c     in a graphic window
         if(.not.getscalar(fname,topk,top-rhs+1,lr))return
         iwin = int(stk(lr))
         iskip = 0
         elseif (istk(il1).eq.10) then
c      if -nw mode main window does not exists - error
        if (inxsci.eq.0) then
         buf='No main graphic window in -nw mode, specify 1-th arg...'
          call error(1020)
          return
         endif
c     in main window
         iskip =1
         iwin =-1
      else
         err = 1
         call error(44)
         return
      endif

c     checking variable name (number 2-iskip)

      if(.not.getsmat(fname,top,top-rhs+2-iskip,m2,n2,1,1,lr2,nlr2))
     $     return
      call cvstr(nlr2,istk(lr2),buf,1)
      buf(nlr2+1:nlr2+1)=char(0)
      if (.not.full ) then 
         mname = buf(1:nlr2+1)
      endif

      if (rhs.ge.3-iskip) then
         il1 = iadr(lstk(top-rhs+3-iskip))
c        checking variable submenu names (number 3-iskip)
         if ( istk(il1).ne.15 ) then 
            if (.not.getwsmat(fname,topk,top-rhs+3-iskip,m3,n3,
     $           il3,ild3))           return
            if (m3.ne.1.and.n3.ne.1) then 
               buf= fname// ': Third argument must be a vector'
               call error(999)
               return
            endif
            top=top-rhs+1
            verb=0
            if(iwin.ge.0) then
               call dr('xget'//char(0),'window'//char(0),verb,owin,na,
     $              v,v,v,dv,dv,dv,dv)
               call dr('xset'//char(0),'window'//char(0),iwin,iv,iv,
     $              v,v,v,dv,dv,dv,dv)
               call addmen(iwin,buf,istk(il3),istk(ild3),m3*n3,typ,
     $              mname, ierr) 
               call dr('xset'//char(0),'window'//char(0),owin,iv,iv,
     $              v,v,v,dv,dv,dv,dv)
            else
               call addmen(iwin,buf,istk(il3),istk(ild3),m3*n3,typ, 
     $              mname,         ierr) 
            endif
            call objvide(fname,top)
            return
         endif
      endif
      top=top-rhs+1
      verb=0
      if(iwin.ge.0) then
         call dr('xget'//char(0),'window'//char(0),verb,owin,na,
     $        v,v,v,dv,dv,dv,dv)
         call dr('xset'//char(0),'window'//char(0),iwin,iv,iv,
     $        v,v,v,dv,dv,dv,dv)
         call addmen(iwin,buf,0,0,0,typ, mname,ierr)
         call dr('xset'//char(0),'window'//char(0),owin,iv,iv,
     $        v,v,v,dv,dv,dv,dv)
      else
         call addmen(iwin,buf,0,0,0,typ,mname,ierr)
      endif
      call objvide(fname,top)
      return
      end







      subroutine scidellm(fname)
C     ================================================================
C     SCILAB function : dellmenu 
C     ================================================================ 
      character*(*) fname
c      implicit undefined (a-z)
      include '../stack.h'
      logical checkrhs,getsmat,getscalar
      integer topk,m,n,lr,nlr
      call xscion(inxsci)
c      if (inxsci.eq.0) then
c         return
c      endif
      if (.not.checkrhs(fname,1,2)) return
      topk = top
      if (.not.getsmat(fname,topk,top,m,n,1,1,lr,nlr)) return
      call  cvstr(nlr,istk(lr),buf,1)
      buf(nlr+1:nlr+1)=char(0)
      if ( rhs.eq.2 ) then 
         top = top-1 
         if(.not.getscalar(fname,topk,top,lr))return
         iwin=int(stk(lr))
      else
c      if -nw mode main window does not exists - error
        if (inxsci.eq.0) then
         buf='No main graphic window in -nw mode, specify 1-th arg...'
          call error(1020)
          return
         endif
       iwin=-1
      endif
c     next two lines for compatibility "2D Zoom" button renamed in "Zoom"
      if (buf(1:7).eq.'2D Zoom') buf='Zoom'//char(0)
      if (buf(1:8).eq.'2D &Zoom') buf='&Zoom'//char(0)

      call delbtn(iwin,buf)
      call objvide(fname,top)
      return
      end

      subroutine scisetum(fname,func)
C     ================================================================
C     SCILAB function :  setmenu, unsetmenu,
C     ================================================================ 
      character*(*) fname
c      implicit undefined (a-z)
      include '../stack.h'
      logical checkrhs,getsmat,getscalar
      integer topk,m,n,lr,nlr,gettype
      external func
      call xscion(inxsci)
c      if (inxsci.eq.0) then
c         return
c      endif
      if (.not.checkrhs(fname,1,3)) return
      topk = top
      nsub=0
      itype = gettype(top-rhs+1)
      if ( itype.eq.1 ) then 
         if (.not.checkrhs(fname,2,3)) return
         if (rhs.eq.3 ) then 
            if(.not.getscalar(fname,topk,top,lr))return
            nsub = int(stk(lr))
            top = top -1 
         endif
         if (.not.getsmat(fname,topk,top,m,n,1,1,lr,nlr)) return
         call  cvstr(nlr,istk(lr),buf,1)
         buf(nlr+1:nlr+1)=char(0)
         top = top-1
         if (.not.getscalar(fname,topk,top,lr)) return
         iwin = int(stk(lr))
      else
         if (.not.checkrhs(fname,1,2)) return
c      if -nw mode main window does not exists - error
        if (inxsci.eq.0) then
         buf='No main graphic window in -nw mode, specify 1-th arg...'
          call error(1020)
          return
         endif
         iwin = -1
         if ( rhs.eq.2 ) then 
            if(.not.getscalar(fname,topk,top,lr))return
            nsub = int(stk(lr))
            top = top -1 
         endif
         if (.not.getsmat(fname,topk,top,m,n,1,1,lr,nlr)) return
         call  cvstr(nlr,istk(lr),buf,1)
         buf(nlr+1:nlr+1)=char(0)
      endif
      call func(iwin,buf,0,0,nsub,ierr)
      call objvide(fname,top)
      return
      end


      subroutine scichoice(fname)
C     ================================================================
c     SCILAB function : x_choices
C     ================================================================ 
      character*(*) fname
cc    implicit undefined (a-z)
      include '../stack.h'
      integer topk,m1,n1,lr1,il1,iadr,sadr
      integer m3,n3,il3,ild3,m2,n2,il2,ild2,rep
      logical getrvect,getwsmat,checkrhs
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
      if (.not.checkrhs(fname,3,3)) return
      topk=top
C     third argument is a string vector 
      if (.not.getwsmat(fname,topk,top,m3,n3,il3,ild3)) return
      if (m3.ne.1.and.n3.ne.1) then 
         buf= fname// ': Third argument must be a vector'
         call error(999)
         return
      endif
      top=top-1
C     third argument is a string matrix 
      if (.not.getwsmat(fname,topk,top,m2,n2,il2,ild2)) return
      top=top-1
c     first argument is an int vector
      if(.not.getrvect(fname,topk,top,m1,n1,lr1))return      
      il1=iadr(lr1)
      call entier(m1*n1,stk(lr1),istk(il1))
      call xchoices(istk(il2),istk(ild2),m2*n2,
     $     istk(il3),istk(ild3),m3*n3, istk(il1),m1*n1,rep)
      if(rep.eq.-1) then 
         buf= fname// ': Error'
         call error(999)
         return
      endif
      if(rep.eq.0) then
c     return an empty matrix when canceled  
         il1=iadr(lstk(top))
         istk(il1)=1
         istk(il1+1)=0
         istk(il1+2)=0
         istk(il1+3)=0
         lstk(top+1)=sadr(il1+4)
      else
         call entier2d(m1*n1,stk(lr1),istk(il1))
      endif
      return
      end


      subroutine scidialog(fname)
C     ================================================================
c     SCILAB function : x_dialog 
C     ================================================================
      character*(*) fname
cc      implicit undefined (a-z)
      include '../stack.h'
      integer topk,iadr,isize(2),sadr
      integer m3,n3,il3,ild3,nlr3,m2,n2,il2,ild2,m1,n1,il1,ild1
      logical getwsmat,checkrhs,cresmat1,cresmat2
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
      if (.not.checkrhs(fname,1,2)) return
      topk=top
C     creation of extra arguments
C     size of 'OK' and 'Cancel'
      isize(1) = 2
      isize(2) = 6 
C     2nd argument if missing 
      if (rhs.lt.2) then 
         top  = top+1
         nlr2 = 1
         if(.not.cresmat2(fname,top,nlr2,lr2)) return
         call cvstr(nlr2,istk(lr2),' ',0)
      endif
C     we create ['OK';'Cancel'] 
      top = top+1 
      if (.not.cresmat1(fname,top,2,isize)) return
      call getsimat(fname,top,top,m3,n3,2,1,lr3,nlr3)
      call cvstr(isize(2),istk(lr3),'Cancel',0)
      call getsimat(fname,top,top,m3,n3,1,1,lr3,nlr3)
      call cvstr(isize(1),istk(lr3),'OK',0)
      if (.not.getwsmat(fname,topk,top,m3,n3,il3,ild3)) return
      top = top-1
C     second argument is a string vector
      if (.not.getwsmat(fname,topk,top,m2,n2,il2,ild2)) return
      if (m2.ne.1.and.n2.ne.1) then 
         buf= fname// ': Second argument must be a vector'
         call error(999)
         return
      endif
      top=top-1
C    first argument is a string vector 
      if (.not.getwsmat(fname,topk,top,m1,n1,il1,ild1)) return
      if (m1.ne.1.and.n1.ne.1) then 
         buf= fname// ': First argument must be a vector'
         call error(999)
         return
      endif
C     using the whole stack from top to bottom 
C     to get back the result 
C     (we can use top since the top objet is used before being 
C     scratched 
C     we MUST use ierr inside xdialg to check for space 
      ilmes=iadr(lstk(top))
      nrep=200
      ilw=ilmes+4+nrep+1
      ierr=iadr(lstk(bot))-ilw
      call xdialg(istk(il2),istk(ild2),m2*n2,
     $     istk(il1),istk(ild1),m1*n1,
     $     istk(il3),istk(ild3),m3*n3,
     $     istk(ilw),istk(ilmes+4),nrep,ierr)
      if(ierr.eq.3) then
         call error(113)
         return
      elseif(ierr.eq.2) then
         call error(17)
         return
      elseif(ierr.eq.1) then
         call error(112)
         return
      endif
      if(nrep.eq.0) then
         istk(ilmes)=1
         istk(ilmes+1)=0
         istk(ilmes+2)=0
         istk(ilmes+3)=0
         lstk(top+1)=sadr(ilmes+4)
      else
         istk(ilmes)=10
         istk(ilmes+1)=nrep
         istk(ilmes+2)=1
         il = ilmes+5+nrep
         call icopy(istk(il-1)-1,istk(ilw),1,istk(il),1)
         lstk(top+1)=sadr(il +istk(il-1))
      endif
      return
      end



      subroutine scimdial(fname)
C     ================================================================
c     SCILAB function : x_dialog 
C     ================================================================
      character*(*) fname
cc      implicit undefined (a-z)
      include '../stack.h'
      integer topk,iadr,sadr
      integer m3,n3,il3,ild3,m2,n2,il2,ild2,m1,n1,il1,ild1
      logical getwsmat,checkrhs
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
      if (.not.checkrhs(fname,3,4)) return
      topk=top
      if (rhs.eq.4) then 
         if (.not.getwsmat(fname,topk,top,m4,n4,il4,ild4)) return
         top  = top-1
      endif
      if (.not.getwsmat(fname,topk,top,m3,n3,il3,ild3)) return
      if (m3.ne.1.and.n3.ne.1) then 
         buf= fname// ': third argument must be a vector'
         call error(999)
         return
      endif
      top = top-1
      if (.not.getwsmat(fname,topk,top,m2,n2,il2,ild2)) return
      if (m2.ne.1.and.n2.ne.1) then 
         buf= fname// ': second argument must be a vector'
         call error(999)
         return
      endif
      top=top-1
      if (.not.getwsmat(fname,topk,top,m1,n1,il1,ild1)) return
      if (m1.ne.1.and.n1.ne.1) then 
         buf= fname// ': First argument must be a vector'
         call error(999)
         return
      endif
      if ( rhs.eq.4) then 
         if ( m2*n2.ne.m4 ) then 
            buf= fname// ': incompatible second and fourth argument'
            call error(999)
            return
         endif
         if ( m3*n3.ne.n4 ) then 
            buf= fname// ': incompatible third and fourth argument'
            call error(999)
            return
         endif
      endif
      if ( rhs.eq.3) then 
         if ( m3*n3.ne.m2*n2 ) then 
            buf= fname// ': incompatible second and third argument'
            call error(999)
            return
         endif
      endif

C     (we can use top since the top objet is used before being 
C     scratched 
C     we MUST use ierr inside xdialg to check for space 
      ilres=iadr(lstk(top))
      if (rhs.eq.4 ) then 
         mres = m4
         nres = n4
         ilw=ilres+4+m4*n4+1
         ierr=iadr(lstk(bot))-ilw
         call xmatdg(istk(il1),istk(ild1),m1*n1,
     $        istk(il4),istk(ild4),
     $        istk(il2),istk(ild2),
     $        istk(il3),istk(ild3),mres,nres,
     $        istk(ilw),istk(ilres+4),ierr)
      else
         mres=m2*n2
         nres=1
         ilw=ilres+4+m3*n3+1
         ierr=iadr(lstk(bot))-ilw
         call xmdial(istk(il1),istk(ild1),m1*n1,
     $        istk(il3),istk(ild3),
     $        istk(il2),istk(ild2),mres,
     $        istk(ilw),istk(ilres+4),ierr)
      endif
      if(ierr.eq.3) then
         call error(113)
         return
      elseif(ierr.eq.2) then
         call error(17)
         return
      elseif(ierr.eq.1) then
         call error(112)
         return
      endif
      if(mres.eq.0) then
         istk(ilres)=1
         istk(ilres+1)=0
         istk(ilres+2)=0
         istk(ilres+3)=0
         lstk(top+1)=sadr(ilres+4)
      else
         istk(ilres)=10
         istk(ilres+1)=mres
         istk(ilres+2)=nres
         istk(ilres+3)=0
         lstk(top+1)=sadr(ilres+5+mres*nres+istk(ilres+4+nres*mres))
         return
      endif
      return
      end


      subroutine scimess(fname) 
C     ================================================================
c     SCILAB function : xmessage 
C     ================================================================
      character*(*) fname
cc      implicit undefined (a-z)
      include '../stack.h'
      integer topk,iadr,sadr
      integer m2,n2,il2,ild2,m1,n1,il1,ild1
      logical getwsmat,checkrhs,cresmat2
      logical cremat
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
      if (.not.checkrhs(fname,1,2)) return
      topk=top
C     creation of extra arguments
C     2nd argument if missing 
      if (rhs.lt.2) then 
         top  = top+1
         nlr2 = 2
         if(.not.cresmat2(fname,top,nlr2,lr2)) return
         call cvstr(nlr2,istk(lr2),'Ok',0)
      endif
C     second argument is a string vector
      if (.not.getwsmat(fname,topk,top,m2,n2,il2,ild2)) return
      if (m2.ne.1.and.n2.ne.1) then 
         buf= fname// ': Second argument must be a vector'
         call error(999)
         return
      endif
      top=top-1
C     first argument is a string vector 
      if (.not.getwsmat(fname,topk,top,m1,n1,il1,ild1)) return
      if (m1.ne.1.and.n1.ne.1) then 
         buf= fname// ': First argument must be a vector'
         call error(999)
         return
      endif
      call xmsg(istk(il1),istk(ild1),m1*n1,
     $     istk(il2),istk(ild2),m2*n2,nrep,ierr)
      if(ierr.eq.1) then 
         call error(112)
         return
      endif
      if(m2*n2.eq.1) then
         call objvide(fname,top)
      else
         if (.not.cremat(fname,top,0,1,1,lr1,lc)) return
         stk(lr1)= nrep
      endif
      return
      end

      subroutine scimess1(fname) 
C     ================================================================
c     SCILAB function : xmessage 
C     ================================================================
      character*(*) fname
cc      implicit undefined (a-z)
      include '../stack.h'
      integer topk,iadr,sadr
      integer m2,n2,il2,ild2,m1,n1,il1,ild1
      logical getwsmat,checkrhs,cresmat2
      logical cremat
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
      if (.not.checkrhs(fname,1,1)) return
      topk=top
C     creation of extra arguments
C     add button name
      if (rhs.lt.2) then 
         top  = top+1
         nlr2 = 2
         if(.not.cresmat2(fname,top,nlr2,lr2)) return
         call cvstr(nlr2,istk(lr2),'Ok',0)
      endif
C     second argument is a string vector
      if (.not.getwsmat(fname,topk,top,m2,n2,il2,ild2)) return
      if (m2.ne.1.or.n2.ne.1) then 
         buf= fname// ': Second argument must be a string'
         call error(999)
         return
      endif
      top=top-1
C     first argument is a string vector 
      if (.not.getwsmat(fname,topk,top,m1,n1,il1,ild1)) return
      if (m1.ne.1.and.n1.ne.1) then 
         buf= fname// ': First argument must be a vector'
         call error(999)
         return
      endif
      call xmsg1(istk(il1),istk(ild1),m1*n1,
     $     istk(il2),istk(ild2),m2*n2,ierr)
      if(ierr.eq.1) then 
         call error(112)
         return
      endif
      call objvide(fname,top)
      end

      subroutine scichoose(fname) 
C     ================================================================
c     SCILAB function : x_choose
C     ================================================================
      character*(*) fname
cc      implicit undefined (a-z)
      include '../stack.h'
      integer topk,iadr,sadr
      integer m3,n3,il3,ild3,m2,n2,il2,ild2,m1,n1,il1,ild1
      logical getwsmat,checkrhs,cresmat2
      logical cremat
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
      if (.not.checkrhs(fname,2,3)) return
      topk=top
      if(rhs.eq.2) then
C     Create button list ( just Cancel in fact ) 
         top  = top+1
         nlr2 = 6
         if(.not.cresmat2(fname,top,nlr2,lr2)) return
         call cvstr(nlr2,istk(lr2),'Cancel',0)
      endif
      if (.not.getwsmat(fname,topk,top,m3,n3,il3,ild3)) return
      top = top -1 
C     second argument is a string vector
      if (.not.getwsmat(fname,topk,top,m2,n2,il2,ild2)) return
      if (m2.ne.1.and.n2.ne.1) then 
         buf= fname// ': Second argument must be a vector'
         call error(999)
         return
      endif
      top=top-1
C     first argument is a string vector 
      if (.not.getwsmat(fname,topk,top,m1,n1,il1,ild1)) return
      if (m1.ne.1.and.n1.ne.1) then 
         buf= fname// ': First argument must be a vector'
         call error(999)
         return
      endif
      call xchoose(istk(il2),istk(ild2),m2*n2,
     $     istk(il1),istk(ild1),m1*n1,
     $     istk(il3),istk(ild3),m3*n3,nrep,ierr)
      if(ierr.eq.1) then 
         call error(112)
         return
      endif
      if (.not.cremat(fname,top,0,1,1,lr1,lc)) return
      stk(lr1)= nrep
      return
      end


      subroutine intsxgetfile(fname)
C     ================================================================
c     SCILAB function : xgetfile, fin = 1
C     ================================================================
       character*(*) fname
       integer topk,rhsk,topl
       logical checkrhs,checklhs,cresmat2,getsmat,checkval,bufstore
       logical crepointer,crestring,isoptlw,getwsmat
       include '../stack.h'
       character name*(nlgh)
c
       integer iadr, sadr
       iadr(l)=l+l-1
       sadr(l)=(l/2)+1
       rhs = max(0,rhs)
c
       lbuf = 1
       topk = top 
       rhsk = rhs 
       if(.not.checkrhs(fname,0,3)) return
       if(.not.checklhs(fname,1,1)) return
c       checking variable a (number 1)
c       
       if(rhs .le. 0) then
        top = top+1
        rhs = rhs+1
        nlr1 = 3
        if(.not.cresmat2(fname,top,nlr1,lr1)) return
        call cvstr(nlr1,istk(lr1),'*.*',0)
       endif
c       checking variable dirname (number 2)
c       
       if(rhs .le. 1) then
        top = top+1
        rhs = rhs+1
        nlr2 = 1
        if(.not.cresmat2(fname,top,nlr2,lr2)) return
        call cvstr(nlr2,istk(lr2),'.',0)
       endif

       if(rhs .le. 2) then
        top = top+1
        rhs = rhs+1
        nlr3 = 9
        if(.not.cresmat2(fname,top,nlr3,lr3)) return
        call cvstr(nlr3,istk(lr3),'File menu',0)
       endif

       if(.not.crepointer(fname,top+1,lw3)) return


       if (rhsk.eq.3) then 
          idir=1
          if(.not.getsmat(fname,top,top-rhs+1,m1,n1,1,1,lr1,nlr1))
     $         return
          if(.not.checkval(fname,m1*n1,1)) return
          if(.not.bufstore(fname,lbuf,lbufi1,lbuff1,lr1,nlr1)) return

          if(.not.getsmat(fname,top,top-rhs+2,m2,n2,1,1,lr2,nlr2))
     $         return
          if(.not.checkval(fname,m2*n2,1)) return
          if(.not.bufstore(fname,lbuf,lbufi2,lbuff2,lr2,nlr2)) return

          if (.not.getwsmat(fname,top,top-rhs+3,m3,n3,il3,ild3)) return

          call xgetfile(buf(lbufi1:lbuff1),buf(lbufi2:lbuff2),
     $         stk(lw3),ne5,err,idir,istk(il3),istk(ild3),m3*n3)
       endif
       if (rhsk.eq.2) then 
          if(.not.getsmat(fname,top,top-rhs+1,m1,n1,1,1,lr1,nlr1))
     $         return
          if(.not.checkval(fname,m1*n1,1)) return
          if(.not.bufstore(fname,lbuf,lbufi1,lbuff1,lr1,nlr1)) return

          if (isoptlw(top,top-rhs+2,name)) then 
             if (name.ne.'title') then 
                buf = fname // 'optional argument must be title='
                call error(999)
                return
             endif
             idir = 0
             if (.not.getwsmat(fname,top,top-rhs+2,m2,n2,il2,ild2))
     $            return
             call xgetfile(buf(lbufi1:lbuff1),'.',
     $            stk(lw3),ne5,err,idir,istk(il2),istk(ild2),m2*n2)
          else
             idir = 1
             if(.not.getsmat(fname,top,top-rhs+2,m2,n2,1,1,lr2,nlr2))
     $            return
             if(.not.checkval(fname,m2*n2,1)) return
             if(.not.bufstore(fname,lbuf,lbufi2,lbuff2,lr2,nlr2)) return

             if (.not.getwsmat(fname,top,top-rhs+3,m3,n3,il3,ild3))
     $            return
             call xgetfile(buf(lbufi1:lbuff1),buf(lbufi2:lbuff2),
     $            stk(lw3),ne5,err,idir,istk(il3),istk(ild3),m3*n3)
          endif
       endif
       if ( rhsk.eq.1) then 
          idir = 0
          if (isoptlw(top,top-rhs+1,name)) then 
             if (name.ne.'title') then 
                buf = fname // ' optional argument must be title='
                call error(999)
                return
             endif
             if (.not.getwsmat(fname,top,top-rhs+1,m1,n1,il1,ild1))
     $            return
             call xgetfile('*.*','.',
     $            stk(lw3),ne5,err,idir,istk(il1),istk(ild1),m1*n1)
          else
             if(.not.getsmat(fname,top,top-rhs+1,m1,n1,1,1,lr1,nlr1))
     $            return
             if(.not.checkval(fname,m1*n1,1)) return
             if(.not.bufstore(fname,lbuf,lbufi1,lbuff1,lr1,nlr1)) return

             if(.not.getsmat(fname,top,top-rhs+2,m2,n2,1,1,lr2,nlr2))
     $            return
             if(.not.checkval(fname,m2*n2,1)) return
             if(.not.bufstore(fname,lbuf,lbufi2,lbuff2,lr2,nlr2)) return

             if (.not.getwsmat(fname,top,top-rhs+3,m3,n3,il3,ild3))
     $            return
             call xgetfile(buf(lbufi1:lbuff1),buf(lbufi2:lbuff2),
     $            stk(lw3),ne5,err,idir,istk(il3),istk(ild3),m3*n3)
          endif
       endif
       if (rhsk.le.0 ) then 
          idir=0
          if(.not.getsmat(fname,top,top-rhs+1,m1,n1,1,1,lr1,nlr1))
     $         return
          if(.not.checkval(fname,m1*n1,1)) return
          if(.not.bufstore(fname,lbuf,lbufi1,lbuff1,lr1,nlr1)) return
          
          if(.not.getsmat(fname,top,top-rhs+2,m2,n2,1,1,lr2,nlr2))
     $         return
          if(.not.checkval(fname,m2*n2,1)) return
          if(.not.bufstore(fname,lbuf,lbufi2,lbuff2,lr2,nlr2)) return
          
          if (.not.getwsmat(fname,top,top-rhs+3,m3,n3,il3,ild3))
     $         return
          call xgetfile(buf(lbufi1:lbuff1),buf(lbufi2:lbuff2),
     $         stk(lw3),ne5,err,idir,istk(il3),istk(ild3),m3*n3)
       endif
C
C      the result is a string and xgetfile 
C      will have to create ( malloc ) space for storing the result
C      we will keep track of this allocated string through lw3.

       if(err .gt. 0) then 
        buf = fname // 'Internal Error' 
        call error(999)
       endif
c
       topk=top-rhs
       topl=top+1
c     
       if(lhs .ge. 1) then
c       --------------output variable: res
        top=topl+1
        if(.not.crestring(fname,top,ne5,ilrs)) return
        call ccharf(ne5,stk(lw3),istk(ilrs))
       endif
c     Putting in order the stack
       if(lhs .ge. 1) then
        call copyobj(fname,topl+1,topk+1)
       endif
       top=topk+lhs
       return
       end