<HTML>
<HEAD>
<TITLE>/*this program SLOPE.C calculates slopes, altitudes and real distances (corrected</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF"><FONT SIZE=4>/*this program SLOPE.C calculates slopes, altitudes and real distances (corrected</FONT><FONT SIZE=2><P><A HREF="1st.htm">Back to higher level</A><P></FONT>

<PRE>by slopes) below a transect using heigth line data of a physical map

for this it begins from the highest point of the mountain, first proceeds to
northeast till reaching a plain, then (beginning from the highest point again)
proceeds to southwest until reaching a plain*/

#include "my.h"
#include <math.h>
#define SCALE 136.1 /* how many meters is one cm on the map*/
#define ISOALTDIST 20 /*height difference between two height lines on the map (in meters)*/
#define SAMPLINGDIST 50 /*sampling distance in meters*/
#define TOPP 3.45 /*centimeter location of mountain TOPP on transect*/
#define TOPPALTI 3580 /*altitude at TOPP exaggerated by next higher hypothetical height line*/
#define REALTOPPALTI 3565 /*real altitude at TOPP*/
#define SAMPLENONE 24 /*number of samples in NE direction*/
#define SAMPLENOSW 44 /*number of samples in SE direction*/
#define MAGNDECL 1.25 /*magnetic declination in degrees*/
#define LENMINLAT 13.35 /*length of one minute latitude on the map in cm*/
#define LENMINLONG 11.1 /*length of one minute longitude on the map in cm*/

main()
{float alt[SAMPLENONE+1+SAMPLENOSW];float reallen[SAMPLENONE+1+SAMPLENOSW];float realdist[SAMPLENONE+SAMPLENOSW];float gradtosec(float);
float slope[SAMPLENONE+1+SAMPLENOSW];float north[SAMPLENONE+1+SAMPLENOSW];float east[SAMPLENONE+1+SAMPLENOSW];
float precisne[8]={-1000,0.0,1.28,1.90,2.40,2.65,3.00,TOPP}; /*centimeter locations of height lines*/
int i,dec,sign;
float precissw[9]={1000,7.8,6.4,5.2,4.6,4.25,3.95,3.2,TOPP};
float nn=(0.2/LENMINLAT);float ee=(10.85/LENMINLONG);/*coordinates of TOPP in seconds;from the map*/
float hypot[SAMPLENONE+1+SAMPLENOSW];/*hypotenuse length in meters*/
float x,gone;
FILE *out;
FILE *in;
char hg[20],hgz[2];
char ch;
int j;


x=((REALTOPPALTI-TOPPALTI+ISOALTDIST)/(float)ISOALTDIST);/*hypotenuse corrector for top*/
realdist[SAMPLENONE+1]=0;  /*distance and hypotenuse at TOPP*/
hypot[SAMPLENONE+1]=((precissw[7]-TOPP)*SCALE)/x;

/* go northeast*/
i=SAMPLENONE;
while (i>0)
{int j=7;alt[i]=TOPPALTI;printf("\n\n\n i: %d     ",i);
while (-realdist[i+1]+SAMPLINGDIST>(TOPP-precisne[j-1])*SCALE) {printf("realdist: %f, lastyang: %f\n",-realdist[i+1]+SAMPLINGDIST,(TOPP-precisne[j-1])*SCALE);j--;alt[i]=alt[i]-ISOALTDIST;}
printf("\nprecisne[j]: %f,precisne[j-1]: %f",precisne[j],precisne[j-1]);
if (j>1) {printf("a%d",j);hypot[i]=(precisne[j]-precisne[j-1])*SCALE;
	  printf("hypot[i]: %f\n",hypot[i]);slope[i]=rtod(sin(ISOALTDIST/hypot[i]));printf("slope: %f\n",slope[i]);
	  printf("alti: %f",alt[i]);alt[i]=alt[i]-(ISOALTDIST/hypot[i])*(-realdist[i+1]+SAMPLINGDIST-(TOPP-precisne[j])*SCALE);printf("corrected alti: %f\n",alt[i]);

		gone=-realdist[i+1]+SAMPLINGDIST-(TOPP-precisne[j])*SCALE;printf("\nGONE: %f",gone);
		if (gone>SAMPLINGDIST) gone=SAMPLINGDIST;
		reallen[i]=((sqrt(hypot[i]*hypot[i]-ISOALTDIST*ISOALTDIST))/hypot[i])*(gone);
		if (gone<SAMPLINGDIST)
		reallen[i]+=((sqrt(hypot[i+1]*hypot[i+1]-ISOALTDIST*ISOALTDIST))/hypot[i+1])*(SAMPLINGDIST-gone);
		printf("reallen: %f",reallen[i]);
	  }

else          {printf("c"); slope[i]=0;reallen[i]=SAMPLINGDIST;}

	realdist[i]=realdist[i+1]-reallen[i];printf("realdist: %f",realdist[i]);
	north[i]=gradtosec(nn-sin(dtor(45+MAGNDECL))*(realdist[i]/(LENMINLAT*SCALE)));printf (" north: %f",north[i]);
	east[i]=gradtosec(ee-sin(dtor(45-MAGNDECL))*(realdist[i]/(LENMINLONG*SCALE)));printf(" east: %f\n",east[i]);

i--;
}

/* go southwest*/

i=SAMPLENONE+1+1;
printf("hypot : %f",hypot[SAMPLENONE+1]);
while ((i<(SAMPLENONE+1+SAMPLENOSW+1-1)))

{int j=8;alt[i]=TOPPALTI;printf("\n\n\n i: %d     ",i);
while (realdist[i-1]+SAMPLINGDIST>(precissw[j-1]-TOPP)*SCALE) {printf("realdist: %f, lastyang: %f\n",realdist[i-1]+SAMPLINGDIST,(precissw[j-1]-TOPP)*SCALE);j--;alt[i]=alt[i]-ISOALTDIST;}
printf("\n\n\nFUCK:%d",i);

printf("\nprecissw[j]: %f,precissw[j-1]: %f",precissw[j],precissw[j-1]);
if (j>1) {printf("a%d",j);hypot[i]=(-precissw[j]+precissw[j-1])*SCALE;
	  printf("hypot[i]: %f\n",hypot[i]);slope[i]=rtod(sin(ISOALTDIST/hypot[i]));printf("slope: %f\n",slope[i]);
	  printf("alti: %f",alt[i]);alt[i]=alt[i]-(ISOALTDIST/hypot[i])*(realdist[i-1]+SAMPLINGDIST-(precissw[j]-TOPP)*SCALE);printf("corrected alti: %f\n",alt[i]);

		gone=realdist[i-1]+SAMPLINGDIST-(precissw[j]-TOPP)*SCALE;printf("\nGONE: %f",gone);
		if (gone>SAMPLINGDIST) gone=SAMPLINGDIST;
		reallen[i]=((sqrt(hypot[i]*hypot[i]-ISOALTDIST*ISOALTDIST))/hypot[i])*(gone);
		if (gone<SAMPLINGDIST)
		reallen[i]+=((sqrt(hypot[i-1]*hypot[i-1]-ISOALTDIST*ISOALTDIST))/hypot[i-1])*(SAMPLINGDIST-gone);
		printf("reallen: %f",reallen[i]);

	 }
else     {slope[i]=0;reallen[i]=SAMPLINGDIST;}

	realdist[i]=realdist[i-1]+reallen[i];printf("realdist: %f",realdist[i]);
	north[i]=gradtosec(nn-sin(dtor(45+MAGNDECL))*(realdist[i]/(LENMINLAT*SCALE)));printf (" north: %f",north[i]);
	east[i]=gradtosec(ee-sin(dtor(45-MAGNDECL))*(realdist[i]/(LENMINLONG*SCALE)));printf(" east: %f\n",east[i]);

printf("@@@@@@@@@@@@@");i++;
}
printf("BASTARDS...");
in=fopen("yang.txt","rt");
out=fopen("yang.new","wt");
for (i=8;i<(SAMPLENONE+SAMPLENOSW);i++)
  {for (j=0;j<697;j++)
	{

	if (j==14) /*east:9*/ {fseek(in,9,SEEK_CUR);if (east[i]<10) east[i]+=90;j+=9;gcvt((east[i]+0.5),10,hg);strncpy(hgz,hg,2);fprintf(out,"102o29'%s?",hgz);}
	if (j==23) /*north:8*/{fseek(in,8,SEEK_CUR);if (north[i]<10) north[i]+=90;j+=8;gcvt((north[i]+0.5),10,hg);strncpy(hgz,hg,2);fprintf(out,"33o34'%s?",hgz);}
	if (j==35) /*newa:4*/ {fseek(in,4,SEEK_CUR);j+=4;gcvt((alt[i]+0.5),4,hg);fprintf(out,"%s",hg);}
	if (j==39) /*slope:2*/{fseek(in,2,SEEK_CUR);if (slope[i]<10) slope[i]+=90;j+=2;gcvt((slope[i]+0.5),10,hg);strncpy(hgz,hg,2);fprintf(out,"%s",(hgz));}
	ch=getc(in);fputc(ch,out);
	}
   if (i<13) {fputc('@',out);fputc('@',out);for (j=0;j<697;j++) {ch=getc(in);fputc(ch,out);printf("g");}}
   }
fclose(in);fclose(out);return 0;
}


float gradtosec(float a)
{float b;
int c;
a=a+10;
c=a;
b=(a-c)*60;
return b;}
ÿ</PRE></BODY>
</HTML>
