The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

DOCUMENTATION

SYNOPSIS

PERL PROGRAM NAME: readfiles 
AUTHOR: Juan Lorenzo
DATE: Oct 29 2012
DESCRIPTION read file operations
Version 1use aliased 'App::SeismicUnixGui::misc::control'; # '0.0.3'
        2 May 31 2016, Mom's 83 birthday
        2.1 June 29, 2016 
Add reading configuration file hashes

Notes: 
Package name is the same as the file name
Moose is a package that allows an object-oriented
syntax to organizing your programs

STEPS ARE:

USAGE 1

Read a file with one colume of text 
Read each line

Example
       $readfiles->ref_file($list);
       $readfiles-Step();

sub clear:

clean hash of its values

sub cols_1

read files cols 1 in a text file
open the file of interest
first item has index=1
declare local variables  
counter, a number, row number  
read contents of list, e.g. shotpoint geometry file, file names etc.

sub cols_1p

read files cols 1 in a text file
open the file of interest
1st item has index=0
exclude empty lines
declare local variables  
counter, a number, row number  
read contents of list, e.g. shotpoint geometry file, file names etc.

sub cols_2p

reads cols 1 and 2 in a text file

sub cols_2

reads cols 1 and 2 in a text file

sub cfg

file is a character array scalar 
actually a scalar reference to a string

# my $file1 = '/usr/local/pl/System_Variables_config.pl'; # print("readfiles,cfg,HOME=$CFG->{Project_Variables}{1}{HOME}\n") # print ("readfiles,cfg,Doing $file \n\n"); # print ("A hash: variables $variables \n\n"); # #print ("log is $CFG->{log}{level} \n\n"); # ## Check for errors #my $file = '/usr/local/pl/System_Variables_config.pl'; # my $file1 = '/usr/local/pl/Sudipfilt_config.pl';

sub configs

read configuration parameter files
for seismic unix modules
and for tool (superflow) modules
(not for user-built flows)

TODO: since sub configs= sub params
      ONLY NEED TO USE ONE OF THEM 
      AMONG ANY PROGRAM
   set the counter
   uses the perl convention -- first index is 0
   readfiles contents of a file
   print ("\nThis file contains ($max_index +1) row(s) of data\n");	
   print("line $i is $line");
   print ("\nThis file contains $num_rows row(s) of data\n");
  regex:
   trim white spaces from both ends
   split on '=' and its surrounding spaces
   
    control does the following:
     # 1. remove double quotes if they exist
     #  anywhere in the line
	$x =~ tr/"//d;
			
     # 2. remove extra single quotes if they exist at the start of the string
     $x =~ s/^'//;
     		
    # 3. remove extra single quotes if they exist at the end of the string     							
	$x =~ s/'$//; 
	# print("after removing only a last single quote: $x\n ");
	     		# 4. determine whether we have a string or a number
			my $fmt	=	0;
			$fmt  	= 	looks_like_number($x);
			
			if ($fmt) {
				# printf("$x looks like a number \n");
				# do nothing
				
			} else {		
				# printf("$x does not look like a number \n");
				my $x_as_string = '\''.$x.'\'';
				print (" Made $x into a string: $x_as_string\n");
				$x				= $x_as_string;
			}

sub get_cols_3

reads cols 1 through 3 in a text file

sub get_cols_8

reads cols 1 through 7 in a text file

sub params

read parameter files
for seismic unix modules
  print("readfiles,params,this:$this\n");
  set the counter
  uses the perl convention -- first index is 0

  readfiles contents of shotpoint geometry file
print ("\nThis file contains ($max_index +1) row(s) of data\n");	
  print("line $i is $line");
  print ("\nThis file contains $num_rows row(s) of data\n");

 regex:
  trim white spaces from both ends
  split on '=' and its surrounding spaces

sub set_file_name

sub set_path

sub set_skip_lines