// File: tlestang[P]IW_gene/write_vtk.cpp
// Function: write_fluid_vtk(int, int, int, double**, double***, char const*)
void write_fluid_vtk(int time, int Dx, int Dy, double **T, double ***u, const char* folderName)
// Writes the normalized velocities u and v. (u/Uref and v/Uref)
{

  /// Create filename
  stringstream fileName;

  fileName << "fluid_t" << time << ".vtk";

  string output_filename = string(folderName) + "/vtk_fluid/" + fileName.str();

  ofstream output_file;
  double rho0 = 1.0; double u0 = 0.01;

  /// Open file
  output_file.open(output_filename.c_str());

  /// Write VTK header
  output_file << "# vtk DataFile Version 3.0\n";
  output_file << "fluid_state\n";
  output_file << "ASCII\n";
  output_file << "DATASET RECTILINEAR_GRID\n";
  output_file << "DIMENSIONS " << Dx << " " << Dy << " 1" << "\n";
  output_file << "X_COORDINATES " << Dx << " float\n";
  for(int i = 0; i < Dx; ++i)
    output_file << i << " ";
  output_file << "\n";
  output_file << "Y_COORDINATES " << Dy  << " float\n";
  for(int j = 0; j < Dy ; ++j)
    output_file << j  << " ";
  output_file << "\n";
  output_file << "Z_COORDINATES " << 1 << " float\n";
  output_file << 0 << "\n";
  output_file << "POINT_DATA " << (Dx) * (Dy) << "\n";

  /// Write density difference
  output_file << "SCALARS temperature float 1\n";
  output_file << "LOOKUP_TABLE default\n";
  for(int Y =0; Y < Dy ; ++Y)
    for(int X = 0; X < Dx; ++X)
      output_file <<  T[X][Y] << "\n";

  /// Write velocity
  output_file << "VECTORS velocity_vector float\n";
  for(int Y = 0; Y < Dy ; ++Y)
    for(int X = 0; X < Dx; ++X)
      output_file << u[X][Y][0] -u0 << " " << u[X][Y][1] << " 0\n";

  /// Close file
  output_file.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x530, %rsp            # imm = 0x530
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x3170
leaq -0x1a0(%rbp), %rdi
leaq 0x230e(%rip), %rsi      # 0x9258
callq 0x3210
movq %rax, -0x478(%rbp)
jmp 0x6f58
movq -0x478(%rbp), %rdi
movl -0x4(%rbp), %esi
callq 0x3370
movq %rax, -0x480(%rbp)
jmp 0x6f70
movq -0x480(%rbp), %rdi
leaq 0x22e2(%rip), %rsi      # 0x9260
callq 0x3210
jmp 0x6f85
movq -0x28(%rbp), %rax
movq %rax, -0x490(%rbp)
leaq -0x221(%rbp), %rdi
movq %rdi, -0x488(%rbp)
callq 0x3390
movq -0x490(%rbp), %rsi
movq -0x488(%rbp), %rdx
leaq -0x220(%rbp), %rdi
callq 0x77f0
jmp 0x6fbf
leaq 0x229f(%rip), %rdx      # 0x9265
leaq -0x200(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x77a0
jmp 0x6fdb
leaq -0x248(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x3200
jmp 0x6ff0
leaq -0x1e0(%rbp), %rdi
leaq -0x200(%rbp), %rsi
leaq -0x248(%rbp), %rdx
callq 0x76d0
jmp 0x700c
leaq -0x248(%rbp), %rdi
callq 0x3140
leaq -0x200(%rbp), %rdi
callq 0x3140
leaq -0x220(%rbp), %rdi
callq 0x3140
leaq -0x221(%rbp), %rdi
callq 0x3260
leaq -0x448(%rbp), %rdi
callq 0x3350
jmp 0x704a
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, -0x450(%rbp)
movabsq $0x3f847ae147ae147b, %rax # imm = 0x3F847AE147AE147B
movq %rax, -0x458(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x30e0
movq %rax, %rsi
leaq -0x448(%rbp), %rdi
movl $0x10, %edx
callq 0x3050
jmp 0x708e
leaq 0x21dc(%rip), %rsi      # 0x9271
leaq -0x448(%rbp), %rdi
callq 0x3210
jmp 0x70a3
leaq 0x21e3(%rip), %rsi      # 0x928d
leaq -0x448(%rbp), %rdi
callq 0x3210
jmp 0x70b8
leaq 0x21db(%rip), %rsi      # 0x929a
leaq -0x448(%rbp), %rdi
callq 0x3210
jmp 0x70cd
leaq 0x21cd(%rip), %rsi      # 0x92a1
leaq -0x448(%rbp), %rdi
callq 0x3210
jmp 0x70e2
leaq 0x21d2(%rip), %rsi      # 0x92bb
leaq -0x448(%rbp), %rdi
callq 0x3210
movq %rax, -0x498(%rbp)
jmp 0x70fe
movq -0x498(%rbp), %rdi
movl -0x8(%rbp), %esi
callq 0x3370
movq %rax, -0x4a0(%rbp)
jmp 0x7116
movq -0x4a0(%rbp), %rdi
leaq 0x2331(%rip), %rsi      # 0x9455
callq 0x3210
movq %rax, -0x4a8(%rbp)
jmp 0x7132
movq -0x4a8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x3370
movq %rax, -0x4b0(%rbp)
jmp 0x714a
movq -0x4b0(%rbp), %rdi
leaq 0x216f(%rip), %rsi      # 0x92c7
callq 0x3210
movq %rax, -0x4b8(%rbp)
jmp 0x7166
movq -0x4b8(%rbp), %rdi
leaq 0x21e3(%rip), %rsi      # 0x9357
callq 0x3210
jmp 0x717b
leaq 0x2148(%rip), %rsi      # 0x92ca
leaq -0x448(%rbp), %rdi
callq 0x3210
movq %rax, -0x4c0(%rbp)
jmp 0x7197
movq -0x4c0(%rbp), %rdi
movl -0x8(%rbp), %esi
callq 0x3370
movq %rax, -0x4c8(%rbp)
jmp 0x71af
movq -0x4c8(%rbp), %rdi
leaq 0x2190(%rip), %rsi      # 0x934d
callq 0x3210
jmp 0x71c4
movl $0x0, -0x45c(%rbp)
movl -0x45c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x72f4
movl -0x45c(%rbp), %esi
leaq -0x448(%rbp), %rdi
callq 0x3370
movq %rax, -0x4d0(%rbp)
jmp 0x71f8
movq -0x4d0(%rbp), %rdi
leaq 0x224f(%rip), %rsi      # 0x9455
callq 0x3210
jmp 0x720d
jmp 0x720f
movl -0x45c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x45c(%rbp)
jmp 0x71ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b8(%rbp)
movl %eax, -0x1bc(%rbp)
jmp 0x76a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b8(%rbp)
movl %eax, -0x1bc(%rbp)
jmp 0x72a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b8(%rbp)
movl %eax, -0x1bc(%rbp)
jmp 0x729d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b8(%rbp)
movl %eax, -0x1bc(%rbp)
jmp 0x7291
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b8(%rbp)
movl %eax, -0x1bc(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x3140
leaq -0x200(%rbp), %rdi
callq 0x3140
leaq -0x220(%rbp), %rdi
callq 0x3140
leaq -0x221(%rbp), %rdi
callq 0x3260
jmp 0x76a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b8(%rbp)
movl %eax, -0x1bc(%rbp)
jmp 0x769d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b8(%rbp)
movl %eax, -0x1bc(%rbp)
leaq -0x448(%rbp), %rdi
callq 0x32e0
jmp 0x769d
leaq 0x205c(%rip), %rsi      # 0x9357
leaq -0x448(%rbp), %rdi
callq 0x3210
jmp 0x7309
leaq 0x1fc9(%rip), %rsi      # 0x92d9
leaq -0x448(%rbp), %rdi
callq 0x3210
movq %rax, -0x4d8(%rbp)
jmp 0x7325
movq -0x4d8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x3370
movq %rax, -0x4e0(%rbp)
jmp 0x733d
movq -0x4e0(%rbp), %rdi
leaq 0x2002(%rip), %rsi      # 0x934d
callq 0x3210
jmp 0x7352
movl $0x0, -0x460(%rbp)
movl -0x460(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x73aa
movl -0x460(%rbp), %esi
leaq -0x448(%rbp), %rdi
callq 0x3370
movq %rax, -0x4e8(%rbp)
jmp 0x7382
movq -0x4e8(%rbp), %rdi
leaq 0x20c5(%rip), %rsi      # 0x9455
callq 0x3210
jmp 0x7397
jmp 0x7399
movl -0x460(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x460(%rbp)
jmp 0x735c
leaq 0x1fa6(%rip), %rsi      # 0x9357
leaq -0x448(%rbp), %rdi
callq 0x3210
jmp 0x73bf
leaq 0x1f22(%rip), %rsi      # 0x92e8
leaq -0x448(%rbp), %rdi
callq 0x3210
movq %rax, -0x4f0(%rbp)
jmp 0x73db
movq -0x4f0(%rbp), %rdi
movl $0x1, %esi
callq 0x3370
movq %rax, -0x4f8(%rbp)
jmp 0x73f5
movq -0x4f8(%rbp), %rdi
leaq 0x1f4a(%rip), %rsi      # 0x934d
callq 0x3210
jmp 0x740a
leaq -0x448(%rbp), %rdi
xorl %esi, %esi
callq 0x3370
movq %rax, -0x500(%rbp)
jmp 0x7421
movq -0x500(%rbp), %rdi
leaq 0x1f28(%rip), %rsi      # 0x9357
callq 0x3210
jmp 0x7436
leaq 0x1eba(%rip), %rsi      # 0x92f7
leaq -0x448(%rbp), %rdi
callq 0x3210
movq %rax, -0x508(%rbp)
jmp 0x7452
movq -0x508(%rbp), %rdi
movl -0x8(%rbp), %esi
movl -0xc(%rbp), %eax
imull %eax, %esi
callq 0x3370
movq %rax, -0x510(%rbp)
jmp 0x7470
movq -0x510(%rbp), %rdi
leaq 0x1ed9(%rip), %rsi      # 0x9357
callq 0x3210
jmp 0x7485
leaq 0x1e77(%rip), %rsi      # 0x9303
leaq -0x448(%rbp), %rdi
callq 0x3210
jmp 0x749a
leaq 0x1e7f(%rip), %rsi      # 0x9320
leaq -0x448(%rbp), %rdi
callq 0x3210
jmp 0x74af
movl $0x0, -0x464(%rbp)
movl -0x464(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x754b
movl $0x0, -0x468(%rbp)
movl -0x468(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x7535
movq -0x18(%rbp), %rax
movslq -0x468(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x464(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq -0x448(%rbp), %rdi
callq 0x33e0
movq %rax, -0x518(%rbp)
jmp 0x750d
movq -0x518(%rbp), %rdi
leaq 0x1e3c(%rip), %rsi      # 0x9357
callq 0x3210
jmp 0x7522
jmp 0x7524
movl -0x468(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x468(%rbp)
jmp 0x74d2
jmp 0x7537
movl -0x464(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
jmp 0x74b9
leaq 0x1de4(%rip), %rsi      # 0x9336
leaq -0x448(%rbp), %rdi
callq 0x3210
jmp 0x7560
movl $0x0, -0x46c(%rbp)
movl -0x46c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x7662
movl $0x0, -0x470(%rbp)
movl -0x470(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x764c
movq -0x20(%rbp), %rax
movslq -0x470(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x46c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
movsd -0x458(%rbp), %xmm1
subsd %xmm1, %xmm0
leaq -0x448(%rbp), %rdi
callq 0x33e0
movq %rax, -0x520(%rbp)
jmp 0x75d1
movq -0x520(%rbp), %rdi
leaq 0x1e76(%rip), %rsi      # 0x9455
callq 0x3210
movq %rax, -0x528(%rbp)
jmp 0x75ed
movq -0x528(%rbp), %rdi
movq -0x20(%rbp), %rax
movslq -0x470(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x46c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd 0x8(%rax), %xmm0
callq 0x33e0
movq %rax, -0x530(%rbp)
jmp 0x7621
movq -0x530(%rbp), %rdi
leaq 0x1d26(%rip), %rsi      # 0x9355
callq 0x3210
jmp 0x7636
jmp 0x7638
movl -0x470(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x470(%rbp)
jmp 0x7583
jmp 0x764e
movl -0x46c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x46c(%rbp)
jmp 0x756a
leaq -0x448(%rbp), %rdi
callq 0x32c0
jmp 0x7670
leaq -0x448(%rbp), %rdi
callq 0x32e0
leaq -0x1e0(%rbp), %rdi
callq 0x3140
leaq -0x1b0(%rbp), %rdi
callq 0x3190
addq $0x530, %rsp            # imm = 0x530
popq %rbp
retq
leaq -0x1e0(%rbp), %rdi
callq 0x3140
leaq -0x1b0(%rbp), %rdi
callq 0x3190
movq -0x1b8(%rbp), %rdi
callq 0x3380
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)