function cavepts = cavemap(surveydata) %------------------------------------------------------------------------------------- %************************** PROGRAM DESCRIPTION CAVEMAP.m **************************** % This cave mapping software includes three main programs (CAVEMAP.m, EXPAND.m, and % PERIM.m) and three subroutines (PLOTTER.m, PLOTTER2.m, and CONVERT.m). All of the % programs are written for MatLab by MathWorks Inc. and take advantage of its % graphical capabilities. Combined, the programs are designed to convert survey data % describing the trends and cross-sectional profiles of connected conduits in a cave % system into three- dimensional Cartesian coordinates. All six programs must be % contained within the same folder. % Output consists of (1) a two-dimensional map of the cave system described by the % input data, (2) an ascii file containing (x,y,z) points describing the top half % of the cave, (3) an ascii file containing (x,y,z) points describing the bottom % half of the cave, (4) an ascii file containing (x,y) points describing the % outermost perimeter of the cave, and (5) a three-dimensional plot of the output % points. % CAVEMAP.m will convert survey data to x,y,z coordinates for the survey line, % walls, and top and bottom of a cave. It will then expand the data set % with EXPAND.m by linear interpolation between survey stations creating nine % new points between each consecutive pair. From there, it will calculate x,y,z % coordinates for the perimeter at each station using PERIM.m. % CAVEMAP.m will first plot the data in PLOTTER.m allowing the user to check for % conflicting cross-section lines that will produce errors in the subsequent % data expansion. Conflicts must be resolved by manual manipulation of the % output x,y,z coordinate data (survpts.txt). Amended x,y,z data must then be % entered into EXPAND.m. % Required data consists of a 10 column matrix constructed as: % col #1 = ssj = a row of markers indicating the tie-in survey station % for any jump in terms of the numerical order in which % it appears in the input list i.e. if there is a jump from % the 5th station in the input list, then ssj will equal 5 % for the first line of data describing that jump and ssj = 0 % for all stations other than the tie-ins. % col #2 = ss = the survey station # where the tie-in station at any jump is % described by 1000 + (the station number) for a first order jump, % 2000 + (the station number) for a second order jump, 3000 + (the % station number) for a third order jump, etc. % col #3 = az = forward azmith reading entered in degrees between consecutive ss's. % col #4 = dis = distance between the ss and the prior ss - can be in any % units including knots. % col #5 = depth = depth at the ss. % col #6 = disrt = distance to the right wall of the cave perpendicular to % the azmith reading. % col #7 = dislt = distance to the left wall of the cave perpendicular to % the azmith reading. % col #8 = depthtop = depth at the top of the cave. % col #9 = depthbot = depth at the bottom of the cave. % col #10 = room = indicator showing whether or not there are two survey % lines running down the walls of the same large room % (used in PERIM.m for perimeter calculations. %------------------------------------------------------------------------------------- %****************** DETERMINING SIZE OF THE INPUT DATA MATRIX ************************ [row,col] = size(surveydata); %------------------------------------------------------------------------------------- %************** ESTABLISHING DISTANCE VECTOR IN TERMS OF INPUT UNITS ***************** % Input from user whether distance is expressed in knots or units of measurement. If % expressed in knots, they are converted to distances of units that were input % otherwise a distance vector is created. disp(' ') disp(' ') disp(' Is distance expressed in terms of knots?') ktquerry = input(' Y/N [Y] ','s'); if isempty(ktquerry) ktquerry = 'Y'; end if ktquerry == 'Y' knots = surveydata(:,4); knotlength = input(' How many units per knot? '); dis = knots * knotlength; else if ktquerry == 'y' knots = surveydata(:,4); knotlength = input(' How many units per knot? '); dis = knots * knotlength; else dis = surveydata(:,4); end end %------------------------------------------------------------------------------------- %******************* EXTRACTING OTHER DATA FROM INPUT MATRIX ************************* ssj = surveydata(:,1); ss = surveydata(:,2); azmith = surveydata(:,3); depth = surveydata(:,5); disrt = surveydata(:,6); dislt = surveydata(:,7); depthtop = surveydata(:,8); depthbot = surveydata(:,9); room = surveydata(:,10); %------------------------------------------------------------------------------------- %***************** CONVERTING AZMITHS FROM DEGREES TO RADIANS ************************ az = ((2 * pi) / 360) * azmith; %------------------------------------------------------------------------------------- %************* CALCULATING RECTILINEAR DISTANCES BETWEEN SURVEY STATIONS ************* % Converts distance / azmith data to rectilinear corrdinates recchk = input(' convert distances to rectilinear coordinates? [Y/N] ','s'); if isempty(recchk) recchk = 'Y'; end if recchk == 'y' recchk = 'Y'; end if recchk == 'Y' RecDis(1) = 0; for i = 2:row D2=depth(i); D1=depth(i-1); if ss(i)>1000 RecDis(i)=0; else if dis(i) < abs((D2-D1)) RecDis(i) = 0; else RecDis(i) = sqrt(dis(i)^2 - (D2-D1)^2); end end end RecDis = RecDis'; else RecDis = dis; end %------------------------------------------------------------------------------------- %**************** CONVERTING SURVEY DATA TO X,Y,Z COORDINATES ************************ % creating an input matrix new_data = [ssj ss az RecDis depth disrt dislt depthtop depthbot room]; % calling the conversion function convert.m surveypts = convert(new_data); %------------------------------------------------------------------------------------- %***************************** EXTRACTING WALL POINTS ******************************** wallptsr = surveypts(:,8:9); wallptsl = surveypts(:,10:11); wallpts = [wallptsr' wallptsl']'; [new_row,new_col] = size(wallpts); wallpoints = [0 0]'; wallct = 0; for i = 1:new_row if wallpts(i,1) ~= -999.9 wallpoints = [wallpoints wallpts(i,1:2)']; wallct = wallct + 1; end end wallpoints = wallpoints(:,2:wallct)'; %------------------------------------------------------------------------------------- %*************************** PLOTTING ORIGINAL DATA ********************************** plotter(surveypts) disp(' '); disp(' If there are no crosses in the transect lines between') disp(' consecutive wall point pairs then proceed. Otherwise') disp(' print out the data points and pick new point pairs. ') %------------------------------------------------------------------------------------- %******************************* EXPANDING DATASET *********************************** disp(' ') disp(' ') disp(' Do you wish to proceed with the program or print out the ') disp(' results now and quit the program to build a new data set?') disp(' [P]roceed / P[r]int') disp(' ') disp(' ') proceedchk = input(' Enter your choice [P / r] ','s'); if isempty(proceedchk) proceedchk = 'P'; end if proceedchk == 'p' proceedchk = 'P'; end if proceedchk == 'P' expdata = expand(surveypts); else save survpts.txt surveypts -ascii -tabs save wallpts.txt wallpoints -ascii -tabs end %------------------------------------------------------------------------------------- %***************************** END PROGRAM CAVEMAP.m *********************************