// File: /workspace/github_cpp_makefile_star2_O2/nompelis[P]INTecplotLib/intecplot.cpp
// Function: inTec_Zone::ManageInternals()
int inTec_Zone::ManageInternals( void )
{
#ifdef _DEBUG_
   printf(" i Inside ManageInternals() \n");
#endif
   int ierror=0,iret=0;

   // processing individual keywords
   const char *string=NULL,*string2=NULL;
   size_t is;
   int i=0;
   std::map< std::string, std::string > :: iterator imap;
   for( imap = keywords.begin(); imap != keywords.end(); ++imap ) {
      printf("   %d  ", i++ );
      string = (*imap).first.c_str();
      printf("   %s  ", string );
      string2 = (*imap).second.c_str();
      printf("   \"%s\"\n", string2 );

      // keywords by size
      is = strlen( string );

      if( is == 1 ) {
         if( strncasecmp( string, "N", 1 ) == 0 ) {
            iold_n = (unsigned long) atol( string2 );
         }

         if( strncasecmp( string, "E", 1 ) == 0 ) {
            iold_e = (unsigned long) atol( string2 );
         }

         if( strncasecmp( string, "I", 1 ) == 0 ) {
            im = (unsigned long) atol( string2 );
         }
         if( strncasecmp( string, "J", 1 ) == 0 ) {
            jm = (unsigned long) atol( string2 );
         }
         if( strncasecmp( string, "K", 1 ) == 0 ) {
            km = (unsigned long) atol( string2 );
         }
         if( strncasecmp( string, "T", 1 ) == 0 ) {
            iret = HandleKeyword_T( string2 );
            if( iret != 0 ) ierror += 1;
         }
         if( strncasecmp( string, "F", 1 ) == 0 ) {
         // will deal with this later...
         // iret = HandleKeyword_F( string2 );
            if( iret != 0 ) ierror += 1;
         }
      }

      if( is == 2 ) {
         if( strncasecmp( string, "DT", 2 ) == 0 ) {
            // will do this later...
         }

         if( strncasecmp( string, "ET", 2 ) == 0 ) {
            iret = HandleKeyword_ET( string2 );
            if( iret != 0 ) ierror += 1;
         }

         if( strncasecmp( string, "NV", 2 ) == 0 ) {
            // will do this later...
         }

      }

      if( is == 5 ) {
         if( strncasecmp( string, "NODES", 5 ) == 0 ) {
            nodes = (unsigned long) atol( string2 );
         }

      }

      if( is == 8 ) {
         if( strncasecmp( string, "ELEMENTS", 8 ) == 0 ) {
            elems = (unsigned long) atol( string2 );
         }

         if( strncasecmp( string, "ZONETYPE", 8 ) == 0 ) {
            iret = HandleKeyword_Zonetype( string2 );
            if( iret != 0 ) ierror += 1;
         }
      }

      if( is == 10 ) {
         if( strncasecmp( string, "PARENTZONE", 10 ) == 0 ) {
            parent_zone = atoi( string2 );
         }
      }

      if( is == 11 ) {
         if( strncasecmp( string, "VARLOCATION", 11 ) == 0 ) {
            iret = HandleKeyword_Varlocation( string2 );
            if( iret != 0 ) ierror += 1;
         }
         if( strncasecmp( string, "DATAPACKING", 11 ) == 0 ) {
            iret = HandleKeyword_Datapacking( string2 );
            if( iret != 0 ) ierror += 1;
         }

      }

      if( is == 12 ) {
         if( strncasecmp( string, "VARSHARELIST", 12 ) == 0 ) {
            iret = HandleKeyword_Varsharelist( string2 );
            if( iret != 0 ) ierror += 1;
         }
      }

   }

   // sanity checks for the zone's collected keywords
   ierror += ConsistencyCheck();

   // final error check
   if( ierror != 0 ) {
      iret = 1;
#ifdef _DEBUG_
      printf(" e Exiting ManageInternals() in error (return %d) \n",iret);
#endif
      return( iret );
   }

   //
   // allocate memory for variables
   //

   // get a vertex and cell count
   size_t iv=0,ie=0;

   // first try the ordered zone sizes
   if( ietype == ORDERED ) {
      unsigned long imt,jmt,kmt;
#ifdef _DEBUG_
      printf(" i Internal var. \"ietype\" indicates it is an ORDERED zone \n");
#endif
      if( im - 1 == 0 ) { imt = 2; } else { imt = im; }
      if( jm - 1 == 0 ) { jmt = 2; } else { jmt = jm; }
      if( km - 1 == 0 ) { kmt = 2; } else { kmt = km; }

      if( jm > 0 ) {
         if( km > 0 ) {
            iv = (size_t) (im*jm*km);
            ie = (size_t) ((imt-1)*(jmt-1)*(kmt-1));
         } else {
            iv = (size_t) (im*jm);
            ie = (size_t) ((imt-1)*(jmt-1));
         }
      } else {
         iv = (size_t) im;
         ie = (size_t) (imt-1);
      }
   }

   // then try the unstruct. zone sizes
   if( ietype != ORDERED ) {
#ifdef _DEBUG_
      printf(" i Internal var. \"ietype\" indicates it is an unstr. zone \n");
#endif
      iv = (size_t) nodes;
      ie = (size_t) elems;
   }

#ifdef _DEBUG_
   printf(" i Number of vertices  %ld, elements  %ld \n",
          (unsigned long) iv, (unsigned long) ie );
#endif

   // sanity check
   if( iv <= 0 || ie <= 0 ) {
      printf(" e Cannot have zero nodes or zero elements \n");
      iret = 1;
#ifdef _DEBUG_
      printf(" e Exiting ManageInternals() in error (return %d) \n",iret);
#endif
      return( iret );
   }

   // allocate memory for data arrays
   for(int n=1;n<=num_var;++n) {
      if( ivar_loc[n] == 1 ) {
         double *p = (double *) malloc(iv*sizeof(double));
         var_vec.push_back( p );
         if( p == NULL ) ierror += 1;
#ifdef _DEBUG_
         printf(" --- Vertex-data pointer at %p \n", p );
#endif
      } else if( ivar_loc[n] == 2 ) {
         double *p = (double *) malloc(ie*sizeof(double));
         var_vec.push_back( p );
         if( p == NULL ) ierror += 1;
#ifdef _DEBUG_
         printf(" --- Cell-data pointer at %p \n", p );
#endif
      } else {
         // allow for the provision to skip allocating memory for a variable
      }
   }

   // allocate memory for connectivity if needed
   if( ietype != ORDERED ) {
      if( ietype == FETRIANGLE ) ncon = 3;
      if( ietype == FEQUADRILATERAL) ncon = 4;
      if( ietype == FETETRAHEDRON) ncon = 4;
      if( ietype == FEBRICK) ncon = 8;

      size_t isize = (size_t) (elems*ncon);
      if( icon == NULL ) {
         icon = (unsigned long *) malloc(isize*sizeof(unsigned long));
      }
      if( icon == NULL ) ierror += 1;
   }

   // drop all memory on any allocation error
   if( ierror != 0 ) {
#ifdef _DEBUG_
      printf(" e There was an allocation error!\n");
#endif
      if( icon != NULL ) free( icon );

      std::vector< double * > :: iterator dpi;
      for( dpi = var_vec.begin() ; dpi != var_vec.end() ; ++dpi ) {
         if( (*dpi) != NULL ) {
#ifdef _DEBUG_
            printf(" --- Freeing memory at: %p \n", (*dpi) );
#endif
            free( (*dpi) );
         }
      }
      var_vec.clear();

      iret = 1;
#ifdef _DEBUG_
      printf(" e Exiting ManageInternals() in error (return %d) \n",iret);
#endif
   } else {
      istate = 2;    // implies a state of reading numerical values
   }

/*
   // set certain internal counters for numeric data reading (later)
   var_no_cnt = 0;
   var_cc_cnt = 0;
   for(int n=1;n<=num_var;++n) {
      if( ivar_loc[n] == 1 ) {
         var_no_cnt += 1;
      } else if( ivar_loc[n] == 2 ) {
         var_cc_cnt += 1;
      } else {
         // I have not thought about this one...
      }
   }
*///HACK

#ifdef _DEBUG_
   printf(" i Exiting ManageInternals() (return %d) \n",iret);
#endif
//printf("EXITING PREMATURELY IN MANAGE...\n");exit(1);//HACK
   return( iret );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
leaq 0x7f87(%rip), %rdi      # 0x10077
callq 0x77b0
movq 0x100(%rbx), %r12
movq %rbx, 0x10(%rsp)
addq $0xf0, %rbx
leaq 0x70d5(%rip), %rbp      # 0xf1e4
xorl %r15d, %r15d
movl $0x0, 0xc(%rsp)
movl $0x0, 0x18(%rsp)
movq %rbx, 0x30(%rsp)
cmpq %rbx, %r12
je 0x8496
movq %rbp, %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0x7060
movq 0x20(%r12), %r14
leaq 0x747d(%rip), %rdi      # 0xf5c6
movq %r14, %rsi
xorl %eax, %eax
callq 0x7060
movq 0x40(%r12), %r13
leaq 0x746f(%rip), %rdi      # 0xf5ce
movq %r13, %rsi
xorl %eax, %eax
callq 0x7060
movq %r14, %rdi
callq 0x71f0
decq %rax
cmpq $0xb, %rax
ja 0x8483
leaq 0x6e8b(%rip), %rcx      # 0xf010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
leaq 0x75cf(%rip), %rsi      # 0xf767
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x7650
testl %eax, %eax
jne 0x81bb
movq %r13, %rdi
callq 0x75d0
movq 0x10(%rsp), %rcx
movq %rax, 0xb0(%rcx)
movq %r14, %rdi
leaq 0x75ad(%rip), %rsi      # 0xf772
movq %rbx, %rdx
callq 0x7650
testl %eax, %eax
jne 0x81e5
movq %r13, %rdi
callq 0x75d0
movq 0x10(%rsp), %rcx
movq %rax, 0xb8(%rcx)
movq %r14, %rdi
leaq 0x73a9(%rip), %rsi      # 0xf598
movq %rbx, %rdx
callq 0x7650
testl %eax, %eax
jne 0x820c
movq %r13, %rdi
callq 0x75d0
movq 0x10(%rsp), %rcx
movq %rax, 0x30(%rcx)
movq %r14, %rdi
leaq 0x7384(%rip), %rsi      # 0xf59a
movq %rbx, %rdx
callq 0x7650
testl %eax, %eax
jne 0x8233
movq %r13, %rdi
callq 0x75d0
movq 0x10(%rsp), %rcx
movq %rax, 0x38(%rcx)
movq %r14, %rdi
leaq 0x7516(%rip), %rsi      # 0xf753
movq %rbx, %rdx
callq 0x7650
testl %eax, %eax
jne 0x825a
movq %r13, %rdi
callq 0x75d0
movq 0x10(%rsp), %rcx
movq %rax, 0x40(%rcx)
movq %r14, %rdi
leaq 0x7041(%rip), %rsi      # 0xf2a5
movq %rbx, %rdx
callq 0x7650
testl %eax, %eax
je 0x842a
movl 0xc(%rsp), %r13d
movl 0x18(%rsp), %ebp
jmp 0x844a
movq %rbx, %rbp
movq %r14, %rdi
leaq 0x7032(%rip), %rsi      # 0xf2c1
pushq $0xb
popq %rdx
callq 0x7650
testl %eax, %eax
je 0x83d9
movl 0x18(%rsp), %ebx
jmp 0x83f4
movq %r14, %rdi
leaq 0x72ec(%rip), %rsi      # 0xf59e
pushq $0x2
popq %rdx
callq 0x7650
testl %eax, %eax
jne 0x8483
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x79e0
movl $0x0, 0xc(%rsp)
jmp 0x8483
movq %r14, %rdi
leaq 0x72d3(%rip), %rsi      # 0xf5b9
pushq $0xc
popq %rdx
callq 0x7650
testl %eax, %eax
jne 0x8483
movq %r13, %rsi
callq 0x7630
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
addl %ecx, 0x18(%rsp)
negl %ecx
movl %ecx, 0xc(%rsp)
jmp 0x8483
movq %r14, %rdi
leaq 0x7286(%rip), %rsi      # 0xf5a4
pushq $0x5
popq %rdx
callq 0x7650
testl %eax, %eax
jne 0x8483
movq %r13, %rdi
callq 0x75d0
movq 0x10(%rsp), %rcx
movq %rax, 0x48(%rcx)
jmp 0x8483
movq %r14, %rdi
leaq 0x7262(%rip), %rsi      # 0xf5b0
pushq $0x8
popq %rbx
movq %rbx, %rdx
callq 0x7650
testl %eax, %eax
jne 0x836e
movq %r13, %rdi
callq 0x75d0
movq 0x10(%rsp), %rcx
movq %rax, 0x50(%rcx)
movq %r14, %rdi
leaq 0x6f1c(%rip), %rsi      # 0xf294
movq %rbx, %rdx
callq 0x7650
testl %eax, %eax
jne 0x8399
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x74f0
movl %eax, 0xc(%rsp)
addl %eax, 0x18(%rsp)
leaq 0x6e44(%rip), %rbp      # 0xf1e4
movq 0x30(%rsp), %rbx
jmp 0x8483
movq %r14, %rdi
leaq 0x7223(%rip), %rsi      # 0xf5d7
pushq $0xa
popq %rdx
callq 0x7650
testl %eax, %eax
jne 0x8483
movq %r13, %rdi
callq 0x77d0
movq 0x10(%rsp), %rcx
movl %eax, 0x24(%rcx)
jmp 0x8483
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x7680
movl %eax, 0xc(%rsp)
cmpl $0x1, %eax
movl 0x18(%rsp), %ebx
sbbl $-0x1, %ebx
movq %r14, %rdi
leaq 0x6eaf(%rip), %rsi      # 0xf2ad
pushq $0xb
popq %rdx
callq 0x7650
testl %eax, %eax
jne 0x8421
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x7110
movl %eax, 0xc(%rsp)
cmpl $0x1, %eax
sbbl $-0x1, %ebx
movl %ebx, 0x18(%rsp)
movq %rbp, %rbx
jmp 0x847c
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x76c0
xorl %r13d, %r13d
testl %eax, %eax
setne %r13b
movl 0x18(%rsp), %ebp
addl %r13d, %ebp
negl %r13d
movq 0x30(%rsp), %rbx
movq %r14, %rdi
leaq 0x7143(%rip), %rsi      # 0xf59c
pushq $0x1
popq %rdx
callq 0x7650
testl %eax, %eax
sete %al
movl %r13d, 0xc(%rsp)
testl %r13d, %r13d
setne %cl
andb %al, %cl
movzbl %cl, %eax
addl %eax, %ebp
movl %ebp, 0x18(%rsp)
leaq 0x6d61(%rip), %rbp      # 0xf1e4
movq %r12, %rdi
callq 0x72f0
movq %rax, %r12
incl %r15d
jmp 0x8127
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
callq 0x7570
addl %eax, 0x18(%rsp)
jne 0x861e
cmpl $0x0, 0x18(%rbp)
jne 0x8519
leaq 0x7bda(%rip), %rdi      # 0x10094
callq 0x77b0
movq 0x30(%rbp), %rdx
movq 0x38(%rbp), %r15
leaq -0x1(%rdx), %rbx
cmpq $0x1, %rdx
cmoveq %rdx, %rbx
movq 0x40(%rbp), %rsi
leaq -0x1(%rsi), %rcx
cmpq $0x1, %rsi
cmoveq %rsi, %rcx
movq %r15, %rax
subq $0x1, %rax
cmoveq %r15, %rax
jae 0x84f5
movq %rdx, %r15
jmp 0x8513
imulq %rdx, %r15
testq %rsi, %rsi
je 0x850f
imulq %rsi, %r15
imulq %rbx, %rax
imulq %rcx, %rax
movq %rax, %rbx
jmp 0x8513
imulq %rax, %rbx
cmpl $0x0, 0x18(%rbp)
je 0x852d
leaq 0x7baf(%rip), %rdi      # 0x100cf
callq 0x77b0
movq 0x48(%rbp), %r15
movq 0x50(%rbp), %rbx
leaq 0x70e2(%rip), %rdi      # 0xf616
movq %r15, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x7060
testq %r15, %r15
je 0x8612
testq %rbx, %rbx
je 0x8612
leaq 0x58(%rbp), %r13
shlq $0x3, %rbx
movq %rbx, 0x18(%rsp)
leaq 0x88(%rbp), %r14
shlq $0x3, %r15
pushq $0x1
popq %rax
leaq 0x2c(%rsp), %r12
xorl %ebx, %ebx
movl %eax, 0x2c(%rsp)
cmpl 0x20(%rbp), %eax
jg 0x862d
movq %r13, %rdi
movq %r12, %rsi
callq 0x72d0
cmpl $0x1, (%rax)
jne 0x85c1
movq %r15, %rdi
callq 0x76e0
movq %rax, 0x20(%rsp)
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
callq 0x7960
movq 0x20(%rsp), %rsi
cmpq $0x1, %rsi
adcl $0x0, %ebx
leaq 0x7083(%rip), %rdi      # 0xf642
jmp 0x8600
movq %r13, %rdi
movq %r12, %rsi
callq 0x72d0
cmpl $0x2, (%rax)
jne 0x8607
movq 0x18(%rsp), %rdi
callq 0x76e0
movq %rax, 0x20(%rsp)
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
callq 0x7960
movq 0x20(%rsp), %rsi
cmpq $0x1, %rsi
adcl $0x0, %ebx
leaq 0x7063(%rip), %rdi      # 0xf663
xorl %eax, %eax
callq 0x7060
movl 0x2c(%rsp), %eax
incl %eax
jmp 0x8575
leaq 0x7b12(%rip), %rdi      # 0x1012b
callq 0x77b0
leaq 0x6fbd(%rip), %rdi      # 0xf5e2
pushq $0x1
popq %rbx
jmp 0x8713
movl 0x18(%rbp), %eax
cmpq $0x6, %rax
ja 0x8658
leaq 0x6a03(%rip), %rcx      # 0xf040
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x4
jmp 0x8650
pushq $0x3
jmp 0x8650
pushq $0x8
popq %rax
movq %rax, 0xa8(%rbp)
xorl %ecx, %ecx
cmpq $0x0, 0xa0(%rbp)
jne 0x8688
movq 0x50(%rbp), %rdi
imulq 0xa8(%rbp), %rdi
shlq $0x3, %rdi
callq 0x76e0
movq %rax, 0xa0(%rbp)
xorl %ecx, %ecx
testq %rax, %rax
sete %cl
addl %ecx, %ebx
testl %ebx, %ebx
je 0x8701
leaq 0x7a74(%rip), %rdi      # 0x10109
callq 0x77b0
movq 0xa0(%rbp), %rdi
callq 0x75c0
movq 0x88(%rbp), %rbx
leaq 0x6fce(%rip), %r15      # 0xf682
cmpq 0x90(%rbp), %rbx
je 0x86dd
movq (%rbx), %rsi
testq %rsi, %rsi
je 0x86d7
movq %r15, %rdi
xorl %eax, %eax
callq 0x7060
movq (%rbx), %rdi
callq 0x75c0
addq $0x8, %rbx
jmp 0x86b4
movq (%r14), %rax
cmpq %rax, %rbx
je 0x86ec
movq %rax, 0x90(%rbp)
leaq 0x6eef(%rip), %rdi      # 0xf5e2
pushq $0x1
popq %rbx
movl %ebx, %esi
xorl %eax, %eax
callq 0x7060
jmp 0x870c
movl $0x2, 0x8(%rbp)
movl 0xc(%rsp), %ebx
leaq 0x6f8c(%rip), %rdi      # 0xf69f
movl %ebx, %esi
xorl %eax, %eax
callq 0x7060
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop