// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
testq %rsi, %rsi
je 0x865c
movq %rsi, %rbx
movq %rdi, %r14
movl 0x8(%rdi), %esi
cmpl $0x3, %esi
jne 0x8672
leaq 0x641a(%rip), %rdi      # 0xe88c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x5060
leaq 0x6427(%rip), %rsi      # 0xe8aa
movq %rbx, %rdi
callq 0x5420
testq %rax, %rax
je 0x868a
movq %rax, %r15
movq %rbx, 0x48(%rsp)
leaq 0x6409(%rip), %rdi      # 0xe8ac
movl $0xc, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x56f0
cmpl $0x0, 0x20(%r14)
jle 0x850e
leaq 0x63f6(%rip), %r12      # 0xe8b9
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 0x84ef
movq (%rax,%rbx), %rdx
jmp 0x84f1
xorl %edx, %edx
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x5550
incq %r13
movslq 0x20(%r14), %rax
addq $0x20, %rbx
cmpq %rax, %r13
jl 0x84c8
movl $0xa, %edi
movq %r15, %rsi
callq 0x5490
leaq 0x639d(%rip), %rdi      # 0xe8bf
movl $0x5, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x56f0
movq 0x100(%r14), %r12
leaq 0xf0(%r14), %rbp
cmpq %rbp, %r12
je 0x8594
leaq 0x6377(%rip), %r13      # 0xe8c5
movq 0x20(%r12), %rbx
movq %rbx, %rdi
callq 0x5150
cmpq $0x1, %rax
jne 0x8584
cmpb $0x54, (%rbx)
jne 0x8584
movq 0x40(%r12), %rdx
cmpb $0x22, (%rdx)
movq %r13, %rsi
je 0x857a
leaq 0x6352(%rip), %rsi      # 0xe8cc
movq %r15, %rdi
xorl %eax, %eax
callq 0x5550
movq %r12, %rdi
callq 0x5200
movq %rax, %r12
cmpq %rbp, %rax
jne 0x854e
cmpl $0x0, 0x18(%r14)
je 0x86a0
movq 0x48(%r14), %rdx
testq %rdx, %rdx
je 0x85b9
leaq 0x633e(%rip), %rsi      # 0xe8ed
movq %r15, %rdi
xorl %eax, %eax
callq 0x5550
movq 0x50(%r14), %rdx
testq %rdx, %rdx
je 0x85d3
leaq 0x6330(%rip), %rsi      # 0xe8f9
movq %r15, %rdi
xorl %eax, %eax
callq 0x5550
cmpl $0x2, 0x18(%r14)
jne 0x85f3
leaq 0x6327(%rip), %rdi      # 0xe908
movl $0x15, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x56f0
cmpl $0x3, 0x18(%r14)
jne 0x8613
leaq 0x631d(%rip), %rdi      # 0xe91e
movl $0x1a, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x56f0
cmpl $0x5, 0x18(%r14)
jne 0x8633
leaq 0x6318(%rip), %rdi      # 0xe939
movl $0x18, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x56f0
cmpl $0x6, 0x18(%r14)
jne 0x86ee
leaq 0x630d(%rip), %rdi      # 0xe952
movl $0x12, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x56f0
jmp 0x86ee
leaq 0x6f40(%rip), %rdi      # 0xf5a3
callq 0x5580
movl $0x1, %ebp
jmp 0x8c36
leaq 0x61ef(%rip), %rdi      # 0xe868
xorl %eax, %eax
callq 0x5060
movl $0x2, %ebp
jmp 0x8c36
leaq 0x6eee(%rip), %rdi      # 0xf57f
callq 0x5580
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x8c36
movq 0x30(%r14), %rdx
testq %rdx, %rdx
je 0x86ba
leaq 0x6225(%rip), %rsi      # 0xe8d5
movq %r15, %rdi
xorl %eax, %eax
callq 0x5550
movq 0x38(%r14), %rdx
testq %rdx, %rdx
je 0x86d4
leaq 0x6213(%rip), %rsi      # 0xe8dd
movq %r15, %rdi
xorl %eax, %eax
callq 0x5550
movq 0x40(%r14), %rdx
testq %rdx, %rdx
je 0x86ee
leaq 0x6201(%rip), %rsi      # 0xe8e5
movq %r15, %rdi
xorl %eax, %eax
callq 0x5550
cmpl $0x1, 0x1c(%r14)
leaq 0x626b(%rip), %rax      # 0xe965
leaq 0x6279(%rip), %rdi      # 0xe97a
cmoveq %rax, %rdi
movl $0x14, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x56f0
movq 0x100(%r14), %r12
cmpq %rbp, %r12
je 0x8777
leaq 0x5aff(%rip), %r13      # 0xe229
movq 0x20(%r12), %rbx
movq %rbx, %rdi
callq 0x5150
cmpq $0xb, %rax
jne 0x8767
movl $0xb, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5160
testl %eax, %eax
jne 0x8767
movq 0x40(%r12), %rdx
movq %r15, %rdi
leaq 0x622f(%rip), %rsi      # 0xe98f
xorl %eax, %eax
callq 0x5550
movq %r12, %rdi
callq 0x5200
movq %rax, %r12
cmpq %rbp, %rax
jne 0x872a
movl $0xa, %edi
movq %r15, %rsi
callq 0x5490
cmpl $0x0, 0x18(%r14)
movl 0x1c(%r14), %eax
je 0x8808
cmpl $0x1, %eax
jne 0x88f7
cmpq $0x0, 0x48(%r14)
je 0x89a5
xorl %ebx, %ebx
leaq 0x61f3(%rip), %r12      # 0xe99f
leaq 0x5eff(%rip), %r13      # 0xe6b2
cmpl $0x0, 0x20(%r14)
jle 0x87e5
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 0x5550
incq %rbp
movslq 0x20(%r14), %rax
cmpq %rax, %rbp
jl 0x87bc
movl $0x2, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %r15, %rcx
callq 0x56f0
incq %rbx
cmpq 0x48(%r14), %rbx
jb 0x87b3
jmp 0x89a5
cmpl $0x1, %eax
jne 0x8a14
movq 0x38(%r14), %rax
movq 0x40(%r14), %rcx
cmpq $0x1, %rax
adcq $0x0, %rax
movq %rax, (%rsp)
cmpq $0x1, %rcx
adcq $0x0, %rcx
movq %rcx, 0x20(%rsp)
xorl %eax, %eax
leaq 0x6164(%rip), %r12      # 0xe99f
movq %rax, 0x28(%rsp)
imulq (%rsp), %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x30(%r14), %r13
testq %r13, %r13
je 0x88c8
movq 0x30(%rsp), %rax
movq 0x8(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
xorl %ebx, %ebx
cmpl $0x0, 0x20(%r14)
jle 0x88af
imulq 0x10(%rsp), %r13
shlq $0x3, %r13
xorl %ebp, %ebp
movq 0x88(%r14), %rax
movq (%rax,%rbp,8), %rax
addq %r13, %rax
movsd (%rax,%rbx,8), %xmm0
movq %r15, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x5550
incq %rbp
movslq 0x20(%r14), %rax
cmpq %rax, %rbp
jl 0x8883
movl $0xa, %edi
movq %r15, %rsi
callq 0x5490
incq %rbx
movq 0x30(%r14), %r13
cmpq %r13, %rbx
jb 0x8870
movq 0x8(%rsp), %rcx
incq %rcx
movq %rcx, 0x8(%rsp)
cmpq (%rsp), %rcx
jne 0x8853
movq 0x28(%rsp), %rax
incq %rax
cmpq 0x20(%rsp), %rax
jne 0x883b
jmp 0x8c11
cmpl $0x0, 0x20(%r14)
jle 0x89a5
leaq 0x58(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %r13d, %r13d
leaq 0x6093(%rip), %rbp      # 0xe9a8
movq %r13, %rbx
incq %r13
movl %r13d, 0x38(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x53e0
cmpl $0x1, (%rax)
jne 0x8967
cmpq $0x0, 0x48(%r14)
je 0x8998
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 0x5550
incq %r12
cmpq 0x48(%r14), %r12
jb 0x893e
jmp 0x8998
cmpq $0x0, 0x50(%r14)
je 0x8998
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 0x5550
incq %r12
cmpq 0x50(%r14), %r12
jb 0x8971
movslq 0x20(%r14), %rax
cmpq %rax, %r13
jl 0x8915
cmpq $0x0, 0x50(%r14)
je 0x8c11
leaq 0x5eac(%rip), %r12      # 0xe863
xorl %ebx, %ebx
xorl %r13d, %r13d
movq 0xa8(%r14), %rax
testq %rax, %rax
je 0x89f5
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 0x5550
incq %rbp
movq 0xa8(%r14), %rax
cmpq %rax, %rbp
jb 0x89ca
movl $0xa, %edi
movq %r15, %rsi
callq 0x5490
incq %r13
addq $0x8, %rbx
cmpq 0x50(%r14), %r13
jb 0x89bc
jmp 0x8c11
cmpl $0x0, 0x20(%r14)
jle 0x8c11
leaq 0x58(%r14), %rax
movq %rax, 0x50(%rsp)
movl $0x1, %r13d
xorl %r12d, %r12d
movl $0x1, %ebp
movq %r15, 0x40(%rsp)
movq %r12, %rbx
incq %r12
movl %r12d, 0x3c(%rsp)
movq 0x50(%rsp), %rdi
leaq 0x3c(%rsp), %rsi
callq 0x53e0
cmpl $0x1, (%rax)
jne 0x8b40
movq 0x38(%r14), %rax
movq 0x40(%r14), %rcx
testq %rax, %rax
cmovneq %rax, %rbp
testq %rcx, %rcx
cmovneq %rcx, %r13
testq %r13, %r13
je 0x8bf8
movq %r12, 0x18(%rsp)
leaq (,%rbp,8), %rax
movq %rax, 0x20(%rsp)
movq $0x0, (%rsp)
xorl %ecx, %ecx
movq %r13, 0x28(%rsp)
movq %rbp, 0x8(%rsp)
movq %rcx, 0x30(%rsp)
testq %rbp, %rbp
je 0x8b0d
movq (%rsp), %r13
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq 0x30(%r14), %rax
testq %rax, %rax
leaq 0x5ee2(%rip), %r12      # 0xe9a8
je 0x8af7
xorl %ebp, %ebp
movq 0x88(%r14), %rcx
imulq %r13, %rax
addq (%rcx,%rbx,8), %rax
movsd (%rax,%rbp,8), %xmm0
movq %r15, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x5550
incq %rbp
movq 0x30(%r14), %rax
cmpq %rax, %rbp
jb 0x8aca
movq 0x10(%rsp), %rax
incq %rax
addq $0x8, %r13
movq 0x8(%rsp), %rbp
cmpq %rbp, %rax
jne 0x8ab3
movq 0x30(%rsp), %rcx
incq %rcx
movq (%rsp), %rax
addq 0x20(%rsp), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %r13
cmpq %r13, %rcx
jne 0x8aa3
movq %rbp, %rcx
movq %r13, %rdx
movq 0x18(%rsp), %r12
jmp 0x8bfe
movq 0x38(%r14), %rcx
subq $0x1, %rcx
cmovbq %rbp, %rcx
movq 0x40(%r14), %rdx
subq $0x1, %rdx
cmovbq %r13, %rdx
cmpq $0x1, 0x30(%r14)
je 0x8bfe
movq %rbx, 0x8(%rsp)
movq %r12, 0x18(%rsp)
xorl %ebx, %ebx
movq %rdx, (%rsp)
testq %rcx, %rcx
je 0x8bdd
xorl %ebp, %ebp
movq %rbp, 0x10(%rsp)
movq %rdx, %r13
testq %rdx, %rdx
movq 0x8(%rsp), %r12
je 0x8bcc
movq 0x30(%r14), %rax
movq %rcx, %r15
movq 0x88(%r14), %rcx
decq %rax
imulq %rbp, %rax
shlq $0x3, %rax
addq (%rcx,%r12,8), %rax
movsd (%rax,%rbx,8), %xmm0
movq 0x40(%rsp), %rdi
leaq 0x5dee(%rip), %rsi      # 0xe9a8
movb $0x1, %al
callq 0x5550
movq %r15, %rcx
addq %r15, %rbp
decq %r13
jne 0x8b8c
movq 0x10(%rsp), %rbp
incq %rbp
cmpq %rcx, %rbp
movq (%rsp), %rdx
jne 0x8b7a
incq %rbx
movq 0x30(%r14), %rax
decq %rax
cmpq %rax, %rbx
jb 0x8b73
movq 0x18(%rsp), %r12
movq 0x40(%rsp), %r15
jmp 0x8bfe
movq %rbp, %rcx
movq %r13, %rdx
movslq 0x20(%r14), %rax
movq %rdx, %r13
movq %rcx, %rbp
cmpq %rax, %r12
jl 0x8a3b
movq %r15, %rdi
callq 0x5410
movq %r15, %rdi
callq 0x5370
leaq 0x5d8b(%rip), %rdi      # 0xe9b3
xorl %ebp, %ebp
movq 0x48(%rsp), %rsi
xorl %eax, %eax
callq 0x5060
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop