Created
March 19, 2021 13:56
-
-
Save kwinkunks/0f9a8c620eda219fb6609debbaa73a78 to your computer and use it in GitHub Desktop.
Old-school conversion of SEG-Y to TIFF (requires segy2ascii and pnmtotiff)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/csh | |
# ++++++++++++++++++++++ | |
# segy2ascii | |
# Matt Hall, October 2009 | |
# Converts SEGY file to a TIFF, one sample per pixel | |
# First, export a SEGY file from Poststack, putting Trace in byte 13 | |
# Note the name of the project and the name of the file | |
# Run this file and follow the instructions | |
# ++++++++++++++++++++++ | |
# | |
# Set up script | |
date >> /tmp/segy2ascii-$USER.tmp | |
echo "Starting job" >> /tmp/segy2ascii-$USER.tmp | |
# | |
# Get the information required by this script | |
echo | |
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++" | |
echo "Segy2tiff" | |
echo "by Matt Hall and the authors of segy2ascii and NetPBM" | |
echo | |
echo "You should already have a SGY file, exported from" | |
echo "a 16-bit seismic SeisWorks file from PostStack," | |
echo "with the Trace number in byte 13. If you haven't" | |
echo "done this yet, please press Ctrl-C now and do it." | |
echo | |
echo "Press Ctrl-C at any time to stop this script." | |
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++" | |
echo | |
echo "Please provide the name of your SeisWorks project." | |
echo "Type the name now, then hit Enter..." | |
set myproj = $< | |
echo "Please enter the name of the SGY file, including the" | |
echo "extension..." | |
set myfilename = $< | |
#set myfilename = "matt.sgy" | |
set myfile = /seis_sys/$myproj/$myfilename | |
# Check the SGY file exists so the job can proceed | |
if ( -f $myfile ) then | |
echo "Using file $myfile." | |
echo | |
echo "Using file $myfile" >> /tmp/segy2ascii-$USER.tmp | |
else | |
echo "You must provide the name of an existing SGY file." | |
echo "/seis_sys/$myproj/$myfilename does not exist. Exiting. Please try again." | |
echo "SGY file does not exist. Exiting." >> /tmp/segy2ascii-$USER.tmp | |
exit 1 | |
endif | |
echo "Please enter the file's time range in SECONDS..." | |
set totaltime = $< | |
echo "Please enter the sample interval in MILLISECONDS..." | |
set timeinterval = $< | |
echo "Collected variables." >> /tmp/segy2ascii-$USER.tmp | |
set samples | |
@ samples = ( 1000 * $totaltime / $timeinterval + 1 ) | |
set linesperrecord | |
@ linesperrecord = ( $samples + 1 ) | |
echo "Set number of samples to $samples." | |
echo "Set number of samples to $samples." >> /tmp/segy2ascii-$USER.tmp | |
# | |
# Swap byte order | |
echo -n "Swapping byte order... " | |
~hallmt/bin/segy2ascii/segyswap $myfile /tmp/segy2ascii-$USER-swap.dat 1 >> /tmp/segy2ascii-$USER-byteorderlog.dat | |
echo "Done." | |
echo "Byte order swapped successfully." >> /tmp/segy2ascii-$USER.tmp | |
# | |
# Convert to ascii | |
echo -n "Converting to xyz... " | |
~hallmt/bin/segy2ascii/segy2xyz /tmp/segy2ascii-$USER-swap.dat /tmp/segy2ascii-$USER-xyz.dat 0 chan >> /tmp/segy2ascii-$USER.tmp | |
echo "Done." | |
echo "Converted to xyz successfully." >> /tmp/segy2ascii-$USER.tmp | |
# | |
# Get number of traces | |
echo -n "Getting number of traces... " | |
set wc_fields = `wc /tmp/segy2ascii-$USER-xyz.dat` | |
set traces | |
@ traces = ( $wc_fields[1] / $linesperrecord ) | |
echo "Set number of traces as $traces." >> /tmp/segy2ascii-$USER.tmp | |
echo "$traces." | |
# | |
# Make the PGM file | |
echo -n "Converting XYZ to PGM... " | |
awk -f ~hallmt/bin/segy2ascii/segy2pgm -v rows=$samples -v columns=$traces /tmp/segy2ascii-$USER-xyz.dat > /tmp/segy2ascii-$USER-pgm.dat | |
echo "Done." | |
echo "Converted to PGM successfully." >> /tmp/segy2ascii-$USER.tmp | |
# | |
# Convert to TIFF | |
echo -n "Converting to PGM to TIFF... " | |
pnmtotiff < /tmp/segy2ascii-$USER-pgm.dat > $myfilename.tif | |
echo "Done." | |
echo "Converted file to TIFF." >> /tmp/segy2ascii-$USER.tmp | |
# | |
# Clean up | |
echo -n "Cleaning up temporary files... " | |
rm /tmp/segy2ascii-$USER-*.dat | |
echo "Done." | |
echo "Cleaned up temporary files." >> /tmp/segy2ascii-$USER.tmp | |
# | |
# End | |
echo | |
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++" | |
# | |
# Check for output file | |
if ( -f $myfilename.tif ) then | |
echo "Done." | |
echo "Your TIFF file is called ./$myfilename.tif" | |
echo "Your TIFF file is called ./$myfilename.tif" >> /tmp/segy2ascii-$USER.tmp | |
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++" | |
echo | |
exit 0 | |
else | |
echo "File creation failed." | |
echo "File creation failed." >> /tmp/segy2ascii-$USER.tmp | |
echo "Please see job log in /tmp/segy2ascii-$USER.tmp" | |
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++" | |
echo | |
exit 1 | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment