Skip to content

Instantly share code, notes, and snippets.

@zhixe
Created July 9, 2018 08:58
Show Gist options
  • Save zhixe/6c0b1255090f80eab915ead6443fe175 to your computer and use it in GitHub Desktop.
Save zhixe/6c0b1255090f80eab915ead6443fe175 to your computer and use it in GitHub Desktop.
Created by SnippLeaf.com
#!/bin/bash
#rj name=Sort_NFH_p190 queue=idle logdir=000scratch/logs/10_script cpus=* mem=8000M io=1 schema=lineList.schema
###########################
# Setup environment
module add production
module add processing
module add prod
module add Nemo
# configure processing
. processing || exit 100
# list currently loaded modules and their versions
module list
###########################
{
# count job time
startTime=$(date +%s)
# defining input and output variables
indirProd=/p8/santos/sS11blkPr_044/loadedData/navi/Sheemanto_3D/Sheemanto_3D_12cable_WGS84_UTM46N.nav
indirNFH=/p8/santos/sS11blkPr_044/loadedData/navi/Sheemanto_3D/Sheemanto_3D_12cable_WGS84_UTM46N_NFH.nav/ORIG
outdir=/p8/santos/sS11blkPr_044/loadedData/navi/Sheemanto_3D/Sheemanto_3D_12cable_WGS84_UTM46N_NFH.nav
NFH_withoutTopHeaders=$outdir/NFH_withoutTopHeaders
positionNFH=$outdir/positionNFH
sourceNFH=$outdir/sourceNFH
topHeaders=$outdir/topHeaders
mkdir -p $outdir/NFH_withoutTopHeaders $outdir/positionNFH $outdir/sourceNFH $outdir/topHeaders
# display required variables and input
# display the output information
dispVars indirProd indirNFH outdir
# main program here || die "main program die"
## [TOP HEADERS] ##
cat $indirNFH/${p190} | awk '/H0100SURVEY AREA Sheemanto 3D Block SS11/,/H2600 13 STREAMER MAPPING A 1 S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 S11 S12/{print}' > $topHeaders/${line}_topHeaders.txt
# ls $indirNFH | while read a; do cat $a | awk '/H0100SURVEY AREA Sheemanto 3D Block SS11/,/H2600 13 STREAMER MAPPING A 1 S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 S11 S12/{print}' > $topHeaders/${a}.txt; done
## [NFH SOURCE HEADERS] ##
cat $indirProd/${p190} | awk '/VS3D/,/R0001/{print}' | grep -v "R0001" > $sourceNFH/${line}_sourceNFH.txt
# ls $indirProd | while read a; do cat $a | awk '/VS3D/,/R0001/{print}' | grep -v "R0001" > $sourceNFH/${a}.txt; done
## [NFH POSITION AND NFH GUN POSITION HEADERS] ##
cat $indirNFH/${p190} | awk '/H2600GENERATED BY ORCA 1.12.1 NF HYDROPHONES POSITIONS/,/VS3D/{print}' | grep -v "VS3D" > $positionNFH/${line}_positionNFH.txt
# ls $indirNFH | while read a; do cat $a | awk '/H2600GENERATED BY ORCA 1.12.1 NF HYDROPHONES POSITIONS/,/VS3D/{print}' | grep -v "VS3D" > $positionNFH/${a}.txt; done
## [NFH WITHOUT TOP HEADERS] ##
awk '
FNR==NR{
if(FNR%37==0){
a[++i]=val ORS $0;
val="";
next};
val=val?val ORS $0:$0;
next
}
count==65{
print a[++j] ORS val;
count="";
val=""}
/H2600GENERATED BY ORCA 1.12.1 NF HYDROPHONES POSITIONS/,/H2600GENERATED BY ORCA 1.12.1 GUN POSITIONS$/{
count++}
{
val=val?val ORS $0:$0
}
END{
if(count){
print a[++j] ORS val}
}' $sourceNFH/${line}_sourceNFH.txt $positionNFH/${line}_positionNFH.txt > $NFH_withoutTopHeaders/${line}_withoutTopHeaders.txt
#paste -d " " <(ls $sourceNFH) <(ls $positionNFH) | while read a b; do
# awk '
# FNR==NR{
# if(FNR%37==0){
# a[++i]=val ORS $0;
# val="";
# next};
# val=val?val ORS $0:$0;
# next
#}
#count==65{
# print a[++j] ORS val;
# count="";
# val=""}
#/H2600GENERATED BY ORCA 1.12.1 NF HYDROPHONES POSITIONS/,/H2600GENERATED BY ORCA 1.12.1 GUN POSITIONS$/{
# count++}
#{
# val=val?val ORS $0:$0
#}
#END{
# if(count){
# print a[++j] ORS val}
#}' $sourceNFH/${a} $positionNFH/${b} > $NFH_withoutTopHeaders/${a}_withoutTopHeaders.txt; done
## [COMPLETE NFH P190] ##
cat $topHeaders/${line}_topHeaders.txt $NFH_withoutTopHeaders/${line}_withoutTopHeaders.txt | sed '/^$/d' > $outdir/${p190}
# paste -d " " <(ls $topHeaders) <(ls $NFH_withoutTopHeaders) | while read a b; do $topHeaders/${a} $NFH_withoutTopHeaders/${b} | sed '/^$/d' > $indirNFH/${a}.p190; done
# display the output information
msg "output generated"
msg "Program completed successfully at $PWD hooray! ^_^"
# count job time
endTime=$(date +%s)
echo "$(basename $0): Total time = $((endTime-startTime)) seconds"
printf ""%dh:%dm:%ds"\n" $(((endTime-startTime)/3600)) $(((endTime-startTime)%3600/60)) $(((endTime-startTime)%60))
} 2>&1 | dateout || exit 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment