-
Notifications
You must be signed in to change notification settings - Fork 2
/
mem_mgr.f
3807 lines (3731 loc) · 128 KB
/
mem_mgr.f
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
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
CM
C=======================================================================
c EMSOL Memory manager:
c
c Call sequences which may be cause block moves (BlkMv) or the space
c limit to be reached (NoPo)
c
c css_mem_mgr -<- g_fr_blk_p -<- nw_blk -<- ope_blk -<- ope_a
c . (BlkMv) (NoPo)
c . | |
c . ^ V
c . | |
c . xp_blk -<- g_fr_blk_n
c . (BlkMv)
c
c Only ope_blk and ope_a are called from external subroutines.
c ope_blk calls ems_mem_mgr_g_al_p if blocks are moved.
c
C=======================================================================
c User-called subroutines.
c
C->>> ---------------------------------------> ems_mem_mgr_dn_blk_id <<<
c Define the text for a new block ID
c
c Possible return code values set in this routine:
c -----------------------------------------------
c
c Routines called:
c ---------------
c
subroutine ems_mem_mgr_dn_blk_id(mem_mgr_rt_cod, is,
& txt, usr_blk_id)
implicit none
include 'EMSMMGR.INC'
include 'EMSMMGRI.INC'
include 'EMSMSG.INC'
integer mem_mgr_rt_cod, is(0:*), usr_blk_id
character*(*) txt
logical ems_mem_mgr_no_ca_iz
mem_mgr_rt_cod = mem_mgr_rt_cod_ok
if (ems_mem_mgr_no_ca_iz(is)) goto 8000
if (n_blk_id+1 .ge. mx_n_blk_id) then
mem_mgr_rt_cod = max(mem_mgr_rt_cod_mx_blk_id,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9400, err=8990)
& mx_n_blk_id-usr_blk_id_os, blk_id_txt(mx_n_blk_id)
call ems_msg_wr_li(warn_msg_n)
usr_blk_id = mx_n_blk_id - usr_blk_id_os
else
n_blk_id = n_blk_id + 1
usr_blk_id = n_blk_id - usr_blk_id_os
blk_id_txt(n_blk_id) = txt
endif
c 7000 continue
7100 continue
return
8000 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_no_ca_iz,
& mem_mgr_rt_cod)
goto 7100
8990 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_serious_f7_wr_er,
& mem_mgr_rt_cod)
goto 7100
9400 format('Reached the limit on the number of block IDs.',
& ' The text associated with block ID ', i3, 'is', a)
end
C->>> -----------------------------------------> ems_mem_mgr_g_hdl_p <<<
c Calculates the pointers associated with a set of handles
c
c Possible return code values set in this routine:
c -----------------------------------------------
c
c Routines called:
c ---------------
c
subroutine ems_mem_mgr_g_hdl_p(mem_mgr_rt_cod, is,
& n_hdl, hdl)
implicit none
include 'EMSV.INC'
include 'EMSMMGR.INC'
include 'EMSMSG.INC'
integer mem_mgr_rt_cod, is(0:*)
integer n_hdl
integer hdl(hdl_z*n_hdl)
logical ems_mem_mgr_no_ca_iz
integer p
integer ca_mem_mgr_rt_cod
character*19 rn_nm
data rn_nm/'ems_mem_mgr_g_hdl_p'/
mem_mgr_rt_cod = mem_mgr_rt_cod_ok
if (ems_mem_mgr_no_ca_iz(is)) goto 8000
if (n_hdl .lt. 0) goto 8030
do 10, p = 1, (n_hdl-1)*hdl_z+1, hdl_z
if (hdl(p+hdl_os_blk_n) .le. 0) then
hdl(p+hdl_os_p) = no_p
goto 10
endif
if (hdl(p+hdl_os_wo_z) .eq. ch_wo_z) then
call ems_mem_mgr_g_p1(ca_mem_mgr_rt_cod, is,
& hdl(p+hdl_os_blk_n), hdl(p+hdl_os_p))
else if (hdl(p+hdl_os_wo_z) .eq. i_wo_z) then
call ems_mem_mgr_g_p4(ca_mem_mgr_rt_cod, is,
& hdl(p+hdl_os_blk_n), hdl(p+hdl_os_p))
else if (hdl(p+hdl_os_wo_z) .eq. rl_wo_z) then
call ems_mem_mgr_g_p8(ca_mem_mgr_rt_cod, is,
& hdl(p+hdl_os_blk_n), hdl(p+hdl_os_p))
endif
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod, mem_mgr_rt_cod)
if (mem_mgr_rt_cod .ge. mem_mgr_rt_lvl_serious) goto 7100
endif
hdl(p+hdl_os_blk_mv_k) = is(ix_blk_mv_k)
10 continue
c 7000 continue
7100 continue
return
8000 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_no_ca_iz,
& mem_mgr_rt_cod)
goto 7100
8030 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_pm_er,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9800, err=8990)
& rn_nm, n_hdl, 3, 0, i_inf
call ems_msg_wr_li(serious_msg_n)
goto 7100
8990 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_serious_f7_wr_er,
& mem_mgr_rt_cod)
goto 7100
9800 format(a, ' has been called with value of ', i9,
& ' for parameter ', i1, '. The valid range is ', i9,
& ' to ', i9)
end
C->>> ------------------------------------> ems_mem_mgr_g_rq_is_n_en <<<
c Returns the current required number of entries in the integer
c workspace which would allow a block of n_wo integer words to be
c allocated, and the maximum number of entries which has been
c required since the memory manager was initialised.
c
c Possible return code values set in this routine:
c -----------------------------------------------
c
c Routines called:
c ---------------
c
subroutine ems_mem_mgr_g_rq_is_n_en(mem_mgr_rt_cod, is,
& n_wo, cu_rq_is_n_en, mx_rq_is_n_en)
implicit none
include 'EMSV.INC'
include 'EMSMMGR.INC'
include 'EMSMMGRI.INC'
integer mem_mgr_rt_cod, is(0:*)
integer n_wo, cu_rq_is_n_en, mx_rq_is_n_en
logical ems_mem_mgr_no_ca_iz
mem_mgr_rt_cod = mem_mgr_rt_cod_ok
if (ems_mem_mgr_no_ca_iz(is)) goto 8000
if (is(ix_n_xa_i_wo_rq) .le. 0) then
cu_rq_is_n_en = is(ix_l_mgr_p)+1 + n_wo - is(ix_n_fr_wo)
mx_rq_is_n_en = is(ix_l_mgr_p)+1 + n_wo - is(ix_mn_n_fr_wo)
else
cu_rq_is_n_en = is(ix_l_mgr_p)+1 + n_wo + is(ix_n_xa_i_wo_rq)
mx_rq_is_n_en = cu_rq_is_n_en
endif
c 7000 continue
7100 continue
return
8000 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_no_ca_iz,
& mem_mgr_rt_cod)
goto 7100
end
C->>> ----------------------------------------------> ems_mem_mgr_iz <<<
c User interface to the routine which initialises the memory
c manager. Avoids the user having to set mn_blk_p
c
c Possible return code values set in this routine:
c -----------------------------------------------
c
c Routines called:
c ---------------
c
subroutine ems_mem_mgr_iz(mem_mgr_rt_cod, is, is_n_en)
implicit none
include 'EMSV.INC'
include 'EMSMMGR.INC'
include 'EMSMMGRI.INC'
include 'EMSMSG.INC'
integer mem_mgr_rt_cod, is_n_en
integer is(0:is_n_en-1)
integer mn_blk_p
integer ca_mem_mgr_rt_cod
character*14 rn_nm
data rn_nm/'ems_mem_mgr_iz'/
mem_mgr_rt_cod = mem_mgr_rt_cod_ok
if (is_n_en .lt. 1) goto 8030
mn_blk_p = mem_mgr_da_l_is_en + 1
call ems_mem_mgr_int_iz(ca_mem_mgr_rt_cod, is, is_n_en, mn_blk_p)
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod, mem_mgr_rt_cod)
if (mem_mgr_rt_cod .ge. mem_mgr_rt_lvl_serious) goto 7100
endif
7100 continue
return
8030 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_pm_er,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9800, err=8990)
& rn_nm, is_n_en, 3, 1, i_inf
call ems_msg_wr_li(serious_msg_n)
goto 7100
8990 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_serious_f7_wr_er,
& mem_mgr_rt_cod)
goto 7100
9800 format(a, ' has been called with value of ', i9,
& ' for parameter ', i1, '. The valid range is ', i9,
& ' to ', i9)
end
C->>> ------------------------------------------> ems_mem_mgr_nw_hdl <<<
c Sets a handle in block blk_n for n_en entries of word length wo_z.
c Serious error reported if handle asks for more space than is
c available in block.
c
c Possible return code values set in this routine:
c -----------------------------------------------
c
c Routines called:
c ---------------
c
subroutine ems_mem_mgr_nw_hdl(mem_mgr_rt_cod, is,
& blk_n, n_en, wo_z, hdl)
implicit none
include 'EMSV.INC'
include 'EMSMMGR.INC'
include 'EMSMMGRI.INC'
include 'EMSMSG.INC'
integer mem_mgr_rt_cod, is(0:*), blk_n, n_en, wo_z
integer hdl(0:hdl_z_m1)
logical ems_mem_mgr_no_ca_iz
integer ems_mem_mgr_nx_i_n_en_p
integer blk_f_fr_p, blk_p, blk_n_wo, sn_p, n_wo
integer blk_n_fr_wo, blk_n_fr_en
integer p_blk_da
integer ca_mem_mgr_rt_cod
character*18 rn_nm
data rn_nm/'ems_mem_mgr_nw_hdl'/
mem_mgr_rt_cod = mem_mgr_rt_cod_ok
if (ems_mem_mgr_no_ca_iz(is)) goto 8000
if (blk_n .lt. 1 .or. blk_n .gt. is(ix_mx_n_blk)) goto 8030
if (wo_z .lt. 1) goto 8050
p_blk_da = is(ix_p_blk_da)+(blk_n-1)*blk_rec_z
blk_p = is(p_blk_da+os_blk_is_p)
if (blk_p .le. 0) goto 8110
blk_f_fr_p = is(p_blk_da+os_blk_f_fr_p)
blk_n_wo = is(p_blk_da+os_blk_n_wo)
n_wo = n_en*wo_z
sn_p = blk_p + blk_f_fr_p
c
c Ensure that the block starts on an integral wo_z boundary.
c
sn_p = ems_mem_mgr_nx_i_n_en_p(sn_p, wo_z)
blk_n_fr_wo = blk_p + blk_n_wo - sn_p
blk_n_fr_en = blk_n_fr_wo/wo_z
if (n_en .lt. 0) goto 8040
if (n_en .gt. blk_n_fr_en) goto 8100
if (sn_p+n_wo .gt. blk_p+blk_n_wo) goto 8120
is(p_blk_da+os_blk_f_fr_p) = sn_p - blk_p + n_wo
hdl(hdl_os_blk_n) = blk_n
hdl(hdl_os_blk_os) = sn_p - blk_p
hdl(hdl_os_wo_z) = wo_z
CM IF (emsol_epc .EQ. 1) THEN
C? if (wo_z .eq. i_wo_z) then
C? call ems_debug_se_i_a_undn(is(sn_p), 1, n_en)
C? else
C? call ems_dum_debug_se_rl_a_undn(is(sn_p), 1, n_en)
C? endif
CM ENDIF
c
c Set the pointer in the handle
c
c 1000 continue
call ems_mem_mgr_g_hdl_p(ca_mem_mgr_rt_cod, is,
& 1, hdl)
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod, mem_mgr_rt_cod)
if (mem_mgr_rt_cod .ge. mem_mgr_rt_lvl_serious) goto 7100
endif
c 7000 continue
7100 continue
return
8000 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_no_ca_iz,
& mem_mgr_rt_cod)
goto 7100
8030 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_pm_er,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9800, err=8990)
& rn_nm, blk_n, 3, 1, is(ix_mx_n_blk)
call ems_msg_wr_li(serious_msg_n)
goto 7100
8040 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_pm_er,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9800, err=8990)
& rn_nm, n_en, 4, 0, blk_n_fr_en
call ems_msg_wr_li(serious_msg_n)
goto 7100
8050 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_pm_er,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9800, err=8990)
& rn_nm, wo_z, 5, 1, i_inf
call ems_msg_wr_li(serious_msg_n)
goto 7100
8100 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_blk_no_po,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9810, err=8990)
& n_en, wo_z, blk_n_fr_en
call ems_msg_wr_li(serious_msg_n)
goto 7100
8110 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_no_blk,
& mem_mgr_rt_cod)
goto 7100
8120 continue
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9812, err=8990)
& sn_p, n_wo, blk_p, blk_n_wo
call ems_msg_wr_li(serious_msg_n)
mem_mgr_rt_cod = max(mem_mgr_rt_cod_int_er,
& mem_mgr_rt_cod)
goto 7100
8990 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_serious_f7_wr_er,
& mem_mgr_rt_cod)
goto 7100
9800 format(a, ' has been called with value of ', i9,
& ' for parameter ', i1, '. The valid range is ', i9,
& ' to ', i9)
9810 format('Attempting to get a handle for an array with ', i9,
& ' entries---each of ', i1,
& ' fullwords---in a block with room for only ', i9,
& ' such entries')
9812 format('Unexpected internal error in ems_mem_mgr_nw_hdl: ',
& 4(2x, i9))
end
C->>> -------------------------------------------> ems_mem_mgr_ope_a <<<
c Allows dynamic allocation of an array as a single block
c
c Possible return code values set in this routine:
c -----------------------------------------------
c
c Routines called:
c ---------------
c
subroutine ems_mem_mgr_ope_a(mem_mgr_rt_cod, is, n_en, wo_z, hdl)
implicit none
include 'EMSV.INC'
include 'EMSMMGR.INC'
include 'EMSMMGRI.INC'
include 'EMSMSG.INC'
integer is(0:*), n_en, wo_z, mem_mgr_rt_cod
integer hdl(0:hdl_z_m1)
logical ems_mem_mgr_no_ca_iz
integer blk_n
integer ca_mem_mgr_rt_cod
character*17 rn_nm
data rn_nm/'ems_mem_mgr_ope_a'/
mem_mgr_rt_cod = mem_mgr_rt_cod_ok
if (ems_mem_mgr_no_ca_iz(is)) goto 8000
if (n_en .lt. 0) goto 8030
if (wo_z .lt. 1) goto 8040
call ems_mem_mgr_ope_blk(ca_mem_mgr_rt_cod, is,
& n_en*wo_z, ope_blk_anywhere,
& 0, usr_a_blk_id, blk_n)
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
if (ca_mem_mgr_rt_cod .eq. mem_mgr_rt_cod_serious_no_po) then
mem_mgr_rt_cod = mem_mgr_rt_cod_serious_no_po
else
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod, mem_mgr_rt_cod)
endif
if (mem_mgr_rt_cod .ge. mem_mgr_rt_lvl_serious) goto 7100
endif
hdl(hdl_os_blk_n) = blk_n
hdl(hdl_os_blk_os) = 0
hdl(hdl_os_wo_z) = wo_z
c
c Set the pointer in the handle
c
call ems_mem_mgr_g_hdl_p(ca_mem_mgr_rt_cod, is,
& 1, hdl)
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod, mem_mgr_rt_cod)
if (mem_mgr_rt_cod .ge. mem_mgr_rt_lvl_serious) goto 7100
endif
c 7000 continue
7100 continue
return
8000 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_no_ca_iz,
& mem_mgr_rt_cod)
goto 7100
8030 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_pm_er,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9800, err=8990)
& rn_nm, n_en, 3, 0, i_inf
call ems_msg_wr_li(serious_msg_n)
goto 7100
8040 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_pm_er,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9800, err=8990)
& rn_nm, wo_z, 4, 1, i_inf
call ems_msg_wr_li(serious_msg_n)
goto 7100
8990 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_serious_f7_wr_er,
& mem_mgr_rt_cod)
goto 7100
9800 format(a, ' has been called with value of ', i9,
& ' for parameter ', i1, '. The valid range is ', i9,
& ' to ', i9)
end
C->>> -----------------------------------------> ems_mem_mgr_ope_blk <<<
c Calls ems_mem_mgr_nw_blk to open a new block.
c Calls ems_mem_mgr_g_al_p if blocks have moved
c
c Possible return code values set in this routine:
c -----------------------------------------------
c
c Routines called:
c ---------------
c
subroutine ems_mem_mgr_ope_blk(mem_mgr_rt_cod, is,
& n_wo, where, blk_ix, usr_blk_id, blk_n)
implicit none
include 'EMSV.INC'
include 'EMSMMGR.INC'
include 'EMSMMGRI.INC'
include 'EMSMSG.INC'
integer mem_mgr_rt_cod, is(0:*)
integer n_wo, where, blk_ix, usr_blk_id, blk_n
logical ems_mem_mgr_no_ca_iz
integer blk_mv_k
integer blk_id
integer ca_mem_mgr_rt_cod
character*19 rn_nm
data rn_nm/'ems_mem_mgr_ope_blk'/
mem_mgr_rt_cod = mem_mgr_rt_cod_ok
if (ems_mem_mgr_no_ca_iz(is)) goto 8000
if (n_wo .lt. 0) goto 8030
if (where .lt. 0 .or. where .gt. 2) goto 8040
blk_id = usr_blk_id + usr_blk_id_os
if (blk_id .lt. 0 .or. blk_id .gt. n_blk_id) goto 8060
c
c Switch off the block move lock and record the block move counter.
c
is(ix_blk_mv_lck) = 0
blk_mv_k = is(ix_blk_mv_k)
call ems_mem_mgr_nw_blk(ca_mem_mgr_rt_cod, is,
& n_wo, where, blk_n, blk_ix, blk_id)
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
if (ca_mem_mgr_rt_cod .eq. mem_mgr_rt_cod_serious_no_po) then
mem_mgr_rt_cod = mem_mgr_rt_cod_serious_no_po
else
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod, mem_mgr_rt_cod)
endif
if (mem_mgr_rt_cod .ge. mem_mgr_rt_lvl_serious) goto 7100
endif
c
c Recalculate all pointers if (some) blocks have moved.
c
if (is(ix_blk_mv_k) .gt. blk_mv_k) then
call ems_mem_mgr_g_al_p(ca_mem_mgr_rt_cod, is)
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod, mem_mgr_rt_cod)
if (mem_mgr_rt_cod .ge. mem_mgr_rt_lvl_serious) goto 7100
endif
endif
c 7000 continue
7100 continue
c
c Switch on the block move lock
c
is(ix_blk_mv_lck) = 1
return
8000 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_no_ca_iz,
& mem_mgr_rt_cod)
goto 7100
8030 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_pm_er,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9800, err=8990)
& rn_nm, n_wo, 3, 1, i_inf
call ems_msg_wr_li(serious_msg_n)
goto 7100
8040 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_pm_er,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9800, err=8990)
& rn_nm, where, 4, 0, 2
call ems_msg_wr_li(serious_msg_n)
goto 7100
8060 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_pm_er,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9800, err=8990)
& rn_nm, usr_blk_id, 6,
& -usr_blk_id_os, n_blk_id-usr_blk_id_os
call ems_msg_wr_li(serious_msg_n)
goto 7100
8990 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_serious_f7_wr_er,
& mem_mgr_rt_cod)
goto 7100
9800 format(a, ' has been called with value of ', i9,
& ' for parameter ', i1, '. The valid range is ', i9,
& ' to ', i9)
end
C->>> --------------------------------------------> ems_mem_mgr_rm_a <<<
c Deallocates an array.
c
c Possible return code values set in this routine:
c -----------------------------------------------
c
c Routines called:
c ---------------
c
subroutine ems_mem_mgr_rm_a(mem_mgr_rt_cod, is, hdl)
implicit none
include 'EMSMMGR.INC'
integer mem_mgr_rt_cod, is(0:*)
integer hdl(0:hdl_z_m1)
logical ems_mem_mgr_no_ca_iz
integer ca_mem_mgr_rt_cod
mem_mgr_rt_cod = mem_mgr_rt_cod_ok
if (ems_mem_mgr_no_ca_iz(is)) goto 8000
call ems_mem_mgr_rm_blk(ca_mem_mgr_rt_cod, is, hdl(hdl_os_blk_n))
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod, mem_mgr_rt_cod)
if (mem_mgr_rt_cod .ge. mem_mgr_rt_lvl_serious) goto 7100
endif
c 7000 continue
7100 continue
return
8000 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_no_ca_iz,
& mem_mgr_rt_cod)
goto 7100
end
C->>> ------------------------------------------> ems_mem_mgr_rm_blk <<<
c Removes block blk_n.
c
c Possible return code values set in this routine:
c -----------------------------------------------
c
c Routines called:
c ---------------
c
subroutine ems_mem_mgr_rm_blk(mem_mgr_rt_cod, is, blk_n)
implicit none
include 'EMSMMGR.INC'
include 'EMSMMGRI.INC'
include 'EMSMSG.INC'
integer mem_mgr_rt_cod, is(0:*)
integer blk_n
logical ems_mem_mgr_no_ca_iz
integer mgr_p, nx_blk_n, pre_blk_n
integer p_blk_da, p_pre_blk_da, p_nx_blk_da
character*18 rn_nm
data rn_nm/'ems_mem_mgr_rm_blk'/
mem_mgr_rt_cod = mem_mgr_rt_cod_ok
if (ems_mem_mgr_no_ca_iz(is)) goto 8000
c
c Check that we are not trying to remove a block which does not
c exist.
c
if (blk_n .lt. 1 .or. blk_n .gt. is(ix_mx_n_blk)) goto 8030
p_blk_da = is(ix_p_blk_da) + (blk_n-1)*blk_rec_z
if (is(p_blk_da+os_blk_is_p) .le. 0) go to 8100
c
c Add the block number to the free list (unless it is already full).
c
if (is(ix_blk_n_fr_ls_n_en) .lt. mx_n_blk_n_fr_ls_en) then
is(ix_blk_n_fr_ls_n_en) = is(ix_blk_n_fr_ls_n_en) + 1
is(p_blk_n_fr_ls+is(ix_blk_n_fr_ls_n_en)) = blk_n
endif
c
c Update the number of free block numbers
c
is(ix_n_fr_blk_n) = is(ix_n_fr_blk_n) + 1
c
c Update the number of free words.
c
is(ix_n_fr_wo) = is(ix_n_fr_wo) + is(p_blk_da+os_blk_n_wo)
is(ix_mn_n_fr_wo) = min(is(ix_n_fr_wo), is(ix_mn_n_fr_wo))
c
c Find the next and previous block in the list.
c
nx_blk_n = is(p_blk_da+os_blk_lkf)
pre_blk_n = is(p_blk_da+os_blk_lkb)
mgr_p = is(p_blk_da+os_blk_mgr_p)
p_nx_blk_da = is(ix_p_blk_da) + (nx_blk_n-1)*blk_rec_z
p_pre_blk_da = is(ix_p_blk_da) + (pre_blk_n-1)*blk_rec_z
if (pre_blk_n .gt. 0) then
c
c Update the forward link of the previous block.
c
is(p_pre_blk_da+os_blk_lkf) = nx_blk_n
else
c
c The first block in the system is being removed.
c Assumes that nx_blk_n > 0 (otherwise we are removing the only
c block in the system which wouldn't happen).
c
if (is(p_nx_blk_da+os_blk_mgr_p) .eq. blk_at_mgr_bac) then
c
c There are no blocks in the front half of the manager.
c
is(ix_f_frt_blk) = -1
is(ix_f_blk_p) = is(ix_f_mgr_p) - 1
else
is(ix_f_frt_blk) = nx_blk_n
is(ix_f_blk_p) = is(p_nx_blk_da+os_blk_is_p)
end if
end if
if (nx_blk_n .gt. 0) then
c
c Update the backward link of the next block.
c
is(p_nx_blk_da+os_blk_lkb) = pre_blk_n
else
c
c The last block in the system is being removed.
c Assumes that pre_blk_n > 0 (otherwise we are removing the only
c block in the system which wouldn't happen).
c
if (is(p_pre_blk_da+os_blk_mgr_p) .eq. blk_at_mgr_frt) then
c
c There are no blocks in the back half of the manager.
c
is(ix_l_bac_blk) = -1
is(ix_l_blk_p) = is(ix_l_mgr_p)+1
else
is(ix_l_bac_blk) = pre_blk_n
is(ix_l_blk_p) = is(p_pre_blk_da+os_blk_is_p) +
& is(p_pre_blk_da+os_blk_n_wo) - 1
end if
end if
if (blk_n .eq. is(ix_l_frt_blk)) then
c
c The block is removed from the beginning of the free space so
c update the first free pointer and the last block at the front of
c the memory manager.
c
is(ix_l_frt_blk) = pre_blk_n
if (pre_blk_n .gt. 0) then
is(ix_f_fr_p) = is(p_pre_blk_da+os_blk_is_p) +
& is(p_pre_blk_da+os_blk_n_wo)
else
is(ix_f_fr_p) = is(ix_f_mgr_p)
end if
else if (blk_n .eq. is(ix_f_bac_blk)) then
c
c The block is removed from the end of the free space so
c update the last free pointer and the first block at the back of
c the memory manager.
c
is(ix_f_bac_blk) = nx_blk_n
if (nx_blk_n .gt. 0) then
is(ix_l_fr_p) = is(p_nx_blk_da+os_blk_is_p) - 1
else
is(ix_l_fr_p) = is(ix_l_mgr_p)
end if
end if
c
c Zero the pointer for the block to be removed.
c
is(p_blk_da+os_blk_is_p) = 0
blk_n = 0
c 7000 continue
7100 continue
return
8000 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_no_ca_iz,
& mem_mgr_rt_cod)
goto 7100
8030 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_pm_er,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9800, err=8990)
& rn_nm, blk_n, 3, 1, is(ix_mx_n_blk)
call ems_msg_wr_li(serious_msg_n)
goto 7100
8100 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_no_blk,
& mem_mgr_rt_cod)
goto 7100
8990 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_serious_f7_wr_er,
& mem_mgr_rt_cod)
goto 7100
9800 format(a, ' has been called with value of ', i9,
& ' for parameter ', i1, '. The valid range is ', i9,
& ' to ', i9)
end
C->>> --------------------------------------> ems_mem_mgr_rp_mem_use <<<
c Report the memory usage.
c
c If rp_cn is negative then messages are put out via ems_msg_wr_li,
c otherwise, they are put out on rp_cn.
c
c If rp_lvl=1 then a brief report is written
c If rp_lvl=2 then a verbose report is written
c
c Possible return code values set in this routine:
c -----------------------------------------------
c
c Routines called:
c ---------------
c
subroutine ems_mem_mgr_rp_mem_use(mem_mgr_rt_cod, is, rp_cn,
& rp_lvl, msg)
implicit none
include 'EMSV.INC'
include 'EMSMMGR.INC'
include 'EMSMMGRI.INC'
include 'EMSMSG.INC'
integer mem_mgr_rt_cod, is(0:*), rp_cn, rp_lvl
character*(*) msg
logical ems_mem_mgr_no_ca_iz
integer cu_rq_is_n_en, mx_rq_is_n_en
integer sv_mem_mgr_ck_rp_mode
integer ca_mem_mgr_rt_cod
logical alw_f7_wr
character*22 rn_nm
data rn_nm/'ems_mem_mgr_rp_mem_use'/
mem_mgr_rt_cod = mem_mgr_rt_cod_ok
if (ems_mem_mgr_no_ca_iz(is)) goto 8000
if (rp_lvl .lt. 1 .or. rp_lvl .gt. 2) goto 8050
alw_f7_wr = ems_msg_no_prt_fm .ge. 1 .or. rp_cn .ge. 0
if (rp_lvl .eq. 1) then
if (alw_f7_wr) write(ems_li, 9000, err=8990)msg
if (rp_cn .lt. 0) then
call ems_msg_wr_li(info_msg_n)
else
if (alw_f7_wr) then
call ems_msg_wr_li_t_cn(ca_mem_mgr_rt_cod, rp_cn)
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod,
& mem_mgr_rt_cod)
if (mem_mgr_rt_cod .ge.
& mem_mgr_rt_lvl_serious) goto 7100
endif
endif
endif
call ems_mem_mgr_rp_ws_use(ca_mem_mgr_rt_cod, is, rp_cn,
& 0, i_wo_z, 'integer')
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod, mem_mgr_rt_cod)
if (mem_mgr_rt_cod .ge. mem_mgr_rt_lvl_serious) goto 7100
endif
call ems_mem_mgr_g_rq_is_n_en(ca_mem_mgr_rt_cod, is,
& 0, cu_rq_is_n_en, mx_rq_is_n_en)
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod, mem_mgr_rt_cod)
if (mem_mgr_rt_cod .ge. mem_mgr_rt_lvl_serious) goto 7100
endif
call ems_mem_mgr_rp_rq_is_n_en(ca_mem_mgr_rt_cod, is,
& rp_cn, cu_rq_is_n_en, mx_rq_is_n_en)
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod, mem_mgr_rt_cod)
if (mem_mgr_rt_cod .ge. mem_mgr_rt_lvl_serious) goto 7100
endif
else if (rp_lvl .eq. 2) then
c
c Save the value of mem_mgr_ck_rp_mode
c
sv_mem_mgr_ck_rp_mode = is(ix_mem_mgr_ck_rp_mode)
c
c Force checking and writing of memory manager
c
is(ix_mem_mgr_ck_rp_mode) = 2
call ems_mem_mgr_ck_rp(ca_mem_mgr_rt_cod, is,
& rp_cn, -1, msg)
c
c Restore the value of mem_mgr_ck_rp_mode
c
is(ix_mem_mgr_ck_rp_mode) = sv_mem_mgr_ck_rp_mode
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod, mem_mgr_rt_cod)
if (mem_mgr_rt_cod .ge. mem_mgr_rt_lvl_serious) goto 7100
endif
endif
c 7000 continue
7100 continue
return
8000 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_no_ca_iz,
& mem_mgr_rt_cod)
goto 7100
8050 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_pm_er,
& mem_mgr_rt_cod)
if (ems_msg_no_prt_fm .ge. 1) write(ems_li, 9800, err=8990)
& rn_nm, rp_lvl, 5, 1, 2
call ems_msg_wr_li(serious_msg_n)
goto 7100
8990 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_serious_f7_wr_er,
& mem_mgr_rt_cod)
goto 7100
9000 format(a)
9800 format(a, ' has been called with value of ', i9,
& ' for parameter ', i1, '. The valid range is ', i9,
& ' to ', i9)
end
C->>> -----------------------------------> ems_mem_mgr_rp_rq_is_n_en <<<
c Calls the routine which reports the required and current number of
c workspace entries, with parameters corresponding to the fullword
c integer workspace.
c
c If rp_cn is negative then messages are put out via ems_msg_wr_li,
c otherwise, they are put out on rp_cn.
c
c Possible return code values set in this routine:
c -----------------------------------------------
c
c Routines called:
c ---------------
c
subroutine ems_mem_mgr_rp_rq_is_n_en(mem_mgr_rt_cod, is, rp_cn,
& cu_rq_is_n_en, mx_rq_is_n_en)
implicit none
include 'EMSV.INC'
include 'EMSMMGR.INC'
include 'EMSMSG.INC'
integer mem_mgr_rt_cod, is(0:*), rp_cn
integer cu_rq_is_n_en, mx_rq_is_n_en
logical ems_mem_mgr_no_ca_iz
integer ca_mem_mgr_rt_cod
mem_mgr_rt_cod = mem_mgr_rt_cod_ok
if (ems_mem_mgr_no_ca_iz(is)) goto 8000
call ems_mem_mgr_rp_rq_ws_n_en(ca_mem_mgr_rt_cod, is, rp_cn,
& cu_rq_is_n_en, mx_rq_is_n_en, i_wo_z, 'integer')
if (ca_mem_mgr_rt_cod .ne. mem_mgr_rt_cod_ok) then
mem_mgr_rt_cod = max(ca_mem_mgr_rt_cod, mem_mgr_rt_cod)
if (mem_mgr_rt_cod .ge. mem_mgr_rt_lvl_serious) goto 7100
endif
7100 continue
return
8000 continue
mem_mgr_rt_cod = max(mem_mgr_rt_cod_no_ca_iz,
& mem_mgr_rt_cod)
goto 7100
end
C->>> ---------------------------------------> ems_mem_mgr_rp_rt_cod <<<
c Report on the value of rp_rt_cod which is assumed to have been
c returned by a memory manager routine `rn_nm'.
c
c If rp_cn is negative then messages are put out via ems_msg_wr_li,
c otherwise, they are put out on rp_cn.
c
c Possible return code values set in this routine:
c -----------------------------------------------
c
c Routines called:
c ---------------
c
subroutine ems_mem_mgr_rp_rt_cod(mem_mgr_rt_cod, is, rp_cn,
& rp_rt_cod, rn_nm)
implicit none
include 'EMSMMGR.INC'
include 'EMSMSG.INC'
integer mem_mgr_rt_cod, is(0:*), rp_cn, rp_rt_cod
character*(*) rn_nm
integer rn_nm_ln, rp_rt_lvl, rp_rt_id
integer part_li_l_ch
character*11 ch11_rt_lvl
character*90 ch90_part_li
character*32 ch32_rn_nm
integer rt_cod
logical alw_f7_wr
mem_mgr_rt_cod = mem_mgr_rt_cod_ok
alw_f7_wr = ems_msg_no_prt_fm .ge. 1 .or. rp_cn .ge. 0
c
c Copy the routine name into a local variable, giving an error
c message if the string length is not positive.
c
rn_nm_ln = min(len(rn_nm), 32)
if (rn_nm_ln .ge. 1) then
ch32_rn_nm = rn_nm(1:rn_nm_ln)
else
rn_nm_ln = 31
ch32_rn_nm = 'with non-positive string length'
endif
c
c Extract the return code level and set up the first part of the
c message.
c
if (rp_rt_cod .ge. mem_mgr_rt_lvl_serious) then
rp_rt_lvl = mem_mgr_rt_lvl_serious
ch11_rt_lvl = '* SERIOUS *'
else if (rp_rt_cod .ge. mem_mgr_rt_lvl_er) then
rp_rt_lvl = mem_mgr_rt_lvl_er
ch11_rt_lvl = '** Error **'
else if (rp_rt_cod .ge. mem_mgr_rt_lvl_warn) then
rp_rt_lvl = mem_mgr_rt_lvl_warn
ch11_rt_lvl = '* Warning *'
else if (rp_rt_cod .ge. mem_mgr_rt_lvl_info) then
rp_rt_lvl = mem_mgr_rt_lvl_info
ch11_rt_lvl = 'Information'
else
goto 8000
endif
ch90_part_li =
& ch11_rt_lvl//
& ' return code from EMSOL memory manager routine '//
& ch32_rn_nm(1:rn_nm_ln)
part_li_l_ch = 11 + 47 + rn_nm_ln
c
c Get the return code ID by subtracting the return code level offset
c
rp_rt_id = rp_rt_cod - rp_rt_lvl
c
c Write out the message corresponding to the value of rp_rt_id
c
if (rp_rt_id .eq. mem_mgr_rt_id_ok) then
if (alw_f7_wr) write(ems_li, 9000, err=8990)
& ch90_part_li(1:part_li_l_ch), rp_rt_id
else if (rp_rt_id .eq. mem_mgr_rt_id_mv_blk) then
if (alw_f7_wr) write(ems_li, 9001, err=8990)
& ch90_part_li(1:part_li_l_ch), rp_rt_id
else if (rp_rt_id .eq. mem_mgr_rt_id_no_po) then
if (alw_f7_wr) write(ems_li, 9002, err=8990)
& ch90_part_li(1:part_li_l_ch), rp_rt_id
else if (rp_rt_id .eq. mem_mgr_rt_id_g_p_wg_wo_z) then
if (alw_f7_wr) write(ems_li, 9003, err=8990)
& ch90_part_li(1:part_li_l_ch), rp_rt_id
else if (rp_rt_id .eq. mem_mgr_rt_id_f7_wr_er) then
if (alw_f7_wr) write(ems_li, 9099, err=8990)
& ch90_part_li(1:part_li_l_ch), rp_rt_id
else if (rp_rt_id .eq. mem_mgr_rt_id_no_ca_iz) then
if (alw_f7_wr) write(ems_li, 9100, err=8990)
& ch90_part_li(1:part_li_l_ch), rp_rt_id
else if (rp_rt_id .eq. mem_mgr_rt_id_pm_er) then
if (alw_f7_wr) write(ems_li, 9101, err=8990)
& ch90_part_li(1:part_li_l_ch), rp_rt_id
else if (rp_rt_id .eq. mem_mgr_rt_id_no_blk) then
if (alw_f7_wr) write(ems_li, 9102, err=8990)
& ch90_part_li(1:part_li_l_ch), rp_rt_id
else if (rp_rt_id .eq. mem_mgr_rt_id_blk_no_po) then
if (alw_f7_wr) write(ems_li, 9103, err=8990)
& ch90_part_li(1:part_li_l_ch), rp_rt_id
else if (rp_rt_id .eq. mem_mgr_rt_id_g_p_no_blk) then
if (alw_f7_wr) write(ems_li, 9104, err=8990)
& ch90_part_li(1:part_li_l_ch), rp_rt_id
else if (rp_rt_id .eq. mem_mgr_rt_id_int_er) then
if (alw_f7_wr) write(ems_li, 9110, err=8990)
& ch90_part_li(1:part_li_l_ch), rp_rt_id
else if (rp_rt_id .eq. mem_mgr_rt_id_blk_mv_lck_on) then
if (alw_f7_wr) write(ems_li, 9111, err=8990)
& ch90_part_li(1:part_li_l_ch), rp_rt_id
else if (rp_rt_id .eq. mem_mgr_rt_id_n_fr_wo_er) then
if (alw_f7_wr) write(ems_li, 9112, err=8990)
& ch90_part_li(1:part_li_l_ch), rp_rt_id
else if (rp_rt_id .eq. mem_mgr_rt_id_blk_n_fr_ls_er) then
if (alw_f7_wr) write(ems_li, 9113, err=8990)