A fortran.cat trobaràs informació relativa a aquest llenguatge de programació tan savi. Fortran segueix molt viu i, per tant, segueix evolucionant com moltes altres tecnologies. És un llenguatge utilitzat en el món de la ciència i l’enginyeria. Com va ser especialment dissenyat per aquesta tasca és relativament pràctic d’utilitzar. Combina la potència d’un llenguatge compilat…
read morePotential errors can come up when using allocatable arrays when returned in functions. Given the example found below, an error is created on purpose to demonstrate the compiled cannot detect it. Output: [mypc]$ gfortran allocarr.f90 && ./a.outvalues= -1 25 25 0 -1 -1 Bear in mind, potential errors could come from allocatable output arrays. Valgrind…
read moreFortran namelist is a I/O method introduced in Fortran 77. It later became a standard in Fortran 90. It basically allows to read/write data as a dictionary like in plain text files. In order to read a REAL array, see the example below: Input param.nml: ¶m nrows=3, ncol=2, data_file=”hello.txt”, values=1.1, 2.2, 3.3, 4.4/ Output: mymachine:~/tests/namelist_arrays$…
read moreWHERE statement can limit the ability to debug the code: see stack overflow. As mentioned in the thread, it could be converted into DO-ELSE-IF loop. However, It might not that charming if the array have several dimensions. As it implies to deal with multiple loops: nesting,… See below for alternatives: Run the example on www.onecompiler.com…
read moreMulti-dimensional arrays need to be padded in the fastest-moving dimension, to ensure array sections to be aligned at the desired byte boundaries : npadded= ((n +veclen– 1) /veclen) *veclen Example:
read moreRecently I had to implement a scientific paper The influence of vegetation, fire spread and fire behaviour on biomass burning and trace gas emissions: results from a process-based model into Fortran code. However, several challenges came up. Specially, edge cases not dealt within several equations. As an example: As seen, the equation shown above is…
read moreFortran namelist is a I/O method introduced in Fortran 77. It later became a standard in Fortran 90. It allows to read/write data as a dictionary like in plain text files. See below for a simple example: Derived types are user defined types. They extend the basic types REAL, INTEGER and LOGICAL. They can be…
read morePerf is a tool used to profile any code in Linux. By following the steps below, you will manage to profile your Fortran binary. It will only provide a simple overview of each function and how much time is spent there. However, this can be your first steps towards improving the execution time of your…
read moreDerived types are User-defined data types that allows to create complex data structures. It is defined with the TYPE statement. In addition, two different derived types exists: The use of PDT’s derived types can be useful in several ways: Its use allows to parametrize the following properties of an array: User types can be parametrized…
read moreWhen launching a “controlled” error it can be useful to show the whole stack trace. In such way, it is easier for the developer to find out where the problem might come. Check below how to do it: The output: Found at Stackoverflow
read moreAmong several things, pointers can be used to represent an array from a specific shape into another one. It can be useful for certain situations. However, the use of pointers is generally not recommended. This is due to potential memory management risks. For instance, It is important to keep the same size when remapping arrays…
read more