Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating binary file 1

Status
Not open for further replies.

mikibelavista

Technical User
Jan 18, 2012
32
I need this binary for other program,want to transfer my ascii values but
pr3.f: In program `pr3':
pr3.f:4:
real(nmax) a
1 2
Invalid kind at (2) for type at (1) -- unsupported or not permitted
pr3.f:5:
integer*2(nmax) b
^
Invalid form for type-declaration statement at (^)
pr3.f:4:
parameter(nmax=10)
1
pr3.f:7: (continued):
nmax=10
2
My code:
program pr3
include 'pch.par'
real(nmax) a
integer*2(nmax) b
nmax=10
open(36,file='pch.mod',form='unformatted')
b=a
write(36)b
end program
pch.par
parameter(nmax=10)
 
This works
program pr4
implicit none

real a
integer*2 b

open(36,file='wb.dat',form='unformatted',status='new')
a=5714
b=a

write(36)b

end program

But how to write array in f77 style?
 
Do you really want to write intrinsic type (I assume 32 bit) real array as a 16 bit integer array ? At least this is what the prog does.

To my knowledge, to declare reals or integers other than intrinsic or double precision is a fortran 90/95 feature and was not part of the fortran 77 release.

But to write unformatted files with intrinsic type reals or integers was possible in fortran 77 - even in earlier versions.

Norbert




The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Oops, slipped on the English again.

I mean 'default' types not 'intrinsic'.

Sorry.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Try something like :
Code:
      program pr3
      integer,parameter :: nmax=10
      real a(nmax)
      integer*2 b(nmax)
      open(36,file='pch.mod',form='unformatted')
      do i=1,nmax
        a(i)=i
      enddo
      b=a
      write(36)b
      end program



François Jacq
 
Yes I want to have everything written as integer*2,because the program that I am using requires that kind of input file.
Jack I have copied and tried your program:
pr3.f: In program `pr3':
pr3.f:2:
integer,parameter :: nmax=10
^
Fortran 90 feature at (^) unsupported
pr3.f:2:
integer,parameter :: nmax=10
1
pr3.f:3: (continued):
real a(nmax)
2
Invalid declaration of or reference to symbol `nmax' at (2) [initially seen at (1)]
pr3.f:3:
real a(nmax)
1
pr3.f:5: (continued):
open(36,file='pch.mod',form='unformatted')
2
Invalid declaration of or reference to symbol `a' at (2) [initially seen at (1)]
pr3.f:4:
integer*2 b(nmax)
1
pr3.f:5: (continued):
open(36,file='pch.mod',form='unformatted')
2
Invalid declaration of or reference to symbol `b' at (2) [initially seen at (1)]
Actually I am using g77 and it is not supporting f90 features.
 
I am just giving part of the code how to make the file(original code):
open(unit=36, file='vel.mod', form='unformatted')
do 130 k=1,nz
do 130 j=1,ny
do 131 i=1,nx
131 veli(i)=vel(i,j,k)*1000.
130 write(36) (veli(i),i=1,nx)
c
stop
end
veli is defined at the very begining integer*2 veli(nxmax)
I have compiled using csh script.
#! /bin/csh -f

set list=`ls *.f`
set FLAG="-o"
echo $list
foreach file (${list})
echo $file
f77 -g ${file} ${FLAG} ${file:r}
mv ${file:r} ../bin/.

end


 
If you want a pure F77 version, try that:

Code:
      program pr3
      integer nmax,i
      parameter (nmax=10)
      real a(nmax)
      integer*2 b(nmax)
      open(36,file='pch.mod',form='unformatted')
      do i=1,nmax
        a(i)=i
      enddo
      b=a
      write(36)b
      end

François Jacq
 
Still does not work:
pr33.f:10:
b=a
^
Expression at (^) has incorrect data type or rank for its context
pr33.f:10:
b=a
^
Expression at (^) has incorrect data type or rank for its context
 
Replace b=a by :

Code:
      DO i=1,n
        b(i)=a(i)
      ENDDO

Now, it should be time to change your Fortran compiler. F77 is obsolete for more than 15 years !

François Jacq
 
... or is this compiler comlaining about the implicit casting ?

Code:
   do i = 1, nmax
      b(j) = int (a(i))
   enddo

And yes, FORTRAN 77 was introduced in 1978 (34 years ago) and was replaced by FORTRAN 90 in 1991 (22 years ago). And there are free FORTRAN 90/95 compilers around.

Norbert

The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Oh sod it....
Somehow I see my typos only after they are posted and not previewing it.

<blush>

Code:
   do i = 1, nmax
      b(i) = int (a(i))
   enddo

</blush>

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top