DATA declaration in Fortran [duplicate] - fortran

This question already has an answer here:
what does DATA TKX/2HKX/ mean in fortran?
(1 answer)
Closed 1 year ago.
Does anyone know the meaning of 4HEND in the following line which comes from an old Fortran code?
DATA XHEND / 4HEND /

4HEND is a Hollerith code to represent the character string "END ". In very old FORTRAN, the variable XHEND might even be a 4-byte integer or real used to hold character data. If implicit typing was in effect in this program, XHEND would have been a real. Another recent question with Hollerith codes: Writing both characters and digits in an array

It replaces assignment
XHEND='END '

Related

simple fortran program to print back what it reads [duplicate]

This question already has answers here:
Using a deferred-length character string to read user input
(4 answers)
Reading a string with spaces in Fortran
(2 answers)
Reading a character string of unknown length
(4 answers)
How to read text files with possibly very long lines in Fortran
(2 answers)
Closed last month.
It's a very simple task, but there are two problems with my current implementation.
I want it to read a whole line. It currently only reads the first few characters if they are separated by space. I think this can be fixed with a custom format, but I don't know what to use.
Fortran needs to know how much to allocate and with my current implementation it can only read 10 characters. I want it to read without a limit. The only way that I know that can fix this right now is asking the user, how many characters they want to be read, but other programming languages can do this without it and I don't want to ask the user for additional things.
program main
implicit none
character(:), allocatable :: name
allocate(character(10) :: name)
read *, name
print *, name
deallocate(name)
end program main

Variable dependent formatting in Fortran90 [duplicate]

This question already has answers here:
Format string for output dependent on a variable
(4 answers)
Closed 2 years ago.
I am trying to understand "variable dependent formatting", specifically where the repeat count in FORTRAN format statement is a variable instead of a fixed number. I have gone through one of the similar questions here, where this is addressed by defining a format variable. I have tried to implement a similar type of test code but I get a run-time error saying "Fortran runtime error: Missing initial left parenthesis in format". I am attaching the code that I have. Could you please let me know where I am going wrong.
Thank you
program main
implicit none
integer num,i
real,dimension(:),allocatable :: logar
character(len = 100) fmt
print*, "enter any number"
read*,num
allocate(logar(num))
do i = 1,num
logar(i) = log(i/3.14)
end do
open(unit=200,file="num.txt",status="unknown")
write(fmt,'( I4,"(f10.5)" )') num
print*,fmt
write(200,fmt) (logar(i),i=1,num)
end program
Change
write(fmt,'( I4,"(f10.5)" )') num
to
write(fmt,'(a, I4,"(f10.5)",a )') '(', num, ')'
Else, you are missing the parenthesis in fmt. Formats strings are delimited by parentheses.

Fortran: user defined integer in file name of "open" statement [duplicate]

This question already has answers here:
Writing multiple output files in Fortran
(2 answers)
Closed 8 years ago.
I want to open a file in fortran with file name "controlinputs.12.dat" and then write into that file. The digit "12" is user defined variable whose value is stored in another variable "k". I have tried following and failed.
k=12
open(10,filename='controlinputs.',k,'.dat')
Tried storing the name in character and then using character to open file.
k=12
fname='controlinputs.',k,'.dat'
open(10,filaname=fname)
This was very simple. I didn't knew how to concatenate characters. I was reading the integer 12 from a file so I saved it in character type then simply used following.
character::k*5
open(10,filename='controlinputs.'//trim(k)//'.dat')

How does C++ understand two letter characters [duplicate]

This question already has answers here:
Multicharacter literal in C and C++
(6 answers)
What do single quotes do in C++ when used on multiple characters?
(5 answers)
Closed 9 years ago.
C++ seems to allow up to four characters to be held in single quotes, such as:
char c = 'abcd';
but at runtime, only the last value ('d') seems to be actually stored away. This behavior seems to happen for pairs of two, three, or four (at five the compiler finally calls uncle). But what's the deal with this design? I don't really see the logic in it.

What is a "literal" in C++? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What does the word “literal” mean?
Often when reading literature about C++, I encounter the word "literal". It is a bit unclear to me what exactly this term means in C++.
A literal is some data that's presented directly in the code, rather than indirectly through a variable or function call.
Here are some examples, one per line:
42
128
3.1415
'a'
"hello world"
The data constituting a literal cannot be modified by a program, but it may be copied into a variable for further use:
int a = 42; // creates variable `a` with the same value as the literal `42`
This concept is by no means unique to C++.
The term "literal" comes from the fact that you've written data literally into your program, i.e. exactly as written, not "hidden" behind a variable name.
Wikipedia gives you quickly this about literals.
In your C or C++ source code, Things like 1234, nullptr (in recent C++), "abcd" are literals.