1 /* @source ajarr **************************************************************
2 **
3 ** AJAX ARRAY functions
4 **
5 ** These functions control all aspects of AJAX array utilities
6 **
7 ** @author Copyright (C) 1999 Alan Bleasby
8 ** @version $Revision: 1.38 $
9 ** @modified Mar 12 1999 ajb First version
10 ** @modified May 10 2000 ajb added dynamically allocated numeric arrays
11 ** @modified $Date: 2012/12/07 10:12:42 $ by $Author: rice $
12 ** @@
13 **
14 ** This library is free software; you can redistribute it and/or
15 ** modify it under the terms of the GNU Lesser General Public
16 ** License as published by the Free Software Foundation; either
17 ** version 2.1 of the License, or (at your option) any later version.
18 **
19 ** This library is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 ** Lesser General Public License for more details.
23 **
24 ** You should have received a copy of the GNU Lesser General Public
25 ** License along with this library; if not, write to the Free Software
26 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 ** MA  02110-1301,  USA.
28 **
29 ******************************************************************************/
30 
31 
32 #include "ajlib.h"
33 
34 #include "ajarr.h"
35 #include "ajmath.h"
36 #include "ajreg.h"
37 
38 #include <stdio.h>
39 #include <sys/types.h>
40 #include <string.h>
41 
42 
43 
44 
45 #ifndef HAVE_MEMMOVE
46 /* @header memmove ***********************************************************
47 **
48 ******************************************************************************/
49 
memmove(void * dst,const void * src,size_t len)50 static void* memmove (void *dst, const void* src, size_t len)
51 {
52     return (void *)bcopy (src, dst, len);
53 }
54 #endif
55 
56 
57 #define RESERVED_SIZE 32
58 
59 static ajlong arrAlloc     = 0;
60 static ajlong arr2dAlloc   = 0;
61 static ajlong arr3dAlloc   = 0;
62 static ajlong arrFree      = 0;
63 static ajlong arr2dFree      = 0;
64 static ajlong arr3dFree      = 0;
65 static ajlong arrFreeCount = 0;
66 static ajlong arr2dFreeCount = 0;
67 static ajlong arr3dFreeCount = 0;
68 static ajlong arrCount     = 0;
69 static ajlong arr2dCount     = 0;
70 static ajlong arr3dCount     = 0;
71 static ajlong arrTotal     = 0;
72 static ajlong arr2dTotal     = 0;
73 static ajlong arr3dTotal     = 0;
74 static ajlong arrResize    = 0;
75 static ajlong arr2dResize    = 0;
76 static ajlong arr3dResize    = 0;
77 static AjPRegexp floatRegNum = NULL;
78 
79 
80 static AjBool arrChararrResize(AjPChar *thys, ajuint elem);
81 static AjBool arrIntResize(AjPInt *thys, ajuint elem);
82 static AjBool arrInt2dResize(AjPInt2d *thys, ajuint elem);
83 static AjBool arrInt3dResize(AjPInt3d *thys, ajuint elem);
84 static AjBool arrFloatResize(AjPFloat *thys, ajuint elem);
85 static AjBool arrFloat2dResize(AjPFloat2d *thys, ajuint elem);
86 static AjBool arrFloat3dResize(AjPFloat3d *thys, ajuint elem);
87 static AjBool arrDoubleResize(AjPDouble *thys, ajuint elem);
88 static AjBool arrDouble2dResize(AjPDouble2d *thys, ajuint elem);
89 static AjBool arrDouble3dResize(AjPDouble3d *thys, ajuint elem);
90 static AjBool arrShortResize(AjPShort *thys, ajuint elem);
91 static AjBool arrShort2dResize(AjPShort2d *thys, ajuint elem);
92 static AjBool arrShort3dResize(AjPShort3d *thys, ajuint elem);
93 static AjBool arrLongResize(AjPLong *thys, ajuint elem);
94 static AjBool arrLong2dResize(AjPLong2d *thys, ajuint elem);
95 static AjBool arrLong3dResize(AjPLong3d *thys, ajuint elem);
96 static AjBool arrUintResize(AjPUint *thys, ajuint elem);
97 static AjBool arrUint2dResize(AjPUint2d *thys, ajuint elem);
98 static AjBool arrUint3dResize(AjPUint3d *thys, ajuint elem);
99 
100 
101 
102 
103 /* @func ajChararrNew *********************************************************
104 **
105 ** Default constructor for empty AJAX character arrays.
106 **
107 ** @return [AjPChar] Pointer to an empty character array structure
108 ** @category new [AjPChar] Default constructor
109 **
110 ** @release 2.0.0
111 ** @@
112 ******************************************************************************/
113 
ajChararrNew(void)114 AjPChar ajChararrNew(void)
115 {
116     AjPChar thys;
117 
118     AJNEW0(thys);
119     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(char));
120     thys->Len = 0;
121     thys->Res = RESERVED_SIZE;
122 
123     arrTotal++;
124     arrAlloc += RESERVED_SIZE*sizeof(char);
125 
126     return thys;
127 }
128 
129 
130 
131 
132 /* @func ajChararrNewRes ******************************************************
133 **
134 ** Constructor given an initial reserved size.
135 **
136 ** @param [r] size [ajuint] Reserved size
137 ** @return [AjPChar] Pointer to an empty character array struct
138 **                   of specified size.
139 ** @category new [AjPChar] Constructor with reserved size
140 **
141 ** @release 6.2.0
142 ** @@
143 ******************************************************************************/
144 
ajChararrNewRes(ajuint size)145 AjPChar ajChararrNewRes(ajuint size)
146 {
147     AjPChar thys;
148 
149     size = ajRound(size,RESERVED_SIZE);
150 
151     AJNEW0(thys);
152     thys->Ptr = AJALLOC0(size*sizeof(char));
153     thys->Len = 0;
154     thys->Res = size;
155 
156     arrTotal++;
157     arrAlloc += size*sizeof(char);
158 
159     return thys;
160 }
161 
162 
163 
164 
165 /* @func ajChararrDel *********************************************************
166 **
167 ** Default destructor for AJAX character arrays.
168 **
169 ** If the given array is a NULL pointer, simply returns.
170 **
171 ** @param  [d] thys [AjPChar*] Pointer to the char array to be deleted.
172 **         The pointer is always deleted.
173 ** @return [void]
174 ** @category delete [AjPChar] Default destructor
175 **
176 ** @release 2.0.0
177 ** @@
178 ******************************************************************************/
179 
ajChararrDel(AjPChar * thys)180 void ajChararrDel(AjPChar *thys)
181 {
182     if(!thys || !*thys)
183 	return;
184 
185     /*ajDebug("ajChararrDel Len %u Res %u\n",
186 	    (*thys)->Len, (*thys)->Res);*/
187 
188     AJFREE((*thys)->Ptr);
189     AJFREE(*thys);
190 
191     *thys = NULL;
192 
193     arrFreeCount++;
194 
195     return;
196 }
197 
198 
199 
200 
201 /* @func ajChararrGet *********************************************************
202 **
203 ** Retrieve an element from an AJAX character array.
204 **
205 ** If the given array is a NULL pointer, simply returns.
206 **
207 ** @param  [r] thys [const AjPChar] Pointer to the char array.
208 ** @param  [r] elem [ajuint] array element.
209 **
210 ** @return [char] contents of array element
211 ** @category cast [AjPChar] Retrieve a character from an array
212 **
213 ** @release 2.0.0
214 ** @@
215 ******************************************************************************/
216 
ajChararrGet(const AjPChar thys,ajuint elem)217 char ajChararrGet(const AjPChar thys, ajuint elem)
218 {
219     if(!thys || elem>=thys->Len)
220 	ajErr("Attempt to access bad char array index %d\n",elem);
221 
222     return thys->Ptr[elem];
223 }
224 
225 
226 
227 
228 /* @func ajChararrPut *********************************************************
229 **
230 ** Load a character array element.
231 **
232 ** If the given array is a NULL pointer an error is generated.
233 ** If the array is of insufficient size then the array is extended.
234 ** Negative indices generate an error.
235 **
236 ** @param  [w] thys [AjPChar*] Pointer to the char array.
237 ** @param  [r] elem [ajuint] array element.
238 ** @param  [r] v [char] value to load.
239 **
240 ** @return [AjBool] true if the array was extended.
241 ** @category modify [AjPChar] Load a character array element
242 **
243 ** @release 2.0.0
244 ** @@
245 ******************************************************************************/
246 
ajChararrPut(AjPChar * thys,ajuint elem,char v)247 AjBool ajChararrPut(AjPChar *thys, ajuint elem, char v)
248 {
249     if(!thys || !*thys)
250 	ajErr("Attempt to write to illegal array value %d\n",elem);
251 
252     if(elem < (*thys)->Res)
253     {
254 	if(elem>=(*thys)->Len)
255 	    (*thys)->Len = elem+1;
256 
257 	(*thys)->Ptr[elem] = v;
258 
259 	return ajFalse;
260     }
261 
262     arrChararrResize(thys, elem);
263 
264     (*thys)->Ptr[elem] = v;
265 
266     return ajTrue;
267 }
268 
269 
270 
271 
272 /* @func ajChararrChararr *****************************************************
273 **
274 ** Returns the current char* pointer. This will remain valid until
275 ** the array is resized or deleted.
276 **
277 ** @param [r] thys [const AjPChar] Source array
278 ** @return [char*] Current array pointer, or a null string if undefined.
279 ** @category cast [AjPChar] Retrieve internal pointer
280 **
281 ** @release 2.0.0
282 ** @@
283 ******************************************************************************/
284 
ajChararrChararr(const AjPChar thys)285 char* ajChararrChararr(const AjPChar thys)
286 {
287     if(!thys || !thys->Len)
288 	return NULL;
289 
290     return thys->Ptr;
291 }
292 
293 
294 
295 
296 /* @func ajChararrLen *********************************************************
297 **
298 ** Get length of dynamic character array
299 **
300 ** @param [r] thys [const AjPChar] Source array
301 ** @return [ajuint] length
302 **
303 ** @release 6.2.0
304 ** @@
305 ******************************************************************************/
306 
ajChararrLen(const AjPChar thys)307 ajuint ajChararrLen(const AjPChar thys)
308 {
309     return thys->Len;
310 }
311 
312 
313 
314 
315 /* @func ajIntNew *************************************************************
316 **
317 ** Default constructor for empty AJAX integer arrays.
318 **
319 ** @return [AjPInt] Pointer to an empty integer array structure
320 ** @category new [AjPInt] Default constructor
321 **
322 ** @release 1.0.0
323 ** @@
324 ******************************************************************************/
325 
ajIntNew(void)326 AjPInt ajIntNew(void)
327 {
328     AjPInt thys;
329 
330     AJNEW0(thys);
331     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(ajint));
332     thys->Len = 0;
333     thys->Res = RESERVED_SIZE;
334 
335     arrTotal++;
336     arrAlloc += RESERVED_SIZE*sizeof(ajint);
337 
338     return thys;
339 }
340 
341 
342 
343 
344 /* @func ajIntNewRes **********************************************************
345 **
346 ** Constructor given an initial reserved size.
347 **
348 ** @param [r] size [ajuint] Reserved size
349 ** @return [AjPInt] Pointer to an empty integer array struct of specified size.
350 ** @category new [AjPInt] Constructor with reserved size
351 **
352 ** @release 6.2.0
353 ** @@
354 ******************************************************************************/
355 
ajIntNewRes(ajuint size)356 AjPInt ajIntNewRes(ajuint size)
357 {
358     AjPInt thys;
359 
360     size = ajRound(size,RESERVED_SIZE);
361 
362     AJNEW0(thys);
363     thys->Ptr = AJALLOC0(size*sizeof(ajint));
364     thys->Len = 0;
365     thys->Res = size;
366 
367     arrTotal++;
368     arrAlloc += size*sizeof(ajint);
369 
370     /*ajDebug("ajIntNewRes size %d*%d %d\n",
371 	    size, sizeof(ajint), size*sizeof(ajint));*/
372 
373     return thys;
374 }
375 
376 
377 
378 
379 
380 /* @func ajIntDel *************************************************************
381 **
382 ** Default destructor for AJAX integer arrays.
383 **
384 ** If the given array is a NULL pointer, simply returns.
385 **
386 ** @param  [d] thys [AjPInt*] Pointer to the ajint array to be deleted.
387 **         The pointer is always deleted.
388 ** @return [void]
389 ** @category delete [AjPInt] Default destructor
390 **
391 ** @release 1.0.0
392 ** @@
393 ******************************************************************************/
394 
ajIntDel(AjPInt * thys)395 void ajIntDel(AjPInt *thys)
396 {
397     if(!thys || !*thys)
398 	return;
399 
400     /*ajDebug("ajIntDel Len %u Res %u\n",
401 	    (*thys)->Len, (*thys)->Res);*/
402 
403     AJFREE((*thys)->Ptr);
404     AJFREE(*thys);
405 
406     *thys = NULL;
407 
408     arrFreeCount++;
409 
410     return;
411 }
412 
413 
414 
415 
416 /* @func ajIntGet *************************************************************
417 **
418 ** Retrieve an element from an AJAX integer array.
419 **
420 ** If the given array is a NULL pointer, simply returns.
421 **
422 ** @param  [r] thys [const AjPInt] Pointer to the ajint array.
423 ** @param  [r] elem [ajuint] array element.
424 **
425 ** @return [ajint] contents of array element
426 ** @category cast [AjPInt] Retrieve an integer from an array
427 **
428 ** @release 1.0.0
429 ** @@
430 ******************************************************************************/
431 
ajIntGet(const AjPInt thys,ajuint elem)432 ajint ajIntGet(const AjPInt thys, ajuint elem)
433 {
434     if(!thys || elem>=thys->Len)
435 	ajErr("Attempt to access bad ajint array index %d\n",elem);
436 
437     return thys->Ptr[elem];
438 }
439 
440 
441 
442 
443 /* @func ajIntPut *************************************************************
444 **
445 ** Load an integer array element.
446 **
447 ** If the given array is a NULL pointer an error is generated.
448 ** If the array is of insufficient size then the array is extended.
449 ** Negative indices generate an error.
450 **
451 ** @param  [w] thys [AjPInt*] Pointer to the ajint array.
452 ** @param  [r] elem [ajuint] array element.
453 ** @param  [r] v [ajint] value to load.
454 **
455 ** @return [AjBool] true if the array was extended.
456 ** @category modify [AjPInt] Load an integer array element
457 **
458 ** @release 1.0.0
459 ** @@
460 ******************************************************************************/
461 
ajIntPut(AjPInt * thys,ajuint elem,ajint v)462 AjBool ajIntPut(AjPInt *thys, ajuint elem, ajint v)
463 {
464     if(!thys || !*thys)
465 	ajErr("Attempt to write to illegal array value %d\n",elem);
466 
467     if(elem < (*thys)->Res)
468     {
469 	if(elem>=(*thys)->Len)
470 	    (*thys)->Len = elem+1;
471 	(*thys)->Ptr[elem] = v;
472 	return ajFalse;
473     }
474 
475     arrIntResize(thys, elem);
476 
477     (*thys)->Ptr[elem] = v;
478 
479     return ajTrue;
480 }
481 
482 
483 
484 
485 /* @func ajIntInc *************************************************************
486 **
487 ** Increment an integer array element.
488 **
489 ** If the given array is a NULL pointer an error is generated.
490 ** Negative indices generate an error.
491 **
492 ** @param  [w] thys [AjPInt*] Pointer to the ajint array.
493 ** @param  [r] elem [ajuint] array element.
494 **
495 ** @return [void]
496 **
497 ** @release 1.8.0
498 ** @@
499 ******************************************************************************/
500 
ajIntInc(AjPInt * thys,ajuint elem)501 void ajIntInc(AjPInt *thys, ajuint elem)
502 {
503     if(!thys || !*thys || elem>(*thys)->Len)
504 	ajErr("Attempt to write to illegal array value %d\n",elem);
505 
506 
507     ++(*thys)->Ptr[elem];
508 
509     return;
510 }
511 
512 
513 
514 
515 /* @func ajIntDec *************************************************************
516 **
517 ** Decrement an integer array element.
518 **
519 ** If the given array is a NULL pointer an error is generated.
520 ** Negative indices generate an error.
521 **
522 ** @param  [w] thys [AjPInt*] Pointer to the ajint array.
523 ** @param  [r] elem [ajuint] array element.
524 **
525 ** @return [void]
526 **
527 ** @release 1.8.0
528 ** @@
529 ******************************************************************************/
530 
ajIntDec(AjPInt * thys,ajuint elem)531 void ajIntDec(AjPInt *thys, ajuint elem)
532 {
533     if(!thys || !*thys || elem>(*thys)->Len)
534 	ajErr("Attempt to write to illegal array value %d\n",elem);
535 
536     --(*thys)->Ptr[elem];
537 
538     return;
539 }
540 
541 
542 
543 
544 /* @func ajUintNew ************************************************************
545 **
546 ** Default constructor for empty AJAX unsigned integer arrays.
547 **
548 ** @return [AjPUint] Pointer to an empty unsigned integer array structure
549 ** @category new [AjPUint] Default constructor
550 **
551 ** @release 4.1.0
552 ** @@
553 ******************************************************************************/
554 
ajUintNew(void)555 AjPUint ajUintNew(void)
556 {
557     AjPUint thys;
558 
559     AJNEW0(thys);
560     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(ajuint));
561     thys->Len = 0;
562     thys->Res = RESERVED_SIZE;
563 
564     arrTotal++;
565     arrAlloc += RESERVED_SIZE*sizeof(ajuint);
566 
567     return thys;
568 }
569 
570 
571 
572 
573 /* @func ajUintNewRes *********************************************************
574 **
575 ** Constructor given an initial reserved size.
576 **
577 ** @param [r] size [ajuint] Reserved size
578 ** @return [AjPUint] Pointer to an empty unsigned integer array struct
579 **                   of specified size.
580 ** @category new [AjPUint] Constructor with reserved size
581 **
582 ** @release 6.2.0
583 ** @@
584 ******************************************************************************/
585 
ajUintNewRes(ajuint size)586 AjPUint ajUintNewRes(ajuint size)
587 {
588     AjPUint thys;
589 
590     size = ajRound(size,RESERVED_SIZE);
591 
592     AJNEW0(thys);
593     thys->Ptr = AJALLOC0(size*sizeof(ajuint));
594     thys->Len = 0;
595     thys->Res = size;
596 
597     arrTotal++;
598     arrAlloc += size*sizeof(ajuint);
599 
600     /*ajDebug("ajUintNewL size %d*%d %d\n",
601 	    size, sizeof(ajuint), size*sizeof(ajuint));*/
602 
603     return thys;
604 }
605 
606 
607 
608 
609 /* @func ajUintDel ************************************************************
610 **
611 ** Default destructor for AJAX integer integer arrays.
612 **
613 ** If the given array is a NULL pointer, simply returns.
614 **
615 ** @param  [d] thys [AjPUint*] Pointer to the ajuint array to be deleted.
616 **         The pointer is always deleted.
617 ** @return [void]
618 ** @category delete [AjPUint] Default destructor
619 **
620 ** @release 4.1.0
621 ** @@
622 ******************************************************************************/
623 
ajUintDel(AjPUint * thys)624 void ajUintDel(AjPUint *thys)
625 {
626     if(!thys || !*thys)
627 	return;
628 
629     /*ajDebug("ajUintDel Len %u Res %u\n",
630 	    (*thys)->Len, (*thys)->Res);*/
631 
632     AJFREE((*thys)->Ptr);
633     AJFREE(*thys);
634 
635     *thys = NULL;
636 
637     arrFreeCount++;
638 
639     return;
640 }
641 
642 
643 
644 
645 /* @func ajUintGet ************************************************************
646 **
647 ** Retrieve an element from an AJAX unsigned integer array.
648 **
649 ** If the given array is a NULL pointer, simply returns.
650 **
651 ** @param  [r] thys [const AjPUint] Pointer to the ajuint array.
652 ** @param  [r] elem [ajuint] array element.
653 **
654 ** @return [ajuint] contents of array element
655 ** @category cast [AjPUint] Retrieve an integer from an array
656 **
657 ** @release 4.1.0
658 ** @@
659 ******************************************************************************/
660 
ajUintGet(const AjPUint thys,ajuint elem)661 ajuint ajUintGet(const AjPUint thys, ajuint elem)
662 {
663     if(!thys || elem>=thys->Len)
664 	ajErr("Attempt to access bad ajuint array index %d\n",elem);
665 
666     return thys->Ptr[elem];
667 }
668 
669 
670 
671 
672 /* @func ajUintPut ************************************************************
673 **
674 ** Load an unsigned integer array element.
675 **
676 ** If the given array is a NULL pointer an error is generated.
677 ** If the array is of insufficient size then the array is extended.
678 ** Negative indices generate an error.
679 **
680 ** @param  [w] thys [AjPUint*] Pointer to the ajuint array.
681 ** @param  [r] elem [ajuint] array element.
682 ** @param  [r] v [ajuint] value to load.
683 **
684 ** @return [AjBool] true if the array was extended.
685 ** @category modify [AjPUint] Load an integer array element
686 **
687 ** @release 4.1.0
688 ** @@
689 ******************************************************************************/
690 
ajUintPut(AjPUint * thys,ajuint elem,ajuint v)691 AjBool ajUintPut(AjPUint *thys, ajuint elem, ajuint v)
692 {
693     if(!thys || !*thys)
694 	ajErr("Attempt to write to illegal array value %d\n",elem);
695 
696     if(elem < (*thys)->Res)
697     {
698 	if(elem>=(*thys)->Len)
699 	    (*thys)->Len = elem+1;
700 	(*thys)->Ptr[elem] = v;
701 	return ajFalse;
702     }
703 
704     arrUintResize(thys, elem);
705 
706     (*thys)->Ptr[elem] = v;
707 
708     return ajTrue;
709 }
710 
711 
712 
713 
714 /* @func ajUintInc ************************************************************
715 **
716 ** Increment an unsigned integer array element.
717 **
718 ** If the given array is a NULL pointer an error is generated.
719 ** Negative indices generate an error.
720 **
721 ** @param  [w] thys [AjPUint*] Pointer to the ajuint array.
722 ** @param  [r] elem [ajuint] array element.
723 **
724 ** @return [void]
725 **
726 ** @release 4.1.0
727 ** @@
728 ******************************************************************************/
729 
ajUintInc(AjPUint * thys,ajuint elem)730 void ajUintInc(AjPUint *thys, ajuint elem)
731 {
732     if(!thys || !*thys || elem>(*thys)->Len)
733 	ajErr("Attempt to write to illegal array value %d\n",elem);
734 
735 
736     ++(*thys)->Ptr[elem];
737 
738     return;
739 }
740 
741 
742 
743 
744 /* @func ajUintDec ************************************************************
745 **
746 ** Decrement an unsigned integer array element.
747 **
748 ** If the given array is a NULL pointer an error is generated.
749 ** Negative indices generate an error.
750 **
751 ** @param  [w] thys [AjPUint*] Pointer to the ajuint array.
752 ** @param  [r] elem [ajuint] array element.
753 **
754 ** @return [void]
755 **
756 ** @release 4.1.0
757 ** @@
758 ******************************************************************************/
759 
ajUintDec(AjPUint * thys,ajuint elem)760 void ajUintDec(AjPUint *thys, ajuint elem)
761 {
762     if(!thys || !*thys || elem>(*thys)->Len)
763 	ajErr("Attempt to write to illegal array value %d\n",elem);
764 
765     --(*thys)->Ptr[elem];
766 
767     return;
768 }
769 
770 
771 
772 
773 /* @funcstatic arrChararrResize ***********************************************
774 **
775 ** Resize a character array.
776 **
777 ** If the given array is a NULL pointer an error is generated.
778 ** Negative indices generate an error.
779 **
780 ** @param  [w] thys [AjPChar*] Pointer to the char array.
781 ** @param  [r] size [ajuint] new size.
782 **
783 ** @return [AjBool] true if the array was extended.
784 **
785 ** @release 4.1.0
786 ** @@
787 ******************************************************************************/
788 
arrChararrResize(AjPChar * thys,ajuint size)789 static AjBool arrChararrResize(AjPChar *thys, ajuint size)
790 {
791     AjPChar p = NULL;
792     ajuint    s;
793     ajuint    clen;
794     ajuint    limit;
795 
796 
797     if(!thys || !*thys)
798 	ajErr("Illegal attempt to resize character array");
799 
800     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
801     s = ajRound(size+1,RESERVED_SIZE);
802 
803     if(s <= clen)
804 	return ajFalse;
805 
806     /*ajDebug("ajChararrResize %d (%d) -> %d (%d)\n",
807 	    (*thys)->Len, clen, size, s);*/
808 
809     p = *thys;
810 
811     *thys = ajChararrNewRes(s);
812 
813     if(size < p->Len)
814 	limit = size+1;
815     else
816 	limit = p->Len;
817 
818     memmove((*thys)->Ptr,p->Ptr,limit*sizeof(char));
819 
820     (*thys)->Len = size+1;
821 
822 
823     ajChararrDel(&p);
824 
825     arrResize++;
826 
827     return ajTrue;
828 }
829 
830 
831 
832 
833 /* @funcstatic arrIntResize ***************************************************
834 **
835 ** Resize an integer array.
836 **
837 ** If the given array is a NULL pointer an error is generated.
838 ** Negative indices generate an error.
839 **
840 ** @param  [w] thys [AjPInt*] Pointer to the ajint array.
841 ** @param  [r] size [ajuint] new size.
842 **
843 ** @return [AjBool] true if the array was extended.
844 **
845 ** @release 4.1.0
846 ** @@
847 ******************************************************************************/
848 
arrIntResize(AjPInt * thys,ajuint size)849 static AjBool arrIntResize(AjPInt *thys, ajuint size)
850 {
851     AjPInt p = NULL;
852     ajuint    s;
853     ajuint    clen;
854     ajuint    limit;
855 
856 
857     if(!thys || !*thys)
858 	ajErr("Illegal attempt to resize integer array");
859 
860     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
861     s    = ajRound(size+1,RESERVED_SIZE);
862 
863     if(s <= clen)
864 	return ajFalse;
865 
866     /*ajDebug("ajIntResize %d (%d) -> %d (%d)\n",
867             (*thys)->Len, clen, size, s);*/
868 
869     p = *thys;
870 
871     *thys = ajIntNewRes(s);
872 
873     if(size < p->Len)
874 	limit = size+1;
875     else
876 	limit = p->Len;
877 
878     memmove((*thys)->Ptr,p->Ptr,limit*sizeof(ajint));
879 
880     (*thys)->Len = size+1;
881 
882 
883     ajIntDel(&p);
884 
885     arrResize++;
886 
887     return ajTrue;
888 }
889 
890 
891 
892 
893 /* @func ajIntInt *************************************************************
894 **
895 ** Returns the current ajint* pointer. This will remain valid until
896 ** the array is resized or deleted.
897 **
898 ** @param [r] thys [const AjPInt] Source array
899 ** @return [ajint*] Current array pointer, or a null string if undefined.
900 ** @category cast [AjPInt] Retrieve internal pointer
901 **
902 ** @release 1.0.0
903 ** @@
904 ******************************************************************************/
905 
ajIntInt(const AjPInt thys)906 ajint* ajIntInt(const AjPInt thys)
907 {
908     if(!thys || !thys->Len)
909 	return NULL;
910 
911     return thys->Ptr;
912 }
913 
914 
915 
916 
917 /* @func ajIntLen *************************************************************
918 **
919 ** Get length of dynamic 1d ajint array
920 **
921 ** @param [r] thys [const AjPInt] Source array
922 ** @return [ajuint] length
923 **
924 ** @release 1.0.0
925 ** @@
926 ******************************************************************************/
927 
ajIntLen(const AjPInt thys)928 ajuint ajIntLen(const AjPInt thys)
929 {
930     return thys->Len;
931 }
932 
933 
934 
935 
936 /* @funcstatic arrUintResize **************************************************
937 **
938 ** Resize an unsigned integer array.
939 **
940 ** If the given array is a NULL pointer an error is generated.
941 ** Negative indices generate an error.
942 **
943 ** @param  [w] thys [AjPUint*] Pointer to the ajuint array.
944 ** @param  [r] size [ajuint] new size.
945 **
946 ** @return [AjBool] true if the array was extended.
947 **
948 ** @release 4.1.0
949 ** @@
950 ******************************************************************************/
951 
arrUintResize(AjPUint * thys,ajuint size)952 static AjBool arrUintResize(AjPUint *thys, ajuint size)
953 {
954     AjPUint p = NULL;
955     ajuint    s;
956     ajuint    clen;
957     ajuint    limit;
958 
959 
960     if(!thys || !*thys)
961 	ajErr("Illegal attempt to resize unsigned integer array");
962 
963     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
964     s    = ajRound(size+1,RESERVED_SIZE);
965 
966     if(s <= clen)
967 	return ajFalse;
968 
969     /*ajDebug("ajIntResize %d (%d) -> %d (%d)\n",
970             (*thys)->Len, clen, size, s);*/
971 
972     p = *thys;
973 
974     *thys = ajUintNewRes(s);
975 
976     if(size < p->Len)
977 	limit = size+1;
978     else
979 	limit = p->Len;
980 
981     memmove((*thys)->Ptr,p->Ptr,limit*sizeof(ajuint));
982 
983     (*thys)->Len = size+1;
984 
985 
986     ajUintDel(&p);
987 
988     arrResize++;
989 
990     return ajTrue;
991 }
992 
993 
994 
995 
996 /* @func ajUintUint ***********************************************************
997 **
998 ** Returns the current ajuint* pointer. This will remain valid until
999 ** the array is resized or deleted.
1000 **
1001 ** @param [r] thys [const AjPUint] Source array
1002 ** @return [ajuint*] Current array pointer, or a null string if undefined.
1003 ** @category cast [AjPUint] Retrieve internal pointer
1004 **
1005 ** @release 4.1.0
1006 ** @@
1007 ******************************************************************************/
1008 
ajUintUint(const AjPUint thys)1009 ajuint* ajUintUint(const AjPUint thys)
1010 {
1011     if(!thys || !thys->Len)
1012 	return NULL;
1013 
1014     return thys->Ptr;
1015 }
1016 
1017 
1018 
1019 
1020 /* @func ajUintLen ************************************************************
1021 **
1022 ** Get length of dynamic 1d ajuint array
1023 **
1024 ** @param [r] thys [const AjPUint] Source array
1025 ** @return [ajuint] length
1026 **
1027 ** @release 4.1.0
1028 ** @@
1029 ******************************************************************************/
1030 
ajUintLen(const AjPUint thys)1031 ajuint ajUintLen(const AjPUint thys)
1032 {
1033     return thys->Len;
1034 }
1035 
1036 
1037 
1038 
1039 /* @func ajFloatNew ***********************************************************
1040 **
1041 ** Default constructor for empty AJAX float arrays.
1042 **
1043 ** @return [AjPFloat] Pointer to an empty float array structure
1044 ** @category new [AjPFloat] Default constructor
1045 **
1046 ** @release 1.0.0
1047 ** @@
1048 ******************************************************************************/
1049 
ajFloatNew(void)1050 AjPFloat ajFloatNew(void)
1051 {
1052     AjPFloat thys;
1053 
1054     AJNEW0(thys);
1055     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(float));
1056     thys->Len = 0;
1057     thys->Res = RESERVED_SIZE;
1058 
1059     arrTotal++;
1060     arrAlloc += RESERVED_SIZE*sizeof(float);
1061 
1062     return thys;
1063 }
1064 
1065 
1066 
1067 
1068 /* @func ajFloatNewRes ********************************************************
1069 **
1070 ** Constructor given an initial reserved size.
1071 **
1072 ** @param [r] size [ajuint] Reserved size
1073 ** @return [AjPFloat] Pointer to an empty float array struct of specified size.
1074 ** @category new [AjPFloat] Constructor with reserved size
1075 **
1076 ** @release 6.2.0
1077 ** @@
1078 ******************************************************************************/
1079 
ajFloatNewRes(ajuint size)1080 AjPFloat ajFloatNewRes(ajuint size)
1081 {
1082     AjPFloat thys;
1083 
1084     size = ajRound(size,RESERVED_SIZE);
1085 
1086     AJNEW0(thys);
1087     thys->Ptr = AJALLOC0(size*sizeof(float));
1088     thys->Len = 0;
1089     thys->Res = size;
1090 
1091     arrTotal++;
1092     arrAlloc += size*sizeof(float);
1093 
1094     return thys;
1095 }
1096 
1097 
1098 
1099 
1100 /* @func ajFloatDel ***********************************************************
1101 **
1102 ** Default destructor for AJAX float arrays.
1103 **
1104 ** If the given array is a NULL pointer, simply returns.
1105 **
1106 ** @param  [d] thys [AjPFloat*] Pointer to the float array to be deleted.
1107 **         The pointer is always deleted.
1108 ** @return [void]
1109 ** @category delete [AjPFloat] Default destructor
1110 **
1111 ** @release 1.0.0
1112 ** @@
1113 ******************************************************************************/
1114 
ajFloatDel(AjPFloat * thys)1115 void ajFloatDel(AjPFloat *thys)
1116 {
1117     if(!thys || !*thys)
1118 	return;
1119 
1120     /*ajDebug("ajFloatDel Len %u Res %u\n",
1121 	    (*thys)->Len, (*thys)->Res);*/
1122 
1123     AJFREE((*thys)->Ptr);
1124     AJFREE(*thys);
1125 
1126     *thys = NULL;
1127 
1128     arrFreeCount++;
1129 
1130     return;
1131 }
1132 
1133 
1134 
1135 
1136 /* @func ajFloatGet ***********************************************************
1137 **
1138 ** Retrieve an element from an AJAX float array.
1139 **
1140 ** If the given array is a NULL pointer, simply returns.
1141 **
1142 ** @param  [r] thys [const AjPFloat] Pointer to the float array.
1143 ** @param  [r] elem [ajuint] array element.
1144 **
1145 ** @return [float] contents of array element
1146 ** @category cast [AjPFloat] Retrieve a float from an array
1147 **
1148 ** @release 1.0.0
1149 ** @@
1150 ******************************************************************************/
1151 
ajFloatGet(const AjPFloat thys,ajuint elem)1152 float ajFloatGet(const AjPFloat thys, ajuint elem)
1153 {
1154     if(!thys || elem>=thys->Len)
1155 	ajErr("Attempt to access bad float array index %d\n",elem);
1156 
1157     return thys->Ptr[elem];
1158 }
1159 
1160 
1161 
1162 
1163 /* @func ajFloatPut ***********************************************************
1164 **
1165 ** Load a float array element.
1166 **
1167 ** If the given array is a NULL pointer an error is generated.
1168 ** If the array is of insufficient size then the array is extended.
1169 ** Negative indices generate an error.
1170 **
1171 ** @param  [w] thys [AjPFloat*] Pointer to the float array.
1172 ** @param  [r] elem [ajuint] array element.
1173 ** @param  [r] v [float] value to load.
1174 **
1175 ** @return [AjBool] true if the array was extended.
1176 ** @category modify [AjPFloat] Load a float array element
1177 **
1178 ** @release 1.0.0
1179 ** @@
1180 ******************************************************************************/
1181 
ajFloatPut(AjPFloat * thys,ajuint elem,float v)1182 AjBool ajFloatPut(AjPFloat *thys, ajuint elem, float v)
1183 {
1184     if(!thys || !*thys)
1185 	ajErr("Attempt to write to illegal array value %d\n",elem);
1186 
1187     if(elem < (*thys)->Res)
1188     {
1189 	if(elem>=(*thys)->Len)
1190 	    (*thys)->Len = elem+1;
1191 
1192 	(*thys)->Ptr[elem] = v;
1193 	return ajFalse;
1194     }
1195 
1196     arrFloatResize(thys, elem);
1197 
1198     (*thys)->Ptr[elem] = v;
1199 
1200     return ajTrue;
1201 }
1202 
1203 
1204 
1205 
1206 
1207 /* @funcstatic arrFloatResize *************************************************
1208 **
1209 ** Resize a float array.
1210 **
1211 ** If the given array is a NULL pointer an error is generated.
1212 ** Negative indices generate an error.
1213 **
1214 ** @param  [w] thys [AjPFloat*] Pointer to the float array.
1215 ** @param  [r] size [ajuint] new size.
1216 **
1217 ** @return [AjBool] true if the array was extended.
1218 **
1219 ** @release 4.1.0
1220 ** @@
1221 ******************************************************************************/
1222 
arrFloatResize(AjPFloat * thys,ajuint size)1223 static AjBool arrFloatResize(AjPFloat *thys, ajuint size)
1224 {
1225     AjPFloat p = NULL;
1226     ajuint    s;
1227     ajuint    clen;
1228     ajuint    limit;
1229 
1230 
1231     if(!thys || !*thys)
1232 	ajErr("Illegal attempt to resize float array");
1233 
1234     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
1235     s = ajRound(size+1,RESERVED_SIZE);
1236 
1237     if(s <= clen)
1238 	return ajFalse;
1239 
1240     /*ajDebug("ajFloatResize %d (%d) -> %d (%d)\n",
1241             (*thys)->Len, clen, size, s);*/
1242 
1243     p = *thys;
1244 
1245     *thys = ajFloatNewRes(s);
1246 
1247     if(size < p->Len)
1248 	limit = size+1;
1249     else
1250 	limit = p->Len;
1251 
1252     memmove((*thys)->Ptr,p->Ptr,limit*sizeof(float));
1253 
1254     (*thys)->Len = size+1;
1255 
1256 
1257     ajFloatDel(&p);
1258 
1259     arrResize++;
1260 
1261     return ajTrue;
1262 }
1263 
1264 
1265 
1266 
1267 /* @func ajFloatFloat *********************************************************
1268 **
1269 ** Returns the current float* pointer. This will remain valid until
1270 ** the array is resized or deleted.
1271 **
1272 ** @param [r] thys [const AjPFloat] Source array
1273 ** @return [float*] Current array pointer, or a null string if undefined.
1274 ** @category cast [AjPFloat] Retrieve internal pointer
1275 **
1276 ** @release 1.0.0
1277 ** @@
1278 ******************************************************************************/
1279 
ajFloatFloat(const AjPFloat thys)1280 float* ajFloatFloat(const AjPFloat thys)
1281 {
1282     if(!thys || !thys->Len)
1283 	return NULL;
1284 
1285     return thys->Ptr;
1286 }
1287 
1288 
1289 
1290 
1291 /* @func ajFloatLen ***********************************************************
1292 **
1293 ** Get length of dynamic 1d float array
1294 **
1295 ** @param [r] thys [const AjPFloat] Source array
1296 ** @return [ajuint] length
1297 **
1298 ** @release 1.0.0
1299 ** @@
1300 ******************************************************************************/
1301 
ajFloatLen(const AjPFloat thys)1302 ajuint ajFloatLen(const AjPFloat thys)
1303 {
1304     return thys->Len;
1305 }
1306 
1307 
1308 
1309 
1310 /* @func ajDoubleNew **********************************************************
1311 **
1312 ** Default constructor for empty AJAX double arrays.
1313 **
1314 ** @return [AjPDouble] Pointer to an empty double array structure
1315 ** @category new [AjPDouble] Default constructor
1316 **
1317 ** @release 1.0.0
1318 ** @@
1319 ******************************************************************************/
1320 
ajDoubleNew(void)1321 AjPDouble ajDoubleNew(void)
1322 {
1323     AjPDouble thys;
1324 
1325     AJNEW0(thys);
1326     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(double));
1327     thys->Len = 0;
1328     thys->Res = RESERVED_SIZE;
1329 
1330     arrTotal++;
1331     arrAlloc += RESERVED_SIZE*sizeof(double);
1332 
1333     return thys;
1334 }
1335 
1336 
1337 
1338 
1339 /* @func ajDoubleNewRes *******************************************************
1340 **
1341 ** Constructor given an initial reserved size.
1342 **
1343 ** @param [r] size [ajuint] Reserved size
1344 ** @return [AjPDouble] Pointer to an empty double array struct
1345 **                     of specified size.
1346 ** @category new [AjPDouble] Constructor with reserved size
1347 **
1348 ** @release 6.2.0
1349 ** @@
1350 ******************************************************************************/
1351 
ajDoubleNewRes(ajuint size)1352 AjPDouble ajDoubleNewRes(ajuint size)
1353 {
1354     AjPDouble thys;
1355 
1356     size = ajRound(size,RESERVED_SIZE);
1357 
1358     AJNEW0(thys);
1359     thys->Ptr = AJALLOC0(size*sizeof(double));
1360     thys->Len = 0;
1361     thys->Res = size;
1362 
1363     arrTotal++;
1364     arrAlloc += size*sizeof(double);
1365 
1366     return thys;
1367 }
1368 
1369 
1370 
1371 
1372 /* @func ajDoubleDel **********************************************************
1373 **
1374 ** Default destructor for AJAX double arrays.
1375 **
1376 ** If the given array is a NULL pointer, simply returns.
1377 **
1378 ** @param  [d] thys [AjPDouble*] Pointer to the double array to be deleted.
1379 **         The pointer is always deleted.
1380 ** @return [void]
1381 ** @category delete [AjPDouble] Default destructor
1382 **
1383 ** @release 1.0.0
1384 ** @@
1385 ******************************************************************************/
1386 
ajDoubleDel(AjPDouble * thys)1387 void ajDoubleDel(AjPDouble *thys)
1388 {
1389     if(!thys || !*thys)
1390 	return;
1391 
1392     /*ajDebug("ajDoubleDel Len %u Res %u\n",
1393 	    (*thys)->Len, (*thys)->Res);*/
1394 
1395     AJFREE((*thys)->Ptr);
1396     AJFREE(*thys);
1397 
1398     *thys = NULL;
1399 
1400     arrFreeCount++;
1401 
1402     return;
1403 }
1404 
1405 
1406 
1407 
1408 /* @func ajDoubleGet **********************************************************
1409 **
1410 ** Retrieve an element from an AJAX double array.
1411 **
1412 ** If the given array is a NULL pointer, simply returns.
1413 **
1414 ** @param  [r] thys [const AjPDouble] Pointer to the double array.
1415 ** @param  [r] elem [ajuint] array element.
1416 **
1417 ** @return [double] contents of array element
1418 ** @category cast [AjPDouble] Retrieve a double from an array
1419 **
1420 ** @release 1.0.0
1421 ** @@
1422 ******************************************************************************/
1423 
ajDoubleGet(const AjPDouble thys,ajuint elem)1424 double ajDoubleGet(const AjPDouble thys, ajuint elem)
1425 {
1426     if(!thys || elem>=thys->Len)
1427 	ajErr("Attempt to access bad double array index %d\n",elem);
1428 
1429     return thys->Ptr[elem];
1430 }
1431 
1432 
1433 
1434 
1435 /* @func ajDoublePut **********************************************************
1436 **
1437 ** Load a double array element.
1438 **
1439 ** If the given array is a NULL pointer an error is generated.
1440 ** If the array is of insufficient size then the array is extended.
1441 ** Negative indices generate an error.
1442 **
1443 ** @param  [w] thys [AjPDouble*] Pointer to the double array.
1444 ** @param  [r] elem [ajuint] array element.
1445 ** @param  [r] v [double] value to load.
1446 **
1447 ** @return [AjBool] true if the array was extended.
1448 ** @category modify [AjPDouble] Load a double array element
1449 **
1450 ** @release 1.0.0
1451 ** @@
1452 ******************************************************************************/
1453 
ajDoublePut(AjPDouble * thys,ajuint elem,double v)1454 AjBool ajDoublePut(AjPDouble *thys, ajuint elem, double v)
1455 {
1456     if(!thys || !*thys)
1457 	ajErr("Attempt to write to illegal array value %d\n",elem);
1458 
1459     if(elem < (*thys)->Res)
1460     {
1461 	if(elem>=(*thys)->Len)
1462 	    (*thys)->Len = elem+1;
1463 
1464 	(*thys)->Ptr[elem] = v;
1465 	return ajFalse;
1466     }
1467 
1468     arrDoubleResize(thys, elem);
1469 
1470     (*thys)->Ptr[elem] = v;
1471 
1472     return ajTrue;
1473 }
1474 
1475 
1476 
1477 
1478 /* @funcstatic arrDoubleResize ************************************************
1479 **
1480 ** Resize a double array.
1481 **
1482 ** If the given array is a NULL pointer an error is generated.
1483 ** Negative indices generate an error.
1484 **
1485 ** @param  [w] thys [AjPDouble*] Pointer to the double array.
1486 ** @param  [r] size [ajuint] new size.
1487 **
1488 ** @return [AjBool] true if the array was extended.
1489 **
1490 ** @release 4.1.0
1491 ** @@
1492 ******************************************************************************/
1493 
arrDoubleResize(AjPDouble * thys,ajuint size)1494 static AjBool arrDoubleResize(AjPDouble *thys, ajuint size)
1495 {
1496     AjPDouble p = NULL;
1497     ajuint    s;
1498     ajuint    clen;
1499     ajuint    limit;
1500 
1501 
1502     if(!thys || !*thys)
1503 	ajErr("Illegal attempt to resize double array");
1504 
1505     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
1506     s = ajRound(size+1,RESERVED_SIZE);
1507 
1508     if(s <= clen)
1509 	return ajFalse;
1510 
1511     /*ajDebug("ajDoubleResize %d (%d) -> %d (%d)\n",
1512             (*thys)->Len, clen, size, s);*/
1513 
1514     p = *thys;
1515 
1516     *thys = ajDoubleNewRes(s);
1517 
1518     if(size < p->Len)
1519 	limit = size+1;
1520     else
1521 	limit = p->Len;
1522 
1523     memmove((*thys)->Ptr,p->Ptr,limit*sizeof(double));
1524 
1525     (*thys)->Len = size+1;
1526 
1527 
1528     ajDoubleDel(&p);
1529 
1530     arrResize++;
1531 
1532     return ajTrue;
1533 }
1534 
1535 
1536 
1537 
1538 /* @func ajDoubleDouble *******************************************************
1539 **
1540 ** Returns the current double* pointer. This will remain valid until
1541 ** the array is resized or deleted.
1542 **
1543 ** @param [r] thys [const AjPDouble] Source array
1544 ** @return [double*] Current array pointer, or a null string if undefined.
1545 ** @category cast [AjPDouble] Retrieve internal pointer
1546 **
1547 ** @release 1.0.0
1548 ** @@
1549 ******************************************************************************/
1550 
ajDoubleDouble(const AjPDouble thys)1551 double* ajDoubleDouble(const AjPDouble thys)
1552 {
1553     if(!thys || !thys->Len)
1554 	return NULL;
1555 
1556     return thys->Ptr;
1557 }
1558 
1559 
1560 
1561 
1562 /* @func ajDoubleLen **********************************************************
1563 **
1564 ** Get length of dynamic 1d double array
1565 **
1566 ** @param [r] thys [const AjPDouble] Source array
1567 ** @return [ajuint] length
1568 **
1569 ** @release 1.0.0
1570 ** @@
1571 ******************************************************************************/
1572 
ajDoubleLen(const AjPDouble thys)1573 ajuint ajDoubleLen(const AjPDouble thys)
1574 {
1575     return thys->Len;
1576 }
1577 
1578 
1579 
1580 
1581 /* @func ajShortNew ***********************************************************
1582 **
1583 ** Default constructor for empty AJAX short arrays.
1584 **
1585 ** @return [AjPShort] Pointer to an empty short array structure
1586 ** @category new [AjPShort] Default constructor
1587 **
1588 ** @release 1.0.0
1589 ** @@
1590 ******************************************************************************/
1591 
ajShortNew(void)1592 AjPShort ajShortNew(void)
1593 {
1594     AjPShort thys;
1595 
1596     AJNEW0(thys);
1597     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(short));
1598     thys->Len = 0;
1599     thys->Res = RESERVED_SIZE;
1600 
1601     arrTotal++;
1602     arrAlloc += RESERVED_SIZE*sizeof(short);
1603 
1604     return thys;
1605 }
1606 
1607 
1608 
1609 
1610 /* @func ajShortNewRes ********************************************************
1611 **
1612 ** Constructor given an initial reserved size.
1613 **
1614 ** @param [r] size [ajuint] Reserved size
1615 ** @return [AjPShort] Pointer to an empty short array struct of specified size.
1616 ** @category new [AjPShort] Constructor with reserved size
1617 **
1618 ** @release 6.2.0
1619 ** @@
1620 ******************************************************************************/
1621 
ajShortNewRes(ajuint size)1622 AjPShort ajShortNewRes(ajuint size)
1623 {
1624     AjPShort thys;
1625 
1626     size = ajRound(size,RESERVED_SIZE);
1627 
1628     AJNEW0(thys);
1629     thys->Ptr = AJALLOC0(size*sizeof(short));
1630     thys->Len = 0;
1631     thys->Res = size;
1632 
1633     arrTotal++;
1634     arrAlloc += size*sizeof(short);
1635 
1636     return thys;
1637 }
1638 
1639 
1640 
1641 
1642 /* @func ajShortDel ***********************************************************
1643 **
1644 ** Default destructor for AJAX short arrays.
1645 **
1646 ** If the given array is a NULL pointer, simply returns.
1647 **
1648 ** @param  [d] thys [AjPShort*] Pointer to the short array to be deleted.
1649 **         The pointer is always deleted.
1650 ** @return [void]
1651 ** @category delete [AjPShort] Default destructor
1652 **
1653 ** @release 1.0.0
1654 ** @@
1655 ******************************************************************************/
1656 
ajShortDel(AjPShort * thys)1657 void ajShortDel(AjPShort *thys)
1658 {
1659     if(!thys || !*thys)
1660 	return;
1661 
1662     /*ajDebug("ajShortDel Len %u Res %u\n",
1663 	    (*thys)->Len, (*thys)->Res);*/
1664 
1665     AJFREE((*thys)->Ptr);
1666     AJFREE(*thys);
1667 
1668     *thys = NULL;
1669 
1670     arrFreeCount++;
1671 
1672     return;
1673 }
1674 
1675 
1676 
1677 
1678 /* @func ajShortGet ***********************************************************
1679 **
1680 ** Retrieve an element from an AJAX short array.
1681 **
1682 ** If the given array is a NULL pointer, simply returns.
1683 **
1684 ** @param  [r] thys [const AjPShort] Pointer to the short array.
1685 ** @param  [r] elem [ajuint] array element.
1686 **
1687 ** @return [short] contents of array element
1688 ** @category cast [AjPShort] Retrieve a short from an array
1689 **
1690 ** @release 1.0.0
1691 ** @@
1692 ******************************************************************************/
1693 
ajShortGet(const AjPShort thys,ajuint elem)1694 short ajShortGet(const AjPShort thys, ajuint elem)
1695 {
1696     if(!thys || elem>=thys->Len)
1697 	ajErr("Attempt to access bad short array index %d\n",elem);
1698 
1699     return thys->Ptr[elem];
1700 }
1701 
1702 
1703 
1704 
1705 /* @func ajShortPut ***********************************************************
1706 **
1707 ** Load a short array element.
1708 **
1709 ** If the given array is a NULL pointer an error is generated.
1710 ** If the array is of insufficient size then the array is extended.
1711 ** Negative indices generate an error.
1712 **
1713 ** @param  [w] thys [AjPShort*] Pointer to the short integer array.
1714 ** @param  [r] elem [ajuint] array element.
1715 ** @param  [r] v [short] value to load.
1716 **
1717 ** @return [AjBool] true if the array was extended.
1718 ** @category modify [AjPShort] Load a short array element
1719 **
1720 ** @release 1.0.0
1721 ** @@
1722 ******************************************************************************/
1723 
ajShortPut(AjPShort * thys,ajuint elem,short v)1724 AjBool ajShortPut(AjPShort *thys, ajuint elem, short v)
1725 {
1726     if(!thys || !*thys)
1727 	ajErr("Attempt to write to illegal array value %d\n",elem);
1728 
1729     if(elem < (*thys)->Res)
1730     {
1731 	if(elem>=(*thys)->Len)
1732 	    (*thys)->Len = elem+1;
1733 
1734 	(*thys)->Ptr[elem] = v;
1735 	return ajFalse;
1736     }
1737 
1738     arrShortResize(thys, elem);
1739 
1740     (*thys)->Ptr[elem] = v;
1741 
1742     return ajTrue;
1743 }
1744 
1745 
1746 
1747 
1748 /* @funcstatic arrShortResize *************************************************
1749 **
1750 ** Resize a short array.
1751 **
1752 ** If the given array is a NULL pointer an error is generated.
1753 ** Negative indices generate an error.
1754 **
1755 ** @param  [w] thys [AjPShort*] Pointer to the short integer array.
1756 ** @param  [r] size [ajuint] new size.
1757 **
1758 ** @return [AjBool] true if the array was extended.
1759 **
1760 ** @release 4.1.0
1761 ** @@
1762 ******************************************************************************/
1763 
arrShortResize(AjPShort * thys,ajuint size)1764 static AjBool arrShortResize(AjPShort *thys, ajuint size)
1765 {
1766     AjPShort p = NULL;
1767     ajuint    s;
1768     ajuint    clen;
1769     ajuint    limit;
1770 
1771 
1772     if(!thys || !*thys)
1773 	ajErr("Illegal attempt to resize short array");
1774 
1775     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
1776     s = ajRound(size+1,RESERVED_SIZE);
1777 
1778     if(s <= clen)
1779 	return ajFalse;
1780 
1781     /*ajDebug("ajShortResize %d (%d) -> %d (%d)\n",
1782             (*thys)->Len, clen, size, s);*/
1783 
1784     p = *thys;
1785 
1786     *thys = ajShortNewRes(s);
1787 
1788     if(size < p->Len)
1789 	limit = size+1;
1790     else
1791 	limit = p->Len;
1792 
1793     memmove((*thys)->Ptr,p->Ptr,limit*sizeof(short));
1794 
1795     (*thys)->Len = size+1;
1796 
1797 
1798     ajShortDel(&p);
1799 
1800     arrResize++;
1801 
1802     return ajTrue;
1803 }
1804 
1805 
1806 
1807 
1808 /* @func ajShortShort *********************************************************
1809 **
1810 ** Returns the current short* pointer. This will remain valid until
1811 ** the array is resized or deleted.
1812 **
1813 ** @param [r] thys [const AjPShort] Source array
1814 ** @return [short*] Current array pointer, or a null string if undefined.
1815 ** @category cast [AjPShort] Retrieve internal pointer
1816 **
1817 ** @release 1.0.0
1818 ** @@
1819 ******************************************************************************/
1820 
ajShortShort(const AjPShort thys)1821 short* ajShortShort(const AjPShort thys)
1822 {
1823     if(!thys || !thys->Len)
1824 	return NULL;
1825 
1826     return thys->Ptr;
1827 }
1828 
1829 
1830 
1831 
1832 /* @func ajShortLen ***********************************************************
1833 **
1834 ** Get length of dynamic 1d short array
1835 **
1836 ** @param [r] thys [const AjPShort] Source array
1837 ** @return [ajuint] length
1838 **
1839 ** @release 1.0.0
1840 ** @@
1841 ******************************************************************************/
1842 
ajShortLen(const AjPShort thys)1843 ajuint ajShortLen(const AjPShort thys)
1844 {
1845     return thys->Len;
1846 }
1847 
1848 
1849 
1850 
1851 /* @func ajLongNew ************************************************************
1852 **
1853 ** Default constructor for empty AJAX ajlong arrays.
1854 **
1855 ** @return [AjPLong] Pointer to an empty ajlong array structure
1856 ** @category new [AjPLong] Default constructor
1857 **
1858 ** @release 1.0.0
1859 ** @@
1860 ******************************************************************************/
1861 
ajLongNew(void)1862 AjPLong ajLongNew(void)
1863 {
1864     AjPLong thys;
1865 
1866     AJNEW0(thys);
1867     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(ajlong));
1868     thys->Len = 0;
1869     thys->Res = RESERVED_SIZE;
1870 
1871     arrTotal++;
1872     arrAlloc += RESERVED_SIZE*sizeof(ajlong);
1873 
1874     return thys;
1875 }
1876 
1877 
1878 
1879 
1880 /* @func ajLongNewRes *********************************************************
1881 **
1882 ** Constructor given an initial reserved size.
1883 **
1884 ** @param [r] size [ajuint] Reserved size
1885 ** @return [AjPLong] Pointer to an empty ajlong array struct of specified size.
1886 ** @category new [AjPLong] Constructor with reserved size
1887 **
1888 ** @release 6.2.0
1889 ** @@
1890 ******************************************************************************/
1891 
ajLongNewRes(ajuint size)1892 AjPLong ajLongNewRes(ajuint size)
1893 {
1894     AjPLong thys;
1895 
1896     size = ajRound(size,RESERVED_SIZE);
1897 
1898     AJNEW0(thys);
1899     thys->Ptr = AJALLOC0(size*sizeof(ajlong));
1900     thys->Len = 0;
1901     thys->Res = size;
1902 
1903     arrTotal++;
1904     arrAlloc += size*sizeof(ajlong);
1905 
1906     return thys;
1907 }
1908 
1909 
1910 
1911 
1912 /* @func ajLongDel ************************************************************
1913 **
1914 ** Default destructor for AJAX ajlong arrays.
1915 **
1916 ** If the given array is a NULL pointer, simply returns.
1917 **
1918 ** @param  [d] thys [AjPLong*] Pointer to the ajlong array to be deleted.
1919 **         The pointer is always deleted.
1920 ** @return [void]
1921 ** @category delete [AjPLong] Default destructor
1922 **
1923 ** @release 1.0.0
1924 ** @@
1925 ******************************************************************************/
1926 
ajLongDel(AjPLong * thys)1927 void ajLongDel(AjPLong *thys)
1928 {
1929     if(!thys || !*thys)
1930 	return;
1931 
1932     /*ajDebug("ajLongDel Len %u Res %u\n",
1933 	    (*thys)->Len, (*thys)->Res);*/
1934 
1935     AJFREE((*thys)->Ptr);
1936     AJFREE(*thys);
1937 
1938     *thys = NULL;
1939 
1940     arrFreeCount++;
1941 
1942     return;
1943 }
1944 
1945 
1946 
1947 
1948 /* @func ajLongGet ************************************************************
1949 **
1950 ** Retrieve an element from an AJAX ajlong array.
1951 **
1952 ** If the given array is a NULL pointer, simply returns.
1953 **
1954 ** @param  [r] thys [const AjPLong] Pointer to the ajlong array.
1955 ** @param  [r] elem [ajuint] array element.
1956 **
1957 ** @return [ajlong] contents of array element
1958 ** @category cast [AjPLong] Retrieve a ajlong from an array
1959 **
1960 ** @release 1.0.0
1961 ** @@
1962 ******************************************************************************/
1963 
ajLongGet(const AjPLong thys,ajuint elem)1964 ajlong ajLongGet(const AjPLong thys, ajuint elem)
1965 {
1966     if(!thys || elem>=thys->Len)
1967 	ajErr("Attempt to access bad ajlong array index %d\n",elem);
1968 
1969     return thys->Ptr[elem];
1970 }
1971 
1972 
1973 
1974 
1975 /* @func ajLongPut ************************************************************
1976 **
1977 ** Load a long integer array element.
1978 **
1979 ** If the given array is a NULL pointer an error is generated.
1980 ** If the array is of insufficient size then the array is extended.
1981 ** Negative indices generate an error.
1982 **
1983 ** @param  [w] thys [AjPLong*] Pointer to the long integer array.
1984 ** @param  [r] elem [ajuint] array element.
1985 ** @param  [r] v [ajlong] value to load.
1986 **
1987 ** @return [AjBool] true if the array was extended.
1988 ** @category modify [AjPLong] Load a ajlong array element
1989 **
1990 ** @release 1.0.0
1991 ** @@
1992 ******************************************************************************/
1993 
ajLongPut(AjPLong * thys,ajuint elem,ajlong v)1994 AjBool ajLongPut(AjPLong *thys, ajuint elem, ajlong v)
1995 {
1996     if(!thys || !*thys)
1997 	ajErr("Attempt to write to illegal array value %d\n",elem);
1998 
1999     if(elem < (*thys)->Res)
2000     {
2001 	if(elem>=(*thys)->Len)
2002 	    (*thys)->Len = elem+1;
2003 
2004 	(*thys)->Ptr[elem] = v;
2005 
2006 	return ajFalse;
2007     }
2008 
2009     arrLongResize(thys, elem);
2010 
2011     (*thys)->Ptr[elem] = v;
2012 
2013     return ajTrue;
2014 }
2015 
2016 
2017 
2018 
2019 /* @funcstatic arrLongResize **************************************************
2020 **
2021 ** Resize a long integer array.
2022 **
2023 ** If the given array is a NULL pointer an error is generated.
2024 ** Negative indices generate an error.
2025 **
2026 ** @param  [w] thys [AjPLong*] Pointer to the long integer array.
2027 ** @param  [r] size [ajuint] new size.
2028 **
2029 ** @return [AjBool] true if the array was extended.
2030 **
2031 ** @release 4.1.0
2032 ** @@
2033 ******************************************************************************/
2034 
arrLongResize(AjPLong * thys,ajuint size)2035 static AjBool arrLongResize(AjPLong *thys, ajuint size)
2036 {
2037     AjPLong p = NULL;
2038     ajuint    s;
2039     ajuint    clen;
2040     ajuint    limit;
2041 
2042 
2043     if(!thys || !*thys)
2044 	ajErr("Illegal attempt to resize ajlong array");
2045 
2046     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
2047     s = ajRound(size+1,RESERVED_SIZE);
2048 
2049     if(s <= clen)
2050 	return ajFalse;
2051 
2052     /*ajDebug("ajLongResize %d (%d) -> %d (%d)\n",
2053             (*thys)->Len, clen, size, s);*/
2054 
2055     p = *thys;
2056 
2057     *thys = ajLongNewRes(s);
2058 
2059     if(size < p->Len)
2060 	limit = size+1;
2061     else
2062 	limit = p->Len;
2063 
2064     memmove((*thys)->Ptr,p->Ptr,limit*sizeof(ajlong));
2065 
2066     (*thys)->Len = size+1;
2067 
2068 
2069     ajLongDel(&p);
2070 
2071     arrResize++;
2072 
2073     return ajTrue;
2074 }
2075 
2076 
2077 
2078 
2079 /* @func ajLongLong ***********************************************************
2080 **
2081 ** Returns the current ajlong* pointer. This will remain valid until
2082 ** the array is resized or deleted.
2083 **
2084 ** @param [r] thys [const AjPLong] Source array
2085 ** @return [ajlong*] Current array pointer, or a null string if undefined.
2086 ** @category cast [AjPLong] Retrieve internal pointer
2087 **
2088 ** @release 1.0.0
2089 ** @@
2090 ******************************************************************************/
2091 
ajLongLong(const AjPLong thys)2092 ajlong* ajLongLong(const AjPLong thys)
2093 {
2094     if(!thys || !thys->Len)
2095 	return NULL;
2096 
2097     return thys->Ptr;
2098 }
2099 
2100 
2101 
2102 
2103 /* @func ajLongLen ************************************************************
2104 **
2105 ** Get length of dynamic 1d ajlong array
2106 **
2107 ** @param [r] thys [const AjPLong] Source array
2108 ** @return [ajuint] length
2109 **
2110 ** @release 1.0.0
2111 ** @@
2112 ******************************************************************************/
2113 
ajLongLen(const AjPLong thys)2114 ajuint ajLongLen(const AjPLong thys)
2115 {
2116     return thys->Len;
2117 }
2118 
2119 
2120 
2121 
2122 /* @func ajFloatParse *********************************************************
2123 **
2124 ** Parses a string into a floating point array.
2125 **
2126 ** The array size is already set.
2127 **
2128 ** @param [r] str [const AjPStr] Input string
2129 ** @param [w] array [AjPFloat*] Array
2130 ** @return [AjBool] ajTrue on success.
2131 **
2132 ** @release 1.0.0
2133 ** @@
2134 ******************************************************************************/
2135 
ajFloatParse(const AjPStr str,AjPFloat * array)2136 AjBool ajFloatParse (const AjPStr str, AjPFloat* array)
2137 {
2138     ajuint i = 0;
2139     float t = 0.0;
2140 
2141     AjPStr tmpstr = NULL;
2142     AjPStr tmpstr2 = NULL;
2143     AjPStr numstr = NULL;
2144 
2145     if (!floatRegNum)
2146 	floatRegNum = ajRegCompC ("[+-]?[0-9.]+");
2147 
2148     ajStrAssignS(&tmpstr, str);
2149 
2150     while (ajRegExec (floatRegNum, tmpstr))
2151     {
2152 	ajRegSubI (floatRegNum, 0, &numstr);
2153 	ajRegPost (floatRegNum, &tmpstr2);
2154         ajStrAssignS(&tmpstr, tmpstr2);
2155 	ajStrToFloat (numstr, &t);
2156 	ajFloatPut(array,i,t);
2157 	i++;
2158     }
2159 
2160     ajStrDel(&numstr);
2161     ajStrDel(&tmpstr);
2162     ajStrDel(&tmpstr2);
2163 
2164     if(!i)
2165 	return ajFalse;
2166 
2167     return ajTrue;
2168 }
2169 
2170 
2171 
2172 
2173 /* @func ajFloatStr ***********************************************************
2174 **
2175 ** Writes a floating point array as a string
2176 **
2177 ** @param [r] array [const AjPFloat] Array
2178 ** @param [r] precision [ajint] floating point precision
2179 ** @param [w] str [AjPStr*] Output string
2180 ** @return [void]
2181 **
2182 ** @release 1.0.0
2183 ** @@
2184 ******************************************************************************/
2185 
ajFloatStr(const AjPFloat array,ajint precision,AjPStr * str)2186 void ajFloatStr (const AjPFloat array, ajint precision, AjPStr* str)
2187 {
2188     ajuint i;
2189 
2190     for (i=0; i < array->Len; i++)
2191     {
2192 	if (i)
2193 	    ajStrAppendK(str, ' ');
2194 
2195 	ajFmtPrintAppS (str, "%.*f", precision, ajFloatGet(array,i));
2196     }
2197 
2198     return;
2199 }
2200 
2201 
2202 
2203 
2204 /* @func ajFloatTrace *********************************************************
2205 **
2206 ** Writes a floating point array to the debug file
2207 **
2208 ** @param [r] array [const AjPFloat] Array
2209 ** @param [r] precision [ajint] floating point precision
2210 ** @param [r] text [const char*] Report title
2211 ** @return [void]
2212 **
2213 ** @release 1.0.0
2214 ** @@
2215 ******************************************************************************/
2216 
ajFloatTrace(const AjPFloat array,ajint precision,const char * text)2217 void ajFloatTrace (const AjPFloat array, ajint precision, const char* text)
2218 {
2219     ajuint i;
2220 
2221     ajDebug ("%s\n", text);
2222 
2223     for (i=0; i < array->Len; i++)
2224 	ajDebug ("%3d: %.*f\n", i, precision, ajFloatGet(array,i));
2225 
2226     ajDebug ("\n");
2227 
2228     return;
2229 }
2230 
2231 
2232 
2233 
2234 /* @func ajArrCommaList *******************************************************
2235 **
2236 ** Creates an AjPStr array from a string of comma separated tokens
2237 **
2238 ** @param [r] s [const AjPStr] Line containing comma separated strings
2239 ** @param [w] a [AjPStr **] array pointer to create and load
2240 **
2241 ** @return [ajuint] number of array elements created
2242 **
2243 ** @release 1.0.0
2244 ** @@
2245 ******************************************************************************/
ajArrCommaList(const AjPStr s,AjPStr ** a)2246 ajuint ajArrCommaList(const AjPStr s, AjPStr **a)
2247 {
2248     AjPStr    x;
2249     AjPStrTok t;
2250     ajuint n;
2251     ajuint i;
2252 
2253 
2254     n = ajStrParseCountC(s,",\n");
2255 
2256     if(!n)
2257 	return 0;
2258 
2259     AJCNEW(*a, n);
2260 
2261     x = ajStrNew();
2262     t = ajStrTokenNewC(s,",\n");
2263 
2264     for(i=0;i<n;++i)
2265     {
2266 	ajStrTokenNextParseC(t,",\n", &x);
2267         ajStrTrimWhite(&x);
2268 	(*a)[i] = ajStrNewS(x);
2269     }
2270 
2271     ajStrDel(&x);
2272     ajStrTokenDel(&t);
2273 
2274     return n;
2275 }
2276 
2277 
2278 
2279 
2280 /* @func ajArrDoubleLine ******************************************************
2281 **
2282 ** Creates a double array from a string of columns
2283 **
2284 ** @param [r] line [const AjPStr] Line containing numbers
2285 ** @param [r] delim [const char*]  Delimiter string for tokens
2286 ** @param [r] startcol [ajuint] Start token (1 to n)
2287 ** @param [r] endcol [ajuint] End token (1 to n)
2288 ** @return [double*] Allocated array of integers
2289 **
2290 ** @release 1.0.0
2291 ** @@
2292 ******************************************************************************/
2293 
ajArrDoubleLine(const AjPStr line,const char * delim,ajuint startcol,ajuint endcol)2294 double* ajArrDoubleLine(const AjPStr line, const char *delim,
2295 			ajuint startcol, ajuint endcol)
2296 {
2297     AjPStrTok t = NULL;
2298     AjPStr tmp  = NULL;
2299     static double *ret;
2300     ajuint ncols;
2301     ajuint i;
2302 
2303 
2304     t = ajStrTokenNewC(line, delim);
2305     tmp = ajStrNew();
2306     ncols = (endcol-startcol)+1;
2307     AJCNEW(ret, ncols);
2308 
2309     for(i=0;i<startcol-1;++i)
2310 	if(!ajStrTokenNextParseC(t,delim,&tmp))
2311 	    ajFatal("Token missing %u of %u at start of line:\n%S",
2312 		    (i+1), (startcol-1), line);
2313 
2314     for(i=0;i<ncols;++i)
2315     {
2316 	if(!ajStrTokenNextParseC(t,delim,&tmp))
2317 	    ajFatal("Token missing %u of %u expected in line:\n%S",
2318 		    (startcol+i), endcol, line);
2319 
2320 	if(!ajStrToDouble(tmp,&ret[i]))
2321 	    ajFatal("Bad float conversion %u of %u (%S) in line:\n%S",
2322 		    (startcol+i), endcol, tmp, line);
2323     }
2324 
2325     ajStrDel(&tmp);
2326     ajStrTokenDel(&t);
2327 
2328     return ret;
2329 }
2330 
2331 
2332 
2333 
2334 /* @func ajArrIntLine *********************************************************
2335 **
2336 ** Creates an Int array from a string of columns
2337 **
2338 ** @param [r] line [const AjPStr] Line containing numbers
2339 ** @param [r] delim [const char*]  Delimiter string for tokens
2340 ** @param [r] startcol [ajuint] Start token (1 to n)
2341 ** @param [r] endcol [ajuint] End token (1 to n)
2342 ** @return [ajint*] Allocated array of integers
2343 **
2344 ** @release 1.0.0
2345 ** @@
2346 ******************************************************************************/
2347 
ajArrIntLine(const AjPStr line,const char * delim,ajuint startcol,ajuint endcol)2348 ajint* ajArrIntLine(const AjPStr line, const char *delim,
2349 		    ajuint startcol, ajuint endcol)
2350 {
2351     AjPStrTok t = NULL;
2352     AjPStr tmp  = NULL;
2353     static ajint *ret;
2354     ajuint ncols;
2355     ajuint i;
2356 
2357 
2358     t     = ajStrTokenNewC(line, delim);
2359     tmp   = ajStrNew();
2360     ncols = (endcol-startcol)+1;
2361 
2362     AJCNEW(ret, ncols);
2363 
2364     for(i=0;i<startcol-1;++i)
2365 	if(!ajStrTokenNextParseC(t,delim,&tmp))
2366 	    ajFatal("Token missing %u of %u at start of line:\n%S",
2367 		    (i+1), (startcol-1), line);
2368 
2369     for(i=0;i<ncols;++i)
2370     {
2371 	if(!ajStrTokenNextParseC(t,delim,&tmp))
2372 	    ajFatal("Token missing %u of %u expected in line:\n%S",
2373 		    (startcol+i), endcol, line);
2374 
2375 	if(!ajStrToInt(tmp,&ret[i]))
2376 	    ajFatal("Bad integer array conversion %u of %u (%S) in line:\n%S",
2377 		    (startcol+i), endcol, tmp, line);
2378     }
2379 
2380     ajStrDel(&tmp);
2381     ajStrTokenDel(&t);
2382 
2383     return ret;
2384 }
2385 
2386 
2387 
2388 
2389 /* @func ajArrFloatLine *******************************************************
2390 **
2391 ** Creates a Float array from a string of columns
2392 **
2393 ** @param [r] line [const AjPStr] Line containing numbers
2394 ** @param [r] delim [const char*]  Delimiter string for tokens
2395 ** @param [r] startcol [ajuint] Start token (1 to n)
2396 ** @param [r] endcol [ajuint] End token (1 to n)
2397 ** @return [float*] Allocated array of integers
2398 **
2399 ** @release 1.0.0
2400 ** @@
2401 ******************************************************************************/
2402 
ajArrFloatLine(const AjPStr line,const char * delim,ajuint startcol,ajuint endcol)2403 float* ajArrFloatLine(const AjPStr line, const char *delim,
2404 		      ajuint startcol, ajuint endcol)
2405 {
2406     AjPStrTok t = NULL;
2407     AjPStr tmp  = NULL;
2408     static float *ret;
2409     ajuint ncols;
2410     ajuint i;
2411     AjPStr tmpline = NULL;
2412 
2413     tmpline = ajStrNew();
2414     ajStrAssignS(&tmpline,line);
2415 
2416     ajStrRemoveWhiteExcess(&tmpline);
2417 
2418     t     = ajStrTokenNewC(tmpline, delim);
2419     tmp   = ajStrNew();
2420     ncols = (endcol-startcol)+1;
2421 
2422     AJCNEW(ret, ncols);
2423 
2424     for(i=0;i<startcol-1;++i)
2425 	if(!ajStrTokenNextParseC(t,delim,&tmp))
2426 	    ajFatal("Token missing %u of %u at start of line:\n%S",
2427 		    (i+1), (startcol-1), line);
2428 
2429     for(i=0;i<ncols;++i)
2430     {
2431 	if(!ajStrTokenNextParseC(t,delim,&tmp))
2432 	    ajFatal("Token missing %u of %u expected in line:\n%S",
2433 		    (startcol+i), endcol, line);
2434 
2435 	if(!ajStrToFloat(tmp,&ret[i]))
2436 	    ajFatal("Bad float conversion %u of %u (%S) in line:\n%S",
2437 		    (startcol+i), endcol, tmp, line);
2438     }
2439 
2440     ajStrDel(&tmp);
2441     ajStrDel(&tmpline);
2442     ajStrTokenDel(&t);
2443 
2444     return ret;
2445 }
2446 
2447 
2448 
2449 
2450 /* @func ajInt2dNew ***********************************************************
2451 **
2452 ** Default constructor for empty AJAX 2D integer arrays.
2453 **
2454 ** @return [AjPInt2d] Pointer to an empty integer array structure
2455 ** @category new [AjPInt2d] Default constructor
2456 **
2457 ** @release 1.0.0
2458 ** @@
2459 ******************************************************************************/
2460 
ajInt2dNew(void)2461 AjPInt2d ajInt2dNew(void)
2462 {
2463     AjPInt2d thys;
2464     ajuint    i;
2465 
2466 
2467     AJNEW0(thys);
2468     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(AjPInt));
2469     thys->Len = 0;
2470     thys->Res = RESERVED_SIZE;
2471 
2472     for(i=0;i<RESERVED_SIZE;++i)
2473 	thys->Ptr[i] = NULL;
2474 
2475     arr2dTotal++;
2476     arr2dAlloc += RESERVED_SIZE;
2477 
2478     return thys;
2479 }
2480 
2481 
2482 
2483 
2484 /* @func ajInt2dNewRes ********************************************************
2485 **
2486 ** Constructor given an initial reserved size.
2487 **
2488 ** @param [r] size [ajuint] Reserved size 1st dim
2489 ** @return [AjPInt2d] Pointer to an empty integer 2d array struct of
2490 **                    specified size.
2491 ** @category new [AjPInt2d] Constructor with reserved size
2492 **
2493 ** @release 6.2.0
2494 ** @@
2495 ******************************************************************************/
2496 
ajInt2dNewRes(ajuint size)2497 AjPInt2d ajInt2dNewRes(ajuint size)
2498 {
2499     AjPInt2d thys;
2500     ajuint i;
2501 
2502     size = ajRound(size,RESERVED_SIZE);
2503 
2504     AJNEW0(thys);
2505     thys->Ptr = AJALLOC0(size*sizeof(AjPInt));
2506     thys->Len = 0;
2507     thys->Res = size;
2508 
2509     for(i=0;i<size;++i)
2510 	thys->Ptr[i] = NULL;
2511 
2512     arr2dAlloc++;
2513 
2514     return thys;
2515 }
2516 
2517 
2518 
2519 
2520 /* @func ajInt2dNewResRes2 ****************************************************
2521 **
2522 ** Constructor given an initial reserved size in both dimensions
2523 **
2524 ** @param [r] size [ajuint] Reserved size 1st dim
2525 ** @param [r] size2 [ajuint] Reserved size 2nd dim
2526 ** @return [AjPInt2d] Pointer to an empty integer 2d array struct of
2527 **                    specified size.
2528 ** @category new [AjPInt2d] Constructor with reserved size
2529 **
2530 ** @release 6.2.0
2531 ** @@
2532 ******************************************************************************/
2533 
ajInt2dNewResRes2(ajuint size,ajuint size2)2534 AjPInt2d ajInt2dNewResRes2(ajuint size, ajuint size2)
2535 {
2536     AjPInt2d thys;
2537     ajuint i;
2538 
2539     size = ajRound(size,RESERVED_SIZE);
2540 
2541     AJNEW0(thys);
2542     thys->Ptr = AJALLOC0(size*sizeof(AjPInt));
2543     thys->Len = 0;
2544     thys->Res = size;
2545 
2546     for(i=0;i<size;++i)
2547         thys->Ptr[i] = ajIntNewRes(size2);
2548 
2549     arr2dAlloc++;
2550 
2551     /*ajDebug("ajInt2dNewLL %d*%d %d; %d*%d*%d %d\n",
2552 	    size, sizeof(AjPInt*), size*sizeof(AjPInt*),
2553 	    size, size2, sizeof(ajint), size*size2*sizeof(ajint));*/
2554 
2555     return thys;
2556 }
2557 
2558 
2559 
2560 
2561 /* @func ajInt2dDel ***********************************************************
2562 **
2563 ** Default destructor for AJAX integer arrays.
2564 **
2565 ** If the given array is a NULL pointer, simply returns.
2566 **
2567 ** @param  [d] thys [AjPInt2d*] Pointer to the ajint array to be deleted.
2568 **         The pointer is always deleted.
2569 ** @return [void]
2570 ** @category delete [AjPInt2d] Default destructor
2571 **
2572 ** @release 1.0.0
2573 ** @@
2574 ******************************************************************************/
2575 
ajInt2dDel(AjPInt2d * thys)2576 void ajInt2dDel(AjPInt2d *thys)
2577 {
2578     ajint i;
2579 
2580     if(!thys || !*thys)
2581 	return;
2582 
2583     /*ajDebug("ajInt2dDel Len %u Res %u\n",
2584 	    (*thys)->Len, (*thys)->Res);*/
2585 
2586     for(i=(*thys)->Res-1;i>-1;--i)
2587 	if((*thys)->Ptr[i])
2588 	    ajIntDel(&((*thys)->Ptr[i]));
2589 
2590     AJFREE((*thys)->Ptr);
2591     AJFREE(*thys);
2592 
2593     *thys = NULL;
2594 
2595     arr2dFreeCount++;
2596 
2597     return;
2598 }
2599 
2600 
2601 
2602 
2603 /* @func ajInt2dGet ***********************************************************
2604 **
2605 ** Retrieve an element from an AJAX 2d integer array.
2606 **
2607 ** If the given array is a NULL pointer, simply returns.
2608 **
2609 ** @param  [r] thys [const AjPInt2d] Pointer to the ajint array.
2610 ** @param  [r] elem1 [ajuint] array element.
2611 ** @param  [r] elem2 [ajuint] array element.
2612 **
2613 ** @return [ajint] contents of array element
2614 ** @category cast [AjPInt2d] Retrieve an integer from an array
2615 **
2616 ** @release 1.0.0
2617 ** @@
2618 ******************************************************************************/
2619 
ajInt2dGet(const AjPInt2d thys,ajuint elem1,ajuint elem2)2620 ajint ajInt2dGet(const AjPInt2d thys, ajuint elem1, ajuint elem2)
2621 {
2622     AjPInt t;
2623 
2624     if(!thys || elem1>=thys->Len)
2625 	ajErr("Attempt to access bad ajint array index [%d][%d]\n",elem1,
2626 	      elem2);
2627 
2628     t = thys->Ptr[elem1];
2629 
2630     if(!t)
2631 	ajErr("Attempt to access bad 1st dimension [%d][]\n",elem1);
2632 
2633     return ajIntGet(t,elem2);
2634 }
2635 
2636 
2637 
2638 
2639 /* @func ajInt2dPut ***********************************************************
2640 **
2641 ** Load an integer 2d array element.
2642 **
2643 ** If the given array is a NULL pointer an error is generated.
2644 ** If the array is of insufficient size then the array is extended.
2645 ** Negative indices generate an error.
2646 **
2647 ** @param  [w] thys [AjPInt2d*] Pointer to the ajint array.
2648 ** @param  [r] elem1 [ajuint] array element.
2649 ** @param  [r] elem2 [ajuint] array element.
2650 ** @param  [r] v [ajint] value to load.
2651 **
2652 ** @return [AjBool] true if any array was extended.
2653 ** @category modify [AjPInt2d] Load an integer array element
2654 **
2655 ** @release 1.0.0
2656 ** @@
2657 ******************************************************************************/
2658 
ajInt2dPut(AjPInt2d * thys,ajuint elem1,ajuint elem2,ajint v)2659 AjBool ajInt2dPut(AjPInt2d *thys, ajuint elem1, ajuint elem2, ajint v)
2660 {
2661     if(!thys || !*thys)
2662 	ajErr("Attempt to write to illegal array value [%d][%d]\n",elem1,
2663 	      elem2);
2664 
2665     if(elem1 < (*thys)->Res)
2666     {
2667 	/*ajDebug("ajInt2dPut [%u][%u] %d ([%u] %x)\n",
2668 		elem1, elem2, v, (*thys)->Len, (*thys)->Ptr[elem1]);*/
2669 	if(elem1>=(*thys)->Len)
2670 	    (*thys)->Len = elem1+1;
2671 
2672 	if(!(*thys)->Ptr[elem1])
2673 	    (*thys)->Ptr[elem1] = ajIntNew();
2674 
2675 	return ajIntPut(&(*thys)->Ptr[elem1],elem2,v);
2676     }
2677 
2678     arrInt2dResize(thys, elem1);
2679 
2680     if(!(*thys)->Ptr[elem1])
2681 	(*thys)->Ptr[elem1] = ajIntNew();
2682 
2683     ajIntPut(&(*thys)->Ptr[elem1],elem2,v);
2684 
2685     return ajTrue;
2686 }
2687 
2688 
2689 
2690 
2691 /* @funcstatic arrInt2dResize *************************************************
2692 **
2693 ** Resize an integer array.
2694 **
2695 ** If the given array is a NULL pointer an error is generated.
2696 ** Negative indices generate an error.
2697 **
2698 ** @param  [w] thys [AjPInt2d*] Pointer to the ajint array.
2699 ** @param  [r] size [ajuint] new size.
2700 **
2701 ** @return [AjBool] true if the array was extended.
2702 **
2703 ** @release 4.1.0
2704 ** @@
2705 ******************************************************************************/
2706 
arrInt2dResize(AjPInt2d * thys,ajuint size)2707 static AjBool arrInt2dResize(AjPInt2d *thys, ajuint size)
2708 {
2709     AjPInt2d nthys;
2710     AjPInt2d p = NULL;
2711     ajuint    s;
2712     ajuint    clen;
2713     ajuint    limit;
2714     ajuint    i;
2715 
2716 
2717     if(!thys || !*thys)
2718 	ajErr("Illegal attempt to resize integer array");
2719 
2720     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
2721     s    = ajRound(size+1,RESERVED_SIZE);
2722 
2723     if(s <= clen)
2724 	return ajFalse;
2725 
2726     /*ajDebug("ajInt2dResize %d (%d) -> %d (%d)\n",
2727             (*thys)->Len, clen, size, s);*/
2728 
2729     p = *thys;
2730 
2731     AJNEW0(nthys);
2732     nthys->Ptr = AJALLOC0(s*sizeof(AjPInt));
2733     nthys->Res = s;
2734 
2735     if(size < p->Len)
2736 	limit = size+1;
2737     else
2738 	limit = p->Len;
2739 
2740     memmove(nthys->Ptr,p->Ptr,limit*sizeof(AjPInt));
2741 
2742     i = nthys->Len = size+1;
2743 
2744 
2745     for(;i<p->Res;++i)
2746 	if(p->Ptr[i])
2747 	    ajIntDel(&p->Ptr[i]);
2748 
2749     AJFREE(p->Ptr);
2750     AJFREE(p);
2751 
2752     *thys = nthys;
2753 
2754     arr2dResize++;
2755 
2756     return ajTrue;
2757 }
2758 
2759 
2760 
2761 
2762 /* @func ajInt2dLen ***********************************************************
2763 **
2764 ** Get lengths of 2d ajint array
2765 **
2766 **
2767 ** @param  [r] thys [const AjPInt2d] Pointer to the ajint array.
2768 ** @param  [w] len1 [ajuint*] Length of 1st dim
2769 ** @param  [w] len2 [ajuint*] Length of 2nd dim
2770 **
2771 ** @return [void]
2772 **
2773 ** @release 1.0.0
2774 ** @@
2775 ******************************************************************************/
2776 
ajInt2dLen(const AjPInt2d thys,ajuint * len1,ajuint * len2)2777 void ajInt2dLen(const AjPInt2d thys, ajuint* len1, ajuint* len2)
2778 {
2779     AjPInt t;
2780     ajuint i;
2781 
2782     *len1 = thys->Len;
2783     *len2 = 0;
2784 
2785     for(i=0;i<*len1;++i)
2786 	if((t=thys->Ptr[i]))
2787 	    *len2 = (*len2 > t->Len) ? *len2 : t->Len;
2788 
2789     return;
2790 }
2791 
2792 
2793 
2794 
2795 /* @func ajInt2dInt ***********************************************************
2796 **
2797 ** Convert AjPInt2d to ajint**
2798 **
2799 ** @param  [r] thys [const AjPInt2d] Pointer to the ajint array.
2800 **
2801 ** @return [ajint**] converted value.
2802 ** @category cast [AjPInt2d] Retrieve internal pointer
2803 **
2804 ** @release 1.0.0
2805 ** @@
2806 ******************************************************************************/
2807 
ajInt2dInt(const AjPInt2d thys)2808 ajint** ajInt2dInt(const AjPInt2d thys)
2809 {
2810     AjPInt t = NULL;
2811     ajint **array;
2812     ajuint d1;
2813     ajuint d2;
2814     ajuint i;
2815 
2816     ajInt2dLen(thys,&d1,&d2);
2817 
2818     AJCNEW(array,d1);
2819 
2820     for(i=0;i<d1;++i)
2821     {
2822 	AJCNEW0(array[i],d2);
2823 
2824 	if((t=thys->Ptr[i]))
2825 	    memmove(array[i],t->Ptr,t->Len*sizeof(ajint));
2826     }
2827 
2828     return array;
2829 }
2830 
2831 
2832 
2833 
2834 /* @func ajInt3dNew ***********************************************************
2835 **
2836 ** Default constructor for empty AJAX 3D integer arrays.
2837 **
2838 ** @return [AjPInt3d] Pointer to an empty integer array structure
2839 ** @category new [AjPInt3d] Default constructor
2840 **
2841 ** @release 1.0.0
2842 ** @@
2843 ******************************************************************************/
2844 
ajInt3dNew(void)2845 AjPInt3d ajInt3dNew(void)
2846 {
2847     AjPInt3d thys;
2848     ajuint    i;
2849 
2850 
2851     AJNEW0(thys);
2852     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(AjPInt2d));
2853     thys->Len = 0;
2854     thys->Res = RESERVED_SIZE;
2855 
2856     for(i=0;i<RESERVED_SIZE;++i)
2857 	thys->Ptr[i] = NULL;
2858 
2859     return thys;
2860 }
2861 
2862 
2863 
2864 
2865 /* @func ajInt3dNewRes ********************************************************
2866 **
2867 ** Constructor given an initial reserved size.
2868 **
2869 ** @param [r] size [ajuint] Reserved size 1st dim
2870 ** @return [AjPInt3d] Pointer to an empty integer 3d array struct of
2871 **                    specified size.
2872 ** @category new [AjPInt3d] Constructor with reserved size
2873 **
2874 ** @release 6.2.0
2875 ** @@
2876 ******************************************************************************/
2877 
ajInt3dNewRes(ajuint size)2878 AjPInt3d ajInt3dNewRes(ajuint size)
2879 {
2880     AjPInt3d thys;
2881     ajuint i;
2882 
2883     size = ajRound(size,RESERVED_SIZE);
2884 
2885     AJNEW0(thys);
2886     thys->Ptr = AJALLOC0(size*sizeof(AjPInt2d));
2887     thys->Len = 0;
2888     thys->Res = size;
2889 
2890     for(i=0;i<size;++i)
2891 	thys->Ptr[i] = NULL;
2892 
2893     return thys;
2894 }
2895 
2896 
2897 
2898 
2899 /* @func ajInt3dDel ***********************************************************
2900 **
2901 ** Default destructor for AJAX integer arrays.
2902 **
2903 ** If the given array is a NULL pointer, simply returns.
2904 **
2905 ** @param  [d] thys [AjPInt3d*] Pointer to the ajint array to be deleted.
2906 **         The pointer is always deleted.
2907 ** @return [void]
2908 ** @category delete [AjPInt3d] Default destructor
2909 **
2910 ** @release 1.0.0
2911 ** @@
2912 ******************************************************************************/
2913 
ajInt3dDel(AjPInt3d * thys)2914 void ajInt3dDel(AjPInt3d *thys)
2915 {
2916     ajint i;
2917 
2918     if(!thys || !*thys)
2919 	return;
2920 
2921     /*ajDebug("ajInt3dDel Len %u Res %u\n",
2922 	    (*thys)->Len, (*thys)->Res);*/
2923 
2924     for(i=(*thys)->Res-1;i>-1;--i)
2925 	if((*thys)->Ptr[i])
2926 	    ajInt2dDel(&((*thys)->Ptr[i]));
2927 
2928     AJFREE((*thys)->Ptr);
2929     AJFREE(*thys);
2930 
2931     *thys = NULL;
2932 
2933     arr3dFreeCount++;
2934 
2935     return;
2936 }
2937 
2938 
2939 
2940 
2941 /* @func ajInt3dGet ***********************************************************
2942 **
2943 ** Retrieve an element from an AJAX 3d integer array.
2944 **
2945 ** If the given array is a NULL pointer, simply returns.
2946 **
2947 ** @param  [r] thys [const AjPInt3d] Pointer to the ajint array.
2948 ** @param  [r] elem1 [ajuint] array element.
2949 ** @param  [r] elem2 [ajuint] array element.
2950 ** @param  [r] elem3 [ajuint] array element.
2951 **
2952 ** @return [ajint] contents of array element
2953 ** @category cast [AjPInt3d] Retrieve an integer from an array
2954 **
2955 ** @release 1.0.0
2956 ** @@
2957 ******************************************************************************/
2958 
ajInt3dGet(const AjPInt3d thys,ajuint elem1,ajuint elem2,ajuint elem3)2959 ajint ajInt3dGet(const AjPInt3d thys, ajuint elem1, ajuint elem2, ajuint elem3)
2960 {
2961     AjPInt2d t;
2962 
2963     if(!thys || elem1>=thys->Len)
2964 	ajErr("Attempt to access bad ajint array index [%d][%d][%d]\n",elem1,
2965 	      elem2,elem3);
2966 
2967     t = thys->Ptr[elem1];
2968 
2969     if(!t)
2970 	ajErr("Attempt to access bad 1st dimension [%d][][]\n",elem1);
2971 
2972     return ajInt2dGet(t,elem2,elem3);
2973 }
2974 
2975 
2976 
2977 
2978 /* @func ajInt3dPut ***********************************************************
2979 **
2980 ** Load an integer 3d array element.
2981 **
2982 ** If the given array is a NULL pointer an error is generated.
2983 ** If the array is of insufficient size then the array is extended.
2984 ** Negative indices generate an error.
2985 **
2986 ** @param  [w] thys [AjPInt3d*] Pointer to the ajint array.
2987 ** @param  [r] elem1 [ajuint] array element.
2988 ** @param  [r] elem2 [ajuint] array element.
2989 ** @param  [r] elem3 [ajuint] array element.
2990 ** @param  [r] v [ajint] value to load.
2991 **
2992 ** @return [AjBool] true if any array was extended.
2993 ** @category modify [AjPInt3d] Load an integer array element
2994 **
2995 ** @release 1.0.0
2996 ** @@
2997 ******************************************************************************/
2998 
ajInt3dPut(AjPInt3d * thys,ajuint elem1,ajuint elem2,ajuint elem3,ajint v)2999 AjBool ajInt3dPut(AjPInt3d *thys,
3000 		  ajuint elem1, ajuint elem2, ajuint elem3, ajint v)
3001 {
3002     if(!thys || !*thys)
3003 	ajErr("Attempt to write to illegal array value [%d][%d][%d]\n",elem1,
3004 	      elem2,elem3);
3005 
3006     if(elem1 < (*thys)->Res)
3007     {
3008 	if(elem1>=(*thys)->Len)
3009 	    (*thys)->Len = elem1+1;
3010 
3011 	if(!(*thys)->Ptr[elem1])
3012 	    (*thys)->Ptr[elem1] = ajInt2dNew();
3013 
3014 	return ajInt2dPut(&(*thys)->Ptr[elem1],elem2,elem3,v);
3015     }
3016 
3017     arrInt3dResize(thys, elem1);
3018 
3019     if(!(*thys)->Ptr[elem1])
3020 	(*thys)->Ptr[elem1] = ajInt2dNew();
3021 
3022     ajInt2dPut(&(*thys)->Ptr[elem1],elem2,elem3,v);
3023 
3024     return ajTrue;
3025 }
3026 
3027 
3028 
3029 
3030 /* @funcstatic arrInt3dResize *************************************************
3031 **
3032 ** Resize an integer array.
3033 **
3034 ** If the given array is a NULL pointer an error is generated.
3035 ** Negative indices generate an error.
3036 **
3037 ** @param  [w] thys [AjPInt3d*] Pointer to the ajint array.
3038 ** @param  [r] size [ajuint] new size.
3039 **
3040 ** @return [AjBool] true if the array was extended.
3041 **
3042 ** @release 4.1.0
3043 ** @@
3044 ******************************************************************************/
3045 
arrInt3dResize(AjPInt3d * thys,ajuint size)3046 static AjBool arrInt3dResize(AjPInt3d *thys, ajuint size)
3047 {
3048     AjPInt3d nthys;
3049     AjPInt3d p = NULL;
3050     ajuint    s;
3051     ajuint    clen;
3052     ajuint    limit;
3053     ajuint    i;
3054 
3055 
3056     if(!thys || !*thys)
3057 	ajErr("Illegal attempt to resize integer array");
3058 
3059     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
3060     s = ajRound(size+1,RESERVED_SIZE);
3061 
3062     if(s <= clen)
3063 	return ajFalse;
3064 
3065     /*ajDebug("ajInt3dResize %d (%d) -> %d (%d)\n",
3066             (*thys)->Len, clen, size, s);*/
3067 
3068     p = *thys;
3069 
3070     AJNEW0(nthys);
3071     nthys->Ptr = AJALLOC0(s*sizeof(AjPInt2d));
3072     nthys->Res = s;
3073 
3074     if(size < p->Len)
3075 	limit = size+1;
3076     else
3077 	limit = p->Len;
3078 
3079     memmove(nthys->Ptr,p->Ptr,limit*sizeof(AjPInt2d));
3080 
3081     i = nthys->Len = size+1;
3082 
3083 
3084     for(;i<p->Res;++i)
3085 	if(p->Ptr[i])
3086 	    ajInt2dDel(&p->Ptr[i]);
3087 
3088     AJFREE(p->Ptr);
3089     AJFREE(p);
3090 
3091     *thys = nthys;
3092 
3093     arr3dResize++;
3094 
3095     return ajTrue;
3096 }
3097 
3098 
3099 
3100 
3101 /* @func ajInt3dLen ***********************************************************
3102 **
3103 ** Get lengths of 3d ajint array
3104 **
3105 **
3106 ** @param  [r] thys [const AjPInt3d] Pointer to the ajint array.
3107 ** @param  [w] len1 [ajuint*] Length of 1st dim
3108 ** @param  [w] len2 [ajuint*] Length of 2nd dim
3109 ** @param  [w] len3 [ajuint*] Length of 3rd dim
3110 **
3111 ** @return [void]
3112 **
3113 ** @release 1.0.0
3114 ** @@
3115 ******************************************************************************/
3116 
ajInt3dLen(const AjPInt3d thys,ajuint * len1,ajuint * len2,ajuint * len3)3117 void ajInt3dLen(const AjPInt3d thys, ajuint* len1, ajuint* len2, ajuint* len3)
3118 {
3119     AjPInt2d t2;
3120     AjPInt   t1;
3121     ajuint i;
3122     ajuint j;
3123     ajuint v;
3124 
3125     *len1 = thys->Len;
3126     *len2 = 0;
3127 
3128     for(i=0;i<*len1;++i)
3129 	if((t2=thys->Ptr[i]))
3130 	    *len2 = (*len2 > t2->Len) ? *len2 : t2->Len;
3131 
3132     *len3=0;
3133 
3134     for(i=0;i<*len1;++i)
3135 	if((t2=thys->Ptr[i]))
3136 	{
3137 	    v = t2->Len;
3138 	    for(j=0;j<v;++j)
3139 		if((t1=t2->Ptr[j]))
3140 		    *len3 = (*len3 > t1->Len) ? *len3 : t1->Len;
3141 	}
3142 
3143     return;
3144 }
3145 
3146 
3147 
3148 
3149 /* @func ajInt3dInt ***********************************************************
3150 **
3151 ** Convert AjPInt3d to ajint***
3152 **
3153 ** @param  [r] thys [const AjPInt3d] Pointer to the ajint array.
3154 **
3155 ** @return [ajint***] converted values.
3156 ** @category cast [AjPInt3d] Retrieve internal pointer
3157 **
3158 ** @release 1.0.0
3159 ** @@
3160 ******************************************************************************/
3161 
ajInt3dInt(const AjPInt3d thys)3162 ajint*** ajInt3dInt(const AjPInt3d thys)
3163 {
3164     AjPInt2d t2 = NULL;
3165     AjPInt   t1 = NULL;
3166     ajint ***array;
3167     ajuint d1;
3168     ajuint d2;
3169     ajuint d3;
3170     ajuint i;
3171     ajuint j;
3172 
3173     ajInt3dLen(thys,&d1,&d2,&d3);
3174 
3175     AJCNEW0(array,d1);
3176     for(i=0;i<d1;++i)
3177     {
3178 	AJCNEW0(array[i],d2);
3179 	t2 = thys->Ptr[i];
3180 
3181 	for(j=0;j<d2;++j)
3182 	{
3183 	    AJCNEW0(array[i][j],d3);
3184 	    if(t2)
3185 	    {
3186 		if(j>=t2->Len) continue;
3187 		if((t1=t2->Ptr[j]))
3188 		    memmove(array[i][j],t1->Ptr,
3189 				   t1->Len*sizeof(ajint));
3190 	    }
3191 	}
3192     }
3193 
3194     return array;
3195 }
3196 
3197 
3198 
3199 
3200 /* @func ajUint2dNew **********************************************************
3201 **
3202 ** Default constructor for empty AJAX 2D integer arrays.
3203 **
3204 ** @return [AjPUint2d] Pointer to an empty integer array structure
3205 ** @category new [AjPUint2d] Default constructor
3206 **
3207 ** @release 4.1.0
3208 ** @@
3209 ******************************************************************************/
3210 
ajUint2dNew(void)3211 AjPUint2d ajUint2dNew(void)
3212 {
3213     AjPUint2d thys;
3214     ajuint    i;
3215 
3216 
3217     AJNEW0(thys);
3218     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(AjPUint));
3219     thys->Len = 0;
3220     thys->Res = RESERVED_SIZE;
3221 
3222     for(i=0;i<RESERVED_SIZE;++i)
3223 	thys->Ptr[i] = NULL;
3224 
3225     arr2dTotal++;
3226     arr2dAlloc += RESERVED_SIZE;
3227 
3228     return thys;
3229 }
3230 
3231 
3232 
3233 
3234 /* @func ajUint2dNewRes *******************************************************
3235 **
3236 ** Constructor given an initial reserved size.
3237 **
3238 ** @param [r] size [ajuint] Reserved size 1st dim
3239 ** @return [AjPUint2d] Pointer to an empty integer 2d array struct of
3240 **                    specified size.
3241 ** @category new [AjPUint2d] Constructor with reserved size
3242 **
3243 ** @release 6.2.0
3244 ** @@
3245 ******************************************************************************/
3246 
ajUint2dNewRes(ajuint size)3247 AjPUint2d ajUint2dNewRes(ajuint size)
3248 {
3249     AjPUint2d thys;
3250     ajuint i;
3251 
3252     size = ajRound(size,RESERVED_SIZE);
3253 
3254     AJNEW0(thys);
3255     thys->Ptr = AJALLOC0(size*sizeof(AjPUint));
3256     thys->Len = 0;
3257     thys->Res = size;
3258 
3259     for(i=0;i<size;++i)
3260 	thys->Ptr[i] = NULL;
3261 
3262     arr2dAlloc++;
3263 
3264     return thys;
3265 }
3266 
3267 
3268 
3269 
3270 /* @func ajUint2dNewResRes2 ***************************************************
3271 **
3272 ** Constructor given an initial reserved size in both dimensions
3273 **
3274 ** @param [r] size [ajuint] Reserved size 1st dim
3275 ** @param [r] size2 [ajuint] Reserved size 2nd dim
3276 ** @return [AjPUint2d] Pointer to an empty integer 2d array struct of
3277 **                    specified size.
3278 ** @category new [AjPUint2d] Constructor with reserved size
3279 **
3280 ** @release 6.2.0
3281 ** @@
3282 ******************************************************************************/
3283 
ajUint2dNewResRes2(ajuint size,ajuint size2)3284 AjPUint2d ajUint2dNewResRes2(ajuint size, ajuint size2)
3285 {
3286     AjPUint2d thys;
3287     ajuint i;
3288 
3289     size = ajRound(size,RESERVED_SIZE);
3290 
3291     AJNEW0(thys);
3292     thys->Ptr = AJALLOC0(size*sizeof(AjPUint));
3293     thys->Len = 0;
3294     thys->Res = size;
3295 
3296     for(i=0;i<size;++i)
3297         thys->Ptr[i] = ajUintNewRes(size2);
3298 
3299     arr2dAlloc++;
3300 
3301     /*ajDebug("ajUint2dNewLL %d*%d %d; %d*%d*%d %d\n",
3302 	    size, sizeof(AjPUint*), size*sizeof(AjPUint*),
3303 	    size, size2, sizeof(ajuint), size*size2*sizeof(ajuint));*/
3304     return thys;
3305 }
3306 
3307 
3308 
3309 
3310 /* @func ajUint2dDel **********************************************************
3311 **
3312 ** Default destructor for AJAX unsigned integer arrays.
3313 **
3314 ** If the given array is a NULL pointer, simply returns.
3315 **
3316 ** @param  [d] thys [AjPUint2d*] Pointer to the ajuint array to be deleted.
3317 **         The pointer is always deleted.
3318 ** @return [void]
3319 ** @category delete [AjPUint2d] Default destructor
3320 **
3321 ** @release 4.1.0
3322 ** @@
3323 ******************************************************************************/
3324 
ajUint2dDel(AjPUint2d * thys)3325 void ajUint2dDel(AjPUint2d *thys)
3326 {
3327     ajint i;
3328 
3329     if(!thys || !*thys)
3330 	return;
3331 
3332     for(i=(*thys)->Res-1;i>-1;--i)
3333 	if((*thys)->Ptr[i])
3334 	    ajUintDel(&((*thys)->Ptr[i]));
3335 
3336     AJFREE((*thys)->Ptr);
3337     AJFREE(*thys);
3338 
3339     *thys = NULL;
3340 
3341     arr2dFreeCount++;
3342 
3343     return;
3344 }
3345 
3346 
3347 
3348 
3349 /* @func ajUint2dGet **********************************************************
3350 **
3351 ** Retrieve an element from an AJAX 2d unsigned integer array.
3352 **
3353 ** If the given array is a NULL pointer, simply returns.
3354 **
3355 ** @param  [r] thys [const AjPUint2d] Pointer to the ajuint array.
3356 ** @param  [r] elem1 [ajuint] array element.
3357 ** @param  [r] elem2 [ajuint] array element.
3358 **
3359 ** @return [ajuint] contents of array element
3360 ** @category cast [AjPUint2d] Retrieve an integer from an array
3361 **
3362 ** @release 4.1.0
3363 ** @@
3364 ******************************************************************************/
3365 
ajUint2dGet(const AjPUint2d thys,ajuint elem1,ajuint elem2)3366 ajuint ajUint2dGet(const AjPUint2d thys, ajuint elem1, ajuint elem2)
3367 {
3368     AjPUint t;
3369 
3370     if(!thys || elem1>=thys->Len)
3371 	ajErr("Attempt to access bad ajuint array index [%d][%d]\n",elem1,
3372 	      elem2);
3373 
3374     t = thys->Ptr[elem1];
3375 
3376     if(!t)
3377 	ajErr("Attempt to access bad 1st dimension [%d][]\n",elem1);
3378 
3379     return ajUintGet(t,elem2);
3380 }
3381 
3382 
3383 
3384 
3385 /* @func ajUint2dPut **********************************************************
3386 **
3387 ** Load an unsigned integer 2d array element.
3388 **
3389 ** If the given array is a NULL pointer an error is generated.
3390 ** If the array is of insufficient size then the array is extended.
3391 ** Negative indices generate an error.
3392 **
3393 ** @param  [w] thys [AjPUint2d*] Pointer to the ajuint array.
3394 ** @param  [r] elem1 [ajuint] array element.
3395 ** @param  [r] elem2 [ajuint] array element.
3396 ** @param  [r] v [ajuint] value to load.
3397 **
3398 ** @return [AjBool] true if any array was extended.
3399 ** @category modify [AjPUint2d] Load an integer array element
3400 **
3401 ** @release 4.1.0
3402 ** @@
3403 ******************************************************************************/
3404 
ajUint2dPut(AjPUint2d * thys,ajuint elem1,ajuint elem2,ajuint v)3405 AjBool ajUint2dPut(AjPUint2d *thys, ajuint elem1, ajuint elem2, ajuint v)
3406 {
3407     if(!thys || !*thys)
3408 	ajErr("Attempt to write to illegal array value [%d][%d]\n",elem1,
3409 	      elem2);
3410 
3411     if(elem1 < (*thys)->Res)
3412     {
3413 	if(elem1>=(*thys)->Len)
3414 	    (*thys)->Len = elem1+1;
3415 
3416 	if(!(*thys)->Ptr[elem1])
3417 	    (*thys)->Ptr[elem1] = ajUintNew();
3418 
3419 	return ajUintPut(&(*thys)->Ptr[elem1],elem2,v);
3420     }
3421 
3422     arrUint2dResize(thys, elem1);
3423 
3424     if(!(*thys)->Ptr[elem1])
3425 	(*thys)->Ptr[elem1] = ajUintNew();
3426 
3427     ajUintPut(&(*thys)->Ptr[elem1],elem2,v);
3428 
3429     return ajTrue;
3430 }
3431 
3432 
3433 
3434 
3435 /* @funcstatic arrUint2dResize ************************************************
3436 **
3437 ** Resize an unsigned integer array.
3438 **
3439 ** If the given array is a NULL pointer an error is generated.
3440 ** Negative indices generate an error.
3441 **
3442 ** @param  [w] thys [AjPUint2d*] Pointer to the ajuint array.
3443 ** @param  [r] size [ajuint] new size.
3444 **
3445 ** @return [AjBool] true if the array was extended.
3446 **
3447 ** @release 4.1.0
3448 ** @@
3449 ******************************************************************************/
3450 
arrUint2dResize(AjPUint2d * thys,ajuint size)3451 static AjBool arrUint2dResize(AjPUint2d *thys, ajuint size)
3452 {
3453     AjPUint2d nthys;
3454     AjPUint2d p = NULL;
3455     ajuint    s;
3456     ajuint    clen;
3457     ajuint    limit;
3458     ajuint    i;
3459 
3460 
3461     if(!thys || !*thys)
3462 	ajErr("Illegal attempt to resize integer array");
3463 
3464     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
3465     s    = ajRound(size+1,RESERVED_SIZE);
3466 
3467     if(s <= clen)
3468 	return ajFalse;
3469 
3470     /*ajDebug("ajUint2dResize %d (%d) -> %d (%d)\n",
3471             (*thys)->Len, clen, size, s);*/
3472 
3473     p = *thys;
3474 
3475     AJNEW0(nthys);
3476     nthys->Ptr = AJALLOC0(s*sizeof(AjPUint));
3477     nthys->Res = s;
3478 
3479     if(size < p->Len)
3480 	limit = size+1;
3481     else
3482 	limit = p->Len;
3483 
3484     memmove(nthys->Ptr,p->Ptr,limit*sizeof(AjPUint));
3485 
3486     i = nthys->Len = size+1;
3487 
3488 
3489     for(;i<p->Res;++i)
3490 	if(p->Ptr[i])
3491 	    ajUintDel(&p->Ptr[i]);
3492 
3493     AJFREE(p->Ptr);
3494     AJFREE(p);
3495 
3496     *thys = nthys;
3497 
3498     arr2dResize++;
3499 
3500     return ajTrue;
3501 }
3502 
3503 
3504 
3505 
3506 /* @func ajUint2dLen **********************************************************
3507 **
3508 ** Get lengths of 2d ajuint array
3509 **
3510 **
3511 ** @param  [r] thys [const AjPUint2d] Pointer to the ajuint array.
3512 ** @param  [w] len1 [ajuint*] Length of 1st dim
3513 ** @param  [w] len2 [ajuint*] Length of 2nd dim
3514 **
3515 ** @return [void]
3516 **
3517 ** @release 4.1.0
3518 ** @@
3519 ******************************************************************************/
3520 
ajUint2dLen(const AjPUint2d thys,ajuint * len1,ajuint * len2)3521 void ajUint2dLen(const AjPUint2d thys, ajuint* len1, ajuint* len2)
3522 {
3523     AjPUint t;
3524     ajuint i;
3525 
3526     *len1 = thys->Len;
3527     *len2 = 0;
3528 
3529     for(i=0;i<*len1;++i)
3530 	if((t=thys->Ptr[i]))
3531 	    *len2 = (*len2 > t->Len) ? *len2 : t->Len;
3532 
3533     return;
3534 }
3535 
3536 
3537 
3538 
3539 /* @func ajUint2dUint *********************************************************
3540 **
3541 ** Convert AjPUint2d to ajuint**
3542 **
3543 ** @param  [r] thys [const AjPUint2d] Pointer to the ajuint array.
3544 **
3545 ** @return [ajuint**] converted value.
3546 ** @category cast [AjPUint2d] Retrieve internal pointer
3547 **
3548 ** @release 4.1.0
3549 ** @@
3550 ******************************************************************************/
3551 
ajUint2dUint(const AjPUint2d thys)3552 ajuint** ajUint2dUint(const AjPUint2d thys)
3553 {
3554     AjPUint t = NULL;
3555     ajuint **array;
3556     ajuint d1;
3557     ajuint d2;
3558     ajuint i;
3559 
3560     ajUint2dLen(thys,&d1,&d2);
3561 
3562     AJCNEW(array,d1);
3563 
3564     for(i=0;i<d1;++i)
3565     {
3566 	AJCNEW0(array[i],d2);
3567 
3568 	if((t=thys->Ptr[i]))
3569 	    memmove(array[i],t->Ptr,t->Len*sizeof(ajuint));
3570     }
3571 
3572     return array;
3573 }
3574 
3575 
3576 
3577 
3578 /* @func ajUint3dNew **********************************************************
3579 **
3580 ** Default constructor for empty AJAX 3D unsigned integer arrays.
3581 **
3582 ** @return [AjPUint3d] Pointer to an empty unsigned integer array structure
3583 ** @category new [AjPUint3d] Default constructor
3584 **
3585 ** @release 4.1.0
3586 ** @@
3587 ******************************************************************************/
3588 
ajUint3dNew(void)3589 AjPUint3d ajUint3dNew(void)
3590 {
3591     AjPUint3d thys;
3592     ajuint    i;
3593 
3594 
3595     AJNEW0(thys);
3596     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(AjPUint2d));
3597     thys->Len = 0;
3598     thys->Res = RESERVED_SIZE;
3599 
3600     for(i=0;i<RESERVED_SIZE;++i)
3601 	thys->Ptr[i] = NULL;
3602 
3603     return thys;
3604 }
3605 
3606 
3607 
3608 
3609 /* @func ajUint3dNewRes *******************************************************
3610 **
3611 ** Constructor given an initial reserved size.
3612 **
3613 ** @param [r] size [ajuint] Reserved size 1st dim
3614 ** @return [AjPUint3d] Pointer to an empty unsigned integer 3d array struct of
3615 **                    specified size.
3616 ** @category new [AjPUint3d] Constructor with reserved size
3617 **
3618 ** @release 6.2.0
3619 ** @@
3620 ******************************************************************************/
3621 
ajUint3dNewRes(ajuint size)3622 AjPUint3d ajUint3dNewRes(ajuint size)
3623 {
3624     AjPUint3d thys;
3625     ajuint i;
3626 
3627     size = ajRound(size,RESERVED_SIZE);
3628 
3629     AJNEW0(thys);
3630     thys->Ptr = AJALLOC0(size*sizeof(AjPInt2d));
3631     thys->Len = 0;
3632     thys->Res = size;
3633 
3634     for(i=0;i<size;++i)
3635 	thys->Ptr[i] = NULL;
3636 
3637     return thys;
3638 }
3639 
3640 
3641 
3642 
3643 /* @func ajUint3dDel **********************************************************
3644 **
3645 ** Default destructor for AJAX unsigned integer arrays.
3646 **
3647 ** If the given array is a NULL pointer, simply returns.
3648 **
3649 ** @param  [d] thys [AjPUint3d*] Pointer to the ajuint array to be deleted.
3650 **         The pointer is always deleted.
3651 ** @return [void]
3652 ** @category delete [AjPUint3d] Default destructor
3653 **
3654 ** @release 4.1.0
3655 ** @@
3656 ******************************************************************************/
3657 
ajUint3dDel(AjPUint3d * thys)3658 void ajUint3dDel(AjPUint3d *thys)
3659 {
3660     ajint i;
3661 
3662     if(!thys || !*thys)
3663 	return;
3664 
3665     for(i=(*thys)->Res-1;i>-1;--i)
3666 	if((*thys)->Ptr[i])
3667 	    ajUint2dDel(&((*thys)->Ptr[i]));
3668 
3669     AJFREE((*thys)->Ptr);
3670     AJFREE(*thys);
3671 
3672     *thys = NULL;
3673 
3674     arr3dFreeCount++;
3675 
3676     return;
3677 }
3678 
3679 
3680 
3681 
3682 /* @func ajUint3dGet **********************************************************
3683 **
3684 ** Retrieve an element from an AJAX 3d integer array.
3685 **
3686 ** If the given array is a NULL pointer, simply returns.
3687 **
3688 ** @param  [r] thys [const AjPUint3d] Pointer to the ajuint array.
3689 ** @param  [r] elem1 [ajuint] array element.
3690 ** @param  [r] elem2 [ajuint] array element.
3691 ** @param  [r] elem3 [ajuint] array element.
3692 **
3693 ** @return [ajuint] contents of array element
3694 ** @category cast [AjPUint3d] Retrieve an integer from an array
3695 **
3696 ** @release 4.1.0
3697 ** @@
3698 ******************************************************************************/
3699 
ajUint3dGet(const AjPUint3d thys,ajuint elem1,ajuint elem2,ajuint elem3)3700 ajuint ajUint3dGet(const AjPUint3d thys,
3701 		  ajuint elem1, ajuint elem2, ajuint elem3)
3702 {
3703     AjPUint2d t;
3704 
3705     if(!thys || elem1>=thys->Len)
3706 	ajErr("Attempt to access bad ajuint array index [%d][%d][%d]\n",elem1,
3707 	      elem2,elem3);
3708 
3709     t = thys->Ptr[elem1];
3710 
3711     if(!t)
3712 	ajErr("Attempt to access bad 1st dimension [%d][][]\n",elem1);
3713 
3714     return ajUint2dGet(t,elem2,elem3);
3715 }
3716 
3717 
3718 
3719 
3720 /* @func ajUint3dPut **********************************************************
3721 **
3722 ** Load an unsigned integer 3d array element.
3723 **
3724 ** If the given array is a NULL pointer an error is generated.
3725 ** If the array is of insufficient size then the array is extended.
3726 ** Negative indices generate an error.
3727 **
3728 ** @param  [w] thys [AjPUint3d*] Pointer to the ajint array.
3729 ** @param  [r] elem1 [ajuint] array element.
3730 ** @param  [r] elem2 [ajuint] array element.
3731 ** @param  [r] elem3 [ajuint] array element.
3732 ** @param  [r] v [ajuint] value to load.
3733 **
3734 ** @return [AjBool] true if any array was extended.
3735 ** @category modify [AjPUint3d] Load an integer array element
3736 **
3737 ** @release 4.1.0
3738 ** @@
3739 ******************************************************************************/
3740 
ajUint3dPut(AjPUint3d * thys,ajuint elem1,ajuint elem2,ajuint elem3,ajuint v)3741 AjBool ajUint3dPut(AjPUint3d *thys,
3742 		   ajuint elem1, ajuint elem2, ajuint elem3, ajuint v)
3743 {
3744     if(!thys || !*thys)
3745 	ajErr("Attempt to write to illegal array value [%d][%d][%d]\n",elem1,
3746 	      elem2,elem3);
3747 
3748     if(elem1 < (*thys)->Res)
3749     {
3750 	if(elem1>=(*thys)->Len)
3751 	    (*thys)->Len = elem1+1;
3752 
3753 	if(!(*thys)->Ptr[elem1])
3754 	    (*thys)->Ptr[elem1] = ajUint2dNew();
3755 
3756 	return ajUint2dPut(&(*thys)->Ptr[elem1],elem2,elem3,v);
3757     }
3758 
3759     arrUint3dResize(thys, elem1);
3760 
3761     if(!(*thys)->Ptr[elem1])
3762 	(*thys)->Ptr[elem1] = ajUint2dNew();
3763 
3764     ajUint2dPut(&(*thys)->Ptr[elem1],elem2,elem3,v);
3765 
3766     return ajTrue;
3767 }
3768 
3769 
3770 
3771 
3772 /* @funcstatic arrUint3dResize ************************************************
3773 ** Resize an unsigned integer array.
3774 **
3775 ** If the given array is a NULL pointer an error is generated.
3776 ** Negative indices generate an error.
3777 **
3778 ** @param  [w] thys [AjPUint3d*] Pointer to the ajuint array.
3779 ** @param  [r] size [ajuint] new size.
3780 **
3781 ** @return [AjBool] true if the array was extended.
3782 **
3783 ** @release 4.1.0
3784 ** @@
3785 ******************************************************************************/
3786 
arrUint3dResize(AjPUint3d * thys,ajuint size)3787 static AjBool arrUint3dResize(AjPUint3d *thys, ajuint size)
3788 {
3789     AjPUint3d nthys;
3790     AjPUint3d p = NULL;
3791     ajuint    s;
3792     ajuint    clen;
3793     ajuint    limit;
3794     ajuint    i;
3795 
3796 
3797     if(!thys || !*thys)
3798 	ajErr("Illegal attempt to resize unsigned integer array");
3799 
3800     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
3801     s = ajRound(size+1,RESERVED_SIZE);
3802 
3803     if(s <= clen)
3804 	return ajFalse;
3805 
3806     /*ajDebug("ajUint3dResize %d (%d) -> %d (%d)\n",
3807             (*thys)->Len, clen, size, s);*/
3808 
3809     p = *thys;
3810 
3811     AJNEW0(nthys);
3812     nthys->Ptr = AJALLOC0(s*sizeof(AjPUint2d));
3813     nthys->Res = s;
3814 
3815     if(size < p->Len)
3816 	limit = size+1;
3817     else
3818 	limit = p->Len;
3819 
3820     memmove(nthys->Ptr,p->Ptr,limit*sizeof(AjPUint2d));
3821 
3822     i = nthys->Len = size+1;
3823 
3824 
3825     for(;i<p->Res;++i)
3826 	if(p->Ptr[i])
3827 	    ajUint2dDel(&p->Ptr[i]);
3828 
3829     AJFREE(p->Ptr);
3830     AJFREE(p);
3831 
3832     *thys = nthys;
3833 
3834     arr3dResize++;
3835 
3836     return ajTrue;
3837 }
3838 
3839 
3840 
3841 
3842 /* @func ajUint3dLen **********************************************************
3843 **
3844 ** Get lengths of 3d ajuint array
3845 **
3846 **
3847 ** @param  [r] thys [const AjPUint3d] Pointer to the ajuint array.
3848 ** @param  [w] len1 [ajuint*] Length of 1st dim
3849 ** @param  [w] len2 [ajuint*] Length of 2nd dim
3850 ** @param  [w] len3 [ajuint*] Length of 3rd dim
3851 **
3852 ** @return [void]
3853 **
3854 ** @release 4.1.0
3855 ** @@
3856 ******************************************************************************/
3857 
ajUint3dLen(const AjPUint3d thys,ajuint * len1,ajuint * len2,ajuint * len3)3858 void ajUint3dLen(const AjPUint3d thys,
3859 		 ajuint* len1, ajuint* len2, ajuint* len3)
3860 {
3861     AjPUint2d t2;
3862     AjPUint   t1;
3863     ajuint i;
3864     ajuint j;
3865     ajuint v;
3866 
3867     *len1 = thys->Len;
3868     *len2 = 0;
3869 
3870     for(i=0;i<*len1;++i)
3871 	if((t2=thys->Ptr[i]))
3872 	    *len2 = (*len2 > t2->Len) ? *len2 : t2->Len;
3873 
3874     *len3=0;
3875 
3876     for(i=0;i<*len1;++i)
3877 	if((t2=thys->Ptr[i]))
3878 	{
3879 	    v = t2->Len;
3880 	    for(j=0;j<v;++j)
3881 		if((t1=t2->Ptr[j]))
3882 		    *len3 = (*len3 > t1->Len) ? *len3 : t1->Len;
3883 	}
3884 
3885     return;
3886 }
3887 
3888 
3889 
3890 
3891 /* @func ajUint3dUint *********************************************************
3892 **
3893 ** Convert AjPUint3d to ajuint***
3894 **
3895 ** @param  [r] thys [const AjPUint3d] Pointer to the ajuint array.
3896 **
3897 ** @return [ajuint***] converted values.
3898 ** @category cast [AjPUint3d] Retrieve internal pointer
3899 **
3900 ** @release 4.1.0
3901 ** @@
3902 ******************************************************************************/
3903 
ajUint3dUint(const AjPUint3d thys)3904 ajuint*** ajUint3dUint(const AjPUint3d thys)
3905 {
3906     AjPUint2d t2 = NULL;
3907     AjPUint   t1 = NULL;
3908     ajuint ***array;
3909     ajuint d1;
3910     ajuint d2;
3911     ajuint d3;
3912     ajuint i;
3913     ajuint j;
3914 
3915     ajUint3dLen(thys,&d1,&d2,&d3);
3916 
3917     AJCNEW0(array,d1);
3918 
3919     for(i=0;i<d1;++i)
3920     {
3921 	AJCNEW0(array[i],d2);
3922 	t2 = thys->Ptr[i];
3923 
3924 	for(j=0;j<d2;++j)
3925 	{
3926 	    AJCNEW0(array[i][j],d3);
3927 	    if(t2)
3928 	    {
3929 		if(j>=t2->Len)
3930                     continue;
3931 
3932 		if((t1=t2->Ptr[j]))
3933 		    memmove(array[i][j],t1->Ptr,
3934 				   t1->Len*sizeof(ajuint));
3935 	    }
3936 	}
3937     }
3938 
3939     return array;
3940 }
3941 
3942 
3943 
3944 
3945 /* @func ajFloat2dNew *********************************************************
3946 **
3947 ** Default constructor for empty AJAX 2D float arrays.
3948 **
3949 ** @return [AjPFloat2d] Pointer to an empty float array structure
3950 ** @category new [AjPFloat2d] Default constructor
3951 **
3952 ** @release 1.0.0
3953 ** @@
3954 ******************************************************************************/
3955 
ajFloat2dNew(void)3956 AjPFloat2d ajFloat2dNew(void)
3957 {
3958     AjPFloat2d thys;
3959     ajuint    i;
3960 
3961 
3962     AJNEW0(thys);
3963     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(AjPFloat));
3964     thys->Len = 0;
3965     thys->Res = RESERVED_SIZE;
3966 
3967     for(i=0;i<RESERVED_SIZE;++i)
3968 	thys->Ptr[i] = NULL;
3969 
3970     return thys;
3971 }
3972 
3973 
3974 
3975 
3976 /* @func ajFloat2dNewRes ******************************************************
3977 **
3978 ** Constructor given an initial reserved size.
3979 **
3980 ** @param [r] size [ajuint] Reserved size 1st dim
3981 ** @return [AjPFloat2d] Pointer to an empty float 2d array struct of
3982 **                    specified size.
3983 ** @category new [AjPFloat2d] Constructor with reserved size
3984 **
3985 ** @release 6.2.0
3986 ** @@
3987 ******************************************************************************/
3988 
ajFloat2dNewRes(ajuint size)3989 AjPFloat2d ajFloat2dNewRes(ajuint size)
3990 {
3991     AjPFloat2d thys;
3992     ajuint i;
3993 
3994     size = ajRound(size,RESERVED_SIZE);
3995 
3996     AJNEW0(thys);
3997     thys->Ptr = AJALLOC0(size*sizeof(AjPFloat));
3998     thys->Len = 0;
3999     thys->Res = size;
4000 
4001     for(i=0;i<size;++i)
4002 	thys->Ptr[i] = NULL;
4003 
4004     return thys;
4005 }
4006 
4007 
4008 
4009 
4010 /* @func ajFloat2dDel *********************************************************
4011 **
4012 ** Default destructor for AJAX float arrays.
4013 **
4014 ** If the given array is a NULL pointer, simply returns.
4015 **
4016 ** @param  [d] thys [AjPFloat2d*] Pointer to the float array to be deleted.
4017 **         The pointer is always deleted.
4018 ** @return [void]
4019 ** @category delete [AjPFloat2d] Default destructor
4020 **
4021 ** @release 1.0.0
4022 ** @@
4023 ******************************************************************************/
4024 
ajFloat2dDel(AjPFloat2d * thys)4025 void ajFloat2dDel(AjPFloat2d *thys)
4026 {
4027     ajint i;
4028 
4029     if(!thys || !*thys)
4030 	return;
4031 
4032     for(i=(*thys)->Res-1;i>-1;--i)
4033 	if((*thys)->Ptr[i])
4034 	    ajFloatDel(&((*thys)->Ptr[i]));
4035 
4036     AJFREE((*thys)->Ptr);
4037     AJFREE(*thys);
4038 
4039     *thys = NULL;
4040 
4041     arr2dFreeCount++;
4042 
4043     return;
4044 }
4045 
4046 
4047 
4048 
4049 /* @func ajFloat2dGet *********************************************************
4050 **
4051 ** Retrieve an element from an AJAX 2d float array.
4052 **
4053 ** If the given array is a NULL pointer, simply returns.
4054 **
4055 ** @param  [r] thys [const AjPFloat2d] Pointer to the float array.
4056 ** @param  [r] elem1 [ajuint] array element.
4057 ** @param  [r] elem2 [ajuint] array element.
4058 **
4059 ** @return [float] contents of array element
4060 ** @category cast [AjPFloat2d] Retrieve a float from an array
4061 **
4062 ** @release 1.0.0
4063 ** @@
4064 ******************************************************************************/
4065 
ajFloat2dGet(const AjPFloat2d thys,ajuint elem1,ajuint elem2)4066 float ajFloat2dGet(const AjPFloat2d thys, ajuint elem1, ajuint elem2)
4067 {
4068     AjPFloat t;
4069 
4070     if(!thys || elem1>=thys->Len)
4071 	ajErr("Attempt to access bad float array index [%d][%d]\n",elem1,
4072 	      elem2);
4073 
4074     t = thys->Ptr[elem1];
4075 
4076     if(!t)
4077 	ajErr("Attempt to access bad 1st dimension [%d][]\n",elem1);
4078 
4079     return ajFloatGet(t,elem2);
4080 }
4081 
4082 
4083 
4084 
4085 /* @func ajFloat2dPut *********************************************************
4086 **
4087 ** Load a float 2d array element.
4088 **
4089 ** If the given array is a NULL pointer an error is generated.
4090 ** If the array is of insufficient size then the array is extended.
4091 ** Negative indices generate an error.
4092 **
4093 ** @param  [w] thys [AjPFloat2d*] Pointer to the float array.
4094 ** @param  [r] elem1 [ajuint] array element.
4095 ** @param  [r] elem2 [ajuint] array element.
4096 ** @param  [r] v [float] value to load.
4097 **
4098 ** @return [AjBool] true if any array was extended.
4099 ** @category modify [AjPFloat2d] Load a float array element
4100 **
4101 ** @release 1.0.0
4102 ** @@
4103 ******************************************************************************/
4104 
ajFloat2dPut(AjPFloat2d * thys,ajuint elem1,ajuint elem2,float v)4105 AjBool ajFloat2dPut(AjPFloat2d *thys, ajuint elem1, ajuint elem2, float v)
4106 {
4107     if(!thys || !*thys)
4108 	ajErr("Attempt to write to illegal array value [%d][%d]\n",elem1,
4109 	      elem2);
4110 
4111     if(elem1 < (*thys)->Res)
4112     {
4113 	if(elem1>=(*thys)->Len)
4114 	    (*thys)->Len = elem1+1;
4115 	if(!(*thys)->Ptr[elem1])
4116 	    (*thys)->Ptr[elem1] = ajFloatNew();
4117 	return ajFloatPut(&(*thys)->Ptr[elem1],elem2,v);
4118     }
4119 
4120     arrFloat2dResize(thys, elem1);
4121 
4122     if(!(*thys)->Ptr[elem1])
4123 	(*thys)->Ptr[elem1] = ajFloatNew();
4124 
4125     ajFloatPut(&(*thys)->Ptr[elem1],elem2,v);
4126 
4127     return ajTrue;
4128 }
4129 
4130 
4131 
4132 
4133 /* @funcstatic arrFloat2dResize ***********************************************
4134 **
4135 ** Resize a float array.
4136 **
4137 ** If the given array is a NULL pointer an error is generated.
4138 ** Negative indices generate an error.
4139 **
4140 ** @param  [w] thys [AjPFloat2d*] Pointer to the float array.
4141 ** @param  [r] size [ajuint] new size.
4142 **
4143 ** @return [AjBool] true if the array was extended.
4144 **
4145 ** @release 4.1.0
4146 ** @@
4147 ******************************************************************************/
4148 
arrFloat2dResize(AjPFloat2d * thys,ajuint size)4149 static AjBool arrFloat2dResize(AjPFloat2d *thys, ajuint size)
4150 {
4151     AjPFloat2d nthys;
4152     AjPFloat2d p = NULL;
4153     ajuint    s;
4154     ajuint    clen;
4155     ajuint    limit;
4156     ajuint    i;
4157 
4158 
4159     if(!thys || !*thys)
4160 	ajErr("Illegal attempt to resize float array");
4161 
4162     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
4163     s    = ajRound(size+1,RESERVED_SIZE);
4164 
4165     if(s <= clen)
4166 	return ajFalse;
4167 
4168     /*ajDebug("ajFloat2dResize %d (%d) -> %d (%d)\n",
4169             (*thys)->Len, clen, size, s);*/
4170 
4171     p = *thys;
4172 
4173     AJNEW0(nthys);
4174     nthys->Ptr = AJALLOC0(s*sizeof(AjPFloat));
4175     nthys->Res = s;
4176 
4177     if(size < p->Len)
4178 	limit = size+1;
4179     else
4180 	limit = p->Len;
4181 
4182     memmove(nthys->Ptr,p->Ptr,limit*sizeof(AjPFloat));
4183 
4184     i = nthys->Len = size+1;
4185 
4186 
4187     for(;i<p->Res;++i)
4188 	if(p->Ptr[i])
4189 	    ajFloatDel(&p->Ptr[i]);
4190 
4191     AJFREE(p->Ptr);
4192     AJFREE(p);
4193 
4194     *thys = nthys;
4195 
4196     arr2dResize++;
4197 
4198     return ajTrue;
4199 }
4200 
4201 
4202 
4203 
4204 /* @func ajFloat2dLen *********************************************************
4205 **
4206 ** Get lengths of 2d float array
4207 **
4208 ** @param  [r] thys [const AjPFloat2d] Pointer to the float array.
4209 ** @param  [w] len1 [ajuint*] Length of 1st dim
4210 ** @param  [w] len2 [ajuint*] Length of 2nd dim
4211 **
4212 ** @return [void]
4213 **
4214 ** @release 1.0.0
4215 ** @@
4216 ******************************************************************************/
4217 
ajFloat2dLen(const AjPFloat2d thys,ajuint * len1,ajuint * len2)4218 void ajFloat2dLen(const AjPFloat2d thys, ajuint* len1, ajuint* len2)
4219 {
4220     AjPFloat t;
4221     ajuint i;
4222 
4223     *len1 = thys->Len;
4224     *len2 = 0;
4225 
4226     for(i=0;i<*len1;++i)
4227 	if((t=thys->Ptr[i]))
4228 	    *len2 = (*len2 > t->Len) ? *len2 : t->Len;
4229 
4230     return;
4231 }
4232 
4233 
4234 
4235 
4236 /* @func ajFloat2dFloat *******************************************************
4237 **
4238 ** Convert AjPFloat2d to float**
4239 **
4240 ** @param  [r] thys [const AjPFloat2d] Pointer to the float array.
4241 **
4242 ** @return [float**] converted values.
4243 ** @category cast [AjPFloat2d] Retrieve internal pointer
4244 **
4245 ** @release 1.0.0
4246 ** @@
4247 ******************************************************************************/
4248 
ajFloat2dFloat(const AjPFloat2d thys)4249 float** ajFloat2dFloat(const AjPFloat2d thys)
4250 {
4251     AjPFloat t = NULL;
4252     float **array;
4253     ajuint d1;
4254     ajuint d2;
4255     ajuint i;
4256 
4257     ajFloat2dLen(thys,&d1,&d2);
4258 
4259     AJCNEW(array,d1);
4260 
4261     for(i=0;i<d1;++i)
4262     {
4263 	AJCNEW0(array[i],d2);
4264 
4265 	if((t=thys->Ptr[i]))
4266 	    memmove(array[i],t->Ptr,t->Len*sizeof(float));
4267     }
4268 
4269     return array;
4270 }
4271 
4272 
4273 
4274 
4275 /* @func ajFloat3dNew *********************************************************
4276 **
4277 ** Default constructor for empty AJAX 3D float arrays.
4278 **
4279 ** @return [AjPFloat3d] Pointer to an empty float array structure
4280 ** @category new [AjPFloat3d] Default constructor
4281 **
4282 ** @release 1.0.0
4283 ** @@
4284 ******************************************************************************/
4285 
ajFloat3dNew(void)4286 AjPFloat3d ajFloat3dNew(void)
4287 {
4288     AjPFloat3d thys;
4289     ajuint    i;
4290 
4291 
4292     AJNEW0(thys);
4293     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(AjPFloat2d));
4294     thys->Len = 0;
4295     thys->Res = RESERVED_SIZE;
4296 
4297     for(i=0;i<RESERVED_SIZE;++i)
4298 	thys->Ptr[i] = NULL;
4299 
4300     return thys;
4301 }
4302 
4303 
4304 
4305 
4306 /* @func ajFloat3dNewRes ******************************************************
4307 **
4308 ** Constructor given an initial reserved size.
4309 **
4310 ** @param [r] size [ajuint] Reserved size 1st dim
4311 ** @return [AjPFloat3d] Pointer to an empty float 3d array struct of
4312 **                    specified size.
4313 ** @category new [AjPFloat3d] Constructor with reserved size
4314 **
4315 ** @release 6.2.0
4316 ** @@
4317 ******************************************************************************/
4318 
ajFloat3dNewRes(ajuint size)4319 AjPFloat3d ajFloat3dNewRes(ajuint size)
4320 {
4321     AjPFloat3d thys;
4322     ajuint i;
4323 
4324     size = ajRound(size,RESERVED_SIZE);
4325 
4326     AJNEW0(thys);
4327     thys->Ptr = AJALLOC0(size*sizeof(AjPFloat2d));
4328     thys->Len = 0;
4329     thys->Res = size;
4330 
4331     for(i=0;i<size;++i)
4332 	thys->Ptr[i] = NULL;
4333 
4334     return thys;
4335 }
4336 
4337 
4338 
4339 
4340 /* @func ajFloat3dDel *********************************************************
4341 **
4342 ** Default destructor for AJAX float arrays.
4343 **
4344 ** If the given array is a NULL pointer, simply returns.
4345 **
4346 ** @param  [d] thys [AjPFloat3d*] Pointer to the float array to be deleted.
4347 **         The pointer is always deleted.
4348 ** @return [void]
4349 ** @category delete [AjPFloat3d] Default destructor
4350 **
4351 ** @release 1.0.0
4352 ** @@
4353 ******************************************************************************/
4354 
ajFloat3dDel(AjPFloat3d * thys)4355 void ajFloat3dDel(AjPFloat3d *thys)
4356 {
4357     ajint i;
4358 
4359     if(!thys || !*thys)
4360 	return;
4361 
4362     for(i=(*thys)->Res-1;i>-1;--i)
4363 	if((*thys)->Ptr[i])
4364 	    ajFloat2dDel(&((*thys)->Ptr[i]));
4365 
4366     AJFREE((*thys)->Ptr);
4367     AJFREE(*thys);
4368 
4369     *thys = NULL;
4370 
4371     arr3dFreeCount++;
4372 
4373     return;
4374 }
4375 
4376 
4377 
4378 
4379 /* @func ajFloat3dGet *********************************************************
4380 **
4381 ** Retrieve an element from an AJAX 3d float array.
4382 **
4383 ** If the given array is a NULL pointer, simply returns.
4384 **
4385 ** @param  [r] thys [const AjPFloat3d] Pointer to the float array.
4386 ** @param  [r] elem1 [ajuint] array element.
4387 ** @param  [r] elem2 [ajuint] array element.
4388 ** @param  [r] elem3 [ajuint] array element.
4389 **
4390 ** @return [float] contents of array element
4391 ** @category cast [AjPFloat3d] Retrieve a float from an array
4392 **
4393 ** @release 1.0.0
4394 ** @@
4395 ******************************************************************************/
4396 
ajFloat3dGet(const AjPFloat3d thys,ajuint elem1,ajuint elem2,ajuint elem3)4397 float ajFloat3dGet(const AjPFloat3d thys,
4398 		   ajuint elem1, ajuint elem2, ajuint elem3)
4399 {
4400     AjPFloat2d t;
4401 
4402     if(!thys || elem1>=thys->Len)
4403 	ajErr("Attempt to access bad float array index [%d][%d][%d]\n",elem1,
4404 	      elem2,elem3);
4405 
4406     t = thys->Ptr[elem1];
4407 
4408     if(!t)
4409 	ajErr("Attempt to access bad 1st dimension [%d][][]\n",elem1);
4410 
4411     return ajFloat2dGet(t,elem2,elem3);
4412 }
4413 
4414 
4415 
4416 
4417 /* @func ajFloat3dPut *********************************************************
4418 **
4419 ** Load a float 3d array element.
4420 **
4421 ** If the given array is a NULL pointer an error is generated.
4422 ** If the array is of insufficient size then the array is extended.
4423 ** Negative indices generate an error.
4424 **
4425 ** @param  [w] thys [AjPFloat3d*] Pointer to the float array.
4426 ** @param  [r] elem1 [ajuint] array element.
4427 ** @param  [r] elem2 [ajuint] array element.
4428 ** @param  [r] elem3 [ajuint] array element.
4429 ** @param  [r] v [float] value to load.
4430 **
4431 ** @return [AjBool] true if any array was extended.
4432 ** @category modify [AjPFloat3d] Load a float array element
4433 **
4434 ** @release 1.0.0
4435 ** @@
4436 ******************************************************************************/
4437 
ajFloat3dPut(AjPFloat3d * thys,ajuint elem1,ajuint elem2,ajuint elem3,float v)4438 AjBool ajFloat3dPut(AjPFloat3d *thys,
4439 		    ajuint elem1, ajuint elem2, ajuint elem3, float v)
4440 {
4441     if(!thys || !*thys)
4442 	ajErr("Attempt to write to illegal array value [%d][%d][%d]\n",elem1,
4443 	      elem2,elem3);
4444 
4445     if(elem1 < (*thys)->Res)
4446     {
4447 	if(elem1>=(*thys)->Len)
4448 	    (*thys)->Len = elem1+1;
4449 	if(!(*thys)->Ptr[elem1])
4450 	    (*thys)->Ptr[elem1] = ajFloat2dNew();
4451 	return ajFloat2dPut(&(*thys)->Ptr[elem1],elem2,elem3,v);
4452     }
4453 
4454     arrFloat3dResize(thys, elem1);
4455 
4456     if(!(*thys)->Ptr[elem1])
4457 	(*thys)->Ptr[elem1] = ajFloat2dNew();
4458 
4459     ajFloat2dPut(&(*thys)->Ptr[elem1],elem2,elem3,v);
4460 
4461     return ajTrue;
4462 }
4463 
4464 
4465 
4466 
4467 /* @funcstatic arrFloat3dResize ***********************************************
4468 **
4469 ** Resize a float array.
4470 **
4471 ** If the given array is a NULL pointer an error is generated.
4472 ** Negative indices generate an error.
4473 **
4474 ** @param  [w] thys [AjPFloat3d*] Pointer to the float array.
4475 ** @param  [r] size [ajuint] new size.
4476 **
4477 ** @return [AjBool] true if the array was extended.
4478 **
4479 ** @release 4.1.0
4480 ** @@
4481 ******************************************************************************/
4482 
arrFloat3dResize(AjPFloat3d * thys,ajuint size)4483 static AjBool arrFloat3dResize(AjPFloat3d *thys, ajuint size)
4484 {
4485     AjPFloat3d nthys;
4486     AjPFloat3d p = NULL;
4487     ajuint    s;
4488     ajuint    clen;
4489     ajuint    limit;
4490     ajuint    i;
4491 
4492 
4493     if(!thys || !*thys)
4494 	ajErr("Illegal attempt to resize float array");
4495 
4496     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
4497     s = ajRound(size+1,RESERVED_SIZE);
4498 
4499     if(s <= clen)
4500 	return ajFalse;
4501 
4502     /*ajDebug("ajFloat3dResize %d (%d) -> %d (%d)\n",
4503             (*thys)->Len, clen, size, s);*/
4504 
4505     p = *thys;
4506 
4507     AJNEW0(nthys);
4508     nthys->Ptr = AJALLOC0(s*sizeof(AjPFloat2d));
4509     nthys->Res = s;
4510 
4511     if(size < p->Len)
4512 	limit = size+1;
4513     else
4514 	limit = p->Len;
4515 
4516     memmove(nthys->Ptr,p->Ptr,limit*sizeof(AjPFloat2d));
4517 
4518     i = nthys->Len = size+1;
4519 
4520 
4521     for(;i<p->Res;++i)
4522 	if(p->Ptr[i])
4523 	    ajFloat2dDel(&p->Ptr[i]);
4524 
4525     AJFREE(p->Ptr);
4526     AJFREE(p);
4527 
4528     *thys = nthys;
4529 
4530     arr3dResize++;
4531 
4532     return ajTrue;
4533 }
4534 
4535 
4536 
4537 
4538 /* @func ajFloat3dLen *********************************************************
4539 **
4540 ** Get lengths of 3d float array
4541 **
4542 ** @param  [r] thys [const AjPFloat3d] Pointer to the float array.
4543 ** @param  [w] len1 [ajuint*] Length of 1st dim
4544 ** @param  [w] len2 [ajuint*] Length of 2nd dim
4545 ** @param  [w] len3 [ajuint*] Length of 3rd dim
4546 **
4547 ** @return [void]
4548 **
4549 ** @release 1.0.0
4550 ** @@
4551 ******************************************************************************/
4552 
ajFloat3dLen(const AjPFloat3d thys,ajuint * len1,ajuint * len2,ajuint * len3)4553 void ajFloat3dLen(const AjPFloat3d thys,
4554 		  ajuint* len1, ajuint* len2, ajuint* len3)
4555 {
4556     AjPFloat2d t2;
4557     AjPFloat   t1;
4558     ajuint i;
4559     ajuint j;
4560     ajuint v;
4561 
4562     *len1 = thys->Len;
4563     *len2 = 0;
4564 
4565     for(i=0;i<*len1;++i)
4566 	if((t2=thys->Ptr[i]))
4567 	    *len2 = (*len2 > t2->Len) ? *len2 : t2->Len;
4568     *len3 = 0;
4569 
4570     for(i=0;i<*len1;++i)
4571 	if((t2=thys->Ptr[i]))
4572 	{
4573 	    v = t2->Len;
4574 
4575 	    for(j=0;j<v;++j)
4576 		if((t1=t2->Ptr[j]))
4577 		    *len3 = (*len3 > t1->Len) ? *len3 : t1->Len;
4578 	}
4579 
4580     return;
4581 }
4582 
4583 
4584 
4585 
4586 /* @func ajFloat3dFloat *******************************************************
4587 **
4588 ** Convert AjPFloat3d to float***
4589 **
4590 ** @param  [r] thys [const AjPFloat3d] Pointer to the float array.
4591 **
4592 ** @return [float***] converted values.
4593 ** @category cast [AjPFloat3d] Retrieve internal pointer
4594 **
4595 ** @release 1.0.0
4596 ** @@
4597 ******************************************************************************/
4598 
ajFloat3dFloat(const AjPFloat3d thys)4599 float*** ajFloat3dFloat(const AjPFloat3d thys)
4600 {
4601     AjPFloat2d t2 = NULL;
4602     AjPFloat   t1 = NULL;
4603     float ***array;
4604     ajuint d1;
4605     ajuint d2;
4606     ajuint d3;
4607     ajuint i;
4608     ajuint j;
4609 
4610     ajFloat3dLen(thys,&d1,&d2,&d3);
4611 
4612     AJCNEW0(array,d1);
4613     for(i=0;i<d1;++i)
4614     {
4615 	AJCNEW0(array[i],d2);
4616 	t2 = thys->Ptr[i];
4617 
4618 	for(j=0;j<d2;++j)
4619 	{
4620 	    AJCNEW0(array[i][j],d3);
4621 
4622 	    if(t2)
4623 	    {
4624 		if(j>=t2->Len)
4625                     continue;
4626 
4627 		if((t1=t2->Ptr[j]))
4628 		    memmove(array[i][j],t1->Ptr,
4629 				   t1->Len*sizeof(float));
4630 	    }
4631 	}
4632     }
4633 
4634     return array;
4635 }
4636 
4637 
4638 
4639 
4640 /* @func ajDouble2dNew ********************************************************
4641 **
4642 ** Default constructor for empty AJAX 2D double arrays.
4643 **
4644 ** @return [AjPDouble2d] Pointer to an empty double array structure
4645 ** @category new [AjPDouble2d] Default constructor
4646 **
4647 ** @release 1.0.0
4648 ** @@
4649 ******************************************************************************/
4650 
ajDouble2dNew(void)4651 AjPDouble2d ajDouble2dNew(void)
4652 {
4653     AjPDouble2d thys;
4654     ajuint    i;
4655 
4656 
4657     AJNEW0(thys);
4658     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(AjPDouble));
4659     thys->Len = 0;
4660     thys->Res = RESERVED_SIZE;
4661 
4662     for(i=0;i<RESERVED_SIZE;++i)
4663 	thys->Ptr[i] = NULL;
4664 
4665     return thys;
4666 }
4667 
4668 
4669 
4670 
4671 /* @func ajDouble2dNewRes *****************************************************
4672 **
4673 ** Constructor given an initial reserved size.
4674 **
4675 ** @param [r] size [ajuint] Reserved size 1st dim
4676 ** @return [AjPDouble2d] Pointer to an empty double 2d array struct of
4677 **                    specified size.
4678 ** @category new [AjPDouble2d] Constructor with reserved size
4679 **
4680 ** @release 6.2.0
4681 ** @@
4682 ******************************************************************************/
4683 
ajDouble2dNewRes(ajuint size)4684 AjPDouble2d ajDouble2dNewRes(ajuint size)
4685 {
4686     AjPDouble2d thys;
4687     ajuint i;
4688 
4689     size = ajRound(size,RESERVED_SIZE);
4690 
4691     AJNEW0(thys);
4692     thys->Ptr = AJALLOC0(size*sizeof(AjPDouble));
4693     thys->Len = 0;
4694     thys->Res = size;
4695 
4696     for(i=0;i<size;++i)
4697 	thys->Ptr[i] = NULL;
4698 
4699     return thys;
4700 }
4701 
4702 
4703 
4704 
4705 /* @func ajDouble2dDel ********************************************************
4706 **
4707 ** Default destructor for AJAX double arrays.
4708 **
4709 ** If the given array is a NULL pointer, simply returns.
4710 **
4711 ** @param  [d] thys [AjPDouble2d*] Pointer to the double array to be deleted.
4712 **         The pointer is always deleted.
4713 ** @return [void]
4714 ** @category delete [AjPDouble2d] Default destructor
4715 **
4716 ** @release 1.0.0
4717 ** @@
4718 ******************************************************************************/
4719 
ajDouble2dDel(AjPDouble2d * thys)4720 void ajDouble2dDel(AjPDouble2d *thys)
4721 {
4722     ajint i;
4723 
4724     if(!thys || !*thys)
4725 	return;
4726 
4727     for(i=(*thys)->Res-1;i>-1;--i)
4728 	if((*thys)->Ptr[i])
4729 	    ajDoubleDel(&((*thys)->Ptr[i]));
4730 
4731     AJFREE((*thys)->Ptr);
4732     AJFREE(*thys);
4733 
4734     *thys = NULL;
4735 
4736     arr2dFreeCount++;
4737 
4738     return;
4739 }
4740 
4741 
4742 
4743 
4744 /* @func ajDouble2dGet ********************************************************
4745 **
4746 ** Retrieve an element from an AJAX 2d double array.
4747 **
4748 ** If the given array is a NULL pointer, simply returns.
4749 **
4750 ** @param  [r] thys [const AjPDouble2d] Pointer to the double array.
4751 ** @param  [r] elem1 [ajuint] array element.
4752 ** @param  [r] elem2 [ajuint] array element.
4753 **
4754 ** @return [double] contents of array element
4755 ** @category cast [AjPDouble2d] Retrieve a double from an array
4756 **
4757 ** @release 1.0.0
4758 ** @@
4759 ******************************************************************************/
4760 
ajDouble2dGet(const AjPDouble2d thys,ajuint elem1,ajuint elem2)4761 double ajDouble2dGet(const AjPDouble2d thys, ajuint elem1, ajuint elem2)
4762 {
4763     AjPDouble t;
4764 
4765     if(!thys || elem1>=thys->Len)
4766 	ajErr("Attempt to access bad double array index [%d][%d]\n",elem1,
4767 	      elem2);
4768 
4769     t = thys->Ptr[elem1];
4770 
4771     if(!t)
4772 	ajErr("Attempt to access bad 1st dimension [%d][]\n",elem1);
4773 
4774     return ajDoubleGet(t,elem2);
4775 }
4776 
4777 
4778 
4779 
4780 /* @func ajDouble2dPut ********************************************************
4781 **
4782 ** Load a double 2d array element.
4783 **
4784 ** If the given array is a NULL pointer an error is generated.
4785 ** If the array is of insufficient size then the array is extended.
4786 ** Negative indices generate an error.
4787 **
4788 ** @param  [w] thys [AjPDouble2d*] Pointer to the double array.
4789 ** @param  [r] elem1 [ajuint] array element.
4790 ** @param  [r] elem2 [ajuint] array element.
4791 ** @param  [r] v [double] value to load.
4792 **
4793 ** @return [AjBool] true if any array was extended.
4794 ** @category modify [AjPDouble2d] Load a double array element
4795 **
4796 ** @release 1.0.0
4797 ** @@
4798 ******************************************************************************/
4799 
ajDouble2dPut(AjPDouble2d * thys,ajuint elem1,ajuint elem2,double v)4800 AjBool ajDouble2dPut(AjPDouble2d *thys, ajuint elem1, ajuint elem2, double v)
4801 {
4802     if(!thys || !*thys)
4803 	ajErr("Attempt to write to illegal array value [%d][%d]\n",elem1,
4804 	      elem2);
4805 
4806     if(elem1 < (*thys)->Res)
4807     {
4808 	if(elem1>=(*thys)->Len)
4809 	    (*thys)->Len = elem1+1;
4810 
4811 	if(!(*thys)->Ptr[elem1])
4812 	    (*thys)->Ptr[elem1] = ajDoubleNew();
4813 
4814 	return ajDoublePut(&(*thys)->Ptr[elem1],elem2,v);
4815     }
4816 
4817     arrDouble2dResize(thys, elem1);
4818 
4819     if(!(*thys)->Ptr[elem1])
4820 	(*thys)->Ptr[elem1] = ajDoubleNew();
4821 
4822     ajDoublePut(&(*thys)->Ptr[elem1],elem2,v);
4823 
4824     return ajTrue;
4825 }
4826 
4827 
4828 
4829 
4830 /* @funcstatic arrDouble2dResize **********************************************
4831 **
4832 ** Resize a double array.
4833 **
4834 ** If the given array is a NULL pointer an error is generated.
4835 ** Negative indices generate an error.
4836 **
4837 ** @param  [w] thys [AjPDouble2d*] Pointer to the double array.
4838 ** @param  [r] size [ajuint] new size.
4839 **
4840 ** @return [AjBool] true if the array was extended.
4841 **
4842 ** @release 4.1.0
4843 ** @@
4844 ******************************************************************************/
4845 
arrDouble2dResize(AjPDouble2d * thys,ajuint size)4846 static AjBool arrDouble2dResize(AjPDouble2d *thys, ajuint size)
4847 {
4848     AjPDouble2d nthys;
4849     AjPDouble2d p = NULL;
4850     ajuint    s;
4851     ajuint    clen;
4852     ajuint    limit;
4853     ajuint    i;
4854 
4855 
4856     if(!thys || !*thys)
4857 	ajErr("Illegal attempt to resize double array");
4858 
4859     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
4860     s = ajRound(size+1,RESERVED_SIZE);
4861 
4862     if(s <= clen)
4863 	return ajFalse;
4864 
4865     /*ajDebug("ajDouble2dResize %d (%d) -> %d (%d)\n",
4866             (*thys)->Len, clen, size, s);*/
4867 
4868     p = *thys;
4869 
4870     AJNEW0(nthys);
4871     nthys->Ptr = AJALLOC0(s*sizeof(AjPDouble));
4872     nthys->Res = s;
4873 
4874     if(size < p->Len)
4875 	limit = size+1;
4876     else
4877 	limit = p->Len;
4878 
4879     memmove(nthys->Ptr,p->Ptr,limit*sizeof(AjPDouble));
4880 
4881     i = nthys->Len = size+1;
4882 
4883 
4884     for(;i<p->Res;++i)
4885 	if(p->Ptr[i])
4886 	    ajDoubleDel(&p->Ptr[i]);
4887 
4888     AJFREE(p->Ptr);
4889     AJFREE(p);
4890 
4891     *thys = nthys;
4892 
4893     arr2dResize++;
4894 
4895     return ajTrue;
4896 }
4897 
4898 
4899 
4900 
4901 /* @func ajDouble2dLen ********************************************************
4902 **
4903 ** Get lengths of 2d double array
4904 **
4905 ** @param  [r] thys [const AjPDouble2d] Pointer to the double array.
4906 ** @param  [w] len1 [ajuint*] Length of 1st dim
4907 ** @param  [w] len2 [ajuint*] Length of 2nd dim
4908 **
4909 ** @return [void]
4910 **
4911 ** @release 1.0.0
4912 ** @@
4913 ******************************************************************************/
4914 
ajDouble2dLen(const AjPDouble2d thys,ajuint * len1,ajuint * len2)4915 void ajDouble2dLen(const AjPDouble2d thys, ajuint* len1, ajuint* len2)
4916 {
4917     AjPDouble t;
4918     ajuint i;
4919 
4920     *len1 = thys->Len;
4921     *len2 = 0;
4922 
4923     for(i=0;i<*len1;++i)
4924 	if((t=thys->Ptr[i]))
4925 	    *len2 = (*len2 > t->Len) ? *len2 : t->Len;
4926 
4927     return;
4928 }
4929 
4930 
4931 
4932 
4933 /* @func ajDouble2dDouble *****************************************************
4934 **
4935 ** Convert AjPDouble2d to double**
4936 **
4937 ** @param  [r] thys [const AjPDouble2d] Pointer to the double array.
4938 **
4939 ** @return [double**] converted values.
4940 ** @category cast [AjPDouble2d] Retrieve internal pointer
4941 **
4942 ** @release 1.0.0
4943 ** @@
4944 ******************************************************************************/
4945 
ajDouble2dDouble(const AjPDouble2d thys)4946 double** ajDouble2dDouble(const AjPDouble2d thys)
4947 {
4948     AjPDouble t = NULL;
4949     double **array;
4950     ajuint d1;
4951     ajuint d2;
4952     ajuint i;
4953 
4954     ajDouble2dLen(thys,&d1,&d2);
4955 
4956     AJCNEW(array,d1);
4957     for(i=0;i<d1;++i)
4958     {
4959 	AJCNEW0(array[i],d2);
4960 
4961 	if((t=thys->Ptr[i]))
4962 	    memmove(array[i],t->Ptr,t->Len*sizeof(double));
4963     }
4964 
4965     return array;
4966 }
4967 
4968 
4969 
4970 
4971 /* @func ajDouble3dNew ********************************************************
4972 **
4973 ** Default constructor for empty AJAX 3D double arrays.
4974 **
4975 ** @return [AjPDouble3d] Pointer to an empty double array structure
4976 ** @category new [AjPDouble3d] Default constructor
4977 **
4978 ** @release 1.0.0
4979 ** @@
4980 ******************************************************************************/
4981 
ajDouble3dNew(void)4982 AjPDouble3d ajDouble3dNew(void)
4983 {
4984     AjPDouble3d thys;
4985     ajuint    i;
4986 
4987 
4988     AJNEW0(thys);
4989     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(AjPDouble2d));
4990     thys->Len = 0;
4991     thys->Res = RESERVED_SIZE;
4992 
4993     for(i=0;i<RESERVED_SIZE;++i)
4994 	thys->Ptr[i] = NULL;
4995 
4996     return thys;
4997 }
4998 
4999 
5000 
5001 
5002 /* @func ajDouble3dNewRes *****************************************************
5003 **
5004 ** Constructor given an initial reserved size.
5005 **
5006 ** @param [r] size [ajuint] Reserved size 1st dim
5007 ** @return [AjPDouble3d] Pointer to an empty double 3d array struct of
5008 **                    specified size.
5009 ** @category new [AjPDouble3d] Constructor with reserved size
5010 **
5011 ** @release 6.2.0
5012 ** @@
5013 ******************************************************************************/
5014 
ajDouble3dNewRes(ajuint size)5015 AjPDouble3d ajDouble3dNewRes(ajuint size)
5016 {
5017     AjPDouble3d thys;
5018     ajuint i;
5019 
5020     size = ajRound(size,RESERVED_SIZE);
5021 
5022     AJNEW0(thys);
5023     thys->Ptr = AJALLOC0(size*sizeof(AjPDouble2d));
5024     thys->Len = 0;
5025     thys->Res = size;
5026 
5027     for(i=0;i<size;++i)
5028 	thys->Ptr[i] = NULL;
5029 
5030     return thys;
5031 }
5032 
5033 
5034 
5035 
5036 /* @func ajDouble3dDel ********************************************************
5037 **
5038 ** Default destructor for AJAX double arrays.
5039 **
5040 ** If the given array is a NULL pointer, simply returns.
5041 **
5042 ** @param  [d] thys [AjPDouble3d*] Pointer to the double array to be deleted.
5043 **         The pointer is always deleted.
5044 ** @return [void]
5045 ** @category delete [AjPDouble3d] Default destructor
5046 **
5047 ** @release 1.0.0
5048 ** @@
5049 ******************************************************************************/
5050 
ajDouble3dDel(AjPDouble3d * thys)5051 void ajDouble3dDel(AjPDouble3d *thys)
5052 {
5053     ajint i;
5054 
5055     if(!thys || !*thys)
5056 	return;
5057 
5058     for(i=(*thys)->Res-1;i>-1;--i)
5059 	if((*thys)->Ptr[i])
5060 	    ajDouble2dDel(&((*thys)->Ptr[i]));
5061 
5062     AJFREE((*thys)->Ptr);
5063     AJFREE(*thys);
5064 
5065     *thys = NULL;
5066 
5067     arr3dFreeCount++;
5068 
5069     return;
5070 }
5071 
5072 
5073 
5074 
5075 /* @func ajDouble3dGet ********************************************************
5076 **
5077 ** Retrieve an element from an AJAX 3d double array.
5078 **
5079 ** If the given array is a NULL pointer, simply returns.
5080 **
5081 ** @param  [r] thys [const AjPDouble3d] Pointer to the double array.
5082 ** @param  [r] elem1 [ajuint] array element.
5083 ** @param  [r] elem2 [ajuint] array element.
5084 ** @param  [r] elem3 [ajuint] array element.
5085 **
5086 ** @return [double] contents of array element
5087 ** @category cast [AjPDouble3d] Retrieve a double from an array
5088 **
5089 ** @release 1.0.0
5090 ** @@
5091 ******************************************************************************/
5092 
ajDouble3dGet(const AjPDouble3d thys,ajuint elem1,ajuint elem2,ajuint elem3)5093 double ajDouble3dGet(const AjPDouble3d thys,
5094                      ajuint elem1, ajuint elem2, ajuint elem3)
5095 {
5096     AjPDouble2d t;
5097 
5098     if(!thys || elem1>=thys->Len)
5099 	ajErr("Attempt to access bad double array index [%d][%d][%d]\n",elem1,
5100 	      elem2,elem3);
5101 
5102     t = thys->Ptr[elem1];
5103 
5104     if(!t)
5105 	ajErr("Attempt to access bad 1st dimension [%d][][]\n",elem1);
5106 
5107     return ajDouble2dGet(t,elem2,elem3);
5108 }
5109 
5110 
5111 
5112 
5113 /* @func ajDouble3dPut ********************************************************
5114 **
5115 ** Load a double 3d array element.
5116 **
5117 ** If the given array is a NULL pointer an error is generated.
5118 ** If the array is of insufficient size then the array is extended.
5119 ** Negative indices generate an error.
5120 **
5121 ** @param  [w] thys [AjPDouble3d*] Pointer to the double array.
5122 ** @param  [r] elem1 [ajuint] array element.
5123 ** @param  [r] elem2 [ajuint] array element.
5124 ** @param  [r] elem3 [ajuint] array element.
5125 ** @param  [r] v [double] value to load.
5126 **
5127 ** @return [AjBool] true if any array was extended.
5128 ** @category modify [AjPDouble3d] Load a double array element
5129 **
5130 ** @release 1.0.0
5131 ** @@
5132 ******************************************************************************/
5133 
ajDouble3dPut(AjPDouble3d * thys,ajuint elem1,ajuint elem2,ajuint elem3,double v)5134 AjBool ajDouble3dPut(AjPDouble3d *thys,
5135 		     ajuint elem1, ajuint elem2, ajuint elem3, double v)
5136 {
5137     if(!thys || !*thys)
5138 	ajErr("Attempt to write to illegal array value [%d][%d][%d]\n",elem1,
5139 	      elem2,elem3);
5140 
5141     if(elem1 < (*thys)->Res)
5142     {
5143 	if(elem1>=(*thys)->Len)
5144 	    (*thys)->Len = elem1+1;
5145 
5146 	if(!(*thys)->Ptr[elem1])
5147 	    (*thys)->Ptr[elem1] = ajDouble2dNew();
5148 
5149 	return ajDouble2dPut(&(*thys)->Ptr[elem1],elem2,elem3,v);
5150     }
5151 
5152     arrDouble3dResize(thys, elem1);
5153 
5154     if(!(*thys)->Ptr[elem1])
5155 	(*thys)->Ptr[elem1] = ajDouble2dNew();
5156 
5157     ajDouble2dPut(&(*thys)->Ptr[elem1],elem2,elem3,v);
5158 
5159     return ajTrue;
5160 }
5161 
5162 
5163 
5164 
5165 /* @funcstatic arrDouble3dResize **********************************************
5166 **
5167 ** Resize a double array.
5168 **
5169 ** If the given array is a NULL pointer an error is generated.
5170 ** Negative indices generate an error.
5171 **
5172 ** @param  [w] thys [AjPDouble3d*] Pointer to the double array.
5173 ** @param  [r] size [ajuint] new size.
5174 **
5175 ** @return [AjBool] true if the array was extended.
5176 **
5177 ** @release 4.1.0
5178 ** @@
5179 ******************************************************************************/
5180 
arrDouble3dResize(AjPDouble3d * thys,ajuint size)5181 static AjBool arrDouble3dResize(AjPDouble3d *thys, ajuint size)
5182 {
5183     AjPDouble3d nthys;
5184     AjPDouble3d p = NULL;
5185     ajuint    s;
5186     ajuint    clen;
5187     ajuint    limit;
5188     ajuint    i;
5189 
5190 
5191     if(!thys || !*thys)
5192 	ajErr("Illegal attempt to resize double array");
5193 
5194     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
5195     s = ajRound(size+1,RESERVED_SIZE);
5196 
5197     if(s <= clen)
5198 	return ajFalse;
5199 
5200     /*ajDebug("ajDouble3dResize %d (%d) -> %d (%d)\n",
5201             (*thys)->Len, clen, size, s);*/
5202 
5203     p = *thys;
5204 
5205     AJNEW0(nthys);
5206     nthys->Ptr = AJALLOC0(s*sizeof(AjPDouble2d));
5207     nthys->Res = s;
5208 
5209     if(size < p->Len)
5210 	limit = size+1;
5211     else
5212 	limit = p->Len;
5213 
5214     memmove(nthys->Ptr,p->Ptr,limit*sizeof(AjPDouble2d));
5215 
5216     i = nthys->Len = size+1;
5217 
5218 
5219     for(;i<p->Res;++i)
5220 	if(p->Ptr[i])
5221 	    ajDouble2dDel(&p->Ptr[i]);
5222 
5223     AJFREE(p->Ptr);
5224     AJFREE(p);
5225 
5226     *thys = nthys;
5227 
5228     arr3dResize++;
5229 
5230     return ajTrue;
5231 }
5232 
5233 
5234 
5235 
5236 /* @func ajDouble3dLen ********************************************************
5237 **
5238 ** Get lengths of 3d double array
5239 **
5240 ** @param  [r] thys [const AjPDouble3d] Pointer to the double array.
5241 ** @param  [w] len1 [ajuint*] Length of 1st dim
5242 ** @param  [w] len2 [ajuint*] Length of 2nd dim
5243 ** @param  [w] len3 [ajuint*] Length of 3rd dim
5244 **
5245 ** @return [void]
5246 **
5247 ** @release 1.0.0
5248 ** @@
5249 ******************************************************************************/
5250 
ajDouble3dLen(const AjPDouble3d thys,ajuint * len1,ajuint * len2,ajuint * len3)5251 void ajDouble3dLen(const AjPDouble3d thys,
5252 		   ajuint* len1, ajuint* len2, ajuint* len3)
5253 {
5254     AjPDouble2d t2;
5255     AjPDouble   t1;
5256     ajuint i;
5257     ajuint j;
5258     ajuint v;
5259 
5260     *len1 = thys->Len;
5261     *len2 = 0;
5262 
5263     for(i=0;i<*len1;++i)
5264 	if((t2=thys->Ptr[i]))
5265 	    *len2 = (*len2 > t2->Len) ? *len2 : t2->Len;
5266 
5267     *len3 = 0;
5268 
5269     for(i=0;i<*len1;++i)
5270 	if((t2=thys->Ptr[i]))
5271 	{
5272 	    v = t2->Len;
5273 
5274 	    for(j=0;j<v;++j)
5275 		if((t1=t2->Ptr[j]))
5276 		    *len3 = (*len3 > t1->Len) ? *len3 : t1->Len;
5277 	}
5278 
5279     return;
5280 }
5281 
5282 
5283 
5284 
5285 /* @func ajDouble3dDouble *****************************************************
5286 **
5287 ** Convert AjPDouble3d to double***
5288 **
5289 ** @param  [r] thys [const AjPDouble3d] Pointer to the double array.
5290 **
5291 ** @return [double***] converted values.
5292 ** @category cast [AjPDouble3d] Retrieve internal pointer
5293 **
5294 ** @release 1.0.0
5295 ** @@
5296 ******************************************************************************/
5297 
ajDouble3dDouble(const AjPDouble3d thys)5298 double*** ajDouble3dDouble(const AjPDouble3d thys)
5299 {
5300     AjPDouble2d t2 = NULL;
5301     AjPDouble   t1 = NULL;
5302     double ***array;
5303     ajuint d1;
5304     ajuint d2;
5305     ajuint d3;
5306     ajuint i;
5307     ajuint j;
5308 
5309     ajDouble3dLen(thys,&d1,&d2,&d3);
5310 
5311     AJCNEW0(array,d1);
5312 
5313     for(i=0;i<d1;++i)
5314     {
5315 	AJCNEW0(array[i],d2);
5316 	t2 = thys->Ptr[i];
5317 
5318 	for(j=0;j<d2;++j)
5319 	{
5320 	    AJCNEW0(array[i][j],d3);
5321 
5322 	    if(t2)
5323 	    {
5324 		if(j>=t2->Len)
5325                     continue;
5326 
5327 		if((t1=t2->Ptr[j]))
5328 		    memmove(array[i][j],t1->Ptr,
5329 				   t1->Len*sizeof(double));
5330 	    }
5331 	}
5332     }
5333 
5334     return array;
5335 }
5336 
5337 
5338 
5339 
5340 /* @func ajShort2dNew *********************************************************
5341 **
5342 ** Default constructor for empty AJAX 2D short arrays.
5343 **
5344 ** @return [AjPShort2d] Pointer to an empty short array structure
5345 ** @category new [AjPShort2d] Default constructor
5346 **
5347 ** @release 1.0.0
5348 ** @@
5349 ******************************************************************************/
5350 
ajShort2dNew(void)5351 AjPShort2d ajShort2dNew(void)
5352 {
5353     AjPShort2d thys;
5354     ajuint    i;
5355 
5356 
5357     AJNEW0(thys);
5358     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(AjPShort));
5359     thys->Len = 0;
5360     thys->Res = RESERVED_SIZE;
5361 
5362     for(i=0;i<RESERVED_SIZE;++i)
5363 	thys->Ptr[i] = NULL;
5364 
5365     return thys;
5366 }
5367 
5368 
5369 
5370 
5371 /* @func ajShort2dNewRes ******************************************************
5372 **
5373 ** Constructor given an initial reserved size.
5374 **
5375 ** @param [r] size [ajuint] Reserved size 1st dim
5376 ** @return [AjPShort2d] Pointer to an empty short 2d array struct of
5377 **                    specified size.
5378 ** @category new [AjPShort2d] Constructor with reserved size
5379 **
5380 ** @release 6.2.0
5381 ** @@
5382 ******************************************************************************/
5383 
ajShort2dNewRes(ajuint size)5384 AjPShort2d ajShort2dNewRes(ajuint size)
5385 {
5386     AjPShort2d thys;
5387     ajuint i;
5388 
5389     size = ajRound(size,RESERVED_SIZE);
5390 
5391     AJNEW0(thys);
5392     thys->Ptr = AJALLOC0(size*sizeof(AjPShort));
5393     thys->Len = 0;
5394     thys->Res = size;
5395 
5396     for(i=0;i<size;++i)
5397 	thys->Ptr[i] = NULL;
5398 
5399     return thys;
5400 }
5401 
5402 
5403 
5404 
5405 /* @func ajShort2dDel *********************************************************
5406 **
5407 ** Default destructor for AJAX short arrays.
5408 **
5409 ** If the given array is a NULL pointer, simply returns.
5410 **
5411 ** @param  [d] thys [AjPShort2d*] Pointer to the short array to be deleted.
5412 **         The pointer is always deleted.
5413 ** @return [void]
5414 ** @category delete [AjPShort2d] Default destructor
5415 **
5416 ** @release 1.0.0
5417 ** @@
5418 ******************************************************************************/
5419 
ajShort2dDel(AjPShort2d * thys)5420 void ajShort2dDel(AjPShort2d *thys)
5421 {
5422     ajint i;
5423 
5424     if(!thys || !*thys)
5425 	return;
5426 
5427     for(i=(*thys)->Res-1;i>-1;--i)
5428 	if((*thys)->Ptr[i])
5429 	    ajShortDel(&((*thys)->Ptr[i]));
5430 
5431     AJFREE((*thys)->Ptr);
5432     AJFREE(*thys);
5433 
5434     *thys = NULL;
5435 
5436     arr2dFreeCount++;
5437 
5438     return;
5439 }
5440 
5441 
5442 
5443 
5444 /* @func ajShort2dGet *********************************************************
5445 **
5446 ** Retrieve an element from an AJAX 2d short array.
5447 **
5448 ** If the given array is a NULL pointer, simply returns.
5449 **
5450 ** @param  [r] thys [const AjPShort2d] Pointer to the short array.
5451 ** @param  [r] elem1 [ajuint] array element.
5452 ** @param  [r] elem2 [ajuint] array element.
5453 **
5454 ** @return [short] contents of array element
5455 ** @category cast [AjPShort2d] Retrieve a short from an array
5456 **
5457 ** @release 1.0.0
5458 ** @@
5459 ******************************************************************************/
5460 
ajShort2dGet(const AjPShort2d thys,ajuint elem1,ajuint elem2)5461 short ajShort2dGet(const AjPShort2d thys, ajuint elem1, ajuint elem2)
5462 {
5463     AjPShort t;
5464 
5465     if(!thys || elem1>=thys->Len)
5466 	ajErr("Attempt to access bad short array index [%d][%d]\n",elem1,
5467 	      elem2);
5468 
5469     t = thys->Ptr[elem1];
5470 
5471     if(!t)
5472 	ajErr("Attempt to access bad 1st dimension [%d][]\n",elem1);
5473 
5474     return ajShortGet(t,elem2);
5475 }
5476 
5477 
5478 
5479 
5480 /* @func ajShort2dPut *********************************************************
5481 **
5482 ** Load a short 2d array element.
5483 **
5484 ** If the given array is a NULL pointer an error is generated.
5485 ** If the array is of insufficient size then the array is extended.
5486 ** Negative indices generate an error.
5487 **
5488 ** @param  [w] thys [AjPShort2d*] Pointer to the short array.
5489 ** @param  [r] elem1 [ajuint] array element.
5490 ** @param  [r] elem2 [ajuint] array element.
5491 ** @param  [r] v [short] value to load.
5492 **
5493 ** @return [AjBool] true if any array was extended.
5494 ** @category modify [AjPShort2d] Load a short array element
5495 **
5496 ** @release 1.0.0
5497 ** @@
5498 ******************************************************************************/
5499 
ajShort2dPut(AjPShort2d * thys,ajuint elem1,ajuint elem2,short v)5500 AjBool ajShort2dPut(AjPShort2d *thys, ajuint elem1, ajuint elem2, short v)
5501 {
5502     if(!thys || !*thys)
5503 	ajErr("Attempt to write to illegal array value [%d][%d]\n",elem1,
5504 	      elem2);
5505 
5506     if(elem1 < (*thys)->Res)
5507     {
5508 	if(elem1>=(*thys)->Len)
5509 	    (*thys)->Len = elem1+1;
5510 
5511 	if(!(*thys)->Ptr[elem1])
5512 	    (*thys)->Ptr[elem1] = ajShortNew();
5513 
5514 	return ajShortPut(&(*thys)->Ptr[elem1],elem2,v);
5515     }
5516 
5517     arrShort2dResize(thys, elem1);
5518 
5519     if(!(*thys)->Ptr[elem1])
5520 	(*thys)->Ptr[elem1] = ajShortNew();
5521 
5522     ajShortPut(&(*thys)->Ptr[elem1],elem2,v);
5523 
5524     return ajTrue;
5525 }
5526 
5527 
5528 
5529 
5530 /* @funcstatic arrShort2dResize ***********************************************
5531 **
5532 ** Resize a short array.
5533 **
5534 ** If the given array is a NULL pointer an error is generated.
5535 ** Negative indices generate an error.
5536 **
5537 ** @param  [w] thys [AjPShort2d*] Pointer to the short array.
5538 ** @param  [r] size [ajuint] new size.
5539 **
5540 ** @return [AjBool] true if the array was extended.
5541 **
5542 ** @release 4.1.0
5543 ** @@
5544 ******************************************************************************/
5545 
arrShort2dResize(AjPShort2d * thys,ajuint size)5546 static AjBool arrShort2dResize(AjPShort2d *thys, ajuint size)
5547 {
5548     AjPShort2d nthys;
5549     AjPShort2d p = NULL;
5550     ajuint    s;
5551     ajuint    clen;
5552     ajuint    limit;
5553     ajuint    i;
5554 
5555 
5556     if(!thys || !*thys)
5557 	ajErr("Illegal attempt to resize short array");
5558 
5559     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
5560     s = ajRound(size+1,RESERVED_SIZE);
5561 
5562     if(s <= clen)
5563 	return ajFalse;
5564 
5565     /*ajDebug("ajShort2dResize %d (%d) -> %d (%d)\n",
5566             (*thys)->Len, clen, size, s);*/
5567 
5568     p = *thys;
5569 
5570     AJNEW0(nthys);
5571     nthys->Ptr = AJALLOC0(s*sizeof(AjPShort));
5572     nthys->Res = s;
5573 
5574     if(size < p->Len)
5575 	limit = size+1;
5576     else
5577 	limit = p->Len;
5578 
5579     memmove(nthys->Ptr,p->Ptr,limit*sizeof(AjPShort));
5580 
5581     i = nthys->Len = size+1;
5582 
5583 
5584     for(;i<p->Res;++i)
5585 	if(p->Ptr[i])
5586 	    ajShortDel(&p->Ptr[i]);
5587 
5588     AJFREE(p->Ptr);
5589     AJFREE(p);
5590 
5591     *thys = nthys;
5592 
5593     arr2dResize++;
5594 
5595     return ajTrue;
5596 }
5597 
5598 
5599 
5600 
5601 /* @func ajShort2dLen *********************************************************
5602 **
5603 ** Get lengths of 2d short array
5604 **
5605 ** @param  [r] thys [const AjPShort2d] Pointer to the short array.
5606 ** @param  [w] len1 [ajuint*] Length of 1st dim
5607 ** @param  [w] len2 [ajuint*] Length of 2nd dim
5608 **
5609 ** @return [void]
5610 **
5611 ** @release 1.0.0
5612 ** @@
5613 ******************************************************************************/
5614 
ajShort2dLen(const AjPShort2d thys,ajuint * len1,ajuint * len2)5615 void ajShort2dLen(const AjPShort2d thys, ajuint* len1, ajuint* len2)
5616 {
5617     AjPShort t;
5618     ajuint i;
5619 
5620     *len1 = thys->Len;
5621     *len2 = 0;
5622 
5623     for(i=0;i<*len1;++i)
5624 	if((t=thys->Ptr[i]))
5625 	    *len2 = (*len2 > t->Len) ? *len2 : t->Len;
5626 
5627     return;
5628 }
5629 
5630 
5631 
5632 
5633 /* @func ajShort2dShort *******************************************************
5634 **
5635 ** Convert AjPShort2d to short**
5636 **
5637 ** @param  [r] thys [const AjPShort2d] Pointer to the short array.
5638 **
5639 ** @return [short**] converted values
5640 ** @category cast [AjPShort2d] Retrieve internal pointer
5641 **
5642 ** @release 1.0.0
5643 ** @@
5644 ******************************************************************************/
5645 
ajShort2dShort(const AjPShort2d thys)5646 short** ajShort2dShort(const AjPShort2d thys)
5647 {
5648     AjPShort t = NULL;
5649     short **array;
5650     ajuint d1;
5651     ajuint d2;
5652     ajuint i;
5653 
5654     ajShort2dLen(thys,&d1,&d2);
5655 
5656     AJCNEW(array,d1);
5657 
5658     for(i=0;i<d1;++i)
5659     {
5660 	AJCNEW0(array[i],d2);
5661 
5662 	if((t=thys->Ptr[i]))
5663 	    memmove(array[i],t->Ptr,t->Len*sizeof(short));
5664     }
5665 
5666     return array;
5667 }
5668 
5669 
5670 
5671 
5672 /* @func ajShort3dNew *********************************************************
5673 **
5674 ** Default constructor for empty AJAX 3D short arrays.
5675 **
5676 ** @return [AjPShort3d] Pointer to an empty short array structure
5677 ** @category new [AjPShort3d] Default constructor
5678 **
5679 ** @release 1.0.0
5680 ** @@
5681 ******************************************************************************/
5682 
ajShort3dNew(void)5683 AjPShort3d ajShort3dNew(void)
5684 {
5685     AjPShort3d thys;
5686     ajuint    i;
5687 
5688 
5689     AJNEW0(thys);
5690     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(AjPShort2d));
5691     thys->Len = 0;
5692     thys->Res = RESERVED_SIZE;
5693 
5694     for(i=0;i<RESERVED_SIZE;++i)
5695 	thys->Ptr[i] = NULL;
5696 
5697     return thys;
5698 }
5699 
5700 
5701 
5702 
5703 /* @func ajShort3dNewRes ******************************************************
5704 **
5705 ** Constructor given an initial reserved size.
5706 **
5707 ** @param [r] size [ajuint] Reserved size 1st dim
5708 ** @return [AjPShort3d] Pointer to an empty short 3d array struct of
5709 **                    specified size.
5710 ** @category new [AjPShort3d] Constructor with reserved size
5711 **
5712 ** @release 6.2.0
5713 ** @@
5714 ******************************************************************************/
5715 
ajShort3dNewRes(ajuint size)5716 AjPShort3d ajShort3dNewRes(ajuint size)
5717 {
5718     AjPShort3d thys;
5719     ajuint i;
5720 
5721     size = ajRound(size,RESERVED_SIZE);
5722 
5723     AJNEW0(thys);
5724     thys->Ptr = AJALLOC0(size*sizeof(AjPShort2d));
5725     thys->Len = 0;
5726     thys->Res = size;
5727 
5728     for(i=0;i<size;++i)
5729 	thys->Ptr[i] = NULL;
5730 
5731     return thys;
5732 }
5733 
5734 
5735 
5736 
5737 /* @func ajShort3dDel *********************************************************
5738 **
5739 ** Default destructor for AJAX short arrays.
5740 **
5741 ** If the given array is a NULL pointer, simply returns.
5742 **
5743 ** @param  [d] thys [AjPShort3d*] Pointer to the short array to be deleted.
5744 **         The pointer is always deleted.
5745 ** @return [void]
5746 ** @category delete [AjPShort3d] Default destructor
5747 **
5748 ** @release 1.0.0
5749 ** @@
5750 ******************************************************************************/
5751 
ajShort3dDel(AjPShort3d * thys)5752 void ajShort3dDel(AjPShort3d *thys)
5753 {
5754     ajint i;
5755 
5756     if(!thys || !*thys)
5757 	return;
5758 
5759     for(i=(*thys)->Res-1;i>-1;--i)
5760 	if((*thys)->Ptr[i])
5761 	    ajShort2dDel(&((*thys)->Ptr[i]));
5762 
5763     AJFREE((*thys)->Ptr);
5764     AJFREE(*thys);
5765 
5766     *thys = NULL;
5767 
5768     arr3dFreeCount++;
5769 
5770     return;
5771 }
5772 
5773 
5774 
5775 
5776 /* @func ajShort3dGet *********************************************************
5777 **
5778 ** Retrieve an element from an AJAX 3d short array.
5779 **
5780 ** If the given array is a NULL pointer, simply returns.
5781 **
5782 ** @param  [r] thys [const AjPShort3d] Pointer to the short array.
5783 ** @param  [r] elem1 [ajuint] array element.
5784 ** @param  [r] elem2 [ajuint] array element.
5785 ** @param  [r] elem3 [ajuint] array element.
5786 **
5787 ** @return [short] contents of array element
5788 ** @category cast [AjPShort3d] Retrieve a short from an array
5789 **
5790 ** @release 1.0.0
5791 ** @@
5792 ******************************************************************************/
5793 
ajShort3dGet(const AjPShort3d thys,ajuint elem1,ajuint elem2,ajuint elem3)5794 short ajShort3dGet(const AjPShort3d thys,
5795 		   ajuint elem1, ajuint elem2, ajuint elem3)
5796 {
5797     AjPShort2d t;
5798 
5799     if(!thys || elem1>=thys->Len)
5800 	ajErr("Attempt to access bad short array index [%d][%d][%d]\n",elem1,
5801 	      elem2,elem3);
5802 
5803     t = thys->Ptr[elem1];
5804 
5805     if(!t)
5806 	ajErr("Attempt to access bad 1st dimension [%d][][]\n",elem1);
5807 
5808     return ajShort2dGet(t,elem2,elem3);
5809 }
5810 
5811 
5812 
5813 
5814 /* @func ajShort3dPut *********************************************************
5815 **
5816 ** Load a short 3d array element.
5817 **
5818 ** If the given array is a NULL pointer an error is generated.
5819 ** If the array is of insufficient size then the array is extended.
5820 ** Negative indices generate an error.
5821 **
5822 ** @param  [w] thys [AjPShort3d*] Pointer to the short array.
5823 ** @param  [r] elem1 [ajuint] array element.
5824 ** @param  [r] elem2 [ajuint] array element.
5825 ** @param  [r] elem3 [ajuint] array element.
5826 ** @param  [r] v [short] value to load.
5827 **
5828 ** @return [AjBool] true if any array was extended.
5829 ** @category modify [AjPShort3d] Load a short array element
5830 **
5831 ** @release 1.0.0
5832 ** @@
5833 ******************************************************************************/
5834 
ajShort3dPut(AjPShort3d * thys,ajuint elem1,ajuint elem2,ajuint elem3,short v)5835 AjBool ajShort3dPut(AjPShort3d *thys,
5836 		    ajuint elem1, ajuint elem2, ajuint elem3, short v)
5837 {
5838     if(!thys || !*thys)
5839 	ajErr("Attempt to write to illegal array value [%d][%d][%d]\n",elem1,
5840 	      elem2,elem3);
5841 
5842     if(elem1 < (*thys)->Res)
5843     {
5844 	if(elem1>=(*thys)->Len)
5845 	    (*thys)->Len = elem1+1;
5846 
5847 	if(!(*thys)->Ptr[elem1])
5848 	    (*thys)->Ptr[elem1] = ajShort2dNew();
5849 
5850 	return ajShort2dPut(&(*thys)->Ptr[elem1],elem2,elem3,v);
5851     }
5852 
5853     arrShort3dResize(thys, elem1);
5854 
5855     if(!(*thys)->Ptr[elem1])
5856 	(*thys)->Ptr[elem1] = ajShort2dNew();
5857 
5858     ajShort2dPut(&(*thys)->Ptr[elem1],elem2,elem3,v);
5859 
5860     return ajTrue;
5861 }
5862 
5863 
5864 
5865 
5866 /* @funcstatic arrShort3dResize ***********************************************
5867 **
5868 ** Resize a short array.
5869 **
5870 ** If the given array is a NULL pointer an error is generated.
5871 ** Negative indices generate an error.
5872 **
5873 ** @param  [w] thys [AjPShort3d*] Pointer to the short array.
5874 ** @param  [r] size [ajuint] new size.
5875 **
5876 ** @return [AjBool] true if the array was extended.
5877 **
5878 ** @release 4.1.0
5879 ** @@
5880 ******************************************************************************/
5881 
arrShort3dResize(AjPShort3d * thys,ajuint size)5882 static AjBool arrShort3dResize(AjPShort3d *thys, ajuint size)
5883 {
5884     AjPShort3d nthys;
5885     AjPShort3d p = NULL;
5886     ajuint    s;
5887     ajuint    clen;
5888     ajuint    limit;
5889     ajuint    i;
5890 
5891 
5892     if(!thys || !*thys)
5893 	ajErr("Illegal attempt to resize short array");
5894 
5895     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
5896     s = ajRound(size+1,RESERVED_SIZE);
5897 
5898     if(s <= clen)
5899 	return ajFalse;
5900 
5901     /*ajDebug("ajShort3dResize %d (%d) -> %d (%d)\n",
5902             (*thys)->Len, clen, size, s);*/
5903 
5904     p = *thys;
5905 
5906     AJNEW0(nthys);
5907     nthys->Ptr = AJALLOC0(s*sizeof(AjPShort2d));
5908     nthys->Res = s;
5909 
5910     if(size < p->Len)
5911 	limit = size+1;
5912     else
5913 	limit = p->Len;
5914 
5915     memmove(nthys->Ptr,p->Ptr,limit*sizeof(AjPShort2d));
5916 
5917     i = nthys->Len = size+1;
5918 
5919 
5920     for(;i<p->Res;++i)
5921 	if(p->Ptr[i])
5922 	    ajShort2dDel(&p->Ptr[i]);
5923 
5924     AJFREE(p->Ptr);
5925     AJFREE(p);
5926 
5927     *thys = nthys;
5928 
5929     arr3dResize++;
5930 
5931     return ajTrue;
5932 }
5933 
5934 
5935 
5936 
5937 /* @func ajShort3dLen *********************************************************
5938 **
5939 ** Get lengths of 3d short array
5940 **
5941 ** @param  [r] thys [const AjPShort3d] Pointer to the short array.
5942 ** @param  [w] len1 [ajuint*] Length of 1st dim
5943 ** @param  [w] len2 [ajuint*] Length of 2nd dim
5944 ** @param  [w] len3 [ajuint*] Length of 3rd dim
5945 **
5946 ** @return [void]
5947 **
5948 ** @release 1.0.0
5949 ** @@
5950 ******************************************************************************/
5951 
ajShort3dLen(const AjPShort3d thys,ajuint * len1,ajuint * len2,ajuint * len3)5952 void ajShort3dLen(const AjPShort3d thys,
5953 		  ajuint* len1, ajuint* len2, ajuint* len3)
5954 {
5955     AjPShort2d t2;
5956     AjPShort   t1;
5957     ajuint i;
5958     ajuint j;
5959     ajuint v;
5960 
5961     *len1 = thys->Len;
5962     *len2 = 0;
5963 
5964     for(i=0;i<*len1;++i)
5965 	if((t2=thys->Ptr[i]))
5966 	    *len2 = (*len2 > t2->Len) ? *len2 : t2->Len;
5967 
5968     *len3 = 0;
5969 
5970     for(i=0;i<*len1;++i)
5971 	if((t2=thys->Ptr[i]))
5972 	{
5973 	    v = t2->Len;
5974 
5975 	    for(j=0;j<v;++j)
5976 		if((t1=t2->Ptr[j]))
5977 		    *len3 = (*len3 > t1->Len) ? *len3 : t1->Len;
5978 	}
5979 
5980     return;
5981 }
5982 
5983 
5984 
5985 
5986 /* @func ajShort3dShort *******************************************************
5987 **
5988 ** Convert AjPShort3d to short***
5989 **
5990 ** @param  [r] thys [const AjPShort3d] Pointer to the short array.
5991 **
5992 ** @return [short***] converted values.
5993 ** @category cast [AjPShort3d] Retrieve internal pointer
5994 **
5995 ** @release 1.0.0
5996 ** @@
5997 ******************************************************************************/
5998 
ajShort3dShort(const AjPShort3d thys)5999 short*** ajShort3dShort(const AjPShort3d thys)
6000 {
6001     AjPShort2d t2 = NULL;
6002     AjPShort   t1 = NULL;
6003     short ***array;
6004     ajuint d1;
6005     ajuint d2;
6006     ajuint d3;
6007     ajuint i;
6008     ajuint j;
6009 
6010     ajShort3dLen(thys,&d1,&d2,&d3);
6011 
6012     AJCNEW0(array,d1);
6013 
6014     for(i=0;i<d1;++i)
6015     {
6016 	AJCNEW0(array[i],d2);
6017 	t2 = thys->Ptr[i];
6018 
6019 	for(j=0;j<d2;++j)
6020 	{
6021 	    AJCNEW0(array[i][j],d3);
6022 
6023 	    if(t2)
6024 	    {
6025 		if(j>=t2->Len)
6026                     continue;
6027 
6028 		if((t1=t2->Ptr[j]))
6029 		    memmove(array[i][j],t1->Ptr,
6030 				   t1->Len*sizeof(short));
6031 	    }
6032 	}
6033     }
6034 
6035     return array;
6036 }
6037 
6038 
6039 
6040 
6041 /* @func ajLong2dNew **********************************************************
6042 **
6043 ** Default constructor for empty AJAX 2D ajlong arrays.
6044 **
6045 ** @return [AjPLong2d] Pointer to an empty ajlong array structure
6046 ** @category new [AjPLong2d] Default constructor
6047 **
6048 ** @release 1.0.0
6049 ** @@
6050 ******************************************************************************/
6051 
ajLong2dNew(void)6052 AjPLong2d ajLong2dNew(void)
6053 {
6054     AjPLong2d thys;
6055     ajuint    i;
6056 
6057 
6058     AJNEW0(thys);
6059     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(AjPLong));
6060     thys->Len = 0;
6061     thys->Res = RESERVED_SIZE;
6062 
6063     for(i=0;i<RESERVED_SIZE;++i)
6064 	thys->Ptr[i] = NULL;
6065 
6066     return thys;
6067 }
6068 
6069 
6070 
6071 
6072 /* @func ajLong2dNewRes *******************************************************
6073 **
6074 ** Constructor given an initial reserved size.
6075 **
6076 ** @param [r] size [ajuint] Reserved size 1st dim
6077 ** @return [AjPLong2d] Pointer to an empty ajlong 2d array struct of
6078 **                    specified size.
6079 ** @category new [AjPLong2d] Constructor with reserved size
6080 **
6081 ** @release 6.2.0
6082 ** @@
6083 ******************************************************************************/
6084 
ajLong2dNewRes(ajuint size)6085 AjPLong2d ajLong2dNewRes(ajuint size)
6086 {
6087     AjPLong2d thys;
6088     ajuint i;
6089 
6090     size = ajRound(size,RESERVED_SIZE);
6091 
6092     AJNEW0(thys);
6093     thys->Ptr = AJALLOC0(size*sizeof(AjPLong));
6094     thys->Len = 0;
6095     thys->Res = size;
6096 
6097     for(i=0;i<size;++i)
6098 	thys->Ptr[i] = NULL;
6099 
6100     return thys;
6101 }
6102 
6103 
6104 
6105 
6106 /* @func ajLong2dDel **********************************************************
6107 **
6108 ** Default destructor for AJAX ajlong arrays.
6109 **
6110 ** If the given array is a NULL pointer, simply returns.
6111 **
6112 ** @param  [d] thys [AjPLong2d*] Pointer to the ajlong array to be deleted.
6113 **         The pointer is always deleted.
6114 ** @return [void]
6115 ** @category delete [AjPLong2d] Default destructor
6116 **
6117 ** @release 1.0.0
6118 ** @@
6119 ******************************************************************************/
6120 
ajLong2dDel(AjPLong2d * thys)6121 void ajLong2dDel(AjPLong2d *thys)
6122 {
6123     ajint i;
6124 
6125     if(!thys || !*thys)
6126 	return;
6127 
6128     for(i=(*thys)->Res-1;i>-1;--i)
6129 	if((*thys)->Ptr[i])
6130 	    ajLongDel(&((*thys)->Ptr[i]));
6131 
6132     AJFREE((*thys)->Ptr);
6133     AJFREE(*thys);
6134 
6135     *thys = NULL;
6136 
6137     arr2dFreeCount++;
6138 
6139     return;
6140 }
6141 
6142 
6143 
6144 
6145 /* @func ajLong2dGet **********************************************************
6146 **
6147 ** Retrieve an element from an AJAX 2d ajlong array.
6148 **
6149 ** If the given array is a NULL pointer, simply returns.
6150 **
6151 ** @param  [r] thys [const AjPLong2d] Pointer to the ajlong array.
6152 ** @param  [r] elem1 [ajuint] array element.
6153 ** @param  [r] elem2 [ajuint] array element.
6154 **
6155 ** @return [ajlong] contents of array element
6156 ** @category cast [AjPLong2d] Retrieve a ajlong from an array
6157 **
6158 ** @release 1.0.0
6159 ** @@
6160 ******************************************************************************/
6161 
ajLong2dGet(const AjPLong2d thys,ajuint elem1,ajuint elem2)6162 ajlong ajLong2dGet(const AjPLong2d thys, ajuint elem1, ajuint elem2)
6163 {
6164     AjPLong t;
6165 
6166     if(!thys || elem1>=thys->Len)
6167 	ajErr("Attempt to access bad ajlong array index [%d][%d]\n",elem1,
6168 	      elem2);
6169 
6170     t = thys->Ptr[elem1];
6171 
6172     if(!t)
6173 	ajErr("Attempt to access bad 1st dimension [%d][]\n",elem1);
6174 
6175     return ajLongGet(t,elem2);
6176 }
6177 
6178 
6179 
6180 
6181 /* @func ajLong2dPut **********************************************************
6182 **
6183 ** Load a ajlong 2d array element.
6184 **
6185 ** If the given array is a NULL pointer an error is generated.
6186 ** If the array is of insufficient size then the array is extended.
6187 ** Negative indices generate an error.
6188 **
6189 ** @param  [w] thys [AjPLong2d*] Pointer to the ajlong array.
6190 ** @param  [r] elem1 [ajuint] array element.
6191 ** @param  [r] elem2 [ajuint] array element.
6192 ** @param  [r] v [ajlong] value to load.
6193 **
6194 ** @return [AjBool] true if any array was extended.
6195 ** @category modify [AjPLong2d] Load a ajlong array element
6196 **
6197 ** @release 1.0.0
6198 ** @@
6199 ******************************************************************************/
6200 
ajLong2dPut(AjPLong2d * thys,ajuint elem1,ajuint elem2,ajlong v)6201 AjBool ajLong2dPut(AjPLong2d *thys, ajuint elem1, ajuint elem2, ajlong v)
6202 {
6203     if(!thys || !*thys)
6204 	ajErr("Attempt to write to illegal array value [%d][%d]\n",elem1,
6205 	      elem2);
6206 
6207     if(elem1 < (*thys)->Res)
6208     {
6209 	if(elem1>=(*thys)->Len)
6210 	    (*thys)->Len = elem1+1;
6211 
6212 	if(!(*thys)->Ptr[elem1])
6213 	    (*thys)->Ptr[elem1] = ajLongNew();
6214 
6215 	return ajLongPut(&(*thys)->Ptr[elem1],elem2,v);
6216     }
6217 
6218     arrLong2dResize(thys, elem1);
6219 
6220     if(!(*thys)->Ptr[elem1])
6221 	(*thys)->Ptr[elem1] = ajLongNew();
6222 
6223     ajLongPut(&(*thys)->Ptr[elem1],elem2,v);
6224 
6225     return ajTrue;
6226 }
6227 
6228 
6229 
6230 
6231 /* @funcstatic arrLong2dResize ************************************************
6232 **
6233 ** Resize a ajlong array.
6234 **
6235 ** If the given array is a NULL pointer an error is generated.
6236 ** Negative indices generate an error.
6237 **
6238 ** @param  [w] thys [AjPLong2d*] Pointer to the ajlong array.
6239 ** @param  [r] size [ajuint] new size.
6240 **
6241 ** @return [AjBool] true if the array was extended.
6242 **
6243 ** @release 4.1.0
6244 ** @@
6245 ******************************************************************************/
6246 
arrLong2dResize(AjPLong2d * thys,ajuint size)6247 static AjBool arrLong2dResize(AjPLong2d *thys, ajuint size)
6248 {
6249     AjPLong2d nthys;
6250     AjPLong2d p = NULL;
6251     ajuint    s;
6252     ajuint    clen;
6253     ajuint    limit;
6254     ajuint    i;
6255 
6256 
6257     if(!thys || !*thys)
6258 	ajErr("Illegal attempt to resize ajlong array");
6259 
6260     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
6261     s = ajRound(size+1,RESERVED_SIZE);
6262 
6263     if(s <= clen)
6264 	return ajFalse;
6265 
6266     /*ajDebug("ajLong2dResize %d (%d) -> %d (%d)\n",
6267             (*thys)->Len, clen, size, s);*/
6268 
6269     p = *thys;
6270 
6271     AJNEW0(nthys);
6272     nthys->Ptr = AJALLOC0(s*sizeof(AjPLong));
6273     nthys->Res = s;
6274 
6275     if(size < p->Len)
6276 	limit = size+1;
6277     else
6278 	limit = p->Len;
6279 
6280     memmove(nthys->Ptr,p->Ptr,limit*sizeof(AjPLong));
6281 
6282     i = nthys->Len = size+1;
6283 
6284 
6285     for(;i<p->Res;++i)
6286 	if(p->Ptr[i])
6287 	    ajLongDel(&p->Ptr[i]);
6288 
6289     AJFREE(p->Ptr);
6290     AJFREE(p);
6291 
6292     *thys = nthys;
6293 
6294     arr2dResize++;
6295 
6296     return ajTrue;
6297 }
6298 
6299 
6300 
6301 
6302 /* @func ajLong2dLen **********************************************************
6303 **
6304 ** Get lengths of 2d ajlong array
6305 **
6306 ** @param  [r] thys [const AjPLong2d] Pointer to the ajlong array.
6307 ** @param  [w] len1 [ajuint*] Length of 1st dim
6308 ** @param  [w] len2 [ajuint*] Length of 2nd dim
6309 **
6310 ** @return [void]
6311 **
6312 ** @release 1.0.0
6313 ** @@
6314 ******************************************************************************/
6315 
ajLong2dLen(const AjPLong2d thys,ajuint * len1,ajuint * len2)6316 void ajLong2dLen(const AjPLong2d thys, ajuint* len1, ajuint* len2)
6317 {
6318     AjPLong t;
6319     ajuint i;
6320 
6321     *len1 = thys->Len;
6322     *len2 = 0;
6323 
6324     for(i=0;i<*len1;++i)
6325 	if((t=thys->Ptr[i]))
6326 	    *len2 = (*len2 > t->Len) ? *len2 : t->Len;
6327 
6328     return;
6329 }
6330 
6331 
6332 
6333 
6334 /* @func ajLong2dLong *********************************************************
6335 **
6336 ** Convert AjPLong2d to ajlong**
6337 **
6338 ** @param  [r] thys [const AjPLong2d] Pointer to the ajlong array.
6339 **
6340 ** @return [ajlong**] converted values.
6341 ** @category cast [AjPLong2d] Retrieve internal pointer
6342 **
6343 ** @release 1.0.0
6344 ** @@
6345 ******************************************************************************/
6346 
ajLong2dLong(const AjPLong2d thys)6347 ajlong** ajLong2dLong(const AjPLong2d thys)
6348 {
6349     AjPLong t = NULL;
6350     ajlong **array;
6351     ajuint d1;
6352     ajuint d2;
6353     ajuint i;
6354 
6355     ajLong2dLen(thys,&d1,&d2);
6356 
6357     AJCNEW(array,d1);
6358 
6359     for(i=0;i<d1;++i)
6360     {
6361 	AJCNEW0(array[i],d2);
6362 
6363 	if((t=thys->Ptr[i]))
6364 	    memmove(array[i],t->Ptr,t->Len*sizeof(ajlong));
6365     }
6366 
6367     return array;
6368 }
6369 
6370 
6371 
6372 
6373 /* @func ajLong3dNew **********************************************************
6374 **
6375 ** Default constructor for empty AJAX 3D ajlong arrays.
6376 **
6377 ** @return [AjPLong3d] Pointer to an empty ajlong array structure
6378 ** @category new [AjPLong3d] Default constructor
6379 **
6380 ** @release 1.0.0
6381 ** @@
6382 ******************************************************************************/
6383 
ajLong3dNew(void)6384 AjPLong3d ajLong3dNew(void)
6385 {
6386     AjPLong3d thys;
6387     ajuint    i;
6388 
6389 
6390     AJNEW0(thys);
6391     thys->Ptr = AJALLOC0(RESERVED_SIZE*sizeof(AjPLong2d));
6392     thys->Len = 0;
6393     thys->Res = RESERVED_SIZE;
6394 
6395     for(i=0;i<RESERVED_SIZE;++i)
6396 	thys->Ptr[i] = NULL;
6397 
6398     return thys;
6399 }
6400 
6401 
6402 
6403 
6404 /* @func ajLong3dNewRes *******************************************************
6405 **
6406 ** Constructor given an initial reserved size.
6407 **
6408 ** @param [r] size [ajuint] Reserved size 1st dim
6409 ** @return [AjPLong3d] Pointer to an empty ajlong 3d array struct of
6410 **                    specified size.
6411 ** @category new [AjPLong3d] Constructor with reserved size
6412 **
6413 ** @release 6.2.0
6414 ** @@
6415 ******************************************************************************/
6416 
ajLong3dNewRes(ajuint size)6417 AjPLong3d ajLong3dNewRes(ajuint size)
6418 {
6419     AjPLong3d thys;
6420     ajuint i;
6421 
6422     size = ajRound(size,RESERVED_SIZE);
6423 
6424     AJNEW0(thys);
6425     thys->Ptr = AJALLOC0(size*sizeof(AjPLong2d));
6426     thys->Len = 0;
6427     thys->Res = size;
6428 
6429     for(i=0;i<size;++i)
6430 	thys->Ptr[i] = NULL;
6431 
6432     return thys;
6433 }
6434 
6435 
6436 
6437 
6438 /* @func ajLong3dDel **********************************************************
6439 **
6440 ** Default destructor for AJAX ajlong arrays.
6441 **
6442 ** If the given array is a NULL pointer, simply returns.
6443 **
6444 ** @param  [d] thys [AjPLong3d*] Pointer to the ajlong array to be deleted.
6445 **         The pointer is always deleted.
6446 ** @return [void]
6447 ** @category delete [AjPLong3d] Default destructor
6448 **
6449 ** @release 1.0.0
6450 ** @@
6451 ******************************************************************************/
6452 
ajLong3dDel(AjPLong3d * thys)6453 void ajLong3dDel(AjPLong3d *thys)
6454 {
6455     ajint i;
6456 
6457     if(!thys || !*thys)
6458 	return;
6459 
6460     for(i=(*thys)->Res-1;i>-1;--i)
6461 	if((*thys)->Ptr[i])
6462 	    ajLong2dDel(&((*thys)->Ptr[i]));
6463 
6464     AJFREE((*thys)->Ptr);
6465     AJFREE(*thys);
6466 
6467     *thys = NULL;
6468 
6469     arr3dFreeCount++;
6470 
6471     return;
6472 }
6473 
6474 
6475 
6476 
6477 /* @func ajLong3dGet **********************************************************
6478 **
6479 ** Retrieve an element from an AJAX 3d ajlong array.
6480 **
6481 ** If the given array is a NULL pointer, simply returns.
6482 **
6483 ** @param  [r] thys [const AjPLong3d] Pointer to the ajlong array.
6484 ** @param  [r] elem1 [ajuint] array element.
6485 ** @param  [r] elem2 [ajuint] array element.
6486 ** @param  [r] elem3 [ajuint] array element.
6487 **
6488 ** @return [ajlong] contents of array element
6489 ** @category cast [AjPLong3d] Retrieve a ajlong from an array
6490 **
6491 ** @release 1.0.0
6492 ** @@
6493 ******************************************************************************/
6494 
ajLong3dGet(const AjPLong3d thys,ajuint elem1,ajuint elem2,ajuint elem3)6495 ajlong ajLong3dGet(const AjPLong3d thys,
6496 		   ajuint elem1, ajuint elem2, ajuint elem3)
6497 {
6498     AjPLong2d t;
6499 
6500     if(!thys || elem1>=thys->Len)
6501 	ajErr("Attempt to access bad ajlong array index [%d][%d][%d]\n",elem1,
6502 	      elem2,elem3);
6503 
6504     t = thys->Ptr[elem1];
6505 
6506     if(!t)
6507 	ajErr("Attempt to access bad 1st dimension [%d][][]\n",elem1);
6508 
6509     return ajLong2dGet(t,elem2,elem3);
6510 }
6511 
6512 
6513 
6514 
6515 /* @func ajLong3dPut **********************************************************
6516 **
6517 ** Load a ajlong 3d array element.
6518 **
6519 ** If the given array is a NULL pointer an error is generated.
6520 ** If the array is of insufficient size then the array is extended.
6521 ** Negative indices generate an error.
6522 **
6523 ** @param  [w] thys [AjPLong3d*] Pointer to the ajlong array.
6524 ** @param  [r] elem1 [ajuint] array element.
6525 ** @param  [r] elem2 [ajuint] array element.
6526 ** @param  [r] elem3 [ajuint] array element.
6527 ** @param  [r] v [ajlong] value to load.
6528 **
6529 ** @return [AjBool] true if any array was extended.
6530 ** @category modify [AjPLong3d] Load a ajlong array element
6531 **
6532 ** @release 1.0.0
6533 ** @@
6534 ******************************************************************************/
6535 
ajLong3dPut(AjPLong3d * thys,ajuint elem1,ajuint elem2,ajuint elem3,ajlong v)6536 AjBool ajLong3dPut(AjPLong3d *thys,
6537 		   ajuint elem1, ajuint elem2, ajuint elem3, ajlong v)
6538 {
6539     if(!thys || !*thys)
6540 	ajErr("Attempt to write to illegal array value [%d][%d][%d]\n",elem1,
6541 	      elem2,elem3);
6542 
6543     if(elem1 < (*thys)->Res)
6544     {
6545 	if(elem1>=(*thys)->Len)
6546 	    (*thys)->Len = elem1+1;
6547 
6548 	if(!(*thys)->Ptr[elem1])
6549 	    (*thys)->Ptr[elem1] = ajLong2dNew();
6550 
6551 	return ajLong2dPut(&(*thys)->Ptr[elem1],elem2,elem3,v);
6552     }
6553 
6554     arrLong3dResize(thys, elem1);
6555 
6556     if(!(*thys)->Ptr[elem1])
6557 	(*thys)->Ptr[elem1] = ajLong2dNew();
6558 
6559     ajLong2dPut(&(*thys)->Ptr[elem1],elem2,elem3,v);
6560 
6561     return ajTrue;
6562 }
6563 
6564 
6565 
6566 
6567 /* @funcstatic arrLong3dResize ************************************************
6568 **
6569 ** Resize a ajlong array.
6570 **
6571 ** If the given array is a NULL pointer an error is generated.
6572 ** Negative indices generate an error.
6573 **
6574 ** @param  [w] thys [AjPLong3d*] Pointer to the ajlong array.
6575 ** @param  [r] size [ajuint] new size.
6576 **
6577 ** @return [AjBool] true if the array was extended.
6578 **
6579 ** @release 4.1.0
6580 ** @@
6581 ******************************************************************************/
6582 
arrLong3dResize(AjPLong3d * thys,ajuint size)6583 static AjBool arrLong3dResize(AjPLong3d *thys, ajuint size)
6584 {
6585     AjPLong3d nthys;
6586     AjPLong3d p = NULL;
6587     ajuint    s;
6588     ajuint    clen;
6589     ajuint    limit;
6590     ajuint    i;
6591 
6592 
6593     if(!thys || !*thys)
6594 	ajErr("Illegal attempt to resize ajlong array");
6595 
6596     clen = ajRound((*thys)->Len-1,RESERVED_SIZE);
6597     s = ajRound(size+1,RESERVED_SIZE);
6598 
6599     if(s <= clen)
6600 	return ajFalse;
6601 
6602     /*ajDebug("ajLong3dResize %d (%d) -> %d (%d)\n",
6603             (*thys)->Len, clen, size, s);*/
6604 
6605     p = *thys;
6606 
6607     AJNEW0(nthys);
6608     nthys->Ptr = AJALLOC0(s*sizeof(AjPLong2d));
6609     nthys->Res = s;
6610 
6611     if(size < p->Len)
6612 	limit = size+1;
6613     else
6614 	limit = p->Len;
6615 
6616     memmove(nthys->Ptr,p->Ptr,limit*sizeof(AjPLong2d));
6617 
6618     i = nthys->Len = size+1;
6619 
6620 
6621     for(;i<p->Res;++i)
6622 	if(p->Ptr[i])
6623 	    ajLong2dDel(&p->Ptr[i]);
6624 
6625     AJFREE(p->Ptr);
6626     AJFREE(p);
6627 
6628     *thys = nthys;
6629 
6630     arr3dResize++;
6631 
6632     return ajTrue;
6633 }
6634 
6635 
6636 
6637 
6638 /* @func ajLong3dLen **********************************************************
6639 **
6640 ** Get lengths of 3d ajlong array
6641 **
6642 ** @param  [r] thys [const AjPLong3d] Pointer to the ajlong array.
6643 ** @param  [w] len1 [ajuint*] Length of 1st dim
6644 ** @param  [w] len2 [ajuint*] Length of 2nd dim
6645 ** @param  [w] len3 [ajuint*] Length of 3rd dim
6646 **
6647 ** @return [void]
6648 **
6649 ** @release 1.0.0
6650 ** @@
6651 ******************************************************************************/
6652 
ajLong3dLen(const AjPLong3d thys,ajuint * len1,ajuint * len2,ajuint * len3)6653 void ajLong3dLen(const AjPLong3d thys,
6654 		 ajuint* len1, ajuint* len2, ajuint* len3)
6655 {
6656     AjPLong2d t2;
6657     AjPLong   t1;
6658     ajuint i;
6659     ajuint j;
6660     ajuint v;
6661 
6662     *len1 = thys->Len;
6663     *len2 = 0;
6664 
6665     for(i=0;i<*len1;++i)
6666 	if((t2=thys->Ptr[i]))
6667 	    *len2 = (*len2 > t2->Len) ? *len2 : t2->Len;
6668 
6669     *len3 = 0;
6670 
6671     for(i=0;i<*len1;++i)
6672 	if((t2=thys->Ptr[i]))
6673 	{
6674 	    v = t2->Len;
6675 	    for(j=0;j<v;++j)
6676 		if((t1=t2->Ptr[j]))
6677 		    *len3 = (*len3 > t1->Len) ? *len3 : t1->Len;
6678 	}
6679 
6680     return;
6681 }
6682 
6683 
6684 
6685 
6686 /* @func ajLong3dLong *********************************************************
6687 **
6688 ** Convert AjPLong3d to ajlong***
6689 **
6690 ** @param  [r] thys [const AjPLong3d] Pointer to the ajlong array.
6691 **
6692 ** @return [ajlong***] converted values.
6693 ** @category cast [AjPLong3d] Retrieve internal pointer
6694 **
6695 ** @release 1.0.0
6696 ** @@
6697 ******************************************************************************/
6698 
ajLong3dLong(const AjPLong3d thys)6699 ajlong*** ajLong3dLong(const AjPLong3d thys)
6700 {
6701     AjPLong2d t2 = NULL;
6702     AjPLong   t1 = NULL;
6703     ajlong ***array;
6704     ajuint d1;
6705     ajuint d2;
6706     ajuint d3;
6707     ajuint i;
6708     ajuint j;
6709 
6710     ajLong3dLen(thys,&d1,&d2,&d3);
6711 
6712     AJCNEW0(array,d1);
6713     for(i=0;i<d1;++i)
6714     {
6715 	AJCNEW0(array[i],d2);
6716 	t2 = thys->Ptr[i];
6717 
6718 	for(j=0;j<d2;++j)
6719 	{
6720 	    AJCNEW0(array[i][j],d3);
6721 
6722 	    if(t2)
6723 	    {
6724 		if(j>=t2->Len)
6725                     continue;
6726 
6727 		if((t1=t2->Ptr[j]))
6728 		    memmove(array[i][j],t1->Ptr,
6729 				   t1->Len*sizeof(ajlong));
6730 	    }
6731 	}
6732     }
6733 
6734     return array;
6735 }
6736 
6737 
6738 
6739 
6740 /* @func ajArrExit ************************************************************
6741 **
6742 ** Cleanup of array handling internals, and debug report of memory use
6743 **
6744 ** @return [void]
6745 **
6746 ** @release 4.0.0
6747 ******************************************************************************/
6748 
ajArrExit(void)6749 void ajArrExit(void)
6750 {
6751 
6752     ajRegFree(&floatRegNum);
6753 
6754     ajDebug("Array usage (bytes): %Ld allocated, %Ld freed, %Ld in use\n",
6755             arrAlloc, arrFree,
6756             (arrAlloc - arrFree));
6757     ajDebug("Array usage (number): %Ld allocated, %Ld freed, %Ld resized,"
6758             " %Ld in use\n",
6759             arrTotal, arrFreeCount, arrResize, arrCount);
6760 
6761     ajDebug("Array usage 2D (bytes): %Ld allocated, %Ld freed, %Ld in use\n",
6762             arr2dAlloc, arr2dFree,
6763             (arr2dAlloc - arr2dFree));
6764     ajDebug("Array usage 2D (number): %Ld allocated, %Ld freed, %Ld resized,"
6765             " %Ld in use\n",
6766             arr2dTotal, arr2dFreeCount, arr2dResize, arr2dCount);
6767 
6768     ajDebug("Array usage 3D (bytes): %Ld allocated, %Ld freed, %Ld in use\n",
6769             arr3dAlloc, arr3dFree,
6770             (arr3dAlloc - arr3dFree));
6771     ajDebug("Array usage 3D (number): %Ld allocated, %Ld freed, %Ld resized,"
6772             " %Ld in use\n",
6773             arr3dTotal, arr3dFreeCount, arr3dResize, arr3dCount);
6774 
6775 
6776 
6777     return;
6778 }
6779 
6780 
6781 
6782 
6783 #ifdef AJ_COMPILE_DEPRECATED_BOOK
6784 #endif
6785 
6786 
6787 
6788 
6789 #ifdef AJ_COMPILE_DEPRECATED
6790 /* @obsolete ajChararrNewL
6791 ** @rename ajChararrNewRes
6792 */
ajChararrNewL(ajuint size)6793 __deprecated AjPChar ajChararrNewL(ajuint size)
6794 {
6795     return ajChararrNewRes(size);
6796 }
6797 
6798 
6799 
6800 
6801 /* @obsolete ajIntNewL
6802 ** @rename ajIntNewRes
6803 */
ajIntNewL(ajuint size)6804 __deprecated AjPInt ajIntNewL(ajuint size)
6805 {
6806     return ajIntNewRes(size);
6807 }
6808 
6809 
6810 
6811 
6812 /* @obsolete ajUintNewL
6813 ** @rename ajUintNewRes
6814 */
ajUintNewL(ajuint size)6815 __deprecated AjPUint ajUintNewL(ajuint size)
6816 {
6817     return ajUintNewRes(size);
6818 }
6819 
6820 
6821 
6822 
6823 /* @obsolete ajFloatNewL
6824 ** @rename ajFloatNewRes
6825 */
ajFloatNewL(ajuint size)6826 __deprecated AjPFloat ajFloatNewL(ajuint size)
6827 {
6828     return ajFloatNewRes(size);
6829 }
6830 
6831 
6832 
6833 
6834 /* @obsolete ajDoubleNewL
6835 ** @rename ajDoubleNewRes
6836 */
ajDoubleNewL(ajuint size)6837 __deprecated AjPDouble ajDoubleNewL(ajuint size)
6838 {
6839     return ajDoubleNewRes(size);
6840 }
6841 
6842 
6843 
6844 
6845 /* @obsolete ajShortNewL
6846 ** @rename ajShortNewRes
6847 */
ajShortNewL(ajuint size)6848 __deprecated AjPShort ajShortNewL(ajuint size)
6849 {
6850     return ajShortNewRes(size);
6851 }
6852 
6853 
6854 
6855 
6856 /* @obsolete ajLongNewL
6857 ** @rename ajLongNewRes
6858 */
ajLongNewL(ajuint size)6859 __deprecated AjPLong ajLongNewL(ajuint size)
6860 {
6861     return ajLongNewRes(size);
6862 }
6863 
6864 
6865 
6866 
6867 /* @obsolete ajInt2dNewL
6868 ** @rename ajInt2dNewRes
6869 */
ajInt2dNewL(ajuint size)6870 __deprecated AjPInt2d ajInt2dNewL(ajuint size)
6871 {
6872     return ajInt2dNewRes(size);
6873 }
6874 
6875 
6876 
6877 
6878 /* @obsolete ajInt2dNewLL
6879 ** @rename ajInt2dNewRes2
6880 */
ajInt2dNewLL(ajuint size,ajuint size2)6881 __deprecated AjPInt2d ajInt2dNewLL(ajuint size, ajuint size2)
6882 {
6883     return ajInt2dNewResRes2(size, size2);
6884 }
6885 
6886 
6887 
6888 
6889 /* @obsolete ajInt3dNewL
6890 ** @rename ajInt3dNewRes
6891 */
ajInt3dNewL(ajuint size)6892 __deprecated AjPInt3d ajInt3dNewL(ajuint size)
6893 {
6894     return ajInt3dNewRes(size);
6895 }
6896 
6897 
6898 
6899 
6900 /* @obsolete ajUint2dNewL
6901 ** @rename ajUint2dNewRes
6902 */
ajUint2dNewL(ajuint size)6903 __deprecated AjPUint2d ajUint2dNewL(ajuint size)
6904 {
6905     return ajUint2dNewRes(size);
6906 }
6907 
6908 
6909 
6910 
6911 /* @obsolete ajUint2dNewLL
6912 ** @rename ajUint2dNewRes2
6913 */
ajUint2dNewLL(ajuint size,ajuint size2)6914 __deprecated AjPUint2d ajUint2dNewLL(ajuint size, ajuint size2)
6915 {
6916     return ajUint2dNewResRes2(size, size2);
6917 }
6918 
6919 
6920 
6921 
6922 /* @obsolete ajUint3dNewL
6923 ** @rename ajUint3dNewRes
6924 */
ajUint3dNewL(ajuint size)6925 __deprecated AjPUint3d ajUint3dNewL(ajuint size)
6926 {
6927     return ajUint3dNewRes(size);
6928 }
6929 
6930 
6931 
6932 
6933 /* @obsolete ajFloat2dNewL
6934 ** @rename ajFloat2dNewRes
6935 */
ajFloat2dNewL(ajuint size)6936 __deprecated AjPFloat2d ajFloat2dNewL(ajuint size)
6937 {
6938     return ajFloat2dNewRes(size);
6939 }
6940 
6941 
6942 
6943 
6944 /* @obsolete ajDouble2dNewL
6945 ** @rename ajDouble2dNewRes
6946 */
ajDouble2dNewL(ajuint size)6947 __deprecated AjPDouble2d ajDouble2dNewL(ajuint size)
6948 {
6949     return ajDouble2dNewRes(size);
6950 }
6951 
6952 
6953 
6954 
6955 /* @obsolete ajDouble3dNewL
6956 ** @rename ajDouble3dNewRes
6957 */
ajDouble3dNewL(ajuint size)6958 __deprecated AjPDouble3d ajDouble3dNewL(ajuint size)
6959 {
6960     return ajDouble3dNewRes(size);
6961 }
6962 
6963 
6964 
6965 
6966 /* @obsolete ajShort2dNewL
6967 ** @rename ajShort2dNewRes
6968 */
ajShort2dNewL(ajuint size)6969 __deprecated AjPShort2d ajShort2dNewL(ajuint size)
6970 {
6971     return ajShort2dNewRes(size);
6972 }
6973 
6974 
6975 
6976 
6977 /* @obsolete ajShort3dNewL
6978 ** @rename ajShort3dNewRes
6979 */
ajShort3dNewL(ajuint size)6980 __deprecated AjPShort3d ajShort3dNewL(ajuint size)
6981 {
6982     return ajShort3dNewRes(size);
6983 }
6984 
6985 
6986 
6987 
6988 /* @obsolete ajLong2dNewL
6989 ** @rename ajLong2dNewRes
6990 */
ajLong2dNewL(ajuint size)6991 __deprecated AjPLong2d ajLong2dNewL(ajuint size)
6992 {
6993     return ajLong2dNewRes(size);
6994 }
6995 
6996 
6997 
6998 
6999 /* @obsolete ajLong3dNewL
7000 ** @rename ajLong3dNewRes
7001 */
ajLong3dNewL(ajuint size)7002 __deprecated AjPLong3d ajLong3dNewL(ajuint size)
7003 {
7004     return ajLong3dNewRes(size);
7005 }
7006 #endif
7007