[Swift-commit] r6029 - SwiftApps/ParVis/HiRAMTools

tmoore at ci.uchicago.edu tmoore at ci.uchicago.edu
Tue Nov 13 13:37:31 CST 2012


Author: tmoore
Date: 2012-11-13 13:37:30 -0600 (Tue, 13 Nov 2012)
New Revision: 6029

Added:
   SwiftApps/ParVis/HiRAMTools/realizationRealignScript.sh
   SwiftApps/ParVis/HiRAMTools/runRealign.sh
Log:
added some tools for working with 6 month cases

Added: SwiftApps/ParVis/HiRAMTools/realizationRealignScript.sh
===================================================================
--- SwiftApps/ParVis/HiRAMTools/realizationRealignScript.sh	                        (rev 0)
+++ SwiftApps/ParVis/HiRAMTools/realizationRealignScript.sh	2012-11-13 19:37:30 UTC (rev 6029)
@@ -0,0 +1,156 @@
+#!/bin/sh
+
+#set defaults
+YEAR="1950"
+WORKDIR=""
+TARGETDIR=""
+FILENAME=""
+GROUP="0"
+
+while getopts "hy:s:t:f:p:" opt; do
+	case $opt in
+	h)
+		echo "reorganize realization output v. 0.1 help" >&2
+		echo "options:" >&2
+		echo "-h - help" >&2
+		echo "-y - set the year, e.g. 1950. Must be between 1900-2999" >&2
+		echo "-s - original history file directory.(e.g. /intrepid-fs0/users/lzamboni/persistent/enstdIc2/history)" >&2
+		echo "-t - target directory - similar to the above, but a writable directory.)"  >&2
+		echo "-f - filename without full path. (e.g. atmos_4xdaily.tile1.nc.0000)"  >&2
+		echo "-p - 6 month period.  0 Jan-Jun, 1 Jul-Dec"  >&2
+		exit 1
+	;;
+	\?)
+		echo "Invalid option : -$OPTARG" >&2
+		exit 1
+	;;
+	y) YEAR="$OPTARG";;
+	s) WORKDIR="$OPTARG";;
+	t) TARGETDIR="$OPTARG";;
+	f) FILENAME="$OPTARG";;
+	p) GROUP="$OPTARG";;
+	esac
+done
+
+# Now we need to test the input options for validity
+#strip trailing slashes if present
+WORKDIR=`echo "${WORKDIR}" | sed -e "s/\/*$//" `
+TARGETDIR=`echo "${TARGETDIR}" | sed -e "s/\/*$//" `
+
+if [ ! -d "$WORKDIR" ]; then
+ 	echo "$WORKDIR does not appear to be a valid directory"
+	exit 1        
+fi
+if [ ! -d "$TARGETDIR" ]; then
+        echo "$TARGETDIR does not appear to be a valid directory"
+        exit 1
+fi
+
+#echo ${WORKDIR}
+#echo ${TARGETDIR}
+
+#test for empty file name
+
+LEN1=$(echo ${#FILENAME})
+if [ "$LEN1" -lt "1" ]; then
+	echo "Invalid file name"
+	exit 1
+fi
+
+#GROUP should always be less than 2
+if [ "$GROUP" -gt "1" ]; then
+	echo "Group setting must be 0 or 1"
+	exit 1
+fi
+
+if [ "$GROUP" -lt "0" ]; then
+        echo "Group setting must be 0 or 1"
+        exit 1
+fi
+
+#now we test the year.
+
+if [ "$YEAR" -gt "2999" ]; then
+	echo "This script only accepts years from 1900-2999"
+	exit 1
+fi
+
+if [ "$YEAR" -lt "1900" ]; then
+        echo "This script only accepts years from 1900-2999"
+        exit 1
+fi
+
+#we have a valid year. 
+
+PRIORYEAR=$(($YEAR-1))
+NEXTYEAR=$(($YEAR+1))
+ 
+#cd to working dir
+cd $WORKDIR
+
+#read a list of directories for our target year
+DIRS=( )
+for aDir in *
+do
+   if [[ "$aDir" == "$PRIORYEAR"* ]]; then
+	DIRS=("${DIRS[@]}" "${aDir}")
+   fi
+   if [[ "$aDir" == "$YEAR"* ]]; then
+        DIRS=("${DIRS[@]}" "${aDir}")
+   fi
+done	
+#DIRS=`ls -d ${PRIORYEAR}*/`
+#DIRS+=`ls -d ${YEAR}*/`
+
+for aDir in ${DIRS[*]}
+do
+	echo "${aDir}"
+done
+
+
+TARGETFILE="$TARGETDIR/$YEAR"
+if [ "$GROUP" = "0" ]; then
+	STARTDATE="$YEAR-1-1 0:00:0.1"
+	ENDDATE="$YEAR-7-1 0:00:0.0"
+	TARGETFILE="${TARGETFILE}0101"
+else
+        STARTDATE="$YEAR-7-1 0:00:0.1"
+        ENDDATE="$NEXTYEAR-1-1 0:00:0.0"
+	TARGETFILE="${TARGETFILE}0701"
+fi
+echo $STARTDATE
+echo $ENDDATE
+
+#build a list of files we'll use
+SOURCEFILES=""
+
+for ASOURCEDIR in ${DIRS[*]} 
+do
+	#echo $ASOURCEDIR
+	SOURCEFILES="$SOURCEFILES $WORKDIR/$ASOURCEDIR/$FILENAME"
+done
+
+#echo $SOURCEFILES
+#echo $TARGETFILE
+
+if [ ! -d "$TARGETFILE" ]; then
+	mkdir $TARGETFILE
+fi
+
+TARGETFILE="$TARGETFILE/$FILENAME"
+
+#echo $TARGETFILE
+
+#if the target file already exists, let's remove it.
+
+if [ -f "$TARGETFILE" ]
+then
+    echo "File already exists! Removing"
+    rm -Rf $TARGETFILE 
+fi
+
+#at this point, we're ready to give things a shot at concatenation, or other testing.
+
+cmd="ncrcat -d time,'${STARTDATE}','${ENDDATE}' ${SOURCEFILES} ${TARGETFILE}"
+echo $cmd
+eval $cmd


Property changes on: SwiftApps/ParVis/HiRAMTools/realizationRealignScript.sh
___________________________________________________________________
Added: svn:executable
   + *

Added: SwiftApps/ParVis/HiRAMTools/runRealign.sh
===================================================================
--- SwiftApps/ParVis/HiRAMTools/runRealign.sh	                        (rev 0)
+++ SwiftApps/ParVis/HiRAMTools/runRealign.sh	2012-11-13 19:37:30 UTC (rev 6029)
@@ -0,0 +1,72 @@
+#!/bin/sh
+
+#SOURCEDIR is the directory where all of the history files are located
+#SOURCEDIR=/intrepid-fs0/users/lzamboni/persistent/enstdIc2/history
+SOURCEDIR=/intrepid-fs0/projects/SU_Climate/tlmoore/originals/enstdIc2/history/
+
+#FILELISTDIR is a subdirectory in the SOURCEDIR that contains the filesnames
+#FILELISTDIR=/intrepid-fs0/users/lzamboni/persistent/enstdIc2/history/19500101
+FILELISTDIR=/intrepid-fs0/projects/SU_Climate/tlmoore/originals/enstdIc2/history/19500101
+
+STARTYEAR=1950
+ENDYEAR=2000
+SUBYEARS[0]=0
+SUBYEARS[1]=1
+
+#TARGETDIR is the location new files will be created
+TARGETDIR=/intrepid-fs0/projects/SU_Climate/tlmoore/processed/enstdIc2/history
+
+
+#need to start with a list of files
+
+cd $FILELISTDIR
+TARGETFILENAMES=( )
+for aFile in *
+do
+#	echo $aFile
+	TARGETFILENAMES=("${TARGETFILENAMES[@]}" "${aFile}");
+done
+##echo "${TARGETFILENAMES}"
+#let's organize years
+YEARS=( )
+while [ $((STARTYEAR)) -lt $((ENDYEAR)) ]
+do
+	YEARS=("${YEARS[@]}" "${STARTYEAR}");
+	STARTYEAR=$[$STARTYEAR+1]
+done
+
+#validate starting info
+
+#for aYear in ${YEARS[@]}
+#do 
+#   echo $aYear
+#done
+
+#for aName in ${TARGETFILENAMES[@]}
+#do
+#   echo $aName
+#done
+
+#for aSubyear in ${SUBYEARS[@]}
+#do
+#	echo $aSubyear
+#done
+
+ 
+# Here we loop through the possibilities to create our files
+
+echo "starting"
+for aYear in ${YEARS[@]}
+do
+	#echo "Doing ${aYear}"
+	for aName in ${TARGETFILENAMES[@]}
+	do
+		#echo $aName
+		for aSubyear in ${SUBYEARS[@]}
+		do
+			echo "${aYear} ${aName} ${aSubyear}"
+			/home/tlmoore/Documents/realizationRealignScript.sh -y $aYear -s $SOURCEDIR -t $TARGETDIR -f $aName -p $aSubyear
+		done		
+	done
+
+done 


Property changes on: SwiftApps/ParVis/HiRAMTools/runRealign.sh
___________________________________________________________________
Added: svn:executable
   + *




More information about the Swift-commit mailing list