

The plot above was created with the following code. For example, C=DCINDGEN(100) will create a 100-element, complex, double-precision, floating-point array with the values. Each element of the array has its real part set to the value of its one-dimensional subscript. This might not be the easiest or best way to do it, but I think it will at least get you started.The DCINDGEN function creates a complex, double-precision, floating-point array with the specified dimensions. Then you may also do whatever you wish in the loop with your other variables, and you should be able to index um and vm like you are used to in IDL or Fortran. Vm = np.transpose(np.reshape(tmpv, vm.shape)) Um = np.transpose(np.reshape(tmpu, um.shape)) Tmpv = np.fromfile(f, dtype='float32', count=vm.size)

Tmpu = np.fromfile(f, dtype='float32', count=um.size) # These arrays will be flat Recl = np.fromfile(f, dtype='uint32', count=1) Vm=np.empty((34,17), dtype='float32') # Also watch out, I believe the default type is float64 Um=np.empty((34,17), dtype='float32') # Make these dimensions "backwards" for easier reshaping
Idl findgen code#
I think the following code will do approximately what you want, for brevity I just included your um and vm variables: import numpy as np When you read the same thing into a 2D Python variable, it will be the last dimension - keep that in mind when reshaping a flat array, and you'll have to transpose it if you want to keep your indexing. A Fortran 2D array, for example, will write in memory with the first array dimension as the fastest iterating. This matters because Fortran sequential access adds 'record markers' to the file for every call to WRITE(), so you'll have to account for that in your Python read routine, much as in the answer that george linked in the comments.Īs to row/column order, it really just matters which dimension is iterating the fastest in memory. I do know IDL and the read command you have set up in your example is consistent with sequential access. I know there is an issue with the row/column order between IDL and Python but I think I can fix this once I read the code in.įirst off, I have to assume that you wrote the original Fortran file using sequential access rather than direct access, this is a very important distinction. #n.savez(filename=outputsavefile,u=u,v=v,w=w,temp=temp,pressure=pressure,ozone=ozone,date=date,ulevels2=ulevels2,ulevels3=ulevels3,lab=lab,lat=lat,ht=ht) This is where I need some assitance: f=open(inputfile,'rb') Outputsavefile='~cwilliams/metr51/lab12/qbo_FULLX.sav'# name of save file with variables Inputfile='/home/cwilliams/metr51/lab12/uvwtom.dat'# binary file from fortran #create save file for QBO model output #. Save,filename=outputsavefile,u,v,w,temp,pressure,ozone,date,ulevels2,ulevels3,lab,$ Openr,37,inputfile+fname,/f77_unformatted & title='base' Outputsavefile='~cwilliams/Metr_205/qbo/qbo_FULLX.sav' name of save file with variables Inputfile='/home/cwilliams/Metr_205/qbo/uvwtom.' binary file from fortran IDL Code: create save file for QBO model output npz file and I am having trouble on the read line. sav file but I want to convert this script to python and save as an. I have a script in IDL which reads an unformatted binary file (F77) and outputs it as a.
