Mapdb stops after adding 32 items into the hashmap - hash

Here is the definition for my objects:
public class Tuple_comparable implements Serializable, Comparable<Tuple_comparable> {
public String arg1_surface;
public String arg1_type;
public boolean arg1_type_equals;
public String relation;
public String arg2_surface;
public String arg2_type;
public boolean arg2_type_equals;
public Long count;
#Override
public boolean equals(Object o) {
if (!(o instanceof Tuple_comparable))
return false;
Tuple_comparable oo = (Tuple_comparable)o;
if( oo.arg1_type.length() != this.arg1_type.length() )
return false;
if( oo.relation.length() != this.relation.length() )
return false;
if( oo.arg2_type.length() != this.arg2_type.length() )
return false;
if( !oo.arg1_type.equals( this.arg1_type ) )
return false;
if( !oo.arg2_type.equals( this.arg2_type ) )
return false;
if( !oo.relation.equals( this.relation ) )
return false;
return true;
}
#Override
public int hashCode() {
return this.arg1_type.length() + this.relation.length() + this.arg2_type.length();
}
#Override
public int compareTo(Tuple_comparable o) {
return 1;
}
}
And here is how I used MapDB:
DB db = DBMaker.newFileDB(new File(folder + "unique_pairs_withDenoms_directed_forward_test_1" + "_mapdb.bin" ))
//.closeOnJvmShutdown()
.make();
// Create a Map:
Map<Tuple_comparable,long[]> myMap = db.getTreeMap("testmap");
int i = 0;
for( i = 0; i < 100000; i++ ) {
// Work with the Map using the normal Map API.
Tuple_comparable tc = new Tuple_comparable();
tc.arg1_surface = ""+ i;
tc.arg1_type = "" + i;
tc.arg1_type_equals = true;
tc.relation = "" + i;
tc.arg2_surface = "";
tc.arg2_type = "";
tc.arg2_type_equals = false;
tc.count = (long) 2222222;
long[] count = {1,2,3,4,4};
i++;
myMap.put(tc, count);
}
db.commit();
db.close();
When I run it, I see the following:
Proccessed = % 0.001
After myMap.size() = 0
Proccessed = % 0.003
After myMap.size() = 1
Proccessed = % 0.005
After myMap.size() = 2
Proccessed = % 0.007
After myMap.size() = 3
Proccessed = % 0.009
After myMap.size() = 4
Proccessed = % 0.011
After myMap.size() = 5
Proccessed = % 0.013
After myMap.size() = 6
Proccessed = % 0.015
After myMap.size() = 7
Proccessed = % 0.017
After myMap.size() = 8
Proccessed = % 0.019
After myMap.size() = 9
Proccessed = % 0.021
After myMap.size() = 10
Proccessed = % 0.023
After myMap.size() = 11
Proccessed = % 0.025
After myMap.size() = 12
Proccessed = % 0.027
After myMap.size() = 13
Proccessed = % 0.029
After myMap.size() = 14
Proccessed = % 0.031
After myMap.size() = 15
Proccessed = % 0.033
After myMap.size() = 16
Proccessed = % 0.035
After myMap.size() = 17
Proccessed = % 0.037
After myMap.size() = 18
Proccessed = % 0.039
After myMap.size() = 19
Proccessed = % 0.041
After myMap.size() = 20
Proccessed = % 0.043
After myMap.size() = 21
Proccessed = % 0.045
After myMap.size() = 22
Proccessed = % 0.047
After myMap.size() = 23
Proccessed = % 0.049
After myMap.size() = 24
Proccessed = % 0.051
After myMap.size() = 25
Proccessed = % 0.053
After myMap.size() = 26
Proccessed = % 0.055
After myMap.size() = 27
Proccessed = % 0.057
After myMap.size() = 28
Proccessed = % 0.059
After myMap.size() = 29
Proccessed = % 0.061
After myMap.size() = 30
Proccessed = % 0.063
After myMap.size() = 31
Proccessed = % 0.065
After myMap.size() = 32
Proccessed = % 0.067
After myMap.size() = 33
And it continues running for unlimited time at the 34th item suddenly (although I expect it to continue adding the 1000th item). When I remove myMap.put(....) it continues until 1000; so there is some wrong going with the put function. I suspect that I have a problem (or missing a property inside the definition of the object type).
Anyone knows what is wrong with my usage of MapDB?

Problem is this:
public int compareTo(Tuple_comparable o) {
return 1;
}
I am not going to explain it here. For start I would recommend HashMap and generate equals/hashcode by your IDE.
MapDB 1.0 would deadlock, but that is solved in 2.0. So I do not consider it as a problem.

Related

2-DCT Image compression matlab

Problem:
I tried implementing Discrete Cosine Transformation compression using matlab.
Input image would a jpg image (Lena) having a size 512 X 512.
There are two stages namely compression and decompression.
Compression and Quantization:
The input image is converted to YCbCr component. Then Y component is taken up
for compression. Further DCT will quantized.
Quantization and Decompression:
The quantized image is undergoes dequantization for decompression.
Issues:
Rectangular boxes are spotted in the decompressed version of the image. Is anything wrong with the code?
For your inference, below are the sample input and output images and followed by the matlab code.
Input image:
Y Component in YCbCr:
Output image:
Code:
clc;
clear all;
close all;
I = imread('lena512.jpg');
figure, imshow(I);
% Y = I;
YCbCr = rgb2ycbcr(I);
figure, imshow(YCbCr);
Y = YCbCr(:,:, 1);
figure, imshow(Y);
[h, w] = size(Y);
r = h/8;
c = w/8;
s = 1;
q50 = [16 11 10 16 24 40 51 61;
12 12 14 19 26 58 60 55;
14 13 16 24 40 57 69 56;
14 17 22 29 51 87 80 62;
18 22 37 56 68 109 103 77;
24 35 55 64 81 104 113 92;
49 64 78 87 103 121 120 101;
72 92 95 98 112 100 103 99];
% COMPRESSION
for i=1:r
e = 1;
for j=1:c
block = Y(s:s+7,e:e+7);
cent = double(block) - 128;
for m=1:8
for n=1:8
if m == 1
u = 1/sqrt(8);
else
u = sqrt(2/8);
end
if n == 1
v = 1/sqrt(8);
else
v = sqrt(2/8);
end
comp = 0;
for x=1:8
for y=1:8
comp = comp + cent(x, y)*(cos((((2*(x-1))+1)*(m-1)*pi)/16))*(cos((((2*(y-1))+1)*(n-1)*pi)/16));
end
end
F(m, n) = v*u*comp;
end
end
for x=1:8
for y=1:8
cq(x, y) = round(F(x, y)/q50(x, y));
end
end
Q(s:s+7,e:e+7) = cq;
e = e + 8;
end
s = s + 8;
end
% % % % % % % % % % % % % % %
% % DECOMPRESSION
% % % % % % %
s = 1;
for i=1:r
e = 1;
for j=1:c
cq = Q(s:s+7,e:e+7);
for x=1:8
for y=1:8
DQ(x, y) = q50(x, y)*cq(x, y);
end
end
for m=1:8
for n=1:8
if m == 1
u = 1/sqrt(8);
else
u = sqrt(2/8);
end
if n == 1
v = 1/sqrt(8);
else
v = sqrt(2/8);
end
comp = 0;
for x=1:8
for y=1:8
comp = comp + u*v*DQ(x, y)*(cos((((2*(x-1))+1)*(m-1)*pi)/16))*(cos((((2*(y-1))+1)*(n-1)*pi)/16));
end
end
bf(m, n) = round(comp)+128;
end
end
Org(s:s+7,e:e+7) = bf;
e = e + 8;
end
s = s + 8;
end
imwrite(Y, 'F:\workouts\phd\jpeg\input.jpg');
imwrite(uint8(Org), 'F:\workouts\phd\jpeg\output.jpg');
return;
Can you suggest me where the error is? It would be helpful.

MATLAB initializing variables in next for loop

x=[3 1 1 -5 -2 0 1 2 -2 2];
A=[4 2 6; 0 1 -3; -2 5 -2];
B=[-2 3 2; 1 5 5; -3 1 0];
sum=0;
for i=2:3
sum_j=0;
for j=1:2
sum_j=sum_j+A(1,j)*B(j,i);
end
sum=sum+A(2,i)*sum_j;
end
fprintf('(c) %g\n',sum);
>> (c) -32
-32 is a correct answer. However, if I initialize sum_j=0 outside of the the loop, it returns a different value.
sum=0;
sum_j=0;
for i=2:3
for j=1:2
sum_j=sum_j+A(1,j)*B(j,i);
end
sum=sum+A(2,i)*sum_j;
end
fprintf('(c) %g\n',sum);
>> (c) -98
Can anyone explain why this is happening?
In your first code sum_j gets reinitialized in the loop for i and in second code sum_j carry the value in each loop. Here is a simulation of your codes
first code:
sum = 0
i=2:
sum_j = 0
i=2,j=1
sum_j = 0 + 4*3 = 12
i=2,j=2
sum_j = 12 + 2*5 = 22
sum = 0 + 1*22 = 22
i=3
sum_j = 0
i=3,j=1
sum_j = 0 + 4*2 = 8
i=3,j=2
sum_j = 8 + 2*5 = 18
sum = 22 + -3*18 = -32
Second code
sum = 0
sum_j = 0
i=2:
i=2,j=1
sum_j = 0 + 4*3 = 12
i=2,j=2
sum_j = 12 + 2*5 = 22
sum = 0 + 1*22 = 22
i=3
i=3,j=1
sum_j = 22 + 4*2 = 30
i=3,j=2
sum_j = 30 + 2*5 = 40
sum = 22 + -3*40 = -98

Neural network time series app processes values out of range of data

I want to customize my neural network training to process within the range of [0,65] - I tried the code:
net.inputs{1}.processParams;
ymin = 0;
ymax = 65;
net.outputs{2}.processParams;
ymin = 0;
ymax = 65;
Yet when I check the Time Series-Response graph it still processes values beyond these two values.
Using:
SampleData:
18
39
51
26
13
9
13
9
13
13
13
4
46
52
52
8
T = tonndata(SampleData,false,false);
trainFcn = 'trainbr';
feedbackDelays = 1:2;
hiddenLayerSize = 400;
net = narnet(feedbackDelays,hiddenLayerSize, 'open', trainFcn);
[x,xi,ai,li] = preparets(net,{},{},T);
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
then....to scale the training processing...
net.inputs{1}.processParams;
ymin = 0;
ymax = 65;
net.outputs{2}.processParams;
ymin = 0;
ymax = 65;

Intersection of line and curve Matlab

Well another problem has pop up recently.
I have a set representing a curve and a line I drew with the line() function.
So far my code is :
clc, clear all, close all;
n = 800/1500;
I = [ 0 1.1 4 9.5 15.3 19.5 23.1 26 28.2 30.8 33.3 35.9];
E_up = [ 5.8 10.5 28 60.3 85.5 100.3 108 113.2 117 120.5 123.5 126];
E_up = E_up./n;
Iw = [ 34 31.5 28.2 23.9 19.9 16.1 13 8.1 3.5 1.2 0 NaN];
E_down = [124.6 122.5 118.8 112.2 103.9 93.1 81.6 59.1 29.6 14.5 9.5 NaN];
E_down = E_down./n;
x_est = I;
y_est = spline(Iw,E_down,x_est)
A(:,1)= E_up
A(:,2) = y_est
ma = mean(A,2)
% figure()
% hold all
% % plot(x_est,y_est,'ro')
% plot(I,E_up,'b-',Iw,E_down,'g-')
% plot(I,ma,'r')
% grid on
% legend('up','down','mean')
%dane_znamionowe
clc, clear all, close all;
%data_entry
n = 800/1500;
I = [ 0 1.1 4 9.5 15.3 19.5 23.1 26 28.2 30.8 33.3 35.9];
E_up = [ 5.8 10.5 28 60.3 85.5 100.3 108 113.2 117 120.5 123.5 126];
E_up = E_up./n; %rescalling_EMF
Iw = [ 34 31.5 28.2 23.9 19.9 16.1 13 8.1 3.5 1.2 0 NaN];
E_down = [124.6 122.5 118.8 112.2 103.9 93.1 81.6 59.1 29.6 14.5 9.5 NaN];
E_down = E_down./n; %rescalling_EMF
Un = 220;
In = 28.8;
wn = 1500;
wmax = 3000;
P = 5.5e3;
Rs = 15.8/25;
%interpolation
x_est = I;
y_est = spline(Iw,E_down,x_est);
%mean_values
A(:,1)= E_up;
A(:,2) = y_est;
ma = mean(A,2);
%party_Xd
figure()
[ax,h1,h2] = plotyy(I+30,wn,I,ma,'plot','plot');
set(ax(1),'ylim',[0 3000],'ytick',[1500 3000]);
set(ax(2),'ylim',[0 300],'ytick',[100 200 300]);
hold(ax(1))
hold(ax(2))
%stable_parts
set(ax,'NextPlot','add')
plot(ax(2),I,ma,'b')
plot(ax(2),0,Un,'m*')
i2 = 0:0.01:70;
plot(ax(2),i2,Un-(i2*Rs),'m--')
iin = 0:1:300;
plot(ax(2),In,iin,'g-')
plot(ax(1),i2,wn,'k-','linewidth',8)
plot(ax(1),28.8,1500,'g*')
%loop
p1x = [35 45 55 65];
for ii = 1 :length(p1x)
x11 = p1x(ii);
y11 = 0;
x21 = In;
y21 = wn;
x1 = [35 45 55 65];
y1 = [0 0 0 0];
x2 = [In In In In];
y2 = [wn wn wn wn];
slope = (y21-y11)/(x21-x11);
xLeft = 0;
yLeft = slope * (xLeft - x11) + y11;
xRight = 70;
yRight = slope * (xRight - x11) + y11;
plot(ax(2),x11,0,'r.')
a1 = line([xLeft, xRight], [yLeft, yRight], 'Color', 'c');
x0 = (max(min(x1),min(x2))+min(max(x1),max(x2)))/2;
fun1 = #(x) interp1(x1,y1,x,'linear');
fun2 = #(x) interp1(x2,y2,x,'linear');
difffun = #(x) fun1(x)-fun2(x);
crossing = fzero(difffun,x0); %crossing x coordinate
crossval = fun1(crossing);
end
My graph looks like this which is pretty decent.But I need to find the intersection point of the cyan line and blue curve.
An answer based on my solution to a similar question:
%dummy input
x1=[0 1 2 3];
y1=[1 4 2 0];
x2=[-1 3 4 5];
y2=[-1 2 5 3];
x0 = (max(min(x1),min(x2))+min(max(x1),max(x2)))/2;
fun1 = #(x) interp1(x1,y1,x,'linear','extrap');
fun2 = #(x) interp1(x2,y2,x,'linear','extrap');
difffun = #(x) fun1(x)-fun2(x);
crossing = fzero(difffun,x0); %crossing x coordinate
crossval = fun1(crossing); %substitute either function at crossing point
plot(x1,y1,'b-',x2,y2,'r-',crossing,crossval,'ks');
legend('line1','line2','crossover','location','nw');
after which your crossing point is given by [crossing, crossval].
Result:

Matching a string in one file and want to print the value written after that string in certain file

Code:
use strict;
use warnings;
open(my $file, "<", "abc.txt") || die ("Cannot open file.\n");
open(my $out, ">", "output.txt") || die ("Cannot open file.\n");
while (my $line =<$file>) {
chomp $line;
if ($line =~ /\+vth\d = (\d+)/) {
print $out "$1\n";
}
}
abc.txt
.lib cmos_models
.model nmos nmos level = 54
+version = 4.0 binunit = 1 paramchk= 1 mobmod = 0
+capmod = 2 igcmod = 1 igbmod = 1 geomod = 1
+diomod = 1 rdsmod = 0 rbodymod= 1 rgatemod= 1
+permod = 1 acnqsmod= 0 trnqsmod= 0
+tnom = 27 toxe = 1.75e-9 toxp = 1.1e-9 toxm = 1.75e-9
+dtox = 0.65e-9 epsrox = 3.9 wint = 5e-009 lint = 3.75e-009
+ll = 0 wl = 0 lln = 1 wln = 1
+lw = 0 ww = 0 lwn = 1 wwn = 1
+lwl = 0 wwl = 0 xpart = 0 toxref = 1.75e-9
+xl = -20e-9
+vth0 = 0.466 k1 = 0.4 k2 = 0.0 k3 = 0
+k3b = 0 w0 = 2.5e-006 dvt0 = 1 dvt1 = 2
+dvt2 = 0 dvt0w = 0 dvt1w = 0 dvt2w = 0
+dsub = 0.1 minv = 0.05 voffl = 0 dvtp0 = 1.0e-010
+dvtp1 = 0.1 lpe0 = 0 lpeb = 0 xj = 1.4e-008
+ngate = 2e+020 ndep = 3.24e+018 nsd = 2e+020 phin = 0
+cdsc = 0.000 cdscb = 0 cdscd = 0 cit = 0
+voff = -0.13 nfactor = 2.1 eta0 = 0.0049 etab = 0
+vfb = -0.55 u0 = 0.04398 ua = 6e-010 ub = 1.2e-018
+uc = 0 vsat = 147390 a0 = 1.0 ags = 0
+a1 = 0 a2 = 1.0 b0 = 0 b1 = 0
+keta = 0.04 dwg = 0 dwb = 0 pclm = 0.02
+pdiblc1 = 0.001 pdiblc2 = 0.001 pdiblcb = -0.005 drout = 0.5
+pvag = 1e-020 delta = 0.01 pscbe1 = 8.14e+008 pscbe2 = 1e-007
+fprout = 0.2 pdits = 0.08 pditsd = 0.23 pditsl = 2.3e+006
+rsh = 5 rdsw = 155 rsw = 80 rdw = 80
+rdswmin = 0 rdwmin = 0 rswmin = 0 prwg = 0
+prwb = 0 wr = 1 alpha0 = 0.074 alpha1 = 0.005
+beta0 = 30 agidl = 0.0002 bgidl = 2.1e+009 cgidl = 0.0002
+egidl = 0.8
+aigbacc = 0.012 bigbacc = 0.0028 cigbacc = 0.002
+nigbacc = 1 aigbinv = 0.014 bigbinv = 0.004 cigbinv = 0.004
+eigbinv = 1.1 nigbinv = 3 aigc = 0.012 bigc = 0.0028
+cigc = 0.002 aigsd = 0.012 bigsd = 0.0028 cigsd = 0.002
+nigc = 1 poxedge = 1 pigcd = 1 ntox = 1
+xrcrg1 = 12 xrcrg2 = 5
+cgso = 1.1e-010 cgdo = 1.1e-010 cgbo = 2.56e-011 cgdl = 2.653e-10
+cgsl = 2.653e-10 ckappas = 0.03 ckappad = 0.03 acde = 1
+moin = 15 noff = 0.9 voffcv = 0.02
+kt1 = -0.11 kt1l = 0 kt2 = 0.022 ute = -1.5
+ua1 = 4.31e-009 ub1 = 7.61e-018 uc1 = -5.6e-011 prt = 0
+at = 33000
+fnoimod = 1 tnoimod = 0
+jss = 0.0001 jsws = 1e-011 jswgs = 1e-010 njs = 1
+ijthsfwd= 0.01 ijthsrev= 0.001 bvs = 10 xjbvs = 1
+jsd = 0.0001 jswd = 1e-011 jswgd = 1e-010 njd = 1
+ijthdfwd= 0.01 ijthdrev= 0.001 bvd = 10 xjbvd = 1
+pbs = 1 cjs = 0.0005 mjs = 0.5 pbsws = 1
+cjsws = 5e-010 mjsws = 0.33 pbswgs = 1 cjswgs = 3e-010
+mjswgs = 0.33 pbd = 1 cjd = 0.0005 mjd = 0.5
+pbswd = 1 cjswd = 5e-010 mjswd = 0.33 pbswgd = 1
+cjswgd = 5e-010 mjswgd = 0.33 tpb = 0.005 tcj = 0.001
+tpbsw = 0.005 tcjsw = 0.001 tpbswg = 0.005 tcjswg = 0.001
+xtis = 3 xtid = 3
+dmcg = 0e-006 dmci = 0e-006 dmdg = 0e-006 dmcgt = 0e-007
+dwj = 0.0e-008 xgw = 0e-007 xgl = 0e-008
+rshg = 0.4 gbmin = 1e-010 rbpb = 5 rbpd = 15
+rbps = 15 rbdb = 15 rbsb = 15 ngcon = 1
* PTM 45nm PMOS
.model pmos pmos level = 54
+version = 4.0 binunit = 1 paramchk= 1 mobmod = 0
+capmod = 2 igcmod = 1 igbmod = 1 geomod = 1
+diomod = 1 rdsmod = 0 rbodymod= 1 rgatemod= 1
+permod = 1 acnqsmod= 0 trnqsmod= 0
+tnom = 27 toxe = 1.85e-009 toxp = 1.1e-009 toxm = 1.85e-009
+dtox = 0.75e-9 epsrox = 3.9 wint = 5e-009 lint = 3.75e-009
+ll = 0 wl = 0 lln = 1 wln = 1
+lw = 0 ww = 0 lwn = 1 wwn = 1
+lwl = 0 wwl = 0 xpart = 0 toxref = 1.85e-009
+xl = -20e-9
+vth0 = 40 k1 = 0.4 k2 = -0.01 k3 = 0
+k3b = 0 w0 = 2.5e-006 dvt0 = 1 dvt1 = 2
+dvt2 = -0.032 dvt0w = 0 dvt1w = 0 dvt2w = 0
+dsub = 0.1 minv = 0.05 voffl = 0 dvtp0 = 1e-011
+dvtp1 = 0.05 lpe0 = 0 lpeb = 0 xj = 1.4e-008
+ngate = 2e+020 ndep = 2.44e+018 nsd = 2e+020 phin = 0
+cdsc = 0.000 cdscb = 0 cdscd = 0 cit = 0
+voff = -0.126 nfactor = 2.1 eta0 = 0.0049 etab = 0
+vfb = 0.55 u0 = 0.00440 ua = 2.0e-009 ub = 0.5e-018
+uc = 0 vsat = 70000 a0 = 1.0 ags = 1e-020
+a1 = 0 a2 = 1 b0 = 0 b1 = 0
+keta = -0.047 dwg = 0 dwb = 0 pclm = 0.12
+pdiblc1 = 0.001 pdiblc2 = 0.001 pdiblcb = 3.4e-008 drout = 0.56
+pvag = 1e-020 delta = 0.01 pscbe1 = 8.14e+008 pscbe2 = 9.58e-007
+fprout = 0.2 pdits = 0.08 pditsd = 0.23 pditsl = 2.3e+006
+rsh = 5 rdsw = 155 rsw = 75 rdw = 75
+rdswmin = 0 rdwmin = 0 rswmin = 0 prwg = 0
+prwb = 0 wr = 1 alpha0 = 0.074 alpha1 = 0.005
+beta0 = 30 agidl = 0.0002 bgidl = 2.1e+009 cgidl = 0.0002
+egidl = 0.8
+aigbacc = 0.012 bigbacc = 0.0028 cigbacc = 0.002
+nigbacc = 1 aigbinv = 0.014 bigbinv = 0.004 cigbinv = 0.004
+eigbinv = 1.1 nigbinv = 3 aigc = 0.69 bigc = 0.0012
+cigc = 0.0008 aigsd = 0.0087 bigsd = 0.0012 cigsd = 0.0008
+nigc = 1 poxedge = 1 pigcd = 1 ntox = 1
+xrcrg1 = 12 xrcrg2 = 5
+cgso = 1.1e-010 cgdo = 1.1e-010 cgbo = 2.56e-011 cgdl = 2.653e-10
+cgsl = 2.653e-10 ckappas = 0.03 ckappad = 0.03 acde = 1
+moin = 15 noff = 0.9 voffcv = 0.02
+kt1 = -0.11 kt1l = 0 kt2 = 0.022 ute = -1.5
+ua1 = 4.31e-009 ub1 = 7.61e-018 uc1 = -5.6e-011 prt = 0
+at = 33000
+fnoimod = 1 tnoimod = 0
+jss = 0.0001 jsws = 1e-011 jswgs = 1e-010 njs = 1
+ijthsfwd= 0.01 ijthsrev= 0.001 bvs = 10 xjbvs = 1
+jsd = 0.0001 jswd = 1e-011 jswgd = 1e-010 njd = 1
+ijthdfwd= 0.01 ijthdrev= 0.001 bvd = 10 xjbvd = 1
+pbs = 1 cjs = 0.0005 mjs = 0.5 pbsws = 1
+cjsws = 5e-010 mjsws = 0.33 pbswgs = 1 cjswgs = 3e-010
+mjswgs = 0.33 pbd = 1 cjd = 0.0005 mjd = 0.5
+pbswd = 1 cjswd = 5e-010 mjswd = 0.33 pbswgd = 1
+cjswgd = 5e-010 mjswgd = 0.33 tpb = 0.005 tcj = 0.001
+tpbsw = 0.005 tcjsw = 0.001 tpbswg = 0.005 tcjswg = 0.001
+xtis = 3 xtid = 3
+dmcg = 0e-006 dmci = 0e-006 dmdg = 0e-006 dmcgt = 0e-007
+dwj = 0.0e-008 xgw = 0e-007 xgl = 0e-008
+rshg = 0.4 gbmin = 1e-010 rbpb = 5 rbpd = 15
+rbps = 15 rbdb = 15 rbsb = 15 ngcon = 1
.model pmos pmos level = 54
+version = 4.0 binunit = 1 paramchk= 1 mobmod = 0
+capmod = 2 igcmod = 1 igbmod = 1 geomod = 1
+diomod = 1 rdsmod = 0 rbodymod= 1 rgatemod= 1
+permod = 1 acnqsmod= 0 trnqsmod= 0
+tnom = 27 toxe = 1.85e-009 toxp = 1.1e-009 toxm = 1.85e-009
+dtox = 0.75e-9 epsrox = 3.9 wint = 5e-009 lint = 3.75e-009
+ll = 0 wl = 0 lln = 1 wln = 1
+lw = 0 ww = 0 lwn = 1 wwn = 1
+lwl = 0 wwl = 0 xpart = 0 toxref = 1.85e-009
+xl = -20e-9
+vth0 = 50 k1 = 0.4 k2 = -0.01 k3 = 0
+k3b = 0 w0 = 2.5e-006 dvt0 = 1 dvt1 = 2
+dvt2 = -0.032 dvt0w = 0 dvt1w = 0 dvt2w = 0
+dsub = 0.1 minv = 0.05 voffl = 0 dvtp0 = 1e-011
+dvtp1 = 0.05 lpe0 = 0 lpeb = 0 xj = 1.4e-008
+ngate = 2e+020 ndep = 2.44e+018 nsd = 2e+020 phin = 0
+cdsc = 0.000 cdscb = 0 cdscd = 0 cit = 0
+voff = -0.126 nfactor = 2.1 eta0 = 0.0049 etab = 0
+vfb = 0.55 u0 = 0.00440 ua = 2.0e-009 ub = 0.5e-018
+uc = 0 vsat = 70000 a0 = 1.0 ags = 1e-020
+a1 = 0 a2 = 1 b0 = 0 b1 = 0
+keta = -0.047 dwg = 0 dwb = 0 pclm = 0.12
+pdiblc1 = 0.001 pdiblc2 = 0.001 pdiblcb = 3.4e-008 drout = 0.56
+pvag = 1e-020 delta = 0.01 pscbe1 = 8.14e+008 pscbe2 = 9.58e-007
+fprout = 0.2 pdits = 0.08 pditsd = 0.23 pditsl = 2.3e+006
+rsh = 5 rdsw = 155 rsw = 75 rdw = 75
+rdswmin = 0 rdwmin = 0 rswmin = 0 prwg = 0
+prwb = 0 wr = 1 alpha0 = 0.074 alpha1 = 0.005
+beta0 = 30 agidl = 0.0002 bgidl = 2.1e+009 cgidl = 0.0002
+egidl = 0.8
+aigbacc = 0.012 bigbacc = 0.0028 cigbacc = 0.002
+nigbacc = 1 aigbinv = 0.014 bigbinv = 0.004 cigbinv = 0.004
+eigbinv = 1.1 nigbinv = 3 aigc = 0.69 bigc = 0.0012
+cigc = 0.0008 aigsd = 0.0087 bigsd = 0.0012 cigsd = 0.0008
+nigc = 1 poxedge = 1 pigcd = 1 ntox = 1
+xrcrg1 = 12 xrcrg2 = 5
+cgso = 1.1e-010 cgdo = 1.1e-010 cgbo = 2.56e-011 cgdl = 2.653e-10
+cgsl = 2.653e-10 ckappas = 0.03 ckappad = 0.03 acde = 1
+moin = 15 noff = 0.9 voffcv = 0.02
+kt1 = -0.11 kt1l = 0 kt2 = 0.022 ute = -1.5
+ua1 = 4.31e-009 ub1 = 7.61e-018 uc1 = -5.6e-011 prt = 0
+at = 33000
+fnoimod = 1 tnoimod = 0
+jss = 0.0001 jsws = 1e-011 jswgs = 1e-010 njs = 1
+ijthsfwd= 0.01 ijthsrev= 0.001 bvs = 10 xjbvs = 1
+jsd = 0.0001 jswd = 1e-011 jswgd = 1e-010 njd = 1
+ijthdfwd= 0.01 ijthdrev= 0.001 bvd = 10 xjbvd = 1
+pbs = 1 cjs = 0.0005 mjs = 0.5 pbsws = 1
+cjsws = 5e-010 mjsws = 0.33 pbswgs = 1 cjswgs = 3e-010
+mjswgs = 0.33 pbd = 1 cjd = 0.0005 mjd = 0.5
+pbswd = 1 cjswd = 5e-010 mjswd = 0.33 pbswgd = 1
+cjswgd = 5e-010 mjswgd = 0.33 tpb = 0.005 tcj = 0.001
+tpbsw = 0.005 tcjsw = 0.001 tpbswg = 0.005 tcjswg = 0.001
+xtis = 3 xtid = 3
+dmcg = 0e-006 dmci = 0e-006 dmdg = 0e-006 dmcgt = 0e-007
+dwj = 0.0e-008 xgw = 0e-007 xgl = 0e-008
+rshg = 0.4 gbmin = 1e-010 rbpb = 5 rbpd = 15
+rbps = 15 rbdb = 15 rbsb = 15 ngcon = 1
.model pmos pmos level = 54
+version = 4.0 binunit = 1 paramchk= 1 mobmod = 0
+capmod = 2 igcmod = 1 igbmod = 1 geomod = 1
+diomod = 1 rdsmod = 0 rbodymod= 1 rgatemod= 1
+permod = 1 acnqsmod= 0 trnqsmod= 0
+tnom = 27 toxe = 1.85e-009 toxp = 1.1e-009 toxm = 1.85e-009
+dtox = 0.75e-9 epsrox = 3.9 wint = 5e-009 lint = 3.75e-009
+ll = 0 wl = 0 lln = 1 wln = 1
+lw = 0 ww = 0 lwn = 1 wwn = 1
+lwl = 0 wwl = 0 xpart = 0 toxref = 1.85e-009
+xl = -20e-9
+vth0 = 60 k1 = 0.4 k2 = -0.01 k3 = 0
+k3b = 0 w0 = 2.5e-006 dvt0 = 1 dvt1 = 2
+dvt2 = -0.032 dvt0w = 0 dvt1w = 0 dvt2w = 0
+dsub = 0.1 minv = 0.05 voffl = 0 dvtp0 = 1e-011
+dvtp1 = 0.05 lpe0 = 0 lpeb = 0 xj = 1.4e-008
+ngate = 2e+020 ndep = 2.44e+018 nsd = 2e+020 phin = 0
+cdsc = 0.000 cdscb = 0 cdscd = 0 cit = 0
+voff = -0.126 nfactor = 2.1 eta0 = 0.0049 etab = 0
+vfb = 0.55 u0 = 0.00440 ua = 2.0e-009 ub = 0.5e-018
+uc = 0 vsat = 70000 a0 = 1.0 ags = 1e-020
+a1 = 0 a2 = 1 b0 = 0 b1 = 0
+keta = -0.047 dwg = 0 dwb = 0 pclm = 0.12
+pdiblc1 = 0.001 pdiblc2 = 0.001 pdiblcb = 3.4e-008 drout = 0.56
+pvag = 1e-020 delta = 0.01 pscbe1 = 8.14e+008 pscbe2 = 9.58e-007
+fprout = 0.2 pdits = 0.08 pditsd = 0.23 pditsl = 2.3e+006
+rsh = 5 rdsw = 155 rsw = 75 rdw = 75
+rdswmin = 0 rdwmin = 0 rswmin = 0 prwg = 0
+prwb = 0 wr = 1 alpha0 = 0.074 alpha1 = 0.005
+beta0 = 30 agidl = 0.0002 bgidl = 2.1e+009 cgidl = 0.0002
+egidl = 0.8
+aigbacc = 0.012 bigbacc = 0.0028 cigbacc = 0.002
+nigbacc = 1 aigbinv = 0.014 bigbinv = 0.004 cigbinv = 0.004
+eigbinv = 1.1 nigbinv = 3 aigc = 0.69 bigc = 0.0012
+cigc = 0.0008 aigsd = 0.0087 bigsd = 0.0012 cigsd = 0.0008
+nigc = 1 poxedge = 1 pigcd = 1 ntox = 1
+xrcrg1 = 12 xrcrg2 = 5
+cgso = 1.1e-010 cgdo = 1.1e-010 cgbo = 2.56e-011 cgdl = 2.653e-10
+cgsl = 2.653e-10 ckappas = 0.03 ckappad = 0.03 acde = 1
+moin = 15 noff = 0.9 voffcv = 0.02
+kt1 = -0.11 kt1l = 0 kt2 = 0.022 ute = -1.5
+ua1 = 4.31e-009 ub1 = 7.61e-018 uc1 = -5.6e-011 prt = 0
+at = 33000
+fnoimod = 1 tnoimod = 0
+jss = 0.0001 jsws = 1e-011 jswgs = 1e-010 njs = 1
+ijthsfwd= 0.01 ijthsrev= 0.001 bvs = 10 xjbvs = 1
+jsd = 0.0001 jswd = 1e-011 jswgd = 1e-010 njd = 1
+ijthdfwd= 0.01 ijthdrev= 0.001 bvd = 10 xjbvd = 1
+pbs = 1 cjs = 0.0005 mjs = 0.5 pbsws = 1
+cjsws = 5e-010 mjsws = 0.33 pbswgs = 1 cjswgs = 3e-010
+mjswgs = 0.33 pbd = 1 cjd = 0.0005 mjd = 0.5
+pbswd = 1 cjswd = 5e-010 mjswd = 0.33 pbswgd = 1
+cjswgd = 5e-010 mjswgd = 0.33 tpb = 0.005 tcj = 0.001
+tpbsw = 0.005 tcjsw = 0.001 tpbswg = 0.005 tcjswg = 0.001
+xtis = 3 xtid = 3
+dmcg = 0e-006 dmci = 0e-006 dmdg = 0e-006 dmcgt = 0e-007
+dwj = 0.0e-008 xgw = 0e-007 xgl = 0e-008
+rshg = 0.4 gbmin = 1e-010 rbpb = 5 rbpd = 15
+rbps = 15 rbdb = 15 rbsb = 15 ngcon = 1
.endl
There are 4 vth0 in file. At least 4 spaces between vth0 and =, at least one space between = and corresponding value. One more thing what if I need to read only last 3 vth0 values, skipping first one. What changes I have to make.
There are more than one whitespace after vth\d and you are matching just one whitespace. You should match all whitespaces:
#!/usr/bin/perl
use strict;
use warnings;
open(my $file, "<", "abc.txt") || die ("Cannot open file.\n");
open(my $out, ">", "output.txt") || die ("Cannot open file.\n");
while (my $line = <$file>)
{
chomp $line;
if ($line =~ /\+vth\d\s+=\s+(\d+)/)
{
print $out "$1\n";
}
}
Here \s+ will match one or more whitespaces.
Output:
0
40
50
60
Use \s in a regex to match whitespace.
If you want to skip the first occurrence, keep a flag that tells you whether it was already skipped:
my $skip = 1;
while (<$INPUT>) {
if (/vth\d\s*=\s*(\d+)/) {
if ($skip) {
undef $skip; # Don't skip the following occurences.
} else {
print "$1\n";
}
}
}
At least 4 spaces between vth0 and =, at least one space between = and
corresponding value.
vth\d\s{4,}=\s+(\d+)
read only last 3 vth0 values, skipping first one.
Use a flag and if/else blocks to next on first match (or whatever condition you want)