formatting,fortran,fortran90 , How to write a large amount of columns in a formatted file

How to write a large amount of columns in a formatted file


Tag: formatting,fortran,fortran90

I'm trying to write a code in fortran90 that allows me to create lets say 20 columns (f10.6) with one space between them in to the "output file". When I try to create file just with the 4 columns it works, but when I try to format a file with 5 or more columns it writes results wrong.

So my code for four columns looks like:

 do i=1, 200
     write(1,207) nq(i),plt_Dy1c4(i),plt_Dy3(i),plt_Dy4(i) 
       207   format(4(f10.6,x))
 end do

Similar for five columns looks like, but this doesn't works:

 do i=1, 200
 write(1,207) nq(i),plt_Dy1c4(i),plt_Dy3(i),plt_Dy4(i),plt_Dy5
   207   format(5(f10.6,x))
end do

The output files for five columns has 8200 rows instead of 200.

Is there any statement which should be used for creation of file which has many columns?


What is plt_Dy5? I have the nagging feeling that it is an array with dimension(200), as your other plt_* vars seem to be.

If that is the case, then for every write() statement, it would write out the whole 200 values of plt_Dy5 in addition to the current index values of the other arrays, to a total of 204 values.

Since the format only allows for 5 values per row, this would mean 41 rows per write statement. Multiply this by 200 iterations of the loop, and you come to 8200 rows.

So simply replace plt_Dy5 by plt_D5(i) and you should be fine.


Formatting number in European format with two decimals

Trying to format a number to two decimals format in European culture. So that comma is decimal separator and space thousands separator. In example 213245 should be formatted as 213 245,00 How can I do that? 213245.toFixed(2).toLocaleString(); gives 213245.00 but it should be 213 245,00 however 213245.toLocaleString() gives 213 245...

Accessing open files globally in Fortran

Is there any means to accessing (reading, writing to) files that are opened in some other source code by just passing the unit number?

Scala: Better way for String Formatting to PhoneNumber and using Java's MessageFormat

I'm looking for a better way to better implement the following: I have imported import java.text.MessageFormat to set the format I would like. val szphoneFrmt holds the format I would like. val szInitialString is set to the value I pulled from the database. val szWorkString breaks up the string via...

Fortran compiler for mac to read program

I'm using the g77 compiler (on terminal I just type g77 filename.for ) on a Mac. It can't read my fortran program and I can't modify the program (very old program, not mine, and I really just need the output from it). Any suggestion for another compiler to read the...

Formatting long-form survey data in R

We asked 3 people two or three yes-no questions. Let me denote these 3 people by 101,102,103 the questions by "A", "B","C" and the responses by 0, 1. The result is q<-data.frame(response=c(0,0,1,0,0,1,1), qstn=c("A","B","A","B","A","B","C"), person=c(101,101,102,102,103,103,103)) We need to convert this table to the following format person|qustionA|questionB|questionC 101 | 0 | 0...

Ambiguous reference to variable

So I am doing 2 modules which are linking to the main program. The first one has all the variables defined in it and the second one is with the functions. Module1: module zmienne implicit none integer, parameter :: ngauss = 8 integer, parameter :: out_unit=1000 integer, parameter :: out_unit1=1001...

Batch file to conditionally execute ifortvars.bat

I am using a make.bat file to compile my Fortran code. To compile using the ifort command, I first need to initialize the compiler by executing ifortvarsbat intel64 command where I had to setup the path variable. This works fine, however, the path keeps increasing in size and says command...

Using move_alloc in a derived type

I have written a derived type that stores a multidimensional array. The array will be read from a file to an array b. I then want to transfer b to the derived type Space using member a. The advantage for mvalloc is not having to allocate two large arrays which...

Fortran runtime error “bad integer for item 11 in list input”

I receive the runtime error "bad integer for item 11 in list input" referencing the following line of code. read(2,*)a,b,c,d,e,f,g,h,theta1,phi1,k,l,m,n,o, $ p,theta2,phi2,s,theta3,phi3, $ r1,x1,y1,r2,x2,y2,r3,x3,y3,z1,z2,z3 The line its reading from is 1 255.11211 0.2876 165.11404 90 4 8 0.19173 90 165.11404 0.09587 90 345.11404 4 4 0.0764 89.99915 -64.51149 0.11131 90.0015...

gfortran doesn't compile real variables

I have written a simple program in Fortran90 to calculate the area of a triangle. The user enters the three sides of the triangle, and then the program outputs the area. Simple enough. MODULE Triangle_Operations IMPLICIT NONE CONTAINS FUNCTION Area(x,y,z) REAL :: Area ! function type REAL, INTENT( IN )...

Filling Multidimensional Arrays

I have created a derived type to access multi-dimensional arrays. With each array I associate a name in the array nm. My problem consists how to fill the array values once I have allocated the memory. An initial idea has been to use a multi-dimensional array as input. However I...

Checking all elements of array for a logical condition in fortran

I want to check all rows of an array for a logical condition. I used function ALL as described in GNU GCC guide Here is a sample code: program test3 implicit none real, allocatable, dimension (:,:) :: mat1 integer :: i,j,k,r logical :: lg r=3 allocate(mat1(r,r)) mat1=transpose( reshape( (/-1,-2,-3,-4,-5,-6,-7,-8,-9/),...

Are the LAPACK routines thread safe?

I am a novice using the LAPACK routines, so I don't deeply know them, and I want to use them in parallelized loops (openmp). I use Ubuntu 14.04LTS and have LAPACK installed using my package manager. The version installed is: liblapack3 3.5.0-2ubuntu1 Library of linear algebra routines 3 - shared...

FORTRAN unformatted file write by each process

In my parallel program, there was a big matrix. Each process computed and stored a part of it. Then the program wrote the matrix to a file by letting each process wrote its own part of the matrix in the correct order. The output file is in "unformatted" form. But...

How to dynamically set currency symbol in Excel custom format?

The figures in my spreadsheet use the following custom formatting: €#,###.##,, "M" So figures are expressed in millions with 2 decimal places prefixed by the euro symbol and followed by M for millions. My workbook will need to be converted to other currencies and I don't want to have to...

Unclassifiable statement at (1) in Fortran

I am pretty new to to fortran and I don't really know why am I getting this error. integrand(i)=inte(x(i),beta,r2,r1) 1 Error: Unclassifiable statement at (1) calka11.f95:97.6: I have made all the variables into a module file and then call them using use and when I am getting those variables into...

Python 2.7 Etree/lxml minimizing [duplicate]

This question already has an answer here: Close a tag with no text in lxml 3 answers Im using lxml/Etree to parse and write to XSD documents. I have the basic structure tree = ET.parse('file.xsd') # do stuff tree.write('output.xsd') But tags get minimized in some instances, for example: <Cars>...

Fortran Seg Fault when assigning Matrices

[UPDATE] the code and a few sentences were changed to reflect a realization explained in my second comment. The code should compile with the line below, however, I have an older gfortran and may not be seeing some errors that you might. gfortran BLU_implementation_copy.f90 -o BLU_implementation_copy.x I'm getting an incredibly...

Fortran: makefile error

I have a fortran main program called solidsolver.f90, and a module called read_mesh.f90. The module contains two subroutines and is used in the main program. I can compile them manually but not with a makefile. My makefile is named makefile.makefile, and it gives me an error: make: *** No targets...

Wrong column filtering for date column

I use tablesorter to sort columns. But I found the following issue: As you can see the second row doesn't have 16. This table also have the external search field and search result equals 1 if I type 16, thus second row doesn't show. But it lools like a tablesorter...

Can I declare only specific elements of an array as constant? (C/C++/Fortran)

Scenario: I pass e.g. a 2D matrix as argument in a function and I would like to be able to read and change all the elements, BUT I would like to prevent any accidental writting in let's say the last column. So I would like somehow to tell the compiler...

Retaining original table formatting after a 'pagebreak'

So here's the finished product, a statement of accounts with a working statement table, and an ageing analysis: Everything works great. It basically populates itself row by row with data from another table. Here is the sample code: j = 21 'First row on the statement of accounts workbook For...

What does this horribly ugly (yet somehow secretly beautiful) Perl code do?

I found this code in a Powerpoint presentation about Perl scripting and this was on a page demonstrating how ugly Perl code can get if you really wanted to make it that way. The presentation says nothing about what this code does. Honestly I am just very curious to know......

Need help in writing this multiplication code

I need to show process of multiplication in output.for ex:- inputs are two numbers(say 325 and 4405) the output would be:- 325 *4405 ----- 1625 0 1300 1300 ------- 1431625 NOTE:-number of spaces should be minimum. I don't need the exact code. Just tell me which property or way I...

Fortran memory allocation does not give an error, but the program is killed by OS at initialization

Given the minimal working example provided below, do you know why the memory allocation error does not occur at memory allocation step? As I checked, when I use valgrind to run the code, or add parameter source=0.0 to memory allocation statement, then I have, as expected, the memory allocation error....

How to apply scales::percent or scales::percent_format() to prop.table in R to format numbers as percentages

Consider the following example: tab <- table(mtcars$vs, mtcars$cyl, dnn = c("vs", "cylinder")) prop.table(tab) # cylinder # vs 4 6 8 # 0 0.03125 0.09375 0.43750 # 1 0.31250 0.12500 0.00000 round(prop.table(tab)*100, 1) # cylinder # vs 4 6 8 # 0 3.1 9.4 43.8 # 1 31.2 12.5 0.0 Desired...

How to serialize a custom formatted time to/from xml in Go?

When serializing a datetime to/from xml how do I make it use a custom time format?

unformatted output with wild card in Fortran

I've searched for a long time before I ask: I need to output a lot of unformatted files in Fortran to Ensight. I want to name them with geo.000000, geo.000001 ... geo.0001000. Here is how I deal with wild card: character(54) :: filename, temp character(80) :: buffer write(temp,'(i6.6)') step filename...

How to set font-weight of a column text to bold based on another column value in Telerik Grid

I have a Telerik grid in which based on whether my IsTrue value is true or false, I need to set the font-weight of Name text in only that particular row to bold. I tried the following but I seem to be missing something. columns.Bound(d => d.IsTrue).Width(0).HtmlAttributes(new { id="hdnIsTrue", style...

How can I implement BCD in Fortran?

Not sure if the title of my question makes sense, so bear with me. I'd like to find a system for representing single digit numbers with as few bits as possible. There is a method called "Densely packed decimal" ( which would be my ideal solution, but I wouldn't even...

How exactly do pointers in Fortran differ from C/C++ pointers?

It might be useful to have both C/C++ programmers and Fortran programmers compare and contrast pointers in these two languages. In trying to explain to C/C++ programmers how Fortran pointers differ, I usually say pointers to functions or subroutines do not exist. I then try to make the argument that...

How to .write() two items, a zero and an iterator in Python?

I may have a simple formatting question here - I would like to do something like hrOut.write('0',i) in order to add/preface a zero to 'i' which is a timestamp, but I don't know the correct syntax. My code is below. Thank you all. hrIn = open('HrsInput.csv') hrOut = open('HrsOutput.csv', 'wt')...

ieee_arithmetic intrinsic module in gfortran

I need to use gfortran to compile a library that is dependent on ieee_arithmetic. However, it is found that gfortran can not identify this module. For example with the code a.f90 program test use,intrinsic :: ieee_arithmetic real :: x read *, x if (ieee_is_nan(x)) then print *, "Nan" else print...

Using Floor and Int in a computation

I am using a calculation to locate a base pixel. Seems to me that the two calculations for i and j are equivalent (i.e. i==j is always true) when I tried a few examples. Is this always true? i = (int ((x - xmin) / a)) + 1 j =...

error: 'x' argument pf 'dtime' intrinsic at <1> must be of kind 4

My understanding of programming is very limited so I hope I am making sense. I made a change to a fixed variable in a program (the program is called NAFnoise; I was using the .exe but it came with the source code and I made the change there). The program...

Data exchange - Python and Fortran

We are developing a scientific application which has the interface in python 2.7 and the computation routines written in Intel Visual Fortran. Reading the source files is done using python, then only the required data for computations has to be passed to standalone Fortran algorithms. Once the computations done, the...

How can i store 2 numbers in a 1 byte char?

I have the question of the title, but If not, how could I get away with using only 4 bits to represent an integer? EDIT really my question is how. I am aware that there are 1 byte data structures in a language like c, but how could I use...

Formatting large numbers in C#

I am using Unity to make an "Incremental Game" also known as an "Idle Game" and I am trying to format large numbers. For example, when gold gets to say 1000 or more, it will display as Gold: 1k instead of Gold: 1000. using UnityEngine; using System.Collections; public class Click...

Using allocatable/assumed-size arrays with namelist read write

I am using VS2012 and Intel Visual Fortran 2015. According to, it is now allowed to use allocatable and assumed-size arrays with namelist read and write; however, I am still getting the error "A namelist-group-object must not be an assumed-size array". example code: subroutine writeGrid(fname, grid) character*(*) :: fname...

SSRS Average Time in Minutes and then Format to HH MM

I've seen a lot of questions about average time in SSRS but I'm pretty new to this and none of these questions address my specific need so any help would be appreciated. I have a duration field (Fields!Duration1.Value) which is pulling in a duration in minutes (example: 170). In my...

Display a table in MATLAB

I am trying to display a table with two columns and 86 rows. Instead of outputting the rows, the size is stated. Is there a way to change this? I am new to MATLAB and am coming from a background in C/C++ so I may just be approaching this all...

Using BLAS ?gemm on a subset of an array in fortran

The various LDx arguments to BLAS ?gemm functions are there to make it possible to operate on slices of larger arrays. For example, this small C program does a matrix multiplication of the top left and top right (100,100) submatrices of a (200,200) matrix, and stores the result in the...

Fortran derived type in common: initialization?

I got troubles with this common: COMMON /REDCOM/ DPREC,NITMA,INDIC,NBERR,NCAR,KMOTLU, & REDVAR,MOCDER(2) COMMON /REDCO1/ CTEXT C type(double_st) :: DPREC INTEGER :: NITMA,INDIC,NBERR,NCAR,KMOTLU,REDVAR,MOCDER CHARACTER(72) :: CTEXT CHARACTER(4) :: CTEXT4 C EQUIVALENCE (CTEXT,CTEXT4) The double_st derived type is: type double_st sequence real(kind(0.d0)) :: x,y,z integer :: acc = -1 end type double_st Trying...

How to call Fortran routine with unit number argument from C

If I have a Fortran subroutine which takes a Fortran IO Unit as one of its parameters (for printing debug information to), and this function is compiled into a shared library, how do I correctly call this function from C? ! An example subroutine that I want to call from...

How to convert a Rational into a “pretty” String?

I want to display some Rational values in their decimal expansion. That is, instead of displaying 3 % 4, I would rather display 0.75. I'd like this function to be of type Int -> Rational -> String. The first Int is to specify the maximum number of decimal places, since...

How do I extract a floating number in the middle of an alphanumeric chain?

I am coding in Fortran 95. I must extract the two floating values from this line in an ascii file: circle(4097.0438,4111.337) Of course the READ statement is read(unit=11, fmt="(tr7,f9.4,tr1,f8.3)") x, y The problem is that I must do that for hundreds of ascii files, but there are variations in the...

Precision not respected

I use Visual Studio (2010 SP1) with Fortran IMSL (2011) and I can't get the right precision for my reals: program prova use, intrinsic :: iso_fortran_env implicit none integer, parameter :: ikind=selected_real_kind(p=8, r=99) real(kind=ikind) :: a=0.79 real(real64) :: b=0.79 real(kind=16) :: c=0.79 real(8) :: d=0.79 print *, a print *,...

Disabling fp-model strict when using ifort with f2py

I'm using f2py to offload performance critical sections of my python code to fortran. I have two fortran compilers, gfortran and ifort. Since the code I run will be on intel processors, ifort is usually faster. But for the most critical part of my code, I observe the opposite, with...

Altering XML file format in C#

I have a program in Visual Studio which gives the output in an XML file. It looks like so: <?xml version="1.0" encoding="utf-8"?> <leaCEDS> <district> <leaID>01</leaID> <name>Alachua</name> <organizationType>LEA</organizationType> <streetLine1>620 E University Ave</streetLine1> <city>Gainesville</city> <stateProvince>FL</stateProvince> <postalCode>326015448</postalCode> <county>Alachua</county>...

Simple and clean java float to string conversion

This is a very simple question, but I'm amazed on how difficult it has been to answer. Even the documentation didn't give a clear and straight answer. You see, I'm simply trying to convert a simple float to a string such that the result only has one decimal digit. For...