Why is DATE_AND_TIME integer result printed with spaces and how can I trim them? [duplicate] - formatting

This question already has answers here:
Smart printing of integers in fortran90
(1 answer)
Integer output formatting with print statement
(3 answers)
Output formatting: too much whitespace in gfortran
(2 answers)
Closed 5 years ago.
I'm attempting to get a time stamp with DATE_AND_TIME(), but Fortran returns an excessive amount of spaces, and I can't seem to trim these spaces because functions like TRIM() and ADJUST() work on strings only. Fortran appears to not have a function to convert integers to strings or at least I haven't been able to find one so far. I'd like to use the date-time stamp in a file name, so the included spaces are a problem. Can anyone show me how to remove these additional spaces?
Unfortunately I have to use Fortran, although I believe other versions of Fortran are acceptable.
Code:
program
character(8) :: date
character(10) :: time
character(5) :: zone
integer, dimension(8) :: values
zone = "+01"
call date_and_time(ZONE=zone,VALUES=values)
print *, "values(1)", values(1), "-"
Returns (including text before and after values(1) to show spacing):
values(1) 2017 -
As shown above there seem to be about 6 spaces before the number.
I'm compiling this in gfortran, version is: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)

Related

Date in Excel from SQL

I have an excel created from a comma-delimited text file originally from a .sql file with an SQL INSERT query.
In one of the columns I have: "Cast(0x123456AB...) As TIME
Obviously this is NOT the jsondate format... so no help from that question...
I replaced the Cast( and replaced the ") As TIME" with empty strings.
So now I have the time values in hexadecimal.
How do I convert them into Excel Time or Datetime?
OK Playing around with it showed me that it's exactly the same as the jquery date answer. You take the numeric portion starting with 0x.
Take the 10 digits AFTER the 0x. e.g. in A2: =MID(A1, 3, 10)
Turn it into hexadecimal e.g. in A3: = HEX2DEC(A2)
Divide by 86400 e.g. A4: =A3/86400
And add the result to 1/1/1970 date. e.g. = A5: =A4 + Date(1970, 1, 1)
Or in short:
=(hex2dec(mid(a1,numstart,10))/86400) + date(1970,1,1)
Replace numstart with the 1-starting index of the number.
e.g. 3 if you have a 12 or 13 digit number like 0x12345678AB and you'll get 12345678AB
This is similar to the Convert JSON Date /Date(1388624400000)/ to Date in Excel
Except that:
a. The question was answered wrong and wouldn't work. (I edited it)
b. The .sql file was retrieved in a stored procedure from the database via SQL. While in the question they were using jquery returned ajax data, which seemed to differ. Turns out they're the same number with a different format.
As an added remark, I had a space mark at the beginning of my hex number. Until I did the MID on it, I didn't see that.
Note: When using ajax returned formatted dates like /date:0x12345678ab/ you'll set numstart to 8. If hex2dec fails, try turning the hex string into uppercase
before calling hex2dec. To debug just put each formula in a separate cell, so you see what works and what doesn't.

How to write special characters in vb.net console [duplicate]

This question already has answers here:
How to represent Unicode character in VB.Net String literal?
(7 answers)
Is it possible to get a copyright symbol in C# Console application?
(5 answers)
Closed 6 years ago.
How do i output special characters to the console in visual basic. because simply putting console.writeline("Copyright symbol") outputs a C instead of the symbol. how can i fix this.
You can use the ChrW() function with the Unicode decimal value of the symbol you want to print, for the Copyright symbol it is 169.
console.writeline(ChrW(169))
You can find the Unicode decimal values for other symbols on this website.
The real copyright symbol is a unicode character. Use \u00A9 instead of C to print it out correctly.

What is significance of trailing "$" in some function names?

I recently looked at some vba source at Microsoft: [Convert Fractions to Decimal Values][1]
[1]: https://support.microsoft.com/en-us/kb/185424 and I noticed that several functions had a trailing "$", specifically trim$(), left$(), and mid$(). My question is: what does the "$" signify?
I downloaded the microsoft function and it ran correctly under Excel 2007.
Since VBA trim() works differently from the worksheet function trim(), I wrote a small program to compare the operation of the 3 possible trim() calls. I found that trim() and trim$() produced identical output. worksheetfunction.trim(), of course, produces output that has extraneous space characters removed from inside the string.
I am very curious about the trailing "$", and will be grateful for enlightenment!
Thank you,
Dave
To quote from https://bytes.com/topic/access/answers/196893-difference-between-left-left-function
Allen Browne
The trailing $ is a type declaration character for the String data type in
VBA.
The result returned from Left$() is a string, whereas Left() returns a
Variant.
You must use Left(), not Left$() if there is any chance of Null values,
since the Variant can be Null but the String cannot.
That post has a full worked example
The syntax is a left-over habit from ancient history. In early versions of Basic variables did not have to be declared but data types were implied by the name of the variable. Any variable ending with $ was a string and any variable ending with % was an integer.
FORTRAN had a similar convention: any variable starting with the letters I, J, K, L, M or N were integers, all others were real.

Some Strange Output Results in gfortran [duplicate]

This question already has answers here:
Why are floating point numbers inaccurate?
(5 answers)
Closed 8 years ago.
I must have fell asleep during output formatting day in Fortran class, because these results are perplexing me. Using gfortran 4.6,
this program
program f1
real :: x=65246514
write(*,*) x
end program f1
results in
65246512.0
This program
program f1
real :: x=65245.6525
write(*,*) x
end program f1
results in
65245.6523
Finally, this program
program f1
real :: x=65226545.6525
write(*,'(F14.4)') x
end program f1
results in
65226544.0000
Clearly, the console output is not what is being assigned to x. Is there some finite precision result coming in to cause this?
The issue is that the variable and constant are single precision and only have about 7 decimal digits available. Compare to:
program f1
use, intrinsic :: ISO_FORTRAN_ENV
implicit none
real :: x=65226545.6525
real (real64) :: y=65226545.6525_real64
write(*,'(F14.4)') x
write(*,'(F14.4)') y
end program f1
which uses a double-precision number via the ISO Fortran environment, specified as real64, i.e., 64 bits. real64 is also used on the constant, otherwise it will be evaluated as a single-precision constant, then stored in the double-precision variable y. (If you need even more digits, you can use quadrupole precision, real128.)

Correct termiology for documentation [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
The documentation below is for a module, which has now been "decommissioned"
and I'm writing it's replacement.
Before i write the replacement I want to get my terms right.
I know the terms are wrong in the documentation - it was hacked together quickly
so i could instruct a college working on the hardware side of this project on how to use a program I'ld made.
Full documentary can be found here for any who are interested (in so much as has been written and added to our wiki), the Website may only be available to certain IPS's (depends on you ISP - university internet connections are most likely to work), and the SVN repo is private.
So there are alot of terms that are wrong.
such as.
deliminators
formatted string containing value expressions (might now be wrong but is hard to say)
What are the correct terms for these.
And what other mistakes have I made
==== formatted string containing value expressions ====
Before I start on actual programs an explanation of:
"formatted string containing value expressions" and how to encode values in them.
The ''formatted string containing value expressions'' is at the core of doing low level transmission.
We know the decimal 65, hex 41, binary 0100 0001, and the ascii character 'A' all have the same binary representation, so to tell which we are using we have a series of deliminators - numbers preceded by:
# are decimal
$ are Hex
# are binary
No deliminator, then ascii.
Putting a sign indicator after the deliminator is optional. It is required if you want to send a negative number.
You may put muliple values in the same string.
eg: "a#21#1001111$-0F"
All values in a ''formatted string containing value expressions'' must be in the range -128 to 255 (inclusive) as they must fit in 8bytes (other values will cause an error). Negative numbers have the compliment of 2 representation for their binary form.
There are some problems with ascii - characters that can't be sent (in future versions this will be fixed by giving ascii a delineator and some more code to make that deliminator work, I think).
Characters that can't be sent:
* The delineator characters: $##
* Numbers written immediately after a value that could have contained those digits:
* 0,1,2,3,4,5,6,7,8,9 for decimal
* 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,A,B,C,D,E,F for hex
* 0,1 for binary
For a start, deliminator would probably be delimiter, although I notice your text has both delineator and deliminator in it - perhaps deliminator is a special delimiter/terminator combination :-)
However, a delimiter is usually used to separate fields and is usually present no matter what. What you have is an optional prefix which dictates the following field type. So I would probably call that a "prefix" or "type prefix" instead.
The "formatted string containing value expressions" I would just call a "value expression string" or "value string" to change it to a shorter form.
One other possible problem:
must be in the range -128 to 255 (inclusive) as they must fit in 8bytes
I think you mean 8 bits.
Try something like the following:
==== Value string encoding ====
The value string is at the core of the data used for low level
transmissions.
Within the value string the following refixes are used:
# decimal
$ Hex
# binary
No prefix - ASCII.
An optional sign may be included after the delimiter for negative numbers.
Negative numbers are represented using twos complement.
The value string may contain multiple values:
eg: "a#21#1001111$-0F"
All elements of the value string must represent an 8bit value and must
be in the range -128 to 255
When using ASCII representation the following characters that can't be sent
* The delineator characters: $## (use prefixed hex value.)
* Numbers written immediately after a value that could have
contained those digits:
* 0,1,2,3,4,5,6,7,8,9 for decimal
* 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,A,B,C,D,E,F for hex
* 0,1 for binary