What does the format '(a,2(2x,3i4))' mean? - fortran

I am working with some code in Fortran where the format of writing out to some file is '(a,2(2x,3i4))'.
How do you break each part of this down to understand what it means?

a = character string of the length in the value
2( = group repeat of what's in the parentheses two times
2x = skip two columns
3i4 = 4-digit integer, left padded with blanks if needed, repeated three times

Related

matlab: truncate large text and append '...'

I have a large array of text (text, stored as cell-array), that I want to truncate in matlab, say for 5 characters. Truncating with regexprep is quite efficient, but now, I would love to append a '...' at the end of every truncated match (and only there).
(How) can this be achieved within MATLAB's regexprep?
>> text = {'123456780','1','12'}; %<- small representative sample
>> regexprep(text,'(^.{0,5})(.*)','$1') %capture first 5 characters or less in first group (and replace the text with first group captures)
ans =
1×3 cell array
{'12345'} {'1'} {'12'}
it should read:
ans =
1×3 cell array
{'12345...'} {'1'} {'12'}
You need to use
regexprep(text,'^(.{5}).+','$1...')
See the regex demo.
The main point is that you need to only trigger the replacement if a string is linger than five chars (else, you do not even need to truncate the string).
Note that regexprep returns the input string as is if there was no regex match found, thus you do not need to worry about strings that are zero to five chars long.
Details:
^ - start of string
(.{5}) - Capturing group 1 ($1): any five chars
.+ - any one or more chars, as many as possible.
Note that the string 12345... is in fact 8 characters long. You don't want to make the mistake of truncating 1234567 to 12345..., as the truncated version is longer and therefore shouldn't be truncated in the first place.
A solution that takes this into account is:
regexprep(text,'^(.{5}).{3}.+','$1...')
which will only truncate if there are more than 8 characters and, if so, will display the first 5 with the trailing ellipsis.

Remove parts of columns values with regex

I have a dataframe and in 2 columns i have to change values removing all that is not a number or ".". The final result should be only dotted numbers. thank you very much for those of you can help me. I attach how columns areenter image description here
The regex you're after is:
/[0-9.]+/
Explanation:
[0-9.] Looks for one character that is a digit or .
+ repeats last character unlimited times
let regex = /[0-9.]+/;
console.log("1.0.0".match(regex)); //["1.0.0"]
console.log("1.2.4".match(regex)); //["1.2.4"]
console.log("NaN".match(regex)); //[]
console.log("1.1".match(regex)); //["1.1"]
console.log("6.1.61.1".match(regex)); //["6.1.61.1"]
console.log("4.0.3 and up".match(regex)); //["4.0.3"]
This will match any combination of numbers and . of any character length.
For example:

Joining two data sets on a variable with different character length

I'm trying to join two data sets on a variable with different character lengths with the following code, but neither works and I'm not sure why.
FROM A AS ROLLACT
LEFT JOIN MALT.CUST AS ACCOUNT
/* ON (ROLLACT.ACCTNO, BEST.) = INPUT( ACCOUNT.ACCT_NO,BEST.) */
ON INPUT (ROLLACT.ACCTNO, 30.) = INPUT( ACCOUNT.ACCT_NO,30.)
In this case ROLLACT.ACCTNO is a character variable with length 30 and ACCT_NO is a character variable with length 19.
So I'm confused why I can't convert both to a specific length (using Input(30.)) with:
ON INPUT (ROLLACT.ACCTNO, 30.) = INPUT( ACCOUNT.ACCT_NO,30.)
I'm also trying to convert both into numeric with:
ON (ROLLACT.ACCTNO, BEST.) = INPUT( ACCOUNT.ACCT_NO,BEST.)
Does anyone have suggestions about how to do this within the Proc Sql step?
You do not need to do anything special to compare character strings of different lengths. SAS will ignore the trailing spaces. Obviously if the actual value of the longer variable has more than 19 characters it will never match the value that is limited to 19 characters.
The INPUT() function does not change the length. If is used to convert strings into values. If you use a numeric informat, as in your examples, then the result is a number. But you cannot convert a 30 digit string exactly into a number. SAS stores numbers as 8 byte floating point values so the maximum number of decimal digits of precision is 15.
a simple substr does the trick : ON (SUBSTR(ROLLACT.ACCTNO, 1,19)) = ACCOUNT.ACCT_NO

In sapscript, how do I trim/offset from the right of a string?

I have a need in SAPScript to trim a string from the right. There doesn't appear to be a function to accomplish this. &myfield+3& only trims from the left.
Is there a way to trim from the right? Can offset accept a negative value?
My ultimate goal was to take a number such as a quantity; 12.43 and convert that to: 001243.
6 characters long
padded left with zeroes
no special characters (decimals or thousands separators)
Ultimately I had to first define a field and do the intial number formatting:
/:DEFINE &myfield& = &qtyfield(.2CT)&
The above
sets the number to 2 decimal points (.2)
space compreession (C)
removes the thousands separator (T)
Then I call a function within our print routine to do the special character stripping as such:
/:PERFORM get_unformatted_value IN PROGRAM zbc_rle_ean128_label
/:USING &myfield&
/:CHANGING &myfield&
/:ENDPERFORM
Then I can do the final output as such:
/ &myfield(K6RF0)&
which:
Ignores any conversions (K)
Sets output length to 6 and right aligns it (6R)
and left pad with zeros (F0)
That seems to work for me. Hopefully this helps someone!

How to keep leading zero and add comma in openoffice calc formula?

I have 6 fields in a row in open office, the 1st is a word, the 2nd, 3rd, and 4th are a number with a leading zero, the 5th and 6th are regular numbers. How do I join them all together with a comma between them so that the leading zero stays?
Based on your comment about your numbers having a leading 0 in virtue of a custom number format, you need to incorporate TEXT() functions into your formula to retain (i.e., add) your leading 0s.
=CONCATENATE(A1,",",TEXT(B1,"0#####"),",",TEXT(C1,"0#####"),",",TEXT(D1,"0#####"),",",E1,",",F1)
Just be sure to include as many #'s as the max length of a number in that field.
Please try:
=A1&",0"&B1&",0"&C1&",0"&D1&","&E1&","&F1