Minimum knowledge to use computer program in command prompt


Contents

Minimum knowledge
1 Command prompt
  1.1 What is command prompt
  1.2 Store computer programs
  1.3 Execute programs
  1.4 Batch file
2 How to make data for FORTRAN
  2.1 FORTRAN file
  2.2 FORMAT
Small application
3 How to use command prompt
  3.1 How to open command prompt
  3.2 Command in command prompt
4 Path
4.1 Permanent setting of PATH
4.2 Temporary setting of PATH
4.3 Way does not use Path


Minimum knowledge


1 Command prompt

Important note:
When you copy a file in a folder, Windows make alert indicating the existence of the file with same name. However, command prompt is not kind, it is overwritten without alarm.
Lower can upper case letters are not distinguished; for example, AAA.dat and aaa.dat are same file.


1.1 What is command prompt?
Program runs in the command prompt. Command prompt is used in the MS-DOS, an OS before Windows, but it is still working.
In the Start symbol, , there is a command prompt (Sorry some are in Japanese because I am working in Japanese)

When you choose command prompt, following windows opens.

It takes some more work to run in the command prompt. See Small application in this procedure. The simplest method is introduced here.


1.2 Store computer programs
  When you type a command (computer program, files, etc.) in the command prompt, command prompt looks for 1) current folder, 2) folders that is specified by path specification. Shortly, it looks for current folder and if it cannot find, it looks for the folders specified by path. There is another method by which locations of the program etc. by the users directly. Here, the most simpler case that computer programs and data files are in the current folder is explained.

1.3 Execute programs
  Let's first consider that command prompt is open (see chapter 3 to open it).
  type as follows in the command prompt
Program_name<Data_file_name>Output_file_name
  For example, when you are going to run YUSAYUSA.exe
YUSAYUSA.exe<DATA.dat>OUT.out
where DATA.dat is a text fine used as input data, details of the contents is written in the user's manual. OUT.out is also a text file in which result of calculation is stored. The user can name the files. If, instead of above, you type
YUSAYUSA.exe<DATA.dat
Output file is not specified in this case. Then the command prompt output the result on the command prompt screen. It is noted that storage of this screen is very small. Therefore, output at the beginning will disappear if amount of output exceeds storage. On the other hand, if you type
YUSAYUSA.exe
Windows of the command prompt is used for both input and output. In other words, you are using the command prompt as interactive way. You type input data and command prompt type results,.... This method may be possible when input data is several lines, and output data is sufficiently small. Compute program VECTOR and VECTORIZE in my release can be used by this way. However, it is not recommended in general cases.
  At present, method to open command prompt is not explained. Instead of opening command prompt by yourself, alternate method to use a batch file is explained.

1.4 Batch file
  A batch file is a file whose extension is 'bat', and it is a text file. However, it is an executable program. Let's make a file with name ='GO.bat' whose contents are
YUSAYUSA.exe<DATA.dat
PAUSE

It is noted that only executable command is accepted in the batch file. If you double click GO.bat in the explorer, command prompt automatically opens and jobs specified in the batch file is executed one by one. In this example, YUSAYUSA.exe is executed first, then to stop the job by PAUSE command.
  Exactly speaking, the command PAUSE is not necessary when running YSAYUSA.exe. However, command prompt is automatically disappear when execution of YUSAYUSA finishes. If program runs well, it is sufficient. However, if there are some problems such that there is an error in your data, error massage appears in the screen. If, in this case, there is no PAUSE command, since screen disappears quickly and you cannot see the error massages appeared in the screen. Pause command is used not to close the command prompt. You can erase the screen if you input any key, the screen disappears.

2 How to make data for FORTRAN
2.1 FORTRAN file
  There are formatted and unformattedfile in FORTRAN
  Formatted file is a text file. Generally, input data file and output file as used above as DATA.dat and OUT.out are this type. Then you can make input data file by a text editor, and you can see the output file in the text editor, too.
On the other hand, data is written in the binary code in the unformattedfile. Therefore, you cannot see the content by an text editor. In order to retrieve the data, one need to know the contents and read the data same as the way written in the file. Since data size can be significantly made small by using unformattedfile, it is usually used to store time histories.


2.2 FORMAT
  FORMT is a way to give the input data to the computer program. Data (numerals, characters) in the input file is written in the location specified by the computer.
  Computer program uses FORMAT statement to specify the location and type of variable. For example, computer program uses FORMAT statement such that
(I5, 2X, F6.0, 2F7.3, A9)
It means that 5 columns from the beginning (left side end) is used for inter, two spaces (just take two spaces without any other information), 6 columns for real number, two seven-columnsreal numbers, and 9 columnscharacter. Corresponing input data is
___56__5.64__2.65489_5.016__data_qqq (underline _ indicates a blank character)
Then the computer program uses numbers 56,5.64,2.65489,and 5.016, and character set data_qqq
  I the manual of my program, locations are also written from ##-th column to ##-th column. In the general use (especially for elder person who are familiar with FORTRAN very long ago when the computer is not Powerful), Inter is input as right justified, and read number left justified. In the current version of FOTRAN, you can write any place in the specified location. It is strongly suggested to use decimal point for real number. It is noted bland has meaning in the character input. Therefore, left-justified input is necessary.


Small application


3 How to use command prompt
3.1 How to open command prompt
  Command prompt was standard tool up to Windows 8, but PowerShell becomes standard from Windows 10. Of course, command prompt can be used at present and in the future (I do not know how long Microsoft prepares it). However, when you open the command prompt in the previous method, current folder is c:\user\username. So you can move to the folder you want to use, but it is somewhat inconvenient. You can do it by using command 'cd' for this purpose. Alternately, if there is a tool to open command prompt, it is more convenient.
  This can be done by controlling the resistry file. You can use the following method for this purpose. The method is written in Japanese web site https://www.ka-net.org/blog/?p=8115

  Make a text file whose contents are as follows
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\directory\background\shell\CommandPrompt]
@="@shell32.dll,-8506"
"Extended"=""
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\directory\background\shell\CommandPrompt\command]
@="cmd.exe /s /k pushd \"%V\""

[HKEY_CLASSES_ROOT\directory\shell\CommandPrompt]
@="@shell32.dll,-8506"
"Extended"=""
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\directory\shell\CommandPrompt\command]
@="cmd.exe /s /k pushd \"%V\""
Save this file with Unicode character code and extension .reg. Instead of it you can download this filem from here . You can double click to run this file. Note that windows shows warning on this process because it handles resistry. I have used this file at several computers, and there was no problem. However, I cannot guarantee it works well in your computer. So please use it within your individual responsibility. If you do not like, it, you can use the method as follows.

Open the folder by explorer. For example,

is a state to open D:\aaa. Here, in the red rectangular place (usually current folder location is displaced) type 'cmd' and hit return. Then a command prompt opens. Above example results in

You can see D:\aaa on the left top as current folder.

In the old days, horizontal width was fix value 80. Therefore, command was expressed in 2 lines or more. However, you can change the windows size same as other window such as explorer. Controls of font size and font set can also be done by clicking the black rectangular box, a menu

appears (sorry this is again Japanese), and you can choose edit to change fonts. Cut, copy and paste is to be done in this menu in the old days, but now you can do it by the common Windows way.

3.2 Command in command prompt
There are many website which shows how to use command in command prompt. Here, minimum and those I frequently use commands are shown.

(1) Movement of folder
  • two dots indicates one rank upper folder.
  • Slash, /, indicates previous is folder name. File name comes after slash.
  • Movement of folder is 'cd'. For example,
    cd ..:move one rank upper folder
    cd aaa:move to folder aaa which is in the current folder
(2)Copy and move the files
  In the same manner copy and move are used to copy the files. For example
copy aaa.exe ..:copy a file aaa.exe to the upper folder.
mv bbb.txt qqq/rrr.txt:file bbb.txt in the current folder is moved to the folder qqq and file name rrr.txt
It may be much easier to do this by using explorer.

(3) Execution of the program is done here, too. For example you can type above example,
YUSAYUSA.exe<DATA.dat>OUT.out
directly in this window.

  F3 key is used to input previous command. ↑ key trace back input command from new one.

  Some extensions such as .exe, .bat, .com are automatically judged as executable file, in which case extension is not necessary. For example
YUSAYUSA.exe<DATA.dat>OUT.out
YUSAYUSA<DATA.dat>OUT.out
are exactly same meaning. The file GO.bat that we made previously can run just type GO.

4 Path
  Path is a tool to refer the folder when Windows is working. For example, I stored all the computer program I developed in the folder
D:\FORTRAN\PROGRAM
In section '1.2 Store computer programs', it is assumed that data file and program file are stored in the current folder. In this way, computer program is to be copied or to be moved to the new folder, but it is inconvenient. If the program is saved to a particular permanent folder and can use the program from any folder, it is very convenient.

4.1 Permanent setting of PATH
  PATH is set in the Windows system. Move Control Panel → system → detail (sorry again. I use Japanese Windows, so all appearance is in Japanese. I do not know English explanation), then you have the following screen.

Then choose environment variable at the bottom, we obtain

As shown in the figure, select PATH in the lower window, and press edit. Then edit window appears and you can add a new path here. It is noted that location of folder is to be specified by absolute address. In my case, it is to be
D:\FORTRAN\PROGRAM


4.2 Temporary setting of PATH
  Type the following command in the command prompt.
PATH %PATH%; D:\FORTRAN\Program
Here, '%PATH%;' indicates path specified previously (usually specified as explained in section 4.1. This statement means to add a new path D:\FORTRAN\Program in the common path. It is noted that semicolon is used after %PATH%; and colon is used after drive name D.
  When command prompt closes, new path does not work. In other words, this path is valid only when the command prompt open. If you feel this is inconvenient, you can use batch file. For example, make a batch file named PATH.bat, in which
PATH %PATH%; D:\FORTRAN\Program
is written.
  When you use this method, you should run Path.bat whenever you open command prompt. So the procedure is nearly the same with that executable program is to be moved. Instead, if save this file into permanent path, you can type PATH when you open command prompt. Or you can save it in the root of C drive, then you can type just
c:\path
Since, as described before, batch file is executable program, .bat is not necessary.

4.3 Way that does not use Path
  You can directly specify the file without using PATH statement. Method to speficy files and directories in section 2.1, the same procedure can be used. Previously, I showed the statement
YUSAYUSA.exe<DATA.dat>OUT.out
to run YUSAYUSA.exe with input data DATA.dat and output file OUT.out. Here, all files is to be the same folder. Instead of this statement, you can type
D:\FORTRAN:PROGRAN\YUSAYUSA.exe<..\DATA.dat>result/OUT.out
Here, YUSAYUSA in folder D:\FORTRAN:PROGRAN is executed and input data file DATA.dat is stored at upper folder and the resultant file OUT.out is stored in the folder result which is located in the current folder.
  It is noted that seismic response analysis uses more files than input data file, such as earthquake input, time history output and temporary file. These files can also be specified in the input data, but usually the space to specify file name is not so large.