Homework 2b: Sample script xyz2llh

4 downloads 1460 Views 25KB Size Report
Feb 26, 2003 ... echo "The number of points to process is: " $num_point set count = 0 ... set a2 = ` echo 'scale=20; ' $s_maj_ax '*' $s_maj_ax | bc -l`.
#!/bin/csh -f # # G. Mattioli, UARK; 2/26/03 # Program to convert ECEF coordinates into Lat Lon HAE # xyz2llh input_file # # # Accept data from a file with free format of 4 fields: # point_num X Y Z # # point processing loop # get input filename and make a copy set input_file = $1 cp ${input_file} t set filename = t set num_point = `wc -l $filename | awk '{print $1}'` echo "The number of points to process is: " $num_point set count = 0 while ( $count < $num_point ) set point = `sed -n '1p' $filename` sed '1d' ${filename} > t_file mv t_file ${filename} set point_num = `echo $point | awk '{print $1}'` echo "Processing point number: " $point_num echo "The ECEF coordinates to convert are:" set X_value = `echo $point | awk '{print $2}'` set Y_value = `echo $point | awk '{print $3}'` set Z_value = `echo $point | awk '{print $4}'` echo "X = " $X_value echo "Y = " $Y_value echo "Z = " $Z_value # # Now that the data is in, begin the processing # Setup ellipsoidal parameters # set pi = `echo 'scale=20; 4*a(1)' | bc -l` # Reference ellipsoid is the NAD83/GRS80 set s_maj_ax = 6378137.0 set s_min_ax = 6356752.31425 # GIPSY-JPL values #set s_maj_ax = 6378136.0 #set s_min_ax = 6356751.30157 #set f = 0.0033528131778969 #set s_min_ax = `echo 'scale=16; ' $s_maj_ax '-' $s_maj_ax '*' $f | bc -l` set a2 = `echo 'scale=20; ' $s_maj_ax '*' $s_maj_ax | bc -l` set b2 = `echo 'scale=20; ' $s_min_ax '*' $s_min_ax | bc -l`

set e2 = `echo 'scale=20; (' $a2 '-' $b2 ') /' $a2 | bc -l` # # Calculate longitude, which is exactly fixed set lon_r = `echo 'scale=20; a (' $Y_value '/' $X_value ')' | bc -l` set lon_d = `echo 'scale=20; 180.0 / ' $pi '*' $lon_r | bc -l` # # Initial calculation of latitude # set p = `echo 'scale=20; sqrt (' $X_value '^2 +' $Y_value' ^2 )' | bc -l` set lat_init_r = `echo 'scale=20; a (' $Z_value '/' $p '*(1 -' $e2') )' | bc -l` set lat_init_d = `echo 'scale=20; 180.0 / ' $pi '*' $lat_init_r | bc -l` # # Start of while loop for latitude and HAE # set conv_crit = 0.000000000000 set lat_diff = 1.0 set it_test = `echo 'scale=20; ' $lat_diff '>' $conv_crit | bc -l` while ( $it_test > '0' ) set lat_cos = `echo 'scale=20; c (' $lat_init_r ')' | bc -l` set lat_cos2 = `echo 'scale=20; '$lat_cos '^2' | bc -l` set lat_sin = `echo 'scale=20; s (' $lat_init_r ')' | bc -l` set lat_sin2 = `echo 'scale=20; '$lat_sin '^2' | bc -l` set N = `echo 'scale=20; '$a2 '/ sqrt ('$a2'*'$lat_cos2'+'$b2'*'$lat_sin2')' | bc -l` set h = `echo 'scale=20; '$p '/' $lat_cos '-' $N | bc -l` set Nh = `echo 'scale=20; '$N '/ (' $N '+' $h ')' | bc -l` set lat_tan_new_r = `echo 'scale=20; (' $Z_value '/' $p ') * ( 1 -' $e2 '*' $Nh ')^-1' | bc -l` set lat_new_r = `echo 'scale=20; a (' $lat_tan_new_r ')' | bc -l` set lat_new_d = `echo 'scale=20; 180.0 / ' $pi '*' $lat_new_r | bc -l` # make sure that calculated difference is always positive set lat_diff = `echo 'scale=20; ' $lat_new_r '-' $lat_init_r | bc -l` set lat_diff = `echo 'scale=20; sqrt (' $lat_diff '^2 )' | bc -l` set it_test = `echo 'scale=20; ' $lat_diff '>' $conv_crit | bc -l` set lat_init_r = $lat_new_r end # truncate lat and lon to 10 sig digits set lat_new_d = `echo 'scale=10; ' $lat_new_d '/ 1.0' | bc -l` set lon_d = `echo 'scale=10; ' $lon_d '/ 1.0' | bc -l` echo "The Final Geodetic Coordinates are: " echo "Latitude: " $lat_new_d echo "Longitude: " $lon_d # truncate height to nearest 0.1 mm set h = `echo 'scale=4; ' $h '/ 1.0' | bc -l`

echo "HAE (m): " $h @ count++ end echo "There are no more points to process" rm t