# How to open .dlb extension file in Julia?

**URL:** <https://discourse.julialang.org/t/how-to-open-dlb-extension-file-in-julia/111644>\
**Category:** Data\
**Tags:** question\
**Created:** [March 15, 2024, 5:41am UTC](https://discourse.julialang.org/t/how-to-open-dlb-extension-file-in-julia/111644 "2024-03-15T05:41:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [March 15, 2024, 5:41am UTC](https://discourse.julialang.org/t/how-to-open-dlb-extension-file-in-julia/111644/1 "2024-03-15T05:41:06Z")

</div>

Hi , I want to open .dlb extension file using Julia and extract some data on it. I have .dlb file in my laptop. This data.6000.dlb file is in [this tar](https://drive.google.com/file/d/1IHs9rkQI8hBm77NxzexTePWla5R7iqGW/view?usp=sharing). See Python code below 👇

```julia
def load_data(directory, N_r, N_theta, mu):
   """Loads data from .dbl files, returns numpy arrays."""
   # initialize arrays
   num_of_files = 0
   for file in glob.iglob(directory + "*.dbl"):
       num_of_files += 1
   print ("Number of files: %d" % num_of_files)
   # rho,vr,vtheta, vphi,br,btheta, bphi, prs, tracer
   var = np.zeros((9, num_of_files, N_r, N_theta))
   N_points = N_r * N_theta
   count = 0

   for file in sorted(glob.iglob(directory+'*.dbl')):
       f = open(file, 'rb')
       data = np.fromfile(file, dtype='d')

       for j in range(0, 9):
           temp = np.zeros(N_points)
           for i in range(0, N_points):
               temp[i] = data[i + j*N_points]
           temp = temp.reshape(N_theta, N_r).T
           var[j, count] = temp
           del temp
       count += 1
       f.close()

   # add dipole field to B field because PLUTO outputs change from dipole field
   #ccm100217--and multiply by np.sqrt(4.*np.pi) as PLUTO normalizes to it.
   for i in range(0, N_theta):
       var[4, :, :, i] += 2. * mu * np.cos(theta[i]) / (r*r*r)
       var[4, :, :, i] *= np.sqrt(4.0*np.pi)
       var[5, :, :, i] += mu * np.sin(theta[i]) / (r*r*r)
       var[5, :, :, i] *= np.sqrt(4.0*np.pi)

   return var[0],var[1],var[2],var[3],var[4],var[5],var[6],var[7],var[8]

```

I want to convert this Python code to Julia.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [March 15, 2024, 5:43am UTC](https://discourse.julialang.org/t/how-to-open-dlb-extension-file-in-julia/111644/2 "2024-03-15T05:43:50Z")

</div>

Where did you get the file from? Is there any specification of the file format? Which programs use this file format?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [March 15, 2024, 7:54am UTC](https://discourse.julialang.org/t/how-to-open-dlb-extension-file-in-julia/111644/3 "2024-03-15T07:54:31Z")

</div>

Thanks for adding the Python code.

But what do you want to get after reading the file? An array? Or a DataFrame? Or something else?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 15, 2024, 9:30am UTC](https://discourse.julialang.org/t/how-to-open-dlb-extension-file-in-julia/111644/4 "2024-03-15T09:30:59Z")

</div>

What have you tried? What isn’t working?

If your question is just “please rewrite this Python code in Julia for me” then ChatGPT might be a more appropriate venue then this forum?

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [March 15, 2024, 9:43am UTC](https://discourse.julialang.org/t/how-to-open-dlb-extension-file-in-julia/111644/5 "2024-03-15T09:43:40Z")

</div>

I don’t know what should be output. I get following error when i run code. I think output should be an array.

```julia
TypeError Traceback (most recent call last)
Cell In[22], line 37
     35 theta = np.arange(0, N_theta) * (np.pi/1.98) / N_theta
     36 print(load_data(directory, N_r, N_theta, mu))
---> 37 rho, v_r, v_theta, v_phi, B_r, B_theta, B_phi, prs, tracer = load_data(directory, N_r, N_theta, mu)
     40 print( 'N_r = %d' %(N_r))
     41 print( 'N_theta = %d' %(N_theta))

TypeError: cannot unpack non-iterable NoneType object

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 15, 2024, 12:22pm UTC](https://discourse.julialang.org/t/how-to-open-dlb-extension-file-in-julia/111644/6 "2024-03-15T12:22:29Z")

</div>

So you’re saying the Python code isn’t working?

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [March 15, 2024, 2:04pm UTC](https://discourse.julialang.org/t/how-to-open-dlb-extension-file-in-julia/111644/7 "2024-03-15T14:04:18Z")

</div>

No, Code in mc\_2zoom\_rhov\_halfpi.py is working fine. But when i run it separate cells in jupyter then it shows error. You can download code given in [VelocPythJul.tar.gz - Google Drive](https://drive.google.com/file/d/1IHs9rkQI8hBm77NxzexTePWla5R7iqGW/view?usp=sharing) and change directory variable in code accordingly.
