As an application of Fortran file operations
I want to read an array like this line by line, but it doesn't work.
The line count works fine, but it doesn't read the number, what should I do?
Corresponding source code
n = 4 test 0.00000000 At line 27 of file p2.f90 Fortran runtime error: Attempting to allocate already allocated variable'a' Error termination. Backtrace: # 0 0xffffffffffffffff in ??? # 1 0xffffffffffffffff in ??? # 2 0xffffffffffffffff in ??? # 3 0xffffffffffffffff in ??? # 4 0xffffffffffffffff in ??? # 5 0xffffffffffffffff in ??? # 6 0xffffffffffffffff in ??? # 7 0xffffffffffffffff in ??? # 8 0xffffffffffffffff in ???
What I tried Supplementary information (FW/tool version, etc.)
program p2 implicit none real, allocatable :: a (:) integer i integer n character (len = 50) :: str1 open (20, file ='p2.txt', status ='old') read (20, *) str1 n = 0 do read (20, *, end = 99) a n = n + 1 end do 99 print *, ('n ='), n print *, str1 do i = 2, n allocate (a (100)) print *, a (i) end do close (20) ! open (21, file ='p2.csv', status ='replace') ! do i = 1, n ! write (21, *) a ! end do ! close (21) end program p2
Please provide more detailed information here.
Answer # 1
allocate allocateDid you use it without it?
Also, the first line is
testIsn't it a character string?
Where and how are you going to load it?
- C # read and write XML file example code
- how to write when you want to use a common array in multiple methods in laravel's controller
- c ++ - how pointers and arrays work
- read csv file and use in list [java]
- python - read multiple csvs and visualize
- i want to write array to text file with java
- python - what does x = array [:, 0: 8] and y = array [:, 8] mean in this source code?
- php - i want to write an array on the db facade
- Java multidimensional array and Arrays class method summary
- multidimensional arrays - in react, i want to output an array of arrays in a grandchild component
- java read txt file and output the result
- Node-red file read and save examples
- java read cvs file and import database
- Python: read by line, sort and then output
- Java method to read text and pictures in PDF
- jquery - i want to call 10 arrays that have 100, and call from the 11th array with infinite scroll
- vba - i want to read csv and write to excel