Skip to content

Commit 3951678

Browse files
committed
add reference C program
1 parent b1058dc commit 3951678

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
cmake_minimum_required(VERSION 3.14)
22

3-
project(DonutFortran LANGUAGES Fortran)
3+
project(DonutFortran
4+
LANGUAGES C Fortran)
45

56
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
6-
add_compile_options(-Wall -Werror=array-bounds -fcheck=bounds
7-
"$<$<CONFIG:Debug,RelWithDebInfo>:-Wextra;-Wpedantic>"
8-
"$<$<CONFIG:Release>:-fno-backtrace>"
7+
add_compile_options(-Wall -Wextra -Wpedantic
8+
"$<$<COMPILE_LANGUAGE:Fortran>:-Werror=array-bounds;-fcheck=bounds>"
9+
"$<$<AND:$<CONFIG:Release>,$<COMPILE_LANGUAGE:Fortran>>:-fno-backtrace>"
910
)
1011
endif()
1112

1213
add_executable(donut app/main.f90)
14+
15+
add_executable(donut_ref app/main.c)

app/main.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// https://gist.github.com/gcr/1075131
2+
3+
#include <stdio.h>
4+
#include <string.h>
5+
#include <math.h>
6+
7+
int k;
8+
9+
int main(){
10+
float A=0, B=0, i, j, z[1760];
11+
char b[1760];
12+
printf("\x1b[2J");
13+
for(; ; ) {
14+
memset(b,32,1760);
15+
memset(z,0,7040);
16+
for(j=0; 6.28>j; j+=0.07) {
17+
for(i=0; 6.28 >i; i+=0.02) {
18+
float sini=sin(i),
19+
cosj=cos(j),
20+
sinA=sin(A),
21+
sinj=sin(j),
22+
cosA=cos(A),
23+
cosj2=cosj+2,
24+
mess=1/(sini*cosj2*sinA+sinj*cosA+5),
25+
cosi=cos(i),
26+
cosB=cos(B),
27+
sinB=sin(B),
28+
t=sini*cosj2*cosA-sinj* sinA;
29+
int x=40+30*mess*(cosi*cosj2*cosB-t*sinB),
30+
y= 12+15*mess*(cosi*cosj2*sinB +t*cosB),
31+
o=x+80*y,
32+
N=8*((sinj*sinA-sini*cosj*cosA)*cosB-sini*cosj*sinA-sinj*cosA-cosi *cosj*sinB);
33+
if(22>y&&y>0&&x>0&&80>x&&mess>z[o]){
34+
z[o]=mess;
35+
b[o]=".,-~:;=!*#$@"[N>0?N:0];
36+
}
37+
}
38+
}
39+
printf("\x1b[d");
40+
for(k=0; 1761>k; k++)
41+
putchar(k%80?b[k]:10);
42+
A+=0.04;
43+
B+= 0.02;
44+
}
45+
}

0 commit comments

Comments
 (0)