/* This program recursively reads a station # from a dir.dat file, builds */ /* directory paths, explodes all working files, creates a station output */ /* directory, builds the annual files for each station, and compresses */ /* them into an the individual station directory. */ /* Note : This program should be run from the working directory NOT the */ /* output directory. */ /* ------------------------------------------------------------------------ */ #include "string.h" #include "stdio.h" #include "stdlib.h" void main(argc, argv) int argc; char *argv[]; { int stn_no = 1, nyr = 0, nchdir = 0, nchdir2 = 0; char zcat[151], name_line[147], data_dir[80] = "", data_dir2[80], subdir[6], ayr[5], ayrdat[30], uncompressed[151]; char name_list[80] = "", zcat0[] = "zcat ", compress[151], del0[] = "del ", deleteu[133] = "", deletez[133] = "", compress0[] = "compress -k -b 14 -O"; FILE *name_dir; if(argc == 1) { printf("This program requires 3 arguments : \n"); printf(" Name 1st argument is the complete path to the input working"); printf(" name list\n"); printf(" The 2nd argument is the directory path which will contain\n"); printf(" all the input working files (e.g. l:\\nrel\\12345-61.z .....)\n"); printf(" The 3rd argument is the output directory path which will contain\n"); printf(" all of the annual files (e.g. l:\\nrel\\data\\12345-61.z ...\n"); printf("\n\nEnter path to name list file :\n"); gets(name_list); printf("\n\nEnter path to input working directory :\n"); gets(data_dir); printf("\n\nEnter path to output directory :\n"); gets(data_dir2); } else if(argc == 2) { printf("A 2nd argument is needed to give the directory path which\n"); printf(" contains all the input files (e.g. l:\\nrel\\12345.z ....)\n"); printf("A 3rd argument is needed to give the output directory path which\n"); printf(" will contain all the output files (e.g. l:nrel\\data\\12345.z,....)\n"); printf("\n\nEnter path to input working directory :\n"); gets(data_dir); printf("\n\nEnter path to output directory :\n"); gets(data_dir2); } else if(argc == 3) { printf("A 3rd argument is needed to give the output directory path which\n"); printf(" will contain all the output files (e.g. l:\\nrel\\data\\12345.z,....)\n"); printf("\n\nEnter path to output directory :\n"); gets(data_dir2); } else if(argc >= 4) { strcpy(name_list, argv[1]); strcpy(data_dir, argv[2]); strcpy(data_dir2, argv[3]); } /* name_dir = file containing station information which are to be moved */ if((name_dir = fopen(name_list,"rt"))==NULL) { printf("Can't open %s\n", name_list); exit(0); } nchdir = strlen(data_dir); if(data_dir[nchdir-1] != '\\') strcat(data_dir, "\\"); nchdir2 = strlen(data_dir2); if(data_dir2[nchdir2-1] != '\\') strcat(data_dir2, "\\"); /* fgets reads each new zipline character string which contains the filename information */ while (fgets(name_line, 147, name_dir)!=NULL) { /* Build path strings for each file to be exploded for processing */ strncpy(subdir, &name_line[0], 5); subdir[5] = NULL; printf("Begin processing station # : %s \n", subdir); for(nyr = 61; nyr <= 90; ++nyr) { itoa(nyr, ayr,10); strcpy(zcat, zcat0); strcat(zcat, data_dir2); strcat(zcat, subdir); strcat(zcat, "\\"); strcpy(ayrdat, subdir); strcat(ayrdat, "-"); strcat(ayrdat, ayr); strcat(ayrdat, ".z "); strcat(zcat, ayrdat); strcat(zcat, " > "); strcpy(uncompressed, data_dir2); strcat(uncompressed, subdir); strcat(uncompressed, "\\"); strcat(uncompressed, ayr); strcat(uncompressed, "."); strcat(zcat, uncompressed); printf("%s\n",zcat); system(zcat); /* compress each annual output file into the station sub-directory */ /* (compress -k -b 14 -Oj:\nrel\xxxxx\ nn. c:\nrel\vol0\xxxxx\nn.dat, */ /* where xxxxx = station wban #, */ /* nn = 2 digit year) */ printf("Begin compressing station # : %s\n", subdir); strcpy(compress, compress0); strcat(compress, data_dir2); strcat(compress, subdir); strcat(compress, "\\ "); strcat(compress, data_dir2); strcat(compress, subdir); strcat(compress, "\\"); strcat(compress, ayr); strcat(compress, ". "); printf("%s\n",compress); system(compress); strcpy(deleteu, del0); strcat(deleteu, uncompressed); system(deleteu); } /* delete old .z files, initialize, get next station */ strcpy(deletez, del0); strcat(deletez, data_dir2); strcat(deletez, subdir); strcat(deletez, "\\"); strcat(deletez, subdir); strcat(deletez, "-??.z"); /* system(deletez); */ printf("%s\n", deletez); deleteu[0] = NULL; deletez[0] = NULL; compress[0] = NULL; ayrdat[0] = NULL; ++stn_no; } }