'Fortran read data with different colums in multiple rows

Hi I am almost new for fortran and struggling with it at the moment.

My question is,

I open a text file and wanna read muliple lines which have different colums. (My goal is to read the element into an 1D array)

The last line in my code will print the start to end location.

I hope someone could help me.

        IMPLICIT NONE
        CHARACTER(500)             :: MODELLINE
        INTEGER(4)                 :: STARTPOINT, POINT, N, CNT, NROW
        INTEGER(4)                 :: I, NNOD, J, K
        INTEGER(4), ALLOCATABLE    :: STARLIST(:), FINDCOL(:,:)

        OPEN(UNIT=400, FILE='inputfile.txt', STATUS ='OLD')
        CNT = 0
        STARTPOINT =0
        DO I = 1, 4000
            READ(400,'(A)',END = 10001, ERR= 10001) MODELLINE
            CNT = CNT + 1
            IF (MODELLINE(1:7) == '*ELSET,') STARTPOINT = STARTPOINT+1
        ENDDO 
10001 REWIND(400)
        ALLOCATE(STARLIST(STARTPOINT))
        NROW = CNT
        
        K = 0
        POINT =0
        DO I = 1, NROW
            READ(400,'(A)') MODELLINE
            IF (MODELLINE(1:7) == '*ELSET,') K = K+1
            STARLIST(K) = I ! Location for *ELSET
            IF (MODELLINE(1:19) == '*ELSET, ELSET=PART4') POINT = I
        ENDDO 
        !WRITE(*,*) STARTPOINT, STARLIST, POINT
        DO I = 1, STARTPOINT
            IF (STARLIST(I) == POINT-1) THEN 
            K = STARLIST(I)-STARLIST(I+1)
        ENDIF 
        ENDDO 
        WRITE(*,*) POINT, POINT-(K)-1
        REWIND(400)
    END

inputfile is like this

*ELSET, ELSET=PART1
   203,   204,   205,   206,   207,   208,   209,   210,   211,   212
   213,   214,   215,   216,   217,   218,   219,   220,   221,   222
   223,   224,   225,   255,   256,   257,   258,   259,   260,   261
   262,   263,   264,   265,   266,   267,   268,   269,   270,   271
   272,   273,   274,   275,   276,   277,   278,   279,   308,   309
   310,   311,   312,   313,   314,   315,   316,   317,   318,   319
   320,   321,   322,   323,   324,   325,   326,   327,   328,   329
   330,   331,   332,   333,   334,   335,   336,   347,   348,   349
   350,   351,   352,   353,   354,   355,   356
  2203,  2204,  2205,  2206,  2207,  2208,  2209,  2210,  2211,  2212
  2213,  2214,  2215,  2216,  2217,  2218,  2219,  2220,  2221,  2222
  2223,  2224,  2225,  2255,  2256,  2257,  2258,  2259,  2260,  2261
  2262,  2263,  2264,  2265,  2266,  2267,  2268,  2269,  2270,  2271
  2272,  2273,  2274,  2275,  2276,  2277,  2278,  2279,  2308,  2309
  2310,  2311,  2312,  2313,  2314,  2315,  2316,  2317,  2318,  2319
  2320,  2321,  2322,  2323,  2324,  2325,  2326,  2327,  2328,  2329
  2330,  2331,  2332,  2333,  2334,  2335,  2336,  2347,  2348,  2349
  2350,  2351,  2352,  2353,  2354,  2355,  2356
*ELSET, ELSET=PART2
   226,   227,   228,   229,   337,   359,   465,   466,   467,   468
   469,   470,   471,   472,   473,   474,   475,   476,   477,   478
   479,   480,   481,   482,   483,   484,   485,   486,   487,   488
  2226,  2227,  2228,  2229,  2337,  2359,  2465,  2466,  2467,  2468
  2469,  2470,  2471,  2472,  2473,  2474,  2475,  2476,  2477,  2478
  2479,  2480,  2481,  2482,  2483,  2484,  2485,  2486,  2487,  2488
*ELSET, ELSET=PART3
   230,   231,   232,   233,   234,   235,   236,   237,   238,   239
   240,   241,   242,   243,   244,   245,   246,   247,   248,   249
   250,   251,   252,   253,   254
  2230,  2231,  2232,  2233,  2234,  2235,  2236,  2237,  2238,  2239
  2240,  2241,  2242,  2243,  2244,  2245,  2246,  2247,  2248,  2249
  2250,  2251,  2252,  2253,  2254
*ELSET, ELSET=PART4
   255,   256,   257,   258,   259,   260,   261,   262,   263,   264
   265,   266,   267,   268,   269,   270,   271,   272,   273,   274
   275,   276,   277,   278,   279
  2255,  2256,  2257,  2258,  2259,  2260,  2261,  2262,  2263,  2264
  2265,  2266,  2267,  2268,  2269,  2270,  2271,  2272,  2273,  2274
  2275,  2276,  2277,  2278,  2279
*ELSET, ELSET=PART5
   280,   281,   282,   283,   284,   285,   286,   287,   288,   289
   290,   291,   292,   293,   294,   295,   296,   297,   298,   299
   300,   301,   302,   303,   304,   305,   306,   307
  2280,  2281,  2282,  2283,  2284,  2285,  2286,  2287,  2288,  2289
  2290,  2291,  2292,  2293,  2294,  2295,  2296,  2297,  2298,  2299
  2300,  2301,  2302,  2303,  2304,  2305,  2306,  2307
*ELSET, ELSET=PART6
   338,   339,   340,   341,   342,   343,   344,   345,   346
  2338,  2339,  2340,  2341,  2342,  2343,  2344,  2345,  2346
*ELSET, ELSET=PART7
   357,   358,   360,   361,   362,   363,   364,   365,   366,   367
   368,   369,   370,   371,   372,   373,   374,   375,   376,   377
   378,   379,   380,   381,   382,   383,   384,   385,   386,   387
   388,   389,   390,   393
  2357,  2358,  2360,  2361,  2362,  2363,  2364,  2365,  2366,  2367
  2368,  2369,  2370,  2371,  2372,  2373,  2374,  2375,  2376,  2377
  2378,  2379,  2380,  2381,  2382,  2383,  2384,  2385,  2386,  2387
  2388,  2389,  2390,  2393


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source