Monday, January 29, 2018

Install Centos and CRTM

Refresher (Last time I used Linux is 4 months ago and I almost forgot everything)
  • robo vm is 3 GB .vmdk file, password: robo-nd
  • open terminal: ctrl + option + t
main take-away:
  1. use stable version of VirtualBox(older version)
  2. use ready-to-use version of centos VM. So you have GUI and Firefox.

install on Mac OS, fail

cd config-setup
chmod u+x gfortran.setup  # change user access to write
./gfortran.setup   # source some shell code
source config-setup/gfortran-debug.setup
## following is error, setenv may be linux command
-bash: setenv: command not found
-bash: setenv: command not found
-bash: setenv: command not found
-bash: setenv: command not found
cp Makefile # **.in is for linux
./config.status --recheck
make: ./config.status: No such file or directory
make: *** [config.status] Error 1

install on Ubuntu, fail

cd config-setup
chmod u+x gfortran-debug.setup
cd ..
./configure --prefix=/bin/
# configure ...
# recipe for target "CRTM_CloudCover_Efine.o" failed
# recipe for target "all" failed
make check
# Error 2
gfortran --version
# GNU Fortran (Ubuntu 5.4.0)  5.4.0
gcc --version
# gcc (Ubuntu 5.4.0)  5.4.0

install on Centos 7 DVD ISO, but no GUI

install virtual box on macOS High Sierra
University of Oklahoma Open Source Software Mirror:
Virtual Box 5.2.6 doesn’t work on macOS High Sierra. Use VirtualBox 5.2.4.
Installation failure? System configuration -> Seurity & Privacy -> authroize changes ( the lock sign)

install centos on virtual box

Installing Centos 7 on VirtualBox:
Virtual box - new -> name: centos7 -> next -> 2048 MB->create a virtual hard disk now -> Hard disk file type: VDI -> dynamically allocated
Localhost login: root
Password: wnixxxxxxx

add user

adduser yuchao
passwd yuchao
usermod -aG wheel username
CentOS 使用 yum,Ubuntu 使用 apt-get,近些年又出现了一些与发行版无关的第三方包管理器,比如 Linuxbrew.
The problem is no GUI, so inconvenient to use. May try everything ISO next time.

install on Centos, ready-to-use VirtualBox by OSBoxes, success!

Centos 7-1708, password:
transfer file?
df -h
scp jiang@*.sh .
# connection refused
directly download from official website
sudo yum install gcc-gfortran
gfortran --version
# GNU Fortran (GCC) 4.8.5 (Red Hat 4.8.5-16)
gcc --version
# gcc (GCC) 4.8.5 (Red Hat 4.8.5-16)
cd config-setup
chmod u+x gfortran-debug.setup
cd ..
./configure --prefix=/bin/
make check
sudo make install
make clean

Wednesday, January 3, 2018

car hood won't open

understand the problem

Yesterday was extremely cold, all day below -5 C. Then my car battery failed. When I tried to open the hood to give it a jump, the hood latch release failed.
This seems a simple mechanical problem. The latch was cleverly designed. After one evening’s study, I had a clear understanding of the problem. And it is very interesting and deserves a blog post.
There are actually 2 latches:
Each latch has its own spring. You can see how the Primary latch works by the following 2 short videos:
What to do if you have a Stuck Hood Latch or hood won’t open:
How to fix a hood latch that wont close || 1997 Chevy Lumina:
All you need is a long stick to push the metal along the direction of latch release cable:

Everything is well explained in this awesome video

What if your car’s Hood won’t Open?:

Buy parts

back up plan, AAA

$52 per year, 5 miles of towing:
promo code: 52WBOS

gcc and make

refresh C grammar

check C compiler:
gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
If you use Mac OS X, the easiest way to obtain GCC is to download the Xcode development environment from Apple’s website and follow the simple installation instructions. Once you have Xcode setup, you will be able to use GNU compiler for C/C++.
#include <stdio.h>
int main(int argc, char** argv) {
    printf("argument count: %d \n",argc);
    for (int i= 0; i< argc; i++){
        printf("argument vector %d is: %s.\n ", i,argv[i]);
    printf("Hello, World!\n");
    return 0;
argv and argc are how command line arguments are passed to main() in C and C++.
argc will be the number of strings pointed to by argv. This will (in practice) be 1 plus the number of arguments, as virtually all implementations will prepend the name of the program to the array.
The variables are named argc (argument count) and argv (argument vector) by convention, but they can be given any valid identifier: int main(int num_args, char** arg_strings) is equally valid.
When you output, always define the format you want.
$ gcc hello.c  # default output file is a.out
$ gcc -o hello hello.c # define output file as hello
$ ./a.out
Hello, World!
#include <stdio.h>
int main() {
   printf("Storage size for int : %d \n", sizeof(int)); //4, the exact size of a type/variable depends on a specific platform
   return 0;

Make grammar

why makefile?
gcc main.cpp hello.cpp factorial.cpp -o hello
This command generates hello binary. In this example, we have only four files and we know the sequence of the function calls. Hence, it is feasible to type the above command and prepare a final binary. However, for a large project where we have thousands of source code files, it becomes difficult to maintain the binary builds.
To prepare to use make, you must write a file called the makefile that describes the relationships among files in your program and provides commands for updating each file.
It would be tricky to write a grammar for make, since the grammar is extremely context-dependent.
Names of these variables originate from names of the corresponding tools. Usually, the meaning of these abbreviations is the following:
  • CC stands for “C compiler” (in GCC abbreviation it is also treated as “compiler collection”).
  • LD is a linker (comes from “link editor” or from “loader”).
These are also commonly used in makefiles (see Implicit variables chapter of GNU Make manual):
  • CPP stands for “C preprocessor”
  • CXX is a C++ compiler
  • AS is an assembly language compiler
  • AR is an archive-maintaining program

difference between g++ and gcc

GCC: GNU Compiler Collection, Referrers to all the different languages that are supported by the GNU compiler.
gcc: GNU C Compiler
g++: GNU C++ Compiler
The main differences:
gcc will compile: .c/.cpp files as C and C++ respectively.

g++ will compile: .c/.cpp files but they will all be treated as C++ files.

Also if you use g++ to link the object files it automatically links in the std C++ libraries (gcc does not do this).

gcc compiling C files has less predefined macros.

gcc compiling .cpp and g++ compiling *.c/.cpp files has a few extra macros.