// File: /workspace/github_cpp_makefile_star2_O2/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 0xa128
movq %rsi, %rbx
movq %rdi, %r14
movl 0x8(%rdi), %esi
cmpl $0x3, %esi
jne 0xa13b
leaq 0x586c(%rip), %rdi      # 0xf924
movq %rbx, %rsi
xorl %eax, %eax
callq 0x7060
leaq 0x5879(%rip), %rsi      # 0xf942
movq %rbx, %rdi
callq 0x75a0
testq %rax, %rax
je 0xa296
movq %rax, %r15
movq %rbx, 0x40(%rsp)
leaq 0x585b(%rip), %rdi      # 0xf944
pushq $0xc
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x79d0
leaq 0x5853(%rip), %rbx      # 0xf951
xorl %ebp, %ebp
cmpl 0x20(%r14), %ebp
jge 0xa150
movq 0xc8(%r14), %rdi
movl %ebp, %esi
callq 0x7080
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x7780
incl %ebp
jmp 0xa100
leaq 0x650c(%rip), %rdi      # 0x1063b
callq 0x77b0
pushq $0x1
jmp 0xa2a4
leaq 0x57be(%rip), %rdi      # 0xf900
xorl %eax, %eax
callq 0x7060
pushq $0x2
jmp 0xa2a4
pushq $0xa
popq %rdi
movq %r15, %rsi
callq 0x7640
leaq 0x57f5(%rip), %rdi      # 0xf957
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
movq %r15, (%rsp)
movq %r15, %rcx
callq 0x79d0
movq 0x100(%r14), %r12
leaq 0xf0(%r14), %rbp
leaq 0x57d4(%rip), %r13      # 0xf95d
leaq 0x57d4(%rip), %r15      # 0xf964
cmpq %rbp, %r12
je 0xa1d5
movq 0x20(%r12), %rbx
movq %rbx, %rdi
callq 0x71f0
cmpq $0x1, %rax
jne 0xa1c8
cmpb $0x54, (%rbx)
jne 0xa1c8
movq 0x40(%r12), %rdx
cmpb $0x22, (%rdx)
movq %r13, %rsi
je 0xa1bd
movq %r15, %rsi
movq (%rsp), %rdi
xorl %eax, %eax
callq 0x7780
movq %r12, %rdi
callq 0x72f0
movq %rax, %r12
jmp 0xa190
cmpl $0x0, 0x18(%r14)
je 0xa2b6
movq 0x48(%r14), %rdx
testq %rdx, %rdx
movq (%rsp), %r15
je 0xa1fe
leaq 0x5791(%rip), %rsi      # 0xf985
movq %r15, %rdi
xorl %eax, %eax
callq 0x7780
movq 0x50(%r14), %rdx
testq %rdx, %rdx
je 0xa218
leaq 0x5783(%rip), %rsi      # 0xf991
movq %r15, %rdi
xorl %eax, %eax
callq 0x7780
movl 0x18(%r14), %eax
cmpl $0x2, %eax
jne 0xa23a
leaq 0x5778(%rip), %rdi      # 0xf9a0
pushq $0x15
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x79d0
movl 0x18(%r14), %eax
cmpl $0x3, %eax
jne 0xa258
leaq 0x5770(%rip), %rdi      # 0xf9b6
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x79d0
movl 0x18(%r14), %eax
cmpl $0x5, %eax
jne 0xa276
leaq 0x576d(%rip), %rdi      # 0xf9d1
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x79d0
movl 0x18(%r14), %eax
cmpl $0x6, %eax
jne 0xa308
leaq 0x5764(%rip), %rdi      # 0xf9ea
pushq $0x12
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x79d0
jmp 0xa308
leaq 0x637a(%rip), %rdi      # 0x10617
callq 0x77b0
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%r14), %rdx
testq %rdx, %rdx
movq (%rsp), %r15
je 0xa2d4
leaq 0x56a3(%rip), %rsi      # 0xf96d
movq %r15, %rdi
xorl %eax, %eax
callq 0x7780
movq 0x38(%r14), %rdx
testq %rdx, %rdx
je 0xa2ee
leaq 0x5691(%rip), %rsi      # 0xf975
movq %r15, %rdi
xorl %eax, %eax
callq 0x7780
movq 0x40(%r14), %rdx
testq %rdx, %rdx
je 0xa308
leaq 0x567f(%rip), %rsi      # 0xf97d
movq %r15, %rdi
xorl %eax, %eax
callq 0x7780
cmpl $0x1, 0x1c(%r14)
leaq 0x56e9(%rip), %rax      # 0xf9fd
leaq 0x56f7(%rip), %rdi      # 0xfa12
cmoveq %rax, %rdi
pushq $0x14
popq %rsi
pushq $0x1
popq %rdx
movq %rdx, 0x8(%rsp)
movq %r15, %rcx
callq 0x79d0
movq 0x100(%r14), %rbx
leaq 0x4f81(%rip), %r12      # 0xf2c1
cmpq %rbp, %rbx
je 0xa38b
movq 0x20(%rbx), %r13
movq %r13, %rdi
callq 0x71f0
cmpq $0xb, %rax
jne 0xa37e
movq %r13, %rdi
movq %r12, %rsi
pushq $0xb
popq %rdx
callq 0x7210
testl %eax, %eax
jne 0xa37e
movq 0x40(%rbx), %rdx
movq %r15, %rdi
leaq 0x56b0(%rip), %rsi      # 0xfa27
xorl %eax, %eax
callq 0x7780
movq %rbx, %rdi
callq 0x72f0
movq %rax, %rbx
jmp 0xa340
pushq $0xa
popq %rdi
movq %r15, %rsi
callq 0x7640
cmpl $0x0, 0x18(%r14)
movl 0x1c(%r14), %eax
je 0xa410
cmpl $0x1, %eax
jne 0xa4e5
xorl %r12d, %r12d
leaq 0x5683(%rip), %rbx      # 0xfa37
pushq $0x2
popq %r13
pushq $0x1
popq %rbp
cmpq 0x48(%r14), %r12
jae 0xa578
xorl %r15d, %r15d
movslq 0x20(%r14), %rax
cmpq %rax, %r15
jge 0xa3f5
movq 0x88(%r14), %rax
movq (%rax,%r15,8), %rax
movsd (%rax,%r12,8), %xmm0
movq (%rsp), %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x7780
incq %r15
jmp 0xa3c8
leaq 0x534e(%rip), %rdi      # 0xf74a
movq %r13, %rsi
movq %rbp, %rdx
movq (%rsp), %rcx
callq 0x79d0
incq %r12
jmp 0xa3bb
cmpl $0x1, %eax
jne 0xa5d6
movq 0x38(%r14), %rax
cmpq $0x1, %rax
adcq $0x0, %rax
movq %rax, 0x18(%rsp)
movq 0x40(%r14), %rax
cmpq $0x1, %rax
adcq $0x0, %rax
movq %rax, 0x20(%rsp)
xorl %eax, %eax
leaq 0x55f3(%rip), %r12      # 0xfa37
cmpq 0x20(%rsp), %rax
je 0xa77b
movq %rax, %rcx
imulq 0x18(%rsp), %rcx
movq %rcx, 0x28(%rsp)
xorl %ecx, %ecx
movq %rax, 0x10(%rsp)
cmpq 0x18(%rsp), %rcx
je 0xa4dd
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rsp)
leaq (%rcx,%rax), %r13
xorl %ebx, %ebx
movq 0x30(%r14), %r15
cmpq %r15, %rbx
jae 0xa4ce
imulq %r13, %r15
shlq $0x3, %r15
xorl %ebp, %ebp
movslq 0x20(%r14), %rax
cmpq %rax, %rbp
jge 0xa4bd
movq 0x88(%r14), %rax
movq (%rax,%rbp,8), %rax
addq %r15, %rax
movsd (%rax,%rbx,8), %xmm0
movq (%rsp), %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x7780
incq %rbp
jmp 0xa48e
pushq $0xa
popq %rdi
movq (%rsp), %rsi
callq 0x7640
incq %rbx
jmp 0xa47b
movq 0x8(%rsp), %rcx
incq %rcx
movq 0x10(%rsp), %rax
jmp 0xa464
incq %rax
jmp 0xa444
leaq 0x58(%r14), %r12
xorl %ebx, %ebx
leaq 0x554e(%rip), %rbp      # 0xfa40
movslq 0x20(%r14), %rax
cmpq %rax, %rbx
jge 0xa578
leaq 0x1(%rbx), %r13
movl %r13d, 0x30(%rsp)
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
callq 0x7550
cmpl $0x1, (%rax)
jne 0xa543
xorl %r15d, %r15d
cmpq 0x48(%r14), %r15
jae 0xa570
movq 0x88(%r14), %rax
movq (%rax,%rbx,8), %rax
movsd (%rax,%r15,8), %xmm0
movq (%rsp), %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x7780
incq %r15
jmp 0xa519
xorl %r15d, %r15d
cmpq 0x50(%r14), %r15
jae 0xa570
movq 0x88(%r14), %rax
movq (%rax,%rbx,8), %rax
movsd (%rax,%r15,8), %xmm0
movq (%rsp), %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x7780
incq %r15
jmp 0xa546
movq %r13, %rbx
jmp 0xa4f2
leaq 0x537c(%rip), %r12      # 0xf8fb
pushq $0xa
popq %rbp
xorl %ebx, %ebx
xorl %r13d, %r13d
cmpq 0x50(%r14), %r13
jae 0xa77b
xorl %r15d, %r15d
movq 0xa8(%r14), %rax
cmpq %rax, %r15
jae 0xa5c2
imulq %rbx, %rax
addq 0xa0(%r14), %rax
movq (%rax,%r15,8), %rdx
movq (%rsp), %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x7780
incq %r15
jmp 0xa594
movl %ebp, %edi
movq (%rsp), %rsi
callq 0x7640
incq %r13
addq $0x8, %rbx
jmp 0xa587
leaq 0x58(%r14), %rax
movq %rax, 0x48(%rsp)
xorl %ebx, %ebx
leaq 0x5458(%rip), %rbp      # 0xfa40
pushq $0x1
popq %rax
movq %rax, 0x10(%rsp)
movslq 0x20(%r14), %rax
cmpq %rax, %rbx
jge 0xa77b
leaq 0x1(%rbx), %rax
movq %rax, 0x38(%rsp)
movl %eax, 0x34(%rsp)
movq 0x48(%rsp), %rdi
leaq 0x34(%rsp), %rsi
callq 0x7550
cmpl $0x1, (%rax)
movq 0x38(%r14), %rax
jne 0xa6da
testq %rax, %rax
movq 0x8(%rsp), %rcx
cmovneq %rax, %rcx
movq 0x40(%r14), %rax
testq %rax, %rax
movq 0x10(%rsp), %rdx
cmovneq %rax, %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
leaq (,%rcx,8), %rax
movq %rax, 0x50(%rsp)
xorl %r13d, %r13d
xorl %eax, %eax
movq (%rsp), %r12
cmpq 0x10(%rsp), %rax
je 0xa771
movq %r13, 0x20(%rsp)
xorl %ecx, %ecx
movq %rax, 0x28(%rsp)
cmpq 0x8(%rsp), %rcx
je 0xa6cb
movq %rcx, 0x18(%rsp)
xorl %r15d, %r15d
movq 0x30(%r14), %rax
cmpq %rax, %r15
jae 0xa6b8
movq 0x88(%r14), %rcx
imulq %r13, %rax
addq (%rcx,%rbx,8), %rax
movsd (%rax,%r15,8), %xmm0
movq %r12, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x7780
incq %r15
jmp 0xa688
movq 0x18(%rsp), %rcx
incq %rcx
addq $0x8, %r13
movq 0x28(%rsp), %rax
jmp 0xa679
incq %rax
movq 0x20(%rsp), %r13
addq 0x50(%rsp), %r13
jmp 0xa662
subq $0x1, %rax
movq 0x8(%rsp), %rcx
cmovaeq %rax, %rcx
movq %rcx, 0x8(%rsp)
movq 0x40(%r14), %rax
subq $0x1, %rax
movq 0x10(%rsp), %rcx
cmovaeq %rax, %rcx
movq %rcx, 0x10(%rsp)
xorl %r13d, %r13d
movq 0x30(%r14), %rax
decq %rax
cmpq %rax, %r13
jae 0xa771
xorl %eax, %eax
movq %rax, %r12
movq 0x10(%rsp), %r15
movq %rax, 0x18(%rsp)
cmpq 0x8(%rsp), %rax
je 0xa76c
subq $0x1, %r15
jb 0xa762
movq 0x30(%r14), %rax
movq 0x88(%r14), %rcx
decq %rax
imulq %r12, %rax
shlq $0x3, %rax
addq (%rcx,%rbx,8), %rax
movsd (%rax,%r13,8), %xmm0
movq (%rsp), %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x7780
addq 0x8(%rsp), %r12
jmp 0xa727
movq 0x18(%rsp), %rax
incq %rax
jmp 0xa713
incq %r13
jmp 0xa705
movq 0x38(%rsp), %rbx
jmp 0xa5f0
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x7590
movq %rbx, %rdi
callq 0x74c0
leaq 0x52b5(%rip), %rdi      # 0xfa4b
xorl %ebx, %ebx
movq 0x40(%rsp), %rsi
xorl %eax, %eax
callq 0x7060
jmp 0xa2a5
nop