Chaque fichier bimg est un fichier de type binaire, 'unformatted', créé par un programme fortran. Une entête contient sur 6 records l'info concernant le fichier, puis sur les records suivant les données proprement dites, stockées sous forme de champ 2D.
Plutot qu'un long discours, je propose de de commenter un programme f77 lisant un fichier bimg, pour expliquer le format:
PROGRAM bimg_demo_lec
IMPLICIT NONE
INTEGER jpi,jpj,jpk,jpt,jpdim
...PARAMETER (jpi=100m,jpj=100,jpk=20)
PARAMETER (jpt=100,jpdim=2)
C
CHARACTER*80 comment1, comment2, comment3, comment4
C
INTEGER ni,nj,nk,nt,ndim,icod ! Real dimension of the field
C
REAL x1, y1, dx, dy , spval ! x1 = x of point(1,1)
C ! y1 = y of point (1,1)
C ! dx = x-grid spacing
C ! dy = y-grid spacing
C ! spval : missing/bad/masked
C ! values are supposed spval
C
REAL dep(jpk) ! array for vertical dep
REAL time(jpt) ! array for times
REAL ptab(jpi,jpj,jpk,jpt,jpdim) ! data array
C ! In application it can be
C ! only 2D (jpi,jpj)
C various
INTEGER numbimg ! logical unit for bimgfile
INTEGER ji,jj,jk,jt,jdim ! loop counter
C
CCC
CC Open file
CC
numbimg=10
OPEN (numbimg,file='filebimg',form='UNFORMATTED')
C Read comment lines
READ(numbimg) comment!
READ(numbimg) comment2
READ(numbimg) comment3
READ(numbimg) comment4
C Read grid dimensions
READ(numbimg) ni,nj,nk,nt,ndim,icod ! icod is spare
C Read grid position and special values
READ(numbimg) x1,y1,dx,dy,spval
C Read depth of levels
READ(numbimg) (dep(jk),jk=1,nk)
C
C Enter the time loop
DO jt = 1, nt
C read current time
READ(numbimg) time(jt)
C enter vertical loop
DO jk=1,nk
C at each level, many 'dimensions' can exists e.g. u,v,w for 3d vector
DO jdim = 1,jpdim
C Note taht the i,j loop are implicit: ! rec hold 1 2D field.
READ(numbimg)(( ptab(ji,jj,jk,jt,jdim),ji=1,ni),jj=1,nj)
C IF we use only 2D array, this is the place to work with the current
C 2D field at ime jt, dep jk and dim jdim ...
C
C...
C
C...
END DO
END DO
END DO
CLOSE(numbimg)
C
C Now enjoy working with ptab ...
END
Le
format bimg a été étendu dans son idée à
des fichiers à accès direct: c'est le format dimg. Pour
en savoir plus sur dimg ...