delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/12/07/21:08:51

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
Message-ID: <3C117177.76B87214@mail.abaconet.com.ar>
Date: Fri, 07 Dec 2001 22:48:39 -0300
From: Marta Ghidella <mghidella AT mail DOT abaconet DOT com DOT ar>
X-Mailer: Mozilla 4.03 [es] (Win95; I)
MIME-Version: 1.0
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
CC: djgpp AT delorie DOT com
Subject: Re: fortran
References: <3C0FB699 DOT 5BB2543 AT dna DOT gov DOT ar> <2110-Thu06Dec2001213938+0200-eliz AT is DOT elta DOT co DOT il>
Reply-To: djgpp AT delorie DOT com

Hello, Eli!

Thank you for your reply ...

I am opening the files as "unformatted". I am enclosing a test program
(test1.f) with its output.

The program creates an unformatted sequential file, apparently without
problems, but I see it has 4137 bytes instead of 4136 as it should. Then
it crashes when I want to read the file, I am enclosing the output I
get.

Thank you for your help.

My best regards,

Marta

      character row
      dimension aj(100),sal(100)
      
      numx=100
      numy=10
      call getarg(1,row)
      
      if(row.eq.'')then
      write(0,*)'test1 w (write file) or test1 r (read file)'
      stop
      end if
      
      if(row.eq.'w')then
       open(1,file='test1.unf',status='new', form='unformatted',err=100)
         
         write(1)numx,numy
         do i=1,numy
            
            do j=1,numx
            aj(j)=float(j)*float(i)
            end do

         ai=i
         write(0,*)'i=',i
         write(1)ai,(aj(j),j=1,numx)
         write(0,*)ai,(aj(j),j=1,numx)
         end do
         close(1)
         stop
100    write(0,*)'error opening file to write'
       stop
       end if
             
       
      if(row.eq.'r')then
      open(1,file='test1.unf',status='old', form='unformatted', err=200)

       read(1)numx,numy
       write(*,*)numx,numy
       do i=1,numy
             read(1)ai,(sal(j),j=1,numx)
             write(*,*)ai,(sal(j),j=1,numx)
         end do
       close(1)
       stop
200    write(0,*)'error opening file to read'
       stop
       end if
       
      write(0,*)'test1 w (write file) or test1 r (read file)'
       
       end
         
This is the output when I run the program to read the filel test1.unf:

 100 10
  1.  1.  2.  3.  4.  5.  6.  7.  8.  9.  10.  11.  12.  13.  14.  15.
16.
  17.  18.  19.  20.  21.  22.  23.  24.  25.  26.  27.  28.  29.  30.
31.
  32.  33.  34.  35.  36.  37.  38.  39.  40.  41.  42.  43.  44.  45.
46.
  47.  48.  49.  50.  51.  52.  53.  54.  55.  56.  57.  58.  59.  60.
61.
  62.  63.  64.  65.  66.  67.  68.  69.  70.  71.  72.  73.  74.  75.
76.
  77.  78.  79.  80.  81.  82.  83.  84.  85.  86.  87.  88.  89.  90.
91.
  92.  93.  94.  95.  96.  97.  98.  99.  100.
do_us: end of file
apparent state: unit 1 named test1.unf
last format: list io
lately reading sequential unformatted external IO
Abort!


Eli Zaretskii wrote:
> 
> > Date: Thu, 06 Dec 2001 15:19:05 -0300
> > From: Marta Ghidella <mghidella AT dna DOT gov DOT ar>
> >
> > I have problems reading and writing binary files, both sequential and
> > direct access files.
> 
> You need to open the files in binary mode.  Did you do that?

-- 
 Marta E. Ghidella                          tel: +54-11-4812-6313
 Instituto Antartico Argentino              fax: +54-11-4813-7807
 Cerrito 1248                      e-mail:   mghidella AT dna DOT gov DOT ar
 1010 Buenos Aires - ARGENTINA     mghidella AT mail DOT abaconet DOT com DOT ar

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019