Change value of same variables in multiple code files - replace

I have multiple f90 files that contain the same variables
integer,parameter :: ilatmin = 0.5
integer,parameter :: ilatmax = 180
integer,parameter :: ilonmin = 0.5
integer,parameter :: ilonmax = 360
I would like to write shell script or a makefile where I specify the value of each variable and that loop through each .f90 file and update the values for each variable.
I though about using a search and replace like in this example Linux find and replace but was wondering if it's a good idea to use sed in a bash script.

Why don't you put those parameters into a module that you use inside the *.f90 files? It could look like:
module myParameters
implicit none
integer,parameter :: ilatmin = 0.5
integer,parameter :: ilatmax = 180
integer,parameter :: ilonmin = 0.5
integer,parameter :: ilonmax = 360
end module
In your code you then can include that module, e.g.
subroutine foo
use myParameters, only: ilatmin, ilatmax, ilonmin, ilonmax
! ...
end subroutine
Now you just need to change the module myParameters...
To your question... Using sed this could look like:
for i in *.f90; do
sed -i -e 's/ilatmin = .*$/ilatmin = XYZ/g' \
-e 's/ilatmax = .*$/ilatmax = XYZ/g' \
-e 's/ilonmin = .*$/ilonmin = XYZ/g' \
-e 's/ilonmax = .*$/ilonmax = XYZ/g' $i
done

Related

Why are rational numbers from Num printed as <abstr>?

I continue with my exploration on the Num library of Ocaml, with the reason that one whole library about logics was written using it.
Today, I would like to make the negative of a rational number. Obtain -1/2, from 1/2.
To do so, I think that, given an a of type Ratio.ratio, I can compute the negative of it (and return a ratio, not a num) this way:
ratio_of_num (minus_num (num_of_ratio a))
(Functions from: https://ocaml.org/releases/4.05/htmlman/libref/Num.html#TYPEnum)
Now, I would like to check the result, but I always get this solution: Ratio.ratio = <abstr>
The point is that now I realize that I always get this solution when I use ratio_of_num. For instance:
ratio_of_num (Int 2);;
- : Ratio.ratio = <abstr>
I have searched a bit and found this question (OCaml toplevel output formatting) where a different function (ratio_of_int 2) was used, but seems no longer possible. Maybe that ratio is a different library.
Any help?
PS: By the way, in order to replace num in the future, I am trying to install Zarith with opam, but cannot.
My problem is I do opam install zarith and this is displayed:
┌─ The following actions failed
│ λ build conf-gmp 3
└─
╶─ No changes have been performed
The packages you requested declare the following system dependencies. Please
make sure they are installed before retrying:
gmp
So I do opam install gmp and I get:
┌─ The following actions failed
│ λ build gmp 6.2.1
└─
╶─ No changes have been performed
Which offers me no clue on how to continue trying. Any help with this also?
I would appreciate any answer whether for the first question or the second one!!
Here below, I post some editions that have been added to the question, as a result of the conversation below:
EDIT (Solved adding the needed #require)
I have done what #ivg has suggested, but still does not work (I do the initial open Num, because it will ask it otherwise):
─( 23:12:59 )─< command 0 >──────────────────────────────────────{ counter: 0 }─
utop # open Num;;
─( 23:13:00 )─< command 1 >──────────────────────────────────────{ counter: 0 }─
utop # let pp_num ppf x = Format.fprintf ppf "%s" (Num.string_of_num x);;
val pp_num : Format.formatter -> num -> unit = <fun>
─( 23:14:11 )─< command 2 >──────────────────────────────────────{ counter: 0 }─
utop # #install_printer pp_num;;
─( 23:14:16 )─< command 3 >──────────────────────────────────────{ counter: 0 }─
utop # ratio_of_num (Int 2);;
- : Ratio.ratio = <abstr>
EDIT 2 (Also needed a #require)
I have also tried Ocaml instead of utop, but the error is worse:
OCaml version 4.10.2
Findlib has been successfully loaded. Additional directives:
#require "package";; to load a package
#list;; to list the available packages
#camlp4o;; to load camlp4 (standard syntax)
#camlp4r;; to load camlp4 (revised syntax)
#predicates "p,q,...";; to set these predicates
Topfind.reset();; to force that packages will be reloaded
#thread;; to enable threads
# open Num;;
# let pp_num ppf x = Format.fprintf ppf "%s" (Num.string_of_num x);;
Error: Reference to undefined global `Num'
#
EDIT 3 (Works in Ocaml, instead of utop)
##require "num";;
# let pp_num ppf x = Format.fprintf ppf "%s" (Num.string_of_num x);;
val pp_num : Format.formatter -> Num.num -> unit = <fun>
# #install_printer pp_num;;
# ratio_of_num (Int 2);;
- : Ratio.ratio = <ratio 2/1>
#
EDIT 4 (Works in utop, note that printing simplifies the result when it is an integer)
utop # let pp_ratio ppf r = Format.fprintf ppf "%a" pp_num (num_of_ratio r);;
val pp_ratio : Format.formatter -> Ratio.ratio -> unit = <fun>
─( 23:28:07 )─< command 6 >──────────────────────────────────────{ counter: 0 }─
utop # #install_printer pp_ratio;;
─( 23:28:22 )─< command 7 >──────────────────────────────────────{ counter: 0 }─
utop # ratio_of_num (Int 2);;
- : Ratio.ratio = 2
─( 23:28:29 )─< command 8 >──────────────────────────────────────{ counter: 0 }─
utop #
The reason why you have <abstr> instead of the actual representation is that the top-level (aka interpreter) doesn't know how to print the num object. It is easy to teach the top-level, using the #install_printer directive, e.g.,
let pp_num ppf x = Format.fprintf ppf "%s" (Num.string_of_num x);;
val pp_num : Format.formatter -> Num.num -> unit = <fun>
# #install_printer pp_num;;
# ratio_of_num (Int 2);;
- : Ratio.ratio = <ratio 2/1>
#
So we defined the pretty-printing function,
let pp_num ppf x = Format.fprintf ppf "%s" (Num.string_of_num x)
And then used the #install_printer directive to install it in the top-level,
# #install_printer pp_num;;
and now every time we have num it will be printed for us.
You can also use this pp_num function together with other Format module functions (that are used for pretty printing), e.g.,
Format.printf "my num = %a" pp_num (ratio_of_num (Int 2))
It might be that an older version of OCaml is unable to derive how to print ratio from the nums itself, so we can help it by defining an additional printer,
# let pp_ratio ppf r = Format.fprintf ppf "%a" pp_num (num_of_ratio r);;
val pp_ratio : Format.formatter -> Ratio.ratio -> unit = <fun>
# #install_printer pp_ratio;;
# ratio_of_num (Int 2);;
- : Ratio.ratio = 2
Re: P.S.
For zarith you need to install system dependencies. You can use opam for that, e.g.,
opam depext --install zarith
it will install the system dependencies (the gmp library) using your operating system package manager and then install the zarith library.

Is there an alternative to the fortran binary file opening option "RECORDTYPE=stream"?

I have a fortran program where I have to open a binary output file. normally one specifies.
RECL=num
However for my particular case, a file opened with that option does not work. What works is
RECORDTYPE=stream
The gfortran which i normally does not accept the second option. With the RECL option, the program works, but the data is unusable. The Intel compiler does. Intel no longer gives a free compiler and I lost the free Intel compiler I had.
I would appreciate any suggestion to write a stream with gfortran, or if someone can backup their compiler folder, put it on google drive and give me the link (hoping this is not an abuse).
I work on Ubuntu 18.04.
I paste below, a sample program I use and the data to be written to binary.
Program stndat
implicit none
integer :: iflag=0,itime=0
integer :: nlev,ihrold,nflag,icount
integer :: ihr !,iwx,delta,cld,vis
integer,dimension(1:3) :: today,now
Real :: lat,lon,iu,iv,itemp,idp,ipress
CHARACTER(len=3) :: stnid
character(len=8) :: date
character(len=10) :: time
character(len=5) :: zone
character(len=8) :: year,inst*10,hour*2
!
integer,dimension(1:8) :: values
! using keyword arguments
call date_and_time(date,time,zone,values)
!
open(1,file='tmp.txt')
write(1,'(1x,a8,2x,a10)') date,time
Program stndat
implicit none
integer :: iflag=0,itime=0
integer :: nlev,ihrold,nflag,icount
integer :: ihr !,iwx,delta,cld,vis
integer,dimension(1:3) :: today,now
Real :: lat,lon,iu,iv,itemp,idp,ipress
CHARACTER(len=3) :: stnid
character(len=8) :: date
character(len=10) :: time
character(len=5) :: zone
character(len=8) :: year,inst*10,hour*2
!
integer,dimension(1:8) :: values
! using keyword arguments
call date_and_time(date,time,zone,values)
!
open(1,file='tmp.txt')
write(1,'(1x,a8,2x,a10)') date,time
rewind(1)
read(1,'(1x,a8,2x,a10)') year,inst
close(1,status='delete')
iflag=0
itime=0
icount=1
hour = time(:2)
hour = '09'
! Open up I/O Files
Open(unit=11,file='../../Output/synop4grads.txt',status='old')
Open(unit=12,file='../../Output/Obs_out.bin',form='unformatted',recordtype='stream',status='unknown')
10 continue
! Read in the line of code
read(11,'(1x,a3,2x,f5.2,2x,f6.2,2x,i2,8(2x,f5.1))',END=40) stnid,lon,lat,ihr,iu,iv,itemp,idp,ipress
IF (iflag.EQ.0) THEN
iflag=1
ihrold=ihr
ENDIF
!
! Check to see if this is an old time group. If so, write a terminator
IF (ihrold.NE.ihr) THEN
nlev=0
write(12)stnid,lat,lon,ihr,nlev,nflag
ENDIF
! Now make ihrold equal to the current ihr
ihrold=ihr
!
! Now we can go ahead and write the report
! First, define some variables to be used in the header
itime=0.
nlev=1
nflag=1
write(12) stnid,lat,lon,ihr,nlev,nflag
!
! read in the following: itemp,idp,ipress,iu,iv,iwx,ic,icl
write(12) iu,iv,itemp,idp,ipress
! When its done writing one report, instruct the program
! to read-in the next line
go to 10
!
! When there are no more lines to read-in, the program
! goes to 40
40 continue
nlev=0
!
write(12)stnid,lat,lon,ihr,nlev,nflag
close(11)
close(12)
end
And the data
403 29.08 -9.80 01 -0.5 -3.0 24.0 16.5 496.0
441 24.43 -11.75 01 -99.0 -99.0 18.5 16.8 533.0
461 28.85 -11.10 01 -1.4 -9.9 26.0 17.7 485.0
475 31.12 -10.21 01 -1.0 -9.9 24.4 14.0 509.0
476 31.25 -10.10 01 -0.7 -6.0 24.0 14.5 -99.0
477 31.43 -11.90 01 -1.7 -49.0 -9.9 0.0 500.0

Debugging access violation error: writing to 2071E05A0 instead of 3071E05A0

Final edit:
Some users on the silverfrost forums directed me very helpfully, to a simplification of the code and a solution.
The issue can be replicated using the following code:
PROGRAM ML14ERROR
INTEGER :: origzn, destzn
INTEGER,PARAMETER :: MXZMA = 1713, LXTZN = 1714, MXAV = 182
INTEGER,PARAMETER :: JTMPREL = 1003, av = 1
REAL(KIND=2) :: RANDOM#
REAL,dimension (1:mxav,lxtzn,lxtzn,JTMPREL:JTMPREL):: znzndaav
DO origzn=1,lxtzn
DO destzn=1,lxtzn
znzndaav(av,origzn,destzn,JTMPREL) = RANDOM#()
END DO
END DO
DO origzn=1,mxzma
DO destzn=1,mxzma
! This is where the error occurs
znzndaav(av,origzn,lxtzn,JTMPREL)=
$ znzndaav(av,origzn,lxtzn,JTMPREL)+
$ znzndaav(av,origzn,destzn,JTMPREL)
ENDDO
ENDDO
WRITE(6,*)'No errors'
END PROGRAM
The issue only arises when MXAV>182, which suggests a memory issue. Indeed, multiplying out the dimensions: 183 * 1714 * 1714 * 4 yields >2GB, exceeding the stack size.
A solution would be to use the heap as follows (Fortan 95):
PROGRAM ML14ERROR
INTEGER :: origzn, destzn
INTEGER,PARAMETER :: MXZMA = 1713, LXTZN = 1714, MXAV = 191
INTEGER,PARAMETER :: JTMPREL = 1003, av = 1
REAL(KIND=2) :: RANDOM#
REAL,allocatable :: znzndaav(:,:,:,:)
ALLOCATE( znzndaav(1:mxav,lxtzn,lxtzn,JTMPREL:JTMPREL) )
DO origzn=1,lxtzn
DO destzn=1,lxtzn
znzndaav(av,origzn,destzn,JTMPREL) = RANDOM#()
END DO
END DO
DO origzn=1,mxzma
DO destzn=1,mxzma
! This is where the error occurs
znzndaav(av,origzn,lxtzn,JTMPREL)= &
& znzndaav(av,origzn,lxtzn,JTMPREL)+ &
& znzndaav(av,origzn,destzn,JTMPREL)
ENDDO
ENDDO
DEALLOCATE(znzndaav)
WRITE(6,*)'No errors'
END PROGRAM
Once we do this, we can allocate more than 2GB and the array works fine. The program this small section of code stems from is a few years old, and we've only just now run into the issue because a model we've built is many times larger than any before. As Fortran 77 doesn't allow ALLOCATABLE arrays, we must either reduce stack usage, or port the code - or seek another optimisation.
Edited to add:
I have now put together a git repo which contains reproducible code.
Overview
I have a program that works fine when compiled to 32-bit, but presents an access violation error when compiled and run in 64-bit.
I'm using the Silverfrost Fortran compiler, FTN95 v8.51, though this issue occurs using v8.40 and v8.50.
Sample code
! .\relocmon.inc
INTEGER JTMPREL
PARAMETER(JTMPREL=1003)
REAL znda(lxtzn,JTMPREL:JTMPREL)
REAL zndaav(1:mxav,lxtzn,JTMPREL:JTMPREL)
REAL,dimension (lxtzn,lxtzn,JTMPREL:JTMPREL) :: znznda
REAL mlrlsum(lxtzn,lxtzn)
REAL,dimension (1:mxav,lxtzn,lxtzn,JTMPREL:JTMPREL):: znzndaav
COMMON /DDMON/ znda, znznda, mlrlsum,znzndaav, zndaav
! EOF .\relocmon.inc
! .\relocmon.inc with values
INTEGER JTMPREL
PARAMETER(JTMPREL=1003)
REAL znda(1714,JTMPREL:JTMPREL)
REAL zndaav(1:191,1714,JTMPREL:JTMPREL)
REAL,dimension (1714,1714,JTMPREL:JTMPREL) :: znznda
REAL mlrlsum(1714,1714)
REAL,dimension (1:191,1714,1714,JTMPREL:JTMPREL):: znzndaav
COMMON /DDMON/ znda, znznda, mlrlsum,znzndaav, zndaav
! EOF .\relocmon.inc
! .\main.for
INCLUDE 'relocmon.inc'
REAL,save,dimension(lxtzn,lxtzn,mxav) :: ddfuncval
DO origzn=1,mxzma
IF( zonedef(origzn,JZUSE) )THEN
DO destzn=1,mxzma
IF (zonedef(destzn,JZUSE)) THEN
znznda(origzn,destzn,JTMPREL)=znda(destzn,JTMPREL)*
$ ddfuncval(origzn,destzn,av)
znznda(origzn,lxtzn,JTMPREL)=znznda(origzn,lxtzn,JTMPREL)
$ +znznda(origzn,destzn,JTMPREL)
znzndaav(av,origzn,destzn,JTMPREL)=zndaav(av,destzn,JTMPREL)*
$ ddfuncval(origzn,destzn,av)
! LINE 309 -- where error occurs
znzndaav(av,origzn,lxtzn,JTMPREL)=
$ znzndaav(av,origzn,lxtzn,JTMPREL)
$ +znzndaav(av,origzn,destzn,JTMPREL)
ENDIF
ENDDO
ENDIF
ENDDO
! EOF .\main.for
NB the function zonedef simply checks that a zone is valid for the calculation we want to undertake. This function returns a logical.
Debugging
As I mentioned initially, the 32-bit compiled version of this program works fine. When attempting to run the 64-bit version, the output of the first loop is this:
from sdbg64.exe:
Error: Access Violation reading address
0x00000002071E05A0
main.for: 309
write exception to file:
Access violation (c0000005) at address 43a1f4
Within file ml14.exe
in main in line 309, at address 2b84
RAX = 0000000000000001 RBX = 000000027fff704c RCX = 000000000285e6b8 RDX = 00000002802296cc
RBP = 0000000000400000 RSI = 000000029ba3ad6c RDI = 0000000307695374 RSP = 000000000285be70
R8 = 0000000307695374 R9 = 00000002ffff5040 R10 = 000000029ba3ad6c R11 = 000000030731f0dc
R12 = 000000027fff5584 R13 = 00000002802296cc R14 = 000000028169f3ec R15 = 0000000281660928
43a1f4) addss XMM11,[85b401b4++R14]
For the rest of this... please bear with me. I'm not a trained software engineer or fortran developer by any stretch, so I'm stabbing in the dark a little to troubleshoot.
The value for ZNZNDAAV(1,337,337,1003) is 2.241640, and this is being added to ZNZNDAAV(1,337,1714,1003). This tallies with register XMM11 as detailed in the exception output. This value is at address 000000029BA3BD60. The other value is at address 00000003071E05A0.
IIUC, in relocmon.inc we're setting COMMON /DDMON/ to contain the dimensioned array znzndaav, so if the software were working nominally, the address of the value in question would be within the /DDMON/ block. The address range for /DDMON/ is z'000000027FFF6040' - z'0000000307421150'. If my logic is correct, the violation occurs outside of this block.
It appears to me that the program is attempting to write to 00000002071E05A0 when it should be using 00000003071E05A0.
Can anyone help me determine why this would be the case? There appears to be something systematic about it - could it be mere coincidence?

Fortran compile error 764 nesting error

!subroutine No.10: to calculate positive capilary pressure required
subroutine Pcow_positive1(sigma_ow,R,alpha,b,teta_ow,Pcow_positive,r1,time)
implicit none
!dummy argument declarations
double precision,intent(in)::sigma_ow
double precision,intent(in)::R
double precision,intent(in)::alpha
double precision,intent(in)::b
double precision,intent(in)::teta_ow
double precision,intent(out)::Pcow_positive
double precision,intent(out)::r1
double precision::omega_eff
double precision::A_eff
double precision::beta
double precision::Pcow
double precision::r2
double precision::error
double precision::error1
double precision::abeta
integer,intent(out)::time
!calculate Pcow_positive
time=0
r1=R
700 if (time>1500) then
goto 950
else
abeta=((b*(sin(alpha)))/(r1))
if (abeta>1.0) then
goto 900
else
end if
beta=asin(abeta)
time=time+1
A_eff=(((R**2.0)/(2.0*tan(alpha))))-(((r1)*(b)*(sin(alpha+beta)))/2.0) &
+(((((r1)**2)*(beta))/2.0))
omega_eff=(((((R)*(1.0/(tan(alpha))))-b)*(cos(teta_ow)))+((r1*beta)))
Pcow=(((sigma_ow)*(omega_eff))/(A_eff))
r2=(sigma_ow)/(Pcow)
error=abs(r2-r1)
error1=abs((sigma_ow/r2)-(sigma_ow/r1))
if (error<=0.01 .or. error1<=0.01) then
goto 800
else
r1=r2
goto 700
end if
800 r1=r2
Pcow_positive=Pcow
goto 1000
900 r1=(b*(sin(alpha)))
Pcow_positive=(sigma_ow)/(r1)
goto 1000
950 r1=(sigma_ow)/(0.0005)
Pcow_positive = 0.0005
1000 end subroutine Pcow_positive1
When I compile the code I get an error message at end subroutine Pcow_positive1 which I cannot fix.
Any help is greatly appreciated.
Compile error: error 764 - Nesting error - the block IF construct on line 4079 has not been terminated
line 4079 :
700 if (time>1500) then
There's a few problems with this code. The most immediate is that you are missing an end if. You don't see this because, as noted, you haven't consistently indented your code. Your editor should do this automatically for you and would make spotting this very easy to spot - I cut and paste your code into emacs, auto indented the subprogram and the problem was clear. However where the endif should go was not, and so in what follows I've had to guess where to put it, and as you haven't supplied a complete program it's difficult to test what I have done, but even if I have made a mistake I hope the ideas behind what I have done is clear.
Anyway the next issue is DON'T USE GOTO! There's very rarely any need and it usually leads, as here, to confusing, so called spaghetti code. Instead learn your control structures and use them. A do loop and a few EXITs will tidy this up nicely.
Next all your constants are single precision. Yet all your variables are double precision. As a result your routine will not be as precise as you want. In a double precision code if you see 1.0 with no other qualifier there is almost always something wrong.
So how to fix that. Well Double Precision is so 1980s, so instead learn about kinds, covered in detail any number of times on stackoverflow, or look in your Fortran book (you do have one?) and use them. Anyway putting this all together with the above caveat (and also that I've only spent 5 mins on this, in practice I would tidy further but breakfast is calling) I would write your routine something like
!subroutine No.10: to calculate positive capilary pressure required
Subroutine Pcow_positive1(sigma_ow,R,alpha,b,teta_ow,Pcow_positive,r1,time)
Implicit None
!dummy argument declarations
Integer, Parameter :: wp = Selected_real_kind( 12, 70 )
Real( wp ),Intent(in)::sigma_ow
Real( wp ),Intent(in)::R
Real( wp ),Intent(in)::alpha
Real( wp ),Intent(in)::b
Real( wp ),Intent(in)::teta_ow
Real( wp ),Intent(out)::Pcow_positive
Real( wp ),Intent(out)::r1
Real( wp )::omega_eff
Real( wp )::A_eff
Real( wp )::beta
Real( wp )::Pcow
Real( wp )::r2
Real( wp )::error
Real( wp )::error1
Real( wp )::abeta
Integer,Intent(out)::time
!calculate Pcow_positive
time=0
r1=R
Do
If (time>1500) Then
r1=(sigma_ow)/(0.0005_wp)
Pcow_positive = 0.0005_wp
Exit
End If
abeta=((b*(Sin(alpha)))/(r1))
If (abeta>1.0_wp) Then
r1=(b*(Sin(alpha)))
Pcow_positive=(sigma_ow)/(r1)
Exit
Else
End If
beta=Asin(abeta)
time=time+1
A_eff=(((R**2.0_wp)/(2.0_wp*Tan(alpha))))-(((r1)*(b)*(Sin(alpha+beta)))/2.0_wp) &
+(((((r1)**2)*(beta))/2.0_wp))
omega_eff=(((((R)*(1.0_wp/(Tan(alpha))))-b)*(Cos(teta_ow)))+((r1*beta)))
Pcow=(((sigma_ow)*(omega_eff))/(A_eff))
r2=(sigma_ow)/(Pcow)
error=Abs(r2-r1)
error1=Abs((sigma_ow/r2)-(sigma_ow/r1))
r1=r2
If (error<=0.01_wp .Or. error1<=0.01_wp) Then
Pcow_positive=Pcow
Exit
End If
End Do
End Subroutine Pcow_positive1

Solve error: Fortran runtime error: Bad integer for item 0 in list input

I have recently changed my f90 editor to CodeBlocks for Mac OS X, and when I try to open a file located in the project folder to read the data, the next error message appears on screen when the code is run:
Fortran runtime error: Bad integer for item 0 in list input
I have introduced the same code I used to write in Windows 7 using the intel compiler for fortran and Visual Studio.
The code itself is:
subroutine read_input_data
use input_data
implicit none
integer i,j
open(UNIT=5, FILE='lifting_line_input_data.txt', STATUS='old', FORM='formatted', ACCESS='sequential')
read(5,*) C
read(5,*) U
read(5,*) alpha
read(5,*) rho
read(5,*) wake_length
read(5,*) wake_eps
read(5,*) n_chord
read(5,*) n_twist
if (n_chord .GE. n_twist ) then
i = n_chord
else
i = n_twist
end if
allocate(chord_twist(5,i))
do j = 1, i
read(5,*) chord_twist(:,j)
end do
close(5)
end subroutine read_input_data
Could you help me to solve this problem? Thank you very much.
PD. the data file is obtain from an Excel sheet saved as a .txt delimited by tabulations
! LIFTING-LINE WING
! Number of panels
6
! Free stream speed [m/s]
50
! Angle of attack [rad]
0.15
! Air density [kg/m^3]
1.225
! Wake length [m]
100
! Convergence parameter
0.01
! Number of data points given for the chord distribution
2
! Number of data points given for the twist distribution
2
! Y coord [m] ! X_LE [m] ! X_TE [m] ! Y coord [m] ! Twist [rad]
0 0 2 0 0
10 0 0.5 10 0.052359878
PD2. I have change the format of the .txt file to make it equal to the input files I had used in Visual Studio. Now the file is:
6 ! Number of panels
50 ! Free stream speed [m/s]
0.15 ! Angle of attack [rad]
1.225 ! Air density [kg/m^3]
100 ! Wake length [m]
0.01 ! Convergence parameter
2 ! Number of data points given for the chord distribution
2 ! Number of data points given for the twist distribution
0 0 2 0 0 ! Y coord [m] ! X_LE [m] ! X_TE [m] ! Y coord [m] !Twist [rad]
10 0 0.5 10 0.052359878
And now the error given at the terminal is that the file is not found. As I am a beginner in CodeBlocks, I will explain what I have done step by step because I do not find where I am wrong and I am starting to get desperate:
New Project -> Fortran application -> I indicate where I want to create the project file.
I remove the main.f95 file and I add the .f90 file with the code.
I write the code.
I save the .txt file in the same folder than all the files of the Project.
When I run the code it appears the error message of file not found.
The code is:
!************************************************
subroutine read_input_data
use input_data
implicit none
integer i,j
open(UNIT=10, FILE='lifting_line_wing_input.txt', STATUS='old', ACCESS='sequential')
read(10,*) C
read(10,*) U
read(10,*) alpha
read(10,*) rho
read(10,*) wake_length
read(10,*) wake_eps
read(10,*) n_chord
read(10,*) n_twist
if (n_chord .GE. n_twist ) then
i = n_chord
else
i = n_twist
end if
allocate(chord_twist(5,i))
do j = 1, i
read(10,*) chord_twist(:,j)
end do
close(10)
end subroutine read_input_data
!************************************************
Thank you very much for your time and help
This looks like your old system did something non-standard with exclamation marks on list-directed input.
Try reformatting your input data like
6 / number of panels
(the slash will terminate the READ).
i don't believe any fortran compiler ever automagically handled those comments.
If you want to read this file the way it is, one approach is to make each read handle the error, eg,
integer ios
ios = 1
do while(ios.ne.0)
read(unit,*,iostat=ios)c
end do
ios=1
do while(ios.ne.0)
read(unit,*,iostat=ios)u
end do
etc..
if its a one-off you could just edit the file and delete all the comments as well.