Fortran Interview Questions & Answers

5 avg. rating (100% score) - 1 votes

Fortran Interview Questions & Answers

Switching jobs? Searching for suitable job on Fortran? Looking for the ways to prepare well for the interviews? If you have experience in design and development on OpenVMS systems using FORTRAN, DCL, C, C++, and SQ and knowledge of XML, C++ STL, Oracle, threads, DCE the search and apply for the suitable jobs on wisdom jobs. Your interview preparation in now made easy with our interview questions and answers page. Hiring managers ask different questions on configuration Control and software release and deployment using CMS/MMS, Polycenter and PVCS Tracker. Crack your interview by preparing well with wisdom jobs Fortran interview questions and answers page. The candidate should have good knowledge on Fortran and upgrade their skills with our interview questions page to shortlist in interviews.

Fortran Interview Questions

Fortran Interview Questions
    1. Question 1. How Should One Spell Fortran/fortran?

      Answer :

      FORTRAN is generally the preferred spelling for discussions of versions of the language prior to the current one (‘90”). Fortran is the spelling chosen by X3J3 and WG5. In this document a feeble effort has been made to capitalize accordingly (e.g. vast existing software ... FORTRAN vs. generic Fortran to mean all versions of the standard, and specifically the modern dialect, ISO 1539:1991).

    2. Question 2. How Does Fortran 90 Relate To Fortran 77?

      Answer :

      With a few minor exceptions, Fortran 90 is a superset of X3.9-1978 FORTRAN. But this does not mean that all ‘77” codes will port sans changes. Many (if not most) programmers employed constructs beyond the ‘77 standard, or rely on unspecified behavior (say, assuming that an OPEN of an existing file will position the file pointer to just past the last record already written) which has changed (that is to say, has become specified).

    3. Question 3. Do Spaces Mater In Fortran Equations?

      Answer :

      No. Spaces are generally added for clarity Some compilers get upset if you write things like” INTEGERI,J” rather than INTEGER I,J”. Simple neatness will keep you out of these problems.

      The following are all equivalent:
      x=x*y**2*sin(x)
      x=x * y2 * sin(x)
      x= x * y**2 * sin ( x)

    4. Question 4. What Is The Advantage Of An Array Over A Spreadsheet Format?

      Answer :

      Both can store similar types of information and a neatly labeled and organized way. The advantage lies in where they are used. You have more control over how Fortran arrays are used than how the contents of a spreadsheet are used. In addition for any given operation on an array of numbers, once the Fortran is written, it will do the job much faster than a spreadsheet. On the other hand, when operations are not complex and computer execution time is not a problem using the spreadsheet is probably your best bet.

    5. Question 5. How Do We Know Where Various Steps Go In A Fortran Program?

      Answer :

      Some commands have special locations, but most are located by the needs of the specific program. The PROGRAM card is always first Statements giving variable types (INTEGER, REAL, LOGICAL, CHARACTER) should precede “executable” statements. The END card must always be at the end of the program unit.

    6. Question 6. Where Can I Get A Fortran Compiler For Ibm Pc?

      Answer :

      We can pick up one on the internet from the GNU project, but get a better package from MOC for about $80.00.

    7. Question 7. Why Do You Put So Many Lines Of Empty Space In Your Programs?

      Answer :

      I hope the lines aren’t totally empty. They should contain a “c” in column one. These “blank” lines are just to make the comments stand out from Fortran code lines or to highlight key blocks of a program.

    8. Question 8. Why Doesn't Fortran Have Intrinsic Functions For Something As Simple As Factorial?

      Answer :

      Two reasons. Factorial isn't all that common in heavy duty scientific and engineering applications. When it does occur, it almost always in a context where it is more computationally efficient to generate it as you go. You need 2! first then 3!, then 4!, etc. You are basically stuck doing a factorial within the context of a do loop unless you get really good and learn to write "recursive functions", but then you are just fooling yourself and writing another form of do loop. When you are taking the factorial of a large number and don't need an exact answer you can resort to Stirling's Approximation. A Fortran statement that will load the value of this approximation into the variable nfact is.

      nfact = sqrt(2*3.1415963*n)*(n/2.71828)**n

    9. Question 9. How Do You Use A Logical Variable? What Is Stored There?

      Answer :

      Most frequently, logical variables are used in association with IF statements. When you want to set a logical variable LVAR to true you use "LVAR=.TRUE.". For false use "LVAR=.FALSE." In practice the computer usually stores an integer 0 in memory for false and integer 1 for true. The normal logical variable occupies 1 byte of space.

    10. Question 10. What Is The Difference Between If Then And Do While Statements?

      Answer :

      IF THEN combined with GO TO statements will let you do anything you want. The DO WHILE and other DO constructs allow you to loop through certain portions of code many times without ever writing GO TO statements. This makes coding slightly simpler, definitely clearer.

    11. Question 11. What Is The Difference Between A Function Subprogram And A Subroutine?

      Answer :

      The biggest difference is that a subroutine never returns a value that is associated with its name. This means that you never need to declare a subroutine name in a type statement (REAL, INTEGER ...). All information coming back from a subroutine passes through the argument list, or something called a COMMON block (later). However, there is nothing in these communications channels that can't be used by a Function Subprogram. A secondary difference is that a Subroutine need not have an argument list.

    12. Question 12. What Is The Difference Between Do, Do While, And If ( ) Goto Loops?

      Answer :

      In terms of what the computer actually does, there is generally no difference. You can structure all three so that they do the same thing. When properly intended, the DO structures tend to be easier to follow. The DO WHILE structure can produce slightly more compact coding, combining a straight DO with the option for some extra comparison logic. In a vector and/or parallel computer, DO's send strong hints to the compiler that it should be looking for ways to feed a pipeline or spread calculations over multiple processors.

    13. Question 13. What Does "common/control/ A, B, C" Do To The Values Of A, B, C?

      Answer :

      It doesn't do anything to the values. It just establishes a place in memory for the values to be stored and retrieved. Every subroutine and function in your program that contains the line "COMMON/CONTROL/ A, B, C" will agree that operations using variables A, B, or C will get numbers from or put numbers in the same appropriate location in memory. That is, they agree that a reference to "A" means the same in all routines with common CONTROL, etc.. To give A, B, or C a value, you have two options. You can assign values at compilation time with a BLOCK DATA routine:

      BLOCK DATA ABCVAL
      COMMON/CONTROL/ A, B, C
      DATA A,B,C / 1.0, 2.0, 3.0/
      END

      You can also assign and use values with executable statements. Say subroutines SUB1 and SUB2 contain this common block. If SUB1 contains the lines "A=1.0", and "B=2.0", and SUB2 has the line "C=A+B", then the value of C after this line in SUB2 is executed is 3.0.

    14. Question 14. What Directory Is Used By The Compiler For Compiling A Fortran Program? Where Does F77 Live?

      Answer :

      For the work in this class, you should assume that everything happens in whatever directory you are in when you type the "f77". Type "pwd" if you don't know the answer to this question. The executable file called "f77" resides both in /bin and /usr/bin on these machines. This is very unusual. To locate an executable file use the "whereis" command (e.g. "whereis f77"). Unfortunately the manual pages on f77 aren't connected properly and are listed under IBM's other name for their compiler, "xlf". 

    15. Question 15. Is There Any Way To Use Variables In A Format Statement?

      Answer :

      Yes, but you have to use one format statement to build a second using a write to a character string. For example if you want to include the value of "n" as the number of real numbers per line you would do the following:

      PARAMETER (N=4)
      CHARACTER FORM1*16
      REAL A(N,N)
      DO 10 I=1,N
      DO 10 J=1,N
      A(I,J)=J*100+I
      10 CONTINUE
      WRITE(FORM1,2000)N
      2000 FORMAT('(1X,',I3,'F6.1)')
      WRITE(6,FORM1) A
      STOP
      END

    16. Question 16. Is It Possible To Lay Out A Two Dimensional Array With The Double Do Loops?

      Answer :

      DO 10 J=1,4
      DO 20 K=1,4
      A(J,K)=SUM(T(1:N)**(J+K-2))
      20 CONTINUE
      10 CONTINUE
      yes, if you have a Fortran 90 compiler.

    17. Question 17. What Does // Do?

      Answer :

      It sticks 2 character strings together into a single string. If char1='file1.in' and char2='file2.out' then when char3=char1(1:5)//char2(6:9) the contents of char3 are 'file1.out'.

    18. Question 18. What Does The Function Real(x) Do?

      Answer :

      Not much if x is already a real variable. If x is and integer, the output of REAL is a real (floating point number with the same value. REAL(3) is 3.00000E+00. If x is a complex number REAL returns the real part (as opposed to the imaginary part) of x.

    19. Question 19. When Is The Common Command Not Used Correctly In A Fortran Statement?

      Answer :

      You're asking for quite a bit here. There are lots of ways to introduce errors. The most obvious is to try inserting a common in the midst of executable statements. It belongs up with DIMENSIONs, PARAMETER's, SAVE's, and the rest of the non-executables. A more subtle problem is the use of multiple COMMON statements for blank common or the same named common. Fortran will accept the following program:

      program testcom
      common a,b
      common c,d
      a=1.0
      b=2.0
      c=3.0
      d=4.0
      call sub1
      stop
      end
      subroutine sub1
      common c,d
      print *, c, d
      return
      end 
      

      However, the values printed out are 1.0 and 2.0. The second common statement in the main program just tacks the variables "c" and "d" onto blank common after "b". The two commons together are equivalent to "common a,b,c,d". In the subroutine you are saying that "c" is the first element in blank common, so Fortran associates "c" in "sub1" with the same address in memory as assigned to "a" in the main program. Also recall that mixing reals and integers (common/blk1/a,b,i,c) when the reals are double precision may cause errors on some machines, and is not a good idea on any 32 bit machine.

    20. Question 20. What's The Use Of A Blank Common As Opposed To A Common With A Name?

      Answer :

      The major use is in cutting the size of the executable file produced by "f77" (usually a.out). It won't seem like a big deal to you now, but in applications containing many arrays with thousands to millions of elements each, this can make a huge difference in the amount of disk space you soak up. A secondary use is that, when the program starts, the space finally allocated to blank common in memory is at the very end of the program. If you are tricky enough, you can take advantage of this to dynamically extend the size of a single array in blank common as your space requirements grow during execution.

    21. Question 21. When Accessing A Data File In A Program Can I Change Directories?

      Answer :

      Yes if you have a subdirectory called "test" under the location that your program, you can open the file "my.data" in "test" for reading on unit 11 with the command: OPEN(11,file='test/my.data')

    22. Question 22. Can More Than One Variable Be Stored In A Data Statement?

      Answer :

      Yes. For example you can set initial values for A, B, and C with either of the following statements.

      DATA A/1.0/,B/2.0/,C/3.0/
      DATA A,B,C/1.0,2.0,3.0/

    23. Question 23. Which Fortran Compiler Should I Use?

      Answer :

      GFortran, G95, Open Watcom, and Silverfrost are free Fortran compilers, while Absoft, IBM, Intel, Lahey,NAG, Pathscale, PGI, and Oracle produce commercial Fortran compilers.

    24. Question 24. How Should One Capitalize "fortran" ?

      Answer :

      Standard capitalization is now the preferred way to write Fortran for several reasons, most notably because that is how recent versions of the standard write it. Another reason is due to an effort to standardize the capitalization of the names of programming languages.

    25. Question 25. How Do I Produce A Library?

      Answer :

      To build a static library libfoo.a containing all modules and procedures in the .f90 files in the current directory on Linux:

      % gfortran -c *.f90
      % ar cr libfoo.a *.o

      The first command builds the object files and the second archives the object files into a static archive.
      To build a shared library libfoo.so:

      % gfortran -shared *.f90 -o libfoo.so -fPIC

      In both cases, other compiler flags such as -O2 can be used.

       

    26. Question 26. How Do I Read Until The End Of A File (eof)?

      Answer :

      A common Fortran 95 idiom for reading lines until the end of file is

      integer :: stat
      character(len=100) :: buf
      open(15, file='foo.txt')
      do
      read(fh, iostat=stat) buf
      if (stat /= 0) exit
      ! process buf
      end do
      close(15)

      This example catches all conditions, not just the end of file. To specifically catch the EOF in Fortran 2003 one can use the iso_fortran_env module and replace the if condition above with

      if (stat == iostat_end) exit

    27. Question 27. Can I Allocate A Variable Length Character String?

      Answer :

      Yes, in Fortran 2003. Declare the variable and allocate with a given length as follows:

      character(LEN=:), allocatable :: str
      integer :: n
      n = 27
      allocate(character(LEN=n) :: str)

      A Fortran 95 solution is the iso_varying_string module, or the variable length string module in FLIBS.

    28. Question 28. Which File Extension Should I Use For My Fortran Code?

      Answer :

      Although there are no official file extensions for Fortran code, there are two widely established conventions. Some use .f for fixed-form source and .f90 for Free form layout. The latter is a reference to the Fortran 90standard, when Free form layout was introduced. The code contained in the file can be Fortran 95, Fortran 2003, etc. Others prefer to use file extensions that indicate the standard under which the code was written. For example, .f03 for Fortran 2003 code and .f08 for Fortran 2008 code. Unfortunately, this results in a proliferation of file extensions and some compilers may not support the newer extensions yet.

    29. Question 29. Will Vf V5 Work With Microsoft Visual C++ 6.0/visual Studio 98? Will Vf V6.x Work With Visual C++ 5.0/visual Studio 97?

      Answer :

      VF V6.x does share the development environment of MS Visual C/C++ 6.0; VF V5 does not. Conversely, VF V5 shares the development environment of MS Visual C/C++ 5.0/Visual Studio 97, and VF V6.x does not. The two generations can coexist on a single system and objects/libraries created by the older compilers can be used with the newer development environment.

    30. Question 30. Does The Compiler Have The Capability Of Optimizing For The Athlon/duron, Pentium Pro, Pentium Ii Or Pentium Iii Processors?

      Answer :

      VF V6.5 includes optimizations for the AMD Athlon/Duron and Intel Pentium III processors. V6.0 and V6.1 could optimize for the Pentium Pro/Pentium II/Celeron as well.

    31. Question 31. Does The Compiler Support The Intel Pentium 4 Processor?

      Answer :

      VF is fully supported on the Pentium 4 processor. For best performance on this processor with VF 6.5, we recommend selecting the optimization settings for "Pentium II/Pro". Version 6.6 adds specific Pentium 4 optimizations.

    32. Question 32. Does Vf Support Windows 2000?

      Answer :

      Yes, as of version 6.1A, which corrects a minor issue relating to QuickWin font selection. Previous versions should install ok, but are not officially supported.

    33. Question 33. Does Vf Support Windows Millennium Edition (windows Me)?

      Answer :

      CVF 6.5 or later supports Windows ME.

    34. Question 34. Does Vf Support Windows Nt/2000 Terminal Server?

      Answer :

      We have done limited testing with Terminal Server and have not identified any problems using Visual Fortran in this environment. Please note that a Visual Fortran license is required for each user.

    35. Question 35. Does Vf Support Windows Xp?

      Answer :

      CVF 6.6 supports Windows XP.

    36. Question 36. Does Vf Have The Capability Of Generating Applications Which Can Make Use Of Multiprocessor Systems Running Under Windows Nt/2000?

      Answer :

      Visual Fortran fully supports multithreaded applications that use the Win32 multithread and synchronization APIs. A multithreaded application will naturally take advantage of a multiprocessor system. However, the compiler and its libraries do not, by themselves, utilize more than one processor.

    37. Question 37. Does Vf Support Generation Of Applications Which Can Run Under Dos Or Windows 3.x?

      Answer :

      No. Like FPS, VF generates Win32 executables only.

    38. Question 38. What About Dos Extenders Or Win32s?

      Answer :

      No attempt was made to restrict library calls to the Win32s subset, or Win32 subsets supported by DOS extenders, and no testing with Win32s or DOS extenders has been done.

    39. Question 39. Can I Run Vf Executables On Windows Nt 3.5x?

      Answer :

      Yes, as long as they don't use APIs not available on that version. The development tools require Windows NT 4.0/2000 (or Windows 9x).

    40. Question 40. Can I Mix Vf Code With Code From Fps?

      Answer :

      If the FPS code is computational only - that is, it does not make calls to the FPS I/O library - then in general the answer is yes. FPS code which makes calls to the FPS library cannot be combined in a static executable or a DLL with VF code, as the Fortran libraries are incompatible. You can build a separate DLL with the FPS code and link that in with VF code, but the two Fortran libraries will not "talk to each other".

    41. Question 41. Can I Mix Vf V6 Code With Msvc V5 Code?

      Answer :

      Yes. You can't use the MSVC 5.x Developer Studio environment to compile VF V6 code (or vice versa), but if the object files or libraries are built separately, they can be linked together, as long as the newer command-line tools (such as linker and librarian) included with VF are used.

    42. Question 42. Can I Use Modules, Libraries Or Dlls Compiled By One Version Of Vf With A Later Version Of Vf?

      Answer :

      Yes. However, the converse is not true - "downwards compatibility" is not supported.

    43. Question 43. I Am Migrating An Application From Openvms. Does Vf Support Indexed Files And Openvms System Services And Run-time Library Routines?

      Answer :

      No - these are OpenVMS operating system features not provided by Windows 95 nor Windows NT. There are companies offering "OpenVMS emulation libraries" which provide some of these capabilities - one such is Sector 7, another is Accelr8.

    44. Question 44. Does Vf Support Access To Data In Databases Such As Ms Access, Excel, Oracle, Foxpro, Sql Or Other Odbc Databases?

      Answer :

      This capability is provided by the f90SQL library from Canaima Software. A freeware version of f90SQL is provided on the Companion Products CD as of CVF 6.5.

    45. Question 45. Can I Install Vf So That It Runs From A Server?

      Answer :

      To perform a server installation of VF, copy the contents of the CD-ROM to your server. From each client PC, run the server's copy of the SETUP.EXE program and specify a "run from CD" installation type. Some files will still be copied to the client PC, but most will remain on the server. Please note that you need a separate license for each client PC which has access to the VF product.

    46. Question 46. I Get Errors When Installing Via Autoplay Or Running Setup.exe In The Kit's Root Directory?

      Answer :

      If this happens, try running X86SETUP.EXE.

    47. Question 47. When I Run Setup, It Just Exits Immediately Without Installing Anything?

      Answer :

      Uninstall Microsoft Internet Explorer and run SETUP again.

    48. Question 48. Can I Install Vf Using Netscape Navigator Instead Of Microsoft Internet Explorer?

      Answer :

      Microsoft Developer Studio uses components of Microsoft Internet Explorer (MSIE) to provide the InfoViewer feature. Other browsers cannot be substituted. Of course, you are free to not use MSIE directly as a browser.

    49. Question 49. How Do I Change A Project Type For An Existing Project?

      Answer :

      Each project type presets a large number of default switch and library settings. The easiest way to change a project type is to create a new project with the correct type and add the source files to it.

    50. Question 50. Can I Build A Vf Dll That Is Linked Against The Vf Static Libraries?

      Answer :

      We strongly recommend that you NOT do this as it can cause subtle and difficult to analyze application errors. If you build a DLL, always link against the shared libraries. Furthermore, any application linked against your DLL must be linked against DLL, not static libraries.

    51. Question 51. How Do I Get Vf Error Messages To Include Traceback Information?

      Answer :

      VF V5 did not include a traceback feature - V6 does. Select Settings.. Fortran.. Run-Time.. Generate Traceback Information (or /traceback on the command line). You must also make sure that Incremental Linking is disabled (Link..General) or else you won't get PC-line correlation.

Fortran Tutorial

Fortran Practice Tests

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Fortran Tutorial