wiki:Documentation/UserGuide/ShellScriptFind

Version 1 (modified by ychen, 9 years ago) (diff)

--

Sometimes, you may need some works for combining the ORCHIDEE results from the specific output frequency to a single file for the post analysis. Here, I made a simple bash script for your reference and you can combine the several files to a single file by running the following bash script. The commands, ncract, find, sort and export, will be used. See the following script for the detail.

#!/bin/bash

# search file names and rebuild
# set up working years
year=(1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000)

# set the experiment name
exp="BCLb"

# set the file path for searching files 
in_dir_path="/ccc/store/cont003/dsm/p529luy/IGCM_OUT/LMDZOR/PROD/amip/"$exp"/ATM/Output/DA"

#echo $in_dir_path
# move the path to search the files
cd $in_dir_path

# start the loop for searching the files...
for index in {0..19}
do
    echo "Search files on year: ${year[$index]}"
    # use the "find" and "sort" command to find the files 
    # and sort by the numeric number appears in the filenames 
    inputfilename=( $(find -name "${exp}_${year[$index]}*" | sort -n) )
    echo "PROCESSING input files: "${inputfilename[@]}

    # make a outout file name based on the working "exp" and "year" 
    export outputfilename="${exp}_${year[$index]}.nc"

    # use "ncrcat" command to re-create(combine) the nc file based on the searched inputfilename    
    ncrcat ${inputfilename[@]} /ccc/store/cont003/dsm/cheny/Daily/${exp}/$outputfilename

    echo "PLEASE CHECK output file: "$outputfilename
done 

echo "FINISHED THE COMBINE files job.. (AH-JA...)"$outputfilename

The above script combines output files (daily temp step monthly output) from 1981-2000.

You can change the path or year for your necessary.