Read .txt file value after a certain string (Matlab) - matlab

I'm trying to obtain the displacements of a node from an FEA .txt results file using matlab. I want to search for the node (e.g. 5151) and then read the displacements, the problem is the node is mentioned a couple of times before getting to the deformations.
The part of the results I'm interested in looks like this......
N O D E O U T P U T
THE FOLLOWING TABLE IS PRINTED FOR NODES BELONGING TO NODE SET ASSEMBLY_TIP_NODES
NODE FOOT- U1 U2 U3 UR1 UR2 UR3
NOTE
5101 2.6105E-03 -1.1943E-02 6.0023E-03 -8.6770E-02 -1.6432E-02 -1.1048E-02
5102 2.5224E-03 -1.1267E-02 5.6868E-03 -8.6763E-02 -1.6390E-02 -1.0943E-02
5103 2.4340E-03 -1.0589E-02 5.3709E-03 -8.6725E-02 -1.6269E-02 -1.0666E-02
5104 2.3455E-03 -9.9121E-03 5.0549E-03 -8.6542E-02 -1.6052E-02 -1.0267E-02
5105 2.2575E-03 -9.2374E-03 4.7396E-03 -8.6041E-02 -1.5708E-02 -9.7843E-03
5106 2.1710E-03 -8.5682E-03 4.4262E-03 -8.5111E-02 -1.5217E-02 -9.2317E-03
5107 2.0869E-03 -7.9085E-03 4.1164E-03 -8.3688E-02 -1.4585E-02 -8.6334E-03
5108 2.0063E-03 -7.2623E-03 3.8120E-03 -8.1750E-02 -1.3825E-02 -8.0049E-03
5109 1.9299E-03 -6.6336E-03 3.5150E-03 -7.9308E-02 -1.2958E-02 -7.3631E-03
5110 1.8586E-03 -6.0265E-03 3.2271E-03 -7.6400E-02 -1.2011E-02 -6.7206E-03
5111 1.7928E-03 -5.4442E-03 2.9500E-03 -7.3084E-02 -1.1010E-02 -6.0892E-03
5112 1.7329E-03 -4.8897E-03 2.6851E-03 -6.9435E-02 -9.9818E-03 -5.4777E-03
5113 1.6791E-03 -4.3652E-03 2.4334E-03 -6.5533E-02 -8.9528E-03 -4.8933E-03
etc, so what I want to do is search for a unique string ' N O D E O U T P U T' and then search for '5151' and import its displacements into an array.
Example output
nodeDisp = 1.6791E-03 -4.3652E-03 2.4334E-03 -6.5533E-02 -8.9528E-03 -4.8933E-03

Related

VScode Exception occur: System.ArgumentOutOfRangeException

When I try to run any c++ program in vs code an exception occur and do not run the program
Oops, something went wrong. Please report this bug with the details below.
Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new
-----------------------------------------------------------------------
Last 101 Keys:
c d Space " c : \ U s e r s \ U S E R
\ D o c u m e n t s \ p r o g r a m m i n g \ " Space ; Space i f Space ( $ ?
) Space { Space g + + Space c o d e 2 . c p p Space - o Space c o d e 2 Space
} Space ; Space i f Space ( $ ? ) Space { Space . \ c o d e 2 Space } Enter
Exception:
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: left
Actual value was -1.
at System.Console.SetCursorPosition(Int32 left, Int32 top)
at Microsoft.PowerShell.Internal.VirtualTerminal.set_CursorLeft(Int32 value)
at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
-----------------------------------------------------------------------
By using manual command in terminal , I can run my c++ program.
I can find some issues in vscode github repository about this problem but can not understand any solution

find nodes with multiple parents using networkx

Let's say I have a directed graph (this is about relational tables). I want to find M:N tables to track relationships enabled thru M:N tables.
from pathlib import Path
import subprocess
import networkx as nx
def write_svg(g, name):
temp = "temp.dot"
suffix = "jpg"
nx.nx_agraph.write_dot(g, temp)
pa_img = Path(f"{name}.{suffix}")
li_cmd = f"/opt/local/bin/dot {temp} -T {suffix} -o {pa_img}".split()
subprocess.check_output(li_cmd)
G = nx.DiGraph()
G.add_edge("C1", "P1")
G.add_edge("C2", "P1")
G.add_edge("C21", "C2")
G.add_edge("MN12", "P1")
G.add_edge("MN12", "P2")
G.add_nodes_from([
("MN12", {"color" : "red"})
])
Run this, and I get:
So what I am considering here is that MN12 has as parents P1 and P2. So I want to consider P2 to be related to P1, with MN12 as the mapping table.
In other words, if I hard-code the relationship graph I want:
G = nx.DiGraph()
G.add_edge("C1", "P1")
G.add_edge("C2", "P1")
G.add_edge("C21", "C2")
G.add_edge("P2(using MN12)", "P1")
G.add_nodes_from([
("P2(using MN12)", {"color" : "green"})
])
Note that C21 remains a child of C2. Only MN12 is modified, because it has 2 parents.
Now, I know I can see the degree of a given node.
Going in back to my input graph:
(Pdb++) G.degree('MN12')
2
(Pdb++) G.degree('C1')
1
(Pdb++) G.degree('C2')
2
(Pdb++) G.degree('P1')
3
But how do I see that the arrows from MN12 go towards both P1 and P2? Is this even a question for networkx?
You can use both out_edges and successors.
>>> G.out_edges("MN12")
OutEdgeDataView([('MN12', 'P1'), ('MN12', 'P2')])
>>> list(G.successors("MN12"))
['P1', 'P2']

pg_dump from 9.1.7 to 9.1.11

I would like to import a table from another postgress database (9.1.7) to mine which is (9.1.11). I tried to import the dump but I get a bunch of syntax errors, I'm assuming there is some issue with the version mismatch?
Is there a better solution other than downgrading my postgress installation to match the desired input file?
This is the command I used to export the database on the 9.1.7 system:
pg_dump superdb -U tester -a -t guidedata > /tmp/guidedata.sql
This is the command I used to import the dump file guidedata.sql
psql linuxdb -U tester -h localhost < guidedata.sql
This is the top portion of the database dump file which I am attempting to import:
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET search_path = public, pg_catalog;
--
-- Data for Name: epg; Type: TABLE DATA; Schema: public; Owner: spy
--
COPY epg (id, channel, sdate, stime, duration, stitle, ltitle, theme, sdesc, ldesc, mpaa, rating, stereo, surround, sap, closedcaptioned, animated, blackwhite, rerun, live, ismovie, nudity, language, violence, adulttheme, halfstars, field1) FROM stdin;
90056520 AMC 01092014 0100 270 Titanic Titanic 8,15 A woman falls for an artist aboard the ill-fated ship. Leonardo DiCaprio, Kate Winslet (1997) A society girl abandons her haughty fiance for a penniless artist on the ill-fated ship's maiden voyage. (3:15) MPAAPG13 TVPG f f f t f f t f t t t t t 8 f
90056521 AMC 01092014 0530 180 Love Actually Love Actually 23,15 Various people deal with relationships in London. Hugh Grant, Laura Linney (2003) A prime minister, an office worker, a pop star, a jilted writer, married couples and various others deal with relationships in London. (2:15) MPAAR TVPG f f t t f f t f t t t f t 6 f
90056522 AMC 01092014 0830 150 Four Four Weddings and a Funeral 23,15 An English charmer meets a lusty American. Hugh Grant, Andie MacDowell (1994) An English charmer and a lusty American make love over a course of surprising events. (1:56) MPAAR TV14 f f t t f f t f t f t f t 7 f
90056523 AMC 01092014 1100 30 Paid Prog. Paid Programming 0 Paid programming. Paid programming. f f f f f f t f f f f f f 0 f
90056524 AMC 01092014 1130 30 Williams Montel Williams 19 Living well with Montel and the effects of identity theft. Living well with Montel and the devastating effects of identity theft. f f f f f f t f f f f f f 0 f
90056525 AMC 01092014 1200 30 Cindy Crawford Cindy Crawford Reveals Secret to Ageless Beauty 19 Cindy Crawford's skin secret with Meaningful Beauty. Cindy Crawford's supermodel secret to youthful, radiant-looking skin with Meaningful Beauty. f f f f f f t f f f f f f 0 f
90056526 AMC 01092014 1230 30 More Sex More Sex, Less Stress 19 Androzene promotes male sexual health & nourishes the body. Androzene promotes male sexual health and nourishes the body. f f f f f f t f f f f f f 0 f
90056527 AMC 01092014 1300 30 WEN Hair Care WEN by Chaz Dean Revolutionary Hair Care System 19 WEN by Chaz Dean is revolutionary hair care. WEN by Chaz Dean is revolutionary hair care that cleans and conditions without many shampoo's harsh detergents or sulfates. Natural ingredients help make hair shinier, fuller, softer and more manageable! By trusted GuthyRenker. f f f f f f t f f f f f f 0 f
90056528 AMC 01092014 1330 30 Medicare Looking for a Medicare plan? Tune in now! 19 Watch and learn about Humana Medicare Advantage plans. Watch and learn about Humana Medicare Advantage plans. f f f f f f t f f f f f f 0 f
90056529 AMC 01092014 1400 5 Stooges The Three Stooges 6 The caveman boys meet cavewomen. Moe Howard, Larry Fine ''I'm a Monkey's Unc
Here is some of the error output I see on the console when attempting to import:
ERROR: syntax error at or near "Route"
LINE 1: Route 66 renovation gives Ron a change of heart. TVPG t f f...
^
ERROR: syntax error at or near "Ron"
LINE 1: Ron and Jason bring out the Pontiac GTO. TVPG t f f t f f t...
^
ERROR: syntax error at or near "repairing"
LINE 1: repairing the clutch and drive shaft on the 1995 BMW. TVPG ...
^
ERROR: syntax error at or near "classic"
LINE 1: classic Bucik;
Thanks
My guess - one system is linux/unix/mac and the other is Windows.
It's complaining about the first line of the block of data because there is a stray carriage-return (\r) character.
Solution: use the (recommended unless you have a good reason not to) "custom" format with -Fc or --format=custom on your dump command. That should sort it.

Changing format of many files in Excel

I have a folder filled with thousands of csv files. When I open one file, the data looks like:
20110503 01:46.0 1527.8 1 E
20110503 01:46.0 1537.8 1 E
20110504 37:40.0 1536.6 1 E
20110504 37:40.0 1533.6 1 E
20110504 36:17.0 1531.1 1 E
The second column(time) has minutes and seconds before the decimal point. If I select the second column, right click and click format cells, select time, and change to 13:30:55 mode, the same data looks like:
20110503 19:01:46 1527.8 1 E
20110503 19:01:46 1537.8 1 E
20110504 0:37:40 1536.6 1 E
20110504 0:37:40 1533.6 1 E
20110504 8:36:17 1531.1 1 E
Now I can see hours, minutes and seconds. I have written a matlab function that reads these files, but needs to be able to read the hours. The function can only be used after I change the format to display the hours. Now I have to apply the function to all the files in the folder.
I'm wondering, is there a way to change the default time display so hours are included? If not, is there a way of writing a script to change the format of these files? Thanks!
Note: the part of my matlab function that reads the file looks like:
fid = fopen('E:\Tick Data\Data Output\NGU13.csv','rt');
c = fscanf(fid, '%d,%d:%d:%d,%f,%d,%*c');
datamat = reshape(c,6,length(c)/6)'; % reshape into matrix
yyyymmdd = datamat(:,1);
hr = datamat(:,2);
mn = datamat(:,3);
sec = datamat(:,4);
pp = datamat(:,5); % price
vv = datamat(:,6); % volume
In Excel:
In Notepad, you can see hours, minutes, seconds, and milliseconds:
20111206,09:50:56.411,4.320,1,E
20111206,10:02:10.167,4.300,1,E
20111206,11:24:09.052,4.313,1,E
20111206,11:46:09.359,4.307,1,E
20111206,11:50:22.785,4.320,1,E
For a record of the type
20010402, 09:30:24.456, 4.235, 1, E
you should use this fmt:
fmt = '%f%f:%f:%f.%f%f%*s';
data = textscan(fid, fmt, 'Delimiter',',','CollectOutput',true);

DNA to RNA and Getting Proteins with Perl

I am working on a project(I have to implement it in Perl but I am not good at it) that reads DNA and finds its RNA. Divide that RNA's into triplets to get the equivalent protein name of it. I will explain the steps:
1) Transcribe the following DNA to RNA, then use the genetic code to translate it to a sequence of amino acids
Example:
TCATAATACGTTTTGTATTCGCCAGCGCTTCGGTGT
2) To transcribe the DNA, first substitute each DNA for it’s counterpart (i.e., G for C, C for G, T for A and A for T):
TCATAATACGTTTTGTATTCGCCAGCGCTTCGGTGT
AGTATTATGCAAAACATAAGCGGTCGCGAAGCCACA
Next, remember that the Thymine (T) bases become a Uracil (U). Hence our sequence becomes:
AGUAUUAUGCAAAACAUAAGCGGUCGCGAAGCCACA
Using the genetic code is like that
AGU AUU AUG CAA AAC AUA AGC GGU CGC GAA GCC ACA
then look each triplet (codon) up in the genetic code table. So AGU becomes Serine, which we can write as Ser, or
just S. AUU becomes Isoleucine (Ile), which we write as I. Carrying on in this way, we get:
SIMQNISGREAT
I will give the protein table:
So how can I write that code in Perl? I will edit my question and write the code that what I did.
Try the script below, it accepts input on STDIN (or in file given as parameter) and read it by line. I also presume, that "STOP" in the image attached is some stop state. Hope I read it all well from that picture.
#!/usr/bin/perl
use strict;
use warnings;
my %proteins = qw/
UUU F UUC F UUA L UUG L UCU S UCC S UCA S UCG S UAU Y UAC Y UGU C UGC C UGG W
CUU L CUC L CUA L CUG L CCU P CCC P CCA P CCG P CAU H CAC H CAA Q CAG Q CGU R CGC R CGA R CGG R
AUU I AUC I AUA I AUG M ACU T ACC T ACA T ACG T AAU N AAC N AAA K AAG K AGU S AGC S AGA R AGG R
GUU V GUC V GUA V GUG V GCU A GCC A GCA A GCG A GAU D GAC D GAA E GAG E GGU G GGC G GGA G GGG G
/;
LINE: while (<>) {
chomp;
y/GCTA/CGAU/; # translate (point 1&2 mixed)
foreach my $protein (/(...)/g) {
if (defined $proteins{$protein}) {
print $proteins{$protein};
}
else {
print "Whoops, stop state?\n";
next LINE;
}
}
print "\n"
}