[Fortran} error in formatted

In summary, the error you got was: "positive width required in format specifier D at (1) not defined."
  • #1
s_hy
61
0
Hi all,

I got this error:

Code:
rm -f *.o *.mod *.MOD *.exe *.stackdump main 
gfortran -g  -I/usr/include -c main.f90
gfortran -g  -I/usr/include -c subroutines.f90
subroutines.f90:21.16:

10  format(data,'i3.3','.dat')   
                1
Error: Positive width required in format specifier D at (1)
subroutines.f90:13.22:

    write (filename,10) a
                      1
Error: FORMAT label 10 at (1) not defined
make: *** [subroutines.o] Error 1
./runcase.sh: line 11: ./main: No such file or directory


after executing below code:

Code:
subroutine outputtest
implicit none

 integer :: a,io, i,j,k,ierror
 double precision, dimension (500,500) :: x,y,z
 character (len=20) :: filename

 
  open(200,file=filename, status = 'new', action = 'write', iostat = ierror)
  
  do a = 1,20
    write (filename,10) a
    open (100,file = filename)
    do i = 1,299
      do j = 1,299
        write (200,*) x(120,120),y(120,120),z(120,120)
      end do
    end do          
  !  write(*,*) a 
10  format(data,'i3.3','.dat')   
  end do

 end subroutine


what is that mean of specifier D?


thank you
 
Technology news on Phys.org
  • #2
I can't tell what you're trying to do.

In the first executable statement, you're opening a file to write in, and associating unit number 200. Any writes to the file should have a first parameter of 200, the unit number. Since you have not initialized your filename string, when you open the file, the program give it some random name.

In the DO loop, the first write statement should be write(200, 10) a. This assumes that you want to write the values 1, 2, 3, ..., 19, and 20 to unit 200. The format statement whose label is 10 is not written correctly. Since all you're doing is writing an integer value to the file, it should be something like this:
10 format (i5)

You have another open statement inside the DO loop. Do you really mean to open a second file?

Inside the nested DO loops you are writing to unit 200, the first file you opened, and are writing the same three values in the file; namely x(120, 120), y(120, 120), and z(120, 120). These will be garbage values, as you have not initialized any of these arrays. That write statement executes almost 90,000 times, but it writes the same three garbage values for each of these times.

It would be good for you to spend some time studying fortran syntax, such as opening files, how print and format statements work, among other things.
 
  • #3
Actually, I have 20 .dat files containing (x,y,z). From each files, I need to extract data from row (i,j) = (120,120), and the value from all the files will be write into one new file. I am really not an expert in fortran. Please guide me.

thank you
 
  • #4
To extract data, you need to READ from the files, not WRITE to them.

How is the data arranged in each of the files? Data is not stored in files as tables. Is the file a binary file or a text file?Some pseudocode...
Code:
Open a file for writing.
For each of the 20 data files
   Construct a string that contains the name of one of the input data files.
   Open the file for reading.
   Locate to the correct position in the file. (*)
   Read the data from the input file.
   Write the value to the output file.
End for
(*) The details of the step with the asterisk depend on how the data is stored in the input files.

As I said before,
Mark44 said:
It would be good for you to spend some time studying fortran syntax, such as opening files, how print, and format statements work, among other things.
Also how READ works. I didn't understand before what you were trying to do.

I've seen a lot of your posts over the past almost three years, and it seems that many or even most of them were questions about fortran code. Most of the mistakes you are making would be preventable if you put in some time at learning fortran.
 
  • Like
Likes 1 person
  • #5
for your help

Hello,

It seems like you are getting an error related to the formatting of your code. The error message is pointing to line 21 of your subroutines.f90 file, where you are using a format specifier of 'i3.3' in your write statement. The error is indicating that a positive width is required for this format specifier. This means that you need to specify the number of characters that will be printed for the integer value. For example, if you wanted to print a value of 5, you would need to use a format specifier of 'i1.1' to indicate that only 1 character should be used to print the value.

Additionally, the error message is also indicating that the format label 10 is not defined. This means that the format statement with label 10 is not present in your code, which is causing the error.

I recommend reviewing your code and making sure that all format specifiers have a positive width and that all format labels are defined. This should help resolve the error you are experiencing.

I hope this helps. Let me know if you have any other questions.
 

What is a "Fortran error in formatted"?

A "Fortran error in formatted" is an error that occurs in a Fortran program when there is an issue with the formatting of the input or output of data. This can happen when the format specifier does not match the type of data being read or written, or when there is a mismatch in the number of data items being read or written.

What causes a "Fortran error in formatted"?

There are several possible causes for a "Fortran error in formatted", including using incorrect format specifiers, using the wrong data type for the format specifier, or having a mismatch in the number of data items being read or written.

How can I fix a "Fortran error in formatted"?

To fix a "Fortran error in formatted", you will need to carefully review your code and make sure that all format specifiers match the data being read or written, and that the correct data types are being used. You may also need to check for any mismatches in the number of data items being read or written.

Can "Fortran error in formatted" be prevented?

Yes, "Fortran error in formatted" can be prevented by carefully checking and double-checking your code for any potential format specifier or data type mismatches. It is also helpful to use good coding practices and to test your code thoroughly before running it.

Are there any tools available to help with "Fortran error in formatted"?

Yes, there are several debugging tools available for Fortran that can help with identifying and fixing "Fortran error in formatted". These include compilers with error-checking capabilities, as well as specialized debugging software specifically designed for Fortran programs.

Similar threads

  • Programming and Computer Science
Replies
4
Views
624
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
8
Views
6K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
Back
Top