How can I send data to my C converter?


 
Thread Tools Search this Thread
Top Forums Programming How can I send data to my C converter?
# 1  
Old 02-14-2012
How can I send data to my C converter?

Hello,
I have a directory structure of seismic files that are stored within about 1000 different directories. The directory structure is typically no more than two levels deep, and they are organized by station name and disc name. Each disc name folder contains a text file called 'vdaq.txt' that I need to convert. Thus, there about a thousand of these vdaq.txt files that I want to import into my C program which converts the file into it's required new binary format.

I can hand-type this command from a command line window:

vdaqconv ~/Documents/Sample_data/SEY08N13/vdaq.txt

and the converter will successfully recognize the file name and directory, do the conversion, and place the converted binary file back into the appropriate directory (in this case, ~/Documents/Sample_data/SEY08N13/).

I can also search for all instances of the file vdaq.txt by using the following command from the top of the directory structure:

find . -name 'vdaq.txt'

The result is a nice long table of all the subdirectories that contain the target file. The information found within the file changes, based on time and station location so I cannot jsut 'blanket copy' over the whole dataset; Each one must be individually converted .

I have tried to pipe the output from the find command into the converter thus:

find . -name 'vdaq.txt' | vdaqconv

However the result is that the converter appears to ignore the output from the find command.

How can I get the converter to process each line from the find command?

I have searched the forums, and probably haven't figured out the appropriate terms to find my answers. Could someone point me in the right direction? - Thanks.

-Daniel

---------- Post updated at 01:07 PM ---------- Previous update was at 11:29 AM ----------

..back from lunch with additional information.
I guess what I was looking for was the question:

How do I use the input from the find command as a series of command-line arguments for a C-code program?"

My sample output from the find command: ( I generated this snippet from the greater subset by using the >> command to output the find results into a sample text file.)
Quote:

./SEY/SEY08N13/vdaq.txt
./SEY/SEY04N23/vdaq.txt
./SEY/SEY07N33/vdaq.txt
./SEY/SEY03N42/vdaq.txt
./SEY/SEY04N29/vdaq.txt
./SEY/SEY03N44/vdaq.txt
./SEY/SEY07N32/vdaq.txt
./SEY/SEY04N33/vdaq.txt
./SEY/SEY07N36/vdaq.txt
./SEY/SEY04N26/vdaq.txt
./SEY/SEY04N01/vdaq.txt
./SEY/SEY07N13/vdaq.txt
./SUUS/SUUS06N09/vdaq.txt
./SUUS/SUUS04N05/vdaq.txt
./SUUS/SUUS04N23/vdaq.txt
./ULN/ULN06N02/20060703/vdaq.txt
./ULN/ULN06N02/20050802/vdaq.txt
./ULN/ULN06N02/20060721/vdaq.txt
./ULN/ULN06N03/20060727/vdaq.txt
./ULN/ULN06N01/vdaq.txt
./GOLD/GOLD04N09/vdaq.txt
./GOLD/GOLD03N01/vdaq.txt
./AND1/AND103N99/AND-1/vdaq.txt
./MGD/MGD06N32/vdaq.txt
I want to output this data into a program that accepts one command line argument representing the file name that will be converted from text format into binary format.

--Program code snippet:--
Quote:
int main(int argc, char **argv)
{

FILE *ASCII_Headerfile, *BIN_Headerfile;

/* Declare local variables */

int fhdr=0,len=0,Chval_type=0, Cnt=0, Arrayval = 1;
hdr.unknown = 0; /* There is a variable that has unknown meaning found within all hdr sample files. */
memset(spath,0,sizeof(spath)); /* clear the path of all unknowns */
if ( argc!=2){ /* No single argument is present. Assume file exists in the working directory. */
strncpy(ASCIIfile,"vdaq.txt",8);
printf(" Using default directory and default name vdaq.txt \n");
strncpy(spath,"./",2);
display_usage();

}
else {
/*An assumed file name is present in command line. Strip path and build the header filename */
strncpy(ASCIIfile,argv[1],strlen(argv[1]));
findpath();
}
strcat(spath,"viseis.hdr");
printf("The path is stored as '%s'\n",spath);

printf( "Reading file '%s'\n",ASCIIfile);


ASCII_Headerfile = fopen(ASCIIfile,"r"); /* Open the ascii file */
.
.
. extra program stuff snipped out of here.
.
.
So, the question is, how to I interface the two together? I would like to automate the conversion such that the output of the find command continually calls the converter whenever it finds another copy of the vdaq.txt file within the directory structure.
# 2  
Old 02-14-2012
Probably like:
Code:
find . -name 'vdaq.txt' | xargs vdaqconv

# 3  
Old 02-14-2012
Thanks for the tip. However, as written, my C program called vdaqconv is still acting as if there is no argument being passed to it, and it defaults to the default directory and displays useage information. It then blows up with a 'terminated by signal 11' error, as no target file exists in the topmost directory. I *will* however, look into xargs more to see if there is an option that is required. I didn't know about xargs, since I'm still learning unix/linux.

edit--

Okay, I see what is going on with xargs. I used the --verbose switch and this was the output being fed to the converter:
First the input:
Quote:
msugws@dynamic-mackeyke-msu:~/Documents/Sample_data/SEY_subset> find . -name 'vdaq.txt'
./SEYSAM05/vdaq.txt
./SEYSAM02/vdaq.txt
./SEYSAM04/vdaq.txt
./SEYSAM01/vdaq.txt
./SEYSAM03/vdaq.txt
msugws@dynamic-mackeyke-msu:~/Documents/Sample_data/SEY_subset>
Next, the command with the --verbose enabled:
Quote:
msugws@dynamic-mackeyke-msu:~/Documents/Sample_data/SEY_subset> find . -name 'vdaq.txt' | xargs --verbose vdaqconv
vdaqconv ./SEYSAM05/vdaq.txt ./SEYSAM02/vdaq.txt ./SEYSAM04/vdaq.txt ./SEYSAM01/vdaq.txt ./SEYSAM03/vdaq.txt

Using default directory and default name vdaq.txt

VDAQ2SEIS Revision {26/JAN/2012} : D Burk, NERSP Engineer,

Usage: vdaq2seis [switches] vdaqfile

vdaqfile = vdaq.txt ascii file (input)
.
.
.
stuff cut here
.
.
.
The path is stored as './viseis.hdr'
Reading file 'vdaq.txt'
xargs: vdaqconv: terminated by signal 11
msugws@dynamic-mackeyke-msu:~/Documents/Sample_data/SEY_subset>
So apparently, the xargs is loading all of the lines into the command line argument separated with white space. Either I need to rework my converter to handle an arbitrary number of command line arguments (up to between one and two thousand), or else come up with an alternative method. Maybe I can use xargs with a temporary file: Dump the find data into a file, open the file, use it for the conversion, then delete the file. Maybe embed it all in a .ksh script or something.

--Gotta go, thanks for your help thus far. It's gotten me unstuck, anyway and thinking about options.

Last edited by ws6transam; 02-14-2012 at 03:26 PM..
# 4  
Old 02-14-2012
Specify one argument to your script:
Code:
find . -name 'vdaq.txt' | xargs -n 1 vdaqconv

# 5  
Old 02-16-2012
Turk, Thanks a lot! That is the trick. I tested it on the sample directory and in just a flash, the sample files were converted. Now I can proceed with placing some logging information into the program and some error checks, rename the program from its working name to it's official name, then run it on the real thing.

-Dan

Thanks again, this looks like the way to go.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

UNIX C Send data to PHP

Helo, i try send data from Unix to PHP. What is the correctly way to do this ? i try: c char command ; sprintf(command , "php import.php %s",my_vars); system(command ); php $my_data = @ $argv; this work, but i am not sure that is the right way. an the special chargers are not in... (1 Reply)
Discussion started by: freaky4552
1 Replies

2. IP Networking

Packetize data to send it over tcp sockets

Hello All, I am very new to socket programming and client server architecture. I have to write a client which will send some data to server and server will display it on its console. I am ready with both client and server but my problem is with packetizing of data -- I have... (1 Reply)
Discussion started by: anand.shah
1 Replies

3. Shell Programming and Scripting

Take Data From a table and send it through mail

Hi can anyone help me in writing a code for taking data from a table and need to send that data through mail using mail -x command.. (3 Replies)
Discussion started by: ginrkf
3 Replies

4. Shell Programming and Scripting

To send a mail when the data in a folder changes

Hi All, i have a folder "fold" which will mostly have a date( like 1/2/2013 -a single date alone .whenever the date changes i shoud get a mail. could someone help me with this. (4 Replies)
Discussion started by: mahesh300182
4 Replies

5. Infrastructure Monitoring

Send statistical data via SNMP

I am working on a SunOS 5.10 Generic_142900-03 sun4v sparc SUNW,Netra-T2000 With this command: (Unix based cronjob) tail -1 FSC-xxxxxxxxx.stat | nawk -F, '{print $2}' I want to send the numeric output of this command from a statistical file which is updating constantly via SNMPv2 every 1... (4 Replies)
Discussion started by: thinktank
4 Replies

6. Programming

sockets - can you send data while waiting on select()

Hey guys, Is it possible to have a worker thread send data out a TCP connection while another thread is waiting using using select() on that same connection? If not, then what is the correct way to maintain a connection, react to incoming data, and send data over a TCP connection? Thanks... (16 Replies)
Discussion started by: scubanarc
16 Replies

7. Shell Programming and Scripting

send data with Perl

Hello! I want to sent data (pictures: pic.jpg or textfiles) to a server. The pictures should be stored in \my_pictures\beautiful_images. How can I do it with Perl? I think, that I should start with a socket?? Do you have a tutorial or a site, where I can read about it? I use the IDE Padre /... (1 Reply)
Discussion started by: la_dy82
1 Replies

8. Shell Programming and Scripting

Send data to standard input

Hello, I'm writting a korn script that executes a daemon in a remote server. The problem is that daemon doesn't go background until it receives an enter from the standard input, and it maintains the rsh opened until it get it. I'm looking for the best (efficient and elegant) way to do send the... (3 Replies)
Discussion started by: nefeli
3 Replies

9. Shell Programming and Scripting

Filter data and send email

Need script....We get sar file sa15 with 7 days data which gets appended.. we want filter and parse the outptu such that we should filter only last 48 hours data and then email it to out team. we read -- sar -f sa15 Please help me with the script either by use sar itself or even sar and awk... (10 Replies)
Discussion started by: noorm
10 Replies

10. Programming

Send flaged data ..

Hello ! I'm writing a chat program , and I have a curiozity. I'm curently using two ports ( sockets ) for client - server interconections. One socket is used for ordinary ( normal ) data ( Ex : data on main-chat ) , and the another ( two socket ) is used to send management data : ( Ex... (0 Replies)
Discussion started by: !_30
0 Replies
Login or Register to Ask a Question