|
[Sponsors] |
April 18, 2016, 04:38 |
Creating Binary File, Problems with Fortran
|
#1 |
Member
phil
Join Date: Oct 2013
Posts: 36
Rep Power: 13 |
Hey all,
i try to create my own simple Tecplot binary .plt files with my own Fortran Code. But i face some problems. First of all my Data is just simple ones like this below. Code:
Variables="xdir", "ydir", "zdir", "rel", "mass" 22.3356E-01 2.1550E-02 2.0000E+00 5.0000E+00 6.5505E-14 22.3356E-01 2.1550E-02 2.0000E+00 5.0000E+00 6.5505E-14 22.3356E-01 2.1550E-02 2.0000E+00 5.0111E+00 6.5505E-14 22.3356E-01 2.1550E-02 2.5000E+00 5.0111E+00 6.5505E-14 22.3356E-01 2.1550E-02 2.5000E+00 5.0111E+00 6.5505E-14 Hope you can give me a hint. Here is my Fortran Code as far. The data vector is just for writing and testint the code. Code:
program tecbinary c---- Deklaration implicit none integer*4 unitnum,FileType,NumVar,vardf,arraysize integer*4 enumi,enumj,enumk,enuml character*18 VarName(5),title,zonename real*4 datas(3) c---- Definition unitnum=99 FileType=0 c 0=full, 1=grid, 2=solution zonename='myzone' title='mytestdata' NumVar=5 VarName(1)='xdir' VarName(2)='ydir' VarName(3)='zdir' VarName(4)='rel' VarName(5)='mass' c Variable Data Format c 1 float, 2 double, 3 longint, 4 shortint, 5 byte, 6 bit vardf=1 c random test data to be written datas(1)=1 datas(2)=2 datas(3)=3 c####################################################################### c---- Open File open(unit=unitnum,file='mybinary.plt',form='unformatted', & access='stream') c---- HEADER Section c i Magic number, Version number write(unitnum) '#!TDV112' c ii Integer value of 1 write(unitnum) 1 c iii Type, Title, number of variables and variable names write(unitnum) FileType call converter(unitnum,title) write(unitnum) NumVar do enumi=1, NumVar call converter(unitnum,VarName(enumi)) end do c iv Zones write(unitnum) 299.0 c Variable Data Format call converter(unitnum,zonename) c---- EOHMARKER - Trennung Header zu Data write(unitnum) 357.0 c---- DATA Section c i Zones write(unitnum) 299.0 c Variable Data Format do enumj=1, NumVar write(unitnum) vardf end do c Has passive variables write(unitnum) 0 c Has variable sharing write(unitnum) 0 c Zero based zone number write(unitnum) -1 c---- ZONE DATA do enumk=1, NumVar arraysize=size(datas) do enuml=1, arraysize write(unitnum) datas(enuml) end do end do close(unitnum) end program tecbinary c####################################################################### c---- Subroutine ASCII to Integer subroutine converter(unitnum,inputstring) implicit none character*18 inputstring integer unitnum,i,letter,strlen strlen=len(inputstring) do i=1 ,strlen letter=ichar(inputstring(i:i)) write(unitnum) letter end do write(unitnum) 0 return end subroutine converter Greetings Last edited by gelbebanane; April 19, 2016 at 03:54. Reason: title |
|
April 20, 2016, 04:13 |
Solution
|
#2 |
Member
phil
Join Date: Oct 2013
Posts: 36
Rep Power: 13 |
Ok i solved my problem with "reverse engineering".
i produced a simple .plt file as mentioned in code 1 and converted it with preplot. Then i used a hex editor to compare the produced and my own .plt file. So then i could append my Header to the correct input. Here is my code just for your information, inf anyone other has the same problems. Code:
program binary c---- Deklaration implicit none integer*4 unitnum,FileType,NumVar integer*4 enumi,enumj,enumk,enuml,enumm character*18 VarName(3),title,zonename real*4 daten(4) real*8 mini,maxi c---- Definition unitnum=20 FileType=0 c 0=full, 1=grid, 2=solution zonename='myzone' title='mytitle' NumVar=13 VarName(1)='x' VarName(2)='y' VarName(3)='z' daten(1)=1.1 daten(2)=2.2 daten(3)=3.3 daten(4)=4 c####################################################################### c---- Open File open(unit=unitnum,file='myfilename.plt',form='unformatted', & access='stream',status='replace') c---- HEADER Section c i Magic number, Version number write(unitnum) '#!TDV112' c ii Integer value of 1, little/big endian? write(unitnum) 1 c iii Type, Title, number of variables and variable names write(unitnum) FileType call converter(unitnum,title) c write(unitnum) 0 write(unitnum) NumVar do enumi=1, NumVar call converter(unitnum,VarName(enumi)) end do c iv Zones write(unitnum) 299.0 call converter(unitnum,zonename) c reverse engineering header write(unitnum) -1,-1,0,0,-1,0,0,0,0,size(daten),1,1,0 c---- EOHMARKER - Trennung Header zu Data write(unitnum) 357.0 c---- II DATA Section c i Zones write(unitnum) 299.0 c Variable Data Format, je Variable c 1 float, 2 double, 3 longint, 4 shortint, 5 byte, 6 bit do enumj=1, NumVar write(unitnum) 1 end do c Has passive variables write(unitnum) 0 c Has variable sharing write(unitnum) 0 c Zero based zone number write(unitnum) -1 c write(unitnum) 0 c compressed list of min/max do enumm=1,NumVar mini=minval(daten) maxi=maxval(daten) write(unitnum) mini write(unitnum) maxi end do c---- ZONE DATA loop NumVar,K,J,I do enumk=1, NumVar do enuml=1, size(daten) write(unitnum) daten(enuml) end do end do close(unitnum) end program binary c####################################################################### c---- Subroutine ASCII to Integer subroutine converter(unitnum,inputstring) implicit none character*18 inputstring integer*4 unitnum,i,letter,strlen,spacer strlen=len(inputstring) c remove spaces at then end of strings, 32=space (hex) do while(ichar(inputstring(strlen:strlen)).eq.32) strlen=strlen-1 end do do i=1 ,strlen letter=ichar(inputstring(i:i),4) write(unitnum) letter end do write(unitnum) 0 return end subroutine converter |
|
April 20, 2016, 04:18 |
|
#3 |
Member
phil
Join Date: Oct 2013
Posts: 36
Rep Power: 13 |
At last i have 1 more problem. As i get my data over loops, with each loop i get for 1 variable 1 value. Binary files need to write all values by variable after each one. I have to try if my Code or writting time will explode when i have to save my data in arrays first.
Otherwise is there any Tecplot function to "inverse" the data matrix or tell it that the data for each variable is not in a row but in a column? (weird difference between ASCII and binary files) Greetings --------- Solution Binary files in Tecplot`s format are not meant to be written POINTwise (=DATAPACKING). Last edited by gelbebanane; April 21, 2016 at 06:10. Reason: a |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to calculate mass flow rate on patches and summation of that during the run? | immortality | OpenFOAM Post-Processing | 104 | February 16, 2021 09:46 |
[foam-extend.org] problem when installing foam-extend-1.6 | Thomas pan | OpenFOAM Installation | 7 | September 9, 2015 22:53 |
[OpenFOAM.org] Compile OF 2.3 on Mac OS X .... the patch | gschaider | OpenFOAM Installation | 225 | August 25, 2015 20:43 |
[swak4Foam] Error bulding swak4Foam | sfigato | OpenFOAM Community Contributions | 18 | August 22, 2013 13:41 |
DecomposePar links against liblamso0 with OpenMPI | jens_klostermann | OpenFOAM Bugs | 11 | June 28, 2007 18:51 |