04-05-2014
Help w/ Reading Matrix & Storing in dynamic array
First of I would just like to state that I am not looking for you guys to just do my work for me, I do want to learn and actually understand everything that is happening.
Hey all, I am having trouble on this. What I need to do is... Write an executable C file that will take a text file (not a specific file, will be tested with many) that contains a NxN matrix and read it into a dynamically allocated array so that I can manipulate it however I would like.
I am fairly new to Unix and C and am having trouble with writing the code out.
I understand the steps needed by my program:
1. Use a loop to Scan or get (idk correct terminology) # of rows and columns in the test file.
2. Allocate the proper amount of memory (using malloc) based on the number of rows and columns.
3. Once memory is allocated, create 2d array of the needed size.
4. Loop through and store everything in the test file into the array.
I guess I am just not familiar enough with writing my own code in this language, and also doesn't help that I am doing this through a putty Debian server (not noob friendly IMO). Anything I write I usually end up just scrapping an hour after because I feel I have gotten nowhere with it and end up just overwhelmed by the problem at hand.
So would anyone mind helping me out in any way possible? I am willing to do whatever it takes to get a grasp on this stuff, I need to know this so if anyone would perhaps like to skype or something (I feel it would be much much easier that way) please let me know!
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
All ..
I am having a pointer array . And trying to store the addess into that pointer array . please see below the problem i faced
code:
int cnt1;
char *t_array;
char *f_array;
for(cnt1=0; cnt1<1000; cnt1++)
{
t_array =... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies
2. Shell Programming and Scripting
Hi All,
I need some help with arrays. I need to take input from the user for hostname, username and password until he enters .(dot) or any other character and store the values in the variable array.
I would further connect to the hostname using username and passwd and copy files from server to... (7 Replies)
Discussion started by: nua7
7 Replies
3. Programming
I am facing a strange error while creating posix threads:
Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output.
Snippet 1
This works:
--------------
int *threadids;
threadids = (int *) malloc (num_threads * sizeof(int));
... (4 Replies)
Discussion started by: kmehta
4 Replies
4. Shell Programming and Scripting
hi i have a file as follows:
1
2
3
4
5
6
i want to store all these numbers in an array using awk.. so far i have:
awk '{for(i=1;i<=NR;i++) {a=$1}} END {for(i=1;i<=NR;i++) {printf("%1.11f",a)}}' 1.csv > test
however, i am getting all values as zero in the "test" file..... (3 Replies)
Discussion started by: npatwardhan
3 Replies
5. Shell Programming and Scripting
Hello,
i have a file "Movie.ini" looking e.g. like follows
* MOVIE A
bla bla
MOVIE B
blubb blubb
MOVIE C
I'd like to read the file "Movie.ini" with cat and grep and check whether it includes the string MOVIE only with a '*' at the beginnig.
By doing
"cat Movie.ini| grep MOVIE... (14 Replies)
Discussion started by: ABE2202
14 Replies
6. Shell Programming and Scripting
Hi folks,
I'm using bash and would like to do the following. I would like to read some values from the file and store it in the variable and use it.
My file is 1.txt and its contents are
VERSION=5.6
UPDATE=4
I would like to read "5.6" and "4" and store it in a variable in shell... (6 Replies)
Discussion started by: scriptfriend
6 Replies
7. Shell Programming and Scripting
Hi All,
I have a huge matrix file consisting some some millions rows and 6000 columns. The contents are just floating point numbers in the matrix. I want to extract each column (i.e. 6000 of them) and store each column in a separate file.
For example, 1.dat will consist of elements from column... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies
8. Programming
Hi,
I am trying to read a set of numbers that are in scientific notation into a file so I can do some math on them, but when I display the array contents the numbers aren't the same as the numbers in the file.
Could someone explain why? Thanks.
int main()
{
double fArray;
... (3 Replies)
Discussion started by: Filter500
3 Replies
9. Programming
I am trying to get userinput from stdin and store the lines in an array.
If i do this:
using a char **list to store strings
allocate memory to it
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv)
{
char *prog = argv;
char **linelist;
int... (5 Replies)
Discussion started by: tornow
5 Replies
10. Shell Programming and Scripting
I have a file like this:
ASSPASVFETQY,hTRBV12-4,hTRBJ2-5,2
ASSPASTGGDYGYT,hTRBV18,hTRBJ1-2,2
ASSPASGDGYT,hTRBV5-1,hTRBJ1-2,2
ASSPASFPEDTQY,hTRBV27,hTRBJ2-3,2
ASSPARVNYGYT,hTRBV5-1,hTRBJ1-2,2
ASSPARTSGGLNEQF,hTRBV6-4,hTRBJ2-1,2
ASSPARQSYNEQF,hTRBV11-1,hTRBJ2-1,2... (3 Replies)
Discussion started by: xshang
3 Replies
LEARN ABOUT REDHAT
dlabrd
DLABRD(l) ) DLABRD(l)
NAME
DLABRD - reduce the first NB rows and columns of a real general m by n matrix A to upper or lower bidiagonal form by an orthogonal trans-
formation Q' * A * P, and returns the matrices X and Y which are needed to apply the transformation to the unreduced part of A
SYNOPSIS
SUBROUTINE DLABRD( M, N, NB, A, LDA, D, E, TAUQ, TAUP, X, LDX, Y, LDY )
INTEGER LDA, LDX, LDY, M, N, NB
DOUBLE PRECISION A( LDA, * ), D( * ), E( * ), TAUP( * ), TAUQ( * ), X( LDX, * ), Y( LDY, * )
PURPOSE
DLABRD reduces the first NB rows and columns of a real general m by n matrix A to upper or lower bidiagonal form by an orthogonal transfor-
mation Q' * A * P, and returns the matrices X and Y which are needed to apply the transformation to the unreduced part of A. If m >= n, A
is reduced to upper bidiagonal form; if m < n, to lower bidiagonal form.
This is an auxiliary routine called by DGEBRD
ARGUMENTS
M (input) INTEGER
The number of rows in the matrix A.
N (input) INTEGER
The number of columns in the matrix A.
NB (input) INTEGER
The number of leading rows and columns of A to be reduced.
A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
On entry, the m by n general matrix to be reduced. On exit, the first NB rows and columns of the matrix are overwritten; the rest
of the array is unchanged. If m >= n, elements on and below the diagonal in the first NB columns, with the array TAUQ, represent
the orthogonal matrix Q as a product of elementary reflectors; and elements above the diagonal in the first NB rows, with the array
TAUP, represent the orthogonal matrix P as a product of elementary reflectors. If m < n, elements below the diagonal in the first
NB columns, with the array TAUQ, represent the orthogonal matrix Q as a product of elementary reflectors, and elements on and above
the diagonal in the first NB rows, with the array TAUP, represent the orthogonal matrix P as a product of elementary reflectors.
See Further Details. LDA (input) INTEGER The leading dimension of the array A. LDA >= max(1,M).
D (output) DOUBLE PRECISION array, dimension (NB)
The diagonal elements of the first NB rows and columns of the reduced matrix. D(i) = A(i,i).
E (output) DOUBLE PRECISION array, dimension (NB)
The off-diagonal elements of the first NB rows and columns of the reduced matrix.
TAUQ (output) DOUBLE PRECISION array dimension (NB)
The scalar factors of the elementary reflectors which represent the orthogonal matrix Q. See Further Details. TAUP (output)
DOUBLE PRECISION array, dimension (NB) The scalar factors of the elementary reflectors which represent the orthogonal matrix P. See
Further Details. X (output) DOUBLE PRECISION array, dimension (LDX,NB) The m-by-nb matrix X required to update the unreduced
part of A.
LDX (input) INTEGER
The leading dimension of the array X. LDX >= M.
Y (output) DOUBLE PRECISION array, dimension (LDY,NB)
The n-by-nb matrix Y required to update the unreduced part of A.
LDY (output) INTEGER
The leading dimension of the array Y. LDY >= N.
FURTHER DETAILS
The matrices Q and P are represented as products of elementary reflectors:
Q = H(1) H(2) . . . H(nb) and P = G(1) G(2) . . . G(nb)
Each H(i) and G(i) has the form:
H(i) = I - tauq * v * v' and G(i) = I - taup * u * u'
where tauq and taup are real scalars, and v and u are real vectors.
If m >= n, v(1:i-1) = 0, v(i) = 1, and v(i:m) is stored on exit in A(i:m,i); u(1:i) = 0, u(i+1) = 1, and u(i+1:n) is stored on exit in
A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
If m < n, v(1:i) = 0, v(i+1) = 1, and v(i+1:m) is stored on exit in A(i+2:m,i); u(1:i-1) = 0, u(i) = 1, and u(i:n) is stored on exit in
A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
The elements of the vectors v and u together form the m-by-nb matrix V and the nb-by-n matrix U' which are needed, with X and Y, to apply
the transformation to the unreduced part of the matrix, using a block update of the form: A := A - V*Y' - X*U'.
The contents of A on exit are illustrated by the following examples with nb = 2:
m = 6 and n = 5 (m > n): m = 5 and n = 6 (m < n):
( 1 1 u1 u1 u1 ) ( 1 u1 u1 u1 u1 u1 )
( v1 1 1 u2 u2 ) ( 1 1 u2 u2 u2 u2 )
( v1 v2 a a a ) ( v1 1 a a a a )
( v1 v2 a a a ) ( v1 v2 a a a a )
( v1 v2 a a a ) ( v1 v2 a a a a )
( v1 v2 a a a )
where a denotes an element of the original matrix which is unchanged, vi denotes an element of the vector defining H(i), and ui an element
of the vector defining G(i).
LAPACK version 3.0 15 June 2000 DLABRD(l)