I made my own binary file, but the data is not right loaded

Creating Tecplot binary data files

Moderators: davetaflin, salter, steve, jprenaud, straton, Chris Idso

heguhu
Newbie
Posts: 1
Joined: Sat May 28, 2011 5:05 pm
Location: Osaka, Japan

I made my own binary file, but the data is not right loaded

Postby heguhu » Thu Jun 02, 2011 6:11 pm

I use the Fortran to write out a direct binary file for Tecplot 360 2009.
Not using the tecio.for and tecio.lib.

It seems no problem in the head of the binary file, but the data is not correctly loaded. I have checked the code several times and couldn't find the error. How can found out which part is wrong? Dose any guy meet similar problem?

Code: Select all

      PROGRAM TECBIN
     
      IMPLICIT NONE
      REAL*4 EOHMARKER
      REAL*8      SolTime
      INTEGER*4   I,J,K,IVar,VarDataFt
      INTEGER*4   IMax,JMax,KMax     
      INTEGER*4   FileType,StrandID,ParentZn
      INTEGER*4   SharingZone(4)
      REAL*8      XPosi, YPosi,ZPosi,FH,LineSpacing,PatternLength
      REAL*8      BoxMargin, BoxLineThickness, TextAngle
      INTEGER*4   AttachToZone, Zone, Scope, PositionCoordSys
      INTEGER*4   Clipping
      INTEGER*4   FontType, HeightUnits, Anchor, BoxType
      INTEGER*4   BoxColor, BoxFillColor, TextColor
      CHARACTER*1 NULCHAR
      CHARACTER*4 NNChar
      CHARACTER*30 TimeChar
      CHARACTER*40 VarName(4),TITLE,ZoneName,MacroFun,TimeTEXT
      INTEGER*4 NumVar,ZoneNum,ZoneType,IFile
      INTEGER*4 ValueLocate,NumFaceCntion,AuxiliName
      INTEGER*4 PassiVarList,VarSharing,ShareConty       
      REAL*4 XYZP(4,5,1,4)
     
      NULCHAR = CHAR(0)     

!  Calculate values for the field variables.                 
      IMax   = 4
      JMax   = 5
      KMax   = 1     
      NumVar = 4
      VarName(1) = 'X'
      VarName(2) = 'Y'
      VarName(3) = 'Z'
      VarName(4) = 'P'
     
      ZoneNum = 1
      SolTime = 20.0
     
      do IVar = 1,NumVar
          DO K=1,KMAX                                               
            DO J=1,JMAX
                DO I=1,IMAX
                    XYZP(I,J,K,IVAR) = FLOAT(IVar)
                END DO
            END DO
          ENDDO
      enddo
     
      WRITE(TimeChar,'(F7.4)')SolTime     
      WRITE(NNChar,'(I4)')ZoneNum     
      ZoneName = 'ZONE'//NNChar           

      ParentZn = -1
      StrandID = 1
      ZoneType = 0
      ValueLocate   = 0
      NumFaceCntion = 0
      AuxiliName    = 0
     
      EOHMARKER     = 357.0   
      VarDataFt     = 1 !Float
      PassiVarList  = 0
      VarSharing    = 1         
      SharingZone(1)= -1
      SharingZone(2)= -1
      SharingZone(3)= -1           
      SharingZone(4)= -1           
      ShareConty    = -1
     
      PositionCoordSys = 1
      XPosi            = 60.0
      YPosi            = 80.0
      ZPosi            = 0.0D0
      FH               = 2.0
      Scope            = 1
      Clipping         = 0
      FontType         = 1
      HeightUnits      = 1
      AttachToZone     = 1  !Attach to zone
      Zone             = ZoneNum  !Attach to which zone
      BoxType          = 0
      BoxMargin        = 5.0
      BoxLineThickness = 0.5
      BoxColor         = 3
      BoxFillColor     = 7
      TextAngle        = 0.0
      Anchor           = 0
      LineSpacing      = 1.5
      TextColor        = 0
      MacroFun         = CHAR(0)     
!               
!      NULCHAR   = CHAR(0)
!      Zero      = 0
!      NullPtr   = 0 
 
      IFile = 99
      OPEN(UNIT=IFile,FILE="TECBIN.plt",FORM="BINARY")
       
!I. HEADER SECTION

!The header section contains: the version number of the file, a title
!of the file, the names of the variables to be plotted, the
!descriptions of all zones to be read in and all text and geometry
!definitions.
 
!i. Magic number, Version number
!
!+-----------+
!| 。ー#!TDV112。ア| 8 Bytes, exact characters 。ー#!TDV112。ア.
!+-----------+ Version number follows the 。ーV。ア and
!consumes the next 3 characters (for
!example: 。ーV75 。ー, 。ーV101。ア).
      WRITE(IFile) '#!TDV112'
 
!ii. Integer value of 1.
!+-----------+
!| INT32     | This is used to determine the byte order
!+-----------+ of the reader, relative to the writer.
      WRITE(IFile) 1
 
!iii. Title and variable names.
!+-----------+
!| INT32     | FileType: 0 = FULL,
!+-----------+           1 = GRID,
!                        2 = SOLUTION     
      FileType  = 0
      WRITE(IFile) FileType
     
!+-----------+
!| INT32*N   | The TITLE. (See note 1.)
!+-----------+
      TITLE = 'TIME-STEPS'
      CALL DUMPSTRING(IFile,TITLE)     
     
!+-----------+
!| INT32     | Number of variables (NumVar) in the datafile.
!+-----------+
      WRITE(IFile)NumVar
!+-----------+
!| INT32*N   | Variable names.
!+-----------+ N = L[1] + L[2] + .... L[NumVar]
!where:
!L[i] = length of the ith variable name + 1
!(for the terminating 0 value).
!(See note 1.)

      CALL DUMPSTRING(IFile,VarName(1))
      CALL DUMPSTRING(IFile,VarName(2)) 
      CALL DUMPSTRING(IFile,VarName(3)) 
      CALL DUMPSTRING(IFile,VarName(4))                         
       
!iv. Zones
!+-----------+
!| FLOAT32   | Zone marker. Value = 299.0
!+-----------+
      WRITE(IFile) 299.0
!+-----------+
!| INT32*N   | Zone name. (See note 1.)
!+-----------+ N = (length of zone name) + 1.
      CALL DUMPSTRING(IFile,ZoneName)     
           
!+-----------+
!| INT32     | ParentZone: Zero-based zone number within this
!+-----------+ datafile to which this zone is a child.
!
      WRITE(IFile)ParentZn
     
!+-----------+
!| INT32     | StrandID: -2 = pending strand ID for assignment
!+-----------+ by Tecplot
!-1 = static strand ID
!0 <= N <32700>= 0). This value
!is in addition to the face neighbors supplied
!in the raw section. FEPOLYGON and FEPOLYHEDRON
!zones must specify 0.
      WRITE(IFile) NumFaceCntion
 
    !----------------------------------------------------
    !if 。ーnumber of miscellaneous user-defined
    !face neighbor connections。ア != 0
    !+-----------+
    !| INT32     | User defined face neighbor mode
    !+-----------+  (0=Local 1-to-1, 1=Local 1-to-many,
    !                2=Global 1-to-1, 3=Global 1-to-many)
   
        !----------------------------------------------------------
        !if FE Zone:
        !+-----------+
        !| INT32     | Indicates if the finite element face neighbors
        !+-----------+ are completely specified by the miscellaneous
        !face neighbors given: (0=NO, 1=YES). If yes,
        !then Tecplot will not perform auto assignment
        !of face neighbors otherwise all faces not
        !specified are considered boundaries. If no,
        !then Tecplot will perform auto-assignment of
        !the face neighbors unless the raw face neighbor
        !array was supplied. This option is not valid
        !for ORDERED zones.
       
!if Ordered Zone:
!+-----------+
!| INT32*3   | IMax,JMax,KMax
!+-----------+
      WRITE(IFile) IMax,JMax,KMax
       
!if FE Zone:
!+-----------+
!| INT32     | NumPts
!+-----------+
    !if ZoneType is FEPOLYGON or FEPOLYHEDRON:
    !+-----------+
    !| INT32     | NumFaces
    !+-----------+
    !+-----------+
    !| INT32     | Total number of face nodes. For FEPOLYGON
    !+-----------+ zones, this is NumFaces*2.
    !+-----------+
    !| INT32     | Total number of boundary faces. If any
    !+-----------+ boundary faces exist, include one to represent
    !no neighboring element.
    !+-----------+
    !| INT32     | Total number of boundary connections.
    !+-----------+
    !+-----------+
    !| INT32     | NumElements
    !+-----------+
    !+-----------+
    !| INT32*3   | ICellDim,JCellDim,
    !+-----------+ KCellDim (for future use; set to zero)
 


!For all zone types (repeat for each Auxiliary data name/value pair):
!+-----------+
!| INT32     | 1=Auxiliary name/value pair to follow
!+-----------+ 0=No more Auxiliary name/value pairs.
      WRITE(IFile) AuxiliName
     
    !If the above is 1, then supply the following:
    !+-----------+
    !| INT32*N   | name string (See note 1.)
    !+-----------+
    !+-----------+
    !| INT32     | Auxiliary Value Format
    !+-----------+ (Currently only allow 0=AuxDataType_String)
    !+-----------+
    !| INT32*N   | Value string (See note 1.)
    !+-----------+
 
 
!vi. Text
!+-----------+
!| FLOAT32   | Text marker. Value=499.0
!+-----------+
      WRITE(IFile) 499.0
!+-----------+
!| INT32     | Position CoordSys 0=Grid, 1=Frame,
!+-----------+                   2=FrameOffset(not used),
!                                3= OldWindow(not used),
!                                4=Grid3D(New to V10)
      WRITE(IFile) PositionCoordSys     
!+-----------+
!| INT32     | Scope 0=Global 1=Local
!+-----------+
      WRITE(IFile) Scope     
!+-----------+
!| FLOAT64*3 | (X or Theta),(Y or R),(Z or dummy)
!+-----------+ Starting Location
      WRITE(IFile) XPosi,YPosi,ZPosi     
!+-----------+
!| INT32     | FontType
!+-----------+
      WRITE(IFile) FontType
!+-----------+
!| INT32     | Character Height Units 0=Grid, 1=Frame, 2=Point
!+-----------+
      WRITE(IFile) HeightUnits
!+-----------+
!| FLOAT64   | Height of characters
!+-----------+
      WRITE(IFile) FH
!+-----------+
!| INT32     | Text Box type 0=NoBox 1=Hollow 2=Filled
!+-----------+
      WRITE(IFile) BoxType
!+-----------+
!| FLOAT64   | Text Box Margin
!+-----------+
      WRITE(IFile) BoxMargin
!+-----------+
!| FLOAT64   | Text Box Margin Linewidth
!+-----------+
      WRITE(IFile) BoxLineThickness
!+-----------+
!| INT32     | Text Box Outline Color
!+-----------+
      WRITE(IFile) BoxColor
!+-----------+
!| INT32     | Text Box Fill Color
!+-----------+
      WRITE(IFile) BoxFillColor
!+-----------+
!| FLOAT64   | Angle
!+-----------+
      WRITE(IFile) TextAngle
!+-----------+
!| FLOAT64   | Line Spacing
!+-----------+
      WRITE(IFile) LineSpacing
!+-----------+
!| INT32     | Text Anchor.  0=left, 1=center,
!+-----------+               2=right, 3=midleft
!                            4=midcenter 5=midright,
!                            6=headleft 7=headcenter
!                            8=headright
      WRITE(IFile) Anchor
!+-----------+
!| INT32     | Zone (0=all)
!+-----------+
      WRITE(IFile) 0 ! ZoneNum !Attach to wihch zone
!+-----------+
!| INT32     | Color
!+-----------+
      WRITE(IFile) TextColor
!+-----------+
!| INT32*N   | MacroFunctionCommand (string: N = Length + 1)
!+-----------+
!      CALL DUMPSTRING(IFile,MacroFun)
      WRITE(IFile) 0
           
!+-----------+
!| INT32     | Clipping (0=ClipToAxes,
!+-----------+           1=ClipToViewport, 2=ClipToFrame)
      WRITE(IFile) Clipping
!+-----------+
!| INT32*N   | Text. N=Text Length+1
!+-----------+
      TimeTEXT='Time = '//TimeChar
      CALL DUMPSTRING(IFile,TimeTEXT)

!!vii.CustomLabel

!!viii.UserRec
!! 

      WRITE(IFile) 357.0  !EOHMARKER

*******************************************************************
!II. DATA SECTION (don。ッt forget to separate the header from the data
!with an EOHMARKER). The data section contains all of the data
!associated with the zone definitions in the header.
*******************************************************************
!i. For both ordered and fe zones:
!+-----------+
!| FLOAT32   | Zone marker Value = 299.0
!+-----------+
      WRITE(IFile) 299.0
!+-----------+
!| INT32*N   | Variable data format, N=Total number of vars
!+-----------+   1=Float, 2=Double, 3=LongInt,
!                4=ShortInt, 5=Byte, 6=Bit
!      WRITE(IFile) VarDataFt,VarDataFt,VarDataFt,VarDataFt
      WRITE(IFile)VarDataFt,VarDataFt,VarDataFt,VarDataFt
!+-----------+
!| INT32     | Has passive variables: 0 = no, 1 = yes.
!+-----------+
      WRITE(IFile) PassiVarList
    !if 。ーhas passive variables。ア != 0
    !+-----------+
    !| INT32*NV  | Is variable passive: 0 = no, 1 = yes
    !+-----------+ (Omit entirely if 。ーHas passive variables。ア is 0).
   
!+-----------+
!| INT32     | Has variable sharing 0 = no, 1 = yes.
!+-----------+
      WRITE(IFile) VarSharing     
    !if 。ーhas variable sharing。ア != 0
    !+-----------+
    !| INT32*NV  | Zero based zone number to share variable with
    !+-----------+ (relative to this datafile). (-1 = no sharing).
    !(Omit entirely if 。ーHas variable sharing。ア is 0).
      WRITE(IFile) SharingZone(1),SharingZone(2)     
      WRITE(IFile) SharingZone(3),SharingZone(4)     
     
    !+-----------+
    !| INT32     | Zero based zone number to share connectivity
    !+-----------+ list with (-1 = no sharing). FEPOLYGON and
    !FEPOLYHEDRON zones use this zone number to
    !share face map data.
 
!+-----------+
!| INT32     | Zero based zone number to share connectivity
!+-----------+ list with (-1 = no sharing). FEPOLYGON and
!FEPOLYHEDRON zones use this zone number to
!share face map data.
      WRITE(IFile) ShareConty   
!Compressed list of min/max pairs for each non-shared and non-passive
!variable. For each non-shared and non-passive variable (as specified
!above):
!+-----------+
!| FLOAT64   | Min value
!+-----------+
!      WRITE(IFile) 0.0D0   
     
!+-----------+
!| FLOAT64   | Max value
!+-----------+
!      WRITE(IFile) 10.0D0   
   
************************************************************ 
!+-----------+
!| xxxxxxxxxx| Zone Data. Each variable is in data format as
!+-----------+ specified above.

      !====== Test (Add extra data) ====
!      DO I = 1,16
!        WRITE(IFile)1
!      ENDDO
      !====== Test (Add extra data) ====
     
      do IVar = 1,NumVar
          DO K=1,KMAX                                               
            DO J=1,JMAX
                DO I=1,IMAX
                    WRITE(IFile)XYZP(I,J,K,IVAR)
                END DO
            END DO
          ENDDO
      enddo
 
      STOP
      END
   
     
C********************************************************     
C           SUBROUTINE DUMPSTRING
C********************************************************
      SUBROUTINE DUMPSTRING(IFile,INSTRING)
      CHARACTER*40 INSTRING
      INTEGER LEN,IFile
     
      LEN=LEN_TRIM(INSTRING)
      DO II=1,LEN
          I=ICHAR(INSTRING(II:II))
          WRITE(IFile) I
      END DO
     
      WRITE(99) 0
      RETURN
      END 

User avatar
salter
Moderator
Posts: 188
Joined: Thu Dec 21, 2006 10:57 am
Location: NASA Langley Research Center
Contact:

Re: I made my own binary file, but the data is not right loa

Postby salter » Mon Jun 06, 2011 11:54 am

As long as you link and use the tecio libraries, you should be able to write out a file that tecplot can read. I do this all the time and find the tecio functionality very useful.
Steve...

Aerospace Research Engineer
Aerothermodynamics Branch
NASA Langley Research Center

kostasp
Experienced user
Posts: 15
Joined: Mon May 07, 2012 5:40 am
Location: France

Re: I made my own binary file, but the data is not right loa

Postby kostasp » Wed Jun 12, 2013 4:50 am

Hello,

I would suggest to:
> use stream access output:

open(99,access='stream',form='unformatted')

> use the iso|_fortran_env module and use kinds everywhere just to be sure

use iso_fortran_env

int32 for integer
real32 for floats
or real64 when required

> compare your plt with a plt created by ascii data with preplot using hexdump for a test case.

Kostas

thadsaab
Newbie
Posts: 5
Joined: Fri Feb 06, 2009 5:34 pm
Location: USA
Contact:

Re: I made my own binary file, but the data is not right loa

Postby thadsaab » Thu Jul 11, 2013 10:36 am

For older compilers (compaq and digital fortran), I use
open(99,file=nme,form='binary')

For more recent intel and gfortran, I use
open(99,file=nme,access='stream',form='unformatted')
as kostasp suggests.

I think the best way to learn is to start by reading files. It's easier to debug. Then, you can use your bin file reader to check your bin output.

gelbebanane
Newbie
Posts: 1
Joined: Fri Apr 15, 2016 2:54 am
Location: germany

Re: I made my own binary file, but the data is not right loaded

Postby gelbebanane » Fri Apr 15, 2016 3:16 am

Hello all,
I am facing the same error message : Invalid header in binary datafile.
I made some changes to your code but used it as a basic knowledge how to get started with Fortran. Perhaps you can have a look at my Code:

Code: Select all

      program tecbinary
c---- Deklaration
      implicit none
      integer unitnum,FileType,NumVar,vardf,arraysize
      integer enumi,enumj,enumk,enuml
      character*18 VarName(5),title,zonename
      real*8 datas(3)

c---- Definition
      unitnum=99
      FileType=2
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

The data should then be formatted like this. It is just a basic file with variable names and 1-D arrays for their values. (this is just an exert of the actual data, so please do not wonder why i do not make it by hand)

Code: Select all

 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.0111E+00   6.5505E-14


Return to “TecIO Library”

Who is online

Users browsing this forum: No registered users and 1 guest