Arrays of strings in GFORTRAN errors


 
Thread Tools Search this Thread
Top Forums Programming Arrays of strings in GFORTRAN errors
# 1  
Old 12-06-2012
Arrays of strings in GFORTRAN errors

Hello
I am using gfortran and I intended to do thiis:

Code:
      Module variables
     character(len=:), dimension(:),  allocatable, array
     end module variables

    Sub test
    use variables
    integer (max_len)
    max_len=len_trim("something here")
    if(.not.allocated(array)) &
    allocate(character = max_len :: array(3))
   array = (/'jonas', 'sssssssssssssss','q' /) 
   end sub test

gfortran compilation gives this errors:

Code:
  - max_len can not be used in this context: 
     allocate(character = max_len :: array(3))    &

  - Different character lenghts in array constructor:
      array = (/'jonas', 'sssssssssssssss','q' /)

I solved this using a number instead of max_len for the first error;
The second error can only be solved if all strings have the same lenght but this is not desired.

with a different compiler no error is displayed.
Moderator's Comments:
Mod Comment Please use code tags

Last edited by jim mcnamara; 12-06-2012 at 09:12 AM..
# 2  
Old 12-14-2012
One compiler may store an array of pointers to C-esque null terminated character arrays, so length is not an issue. Another might allocate the array as a block of storage, and making it scan the intializers for max length is asking a lot for FORTRAN. The second require you dimension the array with sufficient space (like for 3 string arrays of 20 characters) for any initializer before you initialize the space. My feel is tha FORTRAN is much more of a "know your compiler" universe than C/C++, where you can predict where every byte is on every implementation.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Added Two Arrays But With Errors

Please could someone have a look at the code below and spot the cause of the error. Thanks in advance. CODE BELOW: (code tags now added) My apologies please, that was my first time here.:) #! /bin/bash # file: whileloop.sh arr1=(2 4 6 8) arr2=(3 6 9 12) arr3=() indextotal=(${#arr1})... (4 Replies)
Discussion started by: Chiadi
4 Replies

2. Shell Programming and Scripting

Using arrays in bash using strings to bash built-in true

I have the following code and for some reason when I call the program using /home/tcdata/tatsh/trunk/hstmy/bin/bash/raytrac.bash --cmod=jcdint.cmod I get hasArgument = hasArgument = true Somehow the array element is returning even though I have not chosen the option. ... (41 Replies)
Discussion started by: kristinu
41 Replies

3. Shell Programming and Scripting

Compare strings between 2 arrays and print number in AWK

Hi to everyone, Please some help over here. Hi have array a with 6 elements and array b with 3 elements as shown inside BEGIN{} statement. I need help to get the correct sintax (the part in red) to compare if string from array b is in array a and print the number related for each match.... (3 Replies)
Discussion started by: Ophiuchus
3 Replies

4. Programming

Compilation problem with gfortran

Hello everyone, I'm trying since a few days to compile a f90 program with gfortran (on Ubuntu) with a makefile. The fortran program calls 2 routines written in C. Here is my makefile: FC = gfortran SFC = gfortran FFLAGS = -ffree-form -O... (21 Replies)
Discussion started by: leroygr
21 Replies

5. Programming

Gfortran compiler options.

I am a INTEL fortran user recently migrated to linux and installed gfortran on my system. I run numerical models as part of my research. my question is on optimization of the fortran code. I used the - vectorize option to compile for reducing the run time considerably and was happy. But... (1 Reply)
Discussion started by: schamarthi1
1 Replies

6. Shell Programming and Scripting

How to make arrays from strings in bash?

Hey all, This is my first post, and I am relatively new to linux/unix scripts. I am writing a bash script in which I am trying to extract one line from another file and parse specific words from the line into an array. So for example, I have a file called SortScans in which the first 5 lines... (9 Replies)
Discussion started by: camocazi
9 Replies

7. Programming

question about int arrays and file pointer arrays

if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Discussion started by: omega666
1 Replies

8. Programming

Fortran 77 and gfortran

Hi! I have a program in fortran77. This program was compiled with pgf90, but now, I need compiled it with gfortran. I show a bit of code. program hello PARAMETER(a=100) integer a write(*,*)'value ', a end program hello What's the problem? Thanks (2 Replies)
Discussion started by: kekaes
2 Replies

9. UNIX for Dummies Questions & Answers

Strings in arrays

Hi There, Code: Number=10 i=1 while do echo "$i" Check=`find $viewing -name $File_Pattern -type f -Print` i=`expr ${i} + 1` done Unable to store the values in variable 'Check', when i display i am getting Check nothing... (1 Reply)
Discussion started by: Naveen_5960
1 Replies

10. Shell Programming and Scripting

comparing two arrays or strings in bash

Hi there, im having issue with comparing two variables, in a bash script. im trying to do the following: - get a word from user 1 - split the word into array - get a character from user2 trying to compare the character entered by user 2 with every single character in the array... (2 Replies)
Discussion started by: new2Linux
2 Replies
Login or Register to Ask a Question