This question already has answers here:
How to convert a List<T?> to List<T> in null safe Dart?
(2 answers)
type 'List<Widget?>' is not a subtype of type 'List<Widget>' in type cast
(3 answers)
Closed 1 year ago.
I have a List of optional DateTimes. So the List can actually have null values inside. But now I need to remove all these null-values, to get a List<DateTime, instead of a List<DateTime?>. How is that possible?
I tried it like this:
List<DateTime> timesOfDayNotNull = timesOfDay.where((time) => time != null).toList();
But this is giving me:
A value of type 'List<DateTime?>' can't be assigned to a variable of type 'List'.
What am I missing here? Any help is appreciated!
This question already has an answer here:
Cmake list-get command
(1 answer)
Closed 3 years ago.
I cannot extract an item from a list. The following code replicates my issue:
set(TEST_LIST "aaa" "bbb" "ccc")
list(GET ${TEST_LIST} 1 TEST_ITEM)
message("TEST_ITEM = ${TEST_ITEM}") # Expect: bbb
What I get is:
TEST_ITEM = NOTFOUND
The index 1 should point to the second element bbb. What am I doing wrong?
It works without braces and dollars:
list(GET TEST_LIST 1 TEST_ITEM)
This question already has answers here:
Line continuation of strings in Fortran
(4 answers)
Closed 4 years ago.
I have this code in FORTRAN 77 (I have to use this because it is used as a subroutine for my Abaqus program) where I am asking the subroutine to print my stresses and strain results, for each element and after each time increment, in a particular place. Now, my directory path is long (because of several reasons). Therefore, I have to write the path to the directory in two lines since FORTRAN 77 only recognizes anything written between columns 6 to 77 (I believe!).
Now, I have tried many things!
I have put & symbol at column 6 on the next line, a number (like 1) at column 6 on the next line, and even a star symbol (*) at the same place!
However, I keep getting error# 5082!
Here is the part of the code that is not being accepted in ifort compiler:
subroutine uvarm(uvar,direct,t,time,dtime,cmname,orname,
1 nuvarm,noel,npt,layer,kspt,kstep,kinc,ndi,nshr,coord,
2 jmac,jmatyp,matlayo,laccfla)
include 'aba_param.inc'
character*80 cmname, orname
character*3 flgray(15)
character*80 file1, file2
dimension uvar(nuvarm),direct(3,3),t(3,3),time(2)
dimension array(15),jarray(15),jmac(*),jmatyp(*),coord(*)
C integer i
call getvrm('E',array,jarray,flgray,jrcd,jmac,jmatyp,
1 matlayo,laccfla)
uvar(1) = array(1)
uvar(2) = array(2)
uvar(3) = array(4)
call getvrm('S',array,jarray,flgray,jrcd,jmac,jmatyp,
1 matlayo,laccfla)
uvar(4) = array(1)
uvar(5) = array(2)
uvar(6) = array(4)
file1 = '/gpfs/work/m/mfg5310/fracture/ResearchWork'
1 '/fracture_subroutines/frac_in_mid_Mode2_case1_strains.txt'
file2 = '/gpfs/work/m/mfg5310/fracture/ResearchWork'
2 '/fracture_subroutines/frac_in_mid_Mode2_case1_stress.txt'
open(unit=101,file=file1)
open(unit=103,file=file2)
write(101,350) uvar(1),uvar(2),uvar(3),coord(1),coord(2)
write(103,350) uvar(4),uvar(5),uvar(6),coord(1),coord(2)
350 format(e12.5,6x,e12.5,6x,e12.5,6x,e12.5,6x,e12.5)
C close(unit=101)
C close(unit=103)
return
end
What should I do?
I know I can always shorten the path so that the entire directory fits in one line. But for two reasons, I want to know how to continue the string into the next line in Fortran 77:
Reason 1: I just really want to know this.
Reason 2: The files printed are more organized this way! I will be able to name the file exactly what I want to.
Simply use the Fortran string concatenation operator // like this
file1 = '/gpfs/work/m/mfg5310/fracture/ResearchWork'//
& '/fracture_subroutines/frac_in_mid_Mode2_case1_strains.txt'
REAL FUNCTION PHI(D)
COMMON FAC,DELTA,ER,T
DOW=2.*D/DELTA
TOW=4.*T/DELTA
DOWM=DOW-1.
DOWP=DOW+1.
IF(D.EQ.0.) GO TO 1
PHI=DOWM*ALOG(DOWM)-DOWP*ALOG(DOWP)
1-0.5*DOWM*ALOG(DOWM**2+TOW**2)
2+0.5*DOWP*ALOG(DOWP**2+TOW**2)
3-TOW*(ATAN(DOWM/TOW)-ATAN(DOWP/TOW))
PHI=PHI*FAC/2.
GO TO 2
PHI=FAC*(0.5*ALOG(1.+TOW*TOW)+TOW*ATAN(1./TOW))
CONTINUE
RETURN
END
My homework is to convert above code into Matlab .m file.
But I couldnt understand and I have never seen an implementation like this:
....
PHI=DOWM*ALOG(DOWM)-DOWP*ALOG(DOWP)
1-0.5*DOWM*ALOG(DOWM**2+TOW**2)
2+0.5*DOWP*ALOG(DOWP**2+TOW**2)
3-TOW*(ATAN(DOWM/TOW)-ATAN(DOWP/TOW))
...
There is not any line continuation mark! This is very confusing.
How should I convert these lines into Matlab code? I know Matlab but I dont know Fortran.
The PHI Calculation is in four lines, the second line is marked with 1, and so on ...
Those are the continuation marks you are looking for (1, 2, 3)
Your formula is:
PHI=DOWM*ALOG(DOWM)-DOWP*ALOG(DOWP)-0.5*DOWM*ALOG(DOWM**2+TOW**2)+0.5*DOWP*ALOG(DOWP**2+TOW**2)-TOW*(ATAN(DOWM/TOW)-ATAN(DOWP/TOW))
But remember that original Fortran can not understand characters form column 73 and up (only 1 to 72) that is why the use of continuation marks in column 6 (normally is asterisk, but numbers can be used too).
Also code only can be between columns 7 to 72, because columns 1 to 5 are reserved for labels.
My Guess is that label 1 is in front of the second definition of PHI, and the label 2 in front of the CONTINUE, this is how should look in Fortran
GO TO 2
1 PHI=FAC*(0.5*ALOG(1.+TOW*TOW)+TOW*ATAN(1./TOW))
2 CONTINUE
The code in Fortran should be something like this:
REAL FUNCTION PHI(D)
COMMON FAC,DELTA,ER,T
DOW=2.*D/DELTA
TOW=4.*T/DELTA
DOWM=DOW-1.
DOWP=DOW+1.
IF(D.EQ.0.) GO TO 1
PHI=DOWM*ALOG(DOWM)-DOWP*ALOG(DOWP)
1-0.5*DOWM*ALOG(DOWM**2+TOW**2)
2+0.5*DOWP*ALOG(DOWP**2+TOW**2)
3-TOW*(ATAN(DOWM/TOW)-ATAN(DOWP/TOW))
C
C Previous four (4) lines have this formula (C mark for comment)
C
C PHI=DOWM*ALOG(DOWM)-DOWP*ALOG(DOWP)-0.5*DOWM*ALOG(DOWM**2+TOW**2)+0.5*DOWP*ALOG(DOWP**2+TOW**2)-TOW*(ATAN(DOWM/TOW)-ATAN(DOWP/TOW))
C
PHI=PHI*FAC/2.
GO TO 2
1 PHI=FAC*(0.5*ALOG(1.+TOW*TOW)+TOW*ATAN(1./TOW))
2 CONTINUE
RETURN
END
This question already has answers here:
Format string dynamically [duplicate]
(5 answers)
Closed 8 years ago.
So I have this simple print statement:
print "%-10s %s" % ("test","string")
which prints the desired output:
test string
I'm trying to figure out the correct syntax for a case where the fill value is a variable. Example:
w = 10
print "%-s %s" % (w,"test","string")
So %-s should be replaced with what to accommodate the fill value?
If I remember it correctly, the syntax is similar to %-xs where x is replaced by a an int variable. I might be mistaken though.
Note
I know this question is probably duplicated since this is really elementary string formatting issue. However, after some time of searching for the right syntax I gave up.
I would be inclined to use str.format, instead:
>>> print "{:{width}}{}".format("test", "string", width=10)
test string
You could do this in two stages: First, create the proper format string, then use it to create the actual output. Use %d as a placeholder for the width and escape each other % as %%.
formatstring = "%%-%ds %%s" % w
print formatstring % ("test","string")
Or in one line:
print ("%%-%ds %%s" % w) % ("test","string")
Update: As pointed out by Martijn in the comments, you can also use * in the format string:
print "%-*s %s" % (w,"test","string")
From the documentation:
Minimum field width (optional). If specified as an '*' (asterisk), the actual width is read from the next element of the tuple in values, and the object to convert comes after the minimum field width and optional precision.