Format specifier in Fortran - fortran77

Fortran question: Which is the correct format statement, format('CRDET',2i5,1p3e12.4) or format('CRDET',2i5,1p,3e12.4)? The difference is the comma separator between the last two arguments.

Going out on a limb, reading standards but not testing it.. It seems both forms are the same and the P applies to all 3 of the E's
1) It (P) applies to all subsequently interpreted F, E, D, and G edit descriptors until another scale factor is encountered,
2) The comma used to separate list items in the list flist may be omitted as follows:
** Between a P edit descriptor and an immediately following F, E, D, or G edit descriptor
I suppose the comma form is safer as its not clear if the repeated edit descriptor falls under point 2..

Related

How to find and replace the first occurrence of any single text character (Excel)

I need to replace or substitute the first instance of a single text character in an excel row.
current: B01 TEST TEST TEST A W B 0 A
expected result where first "A" that is on its own is replaced with "|": B01 TEST TEST TEST | W B 0 A
The issue is, each row has a character that is segmented on its own, but they are all different (some A, some W, some R, etc). Which function can I use to look for the first instance of a single text character surrounded by spaces?
In Office 365 you could use =AGGREGATE(15,6,FIND(" "&CHAR(SEQUENCE(26,,65))&" ",A19),1)
Older version: =AGGREGATE(15,6,FIND(" "&{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}&" ",A19),1)
Edit: better version suggested by Mayukh
=AGGREGATE (15,6,FIND(" "&CHAR(ROW($65:$90))&" ",A19),1)
This uses Office 365 LET and SEQUENCE and is not dependent on it being a capital character. It will replace the first character whether alpha, numeric or special that has a space on either side of it with the |:
=LET(rng,A1,
sq,SEQUENCE(LEN(rng)-3),
md,MID(rng,sq,3),
lft,LEFT(md),
rt,RIGHT(md),
REPLACE(rng,MIN(IF((lft=" ")*(rt=" "),sq+1)),1,"|"))

Excel Return 0,1 or 2 if cell equals A, B or C

I have a cell (Say B16) that has a dropdown list with three options, depending on which one is picked I would like Cell D16 to return a value depending, i.e. if you Pick A return 0, B returns 1 and C returns 2.
I have tried multiple IF, OR, LOOKUP but nothing is working.
Any help would be fantastic.
Make a hidden sheet called mapping with the following:
Now it's just =VLOOKUP(B16,mapping!A:B,2,0). The advantage of this over the nested IF solution is that it's trivial to add more options and easier to read / edit in my option.
also you can use column A of mapping to populate your dropdown list.
Personally I don't like nested IFs as they are hard to read. If you want the transformation to be to {0, 1, 2} then you could use
=CODE(B16)-CODE("A")
This is idiomatic in programming languages using ASCII encoding. You can generalise this if you use CHOOSE. If you want {a, b, c} then use
=CHOOSE(1 + CODE(E3) - CODE("A"), a, b, c)
where a, b, and c are the values that you want: {0, 1, 3} in your case.
How about:
=IF(B16="A",1,IF(B16="B",2,IF(B16="C",3,"")))
This is for a return of {1,2,3}, modify for any three values you would like.

How to duplicate the lines and replace multiple string in ONE Tab Separated File

I have a incoming file like (in.txt) which is a Tab Separated File and NO Header line in it.
I want to duplicated each row TWO times and do the replacement (base on the rules).
I am new in *nux, i am totally no idea what tools can help me to do this.
The Incoming file (in.txt. Separated by Tab(\t))
A B C D E F G H
1 855211046 2/3/2015 $170.00 4154245328852953 328573 1809 CC786875287728777
2 855211046 3/3/2015 $100.10 5524415875875844 822409 1809 CC150330106885244
3 855211046 30/3/2015 $105.00 4875875852875211 445092 1809 CC456387885245062
etc.
The Expected Outcome (Outcome.txt)
^2.{32}(855211046000).{8}(150302)
^5(855211046000).{7}(4154245328852953 ).{60}(150302)(328573).{10}\s{1}(000000017000)
^5(855211046000).{7}(4154245328852953 ).{60}(150302)(328573).{122}(000000017000)
^2.{32}(855211046000).{8}(150303)
^5(855211046000).{7}(5524415875875844 ).{60}(150303)(822409).{10}\s{1}(000000010010)
^5(855211046000).{7}(5524415875875844 ).{60}(150303)(822409).{122}(000000010010)
^2.{32}(855211046000).{8}(150330)
^5(855211046000).{7}(4875875852875211 ).{60}(150330)(445092).{10}\s{1}(000000010500)
^5(855211046000).{7}(4875875852875211 ).{60}(150330)(445092).{122}(000000010500)
Rules
*1st record*
^2.{9}.{7}.{16}([Column B's data, 0 fill right till the position 12]).{8}([Column C's data but reformat to YYMMDD format])
^5([Column B's data, 0 fill right till the position 18]).{7}([Column E's data, SPACE fill right till the position 19]).{60}([Column C's data but reformat to YYMMDD format])([Column F's data]).{10}\s{1}([Column D's data but remove $ sign and then multiplied by 100])
^5([Column B's data, 0 fill right till the position 18]).{7}([Column E's data, SPACE fill right till the position 19]).{60}([Column C's data but reformat to YYMMDD format])([Column F's data]).{122}([Column D's data but remove $ sign and then multiplied by 100])
*2nd record*
same as 1st
*3rd record*
same as 1st
Thanks a lot.
It is not difficult but require attention and some typewriting:
awk '
/./{
split($3,T,"/")
$3=sprintf("%d%02d%02d",T[3]-2000,T[2],T[1])
sub("\\$","",$4);$4*=100
printf "^2.{9}.{7}.{16}(%d%0."12-length($2)"d).{8}(%d)\n",$2,0,$3
printf "^5(%d%0."18-length($2)"d).{7}(%-19d).{60}(%d)(%d).{10}\\s{1}(%012d)\n",$2,0,$5,$3,$6,$4
...
}' in.txt >Outcome.txt
I am sure that you easyly add printf for 3rd line output according to above example.

Mutually dependent variables in a spreadsheet

Assume I have an input variable x and three parameters a,b,c such that:
Given b we have c = f(x,a,b) for some (known) function f
Given c we have b = g(x,a,c) for some (known, different) function g.
I want to model this in a spreadsheet (Excel for instance). More precisely, if the user provides x,a and b then c will be evaluated and if c is given then b will be evaluated. It seems like this cannot be achieved directly, since a cell can hold either a value or a formula.
Is there a canonical way to do this? If not, what would be a best-practice workaround (probably some VBA magic)?
You can separate input fields from the calculated values and add some validation that only one of the mutually exclusive field is used, e.g.:
in my example, I used following conditional formatting to highlight invalid input:
=AND($B$4<>"", $B$5<>"")
and I used following the formulas for calculated values:
=B2
=B3
=IF(AND($B$4<>"", $B$5<>""), "#ERROR: only 1 value can be specified",
IF($B$4<>"", $B$4, $B$5-1))
=IF(AND($B$4<>"", $B$5<>""), "#ERROR: only 1 value can be specified",
IF($B$5<>"", $B$5, $B$4+1))
more generally:
=if(error_condition, error_message, if(b_is_not_empty, b, g(x,a,c)))

Adding annotated values in xmgrace using batch mode

I need some help adding a series of annotated string values to my xy plot in Grace-5.1.22 when using a batch script to plot the graph.
I have two columns of data: a series of x values and a series of y values, and then a third column containing a number for each data point. If I want to plot all numbers in the z column as annotated values then I am able to import the data into grace using the command:
BLOCK XYZ "1:2:3"
S0 AVALUE ON
S0 AVALUE TYPE "Z"
However, since where data points are bunched together the annotations are not clear, I don't want to display the annotation on EVERY point and therefore have replaced some values in the z column with "" to leave the corresponding annotation blank. This means that the 3rd column is now a string and the above commands will not work.
This website http://plasma-gate.weizmann.ac.il/Xmgr/doc/commands.html suggests that I should be able to import the data as:
BLOCK XYSTRING "1:2:3"
However, unfortunately this type was removed from versions 5.0.3 onwards http://plasma-gate.weizmann.ac.il/Grace/doc/CHANGES.html
Instead the documentation now says that "any set type now may have an additional column of text strings associated" however the command:
BLOCK XY "1:2:3"
does not load any data giving the error: "Too many columns scanned in column string".
I am able to import string type annotated values into xy data using the GUI by:
Data>>Import>>ASCII>>"filename.dat">>"load as BLOCK DATA">>"strings from column 3"
however since I would like to plot the same graph many times for different data sets I would like a way of automating this process and not using the GUI.
Sorry for the for the long question but I would be very grateful if anyone could help me.
I know it's old but I had the same question and after 3 hours of experimenting, I found a solution. Therefore I post it for future reference (since no answer currently exists elsewhere online).
If your "filename.dat" has the content format of (x y "string") or (x y z) then you can add to your batch file the following to read it and add the annotations:
READ XY "filename.dat"
s0 line type 1
s0 line linewidth 1
s0 line color 1
# Enable annotations
s0 avalue on
# Select type: 0=None,4=String,5=Z
s0 avalue type 5
s0 avalue color 1
s0 avalue char size 1.0000
s0 avalue offset 0.000000 , 0.000000
If you want to see more options for batch files, you can make a plot interactively with the gui and then save it as an .agr file. If you open this with a text editor, you have all the available commands there.
This is not a direct answer to your question but it may give you a hint.
I ran accross the same error message with the following syntax :
gracebat -graph 0 -settype bardy -block mydatafile -bxy 0:5:6:2
(the last column intended to be the optional string column)
And this one proved to be the right one :
gracebat -graph 0 -settype bardy -block mydatafile -bxy 0:5:6:{2}
So I guess you need to add curly braces.

Resources