// File: /workspace/github_cpp_makefile_star2_O3/nompelis[P]INTecplotLib/intecplot.cpp
// Function: inTec_Zone::Dump(char const*)
int inTec_Zone::Dump( const char *filename )
{
   if( filename == NULL ) {
#ifdef _DEBUG_
      printf(" e You need to supply a non-null filename string \n");
#endif
      return(1);
   }
   if( istate != 3 ) {
#ifdef _DEBUG_
      printf(" e Zone is in the wrong state: %d \n", istate );
#endif
      return(2);
   }

#ifdef _DEBUG_
   printf(" i Dumping zone to file \"%s\"\n", filename);
#endif

   FILE *fout = fopen( filename, "w" );
   if( fout == NULL ) {
      printf(" e Could not open file for writing!\n");
      return(-1);
   }

   // write the variables first
   fprintf( fout, "VARIABLES = " );
   // (queries back the file structure/class)
   for(int n=0;n<num_var;++n) {
      const char *s = file->GetVariableName( n );
      fprintf( fout, "\"%s\" ", s );
   }
   fprintf( fout, "\n" );

   // put a zone keywords and attach the "T" keyword to it
   fprintf( fout, "ZONE " );
   std::map< std::string, std::string > :: iterator imt;
   for( imt = keywords.begin(); imt != keywords.end(); ++imt ) {
      if( strlen( (*imt).first.c_str() ) == 1 ) {
         if( strncmp( (*imt).first.c_str(), "T", 1 ) == 0 ) {
            const char *s = (*imt).second.c_str();
            if( s[0] == '\"' ) {
               fprintf( fout, "T=%s, ", s );
            } else {
               fprintf( fout, "T=\"%s\", ", s );
            }
         }
      }
   }

   // decide which essential keywords to use
   if( ietype == ORDERED ) {
      if( im > 0 ) fprintf( fout, "I=%ld, ", im );
      if( jm > 0 ) fprintf( fout, "J=%ld, ", jm );
      if( km > 0 ) fprintf( fout, "K=%ld, ", km );



   } else {
      if( nodes > 0 ) fprintf( fout, "NODES=%ld, ", nodes );
      if( elems > 0 ) fprintf( fout, "ELEMENTS=%ld, ", elems );

      if( ietype == FETRIANGLE ) 
         fprintf( fout, "ZONETYPE=FETRIANGLE, " );
      if( ietype == FEQUADRILATERAL ) 
         fprintf( fout, "ZONETYPE=FEQUADRILATERAL, " );
      if( ietype == FETETRAHEDRON ) 
         fprintf( fout, "ZONETYPE=FETETRAHEDRON, " );
      if( ietype == FEBRICK )
         fprintf( fout, "ZONETYPE=FEBRICK, " );


   // for( imt = keywords.begin(); imt != keywords.end(); ++imt ) {
   //    if( strlen( (*imt).first.c_str() ) == 11 ) {
   //       if( strncmp( (*imt).first.c_str(), "VARLOCATION", 11 ) == 0 ) {
   //          fprintf( fout, "VARLOCATION=%s ", (*imt).second.c_str() );
   //       }
   //    }
   // }

   }

   if( idatapack == 1 ) {
      fprintf( fout, " DATAPACKING=POINT,\n" );
   } else {
      fprintf( fout, " DATAPACKING=BLOCK,\n" );
   }

   for( imt = keywords.begin(); imt != keywords.end(); ++imt ) {
      if( strlen( (*imt).first.c_str() ) == 11 ) {
         const char *s = (*imt).second.c_str();
         // perhaps do some string sanitation here (capitalization, etc...)
         if( strncmp( (*imt).first.c_str(), "VARLOCATION", 11 ) == 0 ) {
            fprintf( fout, "VARLOCATION=%s ", s );
         }
      }
   }
   fprintf( fout, "\n" );


   if( ietype == ORDERED ) {
      unsigned long jmt=1,kmt=1;

      if( idatapack == 1 ) {
         if( jm > 0 ) jmt = jm;
         if( km > 0 ) kmt = km;

         for(unsigned long k=0;k<kmt;++k) {
         for(unsigned long j=0;j<jmt;++j) {
         for(unsigned long i=0;i<im;++i) {
            unsigned long n = k*jmt*im + j*im + i;
            for(int kk=0;kk<num_var;++kk) {
               fprintf( fout, " %18.11e", var_vec[kk][n] );
            }
            fprintf( fout, "\n");
         }}}
      } else {
         for(int kk=0;kk<num_var;++kk) {
            if( ivar_loc[kk+1] == 1 ) {   // nodal
               if( jm > 0 ) jmt = jm;
               if( km > 0 ) kmt = km;

               for(unsigned long k=0;k<kmt;++k) {
               for(unsigned long j=0;j<jmt;++j) {
               for(unsigned long i=0;i<im;++i) {
                  unsigned long n = k*jmt*im + j*im + i;
                  fprintf( fout, " %18.11e \n", var_vec[kk][n] );
               }}}
            } else {  // cell-centered
               if( jm > 0 ) jmt = jm-1;
               if( km > 0 ) kmt = km-1;

               for(unsigned long i=0;i<im-1;++i) {
               for(unsigned long j=0;j<jmt;++j) {
               for(unsigned long k=0;k<kmt;++k) {
                  unsigned long n = k*jmt*(im-1) + j*(im-1) + i;
                  fprintf( fout, " %18.11e \n", var_vec[kk][n] );
               }}}
            }
         }
      } // datapack
   } else {  // unstructured data
      if( idatapack == 1 ) {
         for(unsigned long n=0;n<nodes;++n) {
            for(int kk=0;kk<num_var;++kk) {
               fprintf( fout, " %18.11e", var_vec[kk][n] );
            }
            fprintf( fout, " \n" );
         }
      } else {
         for(int kk=0;kk<num_var;++kk) {
            if( ivar_loc[kk+1] == 1 ) {   // nodal
               for(unsigned long n=0;n<nodes;++n) {
                  fprintf( fout, " %18.11e \n", var_vec[kk][n] );
               }
            } else {  // cell-centered
               for(unsigned long n=0;n<elems;++n) {
                  fprintf( fout, " %18.11e \n", var_vec[kk][n] );
               }
            }
         }
      } // datapack

      // dump connectivity
      for(unsigned long i=0;i<elems;++i) {
         for(unsigned long j=0;j<ncon;++j) {
            fprintf( fout, " %ld", icon[ i*ncon + j ] );
         }
         fprintf( fout, "\n" );
      }
   }

   // close the file
   fflush( fout );
   fclose( fout );

#ifdef _DEBUG_
   printf(" i Finished dumping zone to file \"%s\"\n", filename);
#endif
   return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
testq %rsi, %rsi
je 0x850c
movq %rsi, %rbx
movq %rdi, %r14
movl 0x8(%rdi), %esi
cmpl $0x3, %esi
jne 0x8522
leaq 0x660a(%rip), %rdi      # 0xe924
movq %rbx, %rsi
xorl %eax, %eax
callq 0x5060
leaq 0x6617(%rip), %rsi      # 0xe942
movq %rbx, %rdi
callq 0x5410
testq %rax, %rax
je 0x853a
movq %rax, %r15
movq %rbx, 0x50(%rsp)
leaq 0x65f9(%rip), %rdi      # 0xe944
movl $0xc, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x56e0
cmpl $0x0, 0x20(%r14)
jle 0x83b6
leaq 0x65e6(%rip), %r12      # 0xe951
xorl %ebx, %ebx
xorl %r13d, %r13d
movq 0xc8(%r14), %rcx
movq 0x160(%rcx), %rax
movq 0x168(%rcx), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
cmpq %r13, %rcx
jbe 0x8397
movq (%rax,%rbx), %rdx
jmp 0x8399
xorl %edx, %edx
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x5540
incq %r13
movslq 0x20(%r14), %rax
addq $0x20, %rbx
cmpq %rax, %r13
jl 0x8370
movl $0xa, %edi
movq %r15, %rsi
callq 0x5480
leaq 0x658d(%rip), %rdi      # 0xe957
movl $0x5, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x56e0
movq 0x100(%r14), %r12
leaq 0xf0(%r14), %rbp
cmpq %rbp, %r12
je 0x843c
leaq 0x6567(%rip), %r13      # 0xe95d
movq 0x20(%r12), %rbx
movq %rbx, %rdi
callq 0x5150
cmpq $0x1, %rax
jne 0x842c
cmpb $0x54, (%rbx)
jne 0x842c
movq 0x40(%r12), %rdx
cmpb $0x22, (%rdx)
movq %r13, %rsi
je 0x8422
leaq 0x6542(%rip), %rsi      # 0xe964
movq %r15, %rdi
xorl %eax, %eax
callq 0x5540
movq %r12, %rdi
callq 0x5200
movq %rax, %r12
cmpq %rbp, %rax
jne 0x83f6
cmpl $0x0, 0x18(%r14)
je 0x8550
movq 0x48(%r14), %rdx
testq %rdx, %rdx
je 0x8461
leaq 0x652e(%rip), %rsi      # 0xe985
movq %r15, %rdi
xorl %eax, %eax
callq 0x5540
movq 0x50(%r14), %rdx
testq %rdx, %rdx
je 0x847b
leaq 0x6520(%rip), %rsi      # 0xe991
movq %r15, %rdi
xorl %eax, %eax
callq 0x5540
movl 0x18(%r14), %eax
cmpl $0x2, %eax
jne 0x84a1
leaq 0x6515(%rip), %rdi      # 0xe9a0
movl $0x15, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x56e0
movl 0x18(%r14), %eax
cmpl $0x3, %eax
jne 0x84c3
leaq 0x6509(%rip), %rdi      # 0xe9b6
movl $0x1a, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x56e0
movl 0x18(%r14), %eax
cmpl $0x5, %eax
jne 0x84e5
leaq 0x6502(%rip), %rdi      # 0xe9d1
movl $0x18, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x56e0
movl 0x18(%r14), %eax
cmpl $0x6, %eax
jne 0x859e
leaq 0x64f5(%rip), %rdi      # 0xe9ea
movl $0x12, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x56e0
jmp 0x859e
leaq 0x7128(%rip), %rdi      # 0xf63b
callq 0x5570
movl $0x1, %ebp
jmp 0x8b27
leaq 0x63d7(%rip), %rdi      # 0xe900
xorl %eax, %eax
callq 0x5060
movl $0x2, %ebp
jmp 0x8b27
leaq 0x70d6(%rip), %rdi      # 0xf617
callq 0x5570
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x8b27
movq 0x30(%r14), %rdx
testq %rdx, %rdx
je 0x856a
leaq 0x640d(%rip), %rsi      # 0xe96d
movq %r15, %rdi
xorl %eax, %eax
callq 0x5540
movq 0x38(%r14), %rdx
testq %rdx, %rdx
je 0x8584
leaq 0x63fb(%rip), %rsi      # 0xe975
movq %r15, %rdi
xorl %eax, %eax
callq 0x5540
movq 0x40(%r14), %rdx
testq %rdx, %rdx
je 0x859e
leaq 0x63e9(%rip), %rsi      # 0xe97d
movq %r15, %rdi
xorl %eax, %eax
callq 0x5540
cmpl $0x1, 0x1c(%r14)
leaq 0x6453(%rip), %rax      # 0xe9fd
leaq 0x6461(%rip), %rdi      # 0xea12
cmoveq %rax, %rdi
movl $0x14, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x56e0
movq 0x100(%r14), %r12
cmpq %rbp, %r12
je 0x8627
leaq 0x5ce7(%rip), %r13      # 0xe2c1
movq 0x20(%r12), %rbx
movq %rbx, %rdi
callq 0x5150
cmpq $0xb, %rax
jne 0x8617
movl $0xb, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5160
testl %eax, %eax
jne 0x8617
movq 0x40(%r12), %rdx
movq %r15, %rdi
leaq 0x6417(%rip), %rsi      # 0xea27
xorl %eax, %eax
callq 0x5540
movq %r12, %rdi
callq 0x5200
movq %rax, %r12
cmpq %rbp, %rax
jne 0x85da
movl $0xa, %edi
movq %r15, %rsi
callq 0x5480
cmpl $0x0, 0x18(%r14)
movl 0x1c(%r14), %eax
je 0x86b8
cmpl $0x1, %eax
jne 0x87a8
cmpq $0x0, 0x48(%r14)
je 0x8856
xorl %ebx, %ebx
leaq 0x63db(%rip), %r12      # 0xea37
leaq 0x60e7(%rip), %r13      # 0xe74a
cmpl $0x0, 0x20(%r14)
jle 0x8695
xorl %ebp, %ebp
movq 0x88(%r14), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%rbx,8), %xmm0
movq %r15, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x5540
incq %rbp
movslq 0x20(%r14), %rax
cmpq %rax, %rbp
jl 0x866c
movl $0x2, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %r15, %rcx
callq 0x56e0
incq %rbx
cmpq 0x48(%r14), %rbx
jb 0x8663
jmp 0x8856
cmpl $0x1, %eax
jne 0x88c5
movq 0x30(%r14), %r13
movq 0x38(%r14), %rax
cmpq $0x1, %rax
adcq $0x0, %rax
movq %rax, (%rsp)
movq 0x40(%r14), %rax
cmpq $0x1, %rax
adcq $0x0, %rax
movq %rax, 0x30(%rsp)
xorl %eax, %eax
leaq 0x6348(%rip), %r12      # 0xea37
movq %rax, 0x10(%rsp)
imulq (%rsp), %rax
movq %rax, 0x18(%rsp)
movq %r13, %rax
xorl %edx, %edx
testq %rax, %rax
movq %rdx, 0x20(%rsp)
je 0x877c
movq 0x18(%rsp), %rcx
addq %rdx, %rcx
movq %rcx, 0x8(%rsp)
movq %rax, %r13
xorl %ebp, %ebp
cmpl $0x0, 0x20(%r14)
jle 0x875e
imulq 0x8(%rsp), %r13
shlq $0x3, %r13
xorl %ebx, %ebx
movq 0x88(%r14), %rax
movq (%rax,%rbx,8), %rax
addq %r13, %rax
movsd (%rax,%rbp,8), %xmm0
movq %r15, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x5540
incq %rbx
movslq 0x20(%r14), %rax
cmpq %rax, %rbx
jl 0x8732
movl $0xa, %edi
movq %r15, %rsi
callq 0x5480
incq %rbp
movq 0x30(%r14), %r13
movq %r13, %rax
cmpq %r13, %rbp
jb 0x871f
jmp 0x877e
xorl %eax, %eax
movq 0x20(%rsp), %rdx
incq %rdx
cmpq (%rsp), %rdx
jne 0x8703
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x30(%rsp), %rax
jne 0x86ef
jmp 0x8b02
cmpl $0x0, 0x20(%r14)
jle 0x8856
leaq 0x58(%r14), %rax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
leaq 0x627a(%rip), %rbp      # 0xea40
movq %r13, %rbx
incq %r13
movl %r13d, 0x40(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x53d0
cmpl $0x1, (%rax)
jne 0x8818
cmpq $0x0, 0x48(%r14)
je 0x8849
xorl %r12d, %r12d
movq 0x88(%r14), %rax
movq (%rax,%rbx,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %r15, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x5540
incq %r12
cmpq 0x48(%r14), %r12
jb 0x87ef
jmp 0x8849
cmpq $0x0, 0x50(%r14)
je 0x8849
xorl %r12d, %r12d
movq 0x88(%r14), %rax
movq (%rax,%rbx,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %r15, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x5540
incq %r12
cmpq 0x50(%r14), %r12
jb 0x8822
movslq 0x20(%r14), %rax
cmpq %rax, %r13
jl 0x87c6
cmpq $0x0, 0x50(%r14)
je 0x8b02
leaq 0x6093(%rip), %r12      # 0xe8fb
xorl %ebx, %ebx
xorl %r13d, %r13d
movq 0xa8(%r14), %rax
testq %rax, %rax
je 0x88a6
xorl %ebp, %ebp
imulq %rbx, %rax
addq 0xa0(%r14), %rax
movq (%rax,%rbp,8), %rdx
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x5540
incq %rbp
movq 0xa8(%r14), %rax
cmpq %rax, %rbp
jb 0x887b
movl $0xa, %edi
movq %r15, %rsi
callq 0x5480
incq %r13
addq $0x8, %rbx
cmpq 0x50(%r14), %r13
jb 0x886d
jmp 0x8b02
cmpl $0x0, 0x20(%r14)
jle 0x8b02
leaq 0x58(%r14), %rax
movq %rax, 0x58(%rsp)
movl $0x1, %r13d
xorl %r12d, %r12d
leaq 0x6157(%rip), %rdx      # 0xea40
movl $0x1, %esi
movq %r14, (%rsp)
movq %r15, 0x38(%rsp)
movq %rsi, %rbx
movq %rdx, %r15
movq %r12, 0x8(%rsp)
incq %r12
movl %r12d, 0x44(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x44(%rsp), %rsi
callq 0x53d0
cmpl $0x1, (%rax)
movq 0x38(%r14), %rax
jne 0x8a22
testq %rax, %rax
movq %rbx, %rsi
cmovneq %rax, %rsi
movq 0x40(%r14), %rax
testq %rax, %rax
cmovneq %rax, %r13
movq %r13, 0x48(%rsp)
testq %r13, %r13
movq %r15, %rdx
je 0x8aeb
movq %r12, 0x28(%rsp)
leaq (,%rsi,8), %rax
movq %rax, 0x60(%rsp)
movq $0x0, 0x10(%rsp)
xorl %ecx, %ecx
movq %rsi, 0x18(%rsp)
movq %rcx, 0x30(%rsp)
testq %rsi, %rsi
je 0x89ed
movq (%rsp), %rax
movq 0x30(%rax), %rax
movq 0x10(%rsp), %r12
xorl %ecx, %ecx
movq %rcx, 0x20(%rsp)
testq %rax, %rax
je 0x89d5
xorl %r13d, %r13d
movq 0x38(%rsp), %rbx
movq 0x8(%rsp), %r14
movq (%rsp), %rbp
movq 0x88(%rbp), %rcx
imulq %r12, %rax
addq (%rcx,%r14,8), %rax
movsd (%rax,%r13,8), %xmm0
movq %rbx, %rdi
movq %r15, %rsi
movb $0x1, %al
callq 0x5540
movq %r15, %rdx
incq %r13
movq 0x30(%rbp), %rax
cmpq %rax, %r13
jb 0x89a2
jmp 0x89d7
xorl %eax, %eax
movq 0x20(%rsp), %rcx
incq %rcx
addq $0x8, %r12
movq 0x18(%rsp), %rsi
cmpq %rsi, %rcx
jne 0x8987
movq 0x30(%rsp), %rcx
incq %rcx
movq 0x10(%rsp), %rax
addq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq 0x48(%rsp), %rcx
jne 0x896e
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %r12
movq (%rsp), %r14
jmp 0x8aed
subq $0x1, %rax
movq %rbx, %rsi
cmovaeq %rax, %rsi
movq 0x30(%r14), %rax
movq 0x40(%r14), %rdi
subq $0x1, %rdi
cmovbq %r13, %rdi
cmpq $0x1, %rax
movq %r15, %rdx
je 0x8aed
movq %r12, 0x28(%rsp)
xorl %r8d, %r8d
movq %rdi, 0x18(%rsp)
testq %rsi, %rsi
je 0x8ad4
xorl %ebp, %ebp
movq %rbp, 0x20(%rsp)
movq %rdi, %r13
testq %rdi, %rdi
movq (%rsp), %rbx
je 0x8aba
movq 0x30(%rbx), %rax
movq 0x88(%rbx), %rcx
decq %rax
imulq %rbp, %rax
shlq $0x3, %rax
movq 0x8(%rsp), %rdx
addq (%rcx,%rdx,8), %rax
movsd (%rax,%r8,8), %xmm0
movq 0x38(%rsp), %rdi
movq %rsi, %r12
movq %r15, %rsi
movb $0x1, %al
movq %r8, %r14
callq 0x5540
movq %r14, %r8
movq %r12, %rsi
movq %r15, %rdx
addq %r12, %rbp
decq %r13
jne 0x8a6f
movq 0x20(%rsp), %rbp
incq %rbp
cmpq %rsi, %rbp
movq 0x18(%rsp), %rdi
jne 0x8a5e
movq (%rsp), %r14
movq 0x30(%r14), %rax
incq %r8
leaq -0x1(%rax), %rcx
cmpq %rcx, %r8
jb 0x8a57
movq 0x28(%rsp), %r12
jmp 0x8aed
xorl %edi, %edi
movslq 0x20(%r14), %rax
movq %rdi, %r13
cmpq %rax, %r12
movq 0x38(%rsp), %r15
jl 0x88f7
movq %r15, %rdi
callq 0x5400
movq %r15, %rdi
callq 0x5360
leaq 0x5f32(%rip), %rdi      # 0xea4b
xorl %ebp, %ebp
movq 0x50(%rsp), %rsi
xorl %eax, %eax
callq 0x5060
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq