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.